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" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprCXX.h" |
| 21 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/Stmt.h" |
| 23 | #include "clang/AST/StmtCXX.h" |
| 24 | #include "clang/AST/StmtObjC.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/Parse/Ownership.h" |
| 27 | #include "clang/Parse/Designator.h" |
| 28 | #include "clang/Lex/Preprocessor.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 30 | #include <algorithm> |
| 31 | |
| 32 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 34 | /// \brief A semantic tree transformation that allows one to transform one |
| 35 | /// abstract syntax tree into another. |
| 36 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 38 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 39 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 40 | /// instantiation is implemented as a tree transformation where the |
| 41 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 42 | /// template arguments for their corresponding template parameters; a similar |
| 43 | /// transformation is performed for non-type template parameters and |
| 44 | /// template template parameters. |
| 45 | /// |
| 46 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// override any of the transformation or rebuild operators by providing an |
| 49 | /// operation with the same signature as the default implementation. The |
| 50 | /// overridding function should not be virtual. |
| 51 | /// |
| 52 | /// Semantic tree transformations are split into two stages, either of which |
| 53 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 54 | /// or the parts of an AST node using the various transformation functions, |
| 55 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 56 | /// node of the appropriate kind from the pieces. The default transformation |
| 57 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 58 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 59 | /// were changed by the transformation, invokes the rebuild operation to create |
| 60 | /// a new AST node. |
| 61 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 63 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 64 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 65 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 66 | /// new implementations. |
| 67 | /// |
| 68 | /// For more fine-grained transformations, subclasses can replace any of the |
| 69 | /// \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] | 70 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 71 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 74 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 75 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 76 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 77 | /// be able to use more efficient rebuild steps. |
| 78 | /// |
| 79 | /// 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] | 80 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 82 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 83 | /// default locations and entity names used for type-checking |
| 84 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 85 | template<typename Derived> |
| 86 | class TreeTransform { |
| 87 | protected: |
| 88 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | |
| 90 | public: |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 91 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 92 | typedef Sema::OwningExprResult OwningExprResult; |
| 93 | typedef Sema::StmtArg StmtArg; |
| 94 | typedef Sema::ExprArg ExprArg; |
| 95 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 96 | typedef Sema::MultiStmtArg MultiStmtArg; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 98 | /// \brief Initializes a new tree transformer. |
| 99 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 101 | /// \brief Retrieves a reference to the derived class. |
| 102 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 103 | |
| 104 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | const Derived &getDerived() const { |
| 106 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 110 | /// this tree transform. |
| 111 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 114 | /// if none of the children have changed. |
| 115 | /// |
| 116 | /// Subclasses may override this function to specify when the transformation |
| 117 | /// should rebuild all AST nodes. |
| 118 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 120 | /// \brief Returns the location of the entity being transformed, if that |
| 121 | /// information was not available elsewhere in the AST. |
| 122 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | /// provide an alternative implementation that provides better location |
| 125 | /// information. |
| 126 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 128 | /// \brief Returns the name of the entity being transformed, if that |
| 129 | /// information was not available elsewhere in the AST. |
| 130 | /// |
| 131 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 132 | /// implementation with a more precise name. |
| 133 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 135 | /// \brief Sets the "base" location and entity when that |
| 136 | /// information is known based on another transformation. |
| 137 | /// |
| 138 | /// By default, the source location and entity are ignored. Subclasses can |
| 139 | /// override this function to provide a customized implementation. |
| 140 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 142 | /// \brief RAII object that temporarily sets the base location and entity |
| 143 | /// used for reporting diagnostics in types. |
| 144 | class TemporaryBase { |
| 145 | TreeTransform &Self; |
| 146 | SourceLocation OldLocation; |
| 147 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 149 | public: |
| 150 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 152 | OldLocation = Self.getDerived().getBaseLocation(); |
| 153 | OldEntity = Self.getDerived().getBaseEntity(); |
| 154 | Self.getDerived().setBase(Location, Entity); |
| 155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 157 | ~TemporaryBase() { |
| 158 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 159 | } |
| 160 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
| 162 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 163 | /// transformed. |
| 164 | /// |
| 165 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | /// 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] | 167 | /// not change. For example, template instantiation need not traverse |
| 168 | /// non-dependent types. |
| 169 | bool AlreadyTransformed(QualType T) { |
| 170 | return T.isNull(); |
| 171 | } |
| 172 | |
| 173 | /// \brief Transforms the given type into another type. |
| 174 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 175 | /// By default, this routine transforms a type by creating a |
| 176 | /// DeclaratorInfo for it and delegating to the appropriate |
| 177 | /// function. This is expensive, but we don't mind, because |
| 178 | /// this method is deprecated anyway; all users should be |
| 179 | /// switched to storing DeclaratorInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 180 | /// |
| 181 | /// \returns the transformed type. |
| 182 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 184 | /// \brief Transforms the given type-with-location into a new |
| 185 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 186 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by delegating to the |
| 188 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 189 | /// may override this function (to take over all type |
| 190 | /// transformations) or some set of the TransformXXXType functions |
| 191 | /// to alter the transformation. |
| 192 | DeclaratorInfo *TransformType(DeclaratorInfo *DI); |
| 193 | |
| 194 | /// \brief Transform the given type-with-location into a new |
| 195 | /// type, collecting location information in the given builder |
| 196 | /// as necessary. |
| 197 | /// |
| 198 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 200 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 201 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 203 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 204 | /// statement or the TransformExpr() function to transform an expression. |
| 205 | /// Subclasses may override this function to transform statements using some |
| 206 | /// other mechanism. |
| 207 | /// |
| 208 | /// \returns the transformed statement. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 209 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 211 | /// \brief Transform the given expression. |
| 212 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 213 | /// By default, this routine transforms an expression by delegating to the |
| 214 | /// appropriate TransformXXXExpr function to build a new expression. |
| 215 | /// Subclasses may override this function to transform expressions using some |
| 216 | /// other mechanism. |
| 217 | /// |
| 218 | /// \returns the transformed expression. |
| 219 | OwningExprResult TransformExpr(Expr *E) { |
| 220 | return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false); |
| 221 | } |
| 222 | |
| 223 | /// \brief Transform the given expression. |
| 224 | /// |
| 225 | /// By default, this routine transforms an expression by delegating to the |
| 226 | /// appropriate TransformXXXExpr function to build a new expression. |
| 227 | /// Subclasses may override this function to transform expressions using some |
| 228 | /// other mechanism. |
| 229 | /// |
| 230 | /// \returns the transformed expression. |
| 231 | OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 233 | /// \brief Transform the given declaration, which is referenced from a type |
| 234 | /// or expression. |
| 235 | /// |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 236 | /// By default, acts as the identity function on declarations. Subclasses |
| 237 | /// may override this function to provide alternate behavior. |
| 238 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 239 | |
| 240 | /// \brief Transform the definition of the given declaration. |
| 241 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 243 | /// Subclasses may override this function to provide alternate behavior. |
| 244 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 246 | /// \brief Transform the given declaration, which was the first part of a |
| 247 | /// nested-name-specifier in a member access expression. |
| 248 | /// |
| 249 | /// This specific declaration transformation only applies to the first |
| 250 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 251 | /// the \c T in \c x->T::member |
| 252 | /// |
| 253 | /// By default, invokes TransformDecl() to transform the declaration. |
| 254 | /// Subclasses may override this function to provide alternate behavior. |
| 255 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 256 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 257 | } |
| 258 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 259 | /// \brief Transform the given nested-name-specifier. |
| 260 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 262 | /// nested-name-specifier. Subclasses may override this function to provide |
| 263 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 264 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 265 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 266 | QualType ObjectType = QualType(), |
| 267 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 269 | /// \brief Transform the given declaration name. |
| 270 | /// |
| 271 | /// By default, transforms the types of conversion function, constructor, |
| 272 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 273 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 274 | /// override this function to provide alternate behavior. |
| 275 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 276 | SourceLocation Loc, |
| 277 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 281 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 284 | TemplateName TransformTemplateName(TemplateName Name, |
| 285 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// \brief Transform the given template argument. |
| 288 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | /// By default, this operation transforms the type, expression, or |
| 290 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 291 | /// new template argument from the transformed result. Subclasses may |
| 292 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 293 | /// |
| 294 | /// Returns true if there was an error. |
| 295 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 296 | TemplateArgumentLoc &Output); |
| 297 | |
| 298 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 299 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 300 | TemplateArgumentLoc &ArgLoc); |
| 301 | |
| 302 | /// \brief Fakes up a DeclaratorInfo for a type. |
| 303 | DeclaratorInfo *InventDeclaratorInfo(QualType T) { |
| 304 | return SemaRef.Context.getTrivialDeclaratorInfo(T, |
| 305 | getDerived().getBaseLocation()); |
| 306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 309 | #define TYPELOC(CLASS, PARENT) \ |
| 310 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 311 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 312 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 313 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 314 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 315 | QualType |
| 316 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 317 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 318 | |
| 319 | QualType |
| 320 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 321 | TemplateSpecializationTypeLoc TL, |
| 322 | QualType ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
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 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
| 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | /// \brief Build a new extended vector type given the element type and |
| 434 | /// number of elements. |
| 435 | /// |
| 436 | /// By default, performs semantic analysis when building the vector type. |
| 437 | /// Subclasses may override this routine to provide different behavior. |
| 438 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 439 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | /// given the element type and number of elements. |
| 443 | /// |
| 444 | /// By default, performs semantic analysis when building the vector type. |
| 445 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 448 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new function type. |
| 451 | /// |
| 452 | /// By default, performs semantic analysis when building the function type. |
| 453 | /// Subclasses may override this routine to provide different behavior. |
| 454 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | unsigned NumParamTypes, |
| 457 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 459 | /// \brief Build a new unprototyped function type. |
| 460 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | /// \brief Build a new typedef type. |
| 463 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 464 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 465 | } |
| 466 | |
| 467 | /// \brief Build a new class/struct/union type. |
| 468 | QualType RebuildRecordType(RecordDecl *Record) { |
| 469 | return SemaRef.Context.getTypeDeclType(Record); |
| 470 | } |
| 471 | |
| 472 | /// \brief Build a new Enum type. |
| 473 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 474 | return SemaRef.Context.getTypeDeclType(Enum); |
| 475 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 476 | |
| 477 | /// \brief Build a new elaborated type. |
| 478 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 479 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 481 | |
| 482 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 483 | /// |
| 484 | /// By default, performs semantic analysis when building the typeof type. |
| 485 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 486 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 487 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 489 | /// |
| 490 | /// By default, builds a new TypeOfType with the given underlying type. |
| 491 | QualType RebuildTypeOfType(QualType Underlying); |
| 492 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// By default, performs semantic analysis when building the decltype type. |
| 496 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 497 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 499 | /// \brief Build a new template specialization type. |
| 500 | /// |
| 501 | /// By default, performs semantic analysis when building the template |
| 502 | /// specialization type. Subclasses may override this routine to provide |
| 503 | /// different behavior. |
| 504 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 505 | SourceLocation TemplateLoc, |
| 506 | SourceLocation LAngleLoc, |
| 507 | const TemplateArgumentLoc *Args, |
| 508 | unsigned NumArgs, |
| 509 | SourceLocation RAngleLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 511 | /// \brief Build a new qualified name type. |
| 512 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | /// By default, builds a new QualifiedNameType type from the |
| 514 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 515 | /// this routine to provide different behavior. |
| 516 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 517 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 518 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 519 | |
| 520 | /// \brief Build a new typename type that refers to a template-id. |
| 521 | /// |
| 522 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 524 | /// different behavior. |
| 525 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 526 | if (NNS->isDependent()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 527 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 528 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 530 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 532 | |
| 533 | /// \brief Build a new typename type that refers to an identifier. |
| 534 | /// |
| 535 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 537 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 539 | const IdentifierInfo *Id, |
| 540 | SourceRange SR) { |
| 541 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 544 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 545 | /// identifier that names the next step in the nested-name-specifier. |
| 546 | /// |
| 547 | /// By default, performs semantic analysis when building the new |
| 548 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 549 | /// different behavior. |
| 550 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 551 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 552 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 553 | QualType ObjectType, |
| 554 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 555 | |
| 556 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 557 | /// namespace named in the next step in the nested-name-specifier. |
| 558 | /// |
| 559 | /// By default, performs semantic analysis when building the new |
| 560 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 561 | /// different behavior. |
| 562 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 563 | SourceRange Range, |
| 564 | NamespaceDecl *NS); |
| 565 | |
| 566 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 567 | /// type named in the next step in the nested-name-specifier. |
| 568 | /// |
| 569 | /// By default, performs semantic analysis when building the new |
| 570 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 571 | /// different behavior. |
| 572 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 573 | SourceRange Range, |
| 574 | bool TemplateKW, |
| 575 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 576 | |
| 577 | /// \brief Build a new template name given a nested name specifier, a flag |
| 578 | /// indicating whether the "template" keyword was provided, and the template |
| 579 | /// that the template name refers to. |
| 580 | /// |
| 581 | /// By default, builds the new template name directly. Subclasses may override |
| 582 | /// this routine to provide different behavior. |
| 583 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 584 | bool TemplateKW, |
| 585 | TemplateDecl *Template); |
| 586 | |
| 587 | /// \brief Build a new template name given a nested name specifier, a flag |
| 588 | /// indicating whether the "template" keyword was provided, and a set of |
| 589 | /// overloaded function templates. |
| 590 | /// |
| 591 | /// By default, builds the new template name directly. Subclasses may override |
| 592 | /// this routine to provide different behavior. |
| 593 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 594 | bool TemplateKW, |
| 595 | OverloadedFunctionDecl *Ovl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 596 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 597 | /// \brief Build a new template name given a nested name specifier and the |
| 598 | /// 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, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 605 | const IdentifierInfo &II, |
| 606 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 608 | /// \brief Build a new template name given a nested name specifier and the |
| 609 | /// overloaded operator name that is referred to as a template. |
| 610 | /// |
| 611 | /// By default, performs semantic analysis to determine whether the name can |
| 612 | /// be resolved to a specific template, then builds the appropriate kind of |
| 613 | /// template name. Subclasses may override this routine to provide different |
| 614 | /// behavior. |
| 615 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 616 | OverloadedOperatorKind Operator, |
| 617 | QualType ObjectType); |
| 618 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 619 | /// \brief Build a new compound statement. |
| 620 | /// |
| 621 | /// By default, performs semantic analysis to build the new statement. |
| 622 | /// Subclasses may override this routine to provide different behavior. |
| 623 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 624 | MultiStmtArg Statements, |
| 625 | SourceLocation RBraceLoc, |
| 626 | bool IsStmtExpr) { |
| 627 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 628 | IsStmtExpr); |
| 629 | } |
| 630 | |
| 631 | /// \brief Build a new case statement. |
| 632 | /// |
| 633 | /// By default, performs semantic analysis to build the new statement. |
| 634 | /// Subclasses may override this routine to provide different behavior. |
| 635 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 636 | ExprArg LHS, |
| 637 | SourceLocation EllipsisLoc, |
| 638 | ExprArg RHS, |
| 639 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 641 | ColonLoc); |
| 642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 644 | /// \brief Attach the body to a new case statement. |
| 645 | /// |
| 646 | /// By default, performs semantic analysis to build the new statement. |
| 647 | /// Subclasses may override this routine to provide different behavior. |
| 648 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 649 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 650 | return move(S); |
| 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 default 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 RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 658 | SourceLocation ColonLoc, |
| 659 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 661 | /*CurScope=*/0); |
| 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 label 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 RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 669 | IdentifierInfo *Id, |
| 670 | SourceLocation ColonLoc, |
| 671 | StmtArg SubStmt) { |
| 672 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 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 Build a new "if" statement. |
| 676 | /// |
| 677 | /// By default, performs semantic analysis to build the new statement. |
| 678 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
| 680 | StmtArg Then, SourceLocation ElseLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 681 | StmtArg Else) { |
| 682 | return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else)); |
| 683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 685 | /// \brief Start building a new switch statement. |
| 686 | /// |
| 687 | /// By default, performs semantic analysis to build the new statement. |
| 688 | /// Subclasses may override this routine to provide different behavior. |
| 689 | OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) { |
| 690 | return getSema().ActOnStartOfSwitchStmt(move(Cond)); |
| 691 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 693 | /// \brief Attach the body to the switch statement. |
| 694 | /// |
| 695 | /// By default, performs semantic analysis to build the new statement. |
| 696 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 698 | StmtArg Switch, StmtArg Body) { |
| 699 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 700 | move(Body)); |
| 701 | } |
| 702 | |
| 703 | /// \brief Build a new while statement. |
| 704 | /// |
| 705 | /// By default, performs semantic analysis to build the new statement. |
| 706 | /// Subclasses may override this routine to provide different behavior. |
| 707 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 708 | Sema::FullExprArg Cond, |
| 709 | StmtArg Body) { |
| 710 | return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body)); |
| 711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 713 | /// \brief Build a new do-while statement. |
| 714 | /// |
| 715 | /// By default, performs semantic analysis to build the new statement. |
| 716 | /// Subclasses may override this routine to provide different behavior. |
| 717 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 718 | SourceLocation WhileLoc, |
| 719 | SourceLocation LParenLoc, |
| 720 | ExprArg Cond, |
| 721 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 723 | move(Cond), RParenLoc); |
| 724 | } |
| 725 | |
| 726 | /// \brief Build a new for statement. |
| 727 | /// |
| 728 | /// By default, performs semantic analysis to build the new statement. |
| 729 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | SourceLocation LParenLoc, |
| 732 | StmtArg Init, ExprArg Cond, ExprArg Inc, |
| 733 | SourceLocation RParenLoc, StmtArg Body) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | move(Inc), RParenLoc, move(Body)); |
| 736 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 738 | /// \brief Build a new goto statement. |
| 739 | /// |
| 740 | /// By default, performs semantic analysis to build the new statement. |
| 741 | /// Subclasses may override this routine to provide different behavior. |
| 742 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 743 | SourceLocation LabelLoc, |
| 744 | LabelStmt *Label) { |
| 745 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 746 | } |
| 747 | |
| 748 | /// \brief Build a new indirect goto statement. |
| 749 | /// |
| 750 | /// By default, performs semantic analysis to build the new statement. |
| 751 | /// Subclasses may override this routine to provide different behavior. |
| 752 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 753 | SourceLocation StarLoc, |
| 754 | ExprArg Target) { |
| 755 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | /// \brief Build a new return statement. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis to build the new statement. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
| 762 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 763 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 765 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 768 | /// \brief Build a new declaration statement. |
| 769 | /// |
| 770 | /// By default, performs semantic analysis to build the new statement. |
| 771 | /// Subclasses may override this routine to provide different behavior. |
| 772 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 774 | SourceLocation EndLoc) { |
| 775 | return getSema().Owned( |
| 776 | new (getSema().Context) DeclStmt( |
| 777 | DeclGroupRef::Create(getSema().Context, |
| 778 | Decls, NumDecls), |
| 779 | StartLoc, EndLoc)); |
| 780 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 782 | /// \brief Build a new C++ exception declaration. |
| 783 | /// |
| 784 | /// By default, performs semantic analysis to build the new decaration. |
| 785 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | DeclaratorInfo *Declarator, |
| 788 | IdentifierInfo *Name, |
| 789 | SourceLocation Loc, |
| 790 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 792 | TypeRange); |
| 793 | } |
| 794 | |
| 795 | /// \brief Build a new C++ catch statement. |
| 796 | /// |
| 797 | /// By default, performs semantic analysis to build the new statement. |
| 798 | /// Subclasses may override this routine to provide different behavior. |
| 799 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 800 | VarDecl *ExceptionDecl, |
| 801 | StmtArg Handler) { |
| 802 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | Handler.takeAs<Stmt>())); |
| 805 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 807 | /// \brief Build a new C++ try statement. |
| 808 | /// |
| 809 | /// By default, performs semantic analysis to build the new statement. |
| 810 | /// Subclasses may override this routine to provide different behavior. |
| 811 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 812 | StmtArg TryBlock, |
| 813 | MultiStmtArg Handlers) { |
| 814 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 815 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 817 | /// \brief Build a new expression that references a declaration. |
| 818 | /// |
| 819 | /// By default, performs semantic analysis to build the new expression. |
| 820 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 821 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 822 | SourceRange QualifierRange, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 823 | NamedDecl *ND, SourceLocation Loc, |
| 824 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 825 | CXXScopeSpec SS; |
| 826 | SS.setScopeRep(Qualifier); |
| 827 | SS.setRange(QualifierRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 828 | return getSema().BuildDeclarationNameExpr(Loc, ND, |
| 829 | /*FIXME:*/false, |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 830 | &SS, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 831 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 832 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 834 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 836 | /// By default, performs semantic analysis to build the new expression. |
| 837 | /// Subclasses may override this routine to provide different behavior. |
| 838 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 839 | SourceLocation RParen) { |
| 840 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 841 | } |
| 842 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 843 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 845 | /// By default, performs semantic analysis to build the new expression. |
| 846 | /// Subclasses may override this routine to provide different behavior. |
| 847 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 848 | SourceLocation OperatorLoc, |
| 849 | bool isArrow, |
| 850 | SourceLocation DestroyedTypeLoc, |
| 851 | QualType DestroyedType, |
| 852 | NestedNameSpecifier *Qualifier, |
| 853 | SourceRange QualifierRange) { |
| 854 | CXXScopeSpec SS; |
| 855 | if (Qualifier) { |
| 856 | SS.setRange(QualifierRange); |
| 857 | SS.setScopeRep(Qualifier); |
| 858 | } |
| 859 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 861 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 862 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | |
| 864 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 865 | OperatorLoc, |
| 866 | isArrow? tok::arrow : tok::period, |
| 867 | DestroyedTypeLoc, |
| 868 | Name, |
| 869 | Sema::DeclPtrTy::make((Decl *)0), |
| 870 | &SS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 873 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 875 | /// By default, performs semantic analysis to build the new expression. |
| 876 | /// Subclasses may override this routine to provide different behavior. |
| 877 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 878 | UnaryOperator::Opcode Opc, |
| 879 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 880 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 881 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 885 | /// By default, performs semantic analysis to build the new expression. |
| 886 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 887 | OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo, |
| 888 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 889 | bool isSizeOf, SourceRange R) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 890 | return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 894 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 896 | /// By default, performs semantic analysis to build the new expression. |
| 897 | /// Subclasses may override this routine to provide different behavior. |
| 898 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 899 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 900 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 901 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 902 | OpLoc, isSizeOf, R); |
| 903 | if (Result.isInvalid()) |
| 904 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 906 | SubExpr.release(); |
| 907 | return move(Result); |
| 908 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 910 | /// \brief Build a new array subscript expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 913 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 915 | SourceLocation LBracketLoc, |
| 916 | ExprArg RHS, |
| 917 | SourceLocation RBracketLoc) { |
| 918 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | RBracketLoc); |
| 921 | } |
| 922 | |
| 923 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 925 | /// By default, performs semantic analysis to build the new expression. |
| 926 | /// Subclasses may override this routine to provide different behavior. |
| 927 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 928 | MultiExprArg Args, |
| 929 | SourceLocation *CommaLocs, |
| 930 | SourceLocation RParenLoc) { |
| 931 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 932 | move(Args), CommaLocs, RParenLoc); |
| 933 | } |
| 934 | |
| 935 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 937 | /// By default, performs semantic analysis to build the new expression. |
| 938 | /// Subclasses may override this routine to provide different behavior. |
| 939 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 941 | NestedNameSpecifier *Qualifier, |
| 942 | SourceRange QualifierRange, |
| 943 | SourceLocation MemberLoc, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 944 | NamedDecl *Member, |
| 945 | bool HasExplicitTemplateArgs, |
| 946 | SourceLocation LAngleLoc, |
| 947 | const TemplateArgumentLoc *ExplicitTemplateArgs, |
| 948 | unsigned NumExplicitTemplateArgs, |
| 949 | SourceLocation RAngleLoc, |
| 950 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 951 | if (!Member->getDeclName()) { |
| 952 | // We have a reference to an unnamed field. |
| 953 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | |
| 955 | MemberExpr *ME = |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 956 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 957 | Member, MemberLoc, |
| 958 | cast<FieldDecl>(Member)->getType()); |
| 959 | return getSema().Owned(ME); |
| 960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 961 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 962 | CXXScopeSpec SS; |
| 963 | if (Qualifier) { |
| 964 | SS.setRange(QualifierRange); |
| 965 | SS.setScopeRep(Qualifier); |
| 966 | } |
| 967 | |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 968 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 969 | isArrow? tok::arrow : tok::period, |
| 970 | MemberLoc, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 971 | Member->getDeclName(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 972 | HasExplicitTemplateArgs, |
| 973 | LAngleLoc, |
| 974 | ExplicitTemplateArgs, |
| 975 | NumExplicitTemplateArgs, |
| 976 | RAngleLoc, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 977 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 978 | &SS, |
| 979 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 980 | } |
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 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 984 | /// By default, performs semantic analysis to build the new expression. |
| 985 | /// Subclasses may override this routine to provide different behavior. |
| 986 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 987 | BinaryOperator::Opcode Opc, |
| 988 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 989 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 990 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 995 | /// By default, performs semantic analysis to build the new expression. |
| 996 | /// Subclasses may override this routine to provide different behavior. |
| 997 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 998 | SourceLocation QuestionLoc, |
| 999 | ExprArg LHS, |
| 1000 | SourceLocation ColonLoc, |
| 1001 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | move(LHS), move(RHS)); |
| 1004 | } |
| 1005 | |
| 1006 | /// \brief Build a new implicit cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1008 | /// By default, builds a new implicit cast without any semantic analysis. |
| 1009 | /// Subclasses may override this routine to provide different behavior. |
| 1010 | OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, |
| 1011 | ExprArg SubExpr, bool isLvalue) { |
| 1012 | ImplicitCastExpr *ICE |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | = new (getSema().Context) ImplicitCastExpr(T, Kind, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1014 | (Expr *)SubExpr.release(), |
| 1015 | isLvalue); |
| 1016 | return getSema().Owned(ICE); |
| 1017 | } |
| 1018 | |
| 1019 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1021 | /// By default, performs semantic analysis to build the new expression. |
| 1022 | /// Subclasses may override this routine to provide different behavior. |
| 1023 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1024 | QualType ExplicitTy, |
| 1025 | SourceLocation RParenLoc, |
| 1026 | ExprArg SubExpr) { |
| 1027 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1028 | LParenLoc, |
| 1029 | ExplicitTy.getAsOpaquePtr(), |
| 1030 | RParenLoc, |
| 1031 | move(SubExpr)); |
| 1032 | } |
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 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1036 | /// By default, performs semantic analysis to build the new expression. |
| 1037 | /// Subclasses may override this routine to provide different behavior. |
| 1038 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1039 | QualType T, |
| 1040 | SourceLocation RParenLoc, |
| 1041 | ExprArg Init) { |
| 1042 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1043 | RParenLoc, move(Init)); |
| 1044 | } |
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 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | /// By default, performs semantic analysis to build the new expression. |
| 1049 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1051 | SourceLocation OpLoc, |
| 1052 | SourceLocation AccessorLoc, |
| 1053 | IdentifierInfo &Accessor) { |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1054 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1055 | tok::period, AccessorLoc, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1056 | DeclarationName(&Accessor), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1057 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0)); |
| 1058 | } |
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 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | /// By default, performs semantic analysis to build the new expression. |
| 1063 | /// Subclasses may override this routine to provide different behavior. |
| 1064 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1065 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1066 | SourceLocation RBraceLoc, |
| 1067 | QualType ResultTy) { |
| 1068 | OwningExprResult Result |
| 1069 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1070 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1071 | return move(Result); |
| 1072 | |
| 1073 | // Patch in the result type we were given, which may have been computed |
| 1074 | // when the initial InitListExpr was built. |
| 1075 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1076 | ILE->setType(ResultTy); |
| 1077 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1078 | } |
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 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1082 | /// By default, performs semantic analysis to build the new expression. |
| 1083 | /// Subclasses may override this routine to provide different behavior. |
| 1084 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1085 | MultiExprArg ArrayExprs, |
| 1086 | SourceLocation EqualOrColonLoc, |
| 1087 | bool GNUSyntax, |
| 1088 | ExprArg Init) { |
| 1089 | OwningExprResult Result |
| 1090 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1091 | move(Init)); |
| 1092 | if (Result.isInvalid()) |
| 1093 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1095 | ArrayExprs.release(); |
| 1096 | return move(Result); |
| 1097 | } |
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 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1101 | /// By default, builds the implicit value initialization without performing |
| 1102 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1103 | /// different behavior. |
| 1104 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1105 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1106 | } |
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 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1110 | /// By default, performs semantic analysis to build the new expression. |
| 1111 | /// Subclasses may override this routine to provide different behavior. |
| 1112 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1113 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | RParenLoc); |
| 1116 | } |
| 1117 | |
| 1118 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1119 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// By default, performs semantic analysis to build the new expression. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
| 1122 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1123 | MultiExprArg SubExprs, |
| 1124 | SourceLocation RParenLoc) { |
| 1125 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); |
| 1126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
| 1130 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1131 | /// rather than attempting to map the label statement itself. |
| 1132 | /// Subclasses may override this routine to provide different behavior. |
| 1133 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1134 | SourceLocation LabelLoc, |
| 1135 | LabelStmt *Label) { |
| 1136 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// By default, performs semantic analysis to build the new expression. |
| 1142 | /// Subclasses may override this routine to provide different behavior. |
| 1143 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1144 | StmtArg SubStmt, |
| 1145 | SourceLocation RParenLoc) { |
| 1146 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1150 | /// |
| 1151 | /// By default, performs semantic analysis to build the new expression. |
| 1152 | /// Subclasses may override this routine to provide different behavior. |
| 1153 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1154 | QualType T1, QualType T2, |
| 1155 | SourceLocation RParenLoc) { |
| 1156 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1157 | T1.getAsOpaquePtr(), |
| 1158 | T2.getAsOpaquePtr(), |
| 1159 | RParenLoc); |
| 1160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1162 | /// \brief Build a new __builtin_choose_expr expression. |
| 1163 | /// |
| 1164 | /// By default, performs semantic analysis to build the new expression. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
| 1166 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1167 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1168 | SourceLocation RParenLoc) { |
| 1169 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1170 | move(Cond), move(LHS), move(RHS), |
| 1171 | RParenLoc); |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1174 | /// \brief Build a new overloaded operator call expression. |
| 1175 | /// |
| 1176 | /// By default, performs semantic analysis to build the new expression. |
| 1177 | /// The semantic analysis provides the behavior of template instantiation, |
| 1178 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1181 | /// provide different behavior. |
| 1182 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1183 | SourceLocation OpLoc, |
| 1184 | ExprArg Callee, |
| 1185 | ExprArg First, |
| 1186 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
| 1188 | /// \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] | 1189 | /// reinterpret_cast. |
| 1190 | /// |
| 1191 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1193 | /// Subclasses may override this routine to provide different behavior. |
| 1194 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1195 | Stmt::StmtClass Class, |
| 1196 | SourceLocation LAngleLoc, |
| 1197 | QualType T, |
| 1198 | SourceLocation RAngleLoc, |
| 1199 | SourceLocation LParenLoc, |
| 1200 | ExprArg SubExpr, |
| 1201 | SourceLocation RParenLoc) { |
| 1202 | switch (Class) { |
| 1203 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1205 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | move(SubExpr), RParenLoc); |
| 1207 | |
| 1208 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1210 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1215 | RAngleLoc, LParenLoc, |
| 1216 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1217 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1221 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1222 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1224 | default: |
| 1225 | assert(false && "Invalid C++ named cast"); |
| 1226 | break; |
| 1227 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1229 | return getSema().ExprError(); |
| 1230 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | /// \brief Build a new C++ static_cast expression. |
| 1233 | /// |
| 1234 | /// By default, performs semantic analysis to build the new expression. |
| 1235 | /// Subclasses may override this routine to provide different behavior. |
| 1236 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1237 | SourceLocation LAngleLoc, |
| 1238 | QualType T, |
| 1239 | SourceLocation RAngleLoc, |
| 1240 | SourceLocation LParenLoc, |
| 1241 | ExprArg SubExpr, |
| 1242 | SourceLocation RParenLoc) { |
| 1243 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | LParenLoc, move(SubExpr), RParenLoc); |
| 1246 | } |
| 1247 | |
| 1248 | /// \brief Build a new C++ dynamic_cast expression. |
| 1249 | /// |
| 1250 | /// By default, performs semantic analysis to build the new expression. |
| 1251 | /// Subclasses may override this routine to provide different behavior. |
| 1252 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1253 | SourceLocation LAngleLoc, |
| 1254 | QualType T, |
| 1255 | SourceLocation RAngleLoc, |
| 1256 | SourceLocation LParenLoc, |
| 1257 | ExprArg SubExpr, |
| 1258 | SourceLocation RParenLoc) { |
| 1259 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1261 | LParenLoc, move(SubExpr), RParenLoc); |
| 1262 | } |
| 1263 | |
| 1264 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1265 | /// |
| 1266 | /// By default, performs semantic analysis to build the new expression. |
| 1267 | /// Subclasses may override this routine to provide different behavior. |
| 1268 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1269 | SourceLocation LAngleLoc, |
| 1270 | QualType T, |
| 1271 | SourceLocation RAngleLoc, |
| 1272 | SourceLocation LParenLoc, |
| 1273 | ExprArg SubExpr, |
| 1274 | SourceLocation RParenLoc) { |
| 1275 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1276 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1277 | LParenLoc, move(SubExpr), RParenLoc); |
| 1278 | } |
| 1279 | |
| 1280 | /// \brief Build a new C++ const_cast expression. |
| 1281 | /// |
| 1282 | /// By default, performs semantic analysis to build the new expression. |
| 1283 | /// Subclasses may override this routine to provide different behavior. |
| 1284 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1285 | SourceLocation LAngleLoc, |
| 1286 | QualType T, |
| 1287 | SourceLocation RAngleLoc, |
| 1288 | SourceLocation LParenLoc, |
| 1289 | ExprArg SubExpr, |
| 1290 | SourceLocation RParenLoc) { |
| 1291 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | LParenLoc, move(SubExpr), RParenLoc); |
| 1294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | /// \brief Build a new C++ functional-style cast expression. |
| 1297 | /// |
| 1298 | /// By default, performs semantic analysis to build the new expression. |
| 1299 | /// Subclasses may override this routine to provide different behavior. |
| 1300 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1301 | QualType T, |
| 1302 | SourceLocation LParenLoc, |
| 1303 | ExprArg SubExpr, |
| 1304 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1305 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1306 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1307 | T.getAsOpaquePtr(), |
| 1308 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1309 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | RParenLoc); |
| 1312 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | /// \brief Build a new C++ typeid(type) expression. |
| 1315 | /// |
| 1316 | /// By default, performs semantic analysis to build the new expression. |
| 1317 | /// Subclasses may override this routine to provide different behavior. |
| 1318 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1319 | SourceLocation LParenLoc, |
| 1320 | QualType T, |
| 1321 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | T.getAsOpaquePtr(), RParenLoc); |
| 1324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1326 | /// \brief Build a new C++ typeid(expr) expression. |
| 1327 | /// |
| 1328 | /// By default, performs semantic analysis to build the new expression. |
| 1329 | /// Subclasses may override this routine to provide different behavior. |
| 1330 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1331 | SourceLocation LParenLoc, |
| 1332 | ExprArg Operand, |
| 1333 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1334 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1336 | RParenLoc); |
| 1337 | if (Result.isInvalid()) |
| 1338 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1340 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1341 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | /// \brief Build a new C++ "this" expression. |
| 1345 | /// |
| 1346 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | QualType ThisType) { |
| 1351 | return getSema().Owned( |
| 1352 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1353 | } |
| 1354 | |
| 1355 | /// \brief Build a new C++ throw expression. |
| 1356 | /// |
| 1357 | /// By default, performs semantic analysis to build the new expression. |
| 1358 | /// Subclasses may override this routine to provide different behavior. |
| 1359 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1360 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1361 | } |
| 1362 | |
| 1363 | /// \brief Build a new C++ default-argument expression. |
| 1364 | /// |
| 1365 | /// By default, builds a new default-argument expression, which does not |
| 1366 | /// require any semantic analysis. Subclasses may override this routine to |
| 1367 | /// provide different behavior. |
| 1368 | OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) { |
Anders Carlsson | f1480ee | 2009-08-14 18:30:22 +0000 | [diff] [blame] | 1369 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /// \brief Build a new C++ zero-initialization expression. |
| 1373 | /// |
| 1374 | /// By default, performs semantic analysis to build the new expression. |
| 1375 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1377 | SourceLocation LParenLoc, |
| 1378 | QualType T, |
| 1379 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1381 | T.getAsOpaquePtr(), LParenLoc, |
| 1382 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | 0, RParenLoc); |
| 1384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1386 | /// \brief Build a new C++ conditional declaration expression. |
| 1387 | /// |
| 1388 | /// By default, performs semantic analysis to build the new expression. |
| 1389 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | SourceLocation EqLoc, |
| 1392 | VarDecl *Var) { |
| 1393 | return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc, |
| 1394 | EqLoc, |
| 1395 | Var)); |
| 1396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1398 | /// \brief Build a new C++ "new" expression. |
| 1399 | /// |
| 1400 | /// By default, performs semantic analysis to build the new expression. |
| 1401 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1403 | bool UseGlobal, |
| 1404 | SourceLocation PlacementLParen, |
| 1405 | MultiExprArg PlacementArgs, |
| 1406 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | QualType AllocType, |
| 1409 | SourceLocation TypeLoc, |
| 1410 | SourceRange TypeRange, |
| 1411 | ExprArg ArraySize, |
| 1412 | SourceLocation ConstructorLParen, |
| 1413 | MultiExprArg ConstructorArgs, |
| 1414 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1416 | PlacementLParen, |
| 1417 | move(PlacementArgs), |
| 1418 | PlacementRParen, |
| 1419 | ParenTypeId, |
| 1420 | AllocType, |
| 1421 | TypeLoc, |
| 1422 | TypeRange, |
| 1423 | move(ArraySize), |
| 1424 | ConstructorLParen, |
| 1425 | move(ConstructorArgs), |
| 1426 | ConstructorRParen); |
| 1427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1429 | /// \brief Build a new C++ "delete" expression. |
| 1430 | /// |
| 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
| 1433 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1434 | bool IsGlobalDelete, |
| 1435 | bool IsArrayForm, |
| 1436 | ExprArg Operand) { |
| 1437 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1438 | move(Operand)); |
| 1439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1440 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1441 | /// \brief Build a new unary type trait expression. |
| 1442 | /// |
| 1443 | /// By default, performs semantic analysis to build the new expression. |
| 1444 | /// Subclasses may override this routine to provide different behavior. |
| 1445 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1446 | SourceLocation StartLoc, |
| 1447 | SourceLocation LParenLoc, |
| 1448 | QualType T, |
| 1449 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | T.getAsOpaquePtr(), RParenLoc); |
| 1452 | } |
| 1453 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1455 | /// expression. |
| 1456 | /// |
| 1457 | /// By default, performs semantic analysis to build the new expression. |
| 1458 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 1459 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | SourceRange QualifierRange, |
| 1461 | DeclarationName Name, |
| 1462 | SourceLocation Location, |
| 1463 | bool IsAddressOfOperand) { |
| 1464 | CXXScopeSpec SS; |
| 1465 | SS.setRange(QualifierRange); |
| 1466 | SS.setScopeRep(NNS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1468 | Location, |
| 1469 | Name, |
| 1470 | /*Trailing lparen=*/false, |
| 1471 | &SS, |
| 1472 | IsAddressOfOperand); |
| 1473 | } |
| 1474 | |
| 1475 | /// \brief Build a new template-id expression. |
| 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1479 | OwningExprResult RebuildTemplateIdExpr(NestedNameSpecifier *Qualifier, |
| 1480 | SourceRange QualifierRange, |
| 1481 | TemplateName Template, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1482 | SourceLocation TemplateLoc, |
| 1483 | SourceLocation LAngleLoc, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1484 | TemplateArgumentLoc *TemplateArgs, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1485 | unsigned NumTemplateArgs, |
| 1486 | SourceLocation RAngleLoc) { |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1487 | return getSema().BuildTemplateIdExpr(Qualifier, QualifierRange, |
| 1488 | Template, TemplateLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | LAngleLoc, |
| 1490 | TemplateArgs, NumTemplateArgs, |
| 1491 | RAngleLoc); |
| 1492 | } |
| 1493 | |
| 1494 | /// \brief Build a new object-construction expression. |
| 1495 | /// |
| 1496 | /// By default, performs semantic analysis to build the new expression. |
| 1497 | /// Subclasses may override this routine to provide different behavior. |
| 1498 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
| 1499 | CXXConstructorDecl *Constructor, |
| 1500 | bool IsElidable, |
| 1501 | MultiExprArg Args) { |
Anders Carlsson | ec8e5ea | 2009-09-05 07:40:38 +0000 | [diff] [blame] | 1502 | return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/ |
| 1503 | SourceLocation(), |
| 1504 | T, Constructor, IsElidable, |
Anders Carlsson | f47511a | 2009-09-07 22:23:31 +0000 | [diff] [blame] | 1505 | move(Args)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | /// \brief Build a new object-construction expression. |
| 1509 | /// |
| 1510 | /// By default, performs semantic analysis to build the new expression. |
| 1511 | /// Subclasses may override this routine to provide different behavior. |
| 1512 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1513 | QualType T, |
| 1514 | SourceLocation LParenLoc, |
| 1515 | MultiExprArg Args, |
| 1516 | SourceLocation *Commas, |
| 1517 | SourceLocation RParenLoc) { |
| 1518 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1519 | T.getAsOpaquePtr(), |
| 1520 | LParenLoc, |
| 1521 | move(Args), |
| 1522 | Commas, |
| 1523 | RParenLoc); |
| 1524 | } |
| 1525 | |
| 1526 | /// \brief Build a new object-construction expression. |
| 1527 | /// |
| 1528 | /// By default, performs semantic analysis to build the new expression. |
| 1529 | /// Subclasses may override this routine to provide different behavior. |
| 1530 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1531 | QualType T, |
| 1532 | SourceLocation LParenLoc, |
| 1533 | MultiExprArg Args, |
| 1534 | SourceLocation *Commas, |
| 1535 | SourceLocation RParenLoc) { |
| 1536 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1537 | /*FIXME*/LParenLoc), |
| 1538 | T.getAsOpaquePtr(), |
| 1539 | LParenLoc, |
| 1540 | move(Args), |
| 1541 | Commas, |
| 1542 | RParenLoc); |
| 1543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1544 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1545 | /// \brief Build a new member reference expression. |
| 1546 | /// |
| 1547 | /// By default, performs semantic analysis to build the new expression. |
| 1548 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 1549 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1550 | bool IsArrow, |
| 1551 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1552 | NestedNameSpecifier *Qualifier, |
| 1553 | SourceRange QualifierRange, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1554 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1555 | SourceLocation MemberLoc, |
| 1556 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0dec56d | 2009-08-11 15:56:57 +0000 | [diff] [blame] | 1557 | OwningExprResult Base = move(BaseE); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1558 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1559 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1561 | SS.setRange(QualifierRange); |
| 1562 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1564 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1565 | move(Base), OperatorLoc, OpKind, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 1566 | MemberLoc, |
| 1567 | Name, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1568 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1569 | &SS, |
| 1570 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1573 | /// \brief Build a new member reference expression with explicit template |
| 1574 | /// arguments. |
| 1575 | /// |
| 1576 | /// By default, performs semantic analysis to build the new expression. |
| 1577 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 1578 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1579 | bool IsArrow, |
| 1580 | SourceLocation OperatorLoc, |
| 1581 | NestedNameSpecifier *Qualifier, |
| 1582 | SourceRange QualifierRange, |
| 1583 | TemplateName Template, |
| 1584 | SourceLocation TemplateNameLoc, |
| 1585 | NamedDecl *FirstQualifierInScope, |
| 1586 | SourceLocation LAngleLoc, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1587 | const TemplateArgumentLoc *TemplateArgs, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1588 | unsigned NumTemplateArgs, |
| 1589 | SourceLocation RAngleLoc) { |
| 1590 | OwningExprResult Base = move(BaseE); |
| 1591 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1593 | CXXScopeSpec SS; |
| 1594 | SS.setRange(QualifierRange); |
| 1595 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1597 | // 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] | 1598 | // twice! Also, duplicates part of Sema::BuildMemberAccessExpr. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1599 | DeclarationName Name; |
| 1600 | if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl()) |
| 1601 | Name = ActualTemplate->getDeclName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1602 | else if (OverloadedFunctionDecl *Ovl |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1603 | = Template.getAsOverloadedFunctionDecl()) |
| 1604 | Name = Ovl->getDeclName(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1605 | else { |
| 1606 | DependentTemplateName *DTN = Template.getAsDependentTemplateName(); |
| 1607 | if (DTN->isIdentifier()) |
| 1608 | Name = DTN->getIdentifier(); |
| 1609 | else |
| 1610 | Name = SemaRef.Context.DeclarationNames.getCXXOperatorName( |
| 1611 | DTN->getOperator()); |
| 1612 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1614 | OperatorLoc, OpKind, |
| 1615 | TemplateNameLoc, Name, true, |
| 1616 | LAngleLoc, TemplateArgs, |
| 1617 | NumTemplateArgs, RAngleLoc, |
| 1618 | Sema::DeclPtrTy(), &SS); |
| 1619 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1620 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1621 | /// \brief Build a new Objective-C @encode expression. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new expression. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1626 | QualType T, |
| 1627 | SourceLocation RParenLoc) { |
| 1628 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1629 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1630 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1631 | |
| 1632 | /// \brief Build a new Objective-C protocol expression. |
| 1633 | /// |
| 1634 | /// By default, performs semantic analysis to build the new expression. |
| 1635 | /// Subclasses may override this routine to provide different behavior. |
| 1636 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1637 | SourceLocation AtLoc, |
| 1638 | SourceLocation ProtoLoc, |
| 1639 | SourceLocation LParenLoc, |
| 1640 | SourceLocation RParenLoc) { |
| 1641 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1642 | Protocol->getIdentifier(), |
| 1643 | AtLoc, |
| 1644 | ProtoLoc, |
| 1645 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | /// \brief Build a new shuffle vector expression. |
| 1650 | /// |
| 1651 | /// By default, performs semantic analysis to build the new expression. |
| 1652 | /// Subclasses may override this routine to provide different behavior. |
| 1653 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1654 | MultiExprArg SubExprs, |
| 1655 | SourceLocation RParenLoc) { |
| 1656 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1659 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1660 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1661 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | // Build a reference to the __builtin_shufflevector builtin |
| 1664 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1665 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1666 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
| 1667 | BuiltinLoc, false, false); |
| 1668 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1669 | |
| 1670 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1671 | unsigned NumSubExprs = SubExprs.size(); |
| 1672 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1673 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1674 | Subs, NumSubExprs, |
| 1675 | Builtin->getResultType(), |
| 1676 | RParenLoc); |
| 1677 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1678 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1679 | // Type-check the __builtin_shufflevector expression. |
| 1680 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1681 | if (Result.isInvalid()) |
| 1682 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1683 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1684 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1686 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1687 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | template<typename Derived> |
| 1690 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1691 | if (!S) |
| 1692 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1694 | switch (S->getStmtClass()) { |
| 1695 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1697 | // Transform individual statement nodes |
| 1698 | #define STMT(Node, Parent) \ |
| 1699 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1700 | #define EXPR(Node, Parent) |
| 1701 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1703 | // Transform expressions by calling TransformExpr. |
| 1704 | #define STMT(Node, Parent) |
| 1705 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1706 | #include "clang/AST/StmtNodes.def" |
| 1707 | { |
| 1708 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1709 | if (E.isInvalid()) |
| 1710 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | |
Douglas Gregor | afe7ec2 | 2009-11-13 18:34:26 +0000 | [diff] [blame] | 1712 | return getSema().ActOnExprStmt(getSema().FullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1716 | return SemaRef.Owned(S->Retain()); |
| 1717 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
| 1719 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1720 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1721 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, |
| 1722 | bool isAddressOfOperand) { |
| 1723 | if (!E) |
| 1724 | return SemaRef.Owned(E); |
| 1725 | |
| 1726 | switch (E->getStmtClass()) { |
| 1727 | case Stmt::NoStmtClass: break; |
| 1728 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1729 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 1730 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \ |
| 1731 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1732 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1735 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1739 | NestedNameSpecifier * |
| 1740 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1741 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1742 | QualType ObjectType, |
| 1743 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1744 | if (!NNS) |
| 1745 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1747 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1748 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1749 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1751 | ObjectType, |
| 1752 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1753 | if (!Prefix) |
| 1754 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
| 1756 | // 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] | 1757 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1758 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1759 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 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 | switch (NNS->getKind()) { |
| 1763 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1764 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1765 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1766 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1767 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1768 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
| 1770 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1771 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1772 | ObjectType, |
| 1773 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1775 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1777 | = cast_or_null<NamespaceDecl>( |
| 1778 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1779 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1780 | Prefix == NNS->getPrefix() && |
| 1781 | NS == NNS->getAsNamespace()) |
| 1782 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1784 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1785 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1786 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1787 | case NestedNameSpecifier::Global: |
| 1788 | // There is no meaningful transformation that one could perform on the |
| 1789 | // global scope. |
| 1790 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1792 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1793 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1794 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1795 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1796 | if (T.isNull()) |
| 1797 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1799 | if (!getDerived().AlwaysRebuild() && |
| 1800 | Prefix == NNS->getPrefix() && |
| 1801 | T == QualType(NNS->getAsType(), 0)) |
| 1802 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
| 1804 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1805 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1806 | T); |
| 1807 | } |
| 1808 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1810 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1811 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1815 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1816 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1817 | SourceLocation Loc, |
| 1818 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1819 | if (!Name) |
| 1820 | return Name; |
| 1821 | |
| 1822 | switch (Name.getNameKind()) { |
| 1823 | case DeclarationName::Identifier: |
| 1824 | case DeclarationName::ObjCZeroArgSelector: |
| 1825 | case DeclarationName::ObjCOneArgSelector: |
| 1826 | case DeclarationName::ObjCMultiArgSelector: |
| 1827 | case DeclarationName::CXXOperatorName: |
| 1828 | case DeclarationName::CXXUsingDirective: |
| 1829 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1831 | case DeclarationName::CXXConstructorName: |
| 1832 | case DeclarationName::CXXDestructorName: |
| 1833 | case DeclarationName::CXXConversionFunctionName: { |
| 1834 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1835 | QualType T; |
| 1836 | if (!ObjectType.isNull() && |
| 1837 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1838 | TemplateSpecializationType *SpecType |
| 1839 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1840 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1841 | } else |
| 1842 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1843 | if (T.isNull()) |
| 1844 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1846 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1848 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1849 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1852 | return DeclarationName(); |
| 1853 | } |
| 1854 | |
| 1855 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1857 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1858 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1860 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1862 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1863 | if (!NNS) |
| 1864 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1865 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1869 | if (!TransTemplate) |
| 1870 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1872 | if (!getDerived().AlwaysRebuild() && |
| 1873 | NNS == QTN->getQualifier() && |
| 1874 | TransTemplate == Template) |
| 1875 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1877 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1878 | TransTemplate); |
| 1879 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1881 | OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl(); |
| 1882 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1883 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1884 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1885 | if (!TransOvl) |
| 1886 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | if (!getDerived().AlwaysRebuild() && |
| 1889 | NNS == QTN->getQualifier() && |
| 1890 | TransOvl == Ovl) |
| 1891 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1892 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1893 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1894 | TransOvl); |
| 1895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1896 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1897 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1899 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1900 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1901 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1902 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1903 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1904 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1905 | NNS == DTN->getQualifier() && |
| 1906 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1907 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1909 | if (DTN->isIdentifier()) |
| 1910 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1911 | ObjectType); |
| 1912 | |
| 1913 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1914 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1917 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1918 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1919 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1920 | if (!TransTemplate) |
| 1921 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1922 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1923 | if (!getDerived().AlwaysRebuild() && |
| 1924 | TransTemplate == Template) |
| 1925 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1927 | return TemplateName(TransTemplate); |
| 1928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1929 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1930 | OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl(); |
| 1931 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1932 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1933 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1934 | if (!TransOvl) |
| 1935 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1936 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1937 | if (!getDerived().AlwaysRebuild() && |
| 1938 | TransOvl == Ovl) |
| 1939 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1940 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1941 | return TemplateName(TransOvl); |
| 1942 | } |
| 1943 | |
| 1944 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1945 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1946 | const TemplateArgument &Arg, |
| 1947 | TemplateArgumentLoc &Output) { |
| 1948 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1949 | switch (Arg.getKind()) { |
| 1950 | case TemplateArgument::Null: |
| 1951 | llvm::llvm_unreachable("null template argument in TreeTransform"); |
| 1952 | break; |
| 1953 | |
| 1954 | case TemplateArgument::Type: |
| 1955 | Output = TemplateArgumentLoc(Arg, |
| 1956 | SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc)); |
| 1957 | |
| 1958 | break; |
| 1959 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1960 | case TemplateArgument::Template: |
| 1961 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1962 | break; |
| 1963 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1964 | case TemplateArgument::Expression: |
| 1965 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1966 | break; |
| 1967 | |
| 1968 | case TemplateArgument::Declaration: |
| 1969 | case TemplateArgument::Integral: |
| 1970 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1971 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1972 | break; |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | template<typename Derived> |
| 1977 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1978 | const TemplateArgumentLoc &Input, |
| 1979 | TemplateArgumentLoc &Output) { |
| 1980 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1981 | switch (Arg.getKind()) { |
| 1982 | case TemplateArgument::Null: |
| 1983 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1984 | Output = Input; |
| 1985 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1986 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1987 | case TemplateArgument::Type: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1988 | DeclaratorInfo *DI = Input.getSourceDeclaratorInfo(); |
| 1989 | if (DI == NULL) |
| 1990 | DI = InventDeclaratorInfo(Input.getArgument().getAsType()); |
| 1991 | |
| 1992 | DI = getDerived().TransformType(DI); |
| 1993 | if (!DI) return true; |
| 1994 | |
| 1995 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1996 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1997 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1998 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1999 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2000 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 2001 | DeclarationName Name; |
| 2002 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 2003 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2004 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2005 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2006 | if (!D) return true; |
| 2007 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2008 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 2009 | if (SourceExpr) { |
| 2010 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 2011 | Action::Unevaluated); |
| 2012 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 2013 | if (E.isInvalid()) |
| 2014 | SourceExpr = NULL; |
| 2015 | else { |
| 2016 | SourceExpr = E.takeAs<Expr>(); |
| 2017 | SourceExpr->Retain(); |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2022 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2023 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2025 | case TemplateArgument::Template: { |
| 2026 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2027 | TemplateName Template |
| 2028 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2029 | if (Template.isNull()) |
| 2030 | return true; |
| 2031 | |
| 2032 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2033 | Input.getTemplateQualifierRange(), |
| 2034 | Input.getTemplateNameLoc()); |
| 2035 | return false; |
| 2036 | } |
| 2037 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2038 | case TemplateArgument::Expression: { |
| 2039 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2040 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2041 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2042 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2043 | Expr *InputExpr = Input.getSourceExpression(); |
| 2044 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2045 | |
| 2046 | Sema::OwningExprResult E |
| 2047 | = getDerived().TransformExpr(InputExpr); |
| 2048 | if (E.isInvalid()) return true; |
| 2049 | |
| 2050 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2051 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2052 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2053 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2056 | case TemplateArgument::Pack: { |
| 2057 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2058 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2059 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2060 | AEnd = Arg.pack_end(); |
| 2061 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2063 | // FIXME: preserve source information here when we start |
| 2064 | // caring about parameter packs. |
| 2065 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2066 | TemplateArgumentLoc InputArg; |
| 2067 | TemplateArgumentLoc OutputArg; |
| 2068 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2069 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2070 | return true; |
| 2071 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2072 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2073 | } |
| 2074 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2075 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2076 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2077 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2078 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2079 | } |
| 2080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2082 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2083 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2086 | //===----------------------------------------------------------------------===// |
| 2087 | // Type transformation |
| 2088 | //===----------------------------------------------------------------------===// |
| 2089 | |
| 2090 | template<typename Derived> |
| 2091 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2092 | if (getDerived().AlreadyTransformed(T)) |
| 2093 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2094 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2095 | // Temporary workaround. All of these transformations should |
| 2096 | // eventually turn into transformations on TypeLocs. |
| 2097 | DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2098 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2099 | |
| 2100 | DeclaratorInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2101 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2102 | if (!NewDI) |
| 2103 | return QualType(); |
| 2104 | |
| 2105 | return NewDI->getType(); |
| 2106 | } |
| 2107 | |
| 2108 | template<typename Derived> |
| 2109 | DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) { |
| 2110 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2111 | return DI; |
| 2112 | |
| 2113 | TypeLocBuilder TLB; |
| 2114 | |
| 2115 | TypeLoc TL = DI->getTypeLoc(); |
| 2116 | TLB.reserve(TL.getFullDataSize()); |
| 2117 | |
| 2118 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2119 | if (Result.isNull()) |
| 2120 | return 0; |
| 2121 | |
| 2122 | return TLB.getDeclaratorInfo(SemaRef.Context, Result); |
| 2123 | } |
| 2124 | |
| 2125 | template<typename Derived> |
| 2126 | QualType |
| 2127 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2128 | switch (T.getTypeLocClass()) { |
| 2129 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2130 | #define TYPELOC(CLASS, PARENT) \ |
| 2131 | case TypeLoc::CLASS: \ |
| 2132 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2133 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2136 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2137 | return QualType(); |
| 2138 | } |
| 2139 | |
| 2140 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2141 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2142 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2143 | /// types). This is the right thing for template instantiation, but |
| 2144 | /// probably not for other clients. |
| 2145 | template<typename Derived> |
| 2146 | QualType |
| 2147 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2148 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2149 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2150 | |
| 2151 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2152 | if (Result.isNull()) |
| 2153 | return QualType(); |
| 2154 | |
| 2155 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2156 | // FIXME: this is the right thing for template instantiation, but |
| 2157 | // probably not for other clients. |
| 2158 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2159 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2160 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2161 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2162 | |
| 2163 | TLB.push<QualifiedTypeLoc>(Result); |
| 2164 | |
| 2165 | // No location information to preserve. |
| 2166 | |
| 2167 | return Result; |
| 2168 | } |
| 2169 | |
| 2170 | template <class TyLoc> static inline |
| 2171 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2172 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2173 | NewT.setNameLoc(T.getNameLoc()); |
| 2174 | return T.getType(); |
| 2175 | } |
| 2176 | |
| 2177 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2178 | // the equivalent template version work. |
| 2179 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2180 | QualType PointeeType \ |
| 2181 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2182 | if (PointeeType.isNull()) \ |
| 2183 | return QualType(); \ |
| 2184 | \ |
| 2185 | QualType Result = TL.getType(); \ |
| 2186 | if (getDerived().AlwaysRebuild() || \ |
| 2187 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2188 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2189 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2190 | if (Result.isNull()) \ |
| 2191 | return QualType(); \ |
| 2192 | } \ |
| 2193 | \ |
| 2194 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2195 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2196 | \ |
| 2197 | return Result; \ |
| 2198 | } while(0) |
| 2199 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2200 | template<typename Derived> |
| 2201 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2202 | BuiltinTypeLoc T) { |
| 2203 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2204 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2205 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2206 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2207 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2209 | FixedWidthIntTypeLoc T) { |
| 2210 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2211 | } |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2213 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2214 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2215 | ComplexTypeLoc T) { |
| 2216 | // FIXME: recurse? |
| 2217 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2218 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2219 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2220 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2221 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2222 | PointerTypeLoc TL) { |
| 2223 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2225 | |
| 2226 | template<typename Derived> |
| 2227 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2228 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2229 | BlockPointerTypeLoc TL) { |
| 2230 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2233 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2234 | /// don't care whether the type itself is an l-value type or an r-value |
| 2235 | /// type; we only care if the type was *written* as an l-value type |
| 2236 | /// or an r-value type. |
| 2237 | template<typename Derived> |
| 2238 | QualType |
| 2239 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2240 | ReferenceTypeLoc TL) { |
| 2241 | const ReferenceType *T = TL.getTypePtr(); |
| 2242 | |
| 2243 | // Note that this works with the pointee-as-written. |
| 2244 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2245 | if (PointeeType.isNull()) |
| 2246 | return QualType(); |
| 2247 | |
| 2248 | QualType Result = TL.getType(); |
| 2249 | if (getDerived().AlwaysRebuild() || |
| 2250 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2251 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2252 | T->isSpelledAsLValue(), |
| 2253 | TL.getSigilLoc()); |
| 2254 | if (Result.isNull()) |
| 2255 | return QualType(); |
| 2256 | } |
| 2257 | |
| 2258 | // r-value references can be rebuilt as l-value references. |
| 2259 | ReferenceTypeLoc NewTL; |
| 2260 | if (isa<LValueReferenceType>(Result)) |
| 2261 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2262 | else |
| 2263 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2264 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2265 | |
| 2266 | return Result; |
| 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>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2272 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2273 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | template<typename Derived> |
| 2277 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2278 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2279 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2280 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2282 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2283 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2284 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2285 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2286 | MemberPointerTypeLoc TL) { |
| 2287 | MemberPointerType *T = TL.getTypePtr(); |
| 2288 | |
| 2289 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2290 | if (PointeeType.isNull()) |
| 2291 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2292 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2293 | // TODO: preserve source information for this. |
| 2294 | QualType ClassType |
| 2295 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2296 | if (ClassType.isNull()) |
| 2297 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2299 | QualType Result = TL.getType(); |
| 2300 | if (getDerived().AlwaysRebuild() || |
| 2301 | PointeeType != T->getPointeeType() || |
| 2302 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2303 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2304 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2305 | if (Result.isNull()) |
| 2306 | return QualType(); |
| 2307 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2308 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2309 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2310 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2311 | |
| 2312 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2315 | template<typename Derived> |
| 2316 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2317 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2318 | ConstantArrayTypeLoc TL) { |
| 2319 | ConstantArrayType *T = TL.getTypePtr(); |
| 2320 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2321 | if (ElementType.isNull()) |
| 2322 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2324 | QualType Result = TL.getType(); |
| 2325 | if (getDerived().AlwaysRebuild() || |
| 2326 | ElementType != T->getElementType()) { |
| 2327 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2328 | T->getSizeModifier(), |
| 2329 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2330 | T->getIndexTypeCVRQualifiers(), |
| 2331 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2332 | if (Result.isNull()) |
| 2333 | return QualType(); |
| 2334 | } |
| 2335 | |
| 2336 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2337 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2338 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2339 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2340 | Expr *Size = TL.getSizeExpr(); |
| 2341 | if (Size) { |
| 2342 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2343 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2344 | } |
| 2345 | NewTL.setSizeExpr(Size); |
| 2346 | |
| 2347 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2349 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2350 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2351 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2352 | TypeLocBuilder &TLB, |
| 2353 | IncompleteArrayTypeLoc TL) { |
| 2354 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2355 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2356 | if (ElementType.isNull()) |
| 2357 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2358 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2359 | QualType Result = TL.getType(); |
| 2360 | if (getDerived().AlwaysRebuild() || |
| 2361 | ElementType != T->getElementType()) { |
| 2362 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2363 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2364 | T->getIndexTypeCVRQualifiers(), |
| 2365 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2366 | if (Result.isNull()) |
| 2367 | return QualType(); |
| 2368 | } |
| 2369 | |
| 2370 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2371 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2372 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2373 | NewTL.setSizeExpr(0); |
| 2374 | |
| 2375 | return Result; |
| 2376 | } |
| 2377 | |
| 2378 | template<typename Derived> |
| 2379 | QualType |
| 2380 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2381 | VariableArrayTypeLoc TL) { |
| 2382 | VariableArrayType *T = TL.getTypePtr(); |
| 2383 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2384 | if (ElementType.isNull()) |
| 2385 | return QualType(); |
| 2386 | |
| 2387 | // Array bounds are not potentially evaluated contexts |
| 2388 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2389 | |
| 2390 | Sema::OwningExprResult SizeResult |
| 2391 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2392 | if (SizeResult.isInvalid()) |
| 2393 | return QualType(); |
| 2394 | |
| 2395 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2396 | |
| 2397 | QualType Result = TL.getType(); |
| 2398 | if (getDerived().AlwaysRebuild() || |
| 2399 | ElementType != T->getElementType() || |
| 2400 | Size != T->getSizeExpr()) { |
| 2401 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2402 | T->getSizeModifier(), |
| 2403 | move(SizeResult), |
| 2404 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2405 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2406 | if (Result.isNull()) |
| 2407 | return QualType(); |
| 2408 | } |
| 2409 | else SizeResult.take(); |
| 2410 | |
| 2411 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2412 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2413 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2414 | NewTL.setSizeExpr(Size); |
| 2415 | |
| 2416 | return Result; |
| 2417 | } |
| 2418 | |
| 2419 | template<typename Derived> |
| 2420 | QualType |
| 2421 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2422 | DependentSizedArrayTypeLoc TL) { |
| 2423 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2424 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2425 | if (ElementType.isNull()) |
| 2426 | return QualType(); |
| 2427 | |
| 2428 | // Array bounds are not potentially evaluated contexts |
| 2429 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2430 | |
| 2431 | Sema::OwningExprResult SizeResult |
| 2432 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2433 | if (SizeResult.isInvalid()) |
| 2434 | return QualType(); |
| 2435 | |
| 2436 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2437 | |
| 2438 | QualType Result = TL.getType(); |
| 2439 | if (getDerived().AlwaysRebuild() || |
| 2440 | ElementType != T->getElementType() || |
| 2441 | Size != T->getSizeExpr()) { |
| 2442 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2443 | T->getSizeModifier(), |
| 2444 | move(SizeResult), |
| 2445 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2446 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2447 | if (Result.isNull()) |
| 2448 | return QualType(); |
| 2449 | } |
| 2450 | else SizeResult.take(); |
| 2451 | |
| 2452 | // We might have any sort of array type now, but fortunately they |
| 2453 | // all have the same location layout. |
| 2454 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2455 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2456 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2457 | NewTL.setSizeExpr(Size); |
| 2458 | |
| 2459 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2461 | |
| 2462 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2463 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2464 | TypeLocBuilder &TLB, |
| 2465 | DependentSizedExtVectorTypeLoc TL) { |
| 2466 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2467 | |
| 2468 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2469 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2470 | if (ElementType.isNull()) |
| 2471 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2472 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2473 | // Vector sizes are not potentially evaluated contexts |
| 2474 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2475 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2476 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2477 | if (Size.isInvalid()) |
| 2478 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2479 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2480 | QualType Result = TL.getType(); |
| 2481 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2482 | ElementType != T->getElementType() || |
| 2483 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2484 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2485 | move(Size), |
| 2486 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2487 | if (Result.isNull()) |
| 2488 | return QualType(); |
| 2489 | } |
| 2490 | else Size.take(); |
| 2491 | |
| 2492 | // Result might be dependent or not. |
| 2493 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2494 | DependentSizedExtVectorTypeLoc NewTL |
| 2495 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2496 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2497 | } else { |
| 2498 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2499 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2500 | } |
| 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> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2506 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2507 | VectorTypeLoc TL) { |
| 2508 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2509 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2510 | if (ElementType.isNull()) |
| 2511 | return QualType(); |
| 2512 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2513 | QualType Result = TL.getType(); |
| 2514 | if (getDerived().AlwaysRebuild() || |
| 2515 | ElementType != T->getElementType()) { |
| 2516 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2517 | if (Result.isNull()) |
| 2518 | return QualType(); |
| 2519 | } |
| 2520 | |
| 2521 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2522 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2523 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2524 | return Result; |
| 2525 | } |
| 2526 | |
| 2527 | template<typename Derived> |
| 2528 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2529 | ExtVectorTypeLoc TL) { |
| 2530 | VectorType *T = TL.getTypePtr(); |
| 2531 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2532 | if (ElementType.isNull()) |
| 2533 | return QualType(); |
| 2534 | |
| 2535 | QualType Result = TL.getType(); |
| 2536 | if (getDerived().AlwaysRebuild() || |
| 2537 | ElementType != T->getElementType()) { |
| 2538 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2539 | T->getNumElements(), |
| 2540 | /*FIXME*/ SourceLocation()); |
| 2541 | if (Result.isNull()) |
| 2542 | return QualType(); |
| 2543 | } |
| 2544 | |
| 2545 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2546 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2547 | |
| 2548 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2549 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2550 | |
| 2551 | template<typename Derived> |
| 2552 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2553 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2554 | FunctionProtoTypeLoc TL) { |
| 2555 | FunctionProtoType *T = TL.getTypePtr(); |
| 2556 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2557 | if (ResultType.isNull()) |
| 2558 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2559 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2560 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2561 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2562 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2563 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2564 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2566 | QualType NewType; |
| 2567 | ParmVarDecl *NewParm; |
| 2568 | |
| 2569 | if (OldParm) { |
| 2570 | DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo(); |
| 2571 | assert(OldDI->getType() == T->getArgType(i)); |
| 2572 | |
| 2573 | DeclaratorInfo *NewDI = getDerived().TransformType(OldDI); |
| 2574 | if (!NewDI) |
| 2575 | return QualType(); |
| 2576 | |
| 2577 | if (NewDI == OldDI) |
| 2578 | NewParm = OldParm; |
| 2579 | else |
| 2580 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2581 | OldParm->getDeclContext(), |
| 2582 | OldParm->getLocation(), |
| 2583 | OldParm->getIdentifier(), |
| 2584 | NewDI->getType(), |
| 2585 | NewDI, |
| 2586 | OldParm->getStorageClass(), |
| 2587 | /* DefArg */ NULL); |
| 2588 | NewType = NewParm->getType(); |
| 2589 | |
| 2590 | // Deal with the possibility that we don't have a parameter |
| 2591 | // declaration for this parameter. |
| 2592 | } else { |
| 2593 | NewParm = 0; |
| 2594 | |
| 2595 | QualType OldType = T->getArgType(i); |
| 2596 | NewType = getDerived().TransformType(OldType); |
| 2597 | if (NewType.isNull()) |
| 2598 | return QualType(); |
| 2599 | } |
| 2600 | |
| 2601 | ParamTypes.push_back(NewType); |
| 2602 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2603 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2605 | QualType Result = TL.getType(); |
| 2606 | if (getDerived().AlwaysRebuild() || |
| 2607 | ResultType != T->getResultType() || |
| 2608 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2609 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2610 | ParamTypes.data(), |
| 2611 | ParamTypes.size(), |
| 2612 | T->isVariadic(), |
| 2613 | T->getTypeQuals()); |
| 2614 | if (Result.isNull()) |
| 2615 | return QualType(); |
| 2616 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2617 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2618 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2619 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2620 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2621 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2622 | NewTL.setArg(i, ParamDecls[i]); |
| 2623 | |
| 2624 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2626 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2627 | template<typename Derived> |
| 2628 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2629 | TypeLocBuilder &TLB, |
| 2630 | FunctionNoProtoTypeLoc TL) { |
| 2631 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2632 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2633 | if (ResultType.isNull()) |
| 2634 | return QualType(); |
| 2635 | |
| 2636 | QualType Result = TL.getType(); |
| 2637 | if (getDerived().AlwaysRebuild() || |
| 2638 | ResultType != T->getResultType()) |
| 2639 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2640 | |
| 2641 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2642 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2643 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2644 | |
| 2645 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2647 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2648 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2649 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2650 | TypedefTypeLoc TL) { |
| 2651 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2652 | TypedefDecl *Typedef |
| 2653 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2654 | if (!Typedef) |
| 2655 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | QualType Result = TL.getType(); |
| 2658 | if (getDerived().AlwaysRebuild() || |
| 2659 | Typedef != T->getDecl()) { |
| 2660 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2661 | if (Result.isNull()) |
| 2662 | return QualType(); |
| 2663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2665 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2666 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2667 | |
| 2668 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2671 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2672 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2673 | TypeOfExprTypeLoc TL) { |
| 2674 | TypeOfExprType *T = TL.getTypePtr(); |
| 2675 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2676 | // typeof expressions are not potentially evaluated contexts |
| 2677 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2678 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2679 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2680 | if (E.isInvalid()) |
| 2681 | return QualType(); |
| 2682 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | QualType Result = TL.getType(); |
| 2684 | if (getDerived().AlwaysRebuild() || |
| 2685 | E.get() != T->getUnderlyingExpr()) { |
| 2686 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2687 | if (Result.isNull()) |
| 2688 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2691 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2692 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2693 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2694 | |
| 2695 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2696 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | |
| 2698 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2699 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2700 | TypeOfTypeLoc TL) { |
| 2701 | TypeOfType *T = TL.getTypePtr(); |
| 2702 | |
| 2703 | // FIXME: should be an inner type, or at least have a DeclaratorInfo. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2704 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2705 | if (Underlying.isNull()) |
| 2706 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2707 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2708 | QualType Result = TL.getType(); |
| 2709 | if (getDerived().AlwaysRebuild() || |
| 2710 | Underlying != T->getUnderlyingType()) { |
| 2711 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2712 | if (Result.isNull()) |
| 2713 | return QualType(); |
| 2714 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2717 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2718 | |
| 2719 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2720 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | |
| 2722 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2724 | DecltypeTypeLoc TL) { |
| 2725 | DecltypeType *T = TL.getTypePtr(); |
| 2726 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2727 | // decltype expressions are not potentially evaluated contexts |
| 2728 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2729 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2730 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2731 | if (E.isInvalid()) |
| 2732 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2733 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | QualType Result = TL.getType(); |
| 2735 | if (getDerived().AlwaysRebuild() || |
| 2736 | E.get() != T->getUnderlyingExpr()) { |
| 2737 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2738 | if (Result.isNull()) |
| 2739 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2740 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2741 | else E.take(); |
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 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2744 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2745 | |
| 2746 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2751 | RecordTypeLoc TL) { |
| 2752 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2753 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2755 | if (!Record) |
| 2756 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2758 | QualType Result = TL.getType(); |
| 2759 | if (getDerived().AlwaysRebuild() || |
| 2760 | Record != T->getDecl()) { |
| 2761 | Result = getDerived().RebuildRecordType(Record); |
| 2762 | if (Result.isNull()) |
| 2763 | return QualType(); |
| 2764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2766 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2767 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2768 | |
| 2769 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2770 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2771 | |
| 2772 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2773 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2774 | EnumTypeLoc TL) { |
| 2775 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2776 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2777 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2778 | if (!Enum) |
| 2779 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2780 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2781 | QualType Result = TL.getType(); |
| 2782 | if (getDerived().AlwaysRebuild() || |
| 2783 | Enum != T->getDecl()) { |
| 2784 | Result = getDerived().RebuildEnumType(Enum); |
| 2785 | if (Result.isNull()) |
| 2786 | return QualType(); |
| 2787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2789 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2790 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2791 | |
| 2792 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2793 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2794 | |
| 2795 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2796 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2797 | ElaboratedTypeLoc TL) { |
| 2798 | ElaboratedType *T = TL.getTypePtr(); |
| 2799 | |
| 2800 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2801 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2802 | if (Underlying.isNull()) |
| 2803 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2805 | QualType Result = TL.getType(); |
| 2806 | if (getDerived().AlwaysRebuild() || |
| 2807 | Underlying != T->getUnderlyingType()) { |
| 2808 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2809 | if (Result.isNull()) |
| 2810 | return QualType(); |
| 2811 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2812 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2814 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2815 | |
| 2816 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2817 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2818 | |
| 2819 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | template<typename Derived> |
| 2821 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2822 | TypeLocBuilder &TLB, |
| 2823 | TemplateTypeParmTypeLoc TL) { |
| 2824 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2827 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2828 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2829 | TypeLocBuilder &TLB, |
| 2830 | SubstTemplateTypeParmTypeLoc TL) { |
| 2831 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2835 | inline QualType |
| 2836 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | TypeLocBuilder &TLB, |
| 2838 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2839 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2840 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2841 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2842 | template<typename Derived> |
| 2843 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2844 | const TemplateSpecializationType *TST, |
| 2845 | QualType ObjectType) { |
| 2846 | // FIXME: this entire method is a temporary workaround; callers |
| 2847 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2849 | // Fake up a TemplateSpecializationTypeLoc. |
| 2850 | TypeLocBuilder TLB; |
| 2851 | TemplateSpecializationTypeLoc TL |
| 2852 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2853 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2854 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2855 | |
| 2856 | TL.setTemplateNameLoc(BaseLoc); |
| 2857 | TL.setLAngleLoc(BaseLoc); |
| 2858 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2859 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2860 | const TemplateArgument &TA = TST->getArg(i); |
| 2861 | TemplateArgumentLoc TAL; |
| 2862 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2863 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2864 | } |
| 2865 | |
| 2866 | TypeLocBuilder IgnoredTLB; |
| 2867 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2871 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2872 | TypeLocBuilder &TLB, |
| 2873 | TemplateSpecializationTypeLoc TL, |
| 2874 | QualType ObjectType) { |
| 2875 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2876 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2878 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2879 | if (Template.isNull()) |
| 2880 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2881 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2882 | llvm::SmallVector<TemplateArgumentLoc, 4> NewTemplateArgs(T->getNumArgs()); |
| 2883 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) |
| 2884 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), |
| 2885 | NewTemplateArgs[i])) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2886 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2887 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2888 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2889 | |
| 2890 | QualType Result = |
| 2891 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2892 | TL.getTemplateNameLoc(), |
| 2893 | TL.getLAngleLoc(), |
| 2894 | NewTemplateArgs.data(), |
| 2895 | NewTemplateArgs.size(), |
| 2896 | TL.getRAngleLoc()); |
| 2897 | |
| 2898 | if (!Result.isNull()) { |
| 2899 | TemplateSpecializationTypeLoc NewTL |
| 2900 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2901 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2902 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2903 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2904 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2905 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2906 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2908 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2909 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | |
| 2911 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2912 | QualType |
| 2913 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2914 | QualifiedNameTypeLoc TL) { |
| 2915 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2916 | NestedNameSpecifier *NNS |
| 2917 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2918 | SourceRange()); |
| 2919 | if (!NNS) |
| 2920 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2922 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2923 | if (Named.isNull()) |
| 2924 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2925 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2926 | QualType Result = TL.getType(); |
| 2927 | if (getDerived().AlwaysRebuild() || |
| 2928 | NNS != T->getQualifier() || |
| 2929 | Named != T->getNamedType()) { |
| 2930 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2931 | if (Result.isNull()) |
| 2932 | return QualType(); |
| 2933 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2934 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2936 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2937 | |
| 2938 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2940 | |
| 2941 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2942 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2943 | TypenameTypeLoc TL) { |
| 2944 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2945 | |
| 2946 | /* FIXME: preserve source information better than this */ |
| 2947 | SourceRange SR(TL.getNameLoc()); |
| 2948 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2949 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2950 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2951 | if (!NNS) |
| 2952 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2954 | QualType Result; |
| 2955 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2956 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2957 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2958 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2959 | if (NewTemplateId.isNull()) |
| 2960 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2961 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2962 | if (!getDerived().AlwaysRebuild() && |
| 2963 | NNS == T->getQualifier() && |
| 2964 | NewTemplateId == QualType(TemplateId, 0)) |
| 2965 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2966 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2967 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2968 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2969 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2970 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2971 | if (Result.isNull()) |
| 2972 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2973 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2974 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2975 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2976 | |
| 2977 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2978 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2980 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2981 | QualType |
| 2982 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2983 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2984 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2985 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 | |
| 2988 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2989 | QualType |
| 2990 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2991 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2992 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2993 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2996 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2997 | // Statement transformation |
| 2998 | //===----------------------------------------------------------------------===// |
| 2999 | template<typename Derived> |
| 3000 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3002 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | template<typename Derived> |
| 3006 | Sema::OwningStmtResult |
| 3007 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3008 | return getDerived().TransformCompoundStmt(S, false); |
| 3009 | } |
| 3010 | |
| 3011 | template<typename Derived> |
| 3012 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3014 | bool IsStmtExpr) { |
| 3015 | bool SubStmtChanged = false; |
| 3016 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3017 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3018 | B != BEnd; ++B) { |
| 3019 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3020 | if (Result.isInvalid()) |
| 3021 | return getSema().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 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3024 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3025 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3026 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3027 | if (!getDerived().AlwaysRebuild() && |
| 3028 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3030 | |
| 3031 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3032 | move_arg(Statements), |
| 3033 | S->getRBracLoc(), |
| 3034 | IsStmtExpr); |
| 3035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3037 | template<typename Derived> |
| 3038 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3040 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3041 | { |
| 3042 | // The case value expressions are not potentially evaluated. |
| 3043 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3044 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3045 | // Transform the left-hand case value. |
| 3046 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3047 | if (LHS.isInvalid()) |
| 3048 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3049 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3050 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3051 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3052 | if (RHS.isInvalid()) |
| 3053 | return SemaRef.StmtError(); |
| 3054 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3055 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3056 | // Build the case statement. |
| 3057 | // Case statements are always rebuilt so that they will attached to their |
| 3058 | // transformed switch statement. |
| 3059 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3060 | move(LHS), |
| 3061 | S->getEllipsisLoc(), |
| 3062 | move(RHS), |
| 3063 | S->getColonLoc()); |
| 3064 | if (Case.isInvalid()) |
| 3065 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3067 | // Transform the statement following the case |
| 3068 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3069 | if (SubStmt.isInvalid()) |
| 3070 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3071 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3072 | // Attach the body to the case statement |
| 3073 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3074 | } |
| 3075 | |
| 3076 | template<typename Derived> |
| 3077 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | // Transform the statement following the default case |
| 3080 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3081 | if (SubStmt.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 | // Default statements are always rebuilt |
| 3085 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3086 | move(SubStmt)); |
| 3087 | } |
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 | template<typename Derived> |
| 3090 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3091 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3092 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3093 | if (SubStmt.isInvalid()) |
| 3094 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3095 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3096 | // FIXME: Pass the real colon location in. |
| 3097 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3098 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3099 | move(SubStmt)); |
| 3100 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3102 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3103 | Sema::OwningStmtResult |
| 3104 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3105 | // Transform the condition |
| 3106 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3107 | if (Cond.isInvalid()) |
| 3108 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3110 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3112 | // Transform the "then" branch. |
| 3113 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3114 | if (Then.isInvalid()) |
| 3115 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3117 | // Transform the "else" branch. |
| 3118 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3119 | if (Else.isInvalid()) |
| 3120 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3121 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | if (!getDerived().AlwaysRebuild() && |
| 3123 | FullCond->get() == S->getCond() && |
| 3124 | Then.get() == S->getThen() && |
| 3125 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3126 | return SemaRef.Owned(S->Retain()); |
| 3127 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3129 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | template<typename Derived> |
| 3133 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3134 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3135 | // Transform the condition. |
| 3136 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3137 | if (Cond.isInvalid()) |
| 3138 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3139 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3140 | // Rebuild the switch statement. |
| 3141 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond)); |
| 3142 | if (Switch.isInvalid()) |
| 3143 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3145 | // Transform the body of the switch statement. |
| 3146 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3147 | if (Body.isInvalid()) |
| 3148 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3150 | // Complete the switch statement. |
| 3151 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3152 | move(Body)); |
| 3153 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | template<typename Derived> |
| 3156 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3157 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3158 | // Transform the condition |
| 3159 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3160 | if (Cond.isInvalid()) |
| 3161 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3165 | // Transform the body |
| 3166 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3167 | if (Body.isInvalid()) |
| 3168 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3170 | if (!getDerived().AlwaysRebuild() && |
| 3171 | FullCond->get() == S->getCond() && |
| 3172 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | return SemaRef.Owned(S->Retain()); |
| 3174 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3175 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body)); |
| 3176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3177 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3178 | template<typename Derived> |
| 3179 | Sema::OwningStmtResult |
| 3180 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3181 | // Transform the condition |
| 3182 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3183 | if (Cond.isInvalid()) |
| 3184 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3185 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3186 | // Transform the body |
| 3187 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3188 | if (Body.isInvalid()) |
| 3189 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3191 | if (!getDerived().AlwaysRebuild() && |
| 3192 | Cond.get() == S->getCond() && |
| 3193 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | return SemaRef.Owned(S->Retain()); |
| 3195 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3196 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3197 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3198 | S->getRParenLoc()); |
| 3199 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3200 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3201 | template<typename Derived> |
| 3202 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3203 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3204 | // Transform the initialization statement |
| 3205 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3206 | if (Init.isInvalid()) |
| 3207 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3208 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3209 | // Transform the condition |
| 3210 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3211 | if (Cond.isInvalid()) |
| 3212 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3213 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3214 | // Transform the increment |
| 3215 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3216 | if (Inc.isInvalid()) |
| 3217 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3218 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3219 | // Transform the body |
| 3220 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3221 | if (Body.isInvalid()) |
| 3222 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3223 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3224 | if (!getDerived().AlwaysRebuild() && |
| 3225 | Init.get() == S->getInit() && |
| 3226 | Cond.get() == S->getCond() && |
| 3227 | Inc.get() == S->getInc() && |
| 3228 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | return SemaRef.Owned(S->Retain()); |
| 3230 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 3232 | move(Init), move(Cond), move(Inc), |
| 3233 | S->getRParenLoc(), move(Body)); |
| 3234 | } |
| 3235 | |
| 3236 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3237 | Sema::OwningStmtResult |
| 3238 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3239 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3240 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3241 | S->getLabel()); |
| 3242 | } |
| 3243 | |
| 3244 | template<typename Derived> |
| 3245 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3248 | if (Target.isInvalid()) |
| 3249 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | if (!getDerived().AlwaysRebuild() && |
| 3252 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3253 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3254 | |
| 3255 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3256 | move(Target)); |
| 3257 | } |
| 3258 | |
| 3259 | template<typename Derived> |
| 3260 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3262 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3265 | template<typename Derived> |
| 3266 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3268 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3269 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | template<typename Derived> |
| 3272 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3275 | if (Result.isInvalid()) |
| 3276 | return SemaRef.StmtError(); |
| 3277 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3279 | // to tell whether the return type of the function has changed. |
| 3280 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | template<typename Derived> |
| 3284 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | bool DeclChanged = false; |
| 3287 | llvm::SmallVector<Decl *, 4> Decls; |
| 3288 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3289 | D != DEnd; ++D) { |
| 3290 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3291 | if (!Transformed) |
| 3292 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3294 | if (Transformed != *D) |
| 3295 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3296 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3297 | Decls.push_back(Transformed); |
| 3298 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3300 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3301 | return SemaRef.Owned(S->Retain()); |
| 3302 | |
| 3303 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | S->getStartLoc(), S->getEndLoc()); |
| 3305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3306 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3307 | template<typename Derived> |
| 3308 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | template<typename Derived> |
| 3315 | Sema::OwningStmtResult |
| 3316 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3317 | // FIXME: Implement! |
| 3318 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3319 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | |
| 3323 | template<typename Derived> |
| 3324 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3325 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3326 | // FIXME: Implement this |
| 3327 | assert(false && "Cannot transform an Objective-C @try statement"); |
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 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3331 | template<typename Derived> |
| 3332 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3334 | // FIXME: Implement this |
| 3335 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3336 | return SemaRef.Owned(S->Retain()); |
| 3337 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | template<typename Derived> |
| 3340 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // FIXME: Implement this |
| 3343 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3346 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3347 | template<typename Derived> |
| 3348 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | // FIXME: Implement this |
| 3351 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3354 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3355 | template<typename Derived> |
| 3356 | Sema::OwningStmtResult |
| 3357 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | ObjCAtSynchronizedStmt *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 @synchronized 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 | } |
| 3363 | |
| 3364 | template<typename Derived> |
| 3365 | Sema::OwningStmtResult |
| 3366 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | ObjCForCollectionStmt *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 for-each 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 | |
| 3374 | template<typename Derived> |
| 3375 | Sema::OwningStmtResult |
| 3376 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3377 | // Transform the exception declaration, if any. |
| 3378 | VarDecl *Var = 0; |
| 3379 | if (S->getExceptionDecl()) { |
| 3380 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3381 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3382 | ExceptionDecl->getDeclName()); |
| 3383 | |
| 3384 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3385 | if (T.isNull()) |
| 3386 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3387 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3388 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3389 | T, |
| 3390 | ExceptionDecl->getDeclaratorInfo(), |
| 3391 | ExceptionDecl->getIdentifier(), |
| 3392 | ExceptionDecl->getLocation(), |
| 3393 | /*FIXME: Inaccurate*/ |
| 3394 | SourceRange(ExceptionDecl->getLocation())); |
| 3395 | if (!Var || Var->isInvalidDecl()) { |
| 3396 | if (Var) |
| 3397 | Var->Destroy(SemaRef.Context); |
| 3398 | return SemaRef.StmtError(); |
| 3399 | } |
| 3400 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3401 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3402 | // Transform the actual exception handler. |
| 3403 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3404 | if (Handler.isInvalid()) { |
| 3405 | if (Var) |
| 3406 | Var->Destroy(SemaRef.Context); |
| 3407 | return SemaRef.StmtError(); |
| 3408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3410 | if (!getDerived().AlwaysRebuild() && |
| 3411 | !Var && |
| 3412 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3413 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | |
| 3415 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3416 | Var, |
| 3417 | move(Handler)); |
| 3418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3420 | template<typename Derived> |
| 3421 | Sema::OwningStmtResult |
| 3422 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3423 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3424 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3426 | if (TryBlock.isInvalid()) |
| 3427 | return SemaRef.StmtError(); |
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 | // Transform the handlers. |
| 3430 | bool HandlerChanged = false; |
| 3431 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3432 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3434 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3435 | if (Handler.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 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3439 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3440 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | if (!getDerived().AlwaysRebuild() && |
| 3443 | TryBlock.get() == S->getTryBlock() && |
| 3444 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3446 | |
| 3447 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3452 | // Expression transformation |
| 3453 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | template<typename Derived> |
| 3455 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3456 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E, |
| 3457 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3459 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3460 | |
| 3461 | template<typename Derived> |
| 3462 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3463 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E, |
| 3464 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3465 | NestedNameSpecifier *Qualifier = 0; |
| 3466 | if (E->getQualifier()) { |
| 3467 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3468 | E->getQualifierRange()); |
| 3469 | if (!Qualifier) |
| 3470 | return SemaRef.ExprError(); |
| 3471 | } |
| 3472 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | NamedDecl *ND |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3474 | = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); |
| 3475 | if (!ND) |
| 3476 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3477 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3478 | if (!getDerived().AlwaysRebuild() && |
| 3479 | Qualifier == E->getQualifier() && |
| 3480 | ND == E->getDecl() && |
| 3481 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | return SemaRef.Owned(E->Retain()); |
| 3483 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3484 | // FIXME: We're losing the explicit template arguments in this transformation. |
| 3485 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3486 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3487 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3488 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3489 | TransArgs[I])) |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3490 | return SemaRef.ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | // FIXME: Pass the qualifier/qualifier range along. |
| 3494 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3495 | ND, E->getLocation(), |
| 3496 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3497 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3499 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3501 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E, |
| 3502 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3506 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3508 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E, |
| 3509 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3510 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3511 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3512 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3513 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3515 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E, |
| 3516 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3519 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3520 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3522 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E, |
| 3523 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3524 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3525 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3527 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3529 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E, |
| 3530 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3531 | return SemaRef.Owned(E->Retain()); |
| 3532 | } |
| 3533 | |
| 3534 | template<typename Derived> |
| 3535 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3536 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E, |
| 3537 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3538 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3539 | if (SubExpr.isInvalid()) |
| 3540 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3542 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3543 | return SemaRef.Owned(E->Retain()); |
| 3544 | |
| 3545 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | E->getRParen()); |
| 3547 | } |
| 3548 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | template<typename Derived> |
| 3550 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3551 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E, |
| 3552 | bool isAddressOfOperand) { |
| 3553 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(), |
| 3554 | E->getOpcode() == UnaryOperator::AddrOf); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3555 | if (SubExpr.isInvalid()) |
| 3556 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3557 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3558 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3559 | return SemaRef.Owned(E->Retain()); |
| 3560 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3561 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3562 | E->getOpcode(), |
| 3563 | move(SubExpr)); |
| 3564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3565 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3566 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3567 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3568 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, |
| 3569 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3570 | if (E->isArgumentType()) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3571 | DeclaratorInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3572 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3573 | DeclaratorInfo *NewT = getDerived().TransformType(OldT); |
| 3574 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3575 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3577 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3578 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3579 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3580 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3581 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3582 | E->getSourceRange()); |
| 3583 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3585 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3586 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3587 | // C++0x [expr.sizeof]p1: |
| 3588 | // The operand is either an expression, which is an unevaluated operand |
| 3589 | // [...] |
| 3590 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3592 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3593 | if (SubExpr.isInvalid()) |
| 3594 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3597 | return SemaRef.Owned(E->Retain()); |
| 3598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3600 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3601 | E->isSizeOf(), |
| 3602 | E->getSourceRange()); |
| 3603 | } |
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 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3606 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3607 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E, |
| 3608 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3609 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3610 | if (LHS.isInvalid()) |
| 3611 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3612 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3614 | if (RHS.isInvalid()) |
| 3615 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
| 3617 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | if (!getDerived().AlwaysRebuild() && |
| 3619 | LHS.get() == E->getLHS() && |
| 3620 | RHS.get() == E->getRHS()) |
| 3621 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3624 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3625 | move(RHS), |
| 3626 | E->getRBracketLoc()); |
| 3627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3628 | |
| 3629 | template<typename Derived> |
| 3630 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3631 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E, |
| 3632 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3633 | // Transform the callee. |
| 3634 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3635 | if (Callee.isInvalid()) |
| 3636 | return SemaRef.ExprError(); |
| 3637 | |
| 3638 | // Transform arguments. |
| 3639 | bool ArgChanged = false; |
| 3640 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3641 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3642 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3643 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3644 | if (Arg.isInvalid()) |
| 3645 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3647 | // FIXME: Wrong source location information for the ','. |
| 3648 | FakeCommaLocs.push_back( |
| 3649 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
| 3651 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | Args.push_back(Arg.takeAs<Expr>()); |
| 3653 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3655 | if (!getDerived().AlwaysRebuild() && |
| 3656 | Callee.get() == E->getCallee() && |
| 3657 | !ArgChanged) |
| 3658 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3660 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3662 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3663 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3664 | move_arg(Args), |
| 3665 | FakeCommaLocs.data(), |
| 3666 | E->getRParenLoc()); |
| 3667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3668 | |
| 3669 | template<typename Derived> |
| 3670 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3671 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E, |
| 3672 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3673 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3674 | if (Base.isInvalid()) |
| 3675 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3676 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3677 | NestedNameSpecifier *Qualifier = 0; |
| 3678 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3679 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3680 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3681 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3682 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3683 | return SemaRef.ExprError(); |
| 3684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | |
| 3686 | NamedDecl *Member |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3687 | = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
| 3688 | if (!Member) |
| 3689 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | if (!getDerived().AlwaysRebuild() && |
| 3692 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3693 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3694 | Member == E->getMemberDecl() && |
| 3695 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3696 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3697 | |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3698 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs; |
| 3699 | if (E->hasExplicitTemplateArgumentList()) { |
| 3700 | TransArgs.resize(E->getNumTemplateArgs()); |
| 3701 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3702 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3703 | TransArgs[I])) |
| 3704 | return SemaRef.ExprError(); |
| 3705 | } |
| 3706 | } |
| 3707 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3708 | // FIXME: Bogus source location for the operator |
| 3709 | SourceLocation FakeOperatorLoc |
| 3710 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3711 | |
| 3712 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3713 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3714 | Qualifier, |
| 3715 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3716 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3717 | Member, |
| 3718 | E->hasExplicitTemplateArgumentList(), |
| 3719 | E->getLAngleLoc(), |
| 3720 | TransArgs.data(), |
| 3721 | TransArgs.size(), |
| 3722 | E->getRAngleLoc(), |
| 3723 | 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3724 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3725 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3726 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3728 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E, |
| 3729 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | assert(false && "Cannot transform abstract class"); |
| 3731 | return SemaRef.Owned(E->Retain()); |
| 3732 | } |
| 3733 | |
| 3734 | template<typename Derived> |
| 3735 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3736 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E, |
| 3737 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3738 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3739 | if (LHS.isInvalid()) |
| 3740 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3741 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3742 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3743 | if (RHS.isInvalid()) |
| 3744 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | if (!getDerived().AlwaysRebuild() && |
| 3747 | LHS.get() == E->getLHS() && |
| 3748 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3749 | return SemaRef.Owned(E->Retain()); |
| 3750 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3752 | move(LHS), move(RHS)); |
| 3753 | } |
| 3754 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3756 | Sema::OwningExprResult |
| 3757 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3758 | CompoundAssignOperator *E, |
| 3759 | bool isAddressOfOperand) { |
| 3760 | return getDerived().TransformBinaryOperator(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3762 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3763 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3764 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3765 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E, |
| 3766 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3767 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3768 | if (Cond.isInvalid()) |
| 3769 | return SemaRef.ExprError(); |
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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3772 | if (LHS.isInvalid()) |
| 3773 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3775 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3776 | if (RHS.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 | if (!getDerived().AlwaysRebuild() && |
| 3780 | Cond.get() == E->getCond() && |
| 3781 | LHS.get() == E->getLHS() && |
| 3782 | RHS.get() == E->getRHS()) |
| 3783 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3784 | |
| 3785 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3786 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3788 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3789 | move(RHS)); |
| 3790 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
| 3792 | template<typename Derived> |
| 3793 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3794 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E, |
| 3795 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3796 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3797 | |
| 3798 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3799 | // so do we even need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3800 | QualType T = getDerived().TransformType(E->getType()); |
| 3801 | if (T.isNull()) |
| 3802 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3803 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3804 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3805 | if (SubExpr.isInvalid()) |
| 3806 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3807 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3808 | if (!getDerived().AlwaysRebuild() && |
| 3809 | T == E->getType() && |
| 3810 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3811 | return SemaRef.Owned(E->Retain()); |
| 3812 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3813 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3815 | E->isLvalueCast()); |
| 3816 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | template<typename Derived> |
| 3819 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3820 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E, |
| 3821 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | assert(false && "Cannot transform abstract class"); |
| 3823 | return SemaRef.Owned(E->Retain()); |
| 3824 | } |
| 3825 | |
| 3826 | template<typename Derived> |
| 3827 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3828 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E, |
| 3829 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3830 | QualType T; |
| 3831 | { |
| 3832 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3835 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3838 | if (T.isNull()) |
| 3839 | return SemaRef.ExprError(); |
| 3840 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3843 | if (SubExpr.isInvalid()) |
| 3844 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3846 | if (!getDerived().AlwaysRebuild() && |
| 3847 | T == E->getTypeAsWritten() && |
| 3848 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3849 | return SemaRef.Owned(E->Retain()); |
| 3850 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3851 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3852 | E->getRParenLoc(), |
| 3853 | move(SubExpr)); |
| 3854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3858 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E, |
| 3859 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3860 | QualType T; |
| 3861 | { |
| 3862 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | SourceLocation FakeTypeLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3865 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | T = getDerived().TransformType(E->getType()); |
| 3868 | if (T.isNull()) |
| 3869 | return SemaRef.ExprError(); |
| 3870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3873 | if (Init.isInvalid()) |
| 3874 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | if (!getDerived().AlwaysRebuild() && |
| 3877 | T == E->getType() && |
| 3878 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3880 | |
| 3881 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3882 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3883 | move(Init)); |
| 3884 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3886 | template<typename Derived> |
| 3887 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3888 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E, |
| 3889 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3890 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3891 | if (Base.isInvalid()) |
| 3892 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 3895 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | return SemaRef.Owned(E->Retain()); |
| 3897 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3901 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3902 | E->getAccessorLoc(), |
| 3903 | E->getAccessor()); |
| 3904 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3905 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3906 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3908 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E, |
| 3909 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3910 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3913 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3914 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3915 | if (Init.isInvalid()) |
| 3916 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3917 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3918 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3919 | Inits.push_back(Init.takeAs<Expr>()); |
| 3920 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3923 | return SemaRef.Owned(E->Retain()); |
| 3924 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3926 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3928 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3929 | template<typename Derived> |
| 3930 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3931 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E, |
| 3932 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3933 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3934 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3935 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3937 | if (Init.isInvalid()) |
| 3938 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3940 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3941 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3942 | bool ExprChanged = false; |
| 3943 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3944 | DEnd = E->designators_end(); |
| 3945 | D != DEnd; ++D) { |
| 3946 | if (D->isFieldDesignator()) { |
| 3947 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3948 | D->getDotLoc(), |
| 3949 | D->getFieldLoc())); |
| 3950 | continue; |
| 3951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3952 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3953 | if (D->isArrayDesignator()) { |
| 3954 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3955 | if (Index.isInvalid()) |
| 3956 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3957 | |
| 3958 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | D->getLBracketLoc())); |
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 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3962 | ArrayExprs.push_back(Index.release()); |
| 3963 | continue; |
| 3964 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3966 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3969 | if (Start.isInvalid()) |
| 3970 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3972 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3973 | if (End.isInvalid()) |
| 3974 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3975 | |
| 3976 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | End.get(), |
| 3978 | D->getLBracketLoc(), |
| 3979 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3980 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3982 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | ArrayExprs.push_back(Start.release()); |
| 3985 | ArrayExprs.push_back(End.release()); |
| 3986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3988 | if (!getDerived().AlwaysRebuild() && |
| 3989 | Init.get() == E->getInit() && |
| 3990 | !ExprChanged) |
| 3991 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3994 | E->getEqualOrColonLoc(), |
| 3995 | E->usesGNUSyntax(), move(Init)); |
| 3996 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3998 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4001 | ImplicitValueInitExpr *E, |
| 4002 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4003 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4004 | |
| 4005 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4006 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4007 | QualType T = getDerived().TransformType(E->getType()); |
| 4008 | if (T.isNull()) |
| 4009 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4011 | if (!getDerived().AlwaysRebuild() && |
| 4012 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | return SemaRef.Owned(E->Retain()); |
| 4014 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4018 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4020 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E, |
| 4021 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4022 | // FIXME: Do we want the type as written? |
| 4023 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4024 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4025 | { |
| 4026 | // FIXME: Source location isn't quite accurate. |
| 4027 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4028 | T = getDerived().TransformType(E->getType()); |
| 4029 | if (T.isNull()) |
| 4030 | return SemaRef.ExprError(); |
| 4031 | } |
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 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4034 | if (SubExpr.isInvalid()) |
| 4035 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | if (!getDerived().AlwaysRebuild() && |
| 4038 | T == E->getType() && |
| 4039 | SubExpr.get() == E->getSubExpr()) |
| 4040 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4042 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4043 | T, E->getRParenLoc()); |
| 4044 | } |
| 4045 | |
| 4046 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4048 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E, |
| 4049 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4050 | bool ArgumentChanged = false; |
| 4051 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4052 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4053 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4054 | if (Init.isInvalid()) |
| 4055 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4056 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4057 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4058 | Inits.push_back(Init.takeAs<Expr>()); |
| 4059 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4060 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4061 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4062 | move_arg(Inits), |
| 4063 | E->getRParenLoc()); |
| 4064 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4065 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4066 | /// \brief Transform an address-of-label expression. |
| 4067 | /// |
| 4068 | /// By default, the transformation of an address-of-label expression always |
| 4069 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4070 | /// the corresponding label statement by semantic analysis. |
| 4071 | template<typename Derived> |
| 4072 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4073 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E, |
| 4074 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4075 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4076 | E->getLabel()); |
| 4077 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4078 | |
| 4079 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4080 | Sema::OwningExprResult |
| 4081 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E, |
| 4082 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4085 | if (SubStmt.isInvalid()) |
| 4086 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | if (!getDerived().AlwaysRebuild() && |
| 4089 | SubStmt.get() == E->getSubStmt()) |
| 4090 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | |
| 4092 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | move(SubStmt), |
| 4094 | E->getRParenLoc()); |
| 4095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | template<typename Derived> |
| 4098 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4099 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E, |
| 4100 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4101 | QualType T1, T2; |
| 4102 | { |
| 4103 | // FIXME: Source location isn't quite accurate. |
| 4104 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4106 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4107 | if (T1.isNull()) |
| 4108 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4111 | if (T2.isNull()) |
| 4112 | return SemaRef.ExprError(); |
| 4113 | } |
| 4114 | |
| 4115 | if (!getDerived().AlwaysRebuild() && |
| 4116 | T1 == E->getArgType1() && |
| 4117 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4118 | return SemaRef.Owned(E->Retain()); |
| 4119 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4121 | T1, T2, E->getRParenLoc()); |
| 4122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | template<typename Derived> |
| 4125 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4126 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E, |
| 4127 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4129 | if (Cond.isInvalid()) |
| 4130 | return SemaRef.ExprError(); |
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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4133 | if (LHS.isInvalid()) |
| 4134 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4135 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4136 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4137 | if (RHS.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 | if (!getDerived().AlwaysRebuild() && |
| 4141 | Cond.get() == E->getCond() && |
| 4142 | LHS.get() == E->getLHS() && |
| 4143 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4144 | return SemaRef.Owned(E->Retain()); |
| 4145 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4147 | move(Cond), move(LHS), move(RHS), |
| 4148 | E->getRParenLoc()); |
| 4149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4152 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4153 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E, |
| 4154 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | template<typename Derived> |
| 4159 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4160 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E, |
| 4161 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4162 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4163 | if (Callee.isInvalid()) |
| 4164 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4165 | |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4166 | OwningExprResult First |
| 4167 | = getDerived().TransformExpr(E->getArg(0), |
| 4168 | E->getNumArgs() == 1 && E->getOperator() == OO_Amp); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | if (First.isInvalid()) |
| 4170 | return SemaRef.ExprError(); |
| 4171 | |
| 4172 | OwningExprResult Second(SemaRef); |
| 4173 | if (E->getNumArgs() == 2) { |
| 4174 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4175 | if (Second.isInvalid()) |
| 4176 | return SemaRef.ExprError(); |
| 4177 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4178 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4179 | if (!getDerived().AlwaysRebuild() && |
| 4180 | Callee.get() == E->getCallee() && |
| 4181 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4182 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4183 | return SemaRef.Owned(E->Retain()); |
| 4184 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4185 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4186 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | move(First), |
| 4189 | move(Second)); |
| 4190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | template<typename Derived> |
| 4193 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4194 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E, |
| 4195 | bool isAddressOfOperand) { |
| 4196 | return getDerived().TransformCallExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4197 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4198 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4199 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4201 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E, |
| 4202 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4203 | QualType ExplicitTy; |
| 4204 | { |
| 4205 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4208 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4211 | if (ExplicitTy.isNull()) |
| 4212 | return SemaRef.ExprError(); |
| 4213 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4215 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4216 | if (SubExpr.isInvalid()) |
| 4217 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4218 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | if (!getDerived().AlwaysRebuild() && |
| 4220 | ExplicitTy == E->getTypeAsWritten() && |
| 4221 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | return SemaRef.Owned(E->Retain()); |
| 4223 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4227 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4228 | SourceLocation FakeRParenLoc |
| 4229 | = SemaRef.PP.getLocForEndOfToken( |
| 4230 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4231 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4232 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4233 | FakeLAngleLoc, |
| 4234 | ExplicitTy, |
| 4235 | FakeRAngleLoc, |
| 4236 | FakeRAngleLoc, |
| 4237 | move(SubExpr), |
| 4238 | FakeRParenLoc); |
| 4239 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | template<typename Derived> |
| 4242 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4243 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E, |
| 4244 | bool isAddressOfOperand) { |
| 4245 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | |
| 4248 | template<typename Derived> |
| 4249 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4250 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E, |
| 4251 | bool isAddressOfOperand) { |
| 4252 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | template<typename Derived> |
| 4256 | Sema::OwningExprResult |
| 4257 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4258 | CXXReinterpretCastExpr *E, |
| 4259 | bool isAddressOfOperand) { |
| 4260 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4261 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | template<typename Derived> |
| 4264 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4265 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E, |
| 4266 | bool isAddressOfOperand) { |
| 4267 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | template<typename Derived> |
| 4271 | Sema::OwningExprResult |
| 4272 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4273 | CXXFunctionalCastExpr *E, |
| 4274 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4275 | QualType ExplicitTy; |
| 4276 | { |
| 4277 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4278 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4279 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4280 | if (ExplicitTy.isNull()) |
| 4281 | return SemaRef.ExprError(); |
| 4282 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4283 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4284 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4285 | if (SubExpr.isInvalid()) |
| 4286 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4287 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4288 | if (!getDerived().AlwaysRebuild() && |
| 4289 | ExplicitTy == E->getTypeAsWritten() && |
| 4290 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | return SemaRef.Owned(E->Retain()); |
| 4292 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4293 | // FIXME: The end of the type's source range is wrong |
| 4294 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4295 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4296 | ExplicitTy, |
| 4297 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4298 | move(SubExpr), |
| 4299 | E->getRParenLoc()); |
| 4300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4301 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4302 | template<typename Derived> |
| 4303 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4304 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E, |
| 4305 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | if (E->isTypeOperand()) { |
| 4307 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4308 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4310 | if (T.isNull()) |
| 4311 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4312 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4313 | if (!getDerived().AlwaysRebuild() && |
| 4314 | T == E->getTypeOperand()) |
| 4315 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4318 | /*FIXME:*/E->getLocStart(), |
| 4319 | T, |
| 4320 | E->getLocEnd()); |
| 4321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4322 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4323 | // We don't know whether the expression is potentially evaluated until |
| 4324 | // after we perform semantic analysis, so the expression is potentially |
| 4325 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4326 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4327 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4328 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4329 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4330 | if (SubExpr.isInvalid()) |
| 4331 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4332 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4333 | if (!getDerived().AlwaysRebuild() && |
| 4334 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | return SemaRef.Owned(E->Retain()); |
| 4336 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4338 | /*FIXME:*/E->getLocStart(), |
| 4339 | move(SubExpr), |
| 4340 | E->getLocEnd()); |
| 4341 | } |
| 4342 | |
| 4343 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4345 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E, |
| 4346 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | template<typename Derived> |
| 4351 | Sema::OwningExprResult |
| 4352 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4353 | CXXNullPtrLiteralExpr *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 |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4360 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E, |
| 4361 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4362 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4363 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | QualType T = getDerived().TransformType(E->getType()); |
| 4365 | if (T.isNull()) |
| 4366 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4367 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4368 | if (!getDerived().AlwaysRebuild() && |
| 4369 | T == E->getType()) |
| 4370 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | template<typename Derived> |
| 4376 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4377 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E, |
| 4378 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4380 | if (SubExpr.isInvalid()) |
| 4381 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4384 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | |
| 4387 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | template<typename Derived> |
| 4391 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4392 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E, |
| 4393 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4395 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4396 | if (!Param) |
| 4397 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4398 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4399 | if (getDerived().AlwaysRebuild() && |
| 4400 | Param == E->getParam()) |
| 4401 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4402 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4403 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4404 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | template<typename Derived> |
| 4407 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4408 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E, |
| 4409 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4410 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4411 | |
| 4412 | QualType T = getDerived().TransformType(E->getType()); |
| 4413 | if (T.isNull()) |
| 4414 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | if (!getDerived().AlwaysRebuild() && |
| 4417 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | return SemaRef.Owned(E->Retain()); |
| 4419 | |
| 4420 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4422 | T, |
| 4423 | E->getRParenLoc()); |
| 4424 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | template<typename Derived> |
| 4427 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4428 | TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E, |
| 4429 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | VarDecl *Var |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4431 | = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | if (!Var) |
| 4433 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | Var == E->getVarDecl()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4437 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
| 4439 | return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | /*FIXME:*/E->getStartLoc(), |
| 4441 | Var); |
| 4442 | } |
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 | template<typename Derived> |
| 4445 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4446 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E, |
| 4447 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | // Transform the type that we're allocating |
| 4449 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4450 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4451 | if (AllocType.isNull()) |
| 4452 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4454 | // Transform the size of the array we're allocating (if any). |
| 4455 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4456 | if (ArraySize.isInvalid()) |
| 4457 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | // Transform the placement arguments (if any). |
| 4460 | bool ArgumentChanged = false; |
| 4461 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4462 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4463 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4464 | if (Arg.isInvalid()) |
| 4465 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4467 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4468 | PlacementArgs.push_back(Arg.take()); |
| 4469 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4470 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4471 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4473 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4474 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4475 | if (Arg.isInvalid()) |
| 4476 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4478 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4479 | ConstructorArgs.push_back(Arg.take()); |
| 4480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | if (!getDerived().AlwaysRebuild() && |
| 4483 | AllocType == E->getAllocatedType() && |
| 4484 | ArraySize.get() == E->getArraySize() && |
| 4485 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4486 | return SemaRef.Owned(E->Retain()); |
| 4487 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4489 | E->isGlobalNew(), |
| 4490 | /*FIXME:*/E->getLocStart(), |
| 4491 | move_arg(PlacementArgs), |
| 4492 | /*FIXME:*/E->getLocStart(), |
| 4493 | E->isParenTypeId(), |
| 4494 | AllocType, |
| 4495 | /*FIXME:*/E->getLocStart(), |
| 4496 | /*FIXME:*/SourceRange(), |
| 4497 | move(ArraySize), |
| 4498 | /*FIXME:*/E->getLocStart(), |
| 4499 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4503 | template<typename Derived> |
| 4504 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4505 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E, |
| 4506 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4508 | if (Operand.isInvalid()) |
| 4509 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4512 | Operand.get() == E->getArgument()) |
| 4513 | return SemaRef.Owned(E->Retain()); |
| 4514 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4515 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4516 | E->isGlobalDelete(), |
| 4517 | E->isArrayForm(), |
| 4518 | move(Operand)); |
| 4519 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4520 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4521 | template<typename Derived> |
| 4522 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4523 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4524 | CXXPseudoDestructorExpr *E, |
| 4525 | bool isAddressOfOperand) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4526 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4527 | if (Base.isInvalid()) |
| 4528 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4530 | NestedNameSpecifier *Qualifier |
| 4531 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4532 | E->getQualifierRange()); |
| 4533 | if (E->getQualifier() && !Qualifier) |
| 4534 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4536 | QualType DestroyedType; |
| 4537 | { |
| 4538 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4539 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4540 | if (DestroyedType.isNull()) |
| 4541 | return SemaRef.ExprError(); |
| 4542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4544 | if (!getDerived().AlwaysRebuild() && |
| 4545 | Base.get() == E->getBase() && |
| 4546 | Qualifier == E->getQualifier() && |
| 4547 | DestroyedType == E->getDestroyedType()) |
| 4548 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4550 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4551 | E->getOperatorLoc(), |
| 4552 | E->isArrow(), |
| 4553 | E->getDestroyedTypeLoc(), |
| 4554 | DestroyedType, |
| 4555 | Qualifier, |
| 4556 | E->getQualifierRange()); |
| 4557 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4559 | template<typename Derived> |
| 4560 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4562 | UnresolvedFunctionNameExpr *E, |
| 4563 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4564 | // There is no transformation we can apply to an unresolved function name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4565 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4566 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4568 | template<typename Derived> |
| 4569 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4570 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E, |
| 4571 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4572 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4574 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4575 | if (T.isNull()) |
| 4576 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4577 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4578 | if (!getDerived().AlwaysRebuild() && |
| 4579 | T == E->getQueriedType()) |
| 4580 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | // FIXME: Bad location information |
| 4583 | SourceLocation FakeLParenLoc |
| 4584 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | |
| 4586 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4587 | E->getLocStart(), |
| 4588 | /*FIXME:*/FakeLParenLoc, |
| 4589 | T, |
| 4590 | E->getLocEnd()); |
| 4591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4592 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4593 | template<typename Derived> |
| 4594 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 4595 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 4596 | DependentScopeDeclRefExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4597 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4598 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4599 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4600 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | if (!NNS) |
| 4602 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4603 | |
| 4604 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4605 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4606 | if (!Name) |
| 4607 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4608 | |
| 4609 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4610 | NNS == E->getQualifier() && |
| 4611 | Name == E->getDeclName()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4612 | return SemaRef.Owned(E->Retain()); |
| 4613 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 4614 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4615 | E->getQualifierRange(), |
| 4616 | Name, |
| 4617 | E->getLocation(), |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4618 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | template<typename Derived> |
| 4622 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4623 | TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E, |
| 4624 | bool isAddressOfOperand) { |
Douglas Gregor | fd2300e | 2009-10-29 17:56:10 +0000 | [diff] [blame] | 4625 | TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName()); |
| 4626 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | TemplateName Template |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4628 | = getDerived().TransformTemplateName(E->getTemplateName()); |
| 4629 | if (Template.isNull()) |
| 4630 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4631 | |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4632 | NestedNameSpecifier *Qualifier = 0; |
| 4633 | if (E->getQualifier()) { |
| 4634 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4635 | E->getQualifierRange()); |
| 4636 | if (!Qualifier) |
| 4637 | return SemaRef.ExprError(); |
| 4638 | } |
| 4639 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4640 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4642 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4643 | TransArgs[I])) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | return SemaRef.ExprError(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | // FIXME: Would like to avoid rebuilding if nothing changed, but we can't |
| 4648 | // compare template arguments (yet). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4649 | |
| 4650 | // FIXME: It's possible that we'll find out now that the template name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | // actually refers to a type, in which case the caller is actually dealing |
| 4652 | // with a functional cast. Give a reasonable error message! |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4653 | return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(), |
| 4654 | Template, E->getTemplateNameLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | E->getLAngleLoc(), |
| 4656 | TransArgs.data(), |
| 4657 | TransArgs.size(), |
| 4658 | E->getRAngleLoc()); |
| 4659 | } |
| 4660 | |
| 4661 | template<typename Derived> |
| 4662 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4663 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E, |
| 4664 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4665 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4666 | |
| 4667 | QualType T = getDerived().TransformType(E->getType()); |
| 4668 | if (T.isNull()) |
| 4669 | return SemaRef.ExprError(); |
| 4670 | |
| 4671 | CXXConstructorDecl *Constructor |
| 4672 | = cast_or_null<CXXConstructorDecl>( |
| 4673 | getDerived().TransformDecl(E->getConstructor())); |
| 4674 | if (!Constructor) |
| 4675 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4676 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4677 | bool ArgumentChanged = false; |
| 4678 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4680 | ArgEnd = E->arg_end(); |
| 4681 | Arg != ArgEnd; ++Arg) { |
| 4682 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4683 | if (TransArg.isInvalid()) |
| 4684 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4685 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4686 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4687 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4688 | } |
| 4689 | |
| 4690 | if (!getDerived().AlwaysRebuild() && |
| 4691 | T == E->getType() && |
| 4692 | Constructor == E->getConstructor() && |
| 4693 | !ArgumentChanged) |
| 4694 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4697 | move_arg(Args)); |
| 4698 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4699 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4700 | /// \brief Transform a C++ temporary-binding expression. |
| 4701 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | /// The transformation of a temporary-binding expression always attempts to |
| 4703 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4704 | /// subexpression itself did not change, because the temporary variable itself |
| 4705 | /// must be unique. |
| 4706 | template<typename Derived> |
| 4707 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4708 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E, |
| 4709 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4711 | if (SubExpr.isInvalid()) |
| 4712 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4714 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4715 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4716 | |
| 4717 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4718 | /// be destroyed after the expression is evaluated. |
| 4719 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4720 | /// The transformation of a full expression always attempts to build a new |
| 4721 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4722 | /// subexpression itself did not change, because it will need to capture the |
| 4723 | /// the new temporary variables introduced in the subexpression. |
| 4724 | template<typename Derived> |
| 4725 | Sema::OwningExprResult |
| 4726 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4727 | CXXExprWithTemporaries *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.Owned( |
| 4734 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4735 | E->shouldDestroyTemporaries())); |
| 4736 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4738 | template<typename Derived> |
| 4739 | Sema::OwningExprResult |
| 4740 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4741 | CXXTemporaryObjectExpr *E, |
| 4742 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4743 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4744 | QualType T = getDerived().TransformType(E->getType()); |
| 4745 | if (T.isNull()) |
| 4746 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4748 | CXXConstructorDecl *Constructor |
| 4749 | = cast_or_null<CXXConstructorDecl>( |
| 4750 | getDerived().TransformDecl(E->getConstructor())); |
| 4751 | if (!Constructor) |
| 4752 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4754 | bool ArgumentChanged = false; |
| 4755 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4756 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4757 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4758 | ArgEnd = E->arg_end(); |
| 4759 | Arg != ArgEnd; ++Arg) { |
| 4760 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4761 | if (TransArg.isInvalid()) |
| 4762 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4765 | Args.push_back((Expr *)TransArg.release()); |
| 4766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4768 | if (!getDerived().AlwaysRebuild() && |
| 4769 | T == E->getType() && |
| 4770 | Constructor == E->getConstructor() && |
| 4771 | !ArgumentChanged) |
| 4772 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | // FIXME: Bogus location information |
| 4775 | SourceLocation CommaLoc; |
| 4776 | if (Args.size() > 1) { |
| 4777 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4778 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4780 | } |
| 4781 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4782 | T, |
| 4783 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4784 | move_arg(Args), |
| 4785 | &CommaLoc, |
| 4786 | E->getLocEnd()); |
| 4787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | template<typename Derived> |
| 4790 | Sema::OwningExprResult |
| 4791 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4792 | CXXUnresolvedConstructExpr *E, |
| 4793 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4795 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4796 | if (T.isNull()) |
| 4797 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4799 | bool ArgumentChanged = false; |
| 4800 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4801 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4802 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4803 | ArgEnd = E->arg_end(); |
| 4804 | Arg != ArgEnd; ++Arg) { |
| 4805 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4806 | if (TransArg.isInvalid()) |
| 4807 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4809 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4810 | FakeCommaLocs.push_back( |
| 4811 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4812 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4813 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4815 | if (!getDerived().AlwaysRebuild() && |
| 4816 | T == E->getTypeAsWritten() && |
| 4817 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4818 | return SemaRef.Owned(E->Retain()); |
| 4819 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4820 | // FIXME: we're faking the locations of the commas |
| 4821 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4822 | T, |
| 4823 | E->getLParenLoc(), |
| 4824 | move_arg(Args), |
| 4825 | FakeCommaLocs.data(), |
| 4826 | E->getRParenLoc()); |
| 4827 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4828 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4829 | template<typename Derived> |
| 4830 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 4831 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 4832 | CXXDependentScopeMemberExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4833 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | // Transform the base of the expression. |
| 4835 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4836 | if (Base.isInvalid()) |
| 4837 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4838 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4839 | // Start the member reference and compute the object's type. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4840 | Sema::TypeTy *ObjectType = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4842 | E->getOperatorLoc(), |
| 4843 | E->isArrow()? tok::arrow : tok::period, |
| 4844 | ObjectType); |
| 4845 | if (Base.isInvalid()) |
| 4846 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4848 | // Transform the first part of the nested-name-specifier that qualifies |
| 4849 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4850 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4851 | = getDerived().TransformFirstQualifierInScope( |
| 4852 | E->getFirstQualifierFoundInScope(), |
| 4853 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4855 | NestedNameSpecifier *Qualifier = 0; |
| 4856 | if (E->getQualifier()) { |
| 4857 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4858 | E->getQualifierRange(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4859 | QualType::getFromOpaquePtr(ObjectType), |
| 4860 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4861 | if (!Qualifier) |
| 4862 | return SemaRef.ExprError(); |
| 4863 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4864 | |
| 4865 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4866 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
| 4867 | QualType::getFromOpaquePtr(ObjectType)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4868 | if (!Name) |
| 4869 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4870 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4871 | if (!E->hasExplicitTemplateArgumentList()) { |
| 4872 | // This is a reference to a member without an explicitly-specified |
| 4873 | // template argument list. Optimize for this common case. |
| 4874 | if (!getDerived().AlwaysRebuild() && |
| 4875 | Base.get() == E->getBase() && |
| 4876 | Qualifier == E->getQualifier() && |
| 4877 | Name == E->getMember() && |
| 4878 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4879 | return SemaRef.Owned(E->Retain()); |
| 4880 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 4881 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4882 | E->isArrow(), |
| 4883 | E->getOperatorLoc(), |
| 4884 | Qualifier, |
| 4885 | E->getQualifierRange(), |
| 4886 | Name, |
| 4887 | E->getMemberLoc(), |
| 4888 | FirstQualifierInScope); |
| 4889 | } |
| 4890 | |
| 4891 | // FIXME: This is an ugly hack, which forces the same template name to |
| 4892 | // be looked up multiple times. Yuck! |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 4893 | TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName()); |
| 4894 | TemplateName OrigTemplateName; |
| 4895 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) |
| 4896 | OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II); |
| 4897 | else |
| 4898 | OrigTemplateName |
| 4899 | = SemaRef.Context.getDependentTemplateName(0, |
| 4900 | Name.getCXXOverloadedOperator()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
| 4902 | TemplateName Template |
| 4903 | = getDerived().TransformTemplateName(OrigTemplateName, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4904 | QualType::getFromOpaquePtr(ObjectType)); |
| 4905 | if (Template.isNull()) |
| 4906 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4907 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4908 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4909 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4910 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4911 | TransArgs[I])) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4912 | return SemaRef.ExprError(); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame^] | 4915 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4916 | E->isArrow(), |
| 4917 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4918 | Qualifier, |
| 4919 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4920 | Template, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4921 | E->getMemberLoc(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4922 | FirstQualifierInScope, |
| 4923 | E->getLAngleLoc(), |
| 4924 | TransArgs.data(), |
| 4925 | TransArgs.size(), |
| 4926 | E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | template<typename Derived> |
| 4930 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4931 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E, |
| 4932 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4933 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4936 | template<typename Derived> |
| 4937 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4938 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E, |
| 4939 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4940 | // FIXME: poor source location |
| 4941 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 4942 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 4943 | if (EncodedType.isNull()) |
| 4944 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4945 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4946 | if (!getDerived().AlwaysRebuild() && |
| 4947 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4949 | |
| 4950 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 4951 | EncodedType, |
| 4952 | E->getRParenLoc()); |
| 4953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4954 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4955 | template<typename Derived> |
| 4956 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4957 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E, |
| 4958 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4959 | // FIXME: Implement this! |
| 4960 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4961 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4962 | } |
| 4963 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4964 | template<typename Derived> |
| 4965 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4966 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E, |
| 4967 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4971 | template<typename Derived> |
| 4972 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4973 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E, |
| 4974 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4975 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4976 | = cast_or_null<ObjCProtocolDecl>( |
| 4977 | getDerived().TransformDecl(E->getProtocol())); |
| 4978 | if (!Protocol) |
| 4979 | return SemaRef.ExprError(); |
| 4980 | |
| 4981 | if (!getDerived().AlwaysRebuild() && |
| 4982 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4983 | return SemaRef.Owned(E->Retain()); |
| 4984 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4985 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 4986 | E->getAtLoc(), |
| 4987 | /*FIXME:*/E->getAtLoc(), |
| 4988 | /*FIXME:*/E->getAtLoc(), |
| 4989 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4990 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4991 | } |
| 4992 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | template<typename Derived> |
| 4994 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4995 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E, |
| 4996 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4997 | // FIXME: Implement this! |
| 4998 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5002 | template<typename Derived> |
| 5003 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5004 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E, |
| 5005 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5006 | // FIXME: Implement this! |
| 5007 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5008 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | template<typename Derived> |
| 5012 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5013 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5014 | ObjCImplicitSetterGetterRefExpr *E, |
| 5015 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5016 | // FIXME: Implement this! |
| 5017 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5018 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5019 | } |
| 5020 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | template<typename Derived> |
| 5022 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5023 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E, |
| 5024 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5025 | // FIXME: Implement this! |
| 5026 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5027 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | template<typename Derived> |
| 5031 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5032 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E, |
| 5033 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5034 | // FIXME: Implement this! |
| 5035 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5039 | template<typename Derived> |
| 5040 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5041 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E, |
| 5042 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5043 | bool ArgumentChanged = false; |
| 5044 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5045 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5046 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5047 | if (SubExpr.isInvalid()) |
| 5048 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5049 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5050 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5051 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | if (!getDerived().AlwaysRebuild() && |
| 5055 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5056 | return SemaRef.Owned(E->Retain()); |
| 5057 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5058 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5059 | move_arg(SubExprs), |
| 5060 | E->getRParenLoc()); |
| 5061 | } |
| 5062 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5063 | template<typename Derived> |
| 5064 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5065 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E, |
| 5066 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | // FIXME: Implement this! |
| 5068 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5069 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5072 | template<typename Derived> |
| 5073 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5074 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E, |
| 5075 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5076 | // FIXME: Implement this! |
| 5077 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5078 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5079 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5081 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5082 | // Type reconstruction |
| 5083 | //===----------------------------------------------------------------------===// |
| 5084 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5085 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5086 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5087 | SourceLocation Star) { |
| 5088 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5089 | getDerived().getBaseEntity()); |
| 5090 | } |
| 5091 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5092 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5093 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5094 | SourceLocation Star) { |
| 5095 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5096 | getDerived().getBaseEntity()); |
| 5097 | } |
| 5098 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5099 | template<typename Derived> |
| 5100 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5101 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5102 | bool WrittenAsLValue, |
| 5103 | SourceLocation Sigil) { |
| 5104 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5105 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5109 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5110 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5111 | QualType ClassType, |
| 5112 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5113 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5114 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5118 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5119 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5120 | SourceLocation Sigil) { |
| 5121 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5122 | getDerived().getBaseEntity()); |
| 5123 | } |
| 5124 | |
| 5125 | template<typename Derived> |
| 5126 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5127 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5128 | ArrayType::ArraySizeModifier SizeMod, |
| 5129 | const llvm::APInt *Size, |
| 5130 | Expr *SizeExpr, |
| 5131 | unsigned IndexTypeQuals, |
| 5132 | SourceRange BracketsRange) { |
| 5133 | if (SizeExpr || !Size) |
| 5134 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5135 | IndexTypeQuals, BracketsRange, |
| 5136 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | |
| 5138 | QualType Types[] = { |
| 5139 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5140 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5141 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5142 | }; |
| 5143 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5144 | QualType SizeType; |
| 5145 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5146 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5147 | SizeType = Types[I]; |
| 5148 | break; |
| 5149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5151 | if (SizeType.isNull()) |
| 5152 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5154 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5155 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5156 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5157 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5158 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5159 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5160 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | QualType |
| 5162 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5163 | ArrayType::ArraySizeModifier SizeMod, |
| 5164 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5165 | unsigned IndexTypeQuals, |
| 5166 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5168 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5173 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5174 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5175 | unsigned IndexTypeQuals, |
| 5176 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5177 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5178 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5180 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5181 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | QualType |
| 5183 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5184 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5185 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5186 | unsigned IndexTypeQuals, |
| 5187 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5188 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5189 | SizeExpr.takeAs<Expr>(), |
| 5190 | IndexTypeQuals, BracketsRange); |
| 5191 | } |
| 5192 | |
| 5193 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | QualType |
| 5195 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5196 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5197 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5198 | unsigned IndexTypeQuals, |
| 5199 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5200 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5201 | SizeExpr.takeAs<Expr>(), |
| 5202 | IndexTypeQuals, BracketsRange); |
| 5203 | } |
| 5204 | |
| 5205 | template<typename Derived> |
| 5206 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5207 | unsigned NumElements) { |
| 5208 | // FIXME: semantic checking! |
| 5209 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5210 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5212 | template<typename Derived> |
| 5213 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5214 | unsigned NumElements, |
| 5215 | SourceLocation AttributeLoc) { |
| 5216 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5217 | NumElements, true); |
| 5218 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5219 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5220 | AttributeLoc); |
| 5221 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5222 | AttributeLoc); |
| 5223 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5224 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5225 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | QualType |
| 5227 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5228 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5229 | SourceLocation AttributeLoc) { |
| 5230 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5231 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5233 | template<typename Derived> |
| 5234 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5235 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5236 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5237 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5238 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5239 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5240 | Quals, |
| 5241 | getDerived().getBaseLocation(), |
| 5242 | getDerived().getBaseEntity()); |
| 5243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5245 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5246 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5247 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5248 | } |
| 5249 | |
| 5250 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5251 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5252 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5253 | } |
| 5254 | |
| 5255 | template<typename Derived> |
| 5256 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5257 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5258 | } |
| 5259 | |
| 5260 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5261 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5262 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5263 | } |
| 5264 | |
| 5265 | template<typename Derived> |
| 5266 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5267 | TemplateName Template, |
| 5268 | SourceLocation TemplateNameLoc, |
| 5269 | SourceLocation LAngleLoc, |
| 5270 | const TemplateArgumentLoc *Args, |
| 5271 | unsigned NumArgs, |
| 5272 | SourceLocation RAngleLoc) { |
| 5273 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, LAngleLoc, |
| 5274 | Args, NumArgs, RAngleLoc); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5277 | template<typename Derived> |
| 5278 | NestedNameSpecifier * |
| 5279 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5280 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5281 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5282 | QualType ObjectType, |
| 5283 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5284 | CXXScopeSpec SS; |
| 5285 | // FIXME: The source location information is all wrong. |
| 5286 | SS.setRange(Range); |
| 5287 | SS.setScopeRep(Prefix); |
| 5288 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5289 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5290 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5291 | ObjectType, |
| 5292 | FirstQualifierInScope, |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5293 | false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | template<typename Derived> |
| 5297 | NestedNameSpecifier * |
| 5298 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5299 | SourceRange Range, |
| 5300 | NamespaceDecl *NS) { |
| 5301 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5302 | } |
| 5303 | |
| 5304 | template<typename Derived> |
| 5305 | NestedNameSpecifier * |
| 5306 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5307 | SourceRange Range, |
| 5308 | bool TemplateKW, |
| 5309 | QualType T) { |
| 5310 | if (T->isDependentType() || T->isRecordType() || |
| 5311 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5312 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5313 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5314 | T.getTypePtr()); |
| 5315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5316 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5317 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5318 | return 0; |
| 5319 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5320 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5321 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5322 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5323 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5324 | bool TemplateKW, |
| 5325 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5327 | Template); |
| 5328 | } |
| 5329 | |
| 5330 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5332 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5333 | bool TemplateKW, |
| 5334 | OverloadedFunctionDecl *Ovl) { |
| 5335 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl); |
| 5336 | } |
| 5337 | |
| 5338 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5339 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5340 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5341 | const IdentifierInfo &II, |
| 5342 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5343 | CXXScopeSpec SS; |
| 5344 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5346 | UnqualifiedId Name; |
| 5347 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5348 | return getSema().ActOnDependentTemplateName( |
| 5349 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5350 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5351 | Name, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5352 | ObjectType.getAsOpaquePtr()) |
| 5353 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5354 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5355 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5356 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5357 | TemplateName |
| 5358 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5359 | OverloadedOperatorKind Operator, |
| 5360 | QualType ObjectType) { |
| 5361 | CXXScopeSpec SS; |
| 5362 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5363 | SS.setScopeRep(Qualifier); |
| 5364 | UnqualifiedId Name; |
| 5365 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5366 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5367 | Operator, SymbolLocations); |
| 5368 | return getSema().ActOnDependentTemplateName( |
| 5369 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5370 | SS, |
| 5371 | Name, |
| 5372 | ObjectType.getAsOpaquePtr()) |
| 5373 | .template getAsVal<TemplateName>(); |
| 5374 | } |
| 5375 | |
| 5376 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5377 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5378 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5379 | SourceLocation OpLoc, |
| 5380 | ExprArg Callee, |
| 5381 | ExprArg First, |
| 5382 | ExprArg Second) { |
| 5383 | Expr *FirstExpr = (Expr *)First.get(); |
| 5384 | Expr *SecondExpr = (Expr *)Second.get(); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5385 | DeclRefExpr *DRE |
| 5386 | = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5387 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5388 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5389 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5390 | if (Op == OO_Subscript) { |
| 5391 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5392 | !SecondExpr->getType()->isOverloadableType()) |
| 5393 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
| 5394 | DRE->getLocStart(), |
| 5395 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5396 | } else if (Op == OO_Arrow) { |
| 5397 | // -> is never a builtin operation. |
| 5398 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5399 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5401 | // The argument is not of overloadable type, so try to create a |
| 5402 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5404 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5406 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5407 | } |
| 5408 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5409 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5410 | !SecondExpr->getType()->isOverloadableType()) { |
| 5411 | // Neither of the arguments is an overloadable type, so try to |
| 5412 | // create a built-in binary operation. |
| 5413 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5415 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5416 | if (Result.isInvalid()) |
| 5417 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5419 | First.release(); |
| 5420 | Second.release(); |
| 5421 | return move(Result); |
| 5422 | } |
| 5423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
| 5425 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5426 | // used during overload resolution. |
| 5427 | Sema::FunctionSet Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5429 | // FIXME: Do we have to check |
| 5430 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
Douglas Gregor | 8f1d89e | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 5431 | for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5432 | Functions.insert(*F); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5433 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5434 | // Add any functions found via argument-dependent lookup. |
| 5435 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5436 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5437 | DeclarationName OpName |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5438 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | 644be85 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5439 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5440 | Functions); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5442 | // Create the overloaded operator invocation for unary operators. |
| 5443 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5445 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5446 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5447 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5448 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5449 | if (Op == OO_Subscript) |
| 5450 | return SemaRef.CreateOverloadedArraySubscriptExpr(DRE->getLocStart(), OpLoc, |
| 5451 | move(First),move(Second)); |
| 5452 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5453 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5454 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5455 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5457 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5458 | if (Result.isInvalid()) |
| 5459 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5461 | First.release(); |
| 5462 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5464 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5465 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5466 | } // end namespace clang |
| 5467 | |
| 5468 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |