John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 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 | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 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 | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 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 | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 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 | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | b98b199 | 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 | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | 577f75a | 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 | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 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 | 577f75a | 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 | |
| 175 | /// \brief Transforms the given type into another type. |
| 176 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 177 | /// By default, this routine transforms a type by creating a |
| 178 | /// DeclaratorInfo for it and delegating to the appropriate |
| 179 | /// function. This is expensive, but we don't mind, because |
| 180 | /// this method is deprecated anyway; all users should be |
| 181 | /// switched to storing DeclaratorInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 182 | /// |
| 183 | /// \returns the transformed type. |
| 184 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 186 | /// \brief Transforms the given type-with-location into a new |
| 187 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 188 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// By default, this routine transforms a type by delegating to the |
| 190 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 191 | /// may override this function (to take over all type |
| 192 | /// transformations) or some set of the TransformXXXType functions |
| 193 | /// to alter the transformation. |
| 194 | DeclaratorInfo *TransformType(DeclaratorInfo *DI); |
| 195 | |
| 196 | /// \brief Transform the given type-with-location into a new |
| 197 | /// type, collecting location information in the given builder |
| 198 | /// as necessary. |
| 199 | /// |
| 200 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 202 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 203 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 205 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 206 | /// statement or the TransformExpr() function to transform an expression. |
| 207 | /// Subclasses may override this function to transform statements using some |
| 208 | /// other mechanism. |
| 209 | /// |
| 210 | /// \returns the transformed statement. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 211 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 213 | /// \brief Transform the given expression. |
| 214 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 215 | /// By default, this routine transforms an expression by delegating to the |
| 216 | /// appropriate TransformXXXExpr function to build a new expression. |
| 217 | /// Subclasses may override this function to transform expressions using some |
| 218 | /// other mechanism. |
| 219 | /// |
| 220 | /// \returns the transformed expression. |
| 221 | OwningExprResult TransformExpr(Expr *E) { |
| 222 | return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false); |
| 223 | } |
| 224 | |
| 225 | /// \brief Transform the given expression. |
| 226 | /// |
| 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
| 233 | OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
| 240 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
| 246 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 248 | /// \brief Transform the given declaration, which was the first part of a |
| 249 | /// nested-name-specifier in a member access expression. |
| 250 | /// |
| 251 | /// This specific declaration transformation only applies to the first |
| 252 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 253 | /// the \c T in \c x->T::member |
| 254 | /// |
| 255 | /// By default, invokes TransformDecl() to transform the declaration. |
| 256 | /// Subclasses may override this function to provide alternate behavior. |
| 257 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 258 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 259 | } |
| 260 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 261 | /// \brief Transform the given nested-name-specifier. |
| 262 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 264 | /// nested-name-specifier. Subclasses may override this function to provide |
| 265 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 266 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 267 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 268 | QualType ObjectType = QualType(), |
| 269 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 271 | /// \brief Transform the given declaration name. |
| 272 | /// |
| 273 | /// By default, transforms the types of conversion function, constructor, |
| 274 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 275 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 276 | /// override this function to provide alternate behavior. |
| 277 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 278 | SourceLocation Loc, |
| 279 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 281 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 286 | TemplateName TransformTemplateName(TemplateName Name, |
| 287 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// \brief Transform the given template argument. |
| 290 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | /// By default, this operation transforms the type, expression, or |
| 292 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 293 | /// new template argument from the transformed result. Subclasses may |
| 294 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 295 | /// |
| 296 | /// Returns true if there was an error. |
| 297 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 298 | TemplateArgumentLoc &Output); |
| 299 | |
| 300 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 301 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 302 | TemplateArgumentLoc &ArgLoc); |
| 303 | |
| 304 | /// \brief Fakes up a DeclaratorInfo for a type. |
| 305 | DeclaratorInfo *InventDeclaratorInfo(QualType T) { |
| 306 | return SemaRef.Context.getTrivialDeclaratorInfo(T, |
| 307 | getDerived().getBaseLocation()); |
| 308 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 310 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 311 | #define TYPELOC(CLASS, PARENT) \ |
| 312 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 313 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 314 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 315 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 316 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 317 | QualType |
| 318 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 319 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 320 | |
| 321 | QualType |
| 322 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 323 | TemplateSpecializationTypeLoc TL, |
| 324 | QualType ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 328 | #define STMT(Node, Parent) \ |
| 329 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 331 | OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 332 | #define ABSTRACT_EXPR(Node, Parent) |
| 333 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 335 | /// \brief Build a new pointer type given its pointee type. |
| 336 | /// |
| 337 | /// By default, performs semantic analysis when building the pointer type. |
| 338 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 339 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 340 | |
| 341 | /// \brief Build a new block pointer type given its pointee type. |
| 342 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 348 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 349 | /// By default, performs semantic analysis when building the |
| 350 | /// reference type. Subclasses may override this routine to provide |
| 351 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 352 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 353 | /// \param LValue whether the type was written with an lvalue sigil |
| 354 | /// or an rvalue sigil. |
| 355 | QualType RebuildReferenceType(QualType ReferentType, |
| 356 | bool LValue, |
| 357 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// \brief Build a new member pointer type given the pointee type and the |
| 360 | /// class type it refers into. |
| 361 | /// |
| 362 | /// By default, performs semantic analysis when building the member pointer |
| 363 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 365 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 367 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 369 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 370 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 371 | /// \brief Build a new array type given the element type, size |
| 372 | /// modifier, size of the array (if known), size expression, and index type |
| 373 | /// qualifiers. |
| 374 | /// |
| 375 | /// By default, performs semantic analysis when building the array type. |
| 376 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 378 | QualType RebuildArrayType(QualType ElementType, |
| 379 | ArrayType::ArraySizeModifier SizeMod, |
| 380 | const llvm::APInt *Size, |
| 381 | Expr *SizeExpr, |
| 382 | unsigned IndexTypeQuals, |
| 383 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | /// \brief Build a new constant array type given the element type, size |
| 386 | /// modifier, (known) size of the array, and index type qualifiers. |
| 387 | /// |
| 388 | /// By default, performs semantic analysis when building the array type. |
| 389 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 391 | ArrayType::ArraySizeModifier SizeMod, |
| 392 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new incomplete array type given the element type, size |
| 397 | /// modifier, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 403 | unsigned IndexTypeQuals, |
| 404 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// size modifier, size expression, and index type qualifiers. |
| 408 | /// |
| 409 | /// By default, performs semantic analysis when building the array type. |
| 410 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 413 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
| 416 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
| 428 | /// \brief Build a new vector type given the element type and |
| 429 | /// number of elements. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the vector type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
| 433 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 435 | /// \brief Build a new extended vector type given the element type and |
| 436 | /// number of elements. |
| 437 | /// |
| 438 | /// By default, performs semantic analysis when building the vector type. |
| 439 | /// Subclasses may override this routine to provide different behavior. |
| 440 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 441 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
| 443 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 444 | /// given the element type and number of elements. |
| 445 | /// |
| 446 | /// By default, performs semantic analysis when building the vector type. |
| 447 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 449 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 451 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 452 | /// \brief Build a new function type. |
| 453 | /// |
| 454 | /// By default, performs semantic analysis when building the function type. |
| 455 | /// Subclasses may override this routine to provide different behavior. |
| 456 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 458 | unsigned NumParamTypes, |
| 459 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 461 | /// \brief Build a new unprototyped function type. |
| 462 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 463 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 464 | /// \brief Build a new typedef type. |
| 465 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 466 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 467 | } |
| 468 | |
| 469 | /// \brief Build a new class/struct/union type. |
| 470 | QualType RebuildRecordType(RecordDecl *Record) { |
| 471 | return SemaRef.Context.getTypeDeclType(Record); |
| 472 | } |
| 473 | |
| 474 | /// \brief Build a new Enum type. |
| 475 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 476 | return SemaRef.Context.getTypeDeclType(Enum); |
| 477 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 478 | |
| 479 | /// \brief Build a new elaborated type. |
| 480 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 481 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 483 | |
| 484 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 485 | /// |
| 486 | /// By default, performs semantic analysis when building the typeof type. |
| 487 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 488 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 489 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 491 | /// |
| 492 | /// By default, builds a new TypeOfType with the given underlying type. |
| 493 | QualType RebuildTypeOfType(QualType Underlying); |
| 494 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 496 | /// |
| 497 | /// By default, performs semantic analysis when building the decltype type. |
| 498 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 499 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 501 | /// \brief Build a new template specialization type. |
| 502 | /// |
| 503 | /// By default, performs semantic analysis when building the template |
| 504 | /// specialization type. Subclasses may override this routine to provide |
| 505 | /// different behavior. |
| 506 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 507 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 508 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 510 | /// \brief Build a new qualified name type. |
| 511 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | /// By default, builds a new QualifiedNameType type from the |
| 513 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 514 | /// this routine to provide different behavior. |
| 515 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 516 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 518 | |
| 519 | /// \brief Build a new typename type that refers to a template-id. |
| 520 | /// |
| 521 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 523 | /// different behavior. |
| 524 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 525 | if (NNS->isDependent()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 527 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | |
| 532 | /// \brief Build a new typename type that refers to an identifier. |
| 533 | /// |
| 534 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 536 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 538 | const IdentifierInfo *Id, |
| 539 | SourceRange SR) { |
| 540 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 541 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 543 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 544 | /// identifier that names the next step in the nested-name-specifier. |
| 545 | /// |
| 546 | /// By default, performs semantic analysis when building the new |
| 547 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 548 | /// different behavior. |
| 549 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 550 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 551 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 552 | QualType ObjectType, |
| 553 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 554 | |
| 555 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 556 | /// namespace named in the next step in the nested-name-specifier. |
| 557 | /// |
| 558 | /// By default, performs semantic analysis when building the new |
| 559 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 560 | /// different behavior. |
| 561 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 562 | SourceRange Range, |
| 563 | NamespaceDecl *NS); |
| 564 | |
| 565 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 566 | /// type named in the next step in the nested-name-specifier. |
| 567 | /// |
| 568 | /// By default, performs semantic analysis when building the new |
| 569 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 570 | /// different behavior. |
| 571 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 572 | SourceRange Range, |
| 573 | bool TemplateKW, |
| 574 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 575 | |
| 576 | /// \brief Build a new template name given a nested name specifier, a flag |
| 577 | /// indicating whether the "template" keyword was provided, and the template |
| 578 | /// that the template name refers to. |
| 579 | /// |
| 580 | /// By default, builds the new template name directly. Subclasses may override |
| 581 | /// this routine to provide different behavior. |
| 582 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 583 | bool TemplateKW, |
| 584 | TemplateDecl *Template); |
| 585 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 586 | /// \brief Build a new template name given a nested name specifier and the |
| 587 | /// name that is referred to as a template. |
| 588 | /// |
| 589 | /// By default, performs semantic analysis to determine whether the name can |
| 590 | /// be resolved to a specific template, then builds the appropriate kind of |
| 591 | /// template name. Subclasses may override this routine to provide different |
| 592 | /// behavior. |
| 593 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 594 | const IdentifierInfo &II, |
| 595 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 597 | /// \brief Build a new template name given a nested name specifier and the |
| 598 | /// overloaded operator name that is referred to as a template. |
| 599 | /// |
| 600 | /// By default, performs semantic analysis to determine whether the name can |
| 601 | /// be resolved to a specific template, then builds the appropriate kind of |
| 602 | /// template name. Subclasses may override this routine to provide different |
| 603 | /// behavior. |
| 604 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 605 | OverloadedOperatorKind Operator, |
| 606 | QualType ObjectType); |
| 607 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 608 | /// \brief Build a new compound statement. |
| 609 | /// |
| 610 | /// By default, performs semantic analysis to build the new statement. |
| 611 | /// Subclasses may override this routine to provide different behavior. |
| 612 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 613 | MultiStmtArg Statements, |
| 614 | SourceLocation RBraceLoc, |
| 615 | bool IsStmtExpr) { |
| 616 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 617 | IsStmtExpr); |
| 618 | } |
| 619 | |
| 620 | /// \brief Build a new case statement. |
| 621 | /// |
| 622 | /// By default, performs semantic analysis to build the new statement. |
| 623 | /// Subclasses may override this routine to provide different behavior. |
| 624 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 625 | ExprArg LHS, |
| 626 | SourceLocation EllipsisLoc, |
| 627 | ExprArg RHS, |
| 628 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 629 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 630 | ColonLoc); |
| 631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 633 | /// \brief Attach the body to a new case statement. |
| 634 | /// |
| 635 | /// By default, performs semantic analysis to build the new statement. |
| 636 | /// Subclasses may override this routine to provide different behavior. |
| 637 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 638 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 639 | return move(S); |
| 640 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 642 | /// \brief Build a new default statement. |
| 643 | /// |
| 644 | /// By default, performs semantic analysis to build the new statement. |
| 645 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 647 | SourceLocation ColonLoc, |
| 648 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 650 | /*CurScope=*/0); |
| 651 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 653 | /// \brief Build a new label statement. |
| 654 | /// |
| 655 | /// By default, performs semantic analysis to build the new statement. |
| 656 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 658 | IdentifierInfo *Id, |
| 659 | SourceLocation ColonLoc, |
| 660 | StmtArg SubStmt) { |
| 661 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 662 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 664 | /// \brief Build a new "if" statement. |
| 665 | /// |
| 666 | /// By default, performs semantic analysis to build the new statement. |
| 667 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 669 | VarDecl *CondVar, StmtArg Then, |
| 670 | SourceLocation ElseLoc, StmtArg Else) { |
| 671 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 672 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 673 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 675 | /// \brief Start building a new switch statement. |
| 676 | /// |
| 677 | /// By default, performs semantic analysis to build the new statement. |
| 678 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 679 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 680 | VarDecl *CondVar) { |
| 681 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 684 | /// \brief Attach the body to the switch statement. |
| 685 | /// |
| 686 | /// By default, performs semantic analysis to build the new statement. |
| 687 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 688 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 689 | StmtArg Switch, StmtArg Body) { |
| 690 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 691 | move(Body)); |
| 692 | } |
| 693 | |
| 694 | /// \brief Build a new while statement. |
| 695 | /// |
| 696 | /// By default, performs semantic analysis to build the new statement. |
| 697 | /// Subclasses may override this routine to provide different behavior. |
| 698 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 699 | Sema::FullExprArg Cond, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 700 | VarDecl *CondVar, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 701 | StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 702 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 703 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 704 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 706 | /// \brief Build a new do-while statement. |
| 707 | /// |
| 708 | /// By default, performs semantic analysis to build the new statement. |
| 709 | /// Subclasses may override this routine to provide different behavior. |
| 710 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 711 | SourceLocation WhileLoc, |
| 712 | SourceLocation LParenLoc, |
| 713 | ExprArg Cond, |
| 714 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 716 | move(Cond), RParenLoc); |
| 717 | } |
| 718 | |
| 719 | /// \brief Build a new for statement. |
| 720 | /// |
| 721 | /// By default, performs semantic analysis to build the new statement. |
| 722 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 724 | SourceLocation LParenLoc, |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 725 | StmtArg Init, Sema::FullExprArg Cond, |
| 726 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 727 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 728 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 729 | DeclPtrTy::make(CondVar), |
| 730 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | /// \brief Build a new goto statement. |
| 734 | /// |
| 735 | /// By default, performs semantic analysis to build the new statement. |
| 736 | /// Subclasses may override this routine to provide different behavior. |
| 737 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 738 | SourceLocation LabelLoc, |
| 739 | LabelStmt *Label) { |
| 740 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 741 | } |
| 742 | |
| 743 | /// \brief Build a new indirect goto statement. |
| 744 | /// |
| 745 | /// By default, performs semantic analysis to build the new statement. |
| 746 | /// Subclasses may override this routine to provide different behavior. |
| 747 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 748 | SourceLocation StarLoc, |
| 749 | ExprArg Target) { |
| 750 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 751 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 753 | /// \brief Build a new return statement. |
| 754 | /// |
| 755 | /// By default, performs semantic analysis to build the new statement. |
| 756 | /// Subclasses may override this routine to provide different behavior. |
| 757 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 758 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 760 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 761 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 763 | /// \brief Build a new declaration statement. |
| 764 | /// |
| 765 | /// By default, performs semantic analysis to build the new statement. |
| 766 | /// Subclasses may override this routine to provide different behavior. |
| 767 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | SourceLocation EndLoc) { |
| 770 | return getSema().Owned( |
| 771 | new (getSema().Context) DeclStmt( |
| 772 | DeclGroupRef::Create(getSema().Context, |
| 773 | Decls, NumDecls), |
| 774 | StartLoc, EndLoc)); |
| 775 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 777 | /// \brief Build a new C++ exception declaration. |
| 778 | /// |
| 779 | /// By default, performs semantic analysis to build the new decaration. |
| 780 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 782 | DeclaratorInfo *Declarator, |
| 783 | IdentifierInfo *Name, |
| 784 | SourceLocation Loc, |
| 785 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | TypeRange); |
| 788 | } |
| 789 | |
| 790 | /// \brief Build a new C++ catch statement. |
| 791 | /// |
| 792 | /// By default, performs semantic analysis to build the new statement. |
| 793 | /// Subclasses may override this routine to provide different behavior. |
| 794 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 795 | VarDecl *ExceptionDecl, |
| 796 | StmtArg Handler) { |
| 797 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 799 | Handler.takeAs<Stmt>())); |
| 800 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 802 | /// \brief Build a new C++ try statement. |
| 803 | /// |
| 804 | /// By default, performs semantic analysis to build the new statement. |
| 805 | /// Subclasses may override this routine to provide different behavior. |
| 806 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 807 | StmtArg TryBlock, |
| 808 | MultiStmtArg Handlers) { |
| 809 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 810 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 812 | /// \brief Build a new expression that references a declaration. |
| 813 | /// |
| 814 | /// By default, performs semantic analysis to build the new expression. |
| 815 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 816 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 817 | LookupResult &R, |
| 818 | bool RequiresADL) { |
| 819 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 820 | } |
| 821 | |
| 822 | |
| 823 | /// \brief Build a new expression that references a declaration. |
| 824 | /// |
| 825 | /// By default, performs semantic analysis to build the new expression. |
| 826 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 827 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 828 | SourceRange QualifierRange, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 829 | NamedDecl *ND, SourceLocation Loc, |
| 830 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 831 | CXXScopeSpec SS; |
| 832 | SS.setScopeRep(Qualifier); |
| 833 | SS.setRange(QualifierRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 834 | return getSema().BuildDeclarationNameExpr(Loc, ND, |
| 835 | /*FIXME:*/false, |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 836 | &SS, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 837 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 838 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 840 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 842 | /// By default, performs semantic analysis to build the new expression. |
| 843 | /// Subclasses may override this routine to provide different behavior. |
| 844 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 845 | SourceLocation RParen) { |
| 846 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 847 | } |
| 848 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 849 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 850 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 851 | /// By default, performs semantic analysis to build the new expression. |
| 852 | /// Subclasses may override this routine to provide different behavior. |
| 853 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 854 | SourceLocation OperatorLoc, |
| 855 | bool isArrow, |
| 856 | SourceLocation DestroyedTypeLoc, |
| 857 | QualType DestroyedType, |
| 858 | NestedNameSpecifier *Qualifier, |
| 859 | SourceRange QualifierRange) { |
| 860 | CXXScopeSpec SS; |
| 861 | if (Qualifier) { |
| 862 | SS.setRange(QualifierRange); |
| 863 | SS.setScopeRep(Qualifier); |
| 864 | } |
| 865 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 866 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 867 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 868 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
| 870 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 871 | OperatorLoc, |
| 872 | isArrow? tok::arrow : tok::period, |
| 873 | DestroyedTypeLoc, |
| 874 | Name, |
| 875 | Sema::DeclPtrTy::make((Decl *)0), |
| 876 | &SS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 879 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 880 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 881 | /// By default, performs semantic analysis to build the new expression. |
| 882 | /// Subclasses may override this routine to provide different behavior. |
| 883 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 884 | UnaryOperator::Opcode Opc, |
| 885 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 886 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 889 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | /// By default, performs semantic analysis to build the new expression. |
| 892 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 893 | OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo, |
| 894 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 895 | bool isSizeOf, SourceRange R) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 896 | return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 899 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 900 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 902 | /// By default, performs semantic analysis to build the new expression. |
| 903 | /// Subclasses may override this routine to provide different behavior. |
| 904 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 905 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 906 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 907 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 908 | OpLoc, isSizeOf, R); |
| 909 | if (Result.isInvalid()) |
| 910 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 912 | SubExpr.release(); |
| 913 | return move(Result); |
| 914 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 918 | /// By default, performs semantic analysis to build the new expression. |
| 919 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 920 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 921 | SourceLocation LBracketLoc, |
| 922 | ExprArg RHS, |
| 923 | SourceLocation RBracketLoc) { |
| 924 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | RBracketLoc); |
| 927 | } |
| 928 | |
| 929 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 931 | /// By default, performs semantic analysis to build the new expression. |
| 932 | /// Subclasses may override this routine to provide different behavior. |
| 933 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 934 | MultiExprArg Args, |
| 935 | SourceLocation *CommaLocs, |
| 936 | SourceLocation RParenLoc) { |
| 937 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 938 | move(Args), CommaLocs, RParenLoc); |
| 939 | } |
| 940 | |
| 941 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 942 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 943 | /// By default, performs semantic analysis to build the new expression. |
| 944 | /// Subclasses may override this routine to provide different behavior. |
| 945 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 947 | NestedNameSpecifier *Qualifier, |
| 948 | SourceRange QualifierRange, |
| 949 | SourceLocation MemberLoc, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 950 | NamedDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 951 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 952 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 953 | if (!Member->getDeclName()) { |
| 954 | // We have a reference to an unnamed field. |
| 955 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 956 | |
| 957 | MemberExpr *ME = |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 958 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 959 | Member, MemberLoc, |
| 960 | cast<FieldDecl>(Member)->getType()); |
| 961 | return getSema().Owned(ME); |
| 962 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 964 | CXXScopeSpec SS; |
| 965 | if (Qualifier) { |
| 966 | SS.setRange(QualifierRange); |
| 967 | SS.setScopeRep(Qualifier); |
| 968 | } |
| 969 | |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 970 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 971 | isArrow? tok::arrow : tok::period, |
| 972 | MemberLoc, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 973 | Member->getDeclName(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 974 | ExplicitTemplateArgs, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 975 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 976 | &SS, |
| 977 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 980 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 982 | /// By default, performs semantic analysis to build the new expression. |
| 983 | /// Subclasses may override this routine to provide different behavior. |
| 984 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 985 | BinaryOperator::Opcode Opc, |
| 986 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 987 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 988 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 993 | /// By default, performs semantic analysis to build the new expression. |
| 994 | /// Subclasses may override this routine to provide different behavior. |
| 995 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 996 | SourceLocation QuestionLoc, |
| 997 | ExprArg LHS, |
| 998 | SourceLocation ColonLoc, |
| 999 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1001 | move(LHS), move(RHS)); |
| 1002 | } |
| 1003 | |
| 1004 | /// \brief Build a new implicit cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1006 | /// By default, builds a new implicit cast without any semantic analysis. |
| 1007 | /// Subclasses may override this routine to provide different behavior. |
| 1008 | OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, |
| 1009 | ExprArg SubExpr, bool isLvalue) { |
| 1010 | ImplicitCastExpr *ICE |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | = new (getSema().Context) ImplicitCastExpr(T, Kind, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1012 | (Expr *)SubExpr.release(), |
| 1013 | isLvalue); |
| 1014 | return getSema().Owned(ICE); |
| 1015 | } |
| 1016 | |
| 1017 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1019 | /// By default, performs semantic analysis to build the new expression. |
| 1020 | /// Subclasses may override this routine to provide different behavior. |
| 1021 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1022 | QualType ExplicitTy, |
| 1023 | SourceLocation RParenLoc, |
| 1024 | ExprArg SubExpr) { |
| 1025 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1026 | LParenLoc, |
| 1027 | ExplicitTy.getAsOpaquePtr(), |
| 1028 | RParenLoc, |
| 1029 | move(SubExpr)); |
| 1030 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1032 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1034 | /// By default, performs semantic analysis to build the new expression. |
| 1035 | /// Subclasses may override this routine to provide different behavior. |
| 1036 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1037 | QualType T, |
| 1038 | SourceLocation RParenLoc, |
| 1039 | ExprArg Init) { |
| 1040 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1041 | RParenLoc, move(Init)); |
| 1042 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | /// By default, performs semantic analysis to build the new expression. |
| 1047 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | SourceLocation OpLoc, |
| 1050 | SourceLocation AccessorLoc, |
| 1051 | IdentifierInfo &Accessor) { |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1052 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | tok::period, AccessorLoc, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1054 | DeclarationName(&Accessor), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1055 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0)); |
| 1056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1058 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1060 | /// By default, performs semantic analysis to build the new expression. |
| 1061 | /// Subclasses may override this routine to provide different behavior. |
| 1062 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1063 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1064 | SourceLocation RBraceLoc, |
| 1065 | QualType ResultTy) { |
| 1066 | OwningExprResult Result |
| 1067 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1068 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1069 | return move(Result); |
| 1070 | |
| 1071 | // Patch in the result type we were given, which may have been computed |
| 1072 | // when the initial InitListExpr was built. |
| 1073 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1074 | ILE->setType(ResultTy); |
| 1075 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1076 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1080 | /// By default, performs semantic analysis to build the new expression. |
| 1081 | /// Subclasses may override this routine to provide different behavior. |
| 1082 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1083 | MultiExprArg ArrayExprs, |
| 1084 | SourceLocation EqualOrColonLoc, |
| 1085 | bool GNUSyntax, |
| 1086 | ExprArg Init) { |
| 1087 | OwningExprResult Result |
| 1088 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1089 | move(Init)); |
| 1090 | if (Result.isInvalid()) |
| 1091 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1093 | ArrayExprs.release(); |
| 1094 | return move(Result); |
| 1095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | /// By default, builds the implicit value initialization without performing |
| 1100 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1101 | /// different behavior. |
| 1102 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1103 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1104 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | /// By default, performs semantic analysis to build the new expression. |
| 1109 | /// Subclasses may override this routine to provide different behavior. |
| 1110 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1111 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1113 | RParenLoc); |
| 1114 | } |
| 1115 | |
| 1116 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1118 | /// By default, performs semantic analysis to build the new expression. |
| 1119 | /// Subclasses may override this routine to provide different behavior. |
| 1120 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1121 | MultiExprArg SubExprs, |
| 1122 | SourceLocation RParenLoc) { |
Fariborz Jahanian | f88f7ab | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1123 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1124 | move(SubExprs)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | /// |
| 1129 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// rather than attempting to map the label statement itself. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
| 1132 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1133 | SourceLocation LabelLoc, |
| 1134 | LabelStmt *Label) { |
| 1135 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1140 | /// By default, performs semantic analysis to build the new expression. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
| 1142 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1143 | StmtArg SubStmt, |
| 1144 | SourceLocation RParenLoc) { |
| 1145 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1146 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1148 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1149 | /// |
| 1150 | /// By default, performs semantic analysis to build the new expression. |
| 1151 | /// Subclasses may override this routine to provide different behavior. |
| 1152 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1153 | QualType T1, QualType T2, |
| 1154 | SourceLocation RParenLoc) { |
| 1155 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1156 | T1.getAsOpaquePtr(), |
| 1157 | T2.getAsOpaquePtr(), |
| 1158 | RParenLoc); |
| 1159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1161 | /// \brief Build a new __builtin_choose_expr expression. |
| 1162 | /// |
| 1163 | /// By default, performs semantic analysis to build the new expression. |
| 1164 | /// Subclasses may override this routine to provide different behavior. |
| 1165 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1166 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1167 | SourceLocation RParenLoc) { |
| 1168 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1169 | move(Cond), move(LHS), move(RHS), |
| 1170 | RParenLoc); |
| 1171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | /// \brief Build a new overloaded operator call expression. |
| 1174 | /// |
| 1175 | /// By default, performs semantic analysis to build the new expression. |
| 1176 | /// The semantic analysis provides the behavior of template instantiation, |
| 1177 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1178 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1179 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1180 | /// provide different behavior. |
| 1181 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1182 | SourceLocation OpLoc, |
| 1183 | ExprArg Callee, |
| 1184 | ExprArg First, |
| 1185 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1186 | |
| 1187 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1188 | /// reinterpret_cast. |
| 1189 | /// |
| 1190 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1191 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1192 | /// Subclasses may override this routine to provide different behavior. |
| 1193 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1194 | Stmt::StmtClass Class, |
| 1195 | SourceLocation LAngleLoc, |
| 1196 | QualType T, |
| 1197 | SourceLocation RAngleLoc, |
| 1198 | SourceLocation LParenLoc, |
| 1199 | ExprArg SubExpr, |
| 1200 | SourceLocation RParenLoc) { |
| 1201 | switch (Class) { |
| 1202 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1204 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1205 | move(SubExpr), RParenLoc); |
| 1206 | |
| 1207 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1209 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1210 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1214 | RAngleLoc, LParenLoc, |
| 1215 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1219 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1220 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1223 | default: |
| 1224 | assert(false && "Invalid C++ named cast"); |
| 1225 | break; |
| 1226 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | return getSema().ExprError(); |
| 1229 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1231 | /// \brief Build a new C++ static_cast expression. |
| 1232 | /// |
| 1233 | /// By default, performs semantic analysis to build the new expression. |
| 1234 | /// Subclasses may override this routine to provide different behavior. |
| 1235 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1236 | SourceLocation LAngleLoc, |
| 1237 | QualType T, |
| 1238 | SourceLocation RAngleLoc, |
| 1239 | SourceLocation LParenLoc, |
| 1240 | ExprArg SubExpr, |
| 1241 | SourceLocation RParenLoc) { |
| 1242 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1244 | LParenLoc, move(SubExpr), RParenLoc); |
| 1245 | } |
| 1246 | |
| 1247 | /// \brief Build a new C++ dynamic_cast expression. |
| 1248 | /// |
| 1249 | /// By default, performs semantic analysis to build the new expression. |
| 1250 | /// Subclasses may override this routine to provide different behavior. |
| 1251 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1252 | SourceLocation LAngleLoc, |
| 1253 | QualType T, |
| 1254 | SourceLocation RAngleLoc, |
| 1255 | SourceLocation LParenLoc, |
| 1256 | ExprArg SubExpr, |
| 1257 | SourceLocation RParenLoc) { |
| 1258 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1260 | LParenLoc, move(SubExpr), RParenLoc); |
| 1261 | } |
| 1262 | |
| 1263 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1264 | /// |
| 1265 | /// By default, performs semantic analysis to build the new expression. |
| 1266 | /// Subclasses may override this routine to provide different behavior. |
| 1267 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1268 | SourceLocation LAngleLoc, |
| 1269 | QualType T, |
| 1270 | SourceLocation RAngleLoc, |
| 1271 | SourceLocation LParenLoc, |
| 1272 | ExprArg SubExpr, |
| 1273 | SourceLocation RParenLoc) { |
| 1274 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1275 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1276 | LParenLoc, move(SubExpr), RParenLoc); |
| 1277 | } |
| 1278 | |
| 1279 | /// \brief Build a new C++ const_cast expression. |
| 1280 | /// |
| 1281 | /// By default, performs semantic analysis to build the new expression. |
| 1282 | /// Subclasses may override this routine to provide different behavior. |
| 1283 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1284 | SourceLocation LAngleLoc, |
| 1285 | QualType T, |
| 1286 | SourceLocation RAngleLoc, |
| 1287 | SourceLocation LParenLoc, |
| 1288 | ExprArg SubExpr, |
| 1289 | SourceLocation RParenLoc) { |
| 1290 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1292 | LParenLoc, move(SubExpr), RParenLoc); |
| 1293 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | /// \brief Build a new C++ functional-style cast expression. |
| 1296 | /// |
| 1297 | /// By default, performs semantic analysis to build the new expression. |
| 1298 | /// Subclasses may override this routine to provide different behavior. |
| 1299 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1300 | QualType T, |
| 1301 | SourceLocation LParenLoc, |
| 1302 | ExprArg SubExpr, |
| 1303 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1304 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1305 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1306 | T.getAsOpaquePtr(), |
| 1307 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1308 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1310 | RParenLoc); |
| 1311 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | /// \brief Build a new C++ typeid(type) expression. |
| 1314 | /// |
| 1315 | /// By default, performs semantic analysis to build the new expression. |
| 1316 | /// Subclasses may override this routine to provide different behavior. |
| 1317 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1318 | SourceLocation LParenLoc, |
| 1319 | QualType T, |
| 1320 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1321 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | T.getAsOpaquePtr(), RParenLoc); |
| 1323 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1325 | /// \brief Build a new C++ typeid(expr) expression. |
| 1326 | /// |
| 1327 | /// By default, performs semantic analysis to build the new expression. |
| 1328 | /// Subclasses may override this routine to provide different behavior. |
| 1329 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1330 | SourceLocation LParenLoc, |
| 1331 | ExprArg Operand, |
| 1332 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1335 | RParenLoc); |
| 1336 | if (Result.isInvalid()) |
| 1337 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1340 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | /// \brief Build a new C++ "this" expression. |
| 1344 | /// |
| 1345 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1346 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1347 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1349 | QualType ThisType) { |
| 1350 | return getSema().Owned( |
| 1351 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1352 | } |
| 1353 | |
| 1354 | /// \brief Build a new C++ throw expression. |
| 1355 | /// |
| 1356 | /// By default, performs semantic analysis to build the new expression. |
| 1357 | /// Subclasses may override this routine to provide different behavior. |
| 1358 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1359 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1360 | } |
| 1361 | |
| 1362 | /// \brief Build a new C++ default-argument expression. |
| 1363 | /// |
| 1364 | /// By default, builds a new default-argument expression, which does not |
| 1365 | /// require any semantic analysis. Subclasses may override this routine to |
| 1366 | /// provide different behavior. |
| 1367 | OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) { |
Anders Carlsson | f1480ee | 2009-08-14 18:30:22 +0000 | [diff] [blame] | 1368 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /// \brief Build a new C++ zero-initialization expression. |
| 1372 | /// |
| 1373 | /// By default, performs semantic analysis to build the new expression. |
| 1374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1376 | SourceLocation LParenLoc, |
| 1377 | QualType T, |
| 1378 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1380 | T.getAsOpaquePtr(), LParenLoc, |
| 1381 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | 0, RParenLoc); |
| 1383 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1384 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1385 | /// \brief Build a new C++ "new" expression. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new expression. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1390 | bool UseGlobal, |
| 1391 | SourceLocation PlacementLParen, |
| 1392 | MultiExprArg PlacementArgs, |
| 1393 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1395 | QualType AllocType, |
| 1396 | SourceLocation TypeLoc, |
| 1397 | SourceRange TypeRange, |
| 1398 | ExprArg ArraySize, |
| 1399 | SourceLocation ConstructorLParen, |
| 1400 | MultiExprArg ConstructorArgs, |
| 1401 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | PlacementLParen, |
| 1404 | move(PlacementArgs), |
| 1405 | PlacementRParen, |
| 1406 | ParenTypeId, |
| 1407 | AllocType, |
| 1408 | TypeLoc, |
| 1409 | TypeRange, |
| 1410 | move(ArraySize), |
| 1411 | ConstructorLParen, |
| 1412 | move(ConstructorArgs), |
| 1413 | ConstructorRParen); |
| 1414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1416 | /// \brief Build a new C++ "delete" expression. |
| 1417 | /// |
| 1418 | /// By default, performs semantic analysis to build the new expression. |
| 1419 | /// Subclasses may override this routine to provide different behavior. |
| 1420 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1421 | bool IsGlobalDelete, |
| 1422 | bool IsArrayForm, |
| 1423 | ExprArg Operand) { |
| 1424 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1425 | move(Operand)); |
| 1426 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1428 | /// \brief Build a new unary type trait expression. |
| 1429 | /// |
| 1430 | /// By default, performs semantic analysis to build the new expression. |
| 1431 | /// Subclasses may override this routine to provide different behavior. |
| 1432 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1433 | SourceLocation StartLoc, |
| 1434 | SourceLocation LParenLoc, |
| 1435 | QualType T, |
| 1436 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1437 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1438 | T.getAsOpaquePtr(), RParenLoc); |
| 1439 | } |
| 1440 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1441 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1442 | /// expression. |
| 1443 | /// |
| 1444 | /// By default, performs semantic analysis to build the new expression. |
| 1445 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1446 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | SourceRange QualifierRange, |
| 1448 | DeclarationName Name, |
| 1449 | SourceLocation Location, |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1450 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | CXXScopeSpec SS; |
| 1452 | SS.setRange(QualifierRange); |
| 1453 | SS.setScopeRep(NNS); |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1454 | |
| 1455 | if (TemplateArgs) |
| 1456 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1457 | *TemplateArgs); |
| 1458 | |
| 1459 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /// \brief Build a new template-id expression. |
| 1463 | /// |
| 1464 | /// By default, performs semantic analysis to build the new expression. |
| 1465 | /// Subclasses may override this routine to provide different behavior. |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1466 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1467 | LookupResult &R, |
| 1468 | bool RequiresADL, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1469 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1470 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /// \brief Build a new object-construction expression. |
| 1474 | /// |
| 1475 | /// By default, performs semantic analysis to build the new expression. |
| 1476 | /// Subclasses may override this routine to provide different behavior. |
| 1477 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
| 1478 | CXXConstructorDecl *Constructor, |
| 1479 | bool IsElidable, |
| 1480 | MultiExprArg Args) { |
Anders Carlsson | ec8e5ea | 2009-09-05 07:40:38 +0000 | [diff] [blame] | 1481 | return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/ |
| 1482 | SourceLocation(), |
| 1483 | T, Constructor, IsElidable, |
Anders Carlsson | f47511a | 2009-09-07 22:23:31 +0000 | [diff] [blame] | 1484 | move(Args)); |
Douglas Gregor | b98b199 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1523 | |
Douglas Gregor | b98b199 | 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 | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1528 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1529 | bool IsArrow, |
| 1530 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1531 | NestedNameSpecifier *Qualifier, |
| 1532 | SourceRange QualifierRange, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1534 | SourceLocation MemberLoc, |
| 1535 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0dec56d | 2009-08-11 15:56:57 +0000 | [diff] [blame] | 1536 | OwningExprResult Base = move(BaseE); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1538 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1540 | SS.setRange(QualifierRange); |
| 1541 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1542 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1543 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | move(Base), OperatorLoc, OpKind, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 1545 | MemberLoc, |
| 1546 | Name, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1547 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1548 | &SS, |
| 1549 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1552 | /// \brief Build a new member reference expression with explicit template |
| 1553 | /// arguments. |
| 1554 | /// |
| 1555 | /// By default, performs semantic analysis to build the new expression. |
| 1556 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1557 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1558 | bool IsArrow, |
| 1559 | SourceLocation OperatorLoc, |
| 1560 | NestedNameSpecifier *Qualifier, |
| 1561 | SourceRange QualifierRange, |
| 1562 | TemplateName Template, |
| 1563 | SourceLocation TemplateNameLoc, |
| 1564 | NamedDecl *FirstQualifierInScope, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1565 | const TemplateArgumentListInfo &TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1566 | OwningExprResult Base = move(BaseE); |
| 1567 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1569 | CXXScopeSpec SS; |
| 1570 | SS.setRange(QualifierRange); |
| 1571 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1573 | // FIXME: We're going to end up looking up the template based on its name, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1574 | // twice! Also, duplicates part of Sema::BuildMemberAccessExpr. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1575 | DeclarationName Name; |
| 1576 | if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl()) |
| 1577 | Name = ActualTemplate->getDeclName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1578 | else if (OverloadedFunctionDecl *Ovl |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1579 | = Template.getAsOverloadedFunctionDecl()) |
| 1580 | Name = Ovl->getDeclName(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1581 | else { |
| 1582 | DependentTemplateName *DTN = Template.getAsDependentTemplateName(); |
| 1583 | if (DTN->isIdentifier()) |
| 1584 | Name = DTN->getIdentifier(); |
| 1585 | else |
| 1586 | Name = SemaRef.Context.DeclarationNames.getCXXOperatorName( |
| 1587 | DTN->getOperator()); |
| 1588 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1589 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
| 1590 | OperatorLoc, OpKind, |
| 1591 | TemplateNameLoc, Name, |
| 1592 | &TemplateArgs, |
| 1593 | Sema::DeclPtrTy(), &SS); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1596 | /// \brief Build a new Objective-C @encode expression. |
| 1597 | /// |
| 1598 | /// By default, performs semantic analysis to build the new expression. |
| 1599 | /// Subclasses may override this routine to provide different behavior. |
| 1600 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1601 | QualType T, |
| 1602 | SourceLocation RParenLoc) { |
| 1603 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1604 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | |
| 1607 | /// \brief Build a new Objective-C protocol expression. |
| 1608 | /// |
| 1609 | /// By default, performs semantic analysis to build the new expression. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
| 1611 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1612 | SourceLocation AtLoc, |
| 1613 | SourceLocation ProtoLoc, |
| 1614 | SourceLocation LParenLoc, |
| 1615 | SourceLocation RParenLoc) { |
| 1616 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1617 | Protocol->getIdentifier(), |
| 1618 | AtLoc, |
| 1619 | ProtoLoc, |
| 1620 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1621 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1622 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1623 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1624 | /// \brief Build a new shuffle vector expression. |
| 1625 | /// |
| 1626 | /// By default, performs semantic analysis to build the new expression. |
| 1627 | /// Subclasses may override this routine to provide different behavior. |
| 1628 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1629 | MultiExprArg SubExprs, |
| 1630 | SourceLocation RParenLoc) { |
| 1631 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1632 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1634 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1635 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1636 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1638 | // Build a reference to the __builtin_shufflevector builtin |
| 1639 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1641 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1642 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | |
| 1645 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | unsigned NumSubExprs = SubExprs.size(); |
| 1647 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1648 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1649 | Subs, NumSubExprs, |
| 1650 | Builtin->getResultType(), |
| 1651 | RParenLoc); |
| 1652 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | // Type-check the __builtin_shufflevector expression. |
| 1655 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1656 | if (Result.isInvalid()) |
| 1657 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1659 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1661 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1662 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1664 | template<typename Derived> |
| 1665 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1666 | if (!S) |
| 1667 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1669 | switch (S->getStmtClass()) { |
| 1670 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1672 | // Transform individual statement nodes |
| 1673 | #define STMT(Node, Parent) \ |
| 1674 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1675 | #define EXPR(Node, Parent) |
| 1676 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1678 | // Transform expressions by calling TransformExpr. |
| 1679 | #define STMT(Node, Parent) |
| 1680 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1681 | #include "clang/AST/StmtNodes.def" |
| 1682 | { |
| 1683 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1684 | if (E.isInvalid()) |
| 1685 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1686 | |
Douglas Gregor | afe7ec2 | 2009-11-13 18:34:26 +0000 | [diff] [blame] | 1687 | return getSema().ActOnExprStmt(getSema().FullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1691 | return SemaRef.Owned(S->Retain()); |
| 1692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
| 1694 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1695 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, |
| 1697 | bool isAddressOfOperand) { |
| 1698 | if (!E) |
| 1699 | return SemaRef.Owned(E); |
| 1700 | |
| 1701 | switch (E->getStmtClass()) { |
| 1702 | case Stmt::NoStmtClass: break; |
| 1703 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1704 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 1705 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \ |
| 1706 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1707 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1710 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1714 | NestedNameSpecifier * |
| 1715 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1716 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1717 | QualType ObjectType, |
| 1718 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1719 | if (!NNS) |
| 1720 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1722 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1723 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1724 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1726 | ObjectType, |
| 1727 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1728 | if (!Prefix) |
| 1729 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | |
| 1731 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1732 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1733 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1734 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1735 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1737 | switch (NNS->getKind()) { |
| 1738 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1739 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1740 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1741 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1742 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1743 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
| 1745 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1746 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1747 | ObjectType, |
| 1748 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1749 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1750 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1751 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1752 | = cast_or_null<NamespaceDecl>( |
| 1753 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1754 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1755 | Prefix == NNS->getPrefix() && |
| 1756 | NS == NNS->getAsNamespace()) |
| 1757 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1759 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1760 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1762 | case NestedNameSpecifier::Global: |
| 1763 | // There is no meaningful transformation that one could perform on the |
| 1764 | // global scope. |
| 1765 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1768 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1769 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1771 | if (T.isNull()) |
| 1772 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1773 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1774 | if (!getDerived().AlwaysRebuild() && |
| 1775 | Prefix == NNS->getPrefix() && |
| 1776 | T == QualType(NNS->getAsType(), 0)) |
| 1777 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1778 | |
| 1779 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1780 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1781 | T); |
| 1782 | } |
| 1783 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1785 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1791 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1792 | SourceLocation Loc, |
| 1793 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1794 | if (!Name) |
| 1795 | return Name; |
| 1796 | |
| 1797 | switch (Name.getNameKind()) { |
| 1798 | case DeclarationName::Identifier: |
| 1799 | case DeclarationName::ObjCZeroArgSelector: |
| 1800 | case DeclarationName::ObjCOneArgSelector: |
| 1801 | case DeclarationName::ObjCMultiArgSelector: |
| 1802 | case DeclarationName::CXXOperatorName: |
| 1803 | case DeclarationName::CXXUsingDirective: |
| 1804 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | case DeclarationName::CXXConstructorName: |
| 1807 | case DeclarationName::CXXDestructorName: |
| 1808 | case DeclarationName::CXXConversionFunctionName: { |
| 1809 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1810 | QualType T; |
| 1811 | if (!ObjectType.isNull() && |
| 1812 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1813 | TemplateSpecializationType *SpecType |
| 1814 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1815 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1816 | } else |
| 1817 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1818 | if (T.isNull()) |
| 1819 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1820 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1821 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1822 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1823 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1827 | return DeclarationName(); |
| 1828 | } |
| 1829 | |
| 1830 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1832 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1833 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1834 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1836 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1837 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1838 | if (!NNS) |
| 1839 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1843 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1844 | if (!TransTemplate) |
| 1845 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1847 | if (!getDerived().AlwaysRebuild() && |
| 1848 | NNS == QTN->getQualifier() && |
| 1849 | TransTemplate == Template) |
| 1850 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1852 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1853 | TransTemplate); |
| 1854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1856 | // These should be getting filtered out before they make it into the AST. |
| 1857 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1860 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1862 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1863 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1864 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1865 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1867 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1868 | NNS == DTN->getQualifier() && |
| 1869 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1872 | if (DTN->isIdentifier()) |
| 1873 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1874 | ObjectType); |
| 1875 | |
| 1876 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1877 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1880 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1882 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1883 | if (!TransTemplate) |
| 1884 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1885 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1886 | if (!getDerived().AlwaysRebuild() && |
| 1887 | TransTemplate == Template) |
| 1888 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1890 | return TemplateName(TransTemplate); |
| 1891 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1893 | // These should be getting filtered out before they reach the AST. |
| 1894 | assert(false && "overloaded function decl survived to here"); |
| 1895 | return TemplateName(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1899 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1900 | const TemplateArgument &Arg, |
| 1901 | TemplateArgumentLoc &Output) { |
| 1902 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1903 | switch (Arg.getKind()) { |
| 1904 | case TemplateArgument::Null: |
| 1905 | llvm::llvm_unreachable("null template argument in TreeTransform"); |
| 1906 | break; |
| 1907 | |
| 1908 | case TemplateArgument::Type: |
| 1909 | Output = TemplateArgumentLoc(Arg, |
| 1910 | SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc)); |
| 1911 | |
| 1912 | break; |
| 1913 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1914 | case TemplateArgument::Template: |
| 1915 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1916 | break; |
| 1917 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1918 | case TemplateArgument::Expression: |
| 1919 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1920 | break; |
| 1921 | |
| 1922 | case TemplateArgument::Declaration: |
| 1923 | case TemplateArgument::Integral: |
| 1924 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1925 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1926 | break; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | template<typename Derived> |
| 1931 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1932 | const TemplateArgumentLoc &Input, |
| 1933 | TemplateArgumentLoc &Output) { |
| 1934 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1935 | switch (Arg.getKind()) { |
| 1936 | case TemplateArgument::Null: |
| 1937 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1938 | Output = Input; |
| 1939 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1941 | case TemplateArgument::Type: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1942 | DeclaratorInfo *DI = Input.getSourceDeclaratorInfo(); |
| 1943 | if (DI == NULL) |
| 1944 | DI = InventDeclaratorInfo(Input.getArgument().getAsType()); |
| 1945 | |
| 1946 | DI = getDerived().TransformType(DI); |
| 1947 | if (!DI) return true; |
| 1948 | |
| 1949 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1950 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1952 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1953 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1954 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1955 | DeclarationName Name; |
| 1956 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1957 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1958 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1959 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1960 | if (!D) return true; |
| 1961 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1962 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1963 | if (SourceExpr) { |
| 1964 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1965 | Action::Unevaluated); |
| 1966 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1967 | if (E.isInvalid()) |
| 1968 | SourceExpr = NULL; |
| 1969 | else { |
| 1970 | SourceExpr = E.takeAs<Expr>(); |
| 1971 | SourceExpr->Retain(); |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1976 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1977 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1978 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1979 | case TemplateArgument::Template: { |
| 1980 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1981 | TemplateName Template |
| 1982 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1983 | if (Template.isNull()) |
| 1984 | return true; |
| 1985 | |
| 1986 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1987 | Input.getTemplateQualifierRange(), |
| 1988 | Input.getTemplateNameLoc()); |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1992 | case TemplateArgument::Expression: { |
| 1993 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1994 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1995 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1997 | Expr *InputExpr = Input.getSourceExpression(); |
| 1998 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1999 | |
| 2000 | Sema::OwningExprResult E |
| 2001 | = getDerived().TransformExpr(InputExpr); |
| 2002 | if (E.isInvalid()) return true; |
| 2003 | |
| 2004 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2005 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2006 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2007 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2010 | case TemplateArgument::Pack: { |
| 2011 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2012 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2014 | AEnd = Arg.pack_end(); |
| 2015 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2017 | // FIXME: preserve source information here when we start |
| 2018 | // caring about parameter packs. |
| 2019 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2020 | TemplateArgumentLoc InputArg; |
| 2021 | TemplateArgumentLoc OutputArg; |
| 2022 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2023 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2024 | return true; |
| 2025 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2026 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2027 | } |
| 2028 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2030 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2031 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2032 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2033 | } |
| 2034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2035 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2036 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2037 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2040 | //===----------------------------------------------------------------------===// |
| 2041 | // Type transformation |
| 2042 | //===----------------------------------------------------------------------===// |
| 2043 | |
| 2044 | template<typename Derived> |
| 2045 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2046 | if (getDerived().AlreadyTransformed(T)) |
| 2047 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2049 | // Temporary workaround. All of these transformations should |
| 2050 | // eventually turn into transformations on TypeLocs. |
| 2051 | DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2052 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2053 | |
| 2054 | DeclaratorInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2055 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2056 | if (!NewDI) |
| 2057 | return QualType(); |
| 2058 | |
| 2059 | return NewDI->getType(); |
| 2060 | } |
| 2061 | |
| 2062 | template<typename Derived> |
| 2063 | DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) { |
| 2064 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2065 | return DI; |
| 2066 | |
| 2067 | TypeLocBuilder TLB; |
| 2068 | |
| 2069 | TypeLoc TL = DI->getTypeLoc(); |
| 2070 | TLB.reserve(TL.getFullDataSize()); |
| 2071 | |
| 2072 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2073 | if (Result.isNull()) |
| 2074 | return 0; |
| 2075 | |
| 2076 | return TLB.getDeclaratorInfo(SemaRef.Context, Result); |
| 2077 | } |
| 2078 | |
| 2079 | template<typename Derived> |
| 2080 | QualType |
| 2081 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2082 | switch (T.getTypeLocClass()) { |
| 2083 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2084 | #define TYPELOC(CLASS, PARENT) \ |
| 2085 | case TypeLoc::CLASS: \ |
| 2086 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2087 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2088 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2089 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2090 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2091 | return QualType(); |
| 2092 | } |
| 2093 | |
| 2094 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2095 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2096 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2097 | /// types). This is the right thing for template instantiation, but |
| 2098 | /// probably not for other clients. |
| 2099 | template<typename Derived> |
| 2100 | QualType |
| 2101 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2102 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2103 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2104 | |
| 2105 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2106 | if (Result.isNull()) |
| 2107 | return QualType(); |
| 2108 | |
| 2109 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2110 | // FIXME: this is the right thing for template instantiation, but |
| 2111 | // probably not for other clients. |
| 2112 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2113 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2115 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2116 | |
| 2117 | TLB.push<QualifiedTypeLoc>(Result); |
| 2118 | |
| 2119 | // No location information to preserve. |
| 2120 | |
| 2121 | return Result; |
| 2122 | } |
| 2123 | |
| 2124 | template <class TyLoc> static inline |
| 2125 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2126 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2127 | NewT.setNameLoc(T.getNameLoc()); |
| 2128 | return T.getType(); |
| 2129 | } |
| 2130 | |
| 2131 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2132 | // the equivalent template version work. |
| 2133 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2134 | QualType PointeeType \ |
| 2135 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2136 | if (PointeeType.isNull()) \ |
| 2137 | return QualType(); \ |
| 2138 | \ |
| 2139 | QualType Result = TL.getType(); \ |
| 2140 | if (getDerived().AlwaysRebuild() || \ |
| 2141 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2142 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2143 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2144 | if (Result.isNull()) \ |
| 2145 | return QualType(); \ |
| 2146 | } \ |
| 2147 | \ |
| 2148 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2149 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2150 | \ |
| 2151 | return Result; \ |
| 2152 | } while(0) |
| 2153 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2154 | template<typename Derived> |
| 2155 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2156 | BuiltinTypeLoc T) { |
| 2157 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2158 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2159 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2160 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2161 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2162 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2163 | FixedWidthIntTypeLoc T) { |
| 2164 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2165 | } |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2166 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2167 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2168 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2169 | ComplexTypeLoc T) { |
| 2170 | // FIXME: recurse? |
| 2171 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2174 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2175 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2176 | PointerTypeLoc TL) { |
| 2177 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2179 | |
| 2180 | template<typename Derived> |
| 2181 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2182 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2183 | BlockPointerTypeLoc TL) { |
| 2184 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2187 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2188 | /// don't care whether the type itself is an l-value type or an r-value |
| 2189 | /// type; we only care if the type was *written* as an l-value type |
| 2190 | /// or an r-value type. |
| 2191 | template<typename Derived> |
| 2192 | QualType |
| 2193 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2194 | ReferenceTypeLoc TL) { |
| 2195 | const ReferenceType *T = TL.getTypePtr(); |
| 2196 | |
| 2197 | // Note that this works with the pointee-as-written. |
| 2198 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2199 | if (PointeeType.isNull()) |
| 2200 | return QualType(); |
| 2201 | |
| 2202 | QualType Result = TL.getType(); |
| 2203 | if (getDerived().AlwaysRebuild() || |
| 2204 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2205 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2206 | T->isSpelledAsLValue(), |
| 2207 | TL.getSigilLoc()); |
| 2208 | if (Result.isNull()) |
| 2209 | return QualType(); |
| 2210 | } |
| 2211 | |
| 2212 | // r-value references can be rebuilt as l-value references. |
| 2213 | ReferenceTypeLoc NewTL; |
| 2214 | if (isa<LValueReferenceType>(Result)) |
| 2215 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2216 | else |
| 2217 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2218 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2219 | |
| 2220 | return Result; |
| 2221 | } |
| 2222 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2223 | template<typename Derived> |
| 2224 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2225 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2226 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2227 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2230 | template<typename Derived> |
| 2231 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2232 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2233 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2234 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2235 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2236 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2237 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2238 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2239 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2240 | MemberPointerTypeLoc TL) { |
| 2241 | MemberPointerType *T = TL.getTypePtr(); |
| 2242 | |
| 2243 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2244 | if (PointeeType.isNull()) |
| 2245 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2247 | // TODO: preserve source information for this. |
| 2248 | QualType ClassType |
| 2249 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | if (ClassType.isNull()) |
| 2251 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2253 | QualType Result = TL.getType(); |
| 2254 | if (getDerived().AlwaysRebuild() || |
| 2255 | PointeeType != T->getPointeeType() || |
| 2256 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2257 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2258 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2259 | if (Result.isNull()) |
| 2260 | return QualType(); |
| 2261 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2263 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2264 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2265 | |
| 2266 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2269 | template<typename Derived> |
| 2270 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2271 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2272 | ConstantArrayTypeLoc TL) { |
| 2273 | ConstantArrayType *T = TL.getTypePtr(); |
| 2274 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2275 | if (ElementType.isNull()) |
| 2276 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2277 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2278 | QualType Result = TL.getType(); |
| 2279 | if (getDerived().AlwaysRebuild() || |
| 2280 | ElementType != T->getElementType()) { |
| 2281 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2282 | T->getSizeModifier(), |
| 2283 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2284 | T->getIndexTypeCVRQualifiers(), |
| 2285 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2286 | if (Result.isNull()) |
| 2287 | return QualType(); |
| 2288 | } |
| 2289 | |
| 2290 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2291 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2292 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2294 | Expr *Size = TL.getSizeExpr(); |
| 2295 | if (Size) { |
| 2296 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2297 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2298 | } |
| 2299 | NewTL.setSizeExpr(Size); |
| 2300 | |
| 2301 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2303 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2304 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2305 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2306 | TypeLocBuilder &TLB, |
| 2307 | IncompleteArrayTypeLoc TL) { |
| 2308 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2309 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2310 | if (ElementType.isNull()) |
| 2311 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2312 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2313 | QualType Result = TL.getType(); |
| 2314 | if (getDerived().AlwaysRebuild() || |
| 2315 | ElementType != T->getElementType()) { |
| 2316 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2317 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2318 | T->getIndexTypeCVRQualifiers(), |
| 2319 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2320 | if (Result.isNull()) |
| 2321 | return QualType(); |
| 2322 | } |
| 2323 | |
| 2324 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2325 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2326 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2327 | NewTL.setSizeExpr(0); |
| 2328 | |
| 2329 | return Result; |
| 2330 | } |
| 2331 | |
| 2332 | template<typename Derived> |
| 2333 | QualType |
| 2334 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2335 | VariableArrayTypeLoc TL) { |
| 2336 | VariableArrayType *T = TL.getTypePtr(); |
| 2337 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2338 | if (ElementType.isNull()) |
| 2339 | return QualType(); |
| 2340 | |
| 2341 | // Array bounds are not potentially evaluated contexts |
| 2342 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2343 | |
| 2344 | Sema::OwningExprResult SizeResult |
| 2345 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2346 | if (SizeResult.isInvalid()) |
| 2347 | return QualType(); |
| 2348 | |
| 2349 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2350 | |
| 2351 | QualType Result = TL.getType(); |
| 2352 | if (getDerived().AlwaysRebuild() || |
| 2353 | ElementType != T->getElementType() || |
| 2354 | Size != T->getSizeExpr()) { |
| 2355 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2356 | T->getSizeModifier(), |
| 2357 | move(SizeResult), |
| 2358 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2359 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2360 | if (Result.isNull()) |
| 2361 | return QualType(); |
| 2362 | } |
| 2363 | else SizeResult.take(); |
| 2364 | |
| 2365 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2366 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2367 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2368 | NewTL.setSizeExpr(Size); |
| 2369 | |
| 2370 | return Result; |
| 2371 | } |
| 2372 | |
| 2373 | template<typename Derived> |
| 2374 | QualType |
| 2375 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2376 | DependentSizedArrayTypeLoc TL) { |
| 2377 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2378 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2379 | if (ElementType.isNull()) |
| 2380 | return QualType(); |
| 2381 | |
| 2382 | // Array bounds are not potentially evaluated contexts |
| 2383 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2384 | |
| 2385 | Sema::OwningExprResult SizeResult |
| 2386 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2387 | if (SizeResult.isInvalid()) |
| 2388 | return QualType(); |
| 2389 | |
| 2390 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2391 | |
| 2392 | QualType Result = TL.getType(); |
| 2393 | if (getDerived().AlwaysRebuild() || |
| 2394 | ElementType != T->getElementType() || |
| 2395 | Size != T->getSizeExpr()) { |
| 2396 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2397 | T->getSizeModifier(), |
| 2398 | move(SizeResult), |
| 2399 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2400 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2401 | if (Result.isNull()) |
| 2402 | return QualType(); |
| 2403 | } |
| 2404 | else SizeResult.take(); |
| 2405 | |
| 2406 | // We might have any sort of array type now, but fortunately they |
| 2407 | // all have the same location layout. |
| 2408 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2409 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2410 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2411 | NewTL.setSizeExpr(Size); |
| 2412 | |
| 2413 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2414 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2415 | |
| 2416 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2417 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2418 | TypeLocBuilder &TLB, |
| 2419 | DependentSizedExtVectorTypeLoc TL) { |
| 2420 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2421 | |
| 2422 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2423 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2424 | if (ElementType.isNull()) |
| 2425 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2426 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2427 | // Vector sizes are not potentially evaluated contexts |
| 2428 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2429 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2430 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2431 | if (Size.isInvalid()) |
| 2432 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2433 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2434 | QualType Result = TL.getType(); |
| 2435 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2436 | ElementType != T->getElementType() || |
| 2437 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2438 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2439 | move(Size), |
| 2440 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2441 | if (Result.isNull()) |
| 2442 | return QualType(); |
| 2443 | } |
| 2444 | else Size.take(); |
| 2445 | |
| 2446 | // Result might be dependent or not. |
| 2447 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2448 | DependentSizedExtVectorTypeLoc NewTL |
| 2449 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2450 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2451 | } else { |
| 2452 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2453 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2454 | } |
| 2455 | |
| 2456 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2457 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2458 | |
| 2459 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2460 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2461 | VectorTypeLoc TL) { |
| 2462 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2463 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2464 | if (ElementType.isNull()) |
| 2465 | return QualType(); |
| 2466 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2467 | QualType Result = TL.getType(); |
| 2468 | if (getDerived().AlwaysRebuild() || |
| 2469 | ElementType != T->getElementType()) { |
| 2470 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2471 | if (Result.isNull()) |
| 2472 | return QualType(); |
| 2473 | } |
| 2474 | |
| 2475 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2476 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2477 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2478 | return Result; |
| 2479 | } |
| 2480 | |
| 2481 | template<typename Derived> |
| 2482 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2483 | ExtVectorTypeLoc TL) { |
| 2484 | VectorType *T = TL.getTypePtr(); |
| 2485 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2486 | if (ElementType.isNull()) |
| 2487 | return QualType(); |
| 2488 | |
| 2489 | QualType Result = TL.getType(); |
| 2490 | if (getDerived().AlwaysRebuild() || |
| 2491 | ElementType != T->getElementType()) { |
| 2492 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2493 | T->getNumElements(), |
| 2494 | /*FIXME*/ SourceLocation()); |
| 2495 | if (Result.isNull()) |
| 2496 | return QualType(); |
| 2497 | } |
| 2498 | |
| 2499 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2500 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2501 | |
| 2502 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2503 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2504 | |
| 2505 | template<typename Derived> |
| 2506 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2507 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2508 | FunctionProtoTypeLoc TL) { |
| 2509 | FunctionProtoType *T = TL.getTypePtr(); |
| 2510 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2511 | if (ResultType.isNull()) |
| 2512 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2513 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2514 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2515 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2516 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2517 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2518 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2519 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2520 | QualType NewType; |
| 2521 | ParmVarDecl *NewParm; |
| 2522 | |
| 2523 | if (OldParm) { |
| 2524 | DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo(); |
| 2525 | assert(OldDI->getType() == T->getArgType(i)); |
| 2526 | |
| 2527 | DeclaratorInfo *NewDI = getDerived().TransformType(OldDI); |
| 2528 | if (!NewDI) |
| 2529 | return QualType(); |
| 2530 | |
| 2531 | if (NewDI == OldDI) |
| 2532 | NewParm = OldParm; |
| 2533 | else |
| 2534 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2535 | OldParm->getDeclContext(), |
| 2536 | OldParm->getLocation(), |
| 2537 | OldParm->getIdentifier(), |
| 2538 | NewDI->getType(), |
| 2539 | NewDI, |
| 2540 | OldParm->getStorageClass(), |
| 2541 | /* DefArg */ NULL); |
| 2542 | NewType = NewParm->getType(); |
| 2543 | |
| 2544 | // Deal with the possibility that we don't have a parameter |
| 2545 | // declaration for this parameter. |
| 2546 | } else { |
| 2547 | NewParm = 0; |
| 2548 | |
| 2549 | QualType OldType = T->getArgType(i); |
| 2550 | NewType = getDerived().TransformType(OldType); |
| 2551 | if (NewType.isNull()) |
| 2552 | return QualType(); |
| 2553 | } |
| 2554 | |
| 2555 | ParamTypes.push_back(NewType); |
| 2556 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2559 | QualType Result = TL.getType(); |
| 2560 | if (getDerived().AlwaysRebuild() || |
| 2561 | ResultType != T->getResultType() || |
| 2562 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2563 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2564 | ParamTypes.data(), |
| 2565 | ParamTypes.size(), |
| 2566 | T->isVariadic(), |
| 2567 | T->getTypeQuals()); |
| 2568 | if (Result.isNull()) |
| 2569 | return QualType(); |
| 2570 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2571 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2572 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2573 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2574 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2575 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2576 | NewTL.setArg(i, ParamDecls[i]); |
| 2577 | |
| 2578 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2579 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2580 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2581 | template<typename Derived> |
| 2582 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2583 | TypeLocBuilder &TLB, |
| 2584 | FunctionNoProtoTypeLoc TL) { |
| 2585 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2586 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2587 | if (ResultType.isNull()) |
| 2588 | return QualType(); |
| 2589 | |
| 2590 | QualType Result = TL.getType(); |
| 2591 | if (getDerived().AlwaysRebuild() || |
| 2592 | ResultType != T->getResultType()) |
| 2593 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2594 | |
| 2595 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2596 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2597 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2598 | |
| 2599 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2600 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2601 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2603 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2604 | TypedefTypeLoc TL) { |
| 2605 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2606 | TypedefDecl *Typedef |
| 2607 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2608 | if (!Typedef) |
| 2609 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2611 | QualType Result = TL.getType(); |
| 2612 | if (getDerived().AlwaysRebuild() || |
| 2613 | Typedef != T->getDecl()) { |
| 2614 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2615 | if (Result.isNull()) |
| 2616 | return QualType(); |
| 2617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2620 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2621 | |
| 2622 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2626 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2627 | TypeOfExprTypeLoc TL) { |
| 2628 | TypeOfExprType *T = TL.getTypePtr(); |
| 2629 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2630 | // typeof expressions are not potentially evaluated contexts |
| 2631 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2632 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2633 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2634 | if (E.isInvalid()) |
| 2635 | return QualType(); |
| 2636 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2637 | QualType Result = TL.getType(); |
| 2638 | if (getDerived().AlwaysRebuild() || |
| 2639 | E.get() != T->getUnderlyingExpr()) { |
| 2640 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2641 | if (Result.isNull()) |
| 2642 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2643 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2645 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2646 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2647 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2648 | |
| 2649 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2650 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | |
| 2652 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2653 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2654 | TypeOfTypeLoc TL) { |
| 2655 | TypeOfType *T = TL.getTypePtr(); |
| 2656 | |
| 2657 | // FIXME: should be an inner type, or at least have a DeclaratorInfo. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2658 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2659 | if (Underlying.isNull()) |
| 2660 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2661 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2662 | QualType Result = TL.getType(); |
| 2663 | if (getDerived().AlwaysRebuild() || |
| 2664 | Underlying != T->getUnderlyingType()) { |
| 2665 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2666 | if (Result.isNull()) |
| 2667 | return QualType(); |
| 2668 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2670 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2671 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2672 | |
| 2673 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2674 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2675 | |
| 2676 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2677 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2678 | DecltypeTypeLoc TL) { |
| 2679 | DecltypeType *T = TL.getTypePtr(); |
| 2680 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2681 | // decltype expressions are not potentially evaluated contexts |
| 2682 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2683 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2684 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2685 | if (E.isInvalid()) |
| 2686 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2687 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2688 | QualType Result = TL.getType(); |
| 2689 | if (getDerived().AlwaysRebuild() || |
| 2690 | E.get() != T->getUnderlyingExpr()) { |
| 2691 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2692 | if (Result.isNull()) |
| 2693 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2694 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2695 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2696 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2697 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2698 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2699 | |
| 2700 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2704 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2705 | RecordTypeLoc TL) { |
| 2706 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2707 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2708 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2709 | if (!Record) |
| 2710 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2712 | QualType Result = TL.getType(); |
| 2713 | if (getDerived().AlwaysRebuild() || |
| 2714 | Record != T->getDecl()) { |
| 2715 | Result = getDerived().RebuildRecordType(Record); |
| 2716 | if (Result.isNull()) |
| 2717 | return QualType(); |
| 2718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2719 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2720 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2721 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2722 | |
| 2723 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
| 2726 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2727 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2728 | EnumTypeLoc TL) { |
| 2729 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2730 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2731 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2732 | if (!Enum) |
| 2733 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2734 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | QualType Result = TL.getType(); |
| 2736 | if (getDerived().AlwaysRebuild() || |
| 2737 | Enum != T->getDecl()) { |
| 2738 | Result = getDerived().RebuildEnumType(Enum); |
| 2739 | if (Result.isNull()) |
| 2740 | return QualType(); |
| 2741 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2742 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2743 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2744 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2745 | |
| 2746 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2748 | |
| 2749 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2751 | ElaboratedTypeLoc TL) { |
| 2752 | ElaboratedType *T = TL.getTypePtr(); |
| 2753 | |
| 2754 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2755 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2756 | if (Underlying.isNull()) |
| 2757 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2758 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2759 | QualType Result = TL.getType(); |
| 2760 | if (getDerived().AlwaysRebuild() || |
| 2761 | Underlying != T->getUnderlyingType()) { |
| 2762 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2763 | if (Result.isNull()) |
| 2764 | return QualType(); |
| 2765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2766 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2767 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2768 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2769 | |
| 2770 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2771 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | |
| 2773 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2774 | template<typename Derived> |
| 2775 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2776 | TypeLocBuilder &TLB, |
| 2777 | TemplateTypeParmTypeLoc TL) { |
| 2778 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2782 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2783 | TypeLocBuilder &TLB, |
| 2784 | SubstTemplateTypeParmTypeLoc TL) { |
| 2785 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2789 | inline QualType |
| 2790 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | TypeLocBuilder &TLB, |
| 2792 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2793 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2794 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2796 | template<typename Derived> |
| 2797 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2798 | const TemplateSpecializationType *TST, |
| 2799 | QualType ObjectType) { |
| 2800 | // FIXME: this entire method is a temporary workaround; callers |
| 2801 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2802 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2803 | // Fake up a TemplateSpecializationTypeLoc. |
| 2804 | TypeLocBuilder TLB; |
| 2805 | TemplateSpecializationTypeLoc TL |
| 2806 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2807 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2808 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2809 | |
| 2810 | TL.setTemplateNameLoc(BaseLoc); |
| 2811 | TL.setLAngleLoc(BaseLoc); |
| 2812 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2813 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2814 | const TemplateArgument &TA = TST->getArg(i); |
| 2815 | TemplateArgumentLoc TAL; |
| 2816 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2817 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2818 | } |
| 2819 | |
| 2820 | TypeLocBuilder IgnoredTLB; |
| 2821 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2825 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2826 | TypeLocBuilder &TLB, |
| 2827 | TemplateSpecializationTypeLoc TL, |
| 2828 | QualType ObjectType) { |
| 2829 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2830 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2831 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2832 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | if (Template.isNull()) |
| 2834 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2835 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2836 | TemplateArgumentListInfo NewTemplateArgs; |
| 2837 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2838 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2839 | |
| 2840 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2841 | TemplateArgumentLoc Loc; |
| 2842 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2843 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2844 | NewTemplateArgs.addArgument(Loc); |
| 2845 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2846 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2847 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2848 | |
| 2849 | QualType Result = |
| 2850 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2851 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2852 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2853 | |
| 2854 | if (!Result.isNull()) { |
| 2855 | TemplateSpecializationTypeLoc NewTL |
| 2856 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2857 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2858 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2859 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2860 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2861 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2863 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2864 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2865 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2866 | |
| 2867 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2868 | QualType |
| 2869 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2870 | QualifiedNameTypeLoc TL) { |
| 2871 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2872 | NestedNameSpecifier *NNS |
| 2873 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2874 | SourceRange()); |
| 2875 | if (!NNS) |
| 2876 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2878 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2879 | if (Named.isNull()) |
| 2880 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2882 | QualType Result = TL.getType(); |
| 2883 | if (getDerived().AlwaysRebuild() || |
| 2884 | NNS != T->getQualifier() || |
| 2885 | Named != T->getNamedType()) { |
| 2886 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2887 | if (Result.isNull()) |
| 2888 | return QualType(); |
| 2889 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2891 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2892 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2893 | |
| 2894 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2896 | |
| 2897 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2898 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2899 | TypenameTypeLoc TL) { |
| 2900 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2901 | |
| 2902 | /* FIXME: preserve source information better than this */ |
| 2903 | SourceRange SR(TL.getNameLoc()); |
| 2904 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2905 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2906 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | if (!NNS) |
| 2908 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2909 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2910 | QualType Result; |
| 2911 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2912 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2913 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2914 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2915 | if (NewTemplateId.isNull()) |
| 2916 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2917 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2918 | if (!getDerived().AlwaysRebuild() && |
| 2919 | NNS == T->getQualifier() && |
| 2920 | NewTemplateId == QualType(TemplateId, 0)) |
| 2921 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2922 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2923 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2924 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2925 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2926 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | if (Result.isNull()) |
| 2928 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2929 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2930 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2931 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2932 | |
| 2933 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2934 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2935 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2936 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2937 | QualType |
| 2938 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2939 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2940 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2941 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2942 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2943 | |
| 2944 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2945 | QualType |
| 2946 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2947 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2948 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2949 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2953 | // Statement transformation |
| 2954 | //===----------------------------------------------------------------------===// |
| 2955 | template<typename Derived> |
| 2956 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2957 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2958 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | template<typename Derived> |
| 2962 | Sema::OwningStmtResult |
| 2963 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2964 | return getDerived().TransformCompoundStmt(S, false); |
| 2965 | } |
| 2966 | |
| 2967 | template<typename Derived> |
| 2968 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2970 | bool IsStmtExpr) { |
| 2971 | bool SubStmtChanged = false; |
| 2972 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2973 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2974 | B != BEnd; ++B) { |
| 2975 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2976 | if (Result.isInvalid()) |
| 2977 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2978 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2979 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2980 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2983 | if (!getDerived().AlwaysRebuild() && |
| 2984 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2985 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2986 | |
| 2987 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2988 | move_arg(Statements), |
| 2989 | S->getRBracLoc(), |
| 2990 | IsStmtExpr); |
| 2991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2993 | template<typename Derived> |
| 2994 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 2996 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 2997 | { |
| 2998 | // The case value expressions are not potentially evaluated. |
| 2999 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3001 | // Transform the left-hand case value. |
| 3002 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3003 | if (LHS.isInvalid()) |
| 3004 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3005 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3006 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3007 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3008 | if (RHS.isInvalid()) |
| 3009 | return SemaRef.StmtError(); |
| 3010 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3012 | // Build the case statement. |
| 3013 | // Case statements are always rebuilt so that they will attached to their |
| 3014 | // transformed switch statement. |
| 3015 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3016 | move(LHS), |
| 3017 | S->getEllipsisLoc(), |
| 3018 | move(RHS), |
| 3019 | S->getColonLoc()); |
| 3020 | if (Case.isInvalid()) |
| 3021 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3023 | // Transform the statement following the case |
| 3024 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3025 | if (SubStmt.isInvalid()) |
| 3026 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3028 | // Attach the body to the case statement |
| 3029 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3030 | } |
| 3031 | |
| 3032 | template<typename Derived> |
| 3033 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3035 | // Transform the statement following the default case |
| 3036 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3037 | if (SubStmt.isInvalid()) |
| 3038 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3040 | // Default statements are always rebuilt |
| 3041 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3042 | move(SubStmt)); |
| 3043 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3045 | template<typename Derived> |
| 3046 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3048 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3049 | if (SubStmt.isInvalid()) |
| 3050 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3051 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3052 | // FIXME: Pass the real colon location in. |
| 3053 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3054 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3055 | move(SubStmt)); |
| 3056 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3058 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | Sema::OwningStmtResult |
| 3060 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3061 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3062 | OwningExprResult Cond(SemaRef); |
| 3063 | VarDecl *ConditionVar = 0; |
| 3064 | if (S->getConditionVariable()) { |
| 3065 | ConditionVar |
| 3066 | = cast_or_null<VarDecl>( |
| 3067 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3068 | if (!ConditionVar) |
| 3069 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3070 | } else { |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3071 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3072 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3073 | if (Cond.isInvalid()) |
| 3074 | return SemaRef.StmtError(); |
| 3075 | } |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3076 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3077 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | // Transform the "then" branch. |
| 3080 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3081 | if (Then.isInvalid()) |
| 3082 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3084 | // Transform the "else" branch. |
| 3085 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3086 | if (Else.isInvalid()) |
| 3087 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | if (!getDerived().AlwaysRebuild() && |
| 3090 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3091 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3092 | Then.get() == S->getThen() && |
| 3093 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | return SemaRef.Owned(S->Retain()); |
| 3095 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3096 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3097 | move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | template<typename Derived> |
| 3102 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3104 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3105 | OwningExprResult Cond(SemaRef); |
| 3106 | VarDecl *ConditionVar = 0; |
| 3107 | if (S->getConditionVariable()) { |
| 3108 | ConditionVar |
| 3109 | = cast_or_null<VarDecl>( |
| 3110 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3111 | if (!ConditionVar) |
| 3112 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3113 | } else { |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3114 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3115 | |
| 3116 | if (Cond.isInvalid()) |
| 3117 | return SemaRef.StmtError(); |
| 3118 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3120 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
| 3121 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | // Rebuild the switch statement. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3123 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3124 | ConditionVar); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3125 | if (Switch.isInvalid()) |
| 3126 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Transform the body of the switch statement. |
| 3129 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3130 | if (Body.isInvalid()) |
| 3131 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | // Complete the switch statement. |
| 3134 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3135 | move(Body)); |
| 3136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | template<typename Derived> |
| 3139 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3140 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3141 | // Transform the condition |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3142 | OwningExprResult Cond(SemaRef); |
| 3143 | VarDecl *ConditionVar = 0; |
| 3144 | if (S->getConditionVariable()) { |
| 3145 | ConditionVar |
| 3146 | = cast_or_null<VarDecl>( |
| 3147 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3148 | if (!ConditionVar) |
| 3149 | return SemaRef.StmtError(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3150 | } else { |
Douglas Gregor | 5656e14 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3151 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3152 | |
| 3153 | if (Cond.isInvalid()) |
| 3154 | return SemaRef.StmtError(); |
| 3155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3156 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3157 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | // Transform the body |
| 3160 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3161 | if (Body.isInvalid()) |
| 3162 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3163 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3164 | if (!getDerived().AlwaysRebuild() && |
| 3165 | FullCond->get() == S->getCond() && |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3166 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | return SemaRef.Owned(S->Retain()); |
| 3169 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3170 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3171 | move(Body)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3174 | template<typename Derived> |
| 3175 | Sema::OwningStmtResult |
| 3176 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3177 | // Transform the condition |
| 3178 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3179 | if (Cond.isInvalid()) |
| 3180 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | // Transform the body |
| 3183 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3184 | if (Body.isInvalid()) |
| 3185 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | if (!getDerived().AlwaysRebuild() && |
| 3188 | Cond.get() == S->getCond() && |
| 3189 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | return SemaRef.Owned(S->Retain()); |
| 3191 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3192 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3193 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3194 | S->getRParenLoc()); |
| 3195 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3197 | template<typename Derived> |
| 3198 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3200 | // Transform the initialization statement |
| 3201 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3202 | if (Init.isInvalid()) |
| 3203 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | // Transform the condition |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3206 | OwningExprResult Cond(SemaRef); |
| 3207 | VarDecl *ConditionVar = 0; |
| 3208 | if (S->getConditionVariable()) { |
| 3209 | ConditionVar |
| 3210 | = cast_or_null<VarDecl>( |
| 3211 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3212 | if (!ConditionVar) |
| 3213 | return SemaRef.StmtError(); |
| 3214 | } else { |
| 3215 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3216 | |
| 3217 | if (Cond.isInvalid()) |
| 3218 | return SemaRef.StmtError(); |
| 3219 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | // Transform the increment |
| 3222 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3223 | if (Inc.isInvalid()) |
| 3224 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3226 | // Transform the body |
| 3227 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3228 | if (Body.isInvalid()) |
| 3229 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | if (!getDerived().AlwaysRebuild() && |
| 3232 | Init.get() == S->getInit() && |
| 3233 | Cond.get() == S->getCond() && |
| 3234 | Inc.get() == S->getInc() && |
| 3235 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | return SemaRef.Owned(S->Retain()); |
| 3237 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3238 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3239 | move(Init), getSema().FullExpr(Cond), |
| 3240 | ConditionVar, |
| 3241 | getSema().FullExpr(Inc), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | S->getRParenLoc(), move(Body)); |
| 3243 | } |
| 3244 | |
| 3245 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | Sema::OwningStmtResult |
| 3247 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3250 | S->getLabel()); |
| 3251 | } |
| 3252 | |
| 3253 | template<typename Derived> |
| 3254 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3257 | if (Target.isInvalid()) |
| 3258 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3259 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3260 | if (!getDerived().AlwaysRebuild() && |
| 3261 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | |
| 3264 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3265 | move(Target)); |
| 3266 | } |
| 3267 | |
| 3268 | template<typename Derived> |
| 3269 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3271 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3272 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | template<typename Derived> |
| 3275 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3277 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | template<typename Derived> |
| 3281 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3284 | if (Result.isInvalid()) |
| 3285 | return SemaRef.StmtError(); |
| 3286 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3288 | // to tell whether the return type of the function has changed. |
| 3289 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | template<typename Derived> |
| 3293 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3294 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3295 | bool DeclChanged = false; |
| 3296 | llvm::SmallVector<Decl *, 4> Decls; |
| 3297 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3298 | D != DEnd; ++D) { |
| 3299 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3300 | if (!Transformed) |
| 3301 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3303 | if (Transformed != *D) |
| 3304 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3306 | Decls.push_back(Transformed); |
| 3307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | return SemaRef.Owned(S->Retain()); |
| 3311 | |
| 3312 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3313 | S->getStartLoc(), S->getEndLoc()); |
| 3314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3316 | template<typename Derived> |
| 3317 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3318 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3319 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | template<typename Derived> |
| 3324 | Sema::OwningStmtResult |
| 3325 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3326 | // FIXME: Implement! |
| 3327 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | |
| 3332 | template<typename Derived> |
| 3333 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | // FIXME: Implement this |
| 3336 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3339 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3340 | template<typename Derived> |
| 3341 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | // FIXME: Implement this |
| 3344 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3345 | return SemaRef.Owned(S->Retain()); |
| 3346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3347 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3348 | template<typename Derived> |
| 3349 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | // FIXME: Implement this |
| 3352 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | template<typename Derived> |
| 3357 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | // FIXME: Implement this |
| 3360 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3363 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3364 | template<typename Derived> |
| 3365 | Sema::OwningStmtResult |
| 3366 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | // FIXME: Implement this |
| 3369 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | template<typename Derived> |
| 3374 | Sema::OwningStmtResult |
| 3375 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3377 | // FIXME: Implement this |
| 3378 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | template<typename Derived> |
| 3384 | Sema::OwningStmtResult |
| 3385 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3386 | // Transform the exception declaration, if any. |
| 3387 | VarDecl *Var = 0; |
| 3388 | if (S->getExceptionDecl()) { |
| 3389 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3390 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3391 | ExceptionDecl->getDeclName()); |
| 3392 | |
| 3393 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3394 | if (T.isNull()) |
| 3395 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3396 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3397 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3398 | T, |
| 3399 | ExceptionDecl->getDeclaratorInfo(), |
| 3400 | ExceptionDecl->getIdentifier(), |
| 3401 | ExceptionDecl->getLocation(), |
| 3402 | /*FIXME: Inaccurate*/ |
| 3403 | SourceRange(ExceptionDecl->getLocation())); |
| 3404 | if (!Var || Var->isInvalidDecl()) { |
| 3405 | if (Var) |
| 3406 | Var->Destroy(SemaRef.Context); |
| 3407 | return SemaRef.StmtError(); |
| 3408 | } |
| 3409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3411 | // Transform the actual exception handler. |
| 3412 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3413 | if (Handler.isInvalid()) { |
| 3414 | if (Var) |
| 3415 | Var->Destroy(SemaRef.Context); |
| 3416 | return SemaRef.StmtError(); |
| 3417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3418 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3419 | if (!getDerived().AlwaysRebuild() && |
| 3420 | !Var && |
| 3421 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3422 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3423 | |
| 3424 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3425 | Var, |
| 3426 | move(Handler)); |
| 3427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | template<typename Derived> |
| 3430 | Sema::OwningStmtResult |
| 3431 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3432 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3435 | if (TryBlock.isInvalid()) |
| 3436 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | // Transform the handlers. |
| 3439 | bool HandlerChanged = false; |
| 3440 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3441 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3443 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3444 | if (Handler.isInvalid()) |
| 3445 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3447 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3448 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3449 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3450 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3451 | if (!getDerived().AlwaysRebuild() && |
| 3452 | TryBlock.get() == S->getTryBlock() && |
| 3453 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | |
| 3456 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3457 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3458 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3459 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3460 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3461 | // Expression transformation |
| 3462 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
| 3464 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3465 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E, |
| 3466 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3467 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | |
| 3470 | template<typename Derived> |
| 3471 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3472 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E, |
| 3473 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3474 | NestedNameSpecifier *Qualifier = 0; |
| 3475 | if (E->getQualifier()) { |
| 3476 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3477 | E->getQualifierRange()); |
| 3478 | if (!Qualifier) |
| 3479 | return SemaRef.ExprError(); |
| 3480 | } |
| 3481 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | NamedDecl *ND |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3483 | = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); |
| 3484 | if (!ND) |
| 3485 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3487 | if (!getDerived().AlwaysRebuild() && |
| 3488 | Qualifier == E->getQualifier() && |
| 3489 | ND == E->getDecl() && |
| 3490 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3491 | return SemaRef.Owned(E->Retain()); |
| 3492 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3493 | // FIXME: We're losing the explicit template arguments in this transformation. |
| 3494 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3495 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3496 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3497 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3498 | TransArgs[I])) |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3499 | return SemaRef.ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | // FIXME: Pass the qualifier/qualifier range along. |
| 3503 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3504 | ND, E->getLocation(), |
| 3505 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3506 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3508 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3509 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3510 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E, |
| 3511 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3513 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3515 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3517 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E, |
| 3518 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3520 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3522 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3524 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E, |
| 3525 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3527 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3529 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3531 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E, |
| 3532 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3536 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3538 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E, |
| 3539 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | return SemaRef.Owned(E->Retain()); |
| 3541 | } |
| 3542 | |
| 3543 | template<typename Derived> |
| 3544 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3545 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E, |
| 3546 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3547 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3548 | if (SubExpr.isInvalid()) |
| 3549 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3550 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3551 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3552 | return SemaRef.Owned(E->Retain()); |
| 3553 | |
| 3554 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3555 | E->getRParen()); |
| 3556 | } |
| 3557 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3558 | template<typename Derived> |
| 3559 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3560 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E, |
| 3561 | bool isAddressOfOperand) { |
| 3562 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(), |
| 3563 | E->getOpcode() == UnaryOperator::AddrOf); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3564 | if (SubExpr.isInvalid()) |
| 3565 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3566 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3567 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3568 | return SemaRef.Owned(E->Retain()); |
| 3569 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3570 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3571 | E->getOpcode(), |
| 3572 | move(SubExpr)); |
| 3573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3575 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3577 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, |
| 3578 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3579 | if (E->isArgumentType()) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3580 | DeclaratorInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3581 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3582 | DeclaratorInfo *NewT = getDerived().TransformType(OldT); |
| 3583 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3584 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3586 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3587 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3589 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3591 | E->getSourceRange()); |
| 3592 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3593 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3594 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3596 | // C++0x [expr.sizeof]p1: |
| 3597 | // The operand is either an expression, which is an unevaluated operand |
| 3598 | // [...] |
| 3599 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3600 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3601 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3602 | if (SubExpr.isInvalid()) |
| 3603 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3605 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3606 | return SemaRef.Owned(E->Retain()); |
| 3607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3609 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3610 | E->isSizeOf(), |
| 3611 | E->getSourceRange()); |
| 3612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3613 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3614 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3616 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E, |
| 3617 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3619 | if (LHS.isInvalid()) |
| 3620 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3622 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3623 | if (RHS.isInvalid()) |
| 3624 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | |
| 3626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3627 | if (!getDerived().AlwaysRebuild() && |
| 3628 | LHS.get() == E->getLHS() && |
| 3629 | RHS.get() == E->getRHS()) |
| 3630 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3633 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3634 | move(RHS), |
| 3635 | E->getRBracketLoc()); |
| 3636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | |
| 3638 | template<typename Derived> |
| 3639 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3640 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E, |
| 3641 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3642 | // Transform the callee. |
| 3643 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3644 | if (Callee.isInvalid()) |
| 3645 | return SemaRef.ExprError(); |
| 3646 | |
| 3647 | // Transform arguments. |
| 3648 | bool ArgChanged = false; |
| 3649 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3650 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3651 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3652 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3653 | if (Arg.isInvalid()) |
| 3654 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | // FIXME: Wrong source location information for the ','. |
| 3657 | FakeCommaLocs.push_back( |
| 3658 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | |
| 3660 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | Args.push_back(Arg.takeAs<Expr>()); |
| 3662 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3664 | if (!getDerived().AlwaysRebuild() && |
| 3665 | Callee.get() == E->getCallee() && |
| 3666 | !ArgChanged) |
| 3667 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3668 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3669 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3670 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3671 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3672 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3673 | move_arg(Args), |
| 3674 | FakeCommaLocs.data(), |
| 3675 | E->getRParenLoc()); |
| 3676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
| 3678 | template<typename Derived> |
| 3679 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3680 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E, |
| 3681 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3682 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3683 | if (Base.isInvalid()) |
| 3684 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3686 | NestedNameSpecifier *Qualifier = 0; |
| 3687 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3689 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3690 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3691 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3692 | return SemaRef.ExprError(); |
| 3693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | |
| 3695 | NamedDecl *Member |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
| 3697 | if (!Member) |
| 3698 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3700 | if (!getDerived().AlwaysRebuild() && |
| 3701 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3702 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3703 | Member == E->getMemberDecl() && |
| 3704 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3706 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3707 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3708 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3709 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3710 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3711 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3712 | TemplateArgumentLoc Loc; |
| 3713 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3714 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3715 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3716 | } |
| 3717 | } |
| 3718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3719 | // FIXME: Bogus source location for the operator |
| 3720 | SourceLocation FakeOperatorLoc |
| 3721 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3722 | |
| 3723 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3724 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3725 | Qualifier, |
| 3726 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3728 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3729 | (E->hasExplicitTemplateArgumentList() |
| 3730 | ? &TransArgs : 0), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3731 | 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3732 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3733 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3734 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3735 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3736 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E, |
| 3737 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | assert(false && "Cannot transform abstract class"); |
| 3739 | return SemaRef.Owned(E->Retain()); |
| 3740 | } |
| 3741 | |
| 3742 | template<typename Derived> |
| 3743 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3744 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E, |
| 3745 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3747 | if (LHS.isInvalid()) |
| 3748 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3750 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3751 | if (RHS.isInvalid()) |
| 3752 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | if (!getDerived().AlwaysRebuild() && |
| 3755 | LHS.get() == E->getLHS() && |
| 3756 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3757 | return SemaRef.Owned(E->Retain()); |
| 3758 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3759 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3760 | move(LHS), move(RHS)); |
| 3761 | } |
| 3762 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3764 | Sema::OwningExprResult |
| 3765 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3766 | CompoundAssignOperator *E, |
| 3767 | bool isAddressOfOperand) { |
| 3768 | return getDerived().TransformBinaryOperator(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3769 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3770 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3771 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3773 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E, |
| 3774 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3775 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3776 | if (Cond.isInvalid()) |
| 3777 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3778 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3779 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3780 | if (LHS.isInvalid()) |
| 3781 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3783 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3784 | if (RHS.isInvalid()) |
| 3785 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3787 | if (!getDerived().AlwaysRebuild() && |
| 3788 | Cond.get() == E->getCond() && |
| 3789 | LHS.get() == E->getLHS() && |
| 3790 | RHS.get() == E->getRHS()) |
| 3791 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
| 3793 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3794 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3795 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3796 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3797 | move(RHS)); |
| 3798 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
| 3800 | template<typename Derived> |
| 3801 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3802 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E, |
| 3803 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3804 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3805 | |
| 3806 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3807 | // so do we even need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3808 | QualType T = getDerived().TransformType(E->getType()); |
| 3809 | if (T.isNull()) |
| 3810 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3812 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3813 | if (SubExpr.isInvalid()) |
| 3814 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3816 | if (!getDerived().AlwaysRebuild() && |
| 3817 | T == E->getType() && |
| 3818 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | return SemaRef.Owned(E->Retain()); |
| 3820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3821 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3823 | E->isLvalueCast()); |
| 3824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3826 | template<typename Derived> |
| 3827 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3828 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E, |
| 3829 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | assert(false && "Cannot transform abstract class"); |
| 3831 | return SemaRef.Owned(E->Retain()); |
| 3832 | } |
| 3833 | |
| 3834 | template<typename Derived> |
| 3835 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3836 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E, |
| 3837 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3838 | QualType T; |
| 3839 | { |
| 3840 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3843 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3846 | if (T.isNull()) |
| 3847 | return SemaRef.ExprError(); |
| 3848 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3850 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3851 | if (SubExpr.isInvalid()) |
| 3852 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | if (!getDerived().AlwaysRebuild() && |
| 3855 | T == E->getTypeAsWritten() && |
| 3856 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | return SemaRef.Owned(E->Retain()); |
| 3858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3860 | E->getRParenLoc(), |
| 3861 | move(SubExpr)); |
| 3862 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3865 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3866 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E, |
| 3867 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | QualType T; |
| 3869 | { |
| 3870 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | SourceLocation FakeTypeLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3873 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | T = getDerived().TransformType(E->getType()); |
| 3876 | if (T.isNull()) |
| 3877 | return SemaRef.ExprError(); |
| 3878 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3880 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3881 | if (Init.isInvalid()) |
| 3882 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | if (!getDerived().AlwaysRebuild() && |
| 3885 | T == E->getType() && |
| 3886 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3887 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3888 | |
| 3889 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3890 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3891 | move(Init)); |
| 3892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | template<typename Derived> |
| 3895 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3896 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E, |
| 3897 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3899 | if (Base.isInvalid()) |
| 3900 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | if (!getDerived().AlwaysRebuild() && |
| 3903 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | return SemaRef.Owned(E->Retain()); |
| 3905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3909 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3910 | E->getAccessorLoc(), |
| 3911 | E->getAccessor()); |
| 3912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3913 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3914 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3916 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E, |
| 3917 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3918 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3921 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3922 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3923 | if (Init.isInvalid()) |
| 3924 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3925 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3927 | Inits.push_back(Init.takeAs<Expr>()); |
| 3928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3929 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3931 | return SemaRef.Owned(E->Retain()); |
| 3932 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3933 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3934 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3935 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3936 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3937 | template<typename Derived> |
| 3938 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3939 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E, |
| 3940 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3941 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3943 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3945 | if (Init.isInvalid()) |
| 3946 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3947 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3948 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3949 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3950 | bool ExprChanged = false; |
| 3951 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3952 | DEnd = E->designators_end(); |
| 3953 | D != DEnd; ++D) { |
| 3954 | if (D->isFieldDesignator()) { |
| 3955 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3956 | D->getDotLoc(), |
| 3957 | D->getFieldLoc())); |
| 3958 | continue; |
| 3959 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | if (D->isArrayDesignator()) { |
| 3962 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3963 | if (Index.isInvalid()) |
| 3964 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
| 3966 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3967 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3970 | ArrayExprs.push_back(Index.release()); |
| 3971 | continue; |
| 3972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3973 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3974 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3975 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3976 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3977 | if (Start.isInvalid()) |
| 3978 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3981 | if (End.isInvalid()) |
| 3982 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
| 3984 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | End.get(), |
| 3986 | D->getLBracketLoc(), |
| 3987 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3990 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3991 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3992 | ArrayExprs.push_back(Start.release()); |
| 3993 | ArrayExprs.push_back(End.release()); |
| 3994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3996 | if (!getDerived().AlwaysRebuild() && |
| 3997 | Init.get() == E->getInit() && |
| 3998 | !ExprChanged) |
| 3999 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4002 | E->getEqualOrColonLoc(), |
| 4003 | E->usesGNUSyntax(), move(Init)); |
| 4004 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4005 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4006 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4008 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4009 | ImplicitValueInitExpr *E, |
| 4010 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4011 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4012 | |
| 4013 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4014 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | QualType T = getDerived().TransformType(E->getType()); |
| 4016 | if (T.isNull()) |
| 4017 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4018 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4019 | if (!getDerived().AlwaysRebuild() && |
| 4020 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4021 | return SemaRef.Owned(E->Retain()); |
| 4022 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4023 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4024 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4026 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4028 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E, |
| 4029 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4030 | // FIXME: Do we want the type as written? |
| 4031 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | { |
| 4034 | // FIXME: Source location isn't quite accurate. |
| 4035 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4036 | T = getDerived().TransformType(E->getType()); |
| 4037 | if (T.isNull()) |
| 4038 | return SemaRef.ExprError(); |
| 4039 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4041 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4042 | if (SubExpr.isInvalid()) |
| 4043 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4045 | if (!getDerived().AlwaysRebuild() && |
| 4046 | T == E->getType() && |
| 4047 | SubExpr.get() == E->getSubExpr()) |
| 4048 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4049 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4050 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4051 | T, E->getRParenLoc()); |
| 4052 | } |
| 4053 | |
| 4054 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4055 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4056 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E, |
| 4057 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4058 | bool ArgumentChanged = false; |
| 4059 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4060 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4061 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4062 | if (Init.isInvalid()) |
| 4063 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4064 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4065 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4066 | Inits.push_back(Init.takeAs<Expr>()); |
| 4067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4070 | move_arg(Inits), |
| 4071 | E->getRParenLoc()); |
| 4072 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4074 | /// \brief Transform an address-of-label expression. |
| 4075 | /// |
| 4076 | /// By default, the transformation of an address-of-label expression always |
| 4077 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4078 | /// the corresponding label statement by semantic analysis. |
| 4079 | template<typename Derived> |
| 4080 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4081 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E, |
| 4082 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4083 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4084 | E->getLabel()); |
| 4085 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4086 | |
| 4087 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4088 | Sema::OwningExprResult |
| 4089 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E, |
| 4090 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4092 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4093 | if (SubStmt.isInvalid()) |
| 4094 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4095 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4096 | if (!getDerived().AlwaysRebuild() && |
| 4097 | SubStmt.get() == E->getSubStmt()) |
| 4098 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
| 4100 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4101 | move(SubStmt), |
| 4102 | E->getRParenLoc()); |
| 4103 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4104 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4105 | template<typename Derived> |
| 4106 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4107 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E, |
| 4108 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4109 | QualType T1, T2; |
| 4110 | { |
| 4111 | // FIXME: Source location isn't quite accurate. |
| 4112 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4115 | if (T1.isNull()) |
| 4116 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4117 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4119 | if (T2.isNull()) |
| 4120 | return SemaRef.ExprError(); |
| 4121 | } |
| 4122 | |
| 4123 | if (!getDerived().AlwaysRebuild() && |
| 4124 | T1 == E->getArgType1() && |
| 4125 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | return SemaRef.Owned(E->Retain()); |
| 4127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4129 | T1, T2, E->getRParenLoc()); |
| 4130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | template<typename Derived> |
| 4133 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4134 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E, |
| 4135 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4136 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4137 | if (Cond.isInvalid()) |
| 4138 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4139 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4140 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4141 | if (LHS.isInvalid()) |
| 4142 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4143 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4144 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4145 | if (RHS.isInvalid()) |
| 4146 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4148 | if (!getDerived().AlwaysRebuild() && |
| 4149 | Cond.get() == E->getCond() && |
| 4150 | LHS.get() == E->getLHS() && |
| 4151 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | return SemaRef.Owned(E->Retain()); |
| 4153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4155 | move(Cond), move(LHS), move(RHS), |
| 4156 | E->getRParenLoc()); |
| 4157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4161 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E, |
| 4162 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | template<typename Derived> |
| 4167 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4168 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E, |
| 4169 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4170 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4171 | if (Callee.isInvalid()) |
| 4172 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4174 | OwningExprResult First |
| 4175 | = getDerived().TransformExpr(E->getArg(0), |
| 4176 | E->getNumArgs() == 1 && E->getOperator() == OO_Amp); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4177 | if (First.isInvalid()) |
| 4178 | return SemaRef.ExprError(); |
| 4179 | |
| 4180 | OwningExprResult Second(SemaRef); |
| 4181 | if (E->getNumArgs() == 2) { |
| 4182 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4183 | if (Second.isInvalid()) |
| 4184 | return SemaRef.ExprError(); |
| 4185 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4186 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4187 | if (!getDerived().AlwaysRebuild() && |
| 4188 | Callee.get() == E->getCallee() && |
| 4189 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4190 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4191 | return SemaRef.Owned(E->Retain()); |
| 4192 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4194 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4195 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4196 | move(First), |
| 4197 | move(Second)); |
| 4198 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | template<typename Derived> |
| 4201 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4202 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E, |
| 4203 | bool isAddressOfOperand) { |
| 4204 | return getDerived().TransformCallExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4205 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4208 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4209 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E, |
| 4210 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4211 | QualType ExplicitTy; |
| 4212 | { |
| 4213 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4216 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4219 | if (ExplicitTy.isNull()) |
| 4220 | return SemaRef.ExprError(); |
| 4221 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4223 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4224 | if (SubExpr.isInvalid()) |
| 4225 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | if (!getDerived().AlwaysRebuild() && |
| 4228 | ExplicitTy == E->getTypeAsWritten() && |
| 4229 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | return SemaRef.Owned(E->Retain()); |
| 4231 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4234 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4235 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4236 | SourceLocation FakeRParenLoc |
| 4237 | = SemaRef.PP.getLocForEndOfToken( |
| 4238 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4239 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | FakeLAngleLoc, |
| 4242 | ExplicitTy, |
| 4243 | FakeRAngleLoc, |
| 4244 | FakeRAngleLoc, |
| 4245 | move(SubExpr), |
| 4246 | FakeRParenLoc); |
| 4247 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4248 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | template<typename Derived> |
| 4250 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4251 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E, |
| 4252 | bool isAddressOfOperand) { |
| 4253 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4255 | |
| 4256 | template<typename Derived> |
| 4257 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4258 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E, |
| 4259 | bool isAddressOfOperand) { |
| 4260 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | } |
| 4262 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | template<typename Derived> |
| 4264 | Sema::OwningExprResult |
| 4265 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4266 | CXXReinterpretCastExpr *E, |
| 4267 | bool isAddressOfOperand) { |
| 4268 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4269 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | template<typename Derived> |
| 4272 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4273 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E, |
| 4274 | bool isAddressOfOperand) { |
| 4275 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4276 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4277 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | template<typename Derived> |
| 4279 | Sema::OwningExprResult |
| 4280 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4281 | CXXFunctionalCastExpr *E, |
| 4282 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | QualType ExplicitTy; |
| 4284 | { |
| 4285 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4286 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4287 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4288 | if (ExplicitTy.isNull()) |
| 4289 | return SemaRef.ExprError(); |
| 4290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4292 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4293 | if (SubExpr.isInvalid()) |
| 4294 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | if (!getDerived().AlwaysRebuild() && |
| 4297 | ExplicitTy == E->getTypeAsWritten() && |
| 4298 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4299 | return SemaRef.Owned(E->Retain()); |
| 4300 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | // FIXME: The end of the type's source range is wrong |
| 4302 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4303 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4304 | ExplicitTy, |
| 4305 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4306 | move(SubExpr), |
| 4307 | E->getRParenLoc()); |
| 4308 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | template<typename Derived> |
| 4311 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4312 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E, |
| 4313 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4314 | if (E->isTypeOperand()) { |
| 4315 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4317 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4318 | if (T.isNull()) |
| 4319 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | if (!getDerived().AlwaysRebuild() && |
| 4322 | T == E->getTypeOperand()) |
| 4323 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4324 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4325 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4326 | /*FIXME:*/E->getLocStart(), |
| 4327 | T, |
| 4328 | E->getLocEnd()); |
| 4329 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | // We don't know whether the expression is potentially evaluated until |
| 4332 | // after we perform semantic analysis, so the expression is potentially |
| 4333 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4336 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4338 | if (SubExpr.isInvalid()) |
| 4339 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4340 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4341 | if (!getDerived().AlwaysRebuild() && |
| 4342 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4343 | return SemaRef.Owned(E->Retain()); |
| 4344 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4346 | /*FIXME:*/E->getLocStart(), |
| 4347 | move(SubExpr), |
| 4348 | E->getLocEnd()); |
| 4349 | } |
| 4350 | |
| 4351 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4353 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E, |
| 4354 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | template<typename Derived> |
| 4359 | Sema::OwningExprResult |
| 4360 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4361 | CXXNullPtrLiteralExpr *E, |
| 4362 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4366 | template<typename Derived> |
| 4367 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4368 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E, |
| 4369 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | QualType T = getDerived().TransformType(E->getType()); |
| 4373 | if (T.isNull()) |
| 4374 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4375 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4376 | if (!getDerived().AlwaysRebuild() && |
| 4377 | T == E->getType()) |
| 4378 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4382 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4383 | template<typename Derived> |
| 4384 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4385 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E, |
| 4386 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4387 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4388 | if (SubExpr.isInvalid()) |
| 4389 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4390 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4391 | if (!getDerived().AlwaysRebuild() && |
| 4392 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | |
| 4395 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | template<typename Derived> |
| 4399 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4400 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E, |
| 4401 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4403 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4404 | if (!Param) |
| 4405 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4407 | if (getDerived().AlwaysRebuild() && |
| 4408 | Param == E->getParam()) |
| 4409 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | template<typename Derived> |
| 4415 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4416 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E, |
| 4417 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4419 | |
| 4420 | QualType T = getDerived().TransformType(E->getType()); |
| 4421 | if (T.isNull()) |
| 4422 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4423 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4424 | if (!getDerived().AlwaysRebuild() && |
| 4425 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | return SemaRef.Owned(E->Retain()); |
| 4427 | |
| 4428 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4430 | T, |
| 4431 | E->getRParenLoc()); |
| 4432 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4434 | template<typename Derived> |
| 4435 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4436 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E, |
| 4437 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | // Transform the type that we're allocating |
| 4439 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4440 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4441 | if (AllocType.isNull()) |
| 4442 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4443 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | // Transform the size of the array we're allocating (if any). |
| 4445 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4446 | if (ArraySize.isInvalid()) |
| 4447 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4448 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4449 | // Transform the placement arguments (if any). |
| 4450 | bool ArgumentChanged = false; |
| 4451 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4452 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4453 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4454 | if (Arg.isInvalid()) |
| 4455 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4457 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4458 | PlacementArgs.push_back(Arg.take()); |
| 4459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4461 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4463 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4464 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4465 | if (Arg.isInvalid()) |
| 4466 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4467 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4468 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4469 | ConstructorArgs.push_back(Arg.take()); |
| 4470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | if (!getDerived().AlwaysRebuild() && |
| 4473 | AllocType == E->getAllocatedType() && |
| 4474 | ArraySize.get() == E->getArraySize() && |
| 4475 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | return SemaRef.Owned(E->Retain()); |
| 4477 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4479 | E->isGlobalNew(), |
| 4480 | /*FIXME:*/E->getLocStart(), |
| 4481 | move_arg(PlacementArgs), |
| 4482 | /*FIXME:*/E->getLocStart(), |
| 4483 | E->isParenTypeId(), |
| 4484 | AllocType, |
| 4485 | /*FIXME:*/E->getLocStart(), |
| 4486 | /*FIXME:*/SourceRange(), |
| 4487 | move(ArraySize), |
| 4488 | /*FIXME:*/E->getLocStart(), |
| 4489 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4492 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4493 | template<typename Derived> |
| 4494 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4495 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E, |
| 4496 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4498 | if (Operand.isInvalid()) |
| 4499 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4502 | Operand.get() == E->getArgument()) |
| 4503 | return SemaRef.Owned(E->Retain()); |
| 4504 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4506 | E->isGlobalDelete(), |
| 4507 | E->isArrayForm(), |
| 4508 | move(Operand)); |
| 4509 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | template<typename Derived> |
| 4512 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4513 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4514 | CXXPseudoDestructorExpr *E, |
| 4515 | bool isAddressOfOperand) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4516 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4517 | if (Base.isInvalid()) |
| 4518 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4519 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4520 | NestedNameSpecifier *Qualifier |
| 4521 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4522 | E->getQualifierRange()); |
| 4523 | if (E->getQualifier() && !Qualifier) |
| 4524 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4526 | QualType DestroyedType; |
| 4527 | { |
| 4528 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4529 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4530 | if (DestroyedType.isNull()) |
| 4531 | return SemaRef.ExprError(); |
| 4532 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4534 | if (!getDerived().AlwaysRebuild() && |
| 4535 | Base.get() == E->getBase() && |
| 4536 | Qualifier == E->getQualifier() && |
| 4537 | DestroyedType == E->getDestroyedType()) |
| 4538 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4540 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4541 | E->getOperatorLoc(), |
| 4542 | E->isArrow(), |
| 4543 | E->getDestroyedTypeLoc(), |
| 4544 | DestroyedType, |
| 4545 | Qualifier, |
| 4546 | E->getQualifierRange()); |
| 4547 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4549 | template<typename Derived> |
| 4550 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4551 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4552 | UnresolvedLookupExpr *Old, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4553 | bool isAddressOfOperand) { |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4554 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4555 | |
| 4556 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4557 | Sema::LookupOrdinaryName); |
| 4558 | |
| 4559 | // Transform all the decls. |
| 4560 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4561 | E = Old->decls_end(); I != E; ++I) { |
| 4562 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
| 4563 | if (!InstD) |
| 4564 | return SemaRef.ExprError(); |
| 4565 | |
| 4566 | // Expand using declarations. |
| 4567 | if (isa<UsingDecl>(InstD)) { |
| 4568 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4569 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4570 | E = UD->shadow_end(); I != E; ++I) |
| 4571 | R.addDecl(*I); |
| 4572 | continue; |
| 4573 | } |
| 4574 | |
| 4575 | R.addDecl(InstD); |
| 4576 | } |
| 4577 | |
| 4578 | // Resolve a kind, but don't do any further analysis. If it's |
| 4579 | // ambiguous, the callee needs to deal with it. |
| 4580 | R.resolveKind(); |
| 4581 | |
| 4582 | // Rebuild the nested-name qualifier, if present. |
| 4583 | CXXScopeSpec SS; |
| 4584 | NestedNameSpecifier *Qualifier = 0; |
| 4585 | if (Old->getQualifier()) { |
| 4586 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4587 | Old->getQualifierRange()); |
| 4588 | if (!Qualifier) |
| 4589 | return SemaRef.ExprError(); |
| 4590 | |
| 4591 | SS.setScopeRep(Qualifier); |
| 4592 | SS.setRange(Old->getQualifierRange()); |
| 4593 | } |
| 4594 | |
| 4595 | // If we have no template arguments, it's a normal declaration name. |
| 4596 | if (!Old->hasExplicitTemplateArgs()) |
| 4597 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4598 | |
| 4599 | // If we have template arguments, rebuild them, then rebuild the |
| 4600 | // templateid expression. |
| 4601 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4602 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4603 | TemplateArgumentLoc Loc; |
| 4604 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4605 | return SemaRef.ExprError(); |
| 4606 | TransArgs.addArgument(Loc); |
| 4607 | } |
| 4608 | |
| 4609 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4610 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4613 | template<typename Derived> |
| 4614 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4615 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E, |
| 4616 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4618 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4620 | if (T.isNull()) |
| 4621 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4623 | if (!getDerived().AlwaysRebuild() && |
| 4624 | T == E->getQueriedType()) |
| 4625 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4627 | // FIXME: Bad location information |
| 4628 | SourceLocation FakeLParenLoc |
| 4629 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4630 | |
| 4631 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4632 | E->getLocStart(), |
| 4633 | /*FIXME:*/FakeLParenLoc, |
| 4634 | T, |
| 4635 | E->getLocEnd()); |
| 4636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4637 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | template<typename Derived> |
| 4639 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4640 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 4641 | DependentScopeDeclRefExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4642 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4643 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4644 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4645 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | if (!NNS) |
| 4647 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4648 | |
| 4649 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4650 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4651 | if (!Name) |
| 4652 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4654 | if (!E->hasExplicitTemplateArgs()) { |
| 4655 | if (!getDerived().AlwaysRebuild() && |
| 4656 | NNS == E->getQualifier() && |
| 4657 | Name == E->getDeclName()) |
| 4658 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4659 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4660 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4661 | E->getQualifierRange(), |
| 4662 | Name, E->getLocation(), |
| 4663 | /*TemplateArgs*/ 0); |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4664 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4665 | |
| 4666 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4667 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4668 | TemplateArgumentLoc Loc; |
| 4669 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4670 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4671 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
John McCall | f7a1a74 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4674 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4675 | E->getQualifierRange(), |
| 4676 | Name, E->getLocation(), |
| 4677 | &TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | template<typename Derived> |
| 4681 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4682 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E, |
| 4683 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4684 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4685 | |
| 4686 | QualType T = getDerived().TransformType(E->getType()); |
| 4687 | if (T.isNull()) |
| 4688 | return SemaRef.ExprError(); |
| 4689 | |
| 4690 | CXXConstructorDecl *Constructor |
| 4691 | = cast_or_null<CXXConstructorDecl>( |
| 4692 | getDerived().TransformDecl(E->getConstructor())); |
| 4693 | if (!Constructor) |
| 4694 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4696 | bool ArgumentChanged = false; |
| 4697 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4699 | ArgEnd = E->arg_end(); |
| 4700 | Arg != ArgEnd; ++Arg) { |
| 4701 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4702 | if (TransArg.isInvalid()) |
| 4703 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4706 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4707 | } |
| 4708 | |
| 4709 | if (!getDerived().AlwaysRebuild() && |
| 4710 | T == E->getType() && |
| 4711 | Constructor == E->getConstructor() && |
| 4712 | !ArgumentChanged) |
| 4713 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4716 | move_arg(Args)); |
| 4717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | /// \brief Transform a C++ temporary-binding expression. |
| 4720 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | /// The transformation of a temporary-binding expression always attempts to |
| 4722 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | /// subexpression itself did not change, because the temporary variable itself |
| 4724 | /// must be unique. |
| 4725 | template<typename Derived> |
| 4726 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4727 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E, |
| 4728 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4730 | if (SubExpr.isInvalid()) |
| 4731 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4733 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | |
| 4736 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4737 | /// be destroyed after the expression is evaluated. |
| 4738 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4739 | /// The transformation of a full expression always attempts to build a new |
| 4740 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4741 | /// subexpression itself did not change, because it will need to capture the |
| 4742 | /// the new temporary variables introduced in the subexpression. |
| 4743 | template<typename Derived> |
| 4744 | Sema::OwningExprResult |
| 4745 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4746 | CXXExprWithTemporaries *E, |
| 4747 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4749 | if (SubExpr.isInvalid()) |
| 4750 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4752 | return SemaRef.Owned( |
| 4753 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4754 | E->shouldDestroyTemporaries())); |
| 4755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4756 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4757 | template<typename Derived> |
| 4758 | Sema::OwningExprResult |
| 4759 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4760 | CXXTemporaryObjectExpr *E, |
| 4761 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4763 | QualType T = getDerived().TransformType(E->getType()); |
| 4764 | if (T.isNull()) |
| 4765 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | CXXConstructorDecl *Constructor |
| 4768 | = cast_or_null<CXXConstructorDecl>( |
| 4769 | getDerived().TransformDecl(E->getConstructor())); |
| 4770 | if (!Constructor) |
| 4771 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | bool ArgumentChanged = false; |
| 4774 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4775 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4776 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4777 | ArgEnd = E->arg_end(); |
| 4778 | Arg != ArgEnd; ++Arg) { |
| 4779 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4780 | if (TransArg.isInvalid()) |
| 4781 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4783 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4784 | Args.push_back((Expr *)TransArg.release()); |
| 4785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | if (!getDerived().AlwaysRebuild() && |
| 4788 | T == E->getType() && |
| 4789 | Constructor == E->getConstructor() && |
| 4790 | !ArgumentChanged) |
| 4791 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4792 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4793 | // FIXME: Bogus location information |
| 4794 | SourceLocation CommaLoc; |
| 4795 | if (Args.size() > 1) { |
| 4796 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4798 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4799 | } |
| 4800 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4801 | T, |
| 4802 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4803 | move_arg(Args), |
| 4804 | &CommaLoc, |
| 4805 | E->getLocEnd()); |
| 4806 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4807 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4808 | template<typename Derived> |
| 4809 | Sema::OwningExprResult |
| 4810 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4811 | CXXUnresolvedConstructExpr *E, |
| 4812 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4813 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4814 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4815 | if (T.isNull()) |
| 4816 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4818 | bool ArgumentChanged = false; |
| 4819 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4820 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4821 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4822 | ArgEnd = E->arg_end(); |
| 4823 | Arg != ArgEnd; ++Arg) { |
| 4824 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4825 | if (TransArg.isInvalid()) |
| 4826 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4828 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4829 | FakeCommaLocs.push_back( |
| 4830 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4831 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | if (!getDerived().AlwaysRebuild() && |
| 4835 | T == E->getTypeAsWritten() && |
| 4836 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | return SemaRef.Owned(E->Retain()); |
| 4838 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | // FIXME: we're faking the locations of the commas |
| 4840 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4841 | T, |
| 4842 | E->getLParenLoc(), |
| 4843 | move_arg(Args), |
| 4844 | FakeCommaLocs.data(), |
| 4845 | E->getRParenLoc()); |
| 4846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | template<typename Derived> |
| 4849 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4850 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 4851 | CXXDependentScopeMemberExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4852 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4853 | // Transform the base of the expression. |
| 4854 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4855 | if (Base.isInvalid()) |
| 4856 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4857 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4858 | // Start the member reference and compute the object's type. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4859 | Sema::TypeTy *ObjectType = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4860 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4861 | E->getOperatorLoc(), |
| 4862 | E->isArrow()? tok::arrow : tok::period, |
| 4863 | ObjectType); |
| 4864 | if (Base.isInvalid()) |
| 4865 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4867 | // Transform the first part of the nested-name-specifier that qualifies |
| 4868 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4869 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4870 | = getDerived().TransformFirstQualifierInScope( |
| 4871 | E->getFirstQualifierFoundInScope(), |
| 4872 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4873 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4874 | NestedNameSpecifier *Qualifier = 0; |
| 4875 | if (E->getQualifier()) { |
| 4876 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4877 | E->getQualifierRange(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4878 | QualType::getFromOpaquePtr(ObjectType), |
| 4879 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4880 | if (!Qualifier) |
| 4881 | return SemaRef.ExprError(); |
| 4882 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4883 | |
| 4884 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4885 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
| 4886 | QualType::getFromOpaquePtr(ObjectType)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4887 | if (!Name) |
| 4888 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4889 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4890 | if (!E->hasExplicitTemplateArgumentList()) { |
| 4891 | // This is a reference to a member without an explicitly-specified |
| 4892 | // template argument list. Optimize for this common case. |
| 4893 | if (!getDerived().AlwaysRebuild() && |
| 4894 | Base.get() == E->getBase() && |
| 4895 | Qualifier == E->getQualifier() && |
| 4896 | Name == E->getMember() && |
| 4897 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4898 | return SemaRef.Owned(E->Retain()); |
| 4899 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4900 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4901 | E->isArrow(), |
| 4902 | E->getOperatorLoc(), |
| 4903 | Qualifier, |
| 4904 | E->getQualifierRange(), |
| 4905 | Name, |
| 4906 | E->getMemberLoc(), |
| 4907 | FirstQualifierInScope); |
| 4908 | } |
| 4909 | |
| 4910 | // FIXME: This is an ugly hack, which forces the same template name to |
| 4911 | // be looked up multiple times. Yuck! |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 4912 | TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName()); |
| 4913 | TemplateName OrigTemplateName; |
| 4914 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) |
| 4915 | OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II); |
| 4916 | else |
| 4917 | OrigTemplateName |
| 4918 | = SemaRef.Context.getDependentTemplateName(0, |
| 4919 | Name.getCXXOverloadedOperator()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4920 | |
| 4921 | TemplateName Template |
| 4922 | = getDerived().TransformTemplateName(OrigTemplateName, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4923 | QualType::getFromOpaquePtr(ObjectType)); |
| 4924 | if (Template.isNull()) |
| 4925 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4926 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4927 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4928 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4929 | TemplateArgumentLoc Loc; |
| 4930 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4931 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4932 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4933 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4935 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4936 | E->isArrow(), |
| 4937 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4938 | Qualifier, |
| 4939 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4940 | Template, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4941 | E->getMemberLoc(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4942 | FirstQualifierInScope, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4943 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | template<typename Derived> |
| 4947 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4948 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E, |
| 4949 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4951 | } |
| 4952 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | template<typename Derived> |
| 4954 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4955 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E, |
| 4956 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4957 | // FIXME: poor source location |
| 4958 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 4959 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 4960 | if (EncodedType.isNull()) |
| 4961 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | if (!getDerived().AlwaysRebuild() && |
| 4964 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4965 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4966 | |
| 4967 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 4968 | EncodedType, |
| 4969 | E->getRParenLoc()); |
| 4970 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4971 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4972 | template<typename Derived> |
| 4973 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4974 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E, |
| 4975 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4976 | // FIXME: Implement this! |
| 4977 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4978 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4981 | template<typename Derived> |
| 4982 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4983 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E, |
| 4984 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4985 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | template<typename Derived> |
| 4989 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4990 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E, |
| 4991 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4993 | = cast_or_null<ObjCProtocolDecl>( |
| 4994 | getDerived().TransformDecl(E->getProtocol())); |
| 4995 | if (!Protocol) |
| 4996 | return SemaRef.ExprError(); |
| 4997 | |
| 4998 | if (!getDerived().AlwaysRebuild() && |
| 4999 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5000 | return SemaRef.Owned(E->Retain()); |
| 5001 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5002 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5003 | E->getAtLoc(), |
| 5004 | /*FIXME:*/E->getAtLoc(), |
| 5005 | /*FIXME:*/E->getAtLoc(), |
| 5006 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5007 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | template<typename Derived> |
| 5011 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5012 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E, |
| 5013 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5014 | // FIXME: Implement this! |
| 5015 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5016 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5019 | template<typename Derived> |
| 5020 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5021 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E, |
| 5022 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5023 | // FIXME: Implement this! |
| 5024 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5025 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5028 | template<typename Derived> |
| 5029 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5030 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5031 | ObjCImplicitSetterGetterRefExpr *E, |
| 5032 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | // FIXME: Implement this! |
| 5034 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5038 | template<typename Derived> |
| 5039 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5040 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E, |
| 5041 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5042 | // FIXME: Implement this! |
| 5043 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5044 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5045 | } |
| 5046 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5047 | template<typename Derived> |
| 5048 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5049 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E, |
| 5050 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | // FIXME: Implement this! |
| 5052 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5056 | template<typename Derived> |
| 5057 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5058 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E, |
| 5059 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5060 | bool ArgumentChanged = false; |
| 5061 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5062 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5063 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5064 | if (SubExpr.isInvalid()) |
| 5065 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5068 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5069 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5070 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5071 | if (!getDerived().AlwaysRebuild() && |
| 5072 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(E->Retain()); |
| 5074 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5076 | move_arg(SubExprs), |
| 5077 | E->getRParenLoc()); |
| 5078 | } |
| 5079 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | template<typename Derived> |
| 5081 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5082 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E, |
| 5083 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5084 | // FIXME: Implement this! |
| 5085 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5086 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5087 | } |
| 5088 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5089 | template<typename Derived> |
| 5090 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5091 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E, |
| 5092 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5093 | // FIXME: Implement this! |
| 5094 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5095 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5096 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5098 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5099 | // Type reconstruction |
| 5100 | //===----------------------------------------------------------------------===// |
| 5101 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5102 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5103 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5104 | SourceLocation Star) { |
| 5105 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5106 | getDerived().getBaseEntity()); |
| 5107 | } |
| 5108 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5110 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5111 | SourceLocation Star) { |
| 5112 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5113 | getDerived().getBaseEntity()); |
| 5114 | } |
| 5115 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | template<typename Derived> |
| 5117 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5118 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5119 | bool WrittenAsLValue, |
| 5120 | SourceLocation Sigil) { |
| 5121 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5122 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5127 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5128 | QualType ClassType, |
| 5129 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5130 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5131 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5135 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5136 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5137 | SourceLocation Sigil) { |
| 5138 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5139 | getDerived().getBaseEntity()); |
| 5140 | } |
| 5141 | |
| 5142 | template<typename Derived> |
| 5143 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5144 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5145 | ArrayType::ArraySizeModifier SizeMod, |
| 5146 | const llvm::APInt *Size, |
| 5147 | Expr *SizeExpr, |
| 5148 | unsigned IndexTypeQuals, |
| 5149 | SourceRange BracketsRange) { |
| 5150 | if (SizeExpr || !Size) |
| 5151 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5152 | IndexTypeQuals, BracketsRange, |
| 5153 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | |
| 5155 | QualType Types[] = { |
| 5156 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5157 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5158 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5159 | }; |
| 5160 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5161 | QualType SizeType; |
| 5162 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5163 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5164 | SizeType = Types[I]; |
| 5165 | break; |
| 5166 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5168 | if (SizeType.isNull()) |
| 5169 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5170 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5171 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5173 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5174 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5175 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5177 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5178 | QualType |
| 5179 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5180 | ArrayType::ArraySizeModifier SizeMod, |
| 5181 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5182 | unsigned IndexTypeQuals, |
| 5183 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5185 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5189 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5191 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5192 | unsigned IndexTypeQuals, |
| 5193 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5195 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5196 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5198 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | QualType |
| 5200 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5201 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5202 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5203 | unsigned IndexTypeQuals, |
| 5204 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5205 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5206 | SizeExpr.takeAs<Expr>(), |
| 5207 | IndexTypeQuals, BracketsRange); |
| 5208 | } |
| 5209 | |
| 5210 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | QualType |
| 5212 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5213 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5215 | unsigned IndexTypeQuals, |
| 5216 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5218 | SizeExpr.takeAs<Expr>(), |
| 5219 | IndexTypeQuals, BracketsRange); |
| 5220 | } |
| 5221 | |
| 5222 | template<typename Derived> |
| 5223 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5224 | unsigned NumElements) { |
| 5225 | // FIXME: semantic checking! |
| 5226 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5228 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5229 | template<typename Derived> |
| 5230 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5231 | unsigned NumElements, |
| 5232 | SourceLocation AttributeLoc) { |
| 5233 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5234 | NumElements, true); |
| 5235 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5237 | AttributeLoc); |
| 5238 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5239 | AttributeLoc); |
| 5240 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5241 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5242 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | QualType |
| 5244 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5245 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5246 | SourceLocation AttributeLoc) { |
| 5247 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5249 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5250 | template<typename Derived> |
| 5251 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5252 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5253 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5254 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5255 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5256 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5257 | Quals, |
| 5258 | getDerived().getBaseLocation(), |
| 5259 | getDerived().getBaseEntity()); |
| 5260 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5261 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5262 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5263 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5264 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5265 | } |
| 5266 | |
| 5267 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5268 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5269 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5270 | } |
| 5271 | |
| 5272 | template<typename Derived> |
| 5273 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5274 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5275 | } |
| 5276 | |
| 5277 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5278 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5279 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5280 | } |
| 5281 | |
| 5282 | template<typename Derived> |
| 5283 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5284 | TemplateName Template, |
| 5285 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5286 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5287 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5288 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5290 | template<typename Derived> |
| 5291 | NestedNameSpecifier * |
| 5292 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5293 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5294 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5295 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5296 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5297 | CXXScopeSpec SS; |
| 5298 | // FIXME: The source location information is all wrong. |
| 5299 | SS.setRange(Range); |
| 5300 | SS.setScopeRep(Prefix); |
| 5301 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5302 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5303 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5304 | ObjectType, |
| 5305 | FirstQualifierInScope, |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5306 | false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | template<typename Derived> |
| 5310 | NestedNameSpecifier * |
| 5311 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5312 | SourceRange Range, |
| 5313 | NamespaceDecl *NS) { |
| 5314 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5315 | } |
| 5316 | |
| 5317 | template<typename Derived> |
| 5318 | NestedNameSpecifier * |
| 5319 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5320 | SourceRange Range, |
| 5321 | bool TemplateKW, |
| 5322 | QualType T) { |
| 5323 | if (T->isDependentType() || T->isRecordType() || |
| 5324 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5325 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5326 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5327 | T.getTypePtr()); |
| 5328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5330 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5331 | return 0; |
| 5332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5333 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5334 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5335 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5336 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5337 | bool TemplateKW, |
| 5338 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5339 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5340 | Template); |
| 5341 | } |
| 5342 | |
| 5343 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5345 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5346 | const IdentifierInfo &II, |
| 5347 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5348 | CXXScopeSpec SS; |
| 5349 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5350 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5351 | UnqualifiedId Name; |
| 5352 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5353 | return getSema().ActOnDependentTemplateName( |
| 5354 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5355 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5356 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5357 | ObjectType.getAsOpaquePtr(), |
| 5358 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5359 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5360 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5361 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5362 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5363 | TemplateName |
| 5364 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5365 | OverloadedOperatorKind Operator, |
| 5366 | QualType ObjectType) { |
| 5367 | CXXScopeSpec SS; |
| 5368 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5369 | SS.setScopeRep(Qualifier); |
| 5370 | UnqualifiedId Name; |
| 5371 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5372 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5373 | Operator, SymbolLocations); |
| 5374 | return getSema().ActOnDependentTemplateName( |
| 5375 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5376 | SS, |
| 5377 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5378 | ObjectType.getAsOpaquePtr(), |
| 5379 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5380 | .template getAsVal<TemplateName>(); |
| 5381 | } |
| 5382 | |
| 5383 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5385 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5386 | SourceLocation OpLoc, |
| 5387 | ExprArg Callee, |
| 5388 | ExprArg First, |
| 5389 | ExprArg Second) { |
| 5390 | Expr *FirstExpr = (Expr *)First.get(); |
| 5391 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5392 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5393 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5394 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5395 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5396 | if (Op == OO_Subscript) { |
| 5397 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5398 | !SecondExpr->getType()->isOverloadableType()) |
| 5399 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5400 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5401 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5402 | } else if (Op == OO_Arrow) { |
| 5403 | // -> is never a builtin operation. |
| 5404 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5405 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5406 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5407 | // The argument is not of overloadable type, so try to create a |
| 5408 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5409 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5410 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5412 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5413 | } |
| 5414 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5415 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5416 | !SecondExpr->getType()->isOverloadableType()) { |
| 5417 | // Neither of the arguments is an overloadable type, so try to |
| 5418 | // create a built-in binary operation. |
| 5419 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5420 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5421 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5422 | if (Result.isInvalid()) |
| 5423 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5425 | First.release(); |
| 5426 | Second.release(); |
| 5427 | return move(Result); |
| 5428 | } |
| 5429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | |
| 5431 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5432 | // used during overload resolution. |
| 5433 | Sema::FunctionSet Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5434 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5435 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5436 | assert(ULE->requiresADL()); |
| 5437 | |
| 5438 | // FIXME: Do we have to check |
| 5439 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5440 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5441 | E = ULE->decls_end(); I != E; ++I) |
| 5442 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5443 | } else { |
| 5444 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5445 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5446 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5448 | // Add any functions found via argument-dependent lookup. |
| 5449 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5450 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | DeclarationName OpName |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5452 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | 644be85 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5453 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5454 | Functions); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5455 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5456 | // Create the overloaded operator invocation for unary operators. |
| 5457 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5458 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5459 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5460 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5461 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5463 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5464 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5465 | OpLoc, |
| 5466 | move(First), |
| 5467 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5468 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5469 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5470 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5471 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5472 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5473 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5474 | if (Result.isInvalid()) |
| 5475 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5477 | First.release(); |
| 5478 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5479 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5481 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5482 | } // end namespace clang |
| 5483 | |
| 5484 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |