John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprCXX.h" |
| 21 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 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 | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 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 | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 30 | #include <algorithm> |
| 31 | |
| 32 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 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 | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 63 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 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 | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 70 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 71 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 85 | template<typename Derived> |
| 86 | class TreeTransform { |
| 87 | protected: |
| 88 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | |
| 90 | public: |
Douglas Gregor | a16548e | 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 | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 96 | typedef Sema::MultiStmtArg MultiStmtArg; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 98 | /// \brief Initializes a new tree transformer. |
| 99 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | const Derived &getDerived() const { |
| 106 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | d6ff332 | 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 | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 149 | public: |
| 150 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 157 | ~TemporaryBase() { |
| 158 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 159 | } |
| 160 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
| 162 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 163 | /// transformed. |
| 164 | /// |
| 165 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 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 | d6ff332 | 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 | 550e0c2 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 180 | /// |
| 181 | /// \returns the transformed type. |
| 182 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
John McCall | 550e0c2 | 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 | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 186 | /// |
John McCall | 550e0c2 | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 200 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 201 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 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 | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 209 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 211 | /// \brief Transform the given expression. |
| 212 | /// |
Douglas Gregor | a16548e | 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 233 | /// \brief Transform the given declaration, which is referenced from a type |
| 234 | /// or expression. |
| 235 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 236 | /// By default, acts as the identity function on declarations. Subclasses |
| 237 | /// may override this function to provide alternate behavior. |
| 238 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 239 | |
| 240 | /// \brief Transform the definition of the given declaration. |
| 241 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 243 | /// Subclasses may override this function to provide alternate behavior. |
| 244 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 246 | /// \brief Transform the given declaration, which was the first part of a |
| 247 | /// nested-name-specifier in a member access expression. |
| 248 | /// |
| 249 | /// This specific declaration transformation only applies to the first |
| 250 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 251 | /// the \c T in \c x->T::member |
| 252 | /// |
| 253 | /// By default, invokes TransformDecl() to transform the declaration. |
| 254 | /// Subclasses may override this function to provide alternate behavior. |
| 255 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 256 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 257 | } |
| 258 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 259 | /// \brief Transform the given nested-name-specifier. |
| 260 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 262 | /// nested-name-specifier. Subclasses may override this function to provide |
| 263 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 264 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 265 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 266 | QualType ObjectType = QualType(), |
| 267 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 269 | /// \brief Transform the given declaration name. |
| 270 | /// |
| 271 | /// By default, transforms the types of conversion function, constructor, |
| 272 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 273 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 274 | /// override this function to provide alternate behavior. |
| 275 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 276 | SourceLocation Loc, |
| 277 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 281 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 284 | TemplateName TransformTemplateName(TemplateName Name, |
| 285 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// \brief Transform the given template argument. |
| 288 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | /// By default, this operation transforms the type, expression, or |
| 290 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 291 | /// new template argument from the transformed result. Subclasses may |
| 292 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 293 | /// |
| 294 | /// Returns true if there was an error. |
| 295 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 296 | TemplateArgumentLoc &Output); |
| 297 | |
| 298 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 299 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 300 | TemplateArgumentLoc &ArgLoc); |
| 301 | |
| 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 | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 309 | #define TYPELOC(CLASS, PARENT) \ |
| 310 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 311 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 313 | QualType |
| 314 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 315 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 316 | |
| 317 | QualType |
| 318 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 319 | TemplateSpecializationTypeLoc TL, |
| 320 | QualType ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 321 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 322 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | #define STMT(Node, Parent) \ |
| 325 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 326 | #define EXPR(Node, Parent) \ |
| 327 | OwningExprResult Transform##Node(Node *E); |
| 328 | #define ABSTRACT_EXPR(Node, Parent) |
| 329 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 330 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 331 | /// \brief Build a new pointer type given its pointee type. |
| 332 | /// |
| 333 | /// By default, performs semantic analysis when building the pointer type. |
| 334 | /// Subclasses may override this routine to provide different behavior. |
| 335 | QualType RebuildPointerType(QualType PointeeType); |
| 336 | |
| 337 | /// \brief Build a new block pointer type given its pointee type. |
| 338 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 340 | /// type. Subclasses may override this routine to provide different behavior. |
| 341 | QualType RebuildBlockPointerType(QualType PointeeType); |
| 342 | |
| 343 | /// \brief Build a new lvalue reference type given the type it references. |
| 344 | /// |
| 345 | /// By default, performs semantic analysis when building the lvalue reference |
| 346 | /// type. Subclasses may override this routine to provide different behavior. |
| 347 | QualType RebuildLValueReferenceType(QualType ReferentType); |
| 348 | |
| 349 | /// \brief Build a new rvalue reference type given the type it references. |
| 350 | /// |
| 351 | /// By default, performs semantic analysis when building the rvalue reference |
| 352 | /// type. Subclasses may override this routine to provide different behavior. |
| 353 | QualType RebuildRValueReferenceType(QualType ReferentType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | /// \brief Build a new member pointer type given the pointee type and the |
| 356 | /// class type it refers into. |
| 357 | /// |
| 358 | /// By default, performs semantic analysis when building the member pointer |
| 359 | /// type. Subclasses may override this routine to provide different behavior. |
| 360 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 362 | /// \brief Build a new Objective C object pointer type. |
| 363 | QualType RebuildObjCObjectPointerType(QualType PointeeType); |
| 364 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 365 | /// \brief Build a new array type given the element type, size |
| 366 | /// modifier, size of the array (if known), size expression, and index type |
| 367 | /// qualifiers. |
| 368 | /// |
| 369 | /// By default, performs semantic analysis when building the array type. |
| 370 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 372 | QualType RebuildArrayType(QualType ElementType, |
| 373 | ArrayType::ArraySizeModifier SizeMod, |
| 374 | const llvm::APInt *Size, |
| 375 | Expr *SizeExpr, |
| 376 | unsigned IndexTypeQuals, |
| 377 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 379 | /// \brief Build a new constant array type given the element type, size |
| 380 | /// modifier, (known) size of the array, and index type qualifiers. |
| 381 | /// |
| 382 | /// By default, performs semantic analysis when building the array type. |
| 383 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | ArrayType::ArraySizeModifier SizeMod, |
| 386 | const llvm::APInt &Size, |
| 387 | unsigned IndexTypeQuals); |
| 388 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | /// \brief Build a new incomplete array type given the element type, size |
| 390 | /// modifier, and index type qualifiers. |
| 391 | /// |
| 392 | /// By default, performs semantic analysis when building the array type. |
| 393 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 395 | ArrayType::ArraySizeModifier SizeMod, |
| 396 | unsigned IndexTypeQuals); |
| 397 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | /// size modifier, size expression, and index type qualifiers. |
| 400 | /// |
| 401 | /// By default, performs semantic analysis when building the array type. |
| 402 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 404 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 405 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 406 | unsigned IndexTypeQuals, |
| 407 | SourceRange BracketsRange); |
| 408 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | /// size modifier, size expression, and index type qualifiers. |
| 411 | /// |
| 412 | /// By default, performs semantic analysis when building the array type. |
| 413 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 414 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 415 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 416 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 417 | unsigned IndexTypeQuals, |
| 418 | SourceRange BracketsRange); |
| 419 | |
| 420 | /// \brief Build a new vector type given the element type and |
| 421 | /// number of elements. |
| 422 | /// |
| 423 | /// By default, performs semantic analysis when building the vector type. |
| 424 | /// Subclasses may override this routine to provide different behavior. |
| 425 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 426 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 427 | /// \brief Build a new extended vector type given the element type and |
| 428 | /// number of elements. |
| 429 | /// |
| 430 | /// By default, performs semantic analysis when building the vector type. |
| 431 | /// Subclasses may override this routine to provide different behavior. |
| 432 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 433 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
| 435 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 436 | /// given the element type and number of elements. |
| 437 | /// |
| 438 | /// By default, performs semantic analysis when building the vector type. |
| 439 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 441 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 443 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 444 | /// \brief Build a new function type. |
| 445 | /// |
| 446 | /// By default, performs semantic analysis when building the function type. |
| 447 | /// Subclasses may override this routine to provide different behavior. |
| 448 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | unsigned NumParamTypes, |
| 451 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 453 | /// \brief Build a new unprototyped function type. |
| 454 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 455 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | /// \brief Build a new typedef type. |
| 457 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 458 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 459 | } |
| 460 | |
| 461 | /// \brief Build a new class/struct/union type. |
| 462 | QualType RebuildRecordType(RecordDecl *Record) { |
| 463 | return SemaRef.Context.getTypeDeclType(Record); |
| 464 | } |
| 465 | |
| 466 | /// \brief Build a new Enum type. |
| 467 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 468 | return SemaRef.Context.getTypeDeclType(Enum); |
| 469 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 470 | |
| 471 | /// \brief Build a new elaborated type. |
| 472 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 473 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
| 476 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 477 | /// |
| 478 | /// By default, performs semantic analysis when building the typeof type. |
| 479 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 480 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 481 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 483 | /// |
| 484 | /// By default, builds a new TypeOfType with the given underlying type. |
| 485 | QualType RebuildTypeOfType(QualType Underlying); |
| 486 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 488 | /// |
| 489 | /// By default, performs semantic analysis when building the decltype type. |
| 490 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 491 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | /// \brief Build a new template specialization type. |
| 494 | /// |
| 495 | /// By default, performs semantic analysis when building the template |
| 496 | /// specialization type. Subclasses may override this routine to provide |
| 497 | /// different behavior. |
| 498 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 499 | SourceLocation TemplateLoc, |
| 500 | SourceLocation LAngleLoc, |
| 501 | const TemplateArgumentLoc *Args, |
| 502 | unsigned NumArgs, |
| 503 | SourceLocation RAngleLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | /// \brief Build a new qualified name type. |
| 506 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | /// By default, builds a new QualifiedNameType type from the |
| 508 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 509 | /// this routine to provide different behavior. |
| 510 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 511 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 513 | |
| 514 | /// \brief Build a new typename type that refers to a template-id. |
| 515 | /// |
| 516 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 518 | /// different behavior. |
| 519 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 520 | if (NNS->isDependent()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 524 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 526 | |
| 527 | /// \brief Build a new typename type that refers to an identifier. |
| 528 | /// |
| 529 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 533 | const IdentifierInfo *Id, |
| 534 | SourceRange SR) { |
| 535 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 538 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 539 | /// identifier that names the next step in the nested-name-specifier. |
| 540 | /// |
| 541 | /// By default, performs semantic analysis when building the new |
| 542 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 543 | /// different behavior. |
| 544 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 545 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 546 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 547 | QualType ObjectType, |
| 548 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 549 | |
| 550 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 551 | /// namespace named in the next step in the nested-name-specifier. |
| 552 | /// |
| 553 | /// By default, performs semantic analysis when building the new |
| 554 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 555 | /// different behavior. |
| 556 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 557 | SourceRange Range, |
| 558 | NamespaceDecl *NS); |
| 559 | |
| 560 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 561 | /// type named in the next step in the nested-name-specifier. |
| 562 | /// |
| 563 | /// By default, performs semantic analysis when building the new |
| 564 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 565 | /// different behavior. |
| 566 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 567 | SourceRange Range, |
| 568 | bool TemplateKW, |
| 569 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 570 | |
| 571 | /// \brief Build a new template name given a nested name specifier, a flag |
| 572 | /// indicating whether the "template" keyword was provided, and the template |
| 573 | /// that the template name refers to. |
| 574 | /// |
| 575 | /// By default, builds the new template name directly. Subclasses may override |
| 576 | /// this routine to provide different behavior. |
| 577 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 578 | bool TemplateKW, |
| 579 | TemplateDecl *Template); |
| 580 | |
| 581 | /// \brief Build a new template name given a nested name specifier, a flag |
| 582 | /// indicating whether the "template" keyword was provided, and a set of |
| 583 | /// overloaded function templates. |
| 584 | /// |
| 585 | /// By default, builds the new template name directly. Subclasses may override |
| 586 | /// this routine to provide different behavior. |
| 587 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 588 | bool TemplateKW, |
| 589 | OverloadedFunctionDecl *Ovl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 590 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 591 | /// \brief Build a new template name given a nested name specifier and the |
| 592 | /// name that is referred to as a template. |
| 593 | /// |
| 594 | /// By default, performs semantic analysis to determine whether the name can |
| 595 | /// be resolved to a specific template, then builds the appropriate kind of |
| 596 | /// template name. Subclasses may override this routine to provide different |
| 597 | /// behavior. |
| 598 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 599 | const IdentifierInfo &II, |
| 600 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
| 602 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 603 | /// \brief Build a new compound statement. |
| 604 | /// |
| 605 | /// By default, performs semantic analysis to build the new statement. |
| 606 | /// Subclasses may override this routine to provide different behavior. |
| 607 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 608 | MultiStmtArg Statements, |
| 609 | SourceLocation RBraceLoc, |
| 610 | bool IsStmtExpr) { |
| 611 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 612 | IsStmtExpr); |
| 613 | } |
| 614 | |
| 615 | /// \brief Build a new case statement. |
| 616 | /// |
| 617 | /// By default, performs semantic analysis to build the new statement. |
| 618 | /// Subclasses may override this routine to provide different behavior. |
| 619 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 620 | ExprArg LHS, |
| 621 | SourceLocation EllipsisLoc, |
| 622 | ExprArg RHS, |
| 623 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 624 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 625 | ColonLoc); |
| 626 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 628 | /// \brief Attach the body to a new case statement. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis to build the new statement. |
| 631 | /// Subclasses may override this routine to provide different behavior. |
| 632 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 633 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 634 | return move(S); |
| 635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 637 | /// \brief Build a new default statement. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis to build the new statement. |
| 640 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 642 | SourceLocation ColonLoc, |
| 643 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 644 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 645 | /*CurScope=*/0); |
| 646 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 647 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 648 | /// \brief Build a new label statement. |
| 649 | /// |
| 650 | /// By default, performs semantic analysis to build the new statement. |
| 651 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 653 | IdentifierInfo *Id, |
| 654 | SourceLocation ColonLoc, |
| 655 | StmtArg SubStmt) { |
| 656 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 657 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 659 | /// \brief Build a new "if" statement. |
| 660 | /// |
| 661 | /// By default, performs semantic analysis to build the new statement. |
| 662 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
| 664 | StmtArg Then, SourceLocation ElseLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 665 | StmtArg Else) { |
| 666 | return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else)); |
| 667 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 669 | /// \brief Start building a new switch statement. |
| 670 | /// |
| 671 | /// By default, performs semantic analysis to build the new statement. |
| 672 | /// Subclasses may override this routine to provide different behavior. |
| 673 | OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) { |
| 674 | return getSema().ActOnStartOfSwitchStmt(move(Cond)); |
| 675 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 677 | /// \brief Attach the body to the switch statement. |
| 678 | /// |
| 679 | /// By default, performs semantic analysis to build the new statement. |
| 680 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | StmtArg Switch, StmtArg Body) { |
| 683 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 684 | move(Body)); |
| 685 | } |
| 686 | |
| 687 | /// \brief Build a new while statement. |
| 688 | /// |
| 689 | /// By default, performs semantic analysis to build the new statement. |
| 690 | /// Subclasses may override this routine to provide different behavior. |
| 691 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 692 | Sema::FullExprArg Cond, |
| 693 | StmtArg Body) { |
| 694 | return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body)); |
| 695 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 696 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 697 | /// \brief Build a new do-while statement. |
| 698 | /// |
| 699 | /// By default, performs semantic analysis to build the new statement. |
| 700 | /// Subclasses may override this routine to provide different behavior. |
| 701 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 702 | SourceLocation WhileLoc, |
| 703 | SourceLocation LParenLoc, |
| 704 | ExprArg Cond, |
| 705 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 707 | move(Cond), RParenLoc); |
| 708 | } |
| 709 | |
| 710 | /// \brief Build a new for statement. |
| 711 | /// |
| 712 | /// By default, performs semantic analysis to build the new statement. |
| 713 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 715 | SourceLocation LParenLoc, |
| 716 | StmtArg Init, ExprArg Cond, ExprArg Inc, |
| 717 | SourceLocation RParenLoc, StmtArg Body) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 719 | move(Inc), RParenLoc, move(Body)); |
| 720 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 722 | /// \brief Build a new goto statement. |
| 723 | /// |
| 724 | /// By default, performs semantic analysis to build the new statement. |
| 725 | /// Subclasses may override this routine to provide different behavior. |
| 726 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 727 | SourceLocation LabelLoc, |
| 728 | LabelStmt *Label) { |
| 729 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 730 | } |
| 731 | |
| 732 | /// \brief Build a new indirect goto statement. |
| 733 | /// |
| 734 | /// By default, performs semantic analysis to build the new statement. |
| 735 | /// Subclasses may override this routine to provide different behavior. |
| 736 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 737 | SourceLocation StarLoc, |
| 738 | ExprArg Target) { |
| 739 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 740 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 742 | /// \brief Build a new return statement. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis to build the new statement. |
| 745 | /// Subclasses may override this routine to provide different behavior. |
| 746 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 747 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 749 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 752 | /// \brief Build a new declaration statement. |
| 753 | /// |
| 754 | /// By default, performs semantic analysis to build the new statement. |
| 755 | /// Subclasses may override this routine to provide different behavior. |
| 756 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 758 | SourceLocation EndLoc) { |
| 759 | return getSema().Owned( |
| 760 | new (getSema().Context) DeclStmt( |
| 761 | DeclGroupRef::Create(getSema().Context, |
| 762 | Decls, NumDecls), |
| 763 | StartLoc, EndLoc)); |
| 764 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 766 | /// \brief Build a new C++ exception declaration. |
| 767 | /// |
| 768 | /// By default, performs semantic analysis to build the new decaration. |
| 769 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | DeclaratorInfo *Declarator, |
| 772 | IdentifierInfo *Name, |
| 773 | SourceLocation Loc, |
| 774 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 776 | TypeRange); |
| 777 | } |
| 778 | |
| 779 | /// \brief Build a new C++ catch statement. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new statement. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
| 783 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 784 | VarDecl *ExceptionDecl, |
| 785 | StmtArg Handler) { |
| 786 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 787 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 788 | Handler.takeAs<Stmt>())); |
| 789 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 791 | /// \brief Build a new C++ try statement. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis to build the new statement. |
| 794 | /// Subclasses may override this routine to provide different behavior. |
| 795 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 796 | StmtArg TryBlock, |
| 797 | MultiStmtArg Handlers) { |
| 798 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 799 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 801 | /// \brief Build a new expression that references a declaration. |
| 802 | /// |
| 803 | /// By default, performs semantic analysis to build the new expression. |
| 804 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 805 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 806 | SourceRange QualifierRange, |
| 807 | NamedDecl *ND, SourceLocation Loc) { |
| 808 | CXXScopeSpec SS; |
| 809 | SS.setScopeRep(Qualifier); |
| 810 | SS.setRange(QualifierRange); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 811 | return getSema().BuildDeclarationNameExpr(Loc, ND, |
| 812 | /*FIXME:*/false, |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 813 | &SS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 814 | /*FIXME:*/false); |
| 815 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 817 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 818 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 819 | /// By default, performs semantic analysis to build the new expression. |
| 820 | /// Subclasses may override this routine to provide different behavior. |
| 821 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 822 | SourceLocation RParen) { |
| 823 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 824 | } |
| 825 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 826 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 828 | /// By default, performs semantic analysis to build the new expression. |
| 829 | /// Subclasses may override this routine to provide different behavior. |
| 830 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 831 | SourceLocation OperatorLoc, |
| 832 | bool isArrow, |
| 833 | SourceLocation DestroyedTypeLoc, |
| 834 | QualType DestroyedType, |
| 835 | NestedNameSpecifier *Qualifier, |
| 836 | SourceRange QualifierRange) { |
| 837 | CXXScopeSpec SS; |
| 838 | if (Qualifier) { |
| 839 | SS.setRange(QualifierRange); |
| 840 | SS.setScopeRep(Qualifier); |
| 841 | } |
| 842 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | DeclarationName Name |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 844 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 845 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
| 847 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 848 | OperatorLoc, |
| 849 | isArrow? tok::arrow : tok::period, |
| 850 | DestroyedTypeLoc, |
| 851 | Name, |
| 852 | Sema::DeclPtrTy::make((Decl *)0), |
| 853 | &SS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 856 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 858 | /// By default, performs semantic analysis to build the new expression. |
| 859 | /// Subclasses may override this routine to provide different behavior. |
| 860 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 861 | UnaryOperator::Opcode Opc, |
| 862 | ExprArg SubExpr) { |
| 863 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(SubExpr)); |
| 864 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 866 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 868 | /// By default, performs semantic analysis to build the new expression. |
| 869 | /// Subclasses may override this routine to provide different behavior. |
| 870 | OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc, |
| 871 | bool isSizeOf, SourceRange R) { |
| 872 | return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R); |
| 873 | } |
| 874 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 876 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 878 | /// By default, performs semantic analysis to build the new expression. |
| 879 | /// Subclasses may override this routine to provide different behavior. |
| 880 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 881 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 884 | OpLoc, isSizeOf, R); |
| 885 | if (Result.isInvalid()) |
| 886 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 888 | SubExpr.release(); |
| 889 | return move(Result); |
| 890 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 891 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 892 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 894 | /// By default, performs semantic analysis to build the new expression. |
| 895 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 896 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 897 | SourceLocation LBracketLoc, |
| 898 | ExprArg RHS, |
| 899 | SourceLocation RBracketLoc) { |
| 900 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 901 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 902 | RBracketLoc); |
| 903 | } |
| 904 | |
| 905 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 906 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 907 | /// By default, performs semantic analysis to build the new expression. |
| 908 | /// Subclasses may override this routine to provide different behavior. |
| 909 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 910 | MultiExprArg Args, |
| 911 | SourceLocation *CommaLocs, |
| 912 | SourceLocation RParenLoc) { |
| 913 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 914 | move(Args), CommaLocs, RParenLoc); |
| 915 | } |
| 916 | |
| 917 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 918 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 919 | /// By default, performs semantic analysis to build the new expression. |
| 920 | /// Subclasses may override this routine to provide different behavior. |
| 921 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 922 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 923 | NestedNameSpecifier *Qualifier, |
| 924 | SourceRange QualifierRange, |
| 925 | SourceLocation MemberLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 926 | NamedDecl *Member) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 927 | if (!Member->getDeclName()) { |
| 928 | // We have a reference to an unnamed field. |
| 929 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
| 931 | MemberExpr *ME = |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 932 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 933 | Member, MemberLoc, |
| 934 | cast<FieldDecl>(Member)->getType()); |
| 935 | return getSema().Owned(ME); |
| 936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 938 | CXXScopeSpec SS; |
| 939 | if (Qualifier) { |
| 940 | SS.setRange(QualifierRange); |
| 941 | SS.setScopeRep(Qualifier); |
| 942 | } |
| 943 | |
Douglas Gregor | f14b46f | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 944 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 945 | isArrow? tok::arrow : tok::period, |
| 946 | MemberLoc, |
Douglas Gregor | f14b46f | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 947 | Member->getDeclName(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 948 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
| 949 | &SS); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 952 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 954 | /// By default, performs semantic analysis to build the new expression. |
| 955 | /// Subclasses may override this routine to provide different behavior. |
| 956 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 957 | BinaryOperator::Opcode Opc, |
| 958 | ExprArg LHS, ExprArg RHS) { |
| 959 | OwningExprResult Result |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | = getSema().CreateBuiltinBinOp(OpLoc, Opc, (Expr *)LHS.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 961 | (Expr *)RHS.get()); |
| 962 | if (Result.isInvalid()) |
| 963 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 965 | LHS.release(); |
| 966 | RHS.release(); |
| 967 | return move(Result); |
| 968 | } |
| 969 | |
| 970 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 972 | /// By default, performs semantic analysis to build the new expression. |
| 973 | /// Subclasses may override this routine to provide different behavior. |
| 974 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 975 | SourceLocation QuestionLoc, |
| 976 | ExprArg LHS, |
| 977 | SourceLocation ColonLoc, |
| 978 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 980 | move(LHS), move(RHS)); |
| 981 | } |
| 982 | |
| 983 | /// \brief Build a new implicit cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 985 | /// By default, builds a new implicit cast without any semantic analysis. |
| 986 | /// Subclasses may override this routine to provide different behavior. |
| 987 | OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, |
| 988 | ExprArg SubExpr, bool isLvalue) { |
| 989 | ImplicitCastExpr *ICE |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | = new (getSema().Context) ImplicitCastExpr(T, Kind, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 991 | (Expr *)SubExpr.release(), |
| 992 | isLvalue); |
| 993 | return getSema().Owned(ICE); |
| 994 | } |
| 995 | |
| 996 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 998 | /// By default, performs semantic analysis to build the new expression. |
| 999 | /// Subclasses may override this routine to provide different behavior. |
| 1000 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1001 | QualType ExplicitTy, |
| 1002 | SourceLocation RParenLoc, |
| 1003 | ExprArg SubExpr) { |
| 1004 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1005 | LParenLoc, |
| 1006 | ExplicitTy.getAsOpaquePtr(), |
| 1007 | RParenLoc, |
| 1008 | move(SubExpr)); |
| 1009 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1011 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1013 | /// By default, performs semantic analysis to build the new expression. |
| 1014 | /// Subclasses may override this routine to provide different behavior. |
| 1015 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1016 | QualType T, |
| 1017 | SourceLocation RParenLoc, |
| 1018 | ExprArg Init) { |
| 1019 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1020 | RParenLoc, move(Init)); |
| 1021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// By default, performs semantic analysis to build the new expression. |
| 1026 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1028 | SourceLocation OpLoc, |
| 1029 | SourceLocation AccessorLoc, |
| 1030 | IdentifierInfo &Accessor) { |
| 1031 | return getSema().ActOnMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
| 1032 | tok::period, AccessorLoc, |
| 1033 | Accessor, |
| 1034 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0)); |
| 1035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// By default, performs semantic analysis to build the new expression. |
| 1040 | /// Subclasses may override this routine to provide different behavior. |
| 1041 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1042 | MultiExprArg Inits, |
| 1043 | SourceLocation RBraceLoc) { |
| 1044 | return SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1045 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1047 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// By default, performs semantic analysis to build the new expression. |
| 1050 | /// Subclasses may override this routine to provide different behavior. |
| 1051 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1052 | MultiExprArg ArrayExprs, |
| 1053 | SourceLocation EqualOrColonLoc, |
| 1054 | bool GNUSyntax, |
| 1055 | ExprArg Init) { |
| 1056 | OwningExprResult Result |
| 1057 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1058 | move(Init)); |
| 1059 | if (Result.isInvalid()) |
| 1060 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1062 | ArrayExprs.release(); |
| 1063 | return move(Result); |
| 1064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1066 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | /// By default, builds the implicit value initialization without performing |
| 1069 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1070 | /// different behavior. |
| 1071 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1072 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1073 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1074 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1075 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1076 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1077 | /// By default, performs semantic analysis to build the new expression. |
| 1078 | /// Subclasses may override this routine to provide different behavior. |
| 1079 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1080 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1082 | RParenLoc); |
| 1083 | } |
| 1084 | |
| 1085 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | /// By default, performs semantic analysis to build the new expression. |
| 1088 | /// Subclasses may override this routine to provide different behavior. |
| 1089 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1090 | MultiExprArg SubExprs, |
| 1091 | SourceLocation RParenLoc) { |
| 1092 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); |
| 1093 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1095 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | /// |
| 1097 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1098 | /// rather than attempting to map the label statement itself. |
| 1099 | /// Subclasses may override this routine to provide different behavior. |
| 1100 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1101 | SourceLocation LabelLoc, |
| 1102 | LabelStmt *Label) { |
| 1103 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | /// By default, performs semantic analysis to build the new expression. |
| 1109 | /// Subclasses may override this routine to provide different behavior. |
| 1110 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1111 | StmtArg SubStmt, |
| 1112 | SourceLocation RParenLoc) { |
| 1113 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1116 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1117 | /// |
| 1118 | /// By default, performs semantic analysis to build the new expression. |
| 1119 | /// Subclasses may override this routine to provide different behavior. |
| 1120 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1121 | QualType T1, QualType T2, |
| 1122 | SourceLocation RParenLoc) { |
| 1123 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1124 | T1.getAsOpaquePtr(), |
| 1125 | T2.getAsOpaquePtr(), |
| 1126 | RParenLoc); |
| 1127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1129 | /// \brief Build a new __builtin_choose_expr expression. |
| 1130 | /// |
| 1131 | /// By default, performs semantic analysis to build the new expression. |
| 1132 | /// Subclasses may override this routine to provide different behavior. |
| 1133 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1134 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1135 | SourceLocation RParenLoc) { |
| 1136 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1137 | move(Cond), move(LHS), move(RHS), |
| 1138 | RParenLoc); |
| 1139 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1141 | /// \brief Build a new overloaded operator call expression. |
| 1142 | /// |
| 1143 | /// By default, performs semantic analysis to build the new expression. |
| 1144 | /// The semantic analysis provides the behavior of template instantiation, |
| 1145 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1148 | /// provide different behavior. |
| 1149 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1150 | SourceLocation OpLoc, |
| 1151 | ExprArg Callee, |
| 1152 | ExprArg First, |
| 1153 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1154 | |
| 1155 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1156 | /// reinterpret_cast. |
| 1157 | /// |
| 1158 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1160 | /// Subclasses may override this routine to provide different behavior. |
| 1161 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1162 | Stmt::StmtClass Class, |
| 1163 | SourceLocation LAngleLoc, |
| 1164 | QualType T, |
| 1165 | SourceLocation RAngleLoc, |
| 1166 | SourceLocation LParenLoc, |
| 1167 | ExprArg SubExpr, |
| 1168 | SourceLocation RParenLoc) { |
| 1169 | switch (Class) { |
| 1170 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1172 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1173 | move(SubExpr), RParenLoc); |
| 1174 | |
| 1175 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1177 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1180 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1182 | RAngleLoc, LParenLoc, |
| 1183 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1184 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1186 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1188 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1189 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1191 | default: |
| 1192 | assert(false && "Invalid C++ named cast"); |
| 1193 | break; |
| 1194 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1196 | return getSema().ExprError(); |
| 1197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1199 | /// \brief Build a new C++ static_cast expression. |
| 1200 | /// |
| 1201 | /// By default, performs semantic analysis to build the new expression. |
| 1202 | /// Subclasses may override this routine to provide different behavior. |
| 1203 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1204 | SourceLocation LAngleLoc, |
| 1205 | QualType T, |
| 1206 | SourceLocation RAngleLoc, |
| 1207 | SourceLocation LParenLoc, |
| 1208 | ExprArg SubExpr, |
| 1209 | SourceLocation RParenLoc) { |
| 1210 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1212 | LParenLoc, move(SubExpr), RParenLoc); |
| 1213 | } |
| 1214 | |
| 1215 | /// \brief Build a new C++ dynamic_cast expression. |
| 1216 | /// |
| 1217 | /// By default, performs semantic analysis to build the new expression. |
| 1218 | /// Subclasses may override this routine to provide different behavior. |
| 1219 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1220 | SourceLocation LAngleLoc, |
| 1221 | QualType T, |
| 1222 | SourceLocation RAngleLoc, |
| 1223 | SourceLocation LParenLoc, |
| 1224 | ExprArg SubExpr, |
| 1225 | SourceLocation RParenLoc) { |
| 1226 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1228 | LParenLoc, move(SubExpr), RParenLoc); |
| 1229 | } |
| 1230 | |
| 1231 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1232 | /// |
| 1233 | /// By default, performs semantic analysis to build the new expression. |
| 1234 | /// Subclasses may override this routine to provide different behavior. |
| 1235 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1236 | SourceLocation LAngleLoc, |
| 1237 | QualType T, |
| 1238 | SourceLocation RAngleLoc, |
| 1239 | SourceLocation LParenLoc, |
| 1240 | ExprArg SubExpr, |
| 1241 | SourceLocation RParenLoc) { |
| 1242 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1243 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1244 | LParenLoc, move(SubExpr), RParenLoc); |
| 1245 | } |
| 1246 | |
| 1247 | /// \brief Build a new C++ const_cast expression. |
| 1248 | /// |
| 1249 | /// By default, performs semantic analysis to build the new expression. |
| 1250 | /// Subclasses may override this routine to provide different behavior. |
| 1251 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1252 | SourceLocation LAngleLoc, |
| 1253 | QualType T, |
| 1254 | SourceLocation RAngleLoc, |
| 1255 | SourceLocation LParenLoc, |
| 1256 | ExprArg SubExpr, |
| 1257 | SourceLocation RParenLoc) { |
| 1258 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1260 | LParenLoc, move(SubExpr), RParenLoc); |
| 1261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1263 | /// \brief Build a new C++ functional-style cast expression. |
| 1264 | /// |
| 1265 | /// By default, performs semantic analysis to build the new expression. |
| 1266 | /// Subclasses may override this routine to provide different behavior. |
| 1267 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1268 | QualType T, |
| 1269 | SourceLocation LParenLoc, |
| 1270 | ExprArg SubExpr, |
| 1271 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1272 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1273 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1274 | T.getAsOpaquePtr(), |
| 1275 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1276 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1278 | RParenLoc); |
| 1279 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1281 | /// \brief Build a new C++ typeid(type) expression. |
| 1282 | /// |
| 1283 | /// By default, performs semantic analysis to build the new expression. |
| 1284 | /// Subclasses may override this routine to provide different behavior. |
| 1285 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1286 | SourceLocation LParenLoc, |
| 1287 | QualType T, |
| 1288 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1289 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1290 | T.getAsOpaquePtr(), RParenLoc); |
| 1291 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1293 | /// \brief Build a new C++ typeid(expr) expression. |
| 1294 | /// |
| 1295 | /// By default, performs semantic analysis to build the new expression. |
| 1296 | /// Subclasses may override this routine to provide different behavior. |
| 1297 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1298 | SourceLocation LParenLoc, |
| 1299 | ExprArg Operand, |
| 1300 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1302 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1303 | RParenLoc); |
| 1304 | if (Result.isInvalid()) |
| 1305 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1307 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1308 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1311 | /// \brief Build a new C++ "this" expression. |
| 1312 | /// |
| 1313 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1317 | QualType ThisType) { |
| 1318 | return getSema().Owned( |
| 1319 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1320 | } |
| 1321 | |
| 1322 | /// \brief Build a new C++ throw expression. |
| 1323 | /// |
| 1324 | /// By default, performs semantic analysis to build the new expression. |
| 1325 | /// Subclasses may override this routine to provide different behavior. |
| 1326 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1327 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1328 | } |
| 1329 | |
| 1330 | /// \brief Build a new C++ default-argument expression. |
| 1331 | /// |
| 1332 | /// By default, builds a new default-argument expression, which does not |
| 1333 | /// require any semantic analysis. Subclasses may override this routine to |
| 1334 | /// provide different behavior. |
| 1335 | OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) { |
Anders Carlsson | e827123 | 2009-08-14 18:30:22 +0000 | [diff] [blame] | 1336 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | /// \brief Build a new C++ zero-initialization expression. |
| 1340 | /// |
| 1341 | /// By default, performs semantic analysis to build the new expression. |
| 1342 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1344 | SourceLocation LParenLoc, |
| 1345 | QualType T, |
| 1346 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1348 | T.getAsOpaquePtr(), LParenLoc, |
| 1349 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | 0, RParenLoc); |
| 1351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1353 | /// \brief Build a new C++ conditional declaration expression. |
| 1354 | /// |
| 1355 | /// By default, performs semantic analysis to build the new expression. |
| 1356 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | SourceLocation EqLoc, |
| 1359 | VarDecl *Var) { |
| 1360 | return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc, |
| 1361 | EqLoc, |
| 1362 | Var)); |
| 1363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1365 | /// \brief Build a new C++ "new" expression. |
| 1366 | /// |
| 1367 | /// By default, performs semantic analysis to build the new expression. |
| 1368 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1370 | bool UseGlobal, |
| 1371 | SourceLocation PlacementLParen, |
| 1372 | MultiExprArg PlacementArgs, |
| 1373 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | QualType AllocType, |
| 1376 | SourceLocation TypeLoc, |
| 1377 | SourceRange TypeRange, |
| 1378 | ExprArg ArraySize, |
| 1379 | SourceLocation ConstructorLParen, |
| 1380 | MultiExprArg ConstructorArgs, |
| 1381 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1383 | PlacementLParen, |
| 1384 | move(PlacementArgs), |
| 1385 | PlacementRParen, |
| 1386 | ParenTypeId, |
| 1387 | AllocType, |
| 1388 | TypeLoc, |
| 1389 | TypeRange, |
| 1390 | move(ArraySize), |
| 1391 | ConstructorLParen, |
| 1392 | move(ConstructorArgs), |
| 1393 | ConstructorRParen); |
| 1394 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1396 | /// \brief Build a new C++ "delete" expression. |
| 1397 | /// |
| 1398 | /// By default, performs semantic analysis to build the new expression. |
| 1399 | /// Subclasses may override this routine to provide different behavior. |
| 1400 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1401 | bool IsGlobalDelete, |
| 1402 | bool IsArrayForm, |
| 1403 | ExprArg Operand) { |
| 1404 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1405 | move(Operand)); |
| 1406 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | /// \brief Build a new unary type trait expression. |
| 1409 | /// |
| 1410 | /// By default, performs semantic analysis to build the new expression. |
| 1411 | /// Subclasses may override this routine to provide different behavior. |
| 1412 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1413 | SourceLocation StartLoc, |
| 1414 | SourceLocation LParenLoc, |
| 1415 | QualType T, |
| 1416 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | T.getAsOpaquePtr(), RParenLoc); |
| 1419 | } |
| 1420 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1422 | /// expression. |
| 1423 | /// |
| 1424 | /// By default, performs semantic analysis to build the new expression. |
| 1425 | /// Subclasses may override this routine to provide different behavior. |
| 1426 | OwningExprResult RebuildUnresolvedDeclRefExpr(NestedNameSpecifier *NNS, |
| 1427 | SourceRange QualifierRange, |
| 1428 | DeclarationName Name, |
| 1429 | SourceLocation Location, |
| 1430 | bool IsAddressOfOperand) { |
| 1431 | CXXScopeSpec SS; |
| 1432 | SS.setRange(QualifierRange); |
| 1433 | SS.setScopeRep(NNS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1435 | Location, |
| 1436 | Name, |
| 1437 | /*Trailing lparen=*/false, |
| 1438 | &SS, |
| 1439 | IsAddressOfOperand); |
| 1440 | } |
| 1441 | |
| 1442 | /// \brief Build a new template-id expression. |
| 1443 | /// |
| 1444 | /// By default, performs semantic analysis to build the new expression. |
| 1445 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1446 | OwningExprResult RebuildTemplateIdExpr(NestedNameSpecifier *Qualifier, |
| 1447 | SourceRange QualifierRange, |
| 1448 | TemplateName Template, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | SourceLocation TemplateLoc, |
| 1450 | SourceLocation LAngleLoc, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1451 | TemplateArgumentLoc *TemplateArgs, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1452 | unsigned NumTemplateArgs, |
| 1453 | SourceLocation RAngleLoc) { |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1454 | return getSema().BuildTemplateIdExpr(Qualifier, QualifierRange, |
| 1455 | Template, TemplateLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | LAngleLoc, |
| 1457 | TemplateArgs, NumTemplateArgs, |
| 1458 | RAngleLoc); |
| 1459 | } |
| 1460 | |
| 1461 | /// \brief Build a new object-construction expression. |
| 1462 | /// |
| 1463 | /// By default, performs semantic analysis to build the new expression. |
| 1464 | /// Subclasses may override this routine to provide different behavior. |
| 1465 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
| 1466 | CXXConstructorDecl *Constructor, |
| 1467 | bool IsElidable, |
| 1468 | MultiExprArg Args) { |
Anders Carlsson | 1b4ebfa | 2009-09-05 07:40:38 +0000 | [diff] [blame] | 1469 | return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/ |
| 1470 | SourceLocation(), |
| 1471 | T, Constructor, IsElidable, |
Anders Carlsson | 5995a3e | 2009-09-07 22:23:31 +0000 | [diff] [blame] | 1472 | move(Args)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | /// \brief Build a new object-construction expression. |
| 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new expression. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
| 1479 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1480 | QualType T, |
| 1481 | SourceLocation LParenLoc, |
| 1482 | MultiExprArg Args, |
| 1483 | SourceLocation *Commas, |
| 1484 | SourceLocation RParenLoc) { |
| 1485 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1486 | T.getAsOpaquePtr(), |
| 1487 | LParenLoc, |
| 1488 | move(Args), |
| 1489 | Commas, |
| 1490 | RParenLoc); |
| 1491 | } |
| 1492 | |
| 1493 | /// \brief Build a new object-construction expression. |
| 1494 | /// |
| 1495 | /// By default, performs semantic analysis to build the new expression. |
| 1496 | /// Subclasses may override this routine to provide different behavior. |
| 1497 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1498 | QualType T, |
| 1499 | SourceLocation LParenLoc, |
| 1500 | MultiExprArg Args, |
| 1501 | SourceLocation *Commas, |
| 1502 | SourceLocation RParenLoc) { |
| 1503 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1504 | /*FIXME*/LParenLoc), |
| 1505 | T.getAsOpaquePtr(), |
| 1506 | LParenLoc, |
| 1507 | move(Args), |
| 1508 | Commas, |
| 1509 | RParenLoc); |
| 1510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1512 | /// \brief Build a new member reference expression. |
| 1513 | /// |
| 1514 | /// By default, performs semantic analysis to build the new expression. |
| 1515 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 2168a9f | 2009-08-11 15:56:57 +0000 | [diff] [blame] | 1516 | OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1517 | bool IsArrow, |
| 1518 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1519 | NestedNameSpecifier *Qualifier, |
| 1520 | SourceRange QualifierRange, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1522 | SourceLocation MemberLoc, |
| 1523 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 2168a9f | 2009-08-11 15:56:57 +0000 | [diff] [blame] | 1524 | OwningExprResult Base = move(BaseE); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1525 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1526 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1527 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1528 | SS.setRange(QualifierRange); |
| 1529 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1530 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1531 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1532 | move(Base), OperatorLoc, OpKind, |
Douglas Gregor | f14b46f | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 1533 | MemberLoc, |
| 1534 | Name, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1535 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1536 | &SS, |
| 1537 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1540 | /// \brief Build a new member reference expression with explicit template |
| 1541 | /// arguments. |
| 1542 | /// |
| 1543 | /// By default, performs semantic analysis to build the new expression. |
| 1544 | /// Subclasses may override this routine to provide different behavior. |
| 1545 | OwningExprResult RebuildCXXUnresolvedMemberExpr(ExprArg BaseE, |
| 1546 | bool IsArrow, |
| 1547 | SourceLocation OperatorLoc, |
| 1548 | NestedNameSpecifier *Qualifier, |
| 1549 | SourceRange QualifierRange, |
| 1550 | TemplateName Template, |
| 1551 | SourceLocation TemplateNameLoc, |
| 1552 | NamedDecl *FirstQualifierInScope, |
| 1553 | SourceLocation LAngleLoc, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1554 | const TemplateArgumentLoc *TemplateArgs, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1555 | unsigned NumTemplateArgs, |
| 1556 | SourceLocation RAngleLoc) { |
| 1557 | OwningExprResult Base = move(BaseE); |
| 1558 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1559 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1560 | CXXScopeSpec SS; |
| 1561 | SS.setRange(QualifierRange); |
| 1562 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1564 | // FIXME: We're going to end up looking up the template based on its name, |
| 1565 | // twice! Also, duplicates part of Sema::ActOnMemberTemplateIdReferenceExpr. |
| 1566 | DeclarationName Name; |
| 1567 | if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl()) |
| 1568 | Name = ActualTemplate->getDeclName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1569 | else if (OverloadedFunctionDecl *Ovl |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1570 | = Template.getAsOverloadedFunctionDecl()) |
| 1571 | Name = Ovl->getDeclName(); |
| 1572 | else |
| 1573 | Name = Template.getAsDependentTemplateName()->getName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1574 | |
| 1575 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1576 | OperatorLoc, OpKind, |
| 1577 | TemplateNameLoc, Name, true, |
| 1578 | LAngleLoc, TemplateArgs, |
| 1579 | NumTemplateArgs, RAngleLoc, |
| 1580 | Sema::DeclPtrTy(), &SS); |
| 1581 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1583 | /// \brief Build a new Objective-C @encode expression. |
| 1584 | /// |
| 1585 | /// By default, performs semantic analysis to build the new expression. |
| 1586 | /// Subclasses may override this routine to provide different behavior. |
| 1587 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1588 | QualType T, |
| 1589 | SourceLocation RParenLoc) { |
| 1590 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1591 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1592 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1593 | |
| 1594 | /// \brief Build a new Objective-C protocol expression. |
| 1595 | /// |
| 1596 | /// By default, performs semantic analysis to build the new expression. |
| 1597 | /// Subclasses may override this routine to provide different behavior. |
| 1598 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1599 | SourceLocation AtLoc, |
| 1600 | SourceLocation ProtoLoc, |
| 1601 | SourceLocation LParenLoc, |
| 1602 | SourceLocation RParenLoc) { |
| 1603 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1604 | Protocol->getIdentifier(), |
| 1605 | AtLoc, |
| 1606 | ProtoLoc, |
| 1607 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1608 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1609 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1611 | /// \brief Build a new shuffle vector expression. |
| 1612 | /// |
| 1613 | /// By default, performs semantic analysis to build the new expression. |
| 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1616 | MultiExprArg SubExprs, |
| 1617 | SourceLocation RParenLoc) { |
| 1618 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1621 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1622 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1623 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | // Build a reference to the __builtin_shufflevector builtin |
| 1626 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
| 1629 | BuiltinLoc, false, false); |
| 1630 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1631 | |
| 1632 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | unsigned NumSubExprs = SubExprs.size(); |
| 1634 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1635 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1636 | Subs, NumSubExprs, |
| 1637 | Builtin->getResultType(), |
| 1638 | RParenLoc); |
| 1639 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1641 | // Type-check the __builtin_shufflevector expression. |
| 1642 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1643 | if (Result.isInvalid()) |
| 1644 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1646 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1648 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1649 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1651 | template<typename Derived> |
| 1652 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1653 | if (!S) |
| 1654 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1656 | switch (S->getStmtClass()) { |
| 1657 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1658 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1659 | // Transform individual statement nodes |
| 1660 | #define STMT(Node, Parent) \ |
| 1661 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1662 | #define EXPR(Node, Parent) |
| 1663 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1665 | // Transform expressions by calling TransformExpr. |
| 1666 | #define STMT(Node, Parent) |
| 1667 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1668 | #include "clang/AST/StmtNodes.def" |
| 1669 | { |
| 1670 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1671 | if (E.isInvalid()) |
| 1672 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1673 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1674 | return getSema().Owned(E.takeAs<Stmt>()); |
| 1675 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1678 | return SemaRef.Owned(S->Retain()); |
| 1679 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
| 1681 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1682 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1683 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, |
| 1684 | bool isAddressOfOperand) { |
| 1685 | if (!E) |
| 1686 | return SemaRef.Owned(E); |
| 1687 | |
| 1688 | switch (E->getStmtClass()) { |
| 1689 | case Stmt::NoStmtClass: break; |
| 1690 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1691 | #define EXPR(Node, Parent) \ |
| 1692 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| 1693 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1696 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1700 | NestedNameSpecifier * |
| 1701 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1702 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1703 | QualType ObjectType, |
| 1704 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1705 | if (!NNS) |
| 1706 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1708 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1709 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1710 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1712 | ObjectType, |
| 1713 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1714 | if (!Prefix) |
| 1715 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | |
| 1717 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1718 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1719 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1720 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1721 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1723 | switch (NNS->getKind()) { |
| 1724 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1726 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1727 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1728 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1729 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | |
| 1731 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1732 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1733 | ObjectType, |
| 1734 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1735 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1736 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1738 | = cast_or_null<NamespaceDecl>( |
| 1739 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1741 | Prefix == NNS->getPrefix() && |
| 1742 | NS == NNS->getAsNamespace()) |
| 1743 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1745 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1746 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1747 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1748 | case NestedNameSpecifier::Global: |
| 1749 | // There is no meaningful transformation that one could perform on the |
| 1750 | // global scope. |
| 1751 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1753 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1754 | case NestedNameSpecifier::TypeSpec: { |
| 1755 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1756 | if (T.isNull()) |
| 1757 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1759 | if (!getDerived().AlwaysRebuild() && |
| 1760 | Prefix == NNS->getPrefix() && |
| 1761 | T == QualType(NNS->getAsType(), 0)) |
| 1762 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | |
| 1764 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1765 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1766 | T); |
| 1767 | } |
| 1768 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1775 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1776 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1777 | SourceLocation Loc, |
| 1778 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1779 | if (!Name) |
| 1780 | return Name; |
| 1781 | |
| 1782 | switch (Name.getNameKind()) { |
| 1783 | case DeclarationName::Identifier: |
| 1784 | case DeclarationName::ObjCZeroArgSelector: |
| 1785 | case DeclarationName::ObjCOneArgSelector: |
| 1786 | case DeclarationName::ObjCMultiArgSelector: |
| 1787 | case DeclarationName::CXXOperatorName: |
| 1788 | case DeclarationName::CXXUsingDirective: |
| 1789 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1791 | case DeclarationName::CXXConstructorName: |
| 1792 | case DeclarationName::CXXDestructorName: |
| 1793 | case DeclarationName::CXXConversionFunctionName: { |
| 1794 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1795 | QualType T; |
| 1796 | if (!ObjectType.isNull() && |
| 1797 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1798 | TemplateSpecializationType *SpecType |
| 1799 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1800 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1801 | } else |
| 1802 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1803 | if (T.isNull()) |
| 1804 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1808 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1812 | return DeclarationName(); |
| 1813 | } |
| 1814 | |
| 1815 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1816 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1817 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1818 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1819 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1820 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1821 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1822 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1823 | if (!NNS) |
| 1824 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1826 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1828 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1829 | if (!TransTemplate) |
| 1830 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1831 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1832 | if (!getDerived().AlwaysRebuild() && |
| 1833 | NNS == QTN->getQualifier() && |
| 1834 | TransTemplate == Template) |
| 1835 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1836 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1837 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1838 | TransTemplate); |
| 1839 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1840 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl(); |
| 1842 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1844 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1845 | if (!TransOvl) |
| 1846 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1848 | if (!getDerived().AlwaysRebuild() && |
| 1849 | NNS == QTN->getQualifier() && |
| 1850 | TransOvl == Ovl) |
| 1851 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1854 | TransOvl); |
| 1855 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1857 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1859 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1860 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1861 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1862 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1864 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1865 | NNS == DTN->getQualifier() && |
| 1866 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1867 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1869 | return getDerived().RebuildTemplateName(NNS, *DTN->getName(), ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1872 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1875 | if (!TransTemplate) |
| 1876 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | if (!getDerived().AlwaysRebuild() && |
| 1879 | TransTemplate == Template) |
| 1880 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1881 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1882 | return TemplateName(TransTemplate); |
| 1883 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1884 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1885 | OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl(); |
| 1886 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1888 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1889 | if (!TransOvl) |
| 1890 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1892 | if (!getDerived().AlwaysRebuild() && |
| 1893 | TransOvl == Ovl) |
| 1894 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | return TemplateName(TransOvl); |
| 1897 | } |
| 1898 | |
| 1899 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1900 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1901 | const TemplateArgument &Arg, |
| 1902 | TemplateArgumentLoc &Output) { |
| 1903 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1904 | switch (Arg.getKind()) { |
| 1905 | case TemplateArgument::Null: |
| 1906 | llvm::llvm_unreachable("null template argument in TreeTransform"); |
| 1907 | break; |
| 1908 | |
| 1909 | case TemplateArgument::Type: |
| 1910 | Output = TemplateArgumentLoc(Arg, |
| 1911 | SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc)); |
| 1912 | |
| 1913 | break; |
| 1914 | |
| 1915 | case TemplateArgument::Expression: |
| 1916 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1917 | break; |
| 1918 | |
| 1919 | case TemplateArgument::Declaration: |
| 1920 | case TemplateArgument::Integral: |
| 1921 | case TemplateArgument::Pack: |
| 1922 | Output = TemplateArgumentLoc(Arg); |
| 1923 | break; |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | template<typename Derived> |
| 1928 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1929 | const TemplateArgumentLoc &Input, |
| 1930 | TemplateArgumentLoc &Output) { |
| 1931 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1932 | switch (Arg.getKind()) { |
| 1933 | case TemplateArgument::Null: |
| 1934 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1935 | Output = Input; |
| 1936 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1937 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1938 | case TemplateArgument::Type: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1939 | DeclaratorInfo *DI = Input.getSourceDeclaratorInfo(); |
| 1940 | if (DI == NULL) |
| 1941 | DI = InventDeclaratorInfo(Input.getArgument().getAsType()); |
| 1942 | |
| 1943 | DI = getDerived().TransformType(DI); |
| 1944 | if (!DI) return true; |
| 1945 | |
| 1946 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1947 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1950 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1951 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1952 | DeclarationName Name; |
| 1953 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1954 | Name = ND->getDeclName(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1955 | TemporaryBase Rebase(*this, SourceLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1956 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1957 | if (!D) return true; |
| 1958 | |
| 1959 | Output = TemplateArgumentLoc(TemplateArgument(D)); |
| 1960 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1961 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1963 | case TemplateArgument::Expression: { |
| 1964 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1966 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1967 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1968 | Expr *InputExpr = Input.getSourceExpression(); |
| 1969 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1970 | |
| 1971 | Sema::OwningExprResult E |
| 1972 | = getDerived().TransformExpr(InputExpr); |
| 1973 | if (E.isInvalid()) return true; |
| 1974 | |
| 1975 | Expr *ETaken = E.takeAs<Expr>(); |
| 1976 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1977 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1980 | case TemplateArgument::Pack: { |
| 1981 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1982 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1983 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1984 | AEnd = Arg.pack_end(); |
| 1985 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1986 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1987 | // FIXME: preserve source information here when we start |
| 1988 | // caring about parameter packs. |
| 1989 | |
| 1990 | TemplateArgumentLoc Input; |
| 1991 | TemplateArgumentLoc Output; |
| 1992 | getDerived().InventTemplateArgumentLoc(*A, Input); |
| 1993 | if (getDerived().TransformTemplateArgument(Input, Output)) |
| 1994 | return true; |
| 1995 | |
| 1996 | TransformedArgs.push_back(Output.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1997 | } |
| 1998 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2000 | true); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2001 | Output = TemplateArgumentLoc(Result); |
| 2002 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2003 | } |
| 2004 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2006 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2007 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2010 | //===----------------------------------------------------------------------===// |
| 2011 | // Type transformation |
| 2012 | //===----------------------------------------------------------------------===// |
| 2013 | |
| 2014 | template<typename Derived> |
| 2015 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2016 | if (getDerived().AlreadyTransformed(T)) |
| 2017 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2019 | // Temporary workaround. All of these transformations should |
| 2020 | // eventually turn into transformations on TypeLocs. |
| 2021 | DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2022 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2023 | |
| 2024 | DeclaratorInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2025 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2026 | if (!NewDI) |
| 2027 | return QualType(); |
| 2028 | |
| 2029 | return NewDI->getType(); |
| 2030 | } |
| 2031 | |
| 2032 | template<typename Derived> |
| 2033 | DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) { |
| 2034 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2035 | return DI; |
| 2036 | |
| 2037 | TypeLocBuilder TLB; |
| 2038 | |
| 2039 | TypeLoc TL = DI->getTypeLoc(); |
| 2040 | TLB.reserve(TL.getFullDataSize()); |
| 2041 | |
| 2042 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2043 | if (Result.isNull()) |
| 2044 | return 0; |
| 2045 | |
| 2046 | return TLB.getDeclaratorInfo(SemaRef.Context, Result); |
| 2047 | } |
| 2048 | |
| 2049 | template<typename Derived> |
| 2050 | QualType |
| 2051 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2052 | switch (T.getTypeLocClass()) { |
| 2053 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2054 | #define TYPELOC(CLASS, PARENT) \ |
| 2055 | case TypeLoc::CLASS: \ |
| 2056 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2057 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2059 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2060 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2061 | return QualType(); |
| 2062 | } |
| 2063 | |
| 2064 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2065 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2066 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2067 | /// types). This is the right thing for template instantiation, but |
| 2068 | /// probably not for other clients. |
| 2069 | template<typename Derived> |
| 2070 | QualType |
| 2071 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2072 | QualifiedTypeLoc T) { |
| 2073 | Qualifiers Quals = T.getType().getQualifiers(); |
| 2074 | |
| 2075 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2076 | if (Result.isNull()) |
| 2077 | return QualType(); |
| 2078 | |
| 2079 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2080 | // FIXME: this is the right thing for template instantiation, but |
| 2081 | // probably not for other clients. |
| 2082 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2083 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2084 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2085 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2086 | |
| 2087 | TLB.push<QualifiedTypeLoc>(Result); |
| 2088 | |
| 2089 | // No location information to preserve. |
| 2090 | |
| 2091 | return Result; |
| 2092 | } |
| 2093 | |
| 2094 | template <class TyLoc> static inline |
| 2095 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2096 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2097 | NewT.setNameLoc(T.getNameLoc()); |
| 2098 | return T.getType(); |
| 2099 | } |
| 2100 | |
| 2101 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2102 | // the equivalent template version work. |
| 2103 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2104 | QualType PointeeType \ |
| 2105 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2106 | if (PointeeType.isNull()) \ |
| 2107 | return QualType(); \ |
| 2108 | \ |
| 2109 | QualType Result = TL.getType(); \ |
| 2110 | if (getDerived().AlwaysRebuild() || \ |
| 2111 | PointeeType != TL.getPointeeLoc().getType()) { \ |
| 2112 | Result = getDerived().Rebuild##TypeClass(PointeeType); \ |
| 2113 | if (Result.isNull()) \ |
| 2114 | return QualType(); \ |
| 2115 | } \ |
| 2116 | \ |
| 2117 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2118 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2119 | \ |
| 2120 | return Result; \ |
| 2121 | } while(0) |
| 2122 | |
| 2123 | // Reference collapsing forces us to transform reference types |
| 2124 | // differently from the other pointer-like types. |
| 2125 | #define TransformReferenceType(TypeClass) do { \ |
| 2126 | QualType PointeeType \ |
| 2127 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2128 | if (PointeeType.isNull()) \ |
| 2129 | return QualType(); \ |
| 2130 | \ |
| 2131 | QualType Result = TL.getType(); \ |
| 2132 | if (getDerived().AlwaysRebuild() || \ |
| 2133 | PointeeType != TL.getPointeeLoc().getType()) { \ |
| 2134 | Result = getDerived().Rebuild##TypeClass(PointeeType); \ |
| 2135 | if (Result.isNull()) \ |
| 2136 | return QualType(); \ |
| 2137 | } \ |
| 2138 | \ |
| 2139 | /* Workaround: rebuild doesn't always change the type */ \ |
| 2140 | /* FIXME: avoid losing this location information. */ \ |
| 2141 | if (Result == PointeeType) \ |
| 2142 | return Result; \ |
| 2143 | ReferenceTypeLoc NewTL; \ |
| 2144 | if (isa<LValueReferenceType>(Result)) \ |
| 2145 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); \ |
| 2146 | else \ |
| 2147 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); \ |
| 2148 | NewTL.setSigilLoc(TL.getSigilLoc()); \ |
| 2149 | return Result; \ |
| 2150 | } while (0) |
| 2151 | |
| 2152 | template<typename Derived> |
| 2153 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2154 | BuiltinTypeLoc T) { |
| 2155 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2157 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2158 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2159 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2160 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2161 | FixedWidthIntTypeLoc T) { |
| 2162 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2163 | } |
Argyrios Kyrtzidis | e918926 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2164 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2165 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2166 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2167 | ComplexTypeLoc T) { |
| 2168 | // FIXME: recurse? |
| 2169 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2170 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2172 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2173 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2174 | PointerTypeLoc TL) { |
| 2175 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2176 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | |
| 2178 | template<typename Derived> |
| 2179 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2180 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2181 | BlockPointerTypeLoc TL) { |
| 2182 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | template<typename Derived> |
| 2186 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2187 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2188 | LValueReferenceTypeLoc TL) { |
| 2189 | TransformReferenceType(LValueReferenceType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2192 | template<typename Derived> |
| 2193 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2194 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2195 | RValueReferenceTypeLoc TL) { |
| 2196 | TransformReferenceType(RValueReferenceType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2199 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2200 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2202 | MemberPointerTypeLoc TL) { |
| 2203 | MemberPointerType *T = TL.getTypePtr(); |
| 2204 | |
| 2205 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2206 | if (PointeeType.isNull()) |
| 2207 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2209 | // TODO: preserve source information for this. |
| 2210 | QualType ClassType |
| 2211 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2212 | if (ClassType.isNull()) |
| 2213 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2214 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2215 | QualType Result = TL.getType(); |
| 2216 | if (getDerived().AlwaysRebuild() || |
| 2217 | PointeeType != T->getPointeeType() || |
| 2218 | ClassType != QualType(T->getClass(), 0)) { |
| 2219 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType); |
| 2220 | if (Result.isNull()) |
| 2221 | return QualType(); |
| 2222 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2223 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2224 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2225 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2226 | |
| 2227 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2230 | template<typename Derived> |
| 2231 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2232 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2233 | ConstantArrayTypeLoc TL) { |
| 2234 | ConstantArrayType *T = TL.getTypePtr(); |
| 2235 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2236 | if (ElementType.isNull()) |
| 2237 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2238 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2239 | QualType Result = TL.getType(); |
| 2240 | if (getDerived().AlwaysRebuild() || |
| 2241 | ElementType != T->getElementType()) { |
| 2242 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2243 | T->getSizeModifier(), |
| 2244 | T->getSize(), |
| 2245 | T->getIndexTypeCVRQualifiers()); |
| 2246 | if (Result.isNull()) |
| 2247 | return QualType(); |
| 2248 | } |
| 2249 | |
| 2250 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2251 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2252 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2253 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2254 | Expr *Size = TL.getSizeExpr(); |
| 2255 | if (Size) { |
| 2256 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2257 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2258 | } |
| 2259 | NewTL.setSizeExpr(Size); |
| 2260 | |
| 2261 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2263 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2264 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2265 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2266 | TypeLocBuilder &TLB, |
| 2267 | IncompleteArrayTypeLoc TL) { |
| 2268 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2269 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2270 | if (ElementType.isNull()) |
| 2271 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2273 | QualType Result = TL.getType(); |
| 2274 | if (getDerived().AlwaysRebuild() || |
| 2275 | ElementType != T->getElementType()) { |
| 2276 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2277 | T->getSizeModifier(), |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2278 | T->getIndexTypeCVRQualifiers()); |
| 2279 | if (Result.isNull()) |
| 2280 | return QualType(); |
| 2281 | } |
| 2282 | |
| 2283 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2284 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2285 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2286 | NewTL.setSizeExpr(0); |
| 2287 | |
| 2288 | return Result; |
| 2289 | } |
| 2290 | |
| 2291 | template<typename Derived> |
| 2292 | QualType |
| 2293 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2294 | VariableArrayTypeLoc TL) { |
| 2295 | VariableArrayType *T = TL.getTypePtr(); |
| 2296 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2297 | if (ElementType.isNull()) |
| 2298 | return QualType(); |
| 2299 | |
| 2300 | // Array bounds are not potentially evaluated contexts |
| 2301 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2302 | |
| 2303 | Sema::OwningExprResult SizeResult |
| 2304 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2305 | if (SizeResult.isInvalid()) |
| 2306 | return QualType(); |
| 2307 | |
| 2308 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2309 | |
| 2310 | QualType Result = TL.getType(); |
| 2311 | if (getDerived().AlwaysRebuild() || |
| 2312 | ElementType != T->getElementType() || |
| 2313 | Size != T->getSizeExpr()) { |
| 2314 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2315 | T->getSizeModifier(), |
| 2316 | move(SizeResult), |
| 2317 | T->getIndexTypeCVRQualifiers(), |
| 2318 | T->getBracketsRange()); |
| 2319 | if (Result.isNull()) |
| 2320 | return QualType(); |
| 2321 | } |
| 2322 | else SizeResult.take(); |
| 2323 | |
| 2324 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2325 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2326 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2327 | NewTL.setSizeExpr(Size); |
| 2328 | |
| 2329 | return Result; |
| 2330 | } |
| 2331 | |
| 2332 | template<typename Derived> |
| 2333 | QualType |
| 2334 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2335 | DependentSizedArrayTypeLoc TL) { |
| 2336 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2337 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2338 | if (ElementType.isNull()) |
| 2339 | return QualType(); |
| 2340 | |
| 2341 | // Array bounds are not potentially evaluated contexts |
| 2342 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2343 | |
| 2344 | Sema::OwningExprResult SizeResult |
| 2345 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2346 | if (SizeResult.isInvalid()) |
| 2347 | return QualType(); |
| 2348 | |
| 2349 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2350 | |
| 2351 | QualType Result = TL.getType(); |
| 2352 | if (getDerived().AlwaysRebuild() || |
| 2353 | ElementType != T->getElementType() || |
| 2354 | Size != T->getSizeExpr()) { |
| 2355 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2356 | T->getSizeModifier(), |
| 2357 | move(SizeResult), |
| 2358 | T->getIndexTypeCVRQualifiers(), |
| 2359 | T->getBracketsRange()); |
| 2360 | if (Result.isNull()) |
| 2361 | return QualType(); |
| 2362 | } |
| 2363 | else SizeResult.take(); |
| 2364 | |
| 2365 | // We might have any sort of array type now, but fortunately they |
| 2366 | // all have the same location layout. |
| 2367 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2368 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2369 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2370 | NewTL.setSizeExpr(Size); |
| 2371 | |
| 2372 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2374 | |
| 2375 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2376 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2377 | TypeLocBuilder &TLB, |
| 2378 | DependentSizedExtVectorTypeLoc TL) { |
| 2379 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2380 | |
| 2381 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2382 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2383 | if (ElementType.isNull()) |
| 2384 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2385 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2386 | // Vector sizes are not potentially evaluated contexts |
| 2387 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2388 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2389 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2390 | if (Size.isInvalid()) |
| 2391 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2393 | QualType Result = TL.getType(); |
| 2394 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2395 | ElementType != T->getElementType() || |
| 2396 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2397 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2398 | move(Size), |
| 2399 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2400 | if (Result.isNull()) |
| 2401 | return QualType(); |
| 2402 | } |
| 2403 | else Size.take(); |
| 2404 | |
| 2405 | // Result might be dependent or not. |
| 2406 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2407 | DependentSizedExtVectorTypeLoc NewTL |
| 2408 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2409 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2410 | } else { |
| 2411 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2412 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2413 | } |
| 2414 | |
| 2415 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2417 | |
| 2418 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2419 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2420 | VectorTypeLoc TL) { |
| 2421 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2422 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2423 | if (ElementType.isNull()) |
| 2424 | return QualType(); |
| 2425 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2426 | QualType Result = TL.getType(); |
| 2427 | if (getDerived().AlwaysRebuild() || |
| 2428 | ElementType != T->getElementType()) { |
| 2429 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2430 | if (Result.isNull()) |
| 2431 | return QualType(); |
| 2432 | } |
| 2433 | |
| 2434 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2435 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2437 | return Result; |
| 2438 | } |
| 2439 | |
| 2440 | template<typename Derived> |
| 2441 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2442 | ExtVectorTypeLoc TL) { |
| 2443 | VectorType *T = TL.getTypePtr(); |
| 2444 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2445 | if (ElementType.isNull()) |
| 2446 | return QualType(); |
| 2447 | |
| 2448 | QualType Result = TL.getType(); |
| 2449 | if (getDerived().AlwaysRebuild() || |
| 2450 | ElementType != T->getElementType()) { |
| 2451 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2452 | T->getNumElements(), |
| 2453 | /*FIXME*/ SourceLocation()); |
| 2454 | if (Result.isNull()) |
| 2455 | return QualType(); |
| 2456 | } |
| 2457 | |
| 2458 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2459 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2460 | |
| 2461 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2462 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2463 | |
| 2464 | template<typename Derived> |
| 2465 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2466 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2467 | FunctionProtoTypeLoc TL) { |
| 2468 | FunctionProtoType *T = TL.getTypePtr(); |
| 2469 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2470 | if (ResultType.isNull()) |
| 2471 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2472 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2473 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2474 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2475 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2476 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2477 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2478 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2479 | QualType NewType; |
| 2480 | ParmVarDecl *NewParm; |
| 2481 | |
| 2482 | if (OldParm) { |
| 2483 | DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo(); |
| 2484 | assert(OldDI->getType() == T->getArgType(i)); |
| 2485 | |
| 2486 | DeclaratorInfo *NewDI = getDerived().TransformType(OldDI); |
| 2487 | if (!NewDI) |
| 2488 | return QualType(); |
| 2489 | |
| 2490 | if (NewDI == OldDI) |
| 2491 | NewParm = OldParm; |
| 2492 | else |
| 2493 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2494 | OldParm->getDeclContext(), |
| 2495 | OldParm->getLocation(), |
| 2496 | OldParm->getIdentifier(), |
| 2497 | NewDI->getType(), |
| 2498 | NewDI, |
| 2499 | OldParm->getStorageClass(), |
| 2500 | /* DefArg */ NULL); |
| 2501 | NewType = NewParm->getType(); |
| 2502 | |
| 2503 | // Deal with the possibility that we don't have a parameter |
| 2504 | // declaration for this parameter. |
| 2505 | } else { |
| 2506 | NewParm = 0; |
| 2507 | |
| 2508 | QualType OldType = T->getArgType(i); |
| 2509 | NewType = getDerived().TransformType(OldType); |
| 2510 | if (NewType.isNull()) |
| 2511 | return QualType(); |
| 2512 | } |
| 2513 | |
| 2514 | ParamTypes.push_back(NewType); |
| 2515 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2516 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2517 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2518 | QualType Result = TL.getType(); |
| 2519 | if (getDerived().AlwaysRebuild() || |
| 2520 | ResultType != T->getResultType() || |
| 2521 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2522 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2523 | ParamTypes.data(), |
| 2524 | ParamTypes.size(), |
| 2525 | T->isVariadic(), |
| 2526 | T->getTypeQuals()); |
| 2527 | if (Result.isNull()) |
| 2528 | return QualType(); |
| 2529 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2530 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2531 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2532 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2533 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2534 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2535 | NewTL.setArg(i, ParamDecls[i]); |
| 2536 | |
| 2537 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2539 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | template<typename Derived> |
| 2541 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2542 | TypeLocBuilder &TLB, |
| 2543 | FunctionNoProtoTypeLoc TL) { |
| 2544 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2545 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2546 | if (ResultType.isNull()) |
| 2547 | return QualType(); |
| 2548 | |
| 2549 | QualType Result = TL.getType(); |
| 2550 | if (getDerived().AlwaysRebuild() || |
| 2551 | ResultType != T->getResultType()) |
| 2552 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2553 | |
| 2554 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2555 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2556 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2557 | |
| 2558 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2560 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2561 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2562 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2563 | TypedefTypeLoc TL) { |
| 2564 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2565 | TypedefDecl *Typedef |
| 2566 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2567 | if (!Typedef) |
| 2568 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2569 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2570 | QualType Result = TL.getType(); |
| 2571 | if (getDerived().AlwaysRebuild() || |
| 2572 | Typedef != T->getDecl()) { |
| 2573 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2574 | if (Result.isNull()) |
| 2575 | return QualType(); |
| 2576 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2577 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2578 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2579 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2580 | |
| 2581 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2582 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2584 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2585 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2586 | TypeOfExprTypeLoc TL) { |
| 2587 | TypeOfExprType *T = TL.getTypePtr(); |
| 2588 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2589 | // typeof expressions are not potentially evaluated contexts |
| 2590 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2592 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2593 | if (E.isInvalid()) |
| 2594 | return QualType(); |
| 2595 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2596 | QualType Result = TL.getType(); |
| 2597 | if (getDerived().AlwaysRebuild() || |
| 2598 | E.get() != T->getUnderlyingExpr()) { |
| 2599 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2600 | if (Result.isNull()) |
| 2601 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2602 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2603 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2604 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2605 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2606 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2607 | |
| 2608 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2609 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | |
| 2611 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2612 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2613 | TypeOfTypeLoc TL) { |
| 2614 | TypeOfType *T = TL.getTypePtr(); |
| 2615 | |
| 2616 | // FIXME: should be an inner type, or at least have a DeclaratorInfo. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2617 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2618 | if (Underlying.isNull()) |
| 2619 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2620 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2621 | QualType Result = TL.getType(); |
| 2622 | if (getDerived().AlwaysRebuild() || |
| 2623 | Underlying != T->getUnderlyingType()) { |
| 2624 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2625 | if (Result.isNull()) |
| 2626 | return QualType(); |
| 2627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2628 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2629 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2630 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2631 | |
| 2632 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 | |
| 2635 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2636 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2637 | DecltypeTypeLoc TL) { |
| 2638 | DecltypeType *T = TL.getTypePtr(); |
| 2639 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2640 | // decltype expressions are not potentially evaluated contexts |
| 2641 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2643 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2644 | if (E.isInvalid()) |
| 2645 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2646 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2647 | QualType Result = TL.getType(); |
| 2648 | if (getDerived().AlwaysRebuild() || |
| 2649 | E.get() != T->getUnderlyingExpr()) { |
| 2650 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2651 | if (Result.isNull()) |
| 2652 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2653 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2654 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2655 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2656 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2657 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2658 | |
| 2659 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2663 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2664 | RecordTypeLoc TL) { |
| 2665 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2666 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2667 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2668 | if (!Record) |
| 2669 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2671 | QualType Result = TL.getType(); |
| 2672 | if (getDerived().AlwaysRebuild() || |
| 2673 | Record != T->getDecl()) { |
| 2674 | Result = getDerived().RebuildRecordType(Record); |
| 2675 | if (Result.isNull()) |
| 2676 | return QualType(); |
| 2677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2678 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2679 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2680 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2681 | |
| 2682 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2683 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2684 | |
| 2685 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2686 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2687 | EnumTypeLoc TL) { |
| 2688 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2689 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2690 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2691 | if (!Enum) |
| 2692 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2693 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | QualType Result = TL.getType(); |
| 2695 | if (getDerived().AlwaysRebuild() || |
| 2696 | Enum != T->getDecl()) { |
| 2697 | Result = getDerived().RebuildEnumType(Enum); |
| 2698 | if (Result.isNull()) |
| 2699 | return QualType(); |
| 2700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2701 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2702 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2703 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2704 | |
| 2705 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2706 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2707 | |
| 2708 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2709 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2710 | ElaboratedTypeLoc TL) { |
| 2711 | ElaboratedType *T = TL.getTypePtr(); |
| 2712 | |
| 2713 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2714 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2715 | if (Underlying.isNull()) |
| 2716 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2717 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2718 | QualType Result = TL.getType(); |
| 2719 | if (getDerived().AlwaysRebuild() || |
| 2720 | Underlying != T->getUnderlyingType()) { |
| 2721 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2722 | if (Result.isNull()) |
| 2723 | return QualType(); |
| 2724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2727 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2728 | |
| 2729 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
| 2732 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2733 | template<typename Derived> |
| 2734 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2735 | TypeLocBuilder &TLB, |
| 2736 | TemplateTypeParmTypeLoc TL) { |
| 2737 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2740 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2741 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2742 | TypeLocBuilder &TLB, |
| 2743 | SubstTemplateTypeParmTypeLoc TL) { |
| 2744 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | template<typename Derived> |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2748 | inline QualType |
| 2749 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2750 | TypeLocBuilder &TLB, |
| 2751 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2752 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2753 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2754 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2755 | template<typename Derived> |
| 2756 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2757 | const TemplateSpecializationType *TST, |
| 2758 | QualType ObjectType) { |
| 2759 | // FIXME: this entire method is a temporary workaround; callers |
| 2760 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2761 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2762 | // Fake up a TemplateSpecializationTypeLoc. |
| 2763 | TypeLocBuilder TLB; |
| 2764 | TemplateSpecializationTypeLoc TL |
| 2765 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2766 | |
| 2767 | TL.setTemplateNameLoc(getDerived().getBaseLocation()); |
| 2768 | TL.setLAngleLoc(SourceLocation()); |
| 2769 | TL.setRAngleLoc(SourceLocation()); |
| 2770 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2771 | const TemplateArgument &TA = TST->getArg(i); |
| 2772 | TemplateArgumentLoc TAL; |
| 2773 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2774 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2775 | } |
| 2776 | |
| 2777 | TypeLocBuilder IgnoredTLB; |
| 2778 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2782 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2783 | TypeLocBuilder &TLB, |
| 2784 | TemplateSpecializationTypeLoc TL, |
| 2785 | QualType ObjectType) { |
| 2786 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2787 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2788 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2789 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2790 | if (Template.isNull()) |
| 2791 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2793 | llvm::SmallVector<TemplateArgumentLoc, 4> NewTemplateArgs(T->getNumArgs()); |
| 2794 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) |
| 2795 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), |
| 2796 | NewTemplateArgs[i])) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2797 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2798 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2799 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2800 | |
| 2801 | QualType Result = |
| 2802 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2803 | TL.getTemplateNameLoc(), |
| 2804 | TL.getLAngleLoc(), |
| 2805 | NewTemplateArgs.data(), |
| 2806 | NewTemplateArgs.size(), |
| 2807 | TL.getRAngleLoc()); |
| 2808 | |
| 2809 | if (!Result.isNull()) { |
| 2810 | TemplateSpecializationTypeLoc NewTL |
| 2811 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2812 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2813 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2814 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2815 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2816 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2817 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2818 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2819 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2821 | |
| 2822 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2823 | QualType |
| 2824 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2825 | QualifiedNameTypeLoc TL) { |
| 2826 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2827 | NestedNameSpecifier *NNS |
| 2828 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2829 | SourceRange()); |
| 2830 | if (!NNS) |
| 2831 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2832 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2834 | if (Named.isNull()) |
| 2835 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2836 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | QualType Result = TL.getType(); |
| 2838 | if (getDerived().AlwaysRebuild() || |
| 2839 | NNS != T->getQualifier() || |
| 2840 | Named != T->getNamedType()) { |
| 2841 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2842 | if (Result.isNull()) |
| 2843 | return QualType(); |
| 2844 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2845 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2846 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2847 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2848 | |
| 2849 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2850 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2851 | |
| 2852 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2853 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2854 | TypenameTypeLoc TL) { |
| 2855 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2856 | |
| 2857 | /* FIXME: preserve source information better than this */ |
| 2858 | SourceRange SR(TL.getNameLoc()); |
| 2859 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2860 | NestedNameSpecifier *NNS |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2861 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2862 | if (!NNS) |
| 2863 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2864 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2865 | QualType Result; |
| 2866 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2867 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2868 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2869 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2870 | if (NewTemplateId.isNull()) |
| 2871 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2872 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2873 | if (!getDerived().AlwaysRebuild() && |
| 2874 | NNS == T->getQualifier() && |
| 2875 | NewTemplateId == QualType(TemplateId, 0)) |
| 2876 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2877 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2878 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2879 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2880 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2881 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2882 | if (Result.isNull()) |
| 2883 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2884 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2885 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2886 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2887 | |
| 2888 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2890 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2891 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2892 | QualType |
| 2893 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2894 | ObjCInterfaceTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2895 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2896 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2897 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2898 | |
| 2899 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2900 | QualType |
| 2901 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2902 | ObjCObjectPointerTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2903 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2904 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2908 | // Statement transformation |
| 2909 | //===----------------------------------------------------------------------===// |
| 2910 | template<typename Derived> |
| 2911 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2912 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2913 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | template<typename Derived> |
| 2917 | Sema::OwningStmtResult |
| 2918 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2919 | return getDerived().TransformCompoundStmt(S, false); |
| 2920 | } |
| 2921 | |
| 2922 | template<typename Derived> |
| 2923 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2924 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2925 | bool IsStmtExpr) { |
| 2926 | bool SubStmtChanged = false; |
| 2927 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2928 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2929 | B != BEnd; ++B) { |
| 2930 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2931 | if (Result.isInvalid()) |
| 2932 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2933 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2934 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2935 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2936 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2938 | if (!getDerived().AlwaysRebuild() && |
| 2939 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2940 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2941 | |
| 2942 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2943 | move_arg(Statements), |
| 2944 | S->getRBracLoc(), |
| 2945 | IsStmtExpr); |
| 2946 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2948 | template<typename Derived> |
| 2949 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2950 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2951 | // The case value expressions are not potentially evaluated. |
| 2952 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2954 | // Transform the left-hand case value. |
| 2955 | OwningExprResult LHS = getDerived().TransformExpr(S->getLHS()); |
| 2956 | if (LHS.isInvalid()) |
| 2957 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2958 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2959 | // Transform the right-hand case value (for the GNU case-range extension). |
| 2960 | OwningExprResult RHS = getDerived().TransformExpr(S->getRHS()); |
| 2961 | if (RHS.isInvalid()) |
| 2962 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2963 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2964 | // Build the case statement. |
| 2965 | // Case statements are always rebuilt so that they will attached to their |
| 2966 | // transformed switch statement. |
| 2967 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 2968 | move(LHS), |
| 2969 | S->getEllipsisLoc(), |
| 2970 | move(RHS), |
| 2971 | S->getColonLoc()); |
| 2972 | if (Case.isInvalid()) |
| 2973 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2975 | // Transform the statement following the case |
| 2976 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 2977 | if (SubStmt.isInvalid()) |
| 2978 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2980 | // Attach the body to the case statement |
| 2981 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 2982 | } |
| 2983 | |
| 2984 | template<typename Derived> |
| 2985 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2987 | // Transform the statement following the default case |
| 2988 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 2989 | if (SubStmt.isInvalid()) |
| 2990 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2992 | // Default statements are always rebuilt |
| 2993 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 2994 | move(SubStmt)); |
| 2995 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2996 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2997 | template<typename Derived> |
| 2998 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2999 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3000 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3001 | if (SubStmt.isInvalid()) |
| 3002 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3004 | // FIXME: Pass the real colon location in. |
| 3005 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3006 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3007 | move(SubStmt)); |
| 3008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3009 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3010 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | Sema::OwningStmtResult |
| 3012 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3013 | // Transform the condition |
| 3014 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3015 | if (Cond.isInvalid()) |
| 3016 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3018 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3019 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3020 | // Transform the "then" branch. |
| 3021 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3022 | if (Then.isInvalid()) |
| 3023 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3025 | // Transform the "else" branch. |
| 3026 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3027 | if (Else.isInvalid()) |
| 3028 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3030 | if (!getDerived().AlwaysRebuild() && |
| 3031 | FullCond->get() == S->getCond() && |
| 3032 | Then.get() == S->getThen() && |
| 3033 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | return SemaRef.Owned(S->Retain()); |
| 3035 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3036 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | template<typename Derived> |
| 3041 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3042 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3043 | // Transform the condition. |
| 3044 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3045 | if (Cond.isInvalid()) |
| 3046 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3048 | // Rebuild the switch statement. |
| 3049 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond)); |
| 3050 | if (Switch.isInvalid()) |
| 3051 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3053 | // Transform the body of the switch statement. |
| 3054 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3055 | if (Body.isInvalid()) |
| 3056 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3058 | // Complete the switch statement. |
| 3059 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3060 | move(Body)); |
| 3061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3062 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3063 | template<typename Derived> |
| 3064 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3065 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3066 | // Transform the condition |
| 3067 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3068 | if (Cond.isInvalid()) |
| 3069 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3070 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3071 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3073 | // Transform the body |
| 3074 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3075 | if (Body.isInvalid()) |
| 3076 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3078 | if (!getDerived().AlwaysRebuild() && |
| 3079 | FullCond->get() == S->getCond() && |
| 3080 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | return SemaRef.Owned(S->Retain()); |
| 3082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body)); |
| 3084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3085 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3086 | template<typename Derived> |
| 3087 | Sema::OwningStmtResult |
| 3088 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3089 | // Transform the condition |
| 3090 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3091 | if (Cond.isInvalid()) |
| 3092 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3094 | // Transform the body |
| 3095 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3096 | if (Body.isInvalid()) |
| 3097 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3098 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | if (!getDerived().AlwaysRebuild() && |
| 3100 | Cond.get() == S->getCond() && |
| 3101 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3102 | return SemaRef.Owned(S->Retain()); |
| 3103 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3104 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3105 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3106 | S->getRParenLoc()); |
| 3107 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3109 | template<typename Derived> |
| 3110 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3111 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3112 | // Transform the initialization statement |
| 3113 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3114 | if (Init.isInvalid()) |
| 3115 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3116 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3117 | // Transform the condition |
| 3118 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3119 | if (Cond.isInvalid()) |
| 3120 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3121 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | // Transform the increment |
| 3123 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3124 | if (Inc.isInvalid()) |
| 3125 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3126 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3127 | // Transform the body |
| 3128 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3129 | if (Body.isInvalid()) |
| 3130 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3131 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3132 | if (!getDerived().AlwaysRebuild() && |
| 3133 | Init.get() == S->getInit() && |
| 3134 | Cond.get() == S->getCond() && |
| 3135 | Inc.get() == S->getInc() && |
| 3136 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | return SemaRef.Owned(S->Retain()); |
| 3138 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3139 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 3140 | move(Init), move(Cond), move(Inc), |
| 3141 | S->getRParenLoc(), move(Body)); |
| 3142 | } |
| 3143 | |
| 3144 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3145 | Sema::OwningStmtResult |
| 3146 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3147 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3149 | S->getLabel()); |
| 3150 | } |
| 3151 | |
| 3152 | template<typename Derived> |
| 3153 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3154 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3156 | if (Target.isInvalid()) |
| 3157 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | if (!getDerived().AlwaysRebuild() && |
| 3160 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3162 | |
| 3163 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3164 | move(Target)); |
| 3165 | } |
| 3166 | |
| 3167 | template<typename Derived> |
| 3168 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3170 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3172 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3173 | template<typename Derived> |
| 3174 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3175 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3176 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3178 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3179 | template<typename Derived> |
| 3180 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3183 | if (Result.isInvalid()) |
| 3184 | return SemaRef.StmtError(); |
| 3185 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | // to tell whether the return type of the function has changed. |
| 3188 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3189 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3191 | template<typename Derived> |
| 3192 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3194 | bool DeclChanged = false; |
| 3195 | llvm::SmallVector<Decl *, 4> Decls; |
| 3196 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3197 | D != DEnd; ++D) { |
| 3198 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3199 | if (!Transformed) |
| 3200 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3202 | if (Transformed != *D) |
| 3203 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | Decls.push_back(Transformed); |
| 3206 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3208 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3209 | return SemaRef.Owned(S->Retain()); |
| 3210 | |
| 3211 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3212 | S->getStartLoc(), S->getEndLoc()); |
| 3213 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3214 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3215 | template<typename Derived> |
| 3216 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3219 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | template<typename Derived> |
| 3223 | Sema::OwningStmtResult |
| 3224 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3225 | // FIXME: Implement! |
| 3226 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | template<typename Derived> |
| 3232 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3234 | // FIXME: Implement this |
| 3235 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3237 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3239 | template<typename Derived> |
| 3240 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3242 | // FIXME: Implement this |
| 3243 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3244 | return SemaRef.Owned(S->Retain()); |
| 3245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3246 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3247 | template<typename Derived> |
| 3248 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3250 | // FIXME: Implement this |
| 3251 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3255 | template<typename Derived> |
| 3256 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3258 | // FIXME: Implement this |
| 3259 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3260 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3263 | template<typename Derived> |
| 3264 | Sema::OwningStmtResult |
| 3265 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3266 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | // FIXME: Implement this |
| 3268 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3269 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | template<typename Derived> |
| 3273 | Sema::OwningStmtResult |
| 3274 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3276 | // FIXME: Implement this |
| 3277 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | |
| 3282 | template<typename Derived> |
| 3283 | Sema::OwningStmtResult |
| 3284 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3285 | // Transform the exception declaration, if any. |
| 3286 | VarDecl *Var = 0; |
| 3287 | if (S->getExceptionDecl()) { |
| 3288 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3289 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3290 | ExceptionDecl->getDeclName()); |
| 3291 | |
| 3292 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3293 | if (T.isNull()) |
| 3294 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3295 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3297 | T, |
| 3298 | ExceptionDecl->getDeclaratorInfo(), |
| 3299 | ExceptionDecl->getIdentifier(), |
| 3300 | ExceptionDecl->getLocation(), |
| 3301 | /*FIXME: Inaccurate*/ |
| 3302 | SourceRange(ExceptionDecl->getLocation())); |
| 3303 | if (!Var || Var->isInvalidDecl()) { |
| 3304 | if (Var) |
| 3305 | Var->Destroy(SemaRef.Context); |
| 3306 | return SemaRef.StmtError(); |
| 3307 | } |
| 3308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3310 | // Transform the actual exception handler. |
| 3311 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3312 | if (Handler.isInvalid()) { |
| 3313 | if (Var) |
| 3314 | Var->Destroy(SemaRef.Context); |
| 3315 | return SemaRef.StmtError(); |
| 3316 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3317 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3318 | if (!getDerived().AlwaysRebuild() && |
| 3319 | !Var && |
| 3320 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | |
| 3323 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3324 | Var, |
| 3325 | move(Handler)); |
| 3326 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3327 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3328 | template<typename Derived> |
| 3329 | Sema::OwningStmtResult |
| 3330 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3331 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3333 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3334 | if (TryBlock.isInvalid()) |
| 3335 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3337 | // Transform the handlers. |
| 3338 | bool HandlerChanged = false; |
| 3339 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3340 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3343 | if (Handler.isInvalid()) |
| 3344 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3347 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3349 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | if (!getDerived().AlwaysRebuild() && |
| 3351 | TryBlock.get() == S->getTryBlock() && |
| 3352 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | |
| 3355 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3360 | // Expression transformation |
| 3361 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | template<typename Derived> |
| 3363 | Sema::OwningExprResult |
| 3364 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| 3365 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3366 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | |
| 3368 | template<typename Derived> |
| 3369 | Sema::OwningExprResult |
| 3370 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3371 | NestedNameSpecifier *Qualifier = 0; |
| 3372 | if (E->getQualifier()) { |
| 3373 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3374 | E->getQualifierRange()); |
| 3375 | if (!Qualifier) |
| 3376 | return SemaRef.ExprError(); |
| 3377 | } |
| 3378 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | NamedDecl *ND |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3380 | = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); |
| 3381 | if (!ND) |
| 3382 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3384 | if (!getDerived().AlwaysRebuild() && |
| 3385 | Qualifier == E->getQualifier() && |
| 3386 | ND == E->getDecl() && |
| 3387 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3388 | return SemaRef.Owned(E->Retain()); |
| 3389 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3390 | // FIXME: We're losing the explicit template arguments in this transformation. |
| 3391 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3392 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3393 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3394 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3395 | TransArgs[I])) |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3396 | return SemaRef.ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | // FIXME: Pass the qualifier/qualifier range along. |
| 3400 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
| 3401 | ND, E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3403 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3404 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | Sema::OwningExprResult |
| 3406 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| 3407 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3409 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3410 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3411 | Sema::OwningExprResult |
| 3412 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| 3413 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3414 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3415 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3416 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | Sema::OwningExprResult |
| 3418 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| 3419 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3420 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3422 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3423 | Sema::OwningExprResult |
| 3424 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| 3425 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3428 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3429 | Sema::OwningExprResult |
| 3430 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| 3431 | return SemaRef.Owned(E->Retain()); |
| 3432 | } |
| 3433 | |
| 3434 | template<typename Derived> |
| 3435 | Sema::OwningExprResult |
| 3436 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3437 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3438 | if (SubExpr.isInvalid()) |
| 3439 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3440 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3441 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3442 | return SemaRef.Owned(E->Retain()); |
| 3443 | |
| 3444 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3445 | E->getRParen()); |
| 3446 | } |
| 3447 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | template<typename Derived> |
| 3449 | Sema::OwningExprResult |
| 3450 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3451 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3452 | if (SubExpr.isInvalid()) |
| 3453 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3455 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | return SemaRef.Owned(E->Retain()); |
| 3457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3458 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3459 | E->getOpcode(), |
| 3460 | move(SubExpr)); |
| 3461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3463 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | Sema::OwningExprResult |
| 3465 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3466 | if (E->isArgumentType()) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3467 | TemporaryBase Rebase(*this, E->getOperatorLoc(), DeclarationName()); |
| 3468 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3469 | QualType T = getDerived().TransformType(E->getArgumentType()); |
| 3470 | if (T.isNull()) |
| 3471 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3472 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3473 | if (!getDerived().AlwaysRebuild() && T == E->getArgumentType()) |
| 3474 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | |
| 3476 | return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(), |
| 3477 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3478 | E->getSourceRange()); |
| 3479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3481 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3482 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3483 | // C++0x [expr.sizeof]p1: |
| 3484 | // The operand is either an expression, which is an unevaluated operand |
| 3485 | // [...] |
| 3486 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3487 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3488 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3489 | if (SubExpr.isInvalid()) |
| 3490 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3492 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3493 | return SemaRef.Owned(E->Retain()); |
| 3494 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3495 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3496 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3497 | E->isSizeOf(), |
| 3498 | E->getSourceRange()); |
| 3499 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3500 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3501 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3503 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 3504 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3505 | if (LHS.isInvalid()) |
| 3506 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3508 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3509 | if (RHS.isInvalid()) |
| 3510 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3511 | |
| 3512 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3513 | if (!getDerived().AlwaysRebuild() && |
| 3514 | LHS.get() == E->getLHS() && |
| 3515 | RHS.get() == E->getRHS()) |
| 3516 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3517 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3518 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3519 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3520 | move(RHS), |
| 3521 | E->getRBracketLoc()); |
| 3522 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
| 3524 | template<typename Derived> |
| 3525 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3526 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| 3527 | // Transform the callee. |
| 3528 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3529 | if (Callee.isInvalid()) |
| 3530 | return SemaRef.ExprError(); |
| 3531 | |
| 3532 | // Transform arguments. |
| 3533 | bool ArgChanged = false; |
| 3534 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3535 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3536 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3537 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3538 | if (Arg.isInvalid()) |
| 3539 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3541 | // FIXME: Wrong source location information for the ','. |
| 3542 | FakeCommaLocs.push_back( |
| 3543 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | |
| 3545 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | Args.push_back(Arg.takeAs<Expr>()); |
| 3547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3549 | if (!getDerived().AlwaysRebuild() && |
| 3550 | Callee.get() == E->getCallee() && |
| 3551 | !ArgChanged) |
| 3552 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3554 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3555 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3556 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3557 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3558 | move_arg(Args), |
| 3559 | FakeCommaLocs.data(), |
| 3560 | E->getRParenLoc()); |
| 3561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3562 | |
| 3563 | template<typename Derived> |
| 3564 | Sema::OwningExprResult |
| 3565 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3566 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3567 | if (Base.isInvalid()) |
| 3568 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3570 | NestedNameSpecifier *Qualifier = 0; |
| 3571 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3573 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3574 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3575 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3576 | return SemaRef.ExprError(); |
| 3577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 | |
| 3579 | NamedDecl *Member |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3580 | = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
| 3581 | if (!Member) |
| 3582 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3584 | if (!getDerived().AlwaysRebuild() && |
| 3585 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3586 | Qualifier == E->getQualifier() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3587 | Member == E->getMemberDecl()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3589 | |
| 3590 | // FIXME: Bogus source location for the operator |
| 3591 | SourceLocation FakeOperatorLoc |
| 3592 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3593 | |
| 3594 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3595 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3596 | Qualifier, |
| 3597 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3598 | E->getMemberLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | Member); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3601 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3602 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3603 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
| 3605 | assert(false && "Cannot transform abstract class"); |
| 3606 | return SemaRef.Owned(E->Retain()); |
| 3607 | } |
| 3608 | |
| 3609 | template<typename Derived> |
| 3610 | Sema::OwningExprResult |
| 3611 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3612 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3613 | if (LHS.isInvalid()) |
| 3614 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3616 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3617 | if (RHS.isInvalid()) |
| 3618 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3619 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3620 | if (!getDerived().AlwaysRebuild() && |
| 3621 | LHS.get() == E->getLHS() && |
| 3622 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3623 | return SemaRef.Owned(E->Retain()); |
| 3624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3625 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3626 | move(LHS), move(RHS)); |
| 3627 | } |
| 3628 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3629 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3630 | Sema::OwningExprResult |
| 3631 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| 3632 | CompoundAssignOperator *E) { |
| 3633 | return getDerived().TransformBinaryOperator(E); |
| 3634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3636 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3637 | Sema::OwningExprResult |
| 3638 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3639 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3640 | if (Cond.isInvalid()) |
| 3641 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3642 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3643 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3644 | if (LHS.isInvalid()) |
| 3645 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3646 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3647 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3648 | if (RHS.isInvalid()) |
| 3649 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3651 | if (!getDerived().AlwaysRebuild() && |
| 3652 | Cond.get() == E->getCond() && |
| 3653 | LHS.get() == E->getLHS() && |
| 3654 | RHS.get() == E->getRHS()) |
| 3655 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3656 | |
| 3657 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3658 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3660 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3661 | move(RHS)); |
| 3662 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
| 3664 | template<typename Derived> |
| 3665 | Sema::OwningExprResult |
| 3666 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3667 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3668 | |
| 3669 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3670 | // so do we even need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3671 | QualType T = getDerived().TransformType(E->getType()); |
| 3672 | if (T.isNull()) |
| 3673 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3674 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3676 | if (SubExpr.isInvalid()) |
| 3677 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3679 | if (!getDerived().AlwaysRebuild() && |
| 3680 | T == E->getType() && |
| 3681 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | return SemaRef.Owned(E->Retain()); |
| 3683 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3684 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3685 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3686 | E->isLvalueCast()); |
| 3687 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3688 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3689 | template<typename Derived> |
| 3690 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
| 3692 | assert(false && "Cannot transform abstract class"); |
| 3693 | return SemaRef.Owned(E->Retain()); |
| 3694 | } |
| 3695 | |
| 3696 | template<typename Derived> |
| 3697 | Sema::OwningExprResult |
| 3698 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3699 | QualType T; |
| 3700 | { |
| 3701 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3703 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3704 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3705 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3706 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3707 | if (T.isNull()) |
| 3708 | return SemaRef.ExprError(); |
| 3709 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3710 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3711 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3712 | if (SubExpr.isInvalid()) |
| 3713 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3714 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3715 | if (!getDerived().AlwaysRebuild() && |
| 3716 | T == E->getTypeAsWritten() && |
| 3717 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | return SemaRef.Owned(E->Retain()); |
| 3719 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3720 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3721 | E->getRParenLoc(), |
| 3722 | move(SubExpr)); |
| 3723 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3724 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3725 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 3728 | QualType T; |
| 3729 | { |
| 3730 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3731 | SourceLocation FakeTypeLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3732 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3733 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3734 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3735 | T = getDerived().TransformType(E->getType()); |
| 3736 | if (T.isNull()) |
| 3737 | return SemaRef.ExprError(); |
| 3738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3739 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3740 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3741 | if (Init.isInvalid()) |
| 3742 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3743 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3744 | if (!getDerived().AlwaysRebuild() && |
| 3745 | T == E->getType() && |
| 3746 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | |
| 3749 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3750 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3751 | move(Init)); |
| 3752 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | template<typename Derived> |
| 3755 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3757 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3758 | if (Base.isInvalid()) |
| 3759 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3760 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3761 | if (!getDerived().AlwaysRebuild() && |
| 3762 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | return SemaRef.Owned(E->Retain()); |
| 3764 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3765 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3766 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3767 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3768 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3769 | E->getAccessorLoc(), |
| 3770 | E->getAccessor()); |
| 3771 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3773 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3774 | Sema::OwningExprResult |
| 3775 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3776 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3778 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3779 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3780 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3781 | if (Init.isInvalid()) |
| 3782 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3783 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3784 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3785 | Inits.push_back(Init.takeAs<Expr>()); |
| 3786 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3788 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3789 | return SemaRef.Owned(E->Retain()); |
| 3790 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3791 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
| 3792 | E->getRBraceLoc()); |
| 3793 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3794 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3795 | template<typename Derived> |
| 3796 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3797 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3798 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3800 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3801 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3802 | if (Init.isInvalid()) |
| 3803 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3804 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3805 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3806 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3807 | bool ExprChanged = false; |
| 3808 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3809 | DEnd = E->designators_end(); |
| 3810 | D != DEnd; ++D) { |
| 3811 | if (D->isFieldDesignator()) { |
| 3812 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3813 | D->getDotLoc(), |
| 3814 | D->getFieldLoc())); |
| 3815 | continue; |
| 3816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | if (D->isArrayDesignator()) { |
| 3819 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3820 | if (Index.isInvalid()) |
| 3821 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3822 | |
| 3823 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3824 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3826 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3827 | ArrayExprs.push_back(Index.release()); |
| 3828 | continue; |
| 3829 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3830 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3831 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3832 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3833 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3834 | if (Start.isInvalid()) |
| 3835 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3838 | if (End.isInvalid()) |
| 3839 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3840 | |
| 3841 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | End.get(), |
| 3843 | D->getLBracketLoc(), |
| 3844 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3845 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3846 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3847 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | ArrayExprs.push_back(Start.release()); |
| 3850 | ArrayExprs.push_back(End.release()); |
| 3851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3853 | if (!getDerived().AlwaysRebuild() && |
| 3854 | Init.get() == E->getInit() && |
| 3855 | !ExprChanged) |
| 3856 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3857 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3859 | E->getEqualOrColonLoc(), |
| 3860 | E->usesGNUSyntax(), move(Init)); |
| 3861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3862 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3864 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3865 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3867 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3868 | |
| 3869 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3870 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3871 | QualType T = getDerived().TransformType(E->getType()); |
| 3872 | if (T.isNull()) |
| 3873 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | if (!getDerived().AlwaysRebuild() && |
| 3876 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | return SemaRef.Owned(E->Retain()); |
| 3878 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3879 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 3880 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3881 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3882 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3884 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| 3885 | // FIXME: Do we want the type as written? |
| 3886 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3888 | { |
| 3889 | // FIXME: Source location isn't quite accurate. |
| 3890 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 3891 | T = getDerived().TransformType(E->getType()); |
| 3892 | if (T.isNull()) |
| 3893 | return SemaRef.ExprError(); |
| 3894 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3896 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3897 | if (SubExpr.isInvalid()) |
| 3898 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | if (!getDerived().AlwaysRebuild() && |
| 3901 | T == E->getType() && |
| 3902 | SubExpr.get() == E->getSubExpr()) |
| 3903 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3904 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3905 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 3906 | T, E->getRParenLoc()); |
| 3907 | } |
| 3908 | |
| 3909 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3910 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3911 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| 3912 | bool ArgumentChanged = false; |
| 3913 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3914 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 3915 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 3916 | if (Init.isInvalid()) |
| 3917 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3919 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 3920 | Inits.push_back(Init.takeAs<Expr>()); |
| 3921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3923 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 3924 | move_arg(Inits), |
| 3925 | E->getRParenLoc()); |
| 3926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3928 | /// \brief Transform an address-of-label expression. |
| 3929 | /// |
| 3930 | /// By default, the transformation of an address-of-label expression always |
| 3931 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 3932 | /// the corresponding label statement by semantic analysis. |
| 3933 | template<typename Derived> |
| 3934 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 3937 | E->getLabel()); |
| 3938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
| 3940 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3941 | Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3943 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 3944 | if (SubStmt.isInvalid()) |
| 3945 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | if (!getDerived().AlwaysRebuild() && |
| 3948 | SubStmt.get() == E->getSubStmt()) |
| 3949 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
| 3951 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | move(SubStmt), |
| 3953 | E->getRParenLoc()); |
| 3954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | template<typename Derived> |
| 3957 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3958 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | QualType T1, T2; |
| 3960 | { |
| 3961 | // FIXME: Source location isn't quite accurate. |
| 3962 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3963 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3964 | T1 = getDerived().TransformType(E->getArgType1()); |
| 3965 | if (T1.isNull()) |
| 3966 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3967 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | T2 = getDerived().TransformType(E->getArgType2()); |
| 3969 | if (T2.isNull()) |
| 3970 | return SemaRef.ExprError(); |
| 3971 | } |
| 3972 | |
| 3973 | if (!getDerived().AlwaysRebuild() && |
| 3974 | T1 == E->getArgType1() && |
| 3975 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | return SemaRef.Owned(E->Retain()); |
| 3977 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3978 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 3979 | T1, T2, E->getRParenLoc()); |
| 3980 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3982 | template<typename Derived> |
| 3983 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3984 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3985 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3986 | if (Cond.isInvalid()) |
| 3987 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3989 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3990 | if (LHS.isInvalid()) |
| 3991 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3993 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3994 | if (RHS.isInvalid()) |
| 3995 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3997 | if (!getDerived().AlwaysRebuild() && |
| 3998 | Cond.get() == E->getCond() && |
| 3999 | LHS.get() == E->getLHS() && |
| 4000 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4001 | return SemaRef.Owned(E->Retain()); |
| 4002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4004 | move(Cond), move(LHS), move(RHS), |
| 4005 | E->getRParenLoc()); |
| 4006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4008 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | Sema::OwningExprResult |
| 4010 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| 4011 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | template<typename Derived> |
| 4015 | Sema::OwningExprResult |
| 4016 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 4017 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4018 | if (Callee.isInvalid()) |
| 4019 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4021 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
| 4022 | if (First.isInvalid()) |
| 4023 | return SemaRef.ExprError(); |
| 4024 | |
| 4025 | OwningExprResult Second(SemaRef); |
| 4026 | if (E->getNumArgs() == 2) { |
| 4027 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4028 | if (Second.isInvalid()) |
| 4029 | return SemaRef.ExprError(); |
| 4030 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4031 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4032 | if (!getDerived().AlwaysRebuild() && |
| 4033 | Callee.get() == E->getCallee() && |
| 4034 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4036 | return SemaRef.Owned(E->Retain()); |
| 4037 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4038 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4039 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4040 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4041 | move(First), |
| 4042 | move(Second)); |
| 4043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4045 | template<typename Derived> |
| 4046 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | return getDerived().TransformCallExpr(E); |
| 4049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4052 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4053 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 4054 | QualType ExplicitTy; |
| 4055 | { |
| 4056 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4057 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4058 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4059 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4060 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4061 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4062 | if (ExplicitTy.isNull()) |
| 4063 | return SemaRef.ExprError(); |
| 4064 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4065 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4066 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4067 | if (SubExpr.isInvalid()) |
| 4068 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | if (!getDerived().AlwaysRebuild() && |
| 4071 | ExplicitTy == E->getTypeAsWritten() && |
| 4072 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | return SemaRef.Owned(E->Retain()); |
| 4074 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4075 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4078 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4079 | SourceLocation FakeRParenLoc |
| 4080 | = SemaRef.PP.getLocForEndOfToken( |
| 4081 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4082 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4083 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4084 | FakeLAngleLoc, |
| 4085 | ExplicitTy, |
| 4086 | FakeRAngleLoc, |
| 4087 | FakeRAngleLoc, |
| 4088 | move(SubExpr), |
| 4089 | FakeRParenLoc); |
| 4090 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4091 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4092 | template<typename Derived> |
| 4093 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4094 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4095 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4096 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | |
| 4098 | template<typename Derived> |
| 4099 | Sema::OwningExprResult |
| 4100 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4101 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4102 | } |
| 4103 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | template<typename Derived> |
| 4105 | Sema::OwningExprResult |
| 4106 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | CXXReinterpretCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4109 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | template<typename Derived> |
| 4112 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4114 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4115 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4117 | template<typename Derived> |
| 4118 | Sema::OwningExprResult |
| 4119 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4121 | QualType ExplicitTy; |
| 4122 | { |
| 4123 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4125 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4126 | if (ExplicitTy.isNull()) |
| 4127 | return SemaRef.ExprError(); |
| 4128 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4131 | if (SubExpr.isInvalid()) |
| 4132 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4134 | if (!getDerived().AlwaysRebuild() && |
| 4135 | ExplicitTy == E->getTypeAsWritten() && |
| 4136 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4137 | return SemaRef.Owned(E->Retain()); |
| 4138 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4139 | // FIXME: The end of the type's source range is wrong |
| 4140 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4141 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4142 | ExplicitTy, |
| 4143 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4144 | move(SubExpr), |
| 4145 | E->getRParenLoc()); |
| 4146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4148 | template<typename Derived> |
| 4149 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4150 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4151 | if (E->isTypeOperand()) { |
| 4152 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4155 | if (T.isNull()) |
| 4156 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4158 | if (!getDerived().AlwaysRebuild() && |
| 4159 | T == E->getTypeOperand()) |
| 4160 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4162 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4163 | /*FIXME:*/E->getLocStart(), |
| 4164 | T, |
| 4165 | E->getLocEnd()); |
| 4166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | // We don't know whether the expression is potentially evaluated until |
| 4169 | // after we perform semantic analysis, so the expression is potentially |
| 4170 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4171 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4174 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4175 | if (SubExpr.isInvalid()) |
| 4176 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | if (!getDerived().AlwaysRebuild() && |
| 4179 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | return SemaRef.Owned(E->Retain()); |
| 4181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4183 | /*FIXME:*/E->getLocStart(), |
| 4184 | move(SubExpr), |
| 4185 | E->getLocEnd()); |
| 4186 | } |
| 4187 | |
| 4188 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | Sema::OwningExprResult |
| 4190 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 4191 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4192 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4193 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4194 | template<typename Derived> |
| 4195 | Sema::OwningExprResult |
| 4196 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | CXXNullPtrLiteralExpr *E) { |
| 4198 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4201 | template<typename Derived> |
| 4202 | Sema::OwningExprResult |
| 4203 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| 4204 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4206 | QualType T = getDerived().TransformType(E->getType()); |
| 4207 | if (T.isNull()) |
| 4208 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | if (!getDerived().AlwaysRebuild() && |
| 4211 | T == E->getType()) |
| 4212 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4215 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4216 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4217 | template<typename Derived> |
| 4218 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4219 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4220 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4221 | if (SubExpr.isInvalid()) |
| 4222 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4223 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4224 | if (!getDerived().AlwaysRebuild() && |
| 4225 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4226 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | |
| 4228 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4230 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4231 | template<typename Derived> |
| 4232 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4233 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 4234 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4235 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4236 | if (!Param) |
| 4237 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4239 | if (getDerived().AlwaysRebuild() && |
| 4240 | Param == E->getParam()) |
| 4241 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4243 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4244 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4245 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | template<typename Derived> |
| 4247 | Sema::OwningExprResult |
| 4248 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
| 4249 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4250 | |
| 4251 | QualType T = getDerived().TransformType(E->getType()); |
| 4252 | if (T.isNull()) |
| 4253 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | if (!getDerived().AlwaysRebuild() && |
| 4256 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4257 | return SemaRef.Owned(E->Retain()); |
| 4258 | |
| 4259 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4260 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4261 | T, |
| 4262 | E->getRParenLoc()); |
| 4263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4264 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4265 | template<typename Derived> |
| 4266 | Sema::OwningExprResult |
| 4267 | TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4268 | VarDecl *Var |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4269 | = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4270 | if (!Var) |
| 4271 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4272 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4273 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4274 | Var == E->getVarDecl()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4275 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4276 | |
| 4277 | return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | /*FIXME:*/E->getStartLoc(), |
| 4279 | Var); |
| 4280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4281 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4282 | template<typename Derived> |
| 4283 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | // Transform the type that we're allocating |
| 4286 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4287 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4288 | if (AllocType.isNull()) |
| 4289 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | // Transform the size of the array we're allocating (if any). |
| 4292 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4293 | if (ArraySize.isInvalid()) |
| 4294 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4295 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | // Transform the placement arguments (if any). |
| 4297 | bool ArgumentChanged = false; |
| 4298 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4299 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4300 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4301 | if (Arg.isInvalid()) |
| 4302 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4304 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4305 | PlacementArgs.push_back(Arg.take()); |
| 4306 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4307 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4308 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4310 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4311 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4312 | if (Arg.isInvalid()) |
| 4313 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4315 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4316 | ConstructorArgs.push_back(Arg.take()); |
| 4317 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4318 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4319 | if (!getDerived().AlwaysRebuild() && |
| 4320 | AllocType == E->getAllocatedType() && |
| 4321 | ArraySize.get() == E->getArraySize() && |
| 4322 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | return SemaRef.Owned(E->Retain()); |
| 4324 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4325 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4326 | E->isGlobalNew(), |
| 4327 | /*FIXME:*/E->getLocStart(), |
| 4328 | move_arg(PlacementArgs), |
| 4329 | /*FIXME:*/E->getLocStart(), |
| 4330 | E->isParenTypeId(), |
| 4331 | AllocType, |
| 4332 | /*FIXME:*/E->getLocStart(), |
| 4333 | /*FIXME:*/SourceRange(), |
| 4334 | move(ArraySize), |
| 4335 | /*FIXME:*/E->getLocStart(), |
| 4336 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4337 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4338 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | template<typename Derived> |
| 4341 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4342 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4343 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4344 | if (Operand.isInvalid()) |
| 4345 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4346 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4347 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | Operand.get() == E->getArgument()) |
| 4349 | return SemaRef.Owned(E->Retain()); |
| 4350 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4352 | E->isGlobalDelete(), |
| 4353 | E->isArrayForm(), |
| 4354 | move(Operand)); |
| 4355 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4356 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4357 | template<typename Derived> |
| 4358 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4359 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| 4360 | CXXPseudoDestructorExpr *E) { |
| 4361 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4362 | if (Base.isInvalid()) |
| 4363 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4365 | NestedNameSpecifier *Qualifier |
| 4366 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4367 | E->getQualifierRange()); |
| 4368 | if (E->getQualifier() && !Qualifier) |
| 4369 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4371 | QualType DestroyedType; |
| 4372 | { |
| 4373 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4374 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4375 | if (DestroyedType.isNull()) |
| 4376 | return SemaRef.ExprError(); |
| 4377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4379 | if (!getDerived().AlwaysRebuild() && |
| 4380 | Base.get() == E->getBase() && |
| 4381 | Qualifier == E->getQualifier() && |
| 4382 | DestroyedType == E->getDestroyedType()) |
| 4383 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4384 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4385 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4386 | E->getOperatorLoc(), |
| 4387 | E->isArrow(), |
| 4388 | E->getDestroyedTypeLoc(), |
| 4389 | DestroyedType, |
| 4390 | Qualifier, |
| 4391 | E->getQualifierRange()); |
| 4392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4394 | template<typename Derived> |
| 4395 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4396 | TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | UnresolvedFunctionNameExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | // There is no transformation we can apply to an unresolved function name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | template<typename Derived> |
| 4403 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4406 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4407 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4408 | if (T.isNull()) |
| 4409 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4410 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | if (!getDerived().AlwaysRebuild() && |
| 4412 | T == E->getQueriedType()) |
| 4413 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4414 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4415 | // FIXME: Bad location information |
| 4416 | SourceLocation FakeLParenLoc |
| 4417 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
| 4419 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4420 | E->getLocStart(), |
| 4421 | /*FIXME:*/FakeLParenLoc, |
| 4422 | T, |
| 4423 | E->getLocEnd()); |
| 4424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4425 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4426 | template<typename Derived> |
| 4427 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4428 | TreeTransform<Derived>::TransformUnresolvedDeclRefExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4429 | UnresolvedDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4430 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4431 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4432 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4433 | if (!NNS) |
| 4434 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4435 | |
| 4436 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4437 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4438 | if (!Name) |
| 4439 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4440 | |
| 4441 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | NNS == E->getQualifier() && |
| 4443 | Name == E->getDeclName()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4444 | return SemaRef.Owned(E->Retain()); |
| 4445 | |
| 4446 | return getDerived().RebuildUnresolvedDeclRefExpr(NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | E->getQualifierRange(), |
| 4448 | Name, |
| 4449 | E->getLocation(), |
| 4450 | /*FIXME:*/false); |
| 4451 | } |
| 4452 | |
| 4453 | template<typename Derived> |
| 4454 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4455 | TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { |
Douglas Gregor | ba91b89 | 2009-10-29 17:56:10 +0000 | [diff] [blame^] | 4456 | TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName()); |
| 4457 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | TemplateName Template |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | = getDerived().TransformTemplateName(E->getTemplateName()); |
| 4460 | if (Template.isNull()) |
| 4461 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4462 | |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4463 | NestedNameSpecifier *Qualifier = 0; |
| 4464 | if (E->getQualifier()) { |
| 4465 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4466 | E->getQualifierRange()); |
| 4467 | if (!Qualifier) |
| 4468 | return SemaRef.ExprError(); |
| 4469 | } |
| 4470 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4471 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4472 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4473 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4474 | TransArgs[I])) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | return SemaRef.ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | // FIXME: Would like to avoid rebuilding if nothing changed, but we can't |
| 4479 | // compare template arguments (yet). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | |
| 4481 | // FIXME: It's possible that we'll find out now that the template name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | // actually refers to a type, in which case the caller is actually dealing |
| 4483 | // with a functional cast. Give a reasonable error message! |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4484 | return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(), |
| 4485 | Template, E->getTemplateNameLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | E->getLAngleLoc(), |
| 4487 | TransArgs.data(), |
| 4488 | TransArgs.size(), |
| 4489 | E->getRAngleLoc()); |
| 4490 | } |
| 4491 | |
| 4492 | template<typename Derived> |
| 4493 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4495 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4496 | |
| 4497 | QualType T = getDerived().TransformType(E->getType()); |
| 4498 | if (T.isNull()) |
| 4499 | return SemaRef.ExprError(); |
| 4500 | |
| 4501 | CXXConstructorDecl *Constructor |
| 4502 | = cast_or_null<CXXConstructorDecl>( |
| 4503 | getDerived().TransformDecl(E->getConstructor())); |
| 4504 | if (!Constructor) |
| 4505 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | bool ArgumentChanged = false; |
| 4508 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4509 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4510 | ArgEnd = E->arg_end(); |
| 4511 | Arg != ArgEnd; ++Arg) { |
| 4512 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4513 | if (TransArg.isInvalid()) |
| 4514 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4516 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4517 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4518 | } |
| 4519 | |
| 4520 | if (!getDerived().AlwaysRebuild() && |
| 4521 | T == E->getType() && |
| 4522 | Constructor == E->getConstructor() && |
| 4523 | !ArgumentChanged) |
| 4524 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4527 | move_arg(Args)); |
| 4528 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4529 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4530 | /// \brief Transform a C++ temporary-binding expression. |
| 4531 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | /// The transformation of a temporary-binding expression always attempts to |
| 4533 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4534 | /// subexpression itself did not change, because the temporary variable itself |
| 4535 | /// must be unique. |
| 4536 | template<typename Derived> |
| 4537 | Sema::OwningExprResult |
| 4538 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 4539 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4540 | if (SubExpr.isInvalid()) |
| 4541 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4543 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | |
| 4546 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4547 | /// be destroyed after the expression is evaluated. |
| 4548 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4549 | /// The transformation of a full expression always attempts to build a new |
| 4550 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4551 | /// subexpression itself did not change, because it will need to capture the |
| 4552 | /// the new temporary variables introduced in the subexpression. |
| 4553 | template<typename Derived> |
| 4554 | Sema::OwningExprResult |
| 4555 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4556 | CXXExprWithTemporaries *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4557 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4558 | if (SubExpr.isInvalid()) |
| 4559 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4561 | return SemaRef.Owned( |
| 4562 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4563 | E->shouldDestroyTemporaries())); |
| 4564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4565 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4566 | template<typename Derived> |
| 4567 | Sema::OwningExprResult |
| 4568 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4571 | QualType T = getDerived().TransformType(E->getType()); |
| 4572 | if (T.isNull()) |
| 4573 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4574 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | CXXConstructorDecl *Constructor |
| 4576 | = cast_or_null<CXXConstructorDecl>( |
| 4577 | getDerived().TransformDecl(E->getConstructor())); |
| 4578 | if (!Constructor) |
| 4579 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4581 | bool ArgumentChanged = false; |
| 4582 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4583 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | ArgEnd = E->arg_end(); |
| 4586 | Arg != ArgEnd; ++Arg) { |
| 4587 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4588 | if (TransArg.isInvalid()) |
| 4589 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4590 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4591 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4592 | Args.push_back((Expr *)TransArg.release()); |
| 4593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4594 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4595 | if (!getDerived().AlwaysRebuild() && |
| 4596 | T == E->getType() && |
| 4597 | Constructor == E->getConstructor() && |
| 4598 | !ArgumentChanged) |
| 4599 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4600 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | // FIXME: Bogus location information |
| 4602 | SourceLocation CommaLoc; |
| 4603 | if (Args.size() > 1) { |
| 4604 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4605 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4606 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4607 | } |
| 4608 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4609 | T, |
| 4610 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4611 | move_arg(Args), |
| 4612 | &CommaLoc, |
| 4613 | E->getLocEnd()); |
| 4614 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4615 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4616 | template<typename Derived> |
| 4617 | Sema::OwningExprResult |
| 4618 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4619 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4620 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4621 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4622 | if (T.isNull()) |
| 4623 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4624 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | bool ArgumentChanged = false; |
| 4626 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4627 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4628 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4629 | ArgEnd = E->arg_end(); |
| 4630 | Arg != ArgEnd; ++Arg) { |
| 4631 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4632 | if (TransArg.isInvalid()) |
| 4633 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4635 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4636 | FakeCommaLocs.push_back( |
| 4637 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4638 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4639 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | if (!getDerived().AlwaysRebuild() && |
| 4642 | T == E->getTypeAsWritten() && |
| 4643 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | return SemaRef.Owned(E->Retain()); |
| 4645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | // FIXME: we're faking the locations of the commas |
| 4647 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4648 | T, |
| 4649 | E->getLParenLoc(), |
| 4650 | move_arg(Args), |
| 4651 | FakeCommaLocs.data(), |
| 4652 | E->getRParenLoc()); |
| 4653 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4654 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | template<typename Derived> |
| 4656 | Sema::OwningExprResult |
| 4657 | TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4658 | CXXUnresolvedMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4659 | // Transform the base of the expression. |
| 4660 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4661 | if (Base.isInvalid()) |
| 4662 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4663 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4664 | // Start the member reference and compute the object's type. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4665 | Sema::TypeTy *ObjectType = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4666 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4667 | E->getOperatorLoc(), |
| 4668 | E->isArrow()? tok::arrow : tok::period, |
| 4669 | ObjectType); |
| 4670 | if (Base.isInvalid()) |
| 4671 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4673 | // Transform the first part of the nested-name-specifier that qualifies |
| 4674 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4675 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4676 | = getDerived().TransformFirstQualifierInScope( |
| 4677 | E->getFirstQualifierFoundInScope(), |
| 4678 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4680 | NestedNameSpecifier *Qualifier = 0; |
| 4681 | if (E->getQualifier()) { |
| 4682 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4683 | E->getQualifierRange(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4684 | QualType::getFromOpaquePtr(ObjectType), |
| 4685 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4686 | if (!Qualifier) |
| 4687 | return SemaRef.ExprError(); |
| 4688 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4689 | |
| 4690 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4691 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
| 4692 | QualType::getFromOpaquePtr(ObjectType)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4693 | if (!Name) |
| 4694 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4696 | if (!E->hasExplicitTemplateArgumentList()) { |
| 4697 | // This is a reference to a member without an explicitly-specified |
| 4698 | // template argument list. Optimize for this common case. |
| 4699 | if (!getDerived().AlwaysRebuild() && |
| 4700 | Base.get() == E->getBase() && |
| 4701 | Qualifier == E->getQualifier() && |
| 4702 | Name == E->getMember() && |
| 4703 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4704 | return SemaRef.Owned(E->Retain()); |
| 4705 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4706 | return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), |
| 4707 | E->isArrow(), |
| 4708 | E->getOperatorLoc(), |
| 4709 | Qualifier, |
| 4710 | E->getQualifierRange(), |
| 4711 | Name, |
| 4712 | E->getMemberLoc(), |
| 4713 | FirstQualifierInScope); |
| 4714 | } |
| 4715 | |
| 4716 | // FIXME: This is an ugly hack, which forces the same template name to |
| 4717 | // be looked up multiple times. Yuck! |
| 4718 | // FIXME: This also won't work for, e.g., x->template operator+<int> |
| 4719 | TemplateName OrigTemplateName |
| 4720 | = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | |
| 4722 | TemplateName Template |
| 4723 | = getDerived().TransformTemplateName(OrigTemplateName, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4724 | QualType::getFromOpaquePtr(ObjectType)); |
| 4725 | if (Template.isNull()) |
| 4726 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4727 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4728 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4729 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4730 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4731 | TransArgs[I])) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4732 | return SemaRef.ExprError(); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4733 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4734 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4735 | return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), |
| 4736 | E->isArrow(), |
| 4737 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4738 | Qualifier, |
| 4739 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4740 | Template, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4741 | E->getMemberLoc(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4742 | FirstQualifierInScope, |
| 4743 | E->getLAngleLoc(), |
| 4744 | TransArgs.data(), |
| 4745 | TransArgs.size(), |
| 4746 | E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | template<typename Derived> |
| 4750 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| 4752 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4755 | template<typename Derived> |
| 4756 | Sema::OwningExprResult |
| 4757 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4758 | // FIXME: poor source location |
| 4759 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 4760 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 4761 | if (EncodedType.isNull()) |
| 4762 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4764 | if (!getDerived().AlwaysRebuild() && |
| 4765 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4766 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4767 | |
| 4768 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 4769 | EncodedType, |
| 4770 | E->getRParenLoc()); |
| 4771 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4773 | template<typename Derived> |
| 4774 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4775 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | // FIXME: Implement this! |
| 4777 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4778 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | } |
| 4780 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4781 | template<typename Derived> |
| 4782 | Sema::OwningExprResult |
| 4783 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 4784 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4787 | template<typename Derived> |
| 4788 | Sema::OwningExprResult |
| 4789 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 4790 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | = cast_or_null<ObjCProtocolDecl>( |
| 4792 | getDerived().TransformDecl(E->getProtocol())); |
| 4793 | if (!Protocol) |
| 4794 | return SemaRef.ExprError(); |
| 4795 | |
| 4796 | if (!getDerived().AlwaysRebuild() && |
| 4797 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4798 | return SemaRef.Owned(E->Retain()); |
| 4799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 4801 | E->getAtLoc(), |
| 4802 | /*FIXME:*/E->getAtLoc(), |
| 4803 | /*FIXME:*/E->getAtLoc(), |
| 4804 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4805 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4808 | template<typename Derived> |
| 4809 | Sema::OwningExprResult |
| 4810 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4811 | // FIXME: Implement this! |
| 4812 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4813 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4814 | } |
| 4815 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 | template<typename Derived> |
| 4817 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4818 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 4819 | // FIXME: Implement this! |
| 4820 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | template<typename Derived> |
| 4825 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 4826 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4827 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4828 | // FIXME: Implement this! |
| 4829 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4830 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4833 | template<typename Derived> |
| 4834 | Sema::OwningExprResult |
| 4835 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4836 | // FIXME: Implement this! |
| 4837 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4838 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | template<typename Derived> |
| 4842 | Sema::OwningExprResult |
| 4843 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4844 | // FIXME: Implement this! |
| 4845 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4846 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4849 | template<typename Derived> |
| 4850 | Sema::OwningExprResult |
| 4851 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4852 | bool ArgumentChanged = false; |
| 4853 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 4854 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 4855 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 4856 | if (SubExpr.isInvalid()) |
| 4857 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4858 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4859 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 4860 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 4861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4862 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4863 | if (!getDerived().AlwaysRebuild() && |
| 4864 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | return SemaRef.Owned(E->Retain()); |
| 4866 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4867 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 4868 | move_arg(SubExprs), |
| 4869 | E->getRParenLoc()); |
| 4870 | } |
| 4871 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4872 | template<typename Derived> |
| 4873 | Sema::OwningExprResult |
| 4874 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4875 | // FIXME: Implement this! |
| 4876 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4877 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4878 | } |
| 4879 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | template<typename Derived> |
| 4881 | Sema::OwningExprResult |
| 4882 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | // FIXME: Implement this! |
| 4884 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4885 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4886 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4887 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4888 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4889 | // Type reconstruction |
| 4890 | //===----------------------------------------------------------------------===// |
| 4891 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4892 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4893 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4894 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4895 | getDerived().getBaseLocation(), |
| 4896 | getDerived().getBaseEntity()); |
| 4897 | } |
| 4898 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4900 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4901 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4902 | getDerived().getBaseLocation(), |
| 4903 | getDerived().getBaseEntity()); |
| 4904 | } |
| 4905 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4906 | template<typename Derived> |
| 4907 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4908 | TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4909 | return SemaRef.BuildReferenceType(ReferentType, true, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4910 | getDerived().getBaseLocation(), |
| 4911 | getDerived().getBaseEntity()); |
| 4912 | } |
| 4913 | |
| 4914 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | QualType |
| 4916 | TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4917 | return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4918 | getDerived().getBaseLocation(), |
| 4919 | getDerived().getBaseEntity()); |
| 4920 | } |
| 4921 | |
| 4922 | template<typename Derived> |
| 4923 | QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4924 | QualType ClassType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4925 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4926 | getDerived().getBaseLocation(), |
| 4927 | getDerived().getBaseEntity()); |
| 4928 | } |
| 4929 | |
| 4930 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4932 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType) { |
| 4933 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), |
| 4934 | getDerived().getBaseLocation(), |
| 4935 | getDerived().getBaseEntity()); |
| 4936 | } |
| 4937 | |
| 4938 | template<typename Derived> |
| 4939 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4940 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 4941 | ArrayType::ArraySizeModifier SizeMod, |
| 4942 | const llvm::APInt *Size, |
| 4943 | Expr *SizeExpr, |
| 4944 | unsigned IndexTypeQuals, |
| 4945 | SourceRange BracketsRange) { |
| 4946 | if (SizeExpr || !Size) |
| 4947 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 4948 | IndexTypeQuals, BracketsRange, |
| 4949 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | |
| 4951 | QualType Types[] = { |
| 4952 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 4953 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 4954 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4955 | }; |
| 4956 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 4957 | QualType SizeType; |
| 4958 | for (unsigned I = 0; I != NumTypes; ++I) |
| 4959 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 4960 | SizeType = Types[I]; |
| 4961 | break; |
| 4962 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4964 | if (SizeType.isNull()) |
| 4965 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4967 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4969 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4970 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4972 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4973 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | QualType |
| 4975 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4976 | ArrayType::ArraySizeModifier SizeMod, |
| 4977 | const llvm::APInt &Size, |
| 4978 | unsigned IndexTypeQuals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4980 | IndexTypeQuals, SourceRange()); |
| 4981 | } |
| 4982 | |
| 4983 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4984 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4985 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4986 | ArrayType::ArraySizeModifier SizeMod, |
| 4987 | unsigned IndexTypeQuals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4989 | IndexTypeQuals, SourceRange()); |
| 4990 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4991 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4992 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4993 | QualType |
| 4994 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4995 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4997 | unsigned IndexTypeQuals, |
| 4998 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4999 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5000 | SizeExpr.takeAs<Expr>(), |
| 5001 | IndexTypeQuals, BracketsRange); |
| 5002 | } |
| 5003 | |
| 5004 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5005 | QualType |
| 5006 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5007 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5008 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5009 | unsigned IndexTypeQuals, |
| 5010 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5012 | SizeExpr.takeAs<Expr>(), |
| 5013 | IndexTypeQuals, BracketsRange); |
| 5014 | } |
| 5015 | |
| 5016 | template<typename Derived> |
| 5017 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5018 | unsigned NumElements) { |
| 5019 | // FIXME: semantic checking! |
| 5020 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5021 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5022 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5023 | template<typename Derived> |
| 5024 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5025 | unsigned NumElements, |
| 5026 | SourceLocation AttributeLoc) { |
| 5027 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5028 | NumElements, true); |
| 5029 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5030 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5031 | AttributeLoc); |
| 5032 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5033 | AttributeLoc); |
| 5034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5036 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5037 | QualType |
| 5038 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5039 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5040 | SourceLocation AttributeLoc) { |
| 5041 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5042 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5044 | template<typename Derived> |
| 5045 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5047 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5049 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5051 | Quals, |
| 5052 | getDerived().getBaseLocation(), |
| 5053 | getDerived().getBaseEntity()); |
| 5054 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5056 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5057 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5058 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5059 | } |
| 5060 | |
| 5061 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5062 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5063 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5064 | } |
| 5065 | |
| 5066 | template<typename Derived> |
| 5067 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5068 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5069 | } |
| 5070 | |
| 5071 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5072 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5073 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5074 | } |
| 5075 | |
| 5076 | template<typename Derived> |
| 5077 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5078 | TemplateName Template, |
| 5079 | SourceLocation TemplateNameLoc, |
| 5080 | SourceLocation LAngleLoc, |
| 5081 | const TemplateArgumentLoc *Args, |
| 5082 | unsigned NumArgs, |
| 5083 | SourceLocation RAngleLoc) { |
| 5084 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, LAngleLoc, |
| 5085 | Args, NumArgs, RAngleLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5086 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5088 | template<typename Derived> |
| 5089 | NestedNameSpecifier * |
| 5090 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5091 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5092 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5093 | QualType ObjectType, |
| 5094 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5095 | CXXScopeSpec SS; |
| 5096 | // FIXME: The source location information is all wrong. |
| 5097 | SS.setRange(Range); |
| 5098 | SS.setScopeRep(Prefix); |
| 5099 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5100 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5101 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5102 | ObjectType, |
| 5103 | FirstQualifierInScope, |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5104 | false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | template<typename Derived> |
| 5108 | NestedNameSpecifier * |
| 5109 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5110 | SourceRange Range, |
| 5111 | NamespaceDecl *NS) { |
| 5112 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5113 | } |
| 5114 | |
| 5115 | template<typename Derived> |
| 5116 | NestedNameSpecifier * |
| 5117 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5118 | SourceRange Range, |
| 5119 | bool TemplateKW, |
| 5120 | QualType T) { |
| 5121 | if (T->isDependentType() || T->isRecordType() || |
| 5122 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5123 | assert(!T.hasQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5124 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5125 | T.getTypePtr()); |
| 5126 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5127 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5128 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5129 | return 0; |
| 5130 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5131 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5132 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5133 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5134 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5135 | bool TemplateKW, |
| 5136 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5137 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5138 | Template); |
| 5139 | } |
| 5140 | |
| 5141 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5142 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5143 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5144 | bool TemplateKW, |
| 5145 | OverloadedFunctionDecl *Ovl) { |
| 5146 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl); |
| 5147 | } |
| 5148 | |
| 5149 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5150 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5151 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5152 | const IdentifierInfo &II, |
| 5153 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5154 | CXXScopeSpec SS; |
| 5155 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5156 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5157 | return getSema().ActOnDependentTemplateName( |
| 5158 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5159 | II, |
| 5160 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5161 | SS, |
| 5162 | ObjectType.getAsOpaquePtr()) |
| 5163 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5164 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5165 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5166 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5167 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5168 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5169 | SourceLocation OpLoc, |
| 5170 | ExprArg Callee, |
| 5171 | ExprArg First, |
| 5172 | ExprArg Second) { |
| 5173 | Expr *FirstExpr = (Expr *)First.get(); |
| 5174 | Expr *SecondExpr = (Expr *)Second.get(); |
| 5175 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5177 | // Determine whether this should be a builtin operation. |
| 5178 | if (SecondExpr == 0 || isPostIncDec) { |
| 5179 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5180 | // The argument is not of overloadable type, so try to create a |
| 5181 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5182 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5183 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5185 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5186 | } |
| 5187 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5188 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5189 | !SecondExpr->getType()->isOverloadableType()) { |
| 5190 | // Neither of the arguments is an overloadable type, so try to |
| 5191 | // create a built-in binary operation. |
| 5192 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5194 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5195 | if (Result.isInvalid()) |
| 5196 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5198 | First.release(); |
| 5199 | Second.release(); |
| 5200 | return move(Result); |
| 5201 | } |
| 5202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5203 | |
| 5204 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5205 | // used during overload resolution. |
| 5206 | Sema::FunctionSet Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5207 | |
| 5208 | DeclRefExpr *DRE |
Douglas Gregor | 32e2c84 | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 5209 | = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5211 | // FIXME: Do we have to check |
| 5212 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
Douglas Gregor | 32e2c84 | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 5213 | for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5214 | Functions.insert(*F); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5215 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5216 | // Add any functions found via argument-dependent lookup. |
| 5217 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5218 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5219 | DeclarationName OpName |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5220 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | c057f42 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5221 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5222 | Functions); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5224 | // Create the overloaded operator invocation for unary operators. |
| 5225 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5226 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5228 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5232 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5233 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5235 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5236 | if (Result.isInvalid()) |
| 5237 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5239 | First.release(); |
| 5240 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5241 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5242 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5244 | } // end namespace clang |
| 5245 | |
| 5246 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |