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 | |
| 959 | MemberExpr *ME = |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 960 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 961 | Member, MemberLoc, |
| 962 | cast<FieldDecl>(Member)->getType()); |
| 963 | return getSema().Owned(ME); |
| 964 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 965 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 966 | CXXScopeSpec SS; |
| 967 | if (Qualifier) { |
| 968 | SS.setRange(QualifierRange); |
| 969 | SS.setScopeRep(Qualifier); |
| 970 | } |
| 971 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 972 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 973 | |
| 974 | // FIXME: wait, this is re-performing lookup? |
| 975 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 976 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 977 | SS, FirstQualifierInScope, |
| 978 | Member->getDeclName(), MemberLoc, |
| 979 | ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 982 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 984 | /// By default, performs semantic analysis to build the new expression. |
| 985 | /// Subclasses may override this routine to provide different behavior. |
| 986 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 987 | BinaryOperator::Opcode Opc, |
| 988 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 989 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 990 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 995 | /// By default, performs semantic analysis to build the new expression. |
| 996 | /// Subclasses may override this routine to provide different behavior. |
| 997 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 998 | SourceLocation QuestionLoc, |
| 999 | ExprArg LHS, |
| 1000 | SourceLocation ColonLoc, |
| 1001 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | move(LHS), move(RHS)); |
| 1004 | } |
| 1005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1006 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1008 | /// By default, performs semantic analysis to build the new expression. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
| 1010 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1011 | QualType ExplicitTy, |
| 1012 | SourceLocation RParenLoc, |
| 1013 | ExprArg SubExpr) { |
| 1014 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1015 | LParenLoc, |
| 1016 | ExplicitTy.getAsOpaquePtr(), |
| 1017 | RParenLoc, |
| 1018 | move(SubExpr)); |
| 1019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | /// By default, performs semantic analysis to build the new expression. |
| 1024 | /// Subclasses may override this routine to provide different behavior. |
| 1025 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1026 | QualType T, |
| 1027 | SourceLocation RParenLoc, |
| 1028 | ExprArg Init) { |
| 1029 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1030 | RParenLoc, move(Init)); |
| 1031 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1033 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | /// By default, performs semantic analysis to build the new expression. |
| 1036 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1038 | SourceLocation OpLoc, |
| 1039 | SourceLocation AccessorLoc, |
| 1040 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1041 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1042 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1043 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1044 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1045 | OpLoc, /*IsArrow*/ false, |
| 1046 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1047 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1048 | AccessorLoc, |
| 1049 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1052 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1054 | /// By default, performs semantic analysis to build the new expression. |
| 1055 | /// Subclasses may override this routine to provide different behavior. |
| 1056 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1057 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1058 | SourceLocation RBraceLoc, |
| 1059 | QualType ResultTy) { |
| 1060 | OwningExprResult Result |
| 1061 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1062 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1063 | return move(Result); |
| 1064 | |
| 1065 | // Patch in the result type we were given, which may have been computed |
| 1066 | // when the initial InitListExpr was built. |
| 1067 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1068 | ILE->setType(ResultTy); |
| 1069 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1072 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1073 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1074 | /// By default, performs semantic analysis to build the new expression. |
| 1075 | /// Subclasses may override this routine to provide different behavior. |
| 1076 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1077 | MultiExprArg ArrayExprs, |
| 1078 | SourceLocation EqualOrColonLoc, |
| 1079 | bool GNUSyntax, |
| 1080 | ExprArg Init) { |
| 1081 | OwningExprResult Result |
| 1082 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1083 | move(Init)); |
| 1084 | if (Result.isInvalid()) |
| 1085 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | ArrayExprs.release(); |
| 1088 | return move(Result); |
| 1089 | } |
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 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | /// By default, builds the implicit value initialization without performing |
| 1094 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1095 | /// different behavior. |
| 1096 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1097 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1098 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1099 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1102 | /// By default, performs semantic analysis to build the new expression. |
| 1103 | /// Subclasses may override this routine to provide different behavior. |
| 1104 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1105 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1107 | RParenLoc); |
| 1108 | } |
| 1109 | |
| 1110 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1112 | /// By default, performs semantic analysis to build the new expression. |
| 1113 | /// Subclasses may override this routine to provide different behavior. |
| 1114 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1115 | MultiExprArg SubExprs, |
| 1116 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1117 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1118 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1119 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1121 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | /// |
| 1123 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1124 | /// rather than attempting to map the label statement itself. |
| 1125 | /// Subclasses may override this routine to provide different behavior. |
| 1126 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1127 | SourceLocation LabelLoc, |
| 1128 | LabelStmt *Label) { |
| 1129 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1133 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1134 | /// By default, performs semantic analysis to build the new expression. |
| 1135 | /// Subclasses may override this routine to provide different behavior. |
| 1136 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1137 | StmtArg SubStmt, |
| 1138 | SourceLocation RParenLoc) { |
| 1139 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1140 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1142 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1143 | /// |
| 1144 | /// By default, performs semantic analysis to build the new expression. |
| 1145 | /// Subclasses may override this routine to provide different behavior. |
| 1146 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1147 | QualType T1, QualType T2, |
| 1148 | SourceLocation RParenLoc) { |
| 1149 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1150 | T1.getAsOpaquePtr(), |
| 1151 | T2.getAsOpaquePtr(), |
| 1152 | RParenLoc); |
| 1153 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1155 | /// \brief Build a new __builtin_choose_expr expression. |
| 1156 | /// |
| 1157 | /// By default, performs semantic analysis to build the new expression. |
| 1158 | /// Subclasses may override this routine to provide different behavior. |
| 1159 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1160 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1161 | SourceLocation RParenLoc) { |
| 1162 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1163 | move(Cond), move(LHS), move(RHS), |
| 1164 | RParenLoc); |
| 1165 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1167 | /// \brief Build a new overloaded operator call expression. |
| 1168 | /// |
| 1169 | /// By default, performs semantic analysis to build the new expression. |
| 1170 | /// The semantic analysis provides the behavior of template instantiation, |
| 1171 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1174 | /// provide different behavior. |
| 1175 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1176 | SourceLocation OpLoc, |
| 1177 | ExprArg Callee, |
| 1178 | ExprArg First, |
| 1179 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | |
| 1181 | /// \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] | 1182 | /// reinterpret_cast. |
| 1183 | /// |
| 1184 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1186 | /// Subclasses may override this routine to provide different behavior. |
| 1187 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1188 | Stmt::StmtClass Class, |
| 1189 | SourceLocation LAngleLoc, |
| 1190 | QualType T, |
| 1191 | SourceLocation RAngleLoc, |
| 1192 | SourceLocation LParenLoc, |
| 1193 | ExprArg SubExpr, |
| 1194 | SourceLocation RParenLoc) { |
| 1195 | switch (Class) { |
| 1196 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1198 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | move(SubExpr), RParenLoc); |
| 1200 | |
| 1201 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1203 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1204 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1208 | RAngleLoc, LParenLoc, |
| 1209 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1210 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1214 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1215 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | default: |
| 1218 | assert(false && "Invalid C++ named cast"); |
| 1219 | break; |
| 1220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | return getSema().ExprError(); |
| 1223 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | /// \brief Build a new C++ static_cast expression. |
| 1226 | /// |
| 1227 | /// By default, performs semantic analysis to build the new expression. |
| 1228 | /// Subclasses may override this routine to provide different behavior. |
| 1229 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1230 | SourceLocation LAngleLoc, |
| 1231 | QualType T, |
| 1232 | SourceLocation RAngleLoc, |
| 1233 | SourceLocation LParenLoc, |
| 1234 | ExprArg SubExpr, |
| 1235 | SourceLocation RParenLoc) { |
| 1236 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1238 | LParenLoc, move(SubExpr), RParenLoc); |
| 1239 | } |
| 1240 | |
| 1241 | /// \brief Build a new C++ dynamic_cast expression. |
| 1242 | /// |
| 1243 | /// By default, performs semantic analysis to build the new expression. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| 1245 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1246 | SourceLocation LAngleLoc, |
| 1247 | QualType T, |
| 1248 | SourceLocation RAngleLoc, |
| 1249 | SourceLocation LParenLoc, |
| 1250 | ExprArg SubExpr, |
| 1251 | SourceLocation RParenLoc) { |
| 1252 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1253 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1254 | LParenLoc, move(SubExpr), RParenLoc); |
| 1255 | } |
| 1256 | |
| 1257 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1258 | /// |
| 1259 | /// By default, performs semantic analysis to build the new expression. |
| 1260 | /// Subclasses may override this routine to provide different behavior. |
| 1261 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1262 | SourceLocation LAngleLoc, |
| 1263 | QualType T, |
| 1264 | SourceLocation RAngleLoc, |
| 1265 | SourceLocation LParenLoc, |
| 1266 | ExprArg SubExpr, |
| 1267 | SourceLocation RParenLoc) { |
| 1268 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1269 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1270 | LParenLoc, move(SubExpr), RParenLoc); |
| 1271 | } |
| 1272 | |
| 1273 | /// \brief Build a new C++ const_cast expression. |
| 1274 | /// |
| 1275 | /// By default, performs semantic analysis to build the new expression. |
| 1276 | /// Subclasses may override this routine to provide different behavior. |
| 1277 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1278 | SourceLocation LAngleLoc, |
| 1279 | QualType T, |
| 1280 | SourceLocation RAngleLoc, |
| 1281 | SourceLocation LParenLoc, |
| 1282 | ExprArg SubExpr, |
| 1283 | SourceLocation RParenLoc) { |
| 1284 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1286 | LParenLoc, move(SubExpr), RParenLoc); |
| 1287 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1289 | /// \brief Build a new C++ functional-style cast expression. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to build the new expression. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1294 | QualType T, |
| 1295 | SourceLocation LParenLoc, |
| 1296 | ExprArg SubExpr, |
| 1297 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1298 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1299 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1300 | T.getAsOpaquePtr(), |
| 1301 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1302 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | RParenLoc); |
| 1305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | /// \brief Build a new C++ typeid(type) expression. |
| 1308 | /// |
| 1309 | /// By default, performs semantic analysis to build the new expression. |
| 1310 | /// Subclasses may override this routine to provide different behavior. |
| 1311 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1312 | SourceLocation LParenLoc, |
| 1313 | QualType T, |
| 1314 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1316 | T.getAsOpaquePtr(), 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(expr) 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 | ExprArg Operand, |
| 1326 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1328 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1329 | RParenLoc); |
| 1330 | if (Result.isInvalid()) |
| 1331 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1332 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1334 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// \brief Build a new C++ "this" expression. |
| 1338 | /// |
| 1339 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | QualType ThisType) { |
| 1344 | return getSema().Owned( |
| 1345 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1346 | } |
| 1347 | |
| 1348 | /// \brief Build a new C++ throw expression. |
| 1349 | /// |
| 1350 | /// By default, performs semantic analysis to build the new expression. |
| 1351 | /// Subclasses may override this routine to provide different behavior. |
| 1352 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1353 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1354 | } |
| 1355 | |
| 1356 | /// \brief Build a new C++ default-argument expression. |
| 1357 | /// |
| 1358 | /// By default, builds a new default-argument expression, which does not |
| 1359 | /// require any semantic analysis. Subclasses may override this routine to |
| 1360 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame^] | 1361 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1362 | ParmVarDecl *Param) { |
| 1363 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1364 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /// \brief Build a new C++ zero-initialization expression. |
| 1368 | /// |
| 1369 | /// By default, performs semantic analysis to build the new expression. |
| 1370 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | SourceLocation LParenLoc, |
| 1373 | QualType T, |
| 1374 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1376 | T.getAsOpaquePtr(), LParenLoc, |
| 1377 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | 0, RParenLoc); |
| 1379 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1381 | /// \brief Build a new C++ "new" 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 RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | bool UseGlobal, |
| 1387 | SourceLocation PlacementLParen, |
| 1388 | MultiExprArg PlacementArgs, |
| 1389 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | QualType AllocType, |
| 1392 | SourceLocation TypeLoc, |
| 1393 | SourceRange TypeRange, |
| 1394 | ExprArg ArraySize, |
| 1395 | SourceLocation ConstructorLParen, |
| 1396 | MultiExprArg ConstructorArgs, |
| 1397 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | PlacementLParen, |
| 1400 | move(PlacementArgs), |
| 1401 | PlacementRParen, |
| 1402 | ParenTypeId, |
| 1403 | AllocType, |
| 1404 | TypeLoc, |
| 1405 | TypeRange, |
| 1406 | move(ArraySize), |
| 1407 | ConstructorLParen, |
| 1408 | move(ConstructorArgs), |
| 1409 | ConstructorRParen); |
| 1410 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | /// \brief Build a new C++ "delete" expression. |
| 1413 | /// |
| 1414 | /// By default, performs semantic analysis to build the new expression. |
| 1415 | /// Subclasses may override this routine to provide different behavior. |
| 1416 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1417 | bool IsGlobalDelete, |
| 1418 | bool IsArrayForm, |
| 1419 | ExprArg Operand) { |
| 1420 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1421 | move(Operand)); |
| 1422 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1424 | /// \brief Build a new unary type trait expression. |
| 1425 | /// |
| 1426 | /// By default, performs semantic analysis to build the new expression. |
| 1427 | /// Subclasses may override this routine to provide different behavior. |
| 1428 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1429 | SourceLocation StartLoc, |
| 1430 | SourceLocation LParenLoc, |
| 1431 | QualType T, |
| 1432 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1434 | T.getAsOpaquePtr(), RParenLoc); |
| 1435 | } |
| 1436 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | /// expression. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to build the new expression. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1442 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1443 | SourceRange QualifierRange, |
| 1444 | DeclarationName Name, |
| 1445 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1446 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | CXXScopeSpec SS; |
| 1448 | SS.setRange(QualifierRange); |
| 1449 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1450 | |
| 1451 | if (TemplateArgs) |
| 1452 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1453 | *TemplateArgs); |
| 1454 | |
| 1455 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /// \brief Build a new template-id expression. |
| 1459 | /// |
| 1460 | /// By default, performs semantic analysis to build the new expression. |
| 1461 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1462 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1463 | LookupResult &R, |
| 1464 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1465 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1466 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /// \brief Build a new object-construction expression. |
| 1470 | /// |
| 1471 | /// By default, performs semantic analysis to build the new expression. |
| 1472 | /// Subclasses may override this routine to provide different behavior. |
| 1473 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1474 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | CXXConstructorDecl *Constructor, |
| 1476 | bool IsElidable, |
| 1477 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1478 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1479 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1480 | ConvertedArgs)) |
| 1481 | return getSema().ExprError(); |
| 1482 | |
| 1483 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1484 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /// \brief Build a new object-construction expression. |
| 1488 | /// |
| 1489 | /// By default, performs semantic analysis to build the new expression. |
| 1490 | /// Subclasses may override this routine to provide different behavior. |
| 1491 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1492 | QualType T, |
| 1493 | SourceLocation LParenLoc, |
| 1494 | MultiExprArg Args, |
| 1495 | SourceLocation *Commas, |
| 1496 | SourceLocation RParenLoc) { |
| 1497 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1498 | T.getAsOpaquePtr(), |
| 1499 | LParenLoc, |
| 1500 | move(Args), |
| 1501 | Commas, |
| 1502 | RParenLoc); |
| 1503 | } |
| 1504 | |
| 1505 | /// \brief Build a new object-construction expression. |
| 1506 | /// |
| 1507 | /// By default, performs semantic analysis to build the new expression. |
| 1508 | /// Subclasses may override this routine to provide different behavior. |
| 1509 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1510 | QualType T, |
| 1511 | SourceLocation LParenLoc, |
| 1512 | MultiExprArg Args, |
| 1513 | SourceLocation *Commas, |
| 1514 | SourceLocation RParenLoc) { |
| 1515 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1516 | /*FIXME*/LParenLoc), |
| 1517 | T.getAsOpaquePtr(), |
| 1518 | LParenLoc, |
| 1519 | move(Args), |
| 1520 | Commas, |
| 1521 | RParenLoc); |
| 1522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1524 | /// \brief Build a new member reference expression. |
| 1525 | /// |
| 1526 | /// By default, performs semantic analysis to build the new expression. |
| 1527 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1528 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1529 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1530 | bool IsArrow, |
| 1531 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1532 | NestedNameSpecifier *Qualifier, |
| 1533 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1534 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1535 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1536 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1537 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1539 | SS.setRange(QualifierRange); |
| 1540 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1541 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1542 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1543 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1544 | SS, FirstQualifierInScope, |
| 1545 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1548 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1549 | /// |
| 1550 | /// By default, performs semantic analysis to build the new expression. |
| 1551 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1552 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1553 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1554 | SourceLocation OperatorLoc, |
| 1555 | bool IsArrow, |
| 1556 | NestedNameSpecifier *Qualifier, |
| 1557 | SourceRange QualifierRange, |
| 1558 | LookupResult &R, |
| 1559 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1560 | CXXScopeSpec SS; |
| 1561 | SS.setRange(QualifierRange); |
| 1562 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1564 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1565 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1566 | SS, R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1567 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1569 | /// \brief Build a new Objective-C @encode expression. |
| 1570 | /// |
| 1571 | /// By default, performs semantic analysis to build the new expression. |
| 1572 | /// Subclasses may override this routine to provide different behavior. |
| 1573 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1574 | QualType T, |
| 1575 | SourceLocation RParenLoc) { |
| 1576 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1577 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1579 | |
| 1580 | /// \brief Build a new Objective-C protocol expression. |
| 1581 | /// |
| 1582 | /// By default, performs semantic analysis to build the new expression. |
| 1583 | /// Subclasses may override this routine to provide different behavior. |
| 1584 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1585 | SourceLocation AtLoc, |
| 1586 | SourceLocation ProtoLoc, |
| 1587 | SourceLocation LParenLoc, |
| 1588 | SourceLocation RParenLoc) { |
| 1589 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1590 | Protocol->getIdentifier(), |
| 1591 | AtLoc, |
| 1592 | ProtoLoc, |
| 1593 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1594 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1595 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1597 | /// \brief Build a new shuffle vector expression. |
| 1598 | /// |
| 1599 | /// By default, performs semantic analysis to build the new expression. |
| 1600 | /// Subclasses may override this routine to provide different behavior. |
| 1601 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1602 | MultiExprArg SubExprs, |
| 1603 | SourceLocation RParenLoc) { |
| 1604 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1607 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1608 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1609 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | // Build a reference to the __builtin_shufflevector builtin |
| 1612 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1614 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1615 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1616 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | |
| 1618 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1619 | unsigned NumSubExprs = SubExprs.size(); |
| 1620 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1621 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1622 | Subs, NumSubExprs, |
| 1623 | Builtin->getResultType(), |
| 1624 | RParenLoc); |
| 1625 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
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 | // Type-check the __builtin_shufflevector expression. |
| 1628 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1629 | if (Result.isInvalid()) |
| 1630 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1632 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1634 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1635 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1637 | template<typename Derived> |
| 1638 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1639 | if (!S) |
| 1640 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1642 | switch (S->getStmtClass()) { |
| 1643 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1645 | // Transform individual statement nodes |
| 1646 | #define STMT(Node, Parent) \ |
| 1647 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1648 | #define EXPR(Node, Parent) |
| 1649 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1651 | // Transform expressions by calling TransformExpr. |
| 1652 | #define STMT(Node, Parent) |
| 1653 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1654 | #include "clang/AST/StmtNodes.def" |
| 1655 | { |
| 1656 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1657 | if (E.isInvalid()) |
| 1658 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1660 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1661 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1664 | return SemaRef.Owned(S->Retain()); |
| 1665 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
| 1667 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1668 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1669 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1670 | if (!E) |
| 1671 | return SemaRef.Owned(E); |
| 1672 | |
| 1673 | switch (E->getStmtClass()) { |
| 1674 | case Stmt::NoStmtClass: break; |
| 1675 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1676 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1677 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1681 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1685 | NestedNameSpecifier * |
| 1686 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1687 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1688 | QualType ObjectType, |
| 1689 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1690 | if (!NNS) |
| 1691 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1693 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1694 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1695 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1697 | ObjectType, |
| 1698 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1699 | if (!Prefix) |
| 1700 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | |
| 1702 | // 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] | 1703 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1704 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1705 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1708 | switch (NNS->getKind()) { |
| 1709 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1711 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1712 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1713 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1714 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1715 | |
| 1716 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1717 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1718 | ObjectType, |
| 1719 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1720 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1721 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1723 | = cast_or_null<NamespaceDecl>( |
| 1724 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1726 | Prefix == NNS->getPrefix() && |
| 1727 | NS == NNS->getAsNamespace()) |
| 1728 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1730 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1733 | case NestedNameSpecifier::Global: |
| 1734 | // There is no meaningful transformation that one could perform on the |
| 1735 | // global scope. |
| 1736 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1738 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1739 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1740 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1741 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1742 | if (T.isNull()) |
| 1743 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1745 | if (!getDerived().AlwaysRebuild() && |
| 1746 | Prefix == NNS->getPrefix() && |
| 1747 | T == QualType(NNS->getAsType(), 0)) |
| 1748 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
| 1750 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1751 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1752 | T); |
| 1753 | } |
| 1754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1756 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1762 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1763 | SourceLocation Loc, |
| 1764 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1765 | if (!Name) |
| 1766 | return Name; |
| 1767 | |
| 1768 | switch (Name.getNameKind()) { |
| 1769 | case DeclarationName::Identifier: |
| 1770 | case DeclarationName::ObjCZeroArgSelector: |
| 1771 | case DeclarationName::ObjCOneArgSelector: |
| 1772 | case DeclarationName::ObjCMultiArgSelector: |
| 1773 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1774 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1775 | case DeclarationName::CXXUsingDirective: |
| 1776 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1778 | case DeclarationName::CXXConstructorName: |
| 1779 | case DeclarationName::CXXDestructorName: |
| 1780 | case DeclarationName::CXXConversionFunctionName: { |
| 1781 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1782 | QualType T; |
| 1783 | if (!ObjectType.isNull() && |
| 1784 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1785 | TemplateSpecializationType *SpecType |
| 1786 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1787 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1788 | } else |
| 1789 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1790 | if (T.isNull()) |
| 1791 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1793 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1795 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1796 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1799 | return DeclarationName(); |
| 1800 | } |
| 1801 | |
| 1802 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1804 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1805 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1806 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1808 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1809 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1810 | if (!NNS) |
| 1811 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1812 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1813 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1815 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1816 | if (!TransTemplate) |
| 1817 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1819 | if (!getDerived().AlwaysRebuild() && |
| 1820 | NNS == QTN->getQualifier() && |
| 1821 | TransTemplate == Template) |
| 1822 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1824 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1825 | TransTemplate); |
| 1826 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1828 | // These should be getting filtered out before they make it into the AST. |
| 1829 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1832 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1833 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1834 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1835 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1836 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1837 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1839 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1840 | NNS == DTN->getQualifier() && |
| 1841 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1842 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1844 | if (DTN->isIdentifier()) |
| 1845 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1846 | ObjectType); |
| 1847 | |
| 1848 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1849 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1852 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1853 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1854 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1855 | if (!TransTemplate) |
| 1856 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1858 | if (!getDerived().AlwaysRebuild() && |
| 1859 | TransTemplate == Template) |
| 1860 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1862 | return TemplateName(TransTemplate); |
| 1863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1865 | // These should be getting filtered out before they reach the AST. |
| 1866 | assert(false && "overloaded function decl survived to here"); |
| 1867 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1871 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1872 | const TemplateArgument &Arg, |
| 1873 | TemplateArgumentLoc &Output) { |
| 1874 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1875 | switch (Arg.getKind()) { |
| 1876 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1877 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1878 | break; |
| 1879 | |
| 1880 | case TemplateArgument::Type: |
| 1881 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1882 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1883 | |
| 1884 | break; |
| 1885 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1886 | case TemplateArgument::Template: |
| 1887 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1888 | break; |
| 1889 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1890 | case TemplateArgument::Expression: |
| 1891 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1892 | break; |
| 1893 | |
| 1894 | case TemplateArgument::Declaration: |
| 1895 | case TemplateArgument::Integral: |
| 1896 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1897 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | template<typename Derived> |
| 1903 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1904 | const TemplateArgumentLoc &Input, |
| 1905 | TemplateArgumentLoc &Output) { |
| 1906 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1907 | switch (Arg.getKind()) { |
| 1908 | case TemplateArgument::Null: |
| 1909 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1910 | Output = Input; |
| 1911 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1913 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1914 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1915 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1916 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1917 | |
| 1918 | DI = getDerived().TransformType(DI); |
| 1919 | if (!DI) return true; |
| 1920 | |
| 1921 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1922 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1923 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1925 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1926 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1927 | DeclarationName Name; |
| 1928 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1929 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1930 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1931 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1932 | if (!D) return true; |
| 1933 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1934 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1935 | if (SourceExpr) { |
| 1936 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1937 | Action::Unevaluated); |
| 1938 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1939 | if (E.isInvalid()) |
| 1940 | SourceExpr = NULL; |
| 1941 | else { |
| 1942 | SourceExpr = E.takeAs<Expr>(); |
| 1943 | SourceExpr->Retain(); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1948 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1950 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1951 | case TemplateArgument::Template: { |
| 1952 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1953 | TemplateName Template |
| 1954 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1955 | if (Template.isNull()) |
| 1956 | return true; |
| 1957 | |
| 1958 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1959 | Input.getTemplateQualifierRange(), |
| 1960 | Input.getTemplateNameLoc()); |
| 1961 | return false; |
| 1962 | } |
| 1963 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1964 | case TemplateArgument::Expression: { |
| 1965 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1966 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1967 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1968 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1969 | Expr *InputExpr = Input.getSourceExpression(); |
| 1970 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1971 | |
| 1972 | Sema::OwningExprResult E |
| 1973 | = getDerived().TransformExpr(InputExpr); |
| 1974 | if (E.isInvalid()) return true; |
| 1975 | |
| 1976 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1977 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1978 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1979 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1981 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1982 | case TemplateArgument::Pack: { |
| 1983 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1984 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1986 | AEnd = Arg.pack_end(); |
| 1987 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1989 | // FIXME: preserve source information here when we start |
| 1990 | // caring about parameter packs. |
| 1991 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1992 | TemplateArgumentLoc InputArg; |
| 1993 | TemplateArgumentLoc OutputArg; |
| 1994 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 1995 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1996 | return true; |
| 1997 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1998 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1999 | } |
| 2000 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2001 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2002 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2003 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2004 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2005 | } |
| 2006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2009 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2012 | //===----------------------------------------------------------------------===// |
| 2013 | // Type transformation |
| 2014 | //===----------------------------------------------------------------------===// |
| 2015 | |
| 2016 | template<typename Derived> |
| 2017 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2018 | if (getDerived().AlreadyTransformed(T)) |
| 2019 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2021 | // Temporary workaround. All of these transformations should |
| 2022 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2023 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2024 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2025 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2026 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2027 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2028 | if (!NewDI) |
| 2029 | return QualType(); |
| 2030 | |
| 2031 | return NewDI->getType(); |
| 2032 | } |
| 2033 | |
| 2034 | template<typename Derived> |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2035 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2036 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2037 | return DI; |
| 2038 | |
| 2039 | TypeLocBuilder TLB; |
| 2040 | |
| 2041 | TypeLoc TL = DI->getTypeLoc(); |
| 2042 | TLB.reserve(TL.getFullDataSize()); |
| 2043 | |
| 2044 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2045 | if (Result.isNull()) |
| 2046 | return 0; |
| 2047 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2048 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | template<typename Derived> |
| 2052 | QualType |
| 2053 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2054 | switch (T.getTypeLocClass()) { |
| 2055 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2056 | #define TYPELOC(CLASS, PARENT) \ |
| 2057 | case TypeLoc::CLASS: \ |
| 2058 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2059 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2060 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2061 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2062 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2063 | return QualType(); |
| 2064 | } |
| 2065 | |
| 2066 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2067 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2068 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2069 | /// types). This is the right thing for template instantiation, but |
| 2070 | /// probably not for other clients. |
| 2071 | template<typename Derived> |
| 2072 | QualType |
| 2073 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2074 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2075 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2076 | |
| 2077 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2078 | if (Result.isNull()) |
| 2079 | return QualType(); |
| 2080 | |
| 2081 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2082 | // FIXME: this is the right thing for template instantiation, but |
| 2083 | // probably not for other clients. |
| 2084 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2085 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2086 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2087 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2088 | |
| 2089 | TLB.push<QualifiedTypeLoc>(Result); |
| 2090 | |
| 2091 | // No location information to preserve. |
| 2092 | |
| 2093 | return Result; |
| 2094 | } |
| 2095 | |
| 2096 | template <class TyLoc> static inline |
| 2097 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2098 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2099 | NewT.setNameLoc(T.getNameLoc()); |
| 2100 | return T.getType(); |
| 2101 | } |
| 2102 | |
| 2103 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2104 | // the equivalent template version work. |
| 2105 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2106 | QualType PointeeType \ |
| 2107 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2108 | if (PointeeType.isNull()) \ |
| 2109 | return QualType(); \ |
| 2110 | \ |
| 2111 | QualType Result = TL.getType(); \ |
| 2112 | if (getDerived().AlwaysRebuild() || \ |
| 2113 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2114 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2115 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2116 | if (Result.isNull()) \ |
| 2117 | return QualType(); \ |
| 2118 | } \ |
| 2119 | \ |
| 2120 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2121 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2122 | \ |
| 2123 | return Result; \ |
| 2124 | } while(0) |
| 2125 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2126 | template<typename Derived> |
| 2127 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2128 | BuiltinTypeLoc T) { |
| 2129 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2131 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2132 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2133 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2134 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2135 | FixedWidthIntTypeLoc T) { |
| 2136 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2137 | } |
Argyrios Kyrtzidis | e918926 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2138 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2139 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2140 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2141 | ComplexTypeLoc T) { |
| 2142 | // FIXME: recurse? |
| 2143 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2146 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2147 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2148 | PointerTypeLoc TL) { |
| 2149 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2151 | |
| 2152 | template<typename Derived> |
| 2153 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2154 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2155 | BlockPointerTypeLoc TL) { |
| 2156 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2159 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2160 | /// don't care whether the type itself is an l-value type or an r-value |
| 2161 | /// type; we only care if the type was *written* as an l-value type |
| 2162 | /// or an r-value type. |
| 2163 | template<typename Derived> |
| 2164 | QualType |
| 2165 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2166 | ReferenceTypeLoc TL) { |
| 2167 | const ReferenceType *T = TL.getTypePtr(); |
| 2168 | |
| 2169 | // Note that this works with the pointee-as-written. |
| 2170 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2171 | if (PointeeType.isNull()) |
| 2172 | return QualType(); |
| 2173 | |
| 2174 | QualType Result = TL.getType(); |
| 2175 | if (getDerived().AlwaysRebuild() || |
| 2176 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2177 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2178 | T->isSpelledAsLValue(), |
| 2179 | TL.getSigilLoc()); |
| 2180 | if (Result.isNull()) |
| 2181 | return QualType(); |
| 2182 | } |
| 2183 | |
| 2184 | // r-value references can be rebuilt as l-value references. |
| 2185 | ReferenceTypeLoc NewTL; |
| 2186 | if (isa<LValueReferenceType>(Result)) |
| 2187 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2188 | else |
| 2189 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2190 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2191 | |
| 2192 | return Result; |
| 2193 | } |
| 2194 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | template<typename Derived> |
| 2196 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2197 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2198 | LValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2199 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2202 | template<typename Derived> |
| 2203 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2204 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2205 | RValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2206 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2207 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2209 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2211 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2212 | MemberPointerTypeLoc TL) { |
| 2213 | MemberPointerType *T = TL.getTypePtr(); |
| 2214 | |
| 2215 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2216 | if (PointeeType.isNull()) |
| 2217 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2218 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2219 | // TODO: preserve source information for this. |
| 2220 | QualType ClassType |
| 2221 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2222 | if (ClassType.isNull()) |
| 2223 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2224 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2225 | QualType Result = TL.getType(); |
| 2226 | if (getDerived().AlwaysRebuild() || |
| 2227 | PointeeType != T->getPointeeType() || |
| 2228 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2229 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2230 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2231 | if (Result.isNull()) |
| 2232 | return QualType(); |
| 2233 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2234 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2235 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2236 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2237 | |
| 2238 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2241 | template<typename Derived> |
| 2242 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2243 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2244 | ConstantArrayTypeLoc TL) { |
| 2245 | ConstantArrayType *T = TL.getTypePtr(); |
| 2246 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2247 | if (ElementType.isNull()) |
| 2248 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2249 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | QualType Result = TL.getType(); |
| 2251 | if (getDerived().AlwaysRebuild() || |
| 2252 | ElementType != T->getElementType()) { |
| 2253 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2254 | T->getSizeModifier(), |
| 2255 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2256 | T->getIndexTypeCVRQualifiers(), |
| 2257 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2258 | if (Result.isNull()) |
| 2259 | return QualType(); |
| 2260 | } |
| 2261 | |
| 2262 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2263 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2264 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2265 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2266 | Expr *Size = TL.getSizeExpr(); |
| 2267 | if (Size) { |
| 2268 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2269 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2270 | } |
| 2271 | NewTL.setSizeExpr(Size); |
| 2272 | |
| 2273 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2276 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2277 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2278 | TypeLocBuilder &TLB, |
| 2279 | IncompleteArrayTypeLoc TL) { |
| 2280 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2281 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2282 | if (ElementType.isNull()) |
| 2283 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2285 | QualType Result = TL.getType(); |
| 2286 | if (getDerived().AlwaysRebuild() || |
| 2287 | ElementType != T->getElementType()) { |
| 2288 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2289 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2290 | T->getIndexTypeCVRQualifiers(), |
| 2291 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2292 | if (Result.isNull()) |
| 2293 | return QualType(); |
| 2294 | } |
| 2295 | |
| 2296 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2297 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2298 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2299 | NewTL.setSizeExpr(0); |
| 2300 | |
| 2301 | return Result; |
| 2302 | } |
| 2303 | |
| 2304 | template<typename Derived> |
| 2305 | QualType |
| 2306 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2307 | VariableArrayTypeLoc TL) { |
| 2308 | VariableArrayType *T = TL.getTypePtr(); |
| 2309 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2310 | if (ElementType.isNull()) |
| 2311 | return QualType(); |
| 2312 | |
| 2313 | // Array bounds are not potentially evaluated contexts |
| 2314 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2315 | |
| 2316 | Sema::OwningExprResult SizeResult |
| 2317 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2318 | if (SizeResult.isInvalid()) |
| 2319 | return QualType(); |
| 2320 | |
| 2321 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2322 | |
| 2323 | QualType Result = TL.getType(); |
| 2324 | if (getDerived().AlwaysRebuild() || |
| 2325 | ElementType != T->getElementType() || |
| 2326 | Size != T->getSizeExpr()) { |
| 2327 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2328 | T->getSizeModifier(), |
| 2329 | move(SizeResult), |
| 2330 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2331 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2332 | if (Result.isNull()) |
| 2333 | return QualType(); |
| 2334 | } |
| 2335 | else SizeResult.take(); |
| 2336 | |
| 2337 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2338 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2339 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2340 | NewTL.setSizeExpr(Size); |
| 2341 | |
| 2342 | return Result; |
| 2343 | } |
| 2344 | |
| 2345 | template<typename Derived> |
| 2346 | QualType |
| 2347 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2348 | DependentSizedArrayTypeLoc TL) { |
| 2349 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2350 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2351 | if (ElementType.isNull()) |
| 2352 | return QualType(); |
| 2353 | |
| 2354 | // Array bounds are not potentially evaluated contexts |
| 2355 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2356 | |
| 2357 | Sema::OwningExprResult SizeResult |
| 2358 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2359 | if (SizeResult.isInvalid()) |
| 2360 | return QualType(); |
| 2361 | |
| 2362 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2363 | |
| 2364 | QualType Result = TL.getType(); |
| 2365 | if (getDerived().AlwaysRebuild() || |
| 2366 | ElementType != T->getElementType() || |
| 2367 | Size != T->getSizeExpr()) { |
| 2368 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2369 | T->getSizeModifier(), |
| 2370 | move(SizeResult), |
| 2371 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2372 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2373 | if (Result.isNull()) |
| 2374 | return QualType(); |
| 2375 | } |
| 2376 | else SizeResult.take(); |
| 2377 | |
| 2378 | // We might have any sort of array type now, but fortunately they |
| 2379 | // all have the same location layout. |
| 2380 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2381 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2382 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2383 | NewTL.setSizeExpr(Size); |
| 2384 | |
| 2385 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2386 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2387 | |
| 2388 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2389 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2390 | TypeLocBuilder &TLB, |
| 2391 | DependentSizedExtVectorTypeLoc TL) { |
| 2392 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2393 | |
| 2394 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2395 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2396 | if (ElementType.isNull()) |
| 2397 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2398 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2399 | // Vector sizes are not potentially evaluated contexts |
| 2400 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2401 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2402 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2403 | if (Size.isInvalid()) |
| 2404 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2405 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2406 | QualType Result = TL.getType(); |
| 2407 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2408 | ElementType != T->getElementType() || |
| 2409 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2410 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2411 | move(Size), |
| 2412 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2413 | if (Result.isNull()) |
| 2414 | return QualType(); |
| 2415 | } |
| 2416 | else Size.take(); |
| 2417 | |
| 2418 | // Result might be dependent or not. |
| 2419 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2420 | DependentSizedExtVectorTypeLoc NewTL |
| 2421 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2422 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2423 | } else { |
| 2424 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2425 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2426 | } |
| 2427 | |
| 2428 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2430 | |
| 2431 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2432 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2433 | VectorTypeLoc TL) { |
| 2434 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2435 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2436 | if (ElementType.isNull()) |
| 2437 | return QualType(); |
| 2438 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2439 | QualType Result = TL.getType(); |
| 2440 | if (getDerived().AlwaysRebuild() || |
| 2441 | ElementType != T->getElementType()) { |
| 2442 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2443 | if (Result.isNull()) |
| 2444 | return QualType(); |
| 2445 | } |
| 2446 | |
| 2447 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2448 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2449 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2450 | return Result; |
| 2451 | } |
| 2452 | |
| 2453 | template<typename Derived> |
| 2454 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2455 | ExtVectorTypeLoc TL) { |
| 2456 | VectorType *T = TL.getTypePtr(); |
| 2457 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2458 | if (ElementType.isNull()) |
| 2459 | return QualType(); |
| 2460 | |
| 2461 | QualType Result = TL.getType(); |
| 2462 | if (getDerived().AlwaysRebuild() || |
| 2463 | ElementType != T->getElementType()) { |
| 2464 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2465 | T->getNumElements(), |
| 2466 | /*FIXME*/ SourceLocation()); |
| 2467 | if (Result.isNull()) |
| 2468 | return QualType(); |
| 2469 | } |
| 2470 | |
| 2471 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2472 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2473 | |
| 2474 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2475 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2476 | |
| 2477 | template<typename Derived> |
| 2478 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2479 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2480 | FunctionProtoTypeLoc TL) { |
| 2481 | FunctionProtoType *T = TL.getTypePtr(); |
| 2482 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2483 | if (ResultType.isNull()) |
| 2484 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2485 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2486 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2487 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2488 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2489 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2490 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2491 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2492 | QualType NewType; |
| 2493 | ParmVarDecl *NewParm; |
| 2494 | |
| 2495 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2496 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | assert(OldDI->getType() == T->getArgType(i)); |
| 2498 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2499 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2500 | if (!NewDI) |
| 2501 | return QualType(); |
| 2502 | |
| 2503 | if (NewDI == OldDI) |
| 2504 | NewParm = OldParm; |
| 2505 | else |
| 2506 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2507 | OldParm->getDeclContext(), |
| 2508 | OldParm->getLocation(), |
| 2509 | OldParm->getIdentifier(), |
| 2510 | NewDI->getType(), |
| 2511 | NewDI, |
| 2512 | OldParm->getStorageClass(), |
| 2513 | /* DefArg */ NULL); |
| 2514 | NewType = NewParm->getType(); |
| 2515 | |
| 2516 | // Deal with the possibility that we don't have a parameter |
| 2517 | // declaration for this parameter. |
| 2518 | } else { |
| 2519 | NewParm = 0; |
| 2520 | |
| 2521 | QualType OldType = T->getArgType(i); |
| 2522 | NewType = getDerived().TransformType(OldType); |
| 2523 | if (NewType.isNull()) |
| 2524 | return QualType(); |
| 2525 | } |
| 2526 | |
| 2527 | ParamTypes.push_back(NewType); |
| 2528 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2530 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2531 | QualType Result = TL.getType(); |
| 2532 | if (getDerived().AlwaysRebuild() || |
| 2533 | ResultType != T->getResultType() || |
| 2534 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2535 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2536 | ParamTypes.data(), |
| 2537 | ParamTypes.size(), |
| 2538 | T->isVariadic(), |
| 2539 | T->getTypeQuals()); |
| 2540 | if (Result.isNull()) |
| 2541 | return QualType(); |
| 2542 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2543 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2544 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2545 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2546 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2547 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2548 | NewTL.setArg(i, ParamDecls[i]); |
| 2549 | |
| 2550 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2552 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2553 | template<typename Derived> |
| 2554 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2555 | TypeLocBuilder &TLB, |
| 2556 | FunctionNoProtoTypeLoc TL) { |
| 2557 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2558 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2559 | if (ResultType.isNull()) |
| 2560 | return QualType(); |
| 2561 | |
| 2562 | QualType Result = TL.getType(); |
| 2563 | if (getDerived().AlwaysRebuild() || |
| 2564 | ResultType != T->getResultType()) |
| 2565 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2566 | |
| 2567 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2568 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2569 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2570 | |
| 2571 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2572 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2573 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2574 | template<typename Derived> QualType |
| 2575 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2576 | UnresolvedUsingTypeLoc TL) { |
| 2577 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2578 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2579 | if (!D) |
| 2580 | return QualType(); |
| 2581 | |
| 2582 | QualType Result = TL.getType(); |
| 2583 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2584 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2585 | if (Result.isNull()) |
| 2586 | return QualType(); |
| 2587 | } |
| 2588 | |
| 2589 | // We might get an arbitrary type spec type back. We should at |
| 2590 | // least always get a type spec type, though. |
| 2591 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2592 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2593 | |
| 2594 | return Result; |
| 2595 | } |
| 2596 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2597 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2598 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2599 | TypedefTypeLoc TL) { |
| 2600 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2601 | TypedefDecl *Typedef |
| 2602 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2603 | if (!Typedef) |
| 2604 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2605 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2606 | QualType Result = TL.getType(); |
| 2607 | if (getDerived().AlwaysRebuild() || |
| 2608 | Typedef != T->getDecl()) { |
| 2609 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2610 | if (Result.isNull()) |
| 2611 | return QualType(); |
| 2612 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2613 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2614 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2615 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2616 | |
| 2617 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2618 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2620 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2621 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2622 | TypeOfExprTypeLoc TL) { |
| 2623 | TypeOfExprType *T = TL.getTypePtr(); |
| 2624 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2625 | // typeof expressions are not potentially evaluated contexts |
| 2626 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2627 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2628 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2629 | if (E.isInvalid()) |
| 2630 | return QualType(); |
| 2631 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | QualType Result = TL.getType(); |
| 2633 | if (getDerived().AlwaysRebuild() || |
| 2634 | E.get() != T->getUnderlyingExpr()) { |
| 2635 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2636 | if (Result.isNull()) |
| 2637 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2638 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2639 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2641 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2642 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2643 | |
| 2644 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2645 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2646 | |
| 2647 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2648 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2649 | TypeOfTypeLoc TL) { |
| 2650 | TypeOfType *T = TL.getTypePtr(); |
| 2651 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2652 | // FIXME: should be an inner type, or at least have a TypeSourceInfo. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2654 | if (Underlying.isNull()) |
| 2655 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | QualType Result = TL.getType(); |
| 2658 | if (getDerived().AlwaysRebuild() || |
| 2659 | Underlying != T->getUnderlyingType()) { |
| 2660 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2661 | if (Result.isNull()) |
| 2662 | return QualType(); |
| 2663 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2665 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2666 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2667 | |
| 2668 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
| 2671 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2672 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2673 | DecltypeTypeLoc TL) { |
| 2674 | DecltypeType *T = TL.getTypePtr(); |
| 2675 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2676 | // decltype expressions are not potentially evaluated contexts |
| 2677 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2678 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2679 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2680 | if (E.isInvalid()) |
| 2681 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2682 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | QualType Result = TL.getType(); |
| 2684 | if (getDerived().AlwaysRebuild() || |
| 2685 | E.get() != T->getUnderlyingExpr()) { |
| 2686 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2687 | if (Result.isNull()) |
| 2688 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | else E.take(); |
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 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2693 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2694 | |
| 2695 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2699 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2700 | RecordTypeLoc TL) { |
| 2701 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2702 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2704 | if (!Record) |
| 2705 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2706 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2707 | QualType Result = TL.getType(); |
| 2708 | if (getDerived().AlwaysRebuild() || |
| 2709 | Record != T->getDecl()) { |
| 2710 | Result = getDerived().RebuildRecordType(Record); |
| 2711 | if (Result.isNull()) |
| 2712 | return QualType(); |
| 2713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2714 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2715 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2716 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2717 | |
| 2718 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2719 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2720 | |
| 2721 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2723 | EnumTypeLoc TL) { |
| 2724 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2725 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2727 | if (!Enum) |
| 2728 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2729 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2730 | QualType Result = TL.getType(); |
| 2731 | if (getDerived().AlwaysRebuild() || |
| 2732 | Enum != T->getDecl()) { |
| 2733 | Result = getDerived().RebuildEnumType(Enum); |
| 2734 | if (Result.isNull()) |
| 2735 | return QualType(); |
| 2736 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2738 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2739 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2740 | |
| 2741 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2742 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2743 | |
| 2744 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2745 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2746 | ElaboratedTypeLoc TL) { |
| 2747 | ElaboratedType *T = TL.getTypePtr(); |
| 2748 | |
| 2749 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2750 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2751 | if (Underlying.isNull()) |
| 2752 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2753 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | QualType Result = TL.getType(); |
| 2755 | if (getDerived().AlwaysRebuild() || |
| 2756 | Underlying != T->getUnderlyingType()) { |
| 2757 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2758 | if (Result.isNull()) |
| 2759 | return QualType(); |
| 2760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2762 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2763 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2764 | |
| 2765 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2766 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
| 2768 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2769 | template<typename Derived> |
| 2770 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | TypeLocBuilder &TLB, |
| 2772 | TemplateTypeParmTypeLoc TL) { |
| 2773 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2776 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2777 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2778 | TypeLocBuilder &TLB, |
| 2779 | SubstTemplateTypeParmTypeLoc TL) { |
| 2780 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | template<typename Derived> |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2784 | inline QualType |
| 2785 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2786 | TypeLocBuilder &TLB, |
| 2787 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2788 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2789 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2790 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2791 | template<typename Derived> |
| 2792 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2793 | const TemplateSpecializationType *TST, |
| 2794 | QualType ObjectType) { |
| 2795 | // FIXME: this entire method is a temporary workaround; callers |
| 2796 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2798 | // Fake up a TemplateSpecializationTypeLoc. |
| 2799 | TypeLocBuilder TLB; |
| 2800 | TemplateSpecializationTypeLoc TL |
| 2801 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2802 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2803 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2804 | |
| 2805 | TL.setTemplateNameLoc(BaseLoc); |
| 2806 | TL.setLAngleLoc(BaseLoc); |
| 2807 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2808 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2809 | const TemplateArgument &TA = TST->getArg(i); |
| 2810 | TemplateArgumentLoc TAL; |
| 2811 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2812 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2813 | } |
| 2814 | |
| 2815 | TypeLocBuilder IgnoredTLB; |
| 2816 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2821 | TypeLocBuilder &TLB, |
| 2822 | TemplateSpecializationTypeLoc TL, |
| 2823 | QualType ObjectType) { |
| 2824 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2825 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2826 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2827 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2828 | if (Template.isNull()) |
| 2829 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2830 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2831 | TemplateArgumentListInfo NewTemplateArgs; |
| 2832 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2833 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2834 | |
| 2835 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2836 | TemplateArgumentLoc Loc; |
| 2837 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2838 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2839 | NewTemplateArgs.addArgument(Loc); |
| 2840 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2841 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2842 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2843 | |
| 2844 | QualType Result = |
| 2845 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2846 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2847 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2848 | |
| 2849 | if (!Result.isNull()) { |
| 2850 | TemplateSpecializationTypeLoc NewTL |
| 2851 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2852 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2853 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2854 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2855 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2856 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2857 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2858 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2859 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2860 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2861 | |
| 2862 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2863 | QualType |
| 2864 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2865 | QualifiedNameTypeLoc TL) { |
| 2866 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2867 | NestedNameSpecifier *NNS |
| 2868 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2869 | SourceRange()); |
| 2870 | if (!NNS) |
| 2871 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2872 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2873 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2874 | if (Named.isNull()) |
| 2875 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2876 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2877 | QualType Result = TL.getType(); |
| 2878 | if (getDerived().AlwaysRebuild() || |
| 2879 | NNS != T->getQualifier() || |
| 2880 | Named != T->getNamedType()) { |
| 2881 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2882 | if (Result.isNull()) |
| 2883 | return QualType(); |
| 2884 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2885 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2886 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2887 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2888 | |
| 2889 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | |
| 2892 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2893 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2894 | TypenameTypeLoc TL) { |
| 2895 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2896 | |
| 2897 | /* FIXME: preserve source information better than this */ |
| 2898 | SourceRange SR(TL.getNameLoc()); |
| 2899 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2900 | NestedNameSpecifier *NNS |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2901 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2902 | if (!NNS) |
| 2903 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2904 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2905 | QualType Result; |
| 2906 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2908 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2910 | if (NewTemplateId.isNull()) |
| 2911 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2912 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2913 | if (!getDerived().AlwaysRebuild() && |
| 2914 | NNS == T->getQualifier() && |
| 2915 | NewTemplateId == QualType(TemplateId, 0)) |
| 2916 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2917 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2918 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2919 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2920 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2921 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2922 | if (Result.isNull()) |
| 2923 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2924 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2925 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2926 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2927 | |
| 2928 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2931 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2932 | QualType |
| 2933 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2934 | ObjCInterfaceTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2935 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2936 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2937 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2938 | |
| 2939 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2940 | QualType |
| 2941 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2942 | ObjCObjectPointerTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2943 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2944 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2945 | } |
| 2946 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2947 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2948 | // Statement transformation |
| 2949 | //===----------------------------------------------------------------------===// |
| 2950 | template<typename Derived> |
| 2951 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2952 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2953 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | template<typename Derived> |
| 2957 | Sema::OwningStmtResult |
| 2958 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2959 | return getDerived().TransformCompoundStmt(S, false); |
| 2960 | } |
| 2961 | |
| 2962 | template<typename Derived> |
| 2963 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2965 | bool IsStmtExpr) { |
| 2966 | bool SubStmtChanged = false; |
| 2967 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2968 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2969 | B != BEnd; ++B) { |
| 2970 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2971 | if (Result.isInvalid()) |
| 2972 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2974 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2975 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2976 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2978 | if (!getDerived().AlwaysRebuild() && |
| 2979 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2980 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2981 | |
| 2982 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2983 | move_arg(Statements), |
| 2984 | S->getRBracLoc(), |
| 2985 | IsStmtExpr); |
| 2986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2988 | template<typename Derived> |
| 2989 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 2991 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 2992 | { |
| 2993 | // The case value expressions are not potentially evaluated. |
| 2994 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 2996 | // Transform the left-hand case value. |
| 2997 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 2998 | if (LHS.isInvalid()) |
| 2999 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3001 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3002 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3003 | if (RHS.isInvalid()) |
| 3004 | return SemaRef.StmtError(); |
| 3005 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3006 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3007 | // Build the case statement. |
| 3008 | // Case statements are always rebuilt so that they will attached to their |
| 3009 | // transformed switch statement. |
| 3010 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3011 | move(LHS), |
| 3012 | S->getEllipsisLoc(), |
| 3013 | move(RHS), |
| 3014 | S->getColonLoc()); |
| 3015 | if (Case.isInvalid()) |
| 3016 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3018 | // Transform the statement following the case |
| 3019 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3020 | if (SubStmt.isInvalid()) |
| 3021 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3023 | // Attach the body to the case statement |
| 3024 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3025 | } |
| 3026 | |
| 3027 | template<typename Derived> |
| 3028 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3030 | // Transform the statement following the default case |
| 3031 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3032 | if (SubStmt.isInvalid()) |
| 3033 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3035 | // Default statements are always rebuilt |
| 3036 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3037 | move(SubStmt)); |
| 3038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3040 | template<typename Derived> |
| 3041 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3042 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3043 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3044 | if (SubStmt.isInvalid()) |
| 3045 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3047 | // FIXME: Pass the real colon location in. |
| 3048 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3049 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3050 | move(SubStmt)); |
| 3051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3053 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3054 | Sema::OwningStmtResult |
| 3055 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3056 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3057 | OwningExprResult Cond(SemaRef); |
| 3058 | VarDecl *ConditionVar = 0; |
| 3059 | if (S->getConditionVariable()) { |
| 3060 | ConditionVar |
| 3061 | = cast_or_null<VarDecl>( |
| 3062 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3063 | if (!ConditionVar) |
| 3064 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3065 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3066 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3067 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3068 | if (Cond.isInvalid()) |
| 3069 | return SemaRef.StmtError(); |
| 3070 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3071 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3072 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3074 | // Transform the "then" branch. |
| 3075 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3076 | if (Then.isInvalid()) |
| 3077 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | // Transform the "else" branch. |
| 3080 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3081 | if (Else.isInvalid()) |
| 3082 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3084 | if (!getDerived().AlwaysRebuild() && |
| 3085 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3086 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3087 | Then.get() == S->getThen() && |
| 3088 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3089 | return SemaRef.Owned(S->Retain()); |
| 3090 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3091 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3092 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | template<typename Derived> |
| 3097 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3100 | OwningExprResult Cond(SemaRef); |
| 3101 | VarDecl *ConditionVar = 0; |
| 3102 | if (S->getConditionVariable()) { |
| 3103 | ConditionVar |
| 3104 | = cast_or_null<VarDecl>( |
| 3105 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3106 | if (!ConditionVar) |
| 3107 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3108 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3109 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3110 | |
| 3111 | if (Cond.isInvalid()) |
| 3112 | return SemaRef.StmtError(); |
| 3113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3115 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3117 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3118 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3119 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3120 | if (Switch.isInvalid()) |
| 3121 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3123 | // Transform the body of the switch statement. |
| 3124 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3125 | if (Body.isInvalid()) |
| 3126 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Complete the switch statement. |
| 3129 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3130 | move(Body)); |
| 3131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | template<typename Derived> |
| 3134 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3135 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3136 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3137 | OwningExprResult Cond(SemaRef); |
| 3138 | VarDecl *ConditionVar = 0; |
| 3139 | if (S->getConditionVariable()) { |
| 3140 | ConditionVar |
| 3141 | = cast_or_null<VarDecl>( |
| 3142 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3143 | if (!ConditionVar) |
| 3144 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3145 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3146 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3147 | |
| 3148 | if (Cond.isInvalid()) |
| 3149 | return SemaRef.StmtError(); |
| 3150 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3151 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3152 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3154 | // Transform the body |
| 3155 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3156 | if (Body.isInvalid()) |
| 3157 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | if (!getDerived().AlwaysRebuild() && |
| 3160 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3161 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3162 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3163 | return SemaRef.Owned(S->Retain()); |
| 3164 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3165 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3166 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3169 | template<typename Derived> |
| 3170 | Sema::OwningStmtResult |
| 3171 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3172 | // Transform the condition |
| 3173 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3174 | if (Cond.isInvalid()) |
| 3175 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3176 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3177 | // Transform the body |
| 3178 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3179 | if (Body.isInvalid()) |
| 3180 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | if (!getDerived().AlwaysRebuild() && |
| 3183 | Cond.get() == S->getCond() && |
| 3184 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3185 | return SemaRef.Owned(S->Retain()); |
| 3186 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3188 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3189 | S->getRParenLoc()); |
| 3190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3192 | template<typename Derived> |
| 3193 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | // Transform the initialization statement |
| 3196 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3197 | if (Init.isInvalid()) |
| 3198 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3200 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3201 | OwningExprResult Cond(SemaRef); |
| 3202 | VarDecl *ConditionVar = 0; |
| 3203 | if (S->getConditionVariable()) { |
| 3204 | ConditionVar |
| 3205 | = cast_or_null<VarDecl>( |
| 3206 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3207 | if (!ConditionVar) |
| 3208 | return SemaRef.StmtError(); |
| 3209 | } else { |
| 3210 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3211 | |
| 3212 | if (Cond.isInvalid()) |
| 3213 | return SemaRef.StmtError(); |
| 3214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3215 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3216 | // Transform the increment |
| 3217 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3218 | if (Inc.isInvalid()) |
| 3219 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | // Transform the body |
| 3222 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3223 | if (Body.isInvalid()) |
| 3224 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | if (!getDerived().AlwaysRebuild() && |
| 3227 | Init.get() == S->getInit() && |
| 3228 | Cond.get() == S->getCond() && |
| 3229 | Inc.get() == S->getInc() && |
| 3230 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3231 | return SemaRef.Owned(S->Retain()); |
| 3232 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3233 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3234 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3235 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3236 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3237 | S->getRParenLoc(), move(Body)); |
| 3238 | } |
| 3239 | |
| 3240 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | Sema::OwningStmtResult |
| 3242 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3243 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3245 | S->getLabel()); |
| 3246 | } |
| 3247 | |
| 3248 | template<typename Derived> |
| 3249 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3252 | if (Target.isInvalid()) |
| 3253 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3255 | if (!getDerived().AlwaysRebuild() && |
| 3256 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3258 | |
| 3259 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3260 | move(Target)); |
| 3261 | } |
| 3262 | |
| 3263 | template<typename Derived> |
| 3264 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3266 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3269 | template<typename Derived> |
| 3270 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3272 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3275 | template<typename Derived> |
| 3276 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3279 | if (Result.isInvalid()) |
| 3280 | return SemaRef.StmtError(); |
| 3281 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | // to tell whether the return type of the function has changed. |
| 3284 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3285 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | template<typename Derived> |
| 3288 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3289 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3290 | bool DeclChanged = false; |
| 3291 | llvm::SmallVector<Decl *, 4> Decls; |
| 3292 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3293 | D != DEnd; ++D) { |
| 3294 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3295 | if (!Transformed) |
| 3296 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3298 | if (Transformed != *D) |
| 3299 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3301 | Decls.push_back(Transformed); |
| 3302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | return SemaRef.Owned(S->Retain()); |
| 3306 | |
| 3307 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | S->getStartLoc(), S->getEndLoc()); |
| 3309 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3311 | template<typename Derived> |
| 3312 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | template<typename Derived> |
| 3319 | Sema::OwningStmtResult |
| 3320 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3321 | // FIXME: Implement! |
| 3322 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3323 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | template<typename Derived> |
| 3328 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3329 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3330 | // FIXME: Implement this |
| 3331 | assert(false && "Cannot transform an Objective-C @try statement"); |
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 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | template<typename Derived> |
| 3336 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | // FIXME: Implement this |
| 3339 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3340 | return SemaRef.Owned(S->Retain()); |
| 3341 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | template<typename Derived> |
| 3344 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | // FIXME: Implement this |
| 3347 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | template<typename Derived> |
| 3352 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | // FIXME: Implement this |
| 3355 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | template<typename Derived> |
| 3360 | Sema::OwningStmtResult |
| 3361 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | ObjCAtSynchronizedStmt *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 @synchronized 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 | } |
| 3367 | |
| 3368 | template<typename Derived> |
| 3369 | Sema::OwningStmtResult |
| 3370 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | ObjCForCollectionStmt *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 for-each 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 | |
| 3378 | template<typename Derived> |
| 3379 | Sema::OwningStmtResult |
| 3380 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3381 | // Transform the exception declaration, if any. |
| 3382 | VarDecl *Var = 0; |
| 3383 | if (S->getExceptionDecl()) { |
| 3384 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3385 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3386 | ExceptionDecl->getDeclName()); |
| 3387 | |
| 3388 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3389 | if (T.isNull()) |
| 3390 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3391 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3392 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3393 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3394 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3395 | ExceptionDecl->getIdentifier(), |
| 3396 | ExceptionDecl->getLocation(), |
| 3397 | /*FIXME: Inaccurate*/ |
| 3398 | SourceRange(ExceptionDecl->getLocation())); |
| 3399 | if (!Var || Var->isInvalidDecl()) { |
| 3400 | if (Var) |
| 3401 | Var->Destroy(SemaRef.Context); |
| 3402 | return SemaRef.StmtError(); |
| 3403 | } |
| 3404 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | // Transform the actual exception handler. |
| 3407 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3408 | if (Handler.isInvalid()) { |
| 3409 | if (Var) |
| 3410 | Var->Destroy(SemaRef.Context); |
| 3411 | return SemaRef.StmtError(); |
| 3412 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | if (!getDerived().AlwaysRebuild() && |
| 3415 | !Var && |
| 3416 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3418 | |
| 3419 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3420 | Var, |
| 3421 | move(Handler)); |
| 3422 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3423 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3424 | template<typename Derived> |
| 3425 | Sema::OwningStmtResult |
| 3426 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3427 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3430 | if (TryBlock.isInvalid()) |
| 3431 | return SemaRef.StmtError(); |
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 | // Transform the handlers. |
| 3434 | bool HandlerChanged = false; |
| 3435 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3436 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3439 | if (Handler.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 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3443 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3446 | if (!getDerived().AlwaysRebuild() && |
| 3447 | TryBlock.get() == S->getTryBlock() && |
| 3448 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | |
| 3451 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3456 | // Expression transformation |
| 3457 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | template<typename Derived> |
| 3459 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3460 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3461 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3462 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | |
| 3464 | template<typename Derived> |
| 3465 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3466 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3467 | NestedNameSpecifier *Qualifier = 0; |
| 3468 | if (E->getQualifier()) { |
| 3469 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3470 | E->getQualifierRange()); |
| 3471 | if (!Qualifier) |
| 3472 | return SemaRef.ExprError(); |
| 3473 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3474 | |
| 3475 | ValueDecl *ND |
| 3476 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3477 | if (!ND) |
| 3478 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3480 | if (!getDerived().AlwaysRebuild() && |
| 3481 | Qualifier == E->getQualifier() && |
| 3482 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3483 | !E->hasExplicitTemplateArgumentList()) { |
| 3484 | |
| 3485 | // Mark it referenced in the new context regardless. |
| 3486 | // FIXME: this is a bit instantiation-specific. |
| 3487 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3488 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3490 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3491 | |
| 3492 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3493 | if (E->hasExplicitTemplateArgumentList()) { |
| 3494 | TemplateArgs = &TransArgs; |
| 3495 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3496 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3497 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3498 | TemplateArgumentLoc Loc; |
| 3499 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3500 | return SemaRef.ExprError(); |
| 3501 | TransArgs.addArgument(Loc); |
| 3502 | } |
| 3503 | } |
| 3504 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3505 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3506 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3507 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3508 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3509 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3511 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3513 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3515 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3517 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3519 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3520 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3521 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3523 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3525 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3527 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3529 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3533 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3534 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3535 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | return SemaRef.Owned(E->Retain()); |
| 3537 | } |
| 3538 | |
| 3539 | template<typename Derived> |
| 3540 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3541 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3542 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3543 | if (SubExpr.isInvalid()) |
| 3544 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | return SemaRef.Owned(E->Retain()); |
| 3548 | |
| 3549 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3550 | E->getRParen()); |
| 3551 | } |
| 3552 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | template<typename Derived> |
| 3554 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3555 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3556 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3557 | if (SubExpr.isInvalid()) |
| 3558 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3560 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | return SemaRef.Owned(E->Retain()); |
| 3562 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3563 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3564 | E->getOpcode(), |
| 3565 | move(SubExpr)); |
| 3566 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3568 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3570 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3571 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3572 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3573 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3574 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3575 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3576 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3577 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3578 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3579 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3581 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3583 | E->getSourceRange()); |
| 3584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3586 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3587 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3588 | // C++0x [expr.sizeof]p1: |
| 3589 | // The operand is either an expression, which is an unevaluated operand |
| 3590 | // [...] |
| 3591 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3593 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3594 | if (SubExpr.isInvalid()) |
| 3595 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3598 | return SemaRef.Owned(E->Retain()); |
| 3599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3600 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3601 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3602 | E->isSizeOf(), |
| 3603 | E->getSourceRange()); |
| 3604 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3607 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3608 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3609 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3610 | if (LHS.isInvalid()) |
| 3611 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3614 | if (RHS.isInvalid()) |
| 3615 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
| 3617 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | if (!getDerived().AlwaysRebuild() && |
| 3619 | LHS.get() == E->getLHS() && |
| 3620 | RHS.get() == E->getRHS()) |
| 3621 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3624 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3625 | move(RHS), |
| 3626 | E->getRBracketLoc()); |
| 3627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | |
| 3629 | template<typename Derived> |
| 3630 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3631 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | // Transform the callee. |
| 3633 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3634 | if (Callee.isInvalid()) |
| 3635 | return SemaRef.ExprError(); |
| 3636 | |
| 3637 | // Transform arguments. |
| 3638 | bool ArgChanged = false; |
| 3639 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3640 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3641 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3642 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3643 | if (Arg.isInvalid()) |
| 3644 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | // FIXME: Wrong source location information for the ','. |
| 3647 | FakeCommaLocs.push_back( |
| 3648 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | |
| 3650 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3651 | Args.push_back(Arg.takeAs<Expr>()); |
| 3652 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3654 | if (!getDerived().AlwaysRebuild() && |
| 3655 | Callee.get() == E->getCallee() && |
| 3656 | !ArgChanged) |
| 3657 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3659 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3660 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3662 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3663 | move_arg(Args), |
| 3664 | FakeCommaLocs.data(), |
| 3665 | E->getRParenLoc()); |
| 3666 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | |
| 3668 | template<typename Derived> |
| 3669 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3670 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3671 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3672 | if (Base.isInvalid()) |
| 3673 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3674 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3675 | NestedNameSpecifier *Qualifier = 0; |
| 3676 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3678 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3679 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3680 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3681 | return SemaRef.ExprError(); |
| 3682 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3684 | ValueDecl *Member |
| 3685 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3686 | if (!Member) |
| 3687 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3689 | if (!getDerived().AlwaysRebuild() && |
| 3690 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3691 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3692 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3693 | !E->hasExplicitTemplateArgumentList()) { |
| 3694 | |
| 3695 | // Mark it referenced in the new context regardless. |
| 3696 | // FIXME: this is a bit instantiation-specific. |
| 3697 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3699 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3700 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3701 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3702 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3703 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3704 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3705 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3706 | TemplateArgumentLoc Loc; |
| 3707 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3708 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3709 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3710 | } |
| 3711 | } |
| 3712 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3713 | // FIXME: Bogus source location for the operator |
| 3714 | SourceLocation FakeOperatorLoc |
| 3715 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3716 | |
| 3717 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3718 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3719 | Qualifier, |
| 3720 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3721 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3722 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3723 | (E->hasExplicitTemplateArgumentList() |
| 3724 | ? &TransArgs : 0), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3725 | 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3726 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3728 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3729 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3730 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3731 | assert(false && "Cannot transform abstract class"); |
| 3732 | return SemaRef.Owned(E->Retain()); |
| 3733 | } |
| 3734 | |
| 3735 | template<typename Derived> |
| 3736 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3737 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3738 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3739 | if (LHS.isInvalid()) |
| 3740 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3742 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3743 | if (RHS.isInvalid()) |
| 3744 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | if (!getDerived().AlwaysRebuild() && |
| 3747 | LHS.get() == E->getLHS() && |
| 3748 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | return SemaRef.Owned(E->Retain()); |
| 3750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3752 | move(LHS), move(RHS)); |
| 3753 | } |
| 3754 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3756 | Sema::OwningExprResult |
| 3757 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3758 | CompoundAssignOperator *E) { |
| 3759 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3761 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3762 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3764 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3765 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3766 | if (Cond.isInvalid()) |
| 3767 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3769 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3770 | if (LHS.isInvalid()) |
| 3771 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3773 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3774 | if (RHS.isInvalid()) |
| 3775 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 3778 | Cond.get() == E->getCond() && |
| 3779 | LHS.get() == E->getLHS() && |
| 3780 | RHS.get() == E->getRHS()) |
| 3781 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
| 3783 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3784 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3785 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3786 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3787 | move(RHS)); |
| 3788 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3789 | |
| 3790 | template<typename Derived> |
| 3791 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3792 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3793 | // Implicit casts are eliminated during transformation, since they |
| 3794 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3795 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3796 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3797 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3798 | template<typename Derived> |
| 3799 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3800 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3801 | assert(false && "Cannot transform abstract class"); |
| 3802 | return SemaRef.Owned(E->Retain()); |
| 3803 | } |
| 3804 | |
| 3805 | template<typename Derived> |
| 3806 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3807 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3808 | QualType T; |
| 3809 | { |
| 3810 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3812 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3813 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3815 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3816 | if (T.isNull()) |
| 3817 | return SemaRef.ExprError(); |
| 3818 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3820 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3821 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3822 | if (SubExpr.isInvalid()) |
| 3823 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3824 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3825 | if (!getDerived().AlwaysRebuild() && |
| 3826 | T == E->getTypeAsWritten() && |
| 3827 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3828 | return SemaRef.Owned(E->Retain()); |
| 3829 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3830 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3831 | E->getRParenLoc(), |
| 3832 | move(SubExpr)); |
| 3833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3834 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3837 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3838 | QualType T; |
| 3839 | { |
| 3840 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | SourceLocation FakeTypeLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3843 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | T = getDerived().TransformType(E->getType()); |
| 3846 | if (T.isNull()) |
| 3847 | return SemaRef.ExprError(); |
| 3848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3850 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3851 | if (Init.isInvalid()) |
| 3852 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3853 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | if (!getDerived().AlwaysRebuild() && |
| 3855 | T == E->getType() && |
| 3856 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | |
| 3859 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3860 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3861 | move(Init)); |
| 3862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | template<typename Derived> |
| 3865 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3866 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3868 | if (Base.isInvalid()) |
| 3869 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3870 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3871 | if (!getDerived().AlwaysRebuild() && |
| 3872 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | return SemaRef.Owned(E->Retain()); |
| 3874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3876 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3877 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3878 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3879 | E->getAccessorLoc(), |
| 3880 | E->getAccessor()); |
| 3881 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3883 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3884 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3885 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3886 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3888 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3889 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3890 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3891 | if (Init.isInvalid()) |
| 3892 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3895 | Inits.push_back(Init.takeAs<Expr>()); |
| 3896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | return SemaRef.Owned(E->Retain()); |
| 3900 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3901 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3902 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3903 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3905 | template<typename Derived> |
| 3906 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3907 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3909 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3910 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3912 | if (Init.isInvalid()) |
| 3913 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3915 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3917 | bool ExprChanged = false; |
| 3918 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3919 | DEnd = E->designators_end(); |
| 3920 | D != DEnd; ++D) { |
| 3921 | if (D->isFieldDesignator()) { |
| 3922 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3923 | D->getDotLoc(), |
| 3924 | D->getFieldLoc())); |
| 3925 | continue; |
| 3926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3928 | if (D->isArrayDesignator()) { |
| 3929 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3930 | if (Index.isInvalid()) |
| 3931 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3932 | |
| 3933 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3937 | ArrayExprs.push_back(Index.release()); |
| 3938 | continue; |
| 3939 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3941 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3943 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3944 | if (Start.isInvalid()) |
| 3945 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3948 | if (End.isInvalid()) |
| 3949 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
| 3951 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | End.get(), |
| 3953 | D->getLBracketLoc(), |
| 3954 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3957 | End.get() != E->getArrayRangeEnd(*D); |
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 | ArrayExprs.push_back(Start.release()); |
| 3960 | ArrayExprs.push_back(End.release()); |
| 3961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | if (!getDerived().AlwaysRebuild() && |
| 3964 | Init.get() == E->getInit() && |
| 3965 | !ExprChanged) |
| 3966 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3969 | E->getEqualOrColonLoc(), |
| 3970 | E->usesGNUSyntax(), move(Init)); |
| 3971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3973 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3976 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3977 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3978 | |
| 3979 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3980 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | QualType T = getDerived().TransformType(E->getType()); |
| 3982 | if (T.isNull()) |
| 3983 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | if (!getDerived().AlwaysRebuild() && |
| 3986 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | return SemaRef.Owned(E->Retain()); |
| 3988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 3990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3992 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3994 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3995 | // FIXME: Do we want the type as written? |
| 3996 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3998 | { |
| 3999 | // FIXME: Source location isn't quite accurate. |
| 4000 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4001 | T = getDerived().TransformType(E->getType()); |
| 4002 | if (T.isNull()) |
| 4003 | return SemaRef.ExprError(); |
| 4004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4007 | if (SubExpr.isInvalid()) |
| 4008 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4011 | T == E->getType() && |
| 4012 | SubExpr.get() == E->getSubExpr()) |
| 4013 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4016 | T, E->getRParenLoc()); |
| 4017 | } |
| 4018 | |
| 4019 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4020 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4021 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4022 | bool ArgumentChanged = false; |
| 4023 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4024 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4025 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4026 | if (Init.isInvalid()) |
| 4027 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4028 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4030 | Inits.push_back(Init.takeAs<Expr>()); |
| 4031 | } |
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().RebuildParenListExpr(E->getLParenLoc(), |
| 4034 | move_arg(Inits), |
| 4035 | E->getRParenLoc()); |
| 4036 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | /// \brief Transform an address-of-label expression. |
| 4039 | /// |
| 4040 | /// By default, the transformation of an address-of-label expression always |
| 4041 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4042 | /// the corresponding label statement by semantic analysis. |
| 4043 | template<typename Derived> |
| 4044 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4045 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4046 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4047 | E->getLabel()); |
| 4048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
| 4050 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4051 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4052 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4053 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4054 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4055 | if (SubStmt.isInvalid()) |
| 4056 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4057 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4058 | if (!getDerived().AlwaysRebuild() && |
| 4059 | SubStmt.get() == E->getSubStmt()) |
| 4060 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4061 | |
| 4062 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4063 | move(SubStmt), |
| 4064 | E->getRParenLoc()); |
| 4065 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | template<typename Derived> |
| 4068 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4069 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | QualType T1, T2; |
| 4071 | { |
| 4072 | // FIXME: Source location isn't quite accurate. |
| 4073 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4074 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4075 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4076 | if (T1.isNull()) |
| 4077 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4080 | if (T2.isNull()) |
| 4081 | return SemaRef.ExprError(); |
| 4082 | } |
| 4083 | |
| 4084 | if (!getDerived().AlwaysRebuild() && |
| 4085 | T1 == E->getArgType1() && |
| 4086 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | return SemaRef.Owned(E->Retain()); |
| 4088 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4089 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4090 | T1, T2, E->getRParenLoc()); |
| 4091 | } |
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 | template<typename Derived> |
| 4094 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4095 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4096 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4097 | if (Cond.isInvalid()) |
| 4098 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4100 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4101 | if (LHS.isInvalid()) |
| 4102 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4103 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4105 | if (RHS.isInvalid()) |
| 4106 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | if (!getDerived().AlwaysRebuild() && |
| 4109 | Cond.get() == E->getCond() && |
| 4110 | LHS.get() == E->getLHS() && |
| 4111 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4112 | return SemaRef.Owned(E->Retain()); |
| 4113 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4115 | move(Cond), move(LHS), move(RHS), |
| 4116 | E->getRParenLoc()); |
| 4117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4118 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4119 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4121 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4122 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | template<typename Derived> |
| 4126 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4127 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4128 | switch (E->getOperator()) { |
| 4129 | case OO_New: |
| 4130 | case OO_Delete: |
| 4131 | case OO_Array_New: |
| 4132 | case OO_Array_Delete: |
| 4133 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4134 | return SemaRef.ExprError(); |
| 4135 | |
| 4136 | case OO_Call: { |
| 4137 | // This is a call to an object's operator(). |
| 4138 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4139 | |
| 4140 | // Transform the object itself. |
| 4141 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4142 | if (Object.isInvalid()) |
| 4143 | return SemaRef.ExprError(); |
| 4144 | |
| 4145 | // FIXME: Poor location information |
| 4146 | SourceLocation FakeLParenLoc |
| 4147 | = SemaRef.PP.getLocForEndOfToken( |
| 4148 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4149 | |
| 4150 | // Transform the call arguments. |
| 4151 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4152 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4153 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4154 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4155 | break; |
| 4156 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4157 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4158 | if (Arg.isInvalid()) |
| 4159 | return SemaRef.ExprError(); |
| 4160 | |
| 4161 | // FIXME: Poor source location information. |
| 4162 | SourceLocation FakeCommaLoc |
| 4163 | = SemaRef.PP.getLocForEndOfToken( |
| 4164 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4165 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4166 | Args.push_back(Arg.release()); |
| 4167 | } |
| 4168 | |
| 4169 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4170 | move_arg(Args), |
| 4171 | FakeCommaLocs.data(), |
| 4172 | E->getLocEnd()); |
| 4173 | } |
| 4174 | |
| 4175 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4176 | case OO_##Name: |
| 4177 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4178 | #include "clang/Basic/OperatorKinds.def" |
| 4179 | case OO_Subscript: |
| 4180 | // Handled below. |
| 4181 | break; |
| 4182 | |
| 4183 | case OO_Conditional: |
| 4184 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4185 | return SemaRef.ExprError(); |
| 4186 | |
| 4187 | case OO_None: |
| 4188 | case NUM_OVERLOADED_OPERATORS: |
| 4189 | llvm_unreachable("not an overloaded operator?"); |
| 4190 | return SemaRef.ExprError(); |
| 4191 | } |
| 4192 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4194 | if (Callee.isInvalid()) |
| 4195 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4197 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | if (First.isInvalid()) |
| 4199 | return SemaRef.ExprError(); |
| 4200 | |
| 4201 | OwningExprResult Second(SemaRef); |
| 4202 | if (E->getNumArgs() == 2) { |
| 4203 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4204 | if (Second.isInvalid()) |
| 4205 | return SemaRef.ExprError(); |
| 4206 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4207 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4208 | if (!getDerived().AlwaysRebuild() && |
| 4209 | Callee.get() == E->getCallee() && |
| 4210 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4211 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4212 | return SemaRef.Owned(E->Retain()); |
| 4213 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4215 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4217 | move(First), |
| 4218 | move(Second)); |
| 4219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4221 | template<typename Derived> |
| 4222 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4223 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4224 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4229 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | QualType ExplicitTy; |
| 4231 | { |
| 4232 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4234 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4235 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4238 | if (ExplicitTy.isNull()) |
| 4239 | return SemaRef.ExprError(); |
| 4240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4242 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4243 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4244 | if (SubExpr.isInvalid()) |
| 4245 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | if (!getDerived().AlwaysRebuild() && |
| 4248 | ExplicitTy == E->getTypeAsWritten() && |
| 4249 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | return SemaRef.Owned(E->Retain()); |
| 4251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4252 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4255 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4256 | SourceLocation FakeRParenLoc |
| 4257 | = SemaRef.PP.getLocForEndOfToken( |
| 4258 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4259 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4260 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4261 | FakeLAngleLoc, |
| 4262 | ExplicitTy, |
| 4263 | FakeRAngleLoc, |
| 4264 | FakeRAngleLoc, |
| 4265 | move(SubExpr), |
| 4266 | FakeRParenLoc); |
| 4267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | template<typename Derived> |
| 4270 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4271 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4272 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4273 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | |
| 4275 | template<typename Derived> |
| 4276 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4277 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4278 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4279 | } |
| 4280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | template<typename Derived> |
| 4282 | Sema::OwningExprResult |
| 4283 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4284 | CXXReinterpretCastExpr *E) { |
| 4285 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4286 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4287 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | template<typename Derived> |
| 4289 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4290 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4291 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4292 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4293 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4294 | template<typename Derived> |
| 4295 | Sema::OwningExprResult |
| 4296 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4297 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4298 | QualType ExplicitTy; |
| 4299 | { |
| 4300 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4301 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4302 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4303 | if (ExplicitTy.isNull()) |
| 4304 | return SemaRef.ExprError(); |
| 4305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4307 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4308 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | if (SubExpr.isInvalid()) |
| 4310 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | if (!getDerived().AlwaysRebuild() && |
| 4313 | ExplicitTy == E->getTypeAsWritten() && |
| 4314 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | return SemaRef.Owned(E->Retain()); |
| 4316 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4317 | // FIXME: The end of the type's source range is wrong |
| 4318 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4319 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4320 | ExplicitTy, |
| 4321 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4322 | move(SubExpr), |
| 4323 | E->getRParenLoc()); |
| 4324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | template<typename Derived> |
| 4327 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4328 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4329 | if (E->isTypeOperand()) { |
| 4330 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4331 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4332 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4333 | if (T.isNull()) |
| 4334 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | if (!getDerived().AlwaysRebuild() && |
| 4337 | T == E->getTypeOperand()) |
| 4338 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4341 | /*FIXME:*/E->getLocStart(), |
| 4342 | T, |
| 4343 | E->getLocEnd()); |
| 4344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4345 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4346 | // We don't know whether the expression is potentially evaluated until |
| 4347 | // after we perform semantic analysis, so the expression is potentially |
| 4348 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4352 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4353 | if (SubExpr.isInvalid()) |
| 4354 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | if (!getDerived().AlwaysRebuild() && |
| 4357 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | return SemaRef.Owned(E->Retain()); |
| 4359 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4360 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4361 | /*FIXME:*/E->getLocStart(), |
| 4362 | move(SubExpr), |
| 4363 | E->getLocEnd()); |
| 4364 | } |
| 4365 | |
| 4366 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4368 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | template<typename Derived> |
| 4373 | Sema::OwningExprResult |
| 4374 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4375 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4376 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | template<typename Derived> |
| 4380 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4381 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4383 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | QualType T = getDerived().TransformType(E->getType()); |
| 4385 | if (T.isNull()) |
| 4386 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4387 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | if (!getDerived().AlwaysRebuild() && |
| 4389 | T == E->getType()) |
| 4390 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4391 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4392 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | template<typename Derived> |
| 4396 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4397 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4399 | if (SubExpr.isInvalid()) |
| 4400 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | if (!getDerived().AlwaysRebuild() && |
| 4403 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | |
| 4406 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4407 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | template<typename Derived> |
| 4410 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4411 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4414 | if (!Param) |
| 4415 | return SemaRef.ExprError(); |
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 | if (getDerived().AlwaysRebuild() && |
| 4418 | Param == E->getParam()) |
| 4419 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame^] | 4421 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4422 | } |
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 | template<typename Derived> |
| 4425 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4426 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4428 | |
| 4429 | QualType T = getDerived().TransformType(E->getType()); |
| 4430 | if (T.isNull()) |
| 4431 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4432 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4433 | if (!getDerived().AlwaysRebuild() && |
| 4434 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | return SemaRef.Owned(E->Retain()); |
| 4436 | |
| 4437 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4439 | T, |
| 4440 | E->getRParenLoc()); |
| 4441 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4442 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | template<typename Derived> |
| 4444 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4445 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | // Transform the type that we're allocating |
| 4447 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4448 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4449 | if (AllocType.isNull()) |
| 4450 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | // Transform the size of the array we're allocating (if any). |
| 4453 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4454 | if (ArraySize.isInvalid()) |
| 4455 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4457 | // Transform the placement arguments (if any). |
| 4458 | bool ArgumentChanged = false; |
| 4459 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4460 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4461 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4462 | if (Arg.isInvalid()) |
| 4463 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4466 | PlacementArgs.push_back(Arg.take()); |
| 4467 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4468 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4469 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4471 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4472 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4473 | if (Arg.isInvalid()) |
| 4474 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4475 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4476 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4477 | ConstructorArgs.push_back(Arg.take()); |
| 4478 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4479 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4480 | if (!getDerived().AlwaysRebuild() && |
| 4481 | AllocType == E->getAllocatedType() && |
| 4482 | ArraySize.get() == E->getArraySize() && |
| 4483 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | return SemaRef.Owned(E->Retain()); |
| 4485 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4486 | if (!ArraySize.get()) { |
| 4487 | // If no array size was specified, but the new expression was |
| 4488 | // instantiated with an array type (e.g., "new T" where T is |
| 4489 | // instantiated with "int[4]"), extract the outer bound from the |
| 4490 | // array type as our array size. We do this with constant and |
| 4491 | // dependently-sized array types. |
| 4492 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4493 | if (!ArrayT) { |
| 4494 | // Do nothing |
| 4495 | } else if (const ConstantArrayType *ConsArrayT |
| 4496 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4497 | ArraySize |
| 4498 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4499 | ConsArrayT->getSize(), |
| 4500 | SemaRef.Context.getSizeType(), |
| 4501 | /*FIXME:*/E->getLocStart())); |
| 4502 | AllocType = ConsArrayT->getElementType(); |
| 4503 | } else if (const DependentSizedArrayType *DepArrayT |
| 4504 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4505 | if (DepArrayT->getSizeExpr()) { |
| 4506 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4507 | AllocType = DepArrayT->getElementType(); |
| 4508 | } |
| 4509 | } |
| 4510 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4512 | E->isGlobalNew(), |
| 4513 | /*FIXME:*/E->getLocStart(), |
| 4514 | move_arg(PlacementArgs), |
| 4515 | /*FIXME:*/E->getLocStart(), |
| 4516 | E->isParenTypeId(), |
| 4517 | AllocType, |
| 4518 | /*FIXME:*/E->getLocStart(), |
| 4519 | /*FIXME:*/SourceRange(), |
| 4520 | move(ArraySize), |
| 4521 | /*FIXME:*/E->getLocStart(), |
| 4522 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | template<typename Derived> |
| 4527 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4528 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4530 | if (Operand.isInvalid()) |
| 4531 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4533 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4534 | Operand.get() == E->getArgument()) |
| 4535 | return SemaRef.Owned(E->Retain()); |
| 4536 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4537 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4538 | E->isGlobalDelete(), |
| 4539 | E->isArrayForm(), |
| 4540 | move(Operand)); |
| 4541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | template<typename Derived> |
| 4544 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4545 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4546 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4547 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4548 | if (Base.isInvalid()) |
| 4549 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4551 | NestedNameSpecifier *Qualifier |
| 4552 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4553 | E->getQualifierRange()); |
| 4554 | if (E->getQualifier() && !Qualifier) |
| 4555 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4557 | QualType DestroyedType; |
| 4558 | { |
| 4559 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4560 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4561 | if (DestroyedType.isNull()) |
| 4562 | return SemaRef.ExprError(); |
| 4563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4565 | if (!getDerived().AlwaysRebuild() && |
| 4566 | Base.get() == E->getBase() && |
| 4567 | Qualifier == E->getQualifier() && |
| 4568 | DestroyedType == E->getDestroyedType()) |
| 4569 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4571 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4572 | E->getOperatorLoc(), |
| 4573 | E->isArrow(), |
| 4574 | E->getDestroyedTypeLoc(), |
| 4575 | DestroyedType, |
| 4576 | Qualifier, |
| 4577 | E->getQualifierRange()); |
| 4578 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4579 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4580 | template<typename Derived> |
| 4581 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4582 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4583 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4584 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4585 | |
| 4586 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4587 | Sema::LookupOrdinaryName); |
| 4588 | |
| 4589 | // Transform all the decls. |
| 4590 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4591 | E = Old->decls_end(); I != E; ++I) { |
| 4592 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4593 | if (!InstD) { |
| 4594 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4595 | // This can happen because of dependent hiding. |
| 4596 | if (isa<UsingShadowDecl>(*I)) |
| 4597 | continue; |
| 4598 | else |
| 4599 | return SemaRef.ExprError(); |
| 4600 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4601 | |
| 4602 | // Expand using declarations. |
| 4603 | if (isa<UsingDecl>(InstD)) { |
| 4604 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4605 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4606 | E = UD->shadow_end(); I != E; ++I) |
| 4607 | R.addDecl(*I); |
| 4608 | continue; |
| 4609 | } |
| 4610 | |
| 4611 | R.addDecl(InstD); |
| 4612 | } |
| 4613 | |
| 4614 | // Resolve a kind, but don't do any further analysis. If it's |
| 4615 | // ambiguous, the callee needs to deal with it. |
| 4616 | R.resolveKind(); |
| 4617 | |
| 4618 | // Rebuild the nested-name qualifier, if present. |
| 4619 | CXXScopeSpec SS; |
| 4620 | NestedNameSpecifier *Qualifier = 0; |
| 4621 | if (Old->getQualifier()) { |
| 4622 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4623 | Old->getQualifierRange()); |
| 4624 | if (!Qualifier) |
| 4625 | return SemaRef.ExprError(); |
| 4626 | |
| 4627 | SS.setScopeRep(Qualifier); |
| 4628 | SS.setRange(Old->getQualifierRange()); |
| 4629 | } |
| 4630 | |
| 4631 | // If we have no template arguments, it's a normal declaration name. |
| 4632 | if (!Old->hasExplicitTemplateArgs()) |
| 4633 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4634 | |
| 4635 | // If we have template arguments, rebuild them, then rebuild the |
| 4636 | // templateid expression. |
| 4637 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4638 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4639 | TemplateArgumentLoc Loc; |
| 4640 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4641 | return SemaRef.ExprError(); |
| 4642 | TransArgs.addArgument(Loc); |
| 4643 | } |
| 4644 | |
| 4645 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4646 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4648 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4649 | template<typename Derived> |
| 4650 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4651 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4654 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4655 | if (T.isNull()) |
| 4656 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4658 | if (!getDerived().AlwaysRebuild() && |
| 4659 | T == E->getQueriedType()) |
| 4660 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4662 | // FIXME: Bad location information |
| 4663 | SourceLocation FakeLParenLoc |
| 4664 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4665 | |
| 4666 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4667 | E->getLocStart(), |
| 4668 | /*FIXME:*/FakeLParenLoc, |
| 4669 | T, |
| 4670 | E->getLocEnd()); |
| 4671 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4673 | template<typename Derived> |
| 4674 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4675 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4676 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4678 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4679 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | if (!NNS) |
| 4681 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | |
| 4683 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4684 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4685 | if (!Name) |
| 4686 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4687 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4688 | if (!E->hasExplicitTemplateArgs()) { |
| 4689 | if (!getDerived().AlwaysRebuild() && |
| 4690 | NNS == E->getQualifier() && |
| 4691 | Name == E->getDeclName()) |
| 4692 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4693 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4694 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4695 | E->getQualifierRange(), |
| 4696 | Name, E->getLocation(), |
| 4697 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4698 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4699 | |
| 4700 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4701 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4702 | TemplateArgumentLoc Loc; |
| 4703 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4704 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4705 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4708 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4709 | E->getQualifierRange(), |
| 4710 | Name, E->getLocation(), |
| 4711 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | template<typename Derived> |
| 4715 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4716 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4717 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4718 | |
| 4719 | QualType T = getDerived().TransformType(E->getType()); |
| 4720 | if (T.isNull()) |
| 4721 | return SemaRef.ExprError(); |
| 4722 | |
| 4723 | CXXConstructorDecl *Constructor |
| 4724 | = cast_or_null<CXXConstructorDecl>( |
| 4725 | getDerived().TransformDecl(E->getConstructor())); |
| 4726 | if (!Constructor) |
| 4727 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4728 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | bool ArgumentChanged = false; |
| 4730 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4732 | ArgEnd = E->arg_end(); |
| 4733 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4734 | if (getDerived().DropCallArgument(*Arg)) { |
| 4735 | ArgumentChanged = true; |
| 4736 | break; |
| 4737 | } |
| 4738 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4740 | if (TransArg.isInvalid()) |
| 4741 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4742 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4743 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4744 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4745 | } |
| 4746 | |
| 4747 | if (!getDerived().AlwaysRebuild() && |
| 4748 | T == E->getType() && |
| 4749 | Constructor == E->getConstructor() && |
| 4750 | !ArgumentChanged) |
| 4751 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4752 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4753 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4754 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | move_arg(Args)); |
| 4756 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4757 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4758 | /// \brief Transform a C++ temporary-binding expression. |
| 4759 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | /// The transformation of a temporary-binding expression always attempts to |
| 4761 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | /// subexpression itself did not change, because the temporary variable itself |
| 4763 | /// must be unique. |
| 4764 | template<typename Derived> |
| 4765 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4766 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4768 | if (SubExpr.isInvalid()) |
| 4769 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4771 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4772 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
| 4774 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4775 | /// be destroyed after the expression is evaluated. |
| 4776 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4777 | /// The transformation of a full expression always attempts to build a new |
| 4778 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | /// subexpression itself did not change, because it will need to capture the |
| 4780 | /// the new temporary variables introduced in the subexpression. |
| 4781 | template<typename Derived> |
| 4782 | Sema::OwningExprResult |
| 4783 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4784 | CXXExprWithTemporaries *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4785 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4786 | if (SubExpr.isInvalid()) |
| 4787 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | return SemaRef.Owned( |
Anders Carlsson | 6e997b2 | 2009-12-15 20:51:39 +0000 | [diff] [blame] | 4790 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4793 | template<typename Derived> |
| 4794 | Sema::OwningExprResult |
| 4795 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4796 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4797 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4798 | QualType T = getDerived().TransformType(E->getType()); |
| 4799 | if (T.isNull()) |
| 4800 | return SemaRef.ExprError(); |
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 | CXXConstructorDecl *Constructor |
| 4803 | = cast_or_null<CXXConstructorDecl>( |
| 4804 | getDerived().TransformDecl(E->getConstructor())); |
| 4805 | if (!Constructor) |
| 4806 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4807 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4808 | bool ArgumentChanged = false; |
| 4809 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4810 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4811 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4812 | ArgEnd = E->arg_end(); |
| 4813 | Arg != ArgEnd; ++Arg) { |
| 4814 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4815 | if (TransArg.isInvalid()) |
| 4816 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4818 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4819 | Args.push_back((Expr *)TransArg.release()); |
| 4820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | if (!getDerived().AlwaysRebuild() && |
| 4823 | T == E->getType() && |
| 4824 | Constructor == E->getConstructor() && |
| 4825 | !ArgumentChanged) |
| 4826 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4828 | // FIXME: Bogus location information |
| 4829 | SourceLocation CommaLoc; |
| 4830 | if (Args.size() > 1) { |
| 4831 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4833 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4834 | } |
| 4835 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4836 | T, |
| 4837 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4838 | move_arg(Args), |
| 4839 | &CommaLoc, |
| 4840 | E->getLocEnd()); |
| 4841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4843 | template<typename Derived> |
| 4844 | Sema::OwningExprResult |
| 4845 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4846 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4847 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4848 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4849 | if (T.isNull()) |
| 4850 | return SemaRef.ExprError(); |
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 | bool ArgumentChanged = false; |
| 4853 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4854 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4855 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4856 | ArgEnd = E->arg_end(); |
| 4857 | Arg != ArgEnd; ++Arg) { |
| 4858 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4859 | if (TransArg.isInvalid()) |
| 4860 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4863 | FakeCommaLocs.push_back( |
| 4864 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4865 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | if (!getDerived().AlwaysRebuild() && |
| 4869 | T == E->getTypeAsWritten() && |
| 4870 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4871 | return SemaRef.Owned(E->Retain()); |
| 4872 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4873 | // FIXME: we're faking the locations of the commas |
| 4874 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4875 | T, |
| 4876 | E->getLParenLoc(), |
| 4877 | move_arg(Args), |
| 4878 | FakeCommaLocs.data(), |
| 4879 | E->getRParenLoc()); |
| 4880 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4882 | template<typename Derived> |
| 4883 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4884 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4885 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4886 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4887 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4888 | Expr *OldBase; |
| 4889 | QualType BaseType; |
| 4890 | QualType ObjectType; |
| 4891 | if (!E->isImplicitAccess()) { |
| 4892 | OldBase = E->getBase(); |
| 4893 | Base = getDerived().TransformExpr(OldBase); |
| 4894 | if (Base.isInvalid()) |
| 4895 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4897 | // Start the member reference and compute the object's type. |
| 4898 | Sema::TypeTy *ObjectTy = 0; |
| 4899 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4900 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4901 | E->isArrow()? tok::arrow : tok::period, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4902 | ObjectTy); |
| 4903 | if (Base.isInvalid()) |
| 4904 | return SemaRef.ExprError(); |
| 4905 | |
| 4906 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 4907 | BaseType = ((Expr*) Base.get())->getType(); |
| 4908 | } else { |
| 4909 | OldBase = 0; |
| 4910 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 4911 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 4912 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4913 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4914 | // Transform the first part of the nested-name-specifier that qualifies |
| 4915 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4916 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4917 | = getDerived().TransformFirstQualifierInScope( |
| 4918 | E->getFirstQualifierFoundInScope(), |
| 4919 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4920 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4921 | NestedNameSpecifier *Qualifier = 0; |
| 4922 | if (E->getQualifier()) { |
| 4923 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4924 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4925 | ObjectType, |
| 4926 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4927 | if (!Qualifier) |
| 4928 | return SemaRef.ExprError(); |
| 4929 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4930 | |
| 4931 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4932 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4933 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4934 | if (!Name) |
| 4935 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4936 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4937 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4938 | // This is a reference to a member without an explicitly-specified |
| 4939 | // template argument list. Optimize for this common case. |
| 4940 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4941 | Base.get() == OldBase && |
| 4942 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4943 | Qualifier == E->getQualifier() && |
| 4944 | Name == E->getMember() && |
| 4945 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4946 | return SemaRef.Owned(E->Retain()); |
| 4947 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4948 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4949 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4950 | E->isArrow(), |
| 4951 | E->getOperatorLoc(), |
| 4952 | Qualifier, |
| 4953 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4954 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4955 | Name, |
| 4956 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4957 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4960 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4961 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4962 | TemplateArgumentLoc Loc; |
| 4963 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4964 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4965 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4966 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4968 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4969 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4970 | E->isArrow(), |
| 4971 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4972 | Qualifier, |
| 4973 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4974 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4975 | Name, |
| 4976 | E->getMemberLoc(), |
| 4977 | &TransArgs); |
| 4978 | } |
| 4979 | |
| 4980 | template<typename Derived> |
| 4981 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4982 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4983 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4984 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4985 | QualType BaseType; |
| 4986 | if (!Old->isImplicitAccess()) { |
| 4987 | Base = getDerived().TransformExpr(Old->getBase()); |
| 4988 | if (Base.isInvalid()) |
| 4989 | return SemaRef.ExprError(); |
| 4990 | BaseType = ((Expr*) Base.get())->getType(); |
| 4991 | } else { |
| 4992 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 4993 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4994 | |
| 4995 | NestedNameSpecifier *Qualifier = 0; |
| 4996 | if (Old->getQualifier()) { |
| 4997 | Qualifier |
| 4998 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4999 | Old->getQualifierRange()); |
| 5000 | if (Qualifier == 0) |
| 5001 | return SemaRef.ExprError(); |
| 5002 | } |
| 5003 | |
| 5004 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5005 | Sema::LookupOrdinaryName); |
| 5006 | |
| 5007 | // Transform all the decls. |
| 5008 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5009 | E = Old->decls_end(); I != E; ++I) { |
| 5010 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5011 | if (!InstD) { |
| 5012 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5013 | // This can happen because of dependent hiding. |
| 5014 | if (isa<UsingShadowDecl>(*I)) |
| 5015 | continue; |
| 5016 | else |
| 5017 | return SemaRef.ExprError(); |
| 5018 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5019 | |
| 5020 | // Expand using declarations. |
| 5021 | if (isa<UsingDecl>(InstD)) { |
| 5022 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5023 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5024 | E = UD->shadow_end(); I != E; ++I) |
| 5025 | R.addDecl(*I); |
| 5026 | continue; |
| 5027 | } |
| 5028 | |
| 5029 | R.addDecl(InstD); |
| 5030 | } |
| 5031 | |
| 5032 | R.resolveKind(); |
| 5033 | |
| 5034 | TemplateArgumentListInfo TransArgs; |
| 5035 | if (Old->hasExplicitTemplateArgs()) { |
| 5036 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5037 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5038 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5039 | TemplateArgumentLoc Loc; |
| 5040 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5041 | Loc)) |
| 5042 | return SemaRef.ExprError(); |
| 5043 | TransArgs.addArgument(Loc); |
| 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5048 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5049 | Old->getOperatorLoc(), |
| 5050 | Old->isArrow(), |
| 5051 | Qualifier, |
| 5052 | Old->getQualifierRange(), |
| 5053 | R, |
| 5054 | (Old->hasExplicitTemplateArgs() |
| 5055 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | template<typename Derived> |
| 5059 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5060 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5061 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | template<typename Derived> |
| 5065 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5066 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | // FIXME: poor source location |
| 5068 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5069 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5070 | if (EncodedType.isNull()) |
| 5071 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5072 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5073 | if (!getDerived().AlwaysRebuild() && |
| 5074 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5075 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | |
| 5077 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5078 | EncodedType, |
| 5079 | E->getRParenLoc()); |
| 5080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5082 | template<typename Derived> |
| 5083 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5084 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5085 | // FIXME: Implement this! |
| 5086 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5090 | template<typename Derived> |
| 5091 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5092 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5093 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5096 | template<typename Derived> |
| 5097 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5098 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5099 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | = cast_or_null<ObjCProtocolDecl>( |
| 5101 | getDerived().TransformDecl(E->getProtocol())); |
| 5102 | if (!Protocol) |
| 5103 | return SemaRef.ExprError(); |
| 5104 | |
| 5105 | if (!getDerived().AlwaysRebuild() && |
| 5106 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5107 | return SemaRef.Owned(E->Retain()); |
| 5108 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5109 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5110 | E->getAtLoc(), |
| 5111 | /*FIXME:*/E->getAtLoc(), |
| 5112 | /*FIXME:*/E->getAtLoc(), |
| 5113 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5117 | template<typename Derived> |
| 5118 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5119 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5120 | // FIXME: Implement this! |
| 5121 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5122 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5125 | template<typename Derived> |
| 5126 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5127 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5128 | // FIXME: Implement this! |
| 5129 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5130 | return SemaRef.Owned(E->Retain()); |
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 |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5135 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5136 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5137 | // FIXME: Implement this! |
| 5138 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5139 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5142 | template<typename Derived> |
| 5143 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5144 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5145 | // FIXME: Implement this! |
| 5146 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | } |
| 5149 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | template<typename Derived> |
| 5151 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5152 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *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>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5161 | bool ArgumentChanged = false; |
| 5162 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5163 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5164 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5165 | if (SubExpr.isInvalid()) |
| 5166 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5169 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5170 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | if (!getDerived().AlwaysRebuild() && |
| 5173 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5174 | return SemaRef.Owned(E->Retain()); |
| 5175 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5176 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5177 | move_arg(SubExprs), |
| 5178 | E->getRParenLoc()); |
| 5179 | } |
| 5180 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | template<typename Derived> |
| 5182 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5183 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | // FIXME: Implement this! |
| 5185 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5186 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5187 | } |
| 5188 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | template<typename Derived> |
| 5190 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5191 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5192 | // FIXME: Implement this! |
| 5193 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5197 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5198 | // Type reconstruction |
| 5199 | //===----------------------------------------------------------------------===// |
| 5200 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5201 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5202 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5203 | SourceLocation Star) { |
| 5204 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5205 | getDerived().getBaseEntity()); |
| 5206 | } |
| 5207 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5209 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5210 | SourceLocation Star) { |
| 5211 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5212 | getDerived().getBaseEntity()); |
| 5213 | } |
| 5214 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5215 | template<typename Derived> |
| 5216 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5217 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5218 | bool WrittenAsLValue, |
| 5219 | SourceLocation Sigil) { |
| 5220 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5221 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5225 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5226 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5227 | QualType ClassType, |
| 5228 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5229 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5230 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5235 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5236 | SourceLocation Sigil) { |
| 5237 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5238 | getDerived().getBaseEntity()); |
| 5239 | } |
| 5240 | |
| 5241 | template<typename Derived> |
| 5242 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5243 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5244 | ArrayType::ArraySizeModifier SizeMod, |
| 5245 | const llvm::APInt *Size, |
| 5246 | Expr *SizeExpr, |
| 5247 | unsigned IndexTypeQuals, |
| 5248 | SourceRange BracketsRange) { |
| 5249 | if (SizeExpr || !Size) |
| 5250 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5251 | IndexTypeQuals, BracketsRange, |
| 5252 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5253 | |
| 5254 | QualType Types[] = { |
| 5255 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5256 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5257 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5258 | }; |
| 5259 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5260 | QualType SizeType; |
| 5261 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5262 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5263 | SizeType = Types[I]; |
| 5264 | break; |
| 5265 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5267 | if (SizeType.isNull()) |
| 5268 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5269 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5270 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5272 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5273 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5274 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5275 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5276 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | QualType |
| 5278 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5279 | ArrayType::ArraySizeModifier SizeMod, |
| 5280 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5281 | unsigned IndexTypeQuals, |
| 5282 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5283 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5284 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5288 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5290 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5291 | unsigned IndexTypeQuals, |
| 5292 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5293 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5294 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5295 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5296 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5297 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5298 | QualType |
| 5299 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5300 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5301 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5302 | unsigned IndexTypeQuals, |
| 5303 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5305 | SizeExpr.takeAs<Expr>(), |
| 5306 | IndexTypeQuals, BracketsRange); |
| 5307 | } |
| 5308 | |
| 5309 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5310 | QualType |
| 5311 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5312 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5313 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5314 | unsigned IndexTypeQuals, |
| 5315 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5316 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5317 | SizeExpr.takeAs<Expr>(), |
| 5318 | IndexTypeQuals, BracketsRange); |
| 5319 | } |
| 5320 | |
| 5321 | template<typename Derived> |
| 5322 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5323 | unsigned NumElements) { |
| 5324 | // FIXME: semantic checking! |
| 5325 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5327 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5328 | template<typename Derived> |
| 5329 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5330 | unsigned NumElements, |
| 5331 | SourceLocation AttributeLoc) { |
| 5332 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5333 | NumElements, true); |
| 5334 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5336 | AttributeLoc); |
| 5337 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5338 | AttributeLoc); |
| 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> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5342 | QualType |
| 5343 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5344 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5345 | SourceLocation AttributeLoc) { |
| 5346 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5348 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5349 | template<typename Derived> |
| 5350 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5351 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5352 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5353 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5354 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5355 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5356 | Quals, |
| 5357 | getDerived().getBaseLocation(), |
| 5358 | getDerived().getBaseEntity()); |
| 5359 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5361 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5362 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5363 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5364 | } |
| 5365 | |
| 5366 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5367 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5368 | assert(D && "no decl found"); |
| 5369 | if (D->isInvalidDecl()) return QualType(); |
| 5370 | |
| 5371 | TypeDecl *Ty; |
| 5372 | if (isa<UsingDecl>(D)) { |
| 5373 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5374 | assert(Using->isTypeName() && |
| 5375 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5376 | |
| 5377 | // A valid resolved using typename decl points to exactly one type decl. |
| 5378 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5379 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5380 | |
| 5381 | } else { |
| 5382 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5383 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5384 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5385 | } |
| 5386 | |
| 5387 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5388 | } |
| 5389 | |
| 5390 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5391 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5392 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5393 | } |
| 5394 | |
| 5395 | template<typename Derived> |
| 5396 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5397 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5398 | } |
| 5399 | |
| 5400 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5401 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5402 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5403 | } |
| 5404 | |
| 5405 | template<typename Derived> |
| 5406 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5407 | TemplateName Template, |
| 5408 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5409 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5410 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5413 | template<typename Derived> |
| 5414 | NestedNameSpecifier * |
| 5415 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5416 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5417 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5418 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5419 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5420 | CXXScopeSpec SS; |
| 5421 | // FIXME: The source location information is all wrong. |
| 5422 | SS.setRange(Range); |
| 5423 | SS.setScopeRep(Prefix); |
| 5424 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5425 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5426 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5427 | ObjectType, |
| 5428 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5429 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
| 5432 | template<typename Derived> |
| 5433 | NestedNameSpecifier * |
| 5434 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5435 | SourceRange Range, |
| 5436 | NamespaceDecl *NS) { |
| 5437 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5438 | } |
| 5439 | |
| 5440 | template<typename Derived> |
| 5441 | NestedNameSpecifier * |
| 5442 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5443 | SourceRange Range, |
| 5444 | bool TemplateKW, |
| 5445 | QualType T) { |
| 5446 | if (T->isDependentType() || T->isRecordType() || |
| 5447 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5448 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5449 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5450 | T.getTypePtr()); |
| 5451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5453 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5454 | return 0; |
| 5455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5457 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5458 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5459 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5460 | bool TemplateKW, |
| 5461 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5463 | Template); |
| 5464 | } |
| 5465 | |
| 5466 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5467 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5468 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5469 | const IdentifierInfo &II, |
| 5470 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5471 | CXXScopeSpec SS; |
| 5472 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5473 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5474 | UnqualifiedId Name; |
| 5475 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5476 | return getSema().ActOnDependentTemplateName( |
| 5477 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5478 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5479 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5480 | ObjectType.getAsOpaquePtr(), |
| 5481 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5482 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5485 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5486 | TemplateName |
| 5487 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5488 | OverloadedOperatorKind Operator, |
| 5489 | QualType ObjectType) { |
| 5490 | CXXScopeSpec SS; |
| 5491 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5492 | SS.setScopeRep(Qualifier); |
| 5493 | UnqualifiedId Name; |
| 5494 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5495 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5496 | Operator, SymbolLocations); |
| 5497 | return getSema().ActOnDependentTemplateName( |
| 5498 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5499 | SS, |
| 5500 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5501 | ObjectType.getAsOpaquePtr(), |
| 5502 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5503 | .template getAsVal<TemplateName>(); |
| 5504 | } |
| 5505 | |
| 5506 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5507 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5508 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5509 | SourceLocation OpLoc, |
| 5510 | ExprArg Callee, |
| 5511 | ExprArg First, |
| 5512 | ExprArg Second) { |
| 5513 | Expr *FirstExpr = (Expr *)First.get(); |
| 5514 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5515 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5516 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5518 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5519 | if (Op == OO_Subscript) { |
| 5520 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5521 | !SecondExpr->getType()->isOverloadableType()) |
| 5522 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5523 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5524 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5525 | } else if (Op == OO_Arrow) { |
| 5526 | // -> is never a builtin operation. |
| 5527 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5528 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5529 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5530 | // The argument is not of overloadable type, so try to create a |
| 5531 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5532 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5533 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5534 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5535 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5536 | } |
| 5537 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5538 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5539 | !SecondExpr->getType()->isOverloadableType()) { |
| 5540 | // Neither of the arguments is an overloadable type, so try to |
| 5541 | // create a built-in binary operation. |
| 5542 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5543 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5544 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5545 | if (Result.isInvalid()) |
| 5546 | return SemaRef.ExprError(); |
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 | First.release(); |
| 5549 | Second.release(); |
| 5550 | return move(Result); |
| 5551 | } |
| 5552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
| 5554 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5555 | // used during overload resolution. |
| 5556 | Sema::FunctionSet Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5557 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5558 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5559 | assert(ULE->requiresADL()); |
| 5560 | |
| 5561 | // FIXME: Do we have to check |
| 5562 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5563 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5564 | E = ULE->decls_end(); I != E; ++I) |
| 5565 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5566 | } else { |
| 5567 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5568 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5569 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5570 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5571 | // Add any functions found via argument-dependent lookup. |
| 5572 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5573 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | DeclarationName OpName |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5575 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | c057f42 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5576 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5577 | Functions); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5579 | // Create the overloaded operator invocation for unary operators. |
| 5580 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5581 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5582 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5583 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5585 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5586 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5587 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5588 | OpLoc, |
| 5589 | move(First), |
| 5590 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5591 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5592 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5594 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5595 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5596 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5597 | if (Result.isInvalid()) |
| 5598 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5600 | First.release(); |
| 5601 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5602 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5603 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5604 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5605 | } // end namespace clang |
| 5606 | |
| 5607 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |