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: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1922 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 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 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1959 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1960 | if (SourceExpr) { |
| 1961 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1962 | Action::Unevaluated); |
| 1963 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1964 | if (E.isInvalid()) |
| 1965 | SourceExpr = NULL; |
| 1966 | else { |
| 1967 | SourceExpr = E.takeAs<Expr>(); |
| 1968 | SourceExpr->Retain(); |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1973 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1974 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1975 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1976 | case TemplateArgument::Expression: { |
| 1977 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1978 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1979 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1980 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1981 | Expr *InputExpr = Input.getSourceExpression(); |
| 1982 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1983 | |
| 1984 | Sema::OwningExprResult E |
| 1985 | = getDerived().TransformExpr(InputExpr); |
| 1986 | if (E.isInvalid()) return true; |
| 1987 | |
| 1988 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1989 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1990 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1991 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1992 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1993 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1994 | case TemplateArgument::Pack: { |
| 1995 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1996 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1997 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1998 | AEnd = Arg.pack_end(); |
| 1999 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2000 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2001 | // FIXME: preserve source information here when we start |
| 2002 | // caring about parameter packs. |
| 2003 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2004 | TemplateArgumentLoc InputArg; |
| 2005 | TemplateArgumentLoc OutputArg; |
| 2006 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2007 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2008 | return true; |
| 2009 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2010 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2011 | } |
| 2012 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2013 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2014 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2015 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2016 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2017 | } |
| 2018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2020 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2021 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2024 | //===----------------------------------------------------------------------===// |
| 2025 | // Type transformation |
| 2026 | //===----------------------------------------------------------------------===// |
| 2027 | |
| 2028 | template<typename Derived> |
| 2029 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2030 | if (getDerived().AlreadyTransformed(T)) |
| 2031 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2032 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2033 | // Temporary workaround. All of these transformations should |
| 2034 | // eventually turn into transformations on TypeLocs. |
| 2035 | DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2036 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2037 | |
| 2038 | DeclaratorInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2039 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2040 | if (!NewDI) |
| 2041 | return QualType(); |
| 2042 | |
| 2043 | return NewDI->getType(); |
| 2044 | } |
| 2045 | |
| 2046 | template<typename Derived> |
| 2047 | DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) { |
| 2048 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2049 | return DI; |
| 2050 | |
| 2051 | TypeLocBuilder TLB; |
| 2052 | |
| 2053 | TypeLoc TL = DI->getTypeLoc(); |
| 2054 | TLB.reserve(TL.getFullDataSize()); |
| 2055 | |
| 2056 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2057 | if (Result.isNull()) |
| 2058 | return 0; |
| 2059 | |
| 2060 | return TLB.getDeclaratorInfo(SemaRef.Context, Result); |
| 2061 | } |
| 2062 | |
| 2063 | template<typename Derived> |
| 2064 | QualType |
| 2065 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2066 | switch (T.getTypeLocClass()) { |
| 2067 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2068 | #define TYPELOC(CLASS, PARENT) \ |
| 2069 | case TypeLoc::CLASS: \ |
| 2070 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2071 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2074 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2075 | return QualType(); |
| 2076 | } |
| 2077 | |
| 2078 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2079 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2080 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2081 | /// types). This is the right thing for template instantiation, but |
| 2082 | /// probably not for other clients. |
| 2083 | template<typename Derived> |
| 2084 | QualType |
| 2085 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2086 | QualifiedTypeLoc T) { |
| 2087 | Qualifiers Quals = T.getType().getQualifiers(); |
| 2088 | |
| 2089 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2090 | if (Result.isNull()) |
| 2091 | return QualType(); |
| 2092 | |
| 2093 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2094 | // FIXME: this is the right thing for template instantiation, but |
| 2095 | // probably not for other clients. |
| 2096 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2097 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2098 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2099 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2100 | |
| 2101 | TLB.push<QualifiedTypeLoc>(Result); |
| 2102 | |
| 2103 | // No location information to preserve. |
| 2104 | |
| 2105 | return Result; |
| 2106 | } |
| 2107 | |
| 2108 | template <class TyLoc> static inline |
| 2109 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2110 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2111 | NewT.setNameLoc(T.getNameLoc()); |
| 2112 | return T.getType(); |
| 2113 | } |
| 2114 | |
| 2115 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2116 | // the equivalent template version work. |
| 2117 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2118 | QualType PointeeType \ |
| 2119 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2120 | if (PointeeType.isNull()) \ |
| 2121 | return QualType(); \ |
| 2122 | \ |
| 2123 | QualType Result = TL.getType(); \ |
| 2124 | if (getDerived().AlwaysRebuild() || \ |
| 2125 | PointeeType != TL.getPointeeLoc().getType()) { \ |
| 2126 | Result = getDerived().Rebuild##TypeClass(PointeeType); \ |
| 2127 | if (Result.isNull()) \ |
| 2128 | return QualType(); \ |
| 2129 | } \ |
| 2130 | \ |
| 2131 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2132 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2133 | \ |
| 2134 | return Result; \ |
| 2135 | } while(0) |
| 2136 | |
| 2137 | // Reference collapsing forces us to transform reference types |
| 2138 | // differently from the other pointer-like types. |
| 2139 | #define TransformReferenceType(TypeClass) do { \ |
| 2140 | QualType PointeeType \ |
| 2141 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2142 | if (PointeeType.isNull()) \ |
| 2143 | return QualType(); \ |
| 2144 | \ |
| 2145 | QualType Result = TL.getType(); \ |
| 2146 | if (getDerived().AlwaysRebuild() || \ |
| 2147 | PointeeType != TL.getPointeeLoc().getType()) { \ |
| 2148 | Result = getDerived().Rebuild##TypeClass(PointeeType); \ |
| 2149 | if (Result.isNull()) \ |
| 2150 | return QualType(); \ |
| 2151 | } \ |
| 2152 | \ |
| 2153 | /* Workaround: rebuild doesn't always change the type */ \ |
| 2154 | /* FIXME: avoid losing this location information. */ \ |
| 2155 | if (Result == PointeeType) \ |
| 2156 | return Result; \ |
| 2157 | ReferenceTypeLoc NewTL; \ |
| 2158 | if (isa<LValueReferenceType>(Result)) \ |
| 2159 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); \ |
| 2160 | else \ |
| 2161 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); \ |
| 2162 | NewTL.setSigilLoc(TL.getSigilLoc()); \ |
| 2163 | return Result; \ |
| 2164 | } while (0) |
| 2165 | |
| 2166 | template<typename Derived> |
| 2167 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2168 | BuiltinTypeLoc T) { |
| 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> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2173 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2174 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2175 | FixedWidthIntTypeLoc T) { |
| 2176 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2177 | } |
Argyrios Kyrtzidis | e918926 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2178 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2179 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2180 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2181 | ComplexTypeLoc T) { |
| 2182 | // FIXME: recurse? |
| 2183 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2184 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2185 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2186 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2187 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2188 | PointerTypeLoc TL) { |
| 2189 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2190 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2191 | |
| 2192 | template<typename Derived> |
| 2193 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2194 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2195 | BlockPointerTypeLoc TL) { |
| 2196 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2199 | template<typename Derived> |
| 2200 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2201 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2202 | LValueReferenceTypeLoc TL) { |
| 2203 | TransformReferenceType(LValueReferenceType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | template<typename Derived> |
| 2207 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2209 | RValueReferenceTypeLoc TL) { |
| 2210 | TransformReferenceType(RValueReferenceType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2211 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2213 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2214 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2215 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2216 | MemberPointerTypeLoc TL) { |
| 2217 | MemberPointerType *T = TL.getTypePtr(); |
| 2218 | |
| 2219 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2220 | if (PointeeType.isNull()) |
| 2221 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2223 | // TODO: preserve source information for this. |
| 2224 | QualType ClassType |
| 2225 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2226 | if (ClassType.isNull()) |
| 2227 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2228 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2229 | QualType Result = TL.getType(); |
| 2230 | if (getDerived().AlwaysRebuild() || |
| 2231 | PointeeType != T->getPointeeType() || |
| 2232 | ClassType != QualType(T->getClass(), 0)) { |
| 2233 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType); |
| 2234 | if (Result.isNull()) |
| 2235 | return QualType(); |
| 2236 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2237 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2238 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2239 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2240 | |
| 2241 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2244 | template<typename Derived> |
| 2245 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2246 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2247 | ConstantArrayTypeLoc TL) { |
| 2248 | ConstantArrayType *T = TL.getTypePtr(); |
| 2249 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | if (ElementType.isNull()) |
| 2251 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2253 | QualType Result = TL.getType(); |
| 2254 | if (getDerived().AlwaysRebuild() || |
| 2255 | ElementType != T->getElementType()) { |
| 2256 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2257 | T->getSizeModifier(), |
| 2258 | T->getSize(), |
| 2259 | T->getIndexTypeCVRQualifiers()); |
| 2260 | if (Result.isNull()) |
| 2261 | return QualType(); |
| 2262 | } |
| 2263 | |
| 2264 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2265 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2266 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2267 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2268 | Expr *Size = TL.getSizeExpr(); |
| 2269 | if (Size) { |
| 2270 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2271 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2272 | } |
| 2273 | NewTL.setSizeExpr(Size); |
| 2274 | |
| 2275 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2277 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2278 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2279 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2280 | TypeLocBuilder &TLB, |
| 2281 | IncompleteArrayTypeLoc TL) { |
| 2282 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2283 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2284 | if (ElementType.isNull()) |
| 2285 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2287 | QualType Result = TL.getType(); |
| 2288 | if (getDerived().AlwaysRebuild() || |
| 2289 | ElementType != T->getElementType()) { |
| 2290 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2291 | T->getSizeModifier(), |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2292 | T->getIndexTypeCVRQualifiers()); |
| 2293 | if (Result.isNull()) |
| 2294 | return QualType(); |
| 2295 | } |
| 2296 | |
| 2297 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2298 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2299 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2300 | NewTL.setSizeExpr(0); |
| 2301 | |
| 2302 | return Result; |
| 2303 | } |
| 2304 | |
| 2305 | template<typename Derived> |
| 2306 | QualType |
| 2307 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2308 | VariableArrayTypeLoc TL) { |
| 2309 | VariableArrayType *T = TL.getTypePtr(); |
| 2310 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2311 | if (ElementType.isNull()) |
| 2312 | return QualType(); |
| 2313 | |
| 2314 | // Array bounds are not potentially evaluated contexts |
| 2315 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2316 | |
| 2317 | Sema::OwningExprResult SizeResult |
| 2318 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2319 | if (SizeResult.isInvalid()) |
| 2320 | return QualType(); |
| 2321 | |
| 2322 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2323 | |
| 2324 | QualType Result = TL.getType(); |
| 2325 | if (getDerived().AlwaysRebuild() || |
| 2326 | ElementType != T->getElementType() || |
| 2327 | Size != T->getSizeExpr()) { |
| 2328 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2329 | T->getSizeModifier(), |
| 2330 | move(SizeResult), |
| 2331 | T->getIndexTypeCVRQualifiers(), |
| 2332 | T->getBracketsRange()); |
| 2333 | if (Result.isNull()) |
| 2334 | return QualType(); |
| 2335 | } |
| 2336 | else SizeResult.take(); |
| 2337 | |
| 2338 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2339 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2340 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2341 | NewTL.setSizeExpr(Size); |
| 2342 | |
| 2343 | return Result; |
| 2344 | } |
| 2345 | |
| 2346 | template<typename Derived> |
| 2347 | QualType |
| 2348 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2349 | DependentSizedArrayTypeLoc TL) { |
| 2350 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2351 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2352 | if (ElementType.isNull()) |
| 2353 | return QualType(); |
| 2354 | |
| 2355 | // Array bounds are not potentially evaluated contexts |
| 2356 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2357 | |
| 2358 | Sema::OwningExprResult SizeResult |
| 2359 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2360 | if (SizeResult.isInvalid()) |
| 2361 | return QualType(); |
| 2362 | |
| 2363 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2364 | |
| 2365 | QualType Result = TL.getType(); |
| 2366 | if (getDerived().AlwaysRebuild() || |
| 2367 | ElementType != T->getElementType() || |
| 2368 | Size != T->getSizeExpr()) { |
| 2369 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2370 | T->getSizeModifier(), |
| 2371 | move(SizeResult), |
| 2372 | T->getIndexTypeCVRQualifiers(), |
| 2373 | T->getBracketsRange()); |
| 2374 | if (Result.isNull()) |
| 2375 | return QualType(); |
| 2376 | } |
| 2377 | else SizeResult.take(); |
| 2378 | |
| 2379 | // We might have any sort of array type now, but fortunately they |
| 2380 | // all have the same location layout. |
| 2381 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2382 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2383 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2384 | NewTL.setSizeExpr(Size); |
| 2385 | |
| 2386 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2388 | |
| 2389 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2390 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2391 | TypeLocBuilder &TLB, |
| 2392 | DependentSizedExtVectorTypeLoc TL) { |
| 2393 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2394 | |
| 2395 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2396 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2397 | if (ElementType.isNull()) |
| 2398 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2399 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2400 | // Vector sizes are not potentially evaluated contexts |
| 2401 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2402 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2403 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2404 | if (Size.isInvalid()) |
| 2405 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2406 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2407 | QualType Result = TL.getType(); |
| 2408 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2409 | ElementType != T->getElementType() || |
| 2410 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2411 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2412 | move(Size), |
| 2413 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2414 | if (Result.isNull()) |
| 2415 | return QualType(); |
| 2416 | } |
| 2417 | else Size.take(); |
| 2418 | |
| 2419 | // Result might be dependent or not. |
| 2420 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2421 | DependentSizedExtVectorTypeLoc NewTL |
| 2422 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2423 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2424 | } else { |
| 2425 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2426 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2427 | } |
| 2428 | |
| 2429 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2431 | |
| 2432 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2433 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2434 | VectorTypeLoc TL) { |
| 2435 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2436 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2437 | if (ElementType.isNull()) |
| 2438 | return QualType(); |
| 2439 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2440 | QualType Result = TL.getType(); |
| 2441 | if (getDerived().AlwaysRebuild() || |
| 2442 | ElementType != T->getElementType()) { |
| 2443 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2444 | if (Result.isNull()) |
| 2445 | return QualType(); |
| 2446 | } |
| 2447 | |
| 2448 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2449 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2450 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2451 | return Result; |
| 2452 | } |
| 2453 | |
| 2454 | template<typename Derived> |
| 2455 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2456 | ExtVectorTypeLoc TL) { |
| 2457 | VectorType *T = TL.getTypePtr(); |
| 2458 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2459 | if (ElementType.isNull()) |
| 2460 | return QualType(); |
| 2461 | |
| 2462 | QualType Result = TL.getType(); |
| 2463 | if (getDerived().AlwaysRebuild() || |
| 2464 | ElementType != T->getElementType()) { |
| 2465 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2466 | T->getNumElements(), |
| 2467 | /*FIXME*/ SourceLocation()); |
| 2468 | if (Result.isNull()) |
| 2469 | return QualType(); |
| 2470 | } |
| 2471 | |
| 2472 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2473 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2474 | |
| 2475 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2476 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2477 | |
| 2478 | template<typename Derived> |
| 2479 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2480 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2481 | FunctionProtoTypeLoc TL) { |
| 2482 | FunctionProtoType *T = TL.getTypePtr(); |
| 2483 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2484 | if (ResultType.isNull()) |
| 2485 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2486 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2487 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2488 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2489 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2490 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2491 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2492 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2493 | QualType NewType; |
| 2494 | ParmVarDecl *NewParm; |
| 2495 | |
| 2496 | if (OldParm) { |
| 2497 | DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo(); |
| 2498 | assert(OldDI->getType() == T->getArgType(i)); |
| 2499 | |
| 2500 | DeclaratorInfo *NewDI = getDerived().TransformType(OldDI); |
| 2501 | if (!NewDI) |
| 2502 | return QualType(); |
| 2503 | |
| 2504 | if (NewDI == OldDI) |
| 2505 | NewParm = OldParm; |
| 2506 | else |
| 2507 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2508 | OldParm->getDeclContext(), |
| 2509 | OldParm->getLocation(), |
| 2510 | OldParm->getIdentifier(), |
| 2511 | NewDI->getType(), |
| 2512 | NewDI, |
| 2513 | OldParm->getStorageClass(), |
| 2514 | /* DefArg */ NULL); |
| 2515 | NewType = NewParm->getType(); |
| 2516 | |
| 2517 | // Deal with the possibility that we don't have a parameter |
| 2518 | // declaration for this parameter. |
| 2519 | } else { |
| 2520 | NewParm = 0; |
| 2521 | |
| 2522 | QualType OldType = T->getArgType(i); |
| 2523 | NewType = getDerived().TransformType(OldType); |
| 2524 | if (NewType.isNull()) |
| 2525 | return QualType(); |
| 2526 | } |
| 2527 | |
| 2528 | ParamTypes.push_back(NewType); |
| 2529 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2532 | QualType Result = TL.getType(); |
| 2533 | if (getDerived().AlwaysRebuild() || |
| 2534 | ResultType != T->getResultType() || |
| 2535 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2536 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2537 | ParamTypes.data(), |
| 2538 | ParamTypes.size(), |
| 2539 | T->isVariadic(), |
| 2540 | T->getTypeQuals()); |
| 2541 | if (Result.isNull()) |
| 2542 | return QualType(); |
| 2543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2544 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2545 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2546 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2547 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2548 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2549 | NewTL.setArg(i, ParamDecls[i]); |
| 2550 | |
| 2551 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2552 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2553 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2554 | template<typename Derived> |
| 2555 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2556 | TypeLocBuilder &TLB, |
| 2557 | FunctionNoProtoTypeLoc TL) { |
| 2558 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2559 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2560 | if (ResultType.isNull()) |
| 2561 | return QualType(); |
| 2562 | |
| 2563 | QualType Result = TL.getType(); |
| 2564 | if (getDerived().AlwaysRebuild() || |
| 2565 | ResultType != T->getResultType()) |
| 2566 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2567 | |
| 2568 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2569 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2570 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2571 | |
| 2572 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2575 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2576 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2577 | TypedefTypeLoc TL) { |
| 2578 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2579 | TypedefDecl *Typedef |
| 2580 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2581 | if (!Typedef) |
| 2582 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2584 | QualType Result = TL.getType(); |
| 2585 | if (getDerived().AlwaysRebuild() || |
| 2586 | Typedef != T->getDecl()) { |
| 2587 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2588 | if (Result.isNull()) |
| 2589 | return QualType(); |
| 2590 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2592 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2593 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2594 | |
| 2595 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2596 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2597 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2598 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2599 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2600 | TypeOfExprTypeLoc TL) { |
| 2601 | TypeOfExprType *T = TL.getTypePtr(); |
| 2602 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2603 | // typeof expressions are not potentially evaluated contexts |
| 2604 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2605 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2606 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2607 | if (E.isInvalid()) |
| 2608 | return QualType(); |
| 2609 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2610 | QualType Result = TL.getType(); |
| 2611 | if (getDerived().AlwaysRebuild() || |
| 2612 | E.get() != T->getUnderlyingExpr()) { |
| 2613 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2614 | if (Result.isNull()) |
| 2615 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2616 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2617 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2619 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2620 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2621 | |
| 2622 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
| 2625 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2626 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2627 | TypeOfTypeLoc TL) { |
| 2628 | TypeOfType *T = TL.getTypePtr(); |
| 2629 | |
| 2630 | // FIXME: should be an inner type, or at least have a DeclaratorInfo. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2631 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2632 | if (Underlying.isNull()) |
| 2633 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2635 | QualType Result = TL.getType(); |
| 2636 | if (getDerived().AlwaysRebuild() || |
| 2637 | Underlying != T->getUnderlyingType()) { |
| 2638 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2639 | if (Result.isNull()) |
| 2640 | return QualType(); |
| 2641 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2643 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2644 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2645 | |
| 2646 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2648 | |
| 2649 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2650 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2651 | DecltypeTypeLoc TL) { |
| 2652 | DecltypeType *T = TL.getTypePtr(); |
| 2653 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2654 | // decltype expressions are not potentially evaluated contexts |
| 2655 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2656 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2657 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2658 | if (E.isInvalid()) |
| 2659 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2660 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2661 | QualType Result = TL.getType(); |
| 2662 | if (getDerived().AlwaysRebuild() || |
| 2663 | E.get() != T->getUnderlyingExpr()) { |
| 2664 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2665 | if (Result.isNull()) |
| 2666 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2667 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2669 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2670 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2671 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2672 | |
| 2673 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2677 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2678 | RecordTypeLoc TL) { |
| 2679 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2682 | if (!Record) |
| 2683 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2684 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2685 | QualType Result = TL.getType(); |
| 2686 | if (getDerived().AlwaysRebuild() || |
| 2687 | Record != T->getDecl()) { |
| 2688 | Result = getDerived().RebuildRecordType(Record); |
| 2689 | if (Result.isNull()) |
| 2690 | return QualType(); |
| 2691 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2692 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2693 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2694 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2695 | |
| 2696 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2698 | |
| 2699 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2700 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2701 | EnumTypeLoc TL) { |
| 2702 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2703 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2704 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2705 | if (!Enum) |
| 2706 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2707 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2708 | QualType Result = TL.getType(); |
| 2709 | if (getDerived().AlwaysRebuild() || |
| 2710 | Enum != T->getDecl()) { |
| 2711 | Result = getDerived().RebuildEnumType(Enum); |
| 2712 | if (Result.isNull()) |
| 2713 | return QualType(); |
| 2714 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2715 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2716 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2717 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2718 | |
| 2719 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2720 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2721 | |
| 2722 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2723 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2724 | ElaboratedTypeLoc TL) { |
| 2725 | ElaboratedType *T = TL.getTypePtr(); |
| 2726 | |
| 2727 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2728 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2729 | if (Underlying.isNull()) |
| 2730 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2732 | QualType Result = TL.getType(); |
| 2733 | if (getDerived().AlwaysRebuild() || |
| 2734 | Underlying != T->getUnderlyingType()) { |
| 2735 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2736 | if (Result.isNull()) |
| 2737 | return QualType(); |
| 2738 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2740 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2741 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2742 | |
| 2743 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2744 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2745 | |
| 2746 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2747 | template<typename Derived> |
| 2748 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2749 | TypeLocBuilder &TLB, |
| 2750 | TemplateTypeParmTypeLoc TL) { |
| 2751 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2755 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2756 | TypeLocBuilder &TLB, |
| 2757 | SubstTemplateTypeParmTypeLoc TL) { |
| 2758 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | template<typename Derived> |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2762 | inline QualType |
| 2763 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2764 | TypeLocBuilder &TLB, |
| 2765 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2766 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2767 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2768 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2769 | template<typename Derived> |
| 2770 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2771 | const TemplateSpecializationType *TST, |
| 2772 | QualType ObjectType) { |
| 2773 | // FIXME: this entire method is a temporary workaround; callers |
| 2774 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2775 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2776 | // Fake up a TemplateSpecializationTypeLoc. |
| 2777 | TypeLocBuilder TLB; |
| 2778 | TemplateSpecializationTypeLoc TL |
| 2779 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2780 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2781 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2782 | |
| 2783 | TL.setTemplateNameLoc(BaseLoc); |
| 2784 | TL.setLAngleLoc(BaseLoc); |
| 2785 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2786 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2787 | const TemplateArgument &TA = TST->getArg(i); |
| 2788 | TemplateArgumentLoc TAL; |
| 2789 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2790 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2791 | } |
| 2792 | |
| 2793 | TypeLocBuilder IgnoredTLB; |
| 2794 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2798 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2799 | TypeLocBuilder &TLB, |
| 2800 | TemplateSpecializationTypeLoc TL, |
| 2801 | QualType ObjectType) { |
| 2802 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2803 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2805 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2806 | if (Template.isNull()) |
| 2807 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2808 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2809 | llvm::SmallVector<TemplateArgumentLoc, 4> NewTemplateArgs(T->getNumArgs()); |
| 2810 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) |
| 2811 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), |
| 2812 | NewTemplateArgs[i])) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2813 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2814 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2815 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2816 | |
| 2817 | QualType Result = |
| 2818 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2819 | TL.getTemplateNameLoc(), |
| 2820 | TL.getLAngleLoc(), |
| 2821 | NewTemplateArgs.data(), |
| 2822 | NewTemplateArgs.size(), |
| 2823 | TL.getRAngleLoc()); |
| 2824 | |
| 2825 | if (!Result.isNull()) { |
| 2826 | TemplateSpecializationTypeLoc NewTL |
| 2827 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2828 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2829 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2830 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2831 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2832 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2833 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2834 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2835 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2836 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2837 | |
| 2838 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2839 | QualType |
| 2840 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2841 | QualifiedNameTypeLoc TL) { |
| 2842 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2843 | NestedNameSpecifier *NNS |
| 2844 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2845 | SourceRange()); |
| 2846 | if (!NNS) |
| 2847 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2848 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2849 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2850 | if (Named.isNull()) |
| 2851 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2852 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2853 | QualType Result = TL.getType(); |
| 2854 | if (getDerived().AlwaysRebuild() || |
| 2855 | NNS != T->getQualifier() || |
| 2856 | Named != T->getNamedType()) { |
| 2857 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2858 | if (Result.isNull()) |
| 2859 | return QualType(); |
| 2860 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2861 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2862 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2863 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2864 | |
| 2865 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2867 | |
| 2868 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2869 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2870 | TypenameTypeLoc TL) { |
| 2871 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2872 | |
| 2873 | /* FIXME: preserve source information better than this */ |
| 2874 | SourceRange SR(TL.getNameLoc()); |
| 2875 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2876 | NestedNameSpecifier *NNS |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2877 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2878 | if (!NNS) |
| 2879 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2880 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2881 | QualType Result; |
| 2882 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2883 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2884 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2885 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2886 | if (NewTemplateId.isNull()) |
| 2887 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2888 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2889 | if (!getDerived().AlwaysRebuild() && |
| 2890 | NNS == T->getQualifier() && |
| 2891 | NewTemplateId == QualType(TemplateId, 0)) |
| 2892 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2894 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2895 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2896 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2897 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2898 | if (Result.isNull()) |
| 2899 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2900 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2901 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2902 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2903 | |
| 2904 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2905 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2907 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2908 | QualType |
| 2909 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2910 | ObjCInterfaceTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2911 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2912 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2913 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | |
| 2915 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2916 | QualType |
| 2917 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2918 | ObjCObjectPointerTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2919 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2920 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2921 | } |
| 2922 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2923 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2924 | // Statement transformation |
| 2925 | //===----------------------------------------------------------------------===// |
| 2926 | template<typename Derived> |
| 2927 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2928 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2929 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | template<typename Derived> |
| 2933 | Sema::OwningStmtResult |
| 2934 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2935 | return getDerived().TransformCompoundStmt(S, false); |
| 2936 | } |
| 2937 | |
| 2938 | template<typename Derived> |
| 2939 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2940 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2941 | bool IsStmtExpr) { |
| 2942 | bool SubStmtChanged = false; |
| 2943 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2944 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2945 | B != BEnd; ++B) { |
| 2946 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2947 | if (Result.isInvalid()) |
| 2948 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2949 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2950 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2951 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2952 | } |
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 | if (!getDerived().AlwaysRebuild() && |
| 2955 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2957 | |
| 2958 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2959 | move_arg(Statements), |
| 2960 | S->getRBracLoc(), |
| 2961 | IsStmtExpr); |
| 2962 | } |
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 | template<typename Derived> |
| 2965 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2966 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2967 | // The case value expressions are not potentially evaluated. |
| 2968 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2970 | // Transform the left-hand case value. |
| 2971 | OwningExprResult LHS = getDerived().TransformExpr(S->getLHS()); |
| 2972 | if (LHS.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 right-hand case value (for the GNU case-range extension). |
| 2976 | OwningExprResult RHS = getDerived().TransformExpr(S->getRHS()); |
| 2977 | if (RHS.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 | // Build the case statement. |
| 2981 | // Case statements are always rebuilt so that they will attached to their |
| 2982 | // transformed switch statement. |
| 2983 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 2984 | move(LHS), |
| 2985 | S->getEllipsisLoc(), |
| 2986 | move(RHS), |
| 2987 | S->getColonLoc()); |
| 2988 | if (Case.isInvalid()) |
| 2989 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2990 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2991 | // Transform the statement following the case |
| 2992 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 2993 | if (SubStmt.isInvalid()) |
| 2994 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2996 | // Attach the body to the case statement |
| 2997 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 2998 | } |
| 2999 | |
| 3000 | template<typename Derived> |
| 3001 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3002 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3003 | // Transform the statement following the default case |
| 3004 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3005 | if (SubStmt.isInvalid()) |
| 3006 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3008 | // Default statements are always rebuilt |
| 3009 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3010 | move(SubStmt)); |
| 3011 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3012 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3013 | template<typename Derived> |
| 3014 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3016 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3017 | if (SubStmt.isInvalid()) |
| 3018 | return SemaRef.StmtError(); |
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 | // FIXME: Pass the real colon location in. |
| 3021 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3022 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3023 | move(SubStmt)); |
| 3024 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3025 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3026 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3027 | Sema::OwningStmtResult |
| 3028 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3029 | // Transform the condition |
| 3030 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3031 | if (Cond.isInvalid()) |
| 3032 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3034 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3036 | // Transform the "then" branch. |
| 3037 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3038 | if (Then.isInvalid()) |
| 3039 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3041 | // Transform the "else" branch. |
| 3042 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3043 | if (Else.isInvalid()) |
| 3044 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3046 | if (!getDerived().AlwaysRebuild() && |
| 3047 | FullCond->get() == S->getCond() && |
| 3048 | Then.get() == S->getThen() && |
| 3049 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3050 | return SemaRef.Owned(S->Retain()); |
| 3051 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3052 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | template<typename Derived> |
| 3057 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3058 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3059 | // Transform the condition. |
| 3060 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3061 | if (Cond.isInvalid()) |
| 3062 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3064 | // Rebuild the switch statement. |
| 3065 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond)); |
| 3066 | if (Switch.isInvalid()) |
| 3067 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3068 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3069 | // Transform the body of the switch statement. |
| 3070 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3071 | if (Body.isInvalid()) |
| 3072 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3074 | // Complete the switch statement. |
| 3075 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3076 | move(Body)); |
| 3077 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3078 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3079 | template<typename Derived> |
| 3080 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3081 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3082 | // Transform the condition |
| 3083 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3084 | if (Cond.isInvalid()) |
| 3085 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3086 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3087 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | // Transform the body |
| 3090 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3091 | if (Body.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 | if (!getDerived().AlwaysRebuild() && |
| 3095 | FullCond->get() == S->getCond() && |
| 3096 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3097 | return SemaRef.Owned(S->Retain()); |
| 3098 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3099 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body)); |
| 3100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3101 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3102 | template<typename Derived> |
| 3103 | Sema::OwningStmtResult |
| 3104 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3105 | // Transform the condition |
| 3106 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3107 | if (Cond.isInvalid()) |
| 3108 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3110 | // Transform the body |
| 3111 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3112 | if (Body.isInvalid()) |
| 3113 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3115 | if (!getDerived().AlwaysRebuild() && |
| 3116 | Cond.get() == S->getCond() && |
| 3117 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3118 | return SemaRef.Owned(S->Retain()); |
| 3119 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3120 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3121 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3122 | S->getRParenLoc()); |
| 3123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3125 | template<typename Derived> |
| 3126 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Transform the initialization statement |
| 3129 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3130 | if (Init.isInvalid()) |
| 3131 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3133 | // Transform the condition |
| 3134 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3135 | if (Cond.isInvalid()) |
| 3136 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3138 | // Transform the increment |
| 3139 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3140 | if (Inc.isInvalid()) |
| 3141 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3142 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3143 | // Transform the body |
| 3144 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3145 | if (Body.isInvalid()) |
| 3146 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3147 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3148 | if (!getDerived().AlwaysRebuild() && |
| 3149 | Init.get() == S->getInit() && |
| 3150 | Cond.get() == S->getCond() && |
| 3151 | Inc.get() == S->getInc() && |
| 3152 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | return SemaRef.Owned(S->Retain()); |
| 3154 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3155 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 3156 | move(Init), move(Cond), move(Inc), |
| 3157 | S->getRParenLoc(), move(Body)); |
| 3158 | } |
| 3159 | |
| 3160 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | Sema::OwningStmtResult |
| 3162 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3165 | S->getLabel()); |
| 3166 | } |
| 3167 | |
| 3168 | template<typename Derived> |
| 3169 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3170 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3171 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3172 | if (Target.isInvalid()) |
| 3173 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3175 | if (!getDerived().AlwaysRebuild() && |
| 3176 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3177 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3178 | |
| 3179 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3180 | move(Target)); |
| 3181 | } |
| 3182 | |
| 3183 | template<typename Derived> |
| 3184 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3185 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3186 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3187 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | template<typename Derived> |
| 3190 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3192 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | template<typename Derived> |
| 3196 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3197 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3199 | if (Result.isInvalid()) |
| 3200 | return SemaRef.StmtError(); |
| 3201 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3203 | // to tell whether the return type of the function has changed. |
| 3204 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3205 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3206 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3207 | template<typename Derived> |
| 3208 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3209 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3210 | bool DeclChanged = false; |
| 3211 | llvm::SmallVector<Decl *, 4> Decls; |
| 3212 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3213 | D != DEnd; ++D) { |
| 3214 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3215 | if (!Transformed) |
| 3216 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | if (Transformed != *D) |
| 3219 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3220 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3221 | Decls.push_back(Transformed); |
| 3222 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3223 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3224 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3225 | return SemaRef.Owned(S->Retain()); |
| 3226 | |
| 3227 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3228 | S->getStartLoc(), S->getEndLoc()); |
| 3229 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3231 | template<typename Derived> |
| 3232 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3234 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3235 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | template<typename Derived> |
| 3239 | Sema::OwningStmtResult |
| 3240 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3241 | // FIXME: Implement! |
| 3242 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3243 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | |
| 3247 | template<typename Derived> |
| 3248 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3249 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *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 @try 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>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *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 @catch statement"); |
| 3260 | return SemaRef.Owned(S->Retain()); |
| 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 |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3266 | // FIXME: Implement this |
| 3267 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3269 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | template<typename Derived> |
| 3272 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | // FIXME: Implement this |
| 3275 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3279 | template<typename Derived> |
| 3280 | Sema::OwningStmtResult |
| 3281 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | // FIXME: Implement this |
| 3284 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | template<typename Derived> |
| 3289 | Sema::OwningStmtResult |
| 3290 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | // FIXME: Implement this |
| 3293 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3294 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | |
| 3298 | template<typename Derived> |
| 3299 | Sema::OwningStmtResult |
| 3300 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3301 | // Transform the exception declaration, if any. |
| 3302 | VarDecl *Var = 0; |
| 3303 | if (S->getExceptionDecl()) { |
| 3304 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3305 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3306 | ExceptionDecl->getDeclName()); |
| 3307 | |
| 3308 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3309 | if (T.isNull()) |
| 3310 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3313 | T, |
| 3314 | ExceptionDecl->getDeclaratorInfo(), |
| 3315 | ExceptionDecl->getIdentifier(), |
| 3316 | ExceptionDecl->getLocation(), |
| 3317 | /*FIXME: Inaccurate*/ |
| 3318 | SourceRange(ExceptionDecl->getLocation())); |
| 3319 | if (!Var || Var->isInvalidDecl()) { |
| 3320 | if (Var) |
| 3321 | Var->Destroy(SemaRef.Context); |
| 3322 | return SemaRef.StmtError(); |
| 3323 | } |
| 3324 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3325 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3326 | // Transform the actual exception handler. |
| 3327 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3328 | if (Handler.isInvalid()) { |
| 3329 | if (Var) |
| 3330 | Var->Destroy(SemaRef.Context); |
| 3331 | return SemaRef.StmtError(); |
| 3332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3333 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3334 | if (!getDerived().AlwaysRebuild() && |
| 3335 | !Var && |
| 3336 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | |
| 3339 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3340 | Var, |
| 3341 | move(Handler)); |
| 3342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | template<typename Derived> |
| 3345 | Sema::OwningStmtResult |
| 3346 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3347 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3350 | if (TryBlock.isInvalid()) |
| 3351 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | // Transform the handlers. |
| 3354 | bool HandlerChanged = false; |
| 3355 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3356 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3357 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3358 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3359 | if (Handler.isInvalid()) |
| 3360 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3363 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3364 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3366 | if (!getDerived().AlwaysRebuild() && |
| 3367 | TryBlock.get() == S->getTryBlock() && |
| 3368 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | |
| 3371 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3372 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3373 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3376 | // Expression transformation |
| 3377 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3378 | template<typename Derived> |
| 3379 | Sema::OwningExprResult |
| 3380 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| 3381 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | |
| 3384 | template<typename Derived> |
| 3385 | Sema::OwningExprResult |
| 3386 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3387 | NestedNameSpecifier *Qualifier = 0; |
| 3388 | if (E->getQualifier()) { |
| 3389 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3390 | E->getQualifierRange()); |
| 3391 | if (!Qualifier) |
| 3392 | return SemaRef.ExprError(); |
| 3393 | } |
| 3394 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3395 | NamedDecl *ND |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3396 | = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); |
| 3397 | if (!ND) |
| 3398 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3399 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3400 | if (!getDerived().AlwaysRebuild() && |
| 3401 | Qualifier == E->getQualifier() && |
| 3402 | ND == E->getDecl() && |
| 3403 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3404 | return SemaRef.Owned(E->Retain()); |
| 3405 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3406 | // FIXME: We're losing the explicit template arguments in this transformation. |
| 3407 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3408 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3409 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3410 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3411 | TransArgs[I])) |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3412 | return SemaRef.ExprError(); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | // FIXME: Pass the qualifier/qualifier range along. |
| 3416 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
| 3417 | ND, E->getLocation()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3418 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3419 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3420 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 | Sema::OwningExprResult |
| 3422 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| 3423 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3424 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3425 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3426 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3427 | Sema::OwningExprResult |
| 3428 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| 3429 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3431 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3432 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3433 | Sema::OwningExprResult |
| 3434 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| 3435 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3436 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3438 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3439 | Sema::OwningExprResult |
| 3440 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| 3441 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3442 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3444 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | Sema::OwningExprResult |
| 3446 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| 3447 | return SemaRef.Owned(E->Retain()); |
| 3448 | } |
| 3449 | |
| 3450 | template<typename Derived> |
| 3451 | Sema::OwningExprResult |
| 3452 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3453 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3454 | if (SubExpr.isInvalid()) |
| 3455 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3457 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | return SemaRef.Owned(E->Retain()); |
| 3459 | |
| 3460 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3461 | E->getRParen()); |
| 3462 | } |
| 3463 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | template<typename Derived> |
| 3465 | Sema::OwningExprResult |
| 3466 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3467 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3468 | if (SubExpr.isInvalid()) |
| 3469 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3471 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3472 | return SemaRef.Owned(E->Retain()); |
| 3473 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3474 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3475 | E->getOpcode(), |
| 3476 | move(SubExpr)); |
| 3477 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3479 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3480 | Sema::OwningExprResult |
| 3481 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3482 | if (E->isArgumentType()) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3483 | TemporaryBase Rebase(*this, E->getOperatorLoc(), DeclarationName()); |
| 3484 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3485 | QualType T = getDerived().TransformType(E->getArgumentType()); |
| 3486 | if (T.isNull()) |
| 3487 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3488 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3489 | if (!getDerived().AlwaysRebuild() && T == E->getArgumentType()) |
| 3490 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3491 | |
| 3492 | return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(), |
| 3493 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3494 | E->getSourceRange()); |
| 3495 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3496 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3497 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3498 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3499 | // C++0x [expr.sizeof]p1: |
| 3500 | // The operand is either an expression, which is an unevaluated operand |
| 3501 | // [...] |
| 3502 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3503 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3504 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3505 | if (SubExpr.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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3509 | return SemaRef.Owned(E->Retain()); |
| 3510 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3511 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3512 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3513 | E->isSizeOf(), |
| 3514 | E->getSourceRange()); |
| 3515 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3517 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3519 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 3520 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3521 | if (LHS.isInvalid()) |
| 3522 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3524 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3525 | if (RHS.isInvalid()) |
| 3526 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3527 | |
| 3528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3529 | if (!getDerived().AlwaysRebuild() && |
| 3530 | LHS.get() == E->getLHS() && |
| 3531 | RHS.get() == E->getRHS()) |
| 3532 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3534 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3535 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3536 | move(RHS), |
| 3537 | E->getRBracketLoc()); |
| 3538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3539 | |
| 3540 | template<typename Derived> |
| 3541 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3542 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| 3543 | // Transform the callee. |
| 3544 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3545 | if (Callee.isInvalid()) |
| 3546 | return SemaRef.ExprError(); |
| 3547 | |
| 3548 | // Transform arguments. |
| 3549 | bool ArgChanged = false; |
| 3550 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3551 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3552 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3553 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3554 | if (Arg.isInvalid()) |
| 3555 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3556 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3557 | // FIXME: Wrong source location information for the ','. |
| 3558 | FakeCommaLocs.push_back( |
| 3559 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3560 | |
| 3561 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3562 | Args.push_back(Arg.takeAs<Expr>()); |
| 3563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3565 | if (!getDerived().AlwaysRebuild() && |
| 3566 | Callee.get() == E->getCallee() && |
| 3567 | !ArgChanged) |
| 3568 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3570 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3571 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3572 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3573 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3574 | move_arg(Args), |
| 3575 | FakeCommaLocs.data(), |
| 3576 | E->getRParenLoc()); |
| 3577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 | |
| 3579 | template<typename Derived> |
| 3580 | Sema::OwningExprResult |
| 3581 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3582 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3583 | if (Base.isInvalid()) |
| 3584 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3586 | NestedNameSpecifier *Qualifier = 0; |
| 3587 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3589 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3590 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3591 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3592 | return SemaRef.ExprError(); |
| 3593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3594 | |
| 3595 | NamedDecl *Member |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3596 | = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
| 3597 | if (!Member) |
| 3598 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3600 | if (!getDerived().AlwaysRebuild() && |
| 3601 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3602 | Qualifier == E->getQualifier() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3603 | Member == E->getMemberDecl()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3605 | |
| 3606 | // FIXME: Bogus source location for the operator |
| 3607 | SourceLocation FakeOperatorLoc |
| 3608 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3609 | |
| 3610 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3611 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3612 | Qualifier, |
| 3613 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3614 | E->getMemberLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3615 | Member); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3617 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3618 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3619 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E) { |
| 3621 | assert(false && "Cannot transform abstract class"); |
| 3622 | return SemaRef.Owned(E->Retain()); |
| 3623 | } |
| 3624 | |
| 3625 | template<typename Derived> |
| 3626 | Sema::OwningExprResult |
| 3627 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3628 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3629 | if (LHS.isInvalid()) |
| 3630 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3633 | if (RHS.isInvalid()) |
| 3634 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 3637 | LHS.get() == E->getLHS() && |
| 3638 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | return SemaRef.Owned(E->Retain()); |
| 3640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3641 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3642 | move(LHS), move(RHS)); |
| 3643 | } |
| 3644 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | Sema::OwningExprResult |
| 3647 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| 3648 | CompoundAssignOperator *E) { |
| 3649 | return getDerived().TransformBinaryOperator(E); |
| 3650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | Sema::OwningExprResult |
| 3654 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3655 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3656 | if (Cond.isInvalid()) |
| 3657 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3659 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3660 | if (LHS.isInvalid()) |
| 3661 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3662 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3663 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3664 | if (RHS.isInvalid()) |
| 3665 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3666 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3667 | if (!getDerived().AlwaysRebuild() && |
| 3668 | Cond.get() == E->getCond() && |
| 3669 | LHS.get() == E->getLHS() && |
| 3670 | RHS.get() == E->getRHS()) |
| 3671 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | |
| 3673 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3674 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3675 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3676 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3677 | move(RHS)); |
| 3678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3679 | |
| 3680 | template<typename Derived> |
| 3681 | Sema::OwningExprResult |
| 3682 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3683 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3684 | |
| 3685 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3686 | // so do we even need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3687 | QualType T = getDerived().TransformType(E->getType()); |
| 3688 | if (T.isNull()) |
| 3689 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3692 | if (SubExpr.isInvalid()) |
| 3693 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3695 | if (!getDerived().AlwaysRebuild() && |
| 3696 | T == E->getType() && |
| 3697 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | return SemaRef.Owned(E->Retain()); |
| 3699 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3700 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3701 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3702 | E->isLvalueCast()); |
| 3703 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3704 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3705 | template<typename Derived> |
| 3706 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3707 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) { |
| 3708 | assert(false && "Cannot transform abstract class"); |
| 3709 | return SemaRef.Owned(E->Retain()); |
| 3710 | } |
| 3711 | |
| 3712 | template<typename Derived> |
| 3713 | Sema::OwningExprResult |
| 3714 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3715 | QualType T; |
| 3716 | { |
| 3717 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3719 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3720 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3723 | if (T.isNull()) |
| 3724 | return SemaRef.ExprError(); |
| 3725 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3726 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3728 | if (SubExpr.isInvalid()) |
| 3729 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3731 | if (!getDerived().AlwaysRebuild() && |
| 3732 | T == E->getTypeAsWritten() && |
| 3733 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3734 | return SemaRef.Owned(E->Retain()); |
| 3735 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3736 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3737 | E->getRParenLoc(), |
| 3738 | move(SubExpr)); |
| 3739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3742 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3743 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 3744 | QualType T; |
| 3745 | { |
| 3746 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | SourceLocation FakeTypeLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3749 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3751 | T = getDerived().TransformType(E->getType()); |
| 3752 | if (T.isNull()) |
| 3753 | return SemaRef.ExprError(); |
| 3754 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3755 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3756 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3757 | if (Init.isInvalid()) |
| 3758 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3759 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3760 | if (!getDerived().AlwaysRebuild() && |
| 3761 | T == E->getType() && |
| 3762 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3764 | |
| 3765 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3766 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3767 | move(Init)); |
| 3768 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3769 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3770 | template<typename Derived> |
| 3771 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3772 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3773 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3774 | if (Base.isInvalid()) |
| 3775 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3776 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3777 | if (!getDerived().AlwaysRebuild() && |
| 3778 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3779 | return SemaRef.Owned(E->Retain()); |
| 3780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3781 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3782 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3783 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3784 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3785 | E->getAccessorLoc(), |
| 3786 | E->getAccessor()); |
| 3787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3789 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | Sema::OwningExprResult |
| 3791 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3793 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3794 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3795 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3796 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3797 | if (Init.isInvalid()) |
| 3798 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3800 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3801 | Inits.push_back(Init.takeAs<Expr>()); |
| 3802 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3803 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3804 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | return SemaRef.Owned(E->Retain()); |
| 3806 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3807 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
| 3808 | E->getRBraceLoc()); |
| 3809 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3810 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3811 | template<typename Derived> |
| 3812 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3814 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3815 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3816 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3817 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3818 | if (Init.isInvalid()) |
| 3819 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3821 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3822 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3823 | bool ExprChanged = false; |
| 3824 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3825 | DEnd = E->designators_end(); |
| 3826 | D != DEnd; ++D) { |
| 3827 | if (D->isFieldDesignator()) { |
| 3828 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3829 | D->getDotLoc(), |
| 3830 | D->getFieldLoc())); |
| 3831 | continue; |
| 3832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3834 | if (D->isArrayDesignator()) { |
| 3835 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3836 | if (Index.isInvalid()) |
| 3837 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3838 | |
| 3839 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3842 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3843 | ArrayExprs.push_back(Index.release()); |
| 3844 | continue; |
| 3845 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3846 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3847 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3850 | if (Start.isInvalid()) |
| 3851 | return SemaRef.ExprError(); |
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 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3854 | if (End.isInvalid()) |
| 3855 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3856 | |
| 3857 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | End.get(), |
| 3859 | D->getLBracketLoc(), |
| 3860 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3862 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3863 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3865 | ArrayExprs.push_back(Start.release()); |
| 3866 | ArrayExprs.push_back(End.release()); |
| 3867 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3868 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3869 | if (!getDerived().AlwaysRebuild() && |
| 3870 | Init.get() == E->getInit() && |
| 3871 | !ExprChanged) |
| 3872 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3874 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3875 | E->getEqualOrColonLoc(), |
| 3876 | E->usesGNUSyntax(), move(Init)); |
| 3877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3878 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3879 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3880 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3881 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3883 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3884 | |
| 3885 | // FIXME: Will we ever have proper type location here? Will we actually |
| 3886 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3887 | QualType T = getDerived().TransformType(E->getType()); |
| 3888 | if (T.isNull()) |
| 3889 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3891 | if (!getDerived().AlwaysRebuild() && |
| 3892 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | return SemaRef.Owned(E->Retain()); |
| 3894 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 3896 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3900 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| 3901 | // FIXME: Do we want the type as written? |
| 3902 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3904 | { |
| 3905 | // FIXME: Source location isn't quite accurate. |
| 3906 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 3907 | T = getDerived().TransformType(E->getType()); |
| 3908 | if (T.isNull()) |
| 3909 | return SemaRef.ExprError(); |
| 3910 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3913 | if (SubExpr.isInvalid()) |
| 3914 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | if (!getDerived().AlwaysRebuild() && |
| 3917 | T == E->getType() && |
| 3918 | SubExpr.get() == E->getSubExpr()) |
| 3919 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3920 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 3922 | T, E->getRParenLoc()); |
| 3923 | } |
| 3924 | |
| 3925 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3927 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| 3928 | bool ArgumentChanged = false; |
| 3929 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3930 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 3931 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 3932 | if (Init.isInvalid()) |
| 3933 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3934 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3935 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 3936 | Inits.push_back(Init.takeAs<Expr>()); |
| 3937 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 3940 | move_arg(Inits), |
| 3941 | E->getRParenLoc()); |
| 3942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | /// \brief Transform an address-of-label expression. |
| 3945 | /// |
| 3946 | /// By default, the transformation of an address-of-label expression always |
| 3947 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 3948 | /// the corresponding label statement by semantic analysis. |
| 3949 | template<typename Derived> |
| 3950 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3951 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 3953 | E->getLabel()); |
| 3954 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
| 3956 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3957 | Sema::OwningExprResult TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3958 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3959 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 3960 | if (SubStmt.isInvalid()) |
| 3961 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | if (!getDerived().AlwaysRebuild() && |
| 3964 | SubStmt.get() == E->getSubStmt()) |
| 3965 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
| 3967 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3968 | move(SubStmt), |
| 3969 | E->getRParenLoc()); |
| 3970 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3971 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3972 | template<typename Derived> |
| 3973 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | QualType T1, T2; |
| 3976 | { |
| 3977 | // FIXME: Source location isn't quite accurate. |
| 3978 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | T1 = getDerived().TransformType(E->getArgType1()); |
| 3981 | if (T1.isNull()) |
| 3982 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | T2 = getDerived().TransformType(E->getArgType2()); |
| 3985 | if (T2.isNull()) |
| 3986 | return SemaRef.ExprError(); |
| 3987 | } |
| 3988 | |
| 3989 | if (!getDerived().AlwaysRebuild() && |
| 3990 | T1 == E->getArgType1() && |
| 3991 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3992 | return SemaRef.Owned(E->Retain()); |
| 3993 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3994 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 3995 | T1, T2, E->getRParenLoc()); |
| 3996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3998 | template<typename Derived> |
| 3999 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4002 | if (Cond.isInvalid()) |
| 4003 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4004 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4005 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4006 | if (LHS.isInvalid()) |
| 4007 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4008 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4010 | if (RHS.isInvalid()) |
| 4011 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4012 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4013 | if (!getDerived().AlwaysRebuild() && |
| 4014 | Cond.get() == E->getCond() && |
| 4015 | LHS.get() == E->getLHS() && |
| 4016 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4017 | return SemaRef.Owned(E->Retain()); |
| 4018 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4019 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4020 | move(Cond), move(LHS), move(RHS), |
| 4021 | E->getRParenLoc()); |
| 4022 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4025 | Sema::OwningExprResult |
| 4026 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| 4027 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | template<typename Derived> |
| 4031 | Sema::OwningExprResult |
| 4032 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 4033 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4034 | if (Callee.isInvalid()) |
| 4035 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
| 4038 | if (First.isInvalid()) |
| 4039 | return SemaRef.ExprError(); |
| 4040 | |
| 4041 | OwningExprResult Second(SemaRef); |
| 4042 | if (E->getNumArgs() == 2) { |
| 4043 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4044 | if (Second.isInvalid()) |
| 4045 | return SemaRef.ExprError(); |
| 4046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4048 | if (!getDerived().AlwaysRebuild() && |
| 4049 | Callee.get() == E->getCallee() && |
| 4050 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4051 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4052 | return SemaRef.Owned(E->Retain()); |
| 4053 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4054 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4055 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4056 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4057 | move(First), |
| 4058 | move(Second)); |
| 4059 | } |
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 | template<typename Derived> |
| 4062 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | return getDerived().TransformCallExpr(E); |
| 4065 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4067 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 4070 | QualType ExplicitTy; |
| 4071 | { |
| 4072 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4074 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4075 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4076 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4077 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4078 | if (ExplicitTy.isNull()) |
| 4079 | return SemaRef.ExprError(); |
| 4080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4082 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4083 | if (SubExpr.isInvalid()) |
| 4084 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4086 | if (!getDerived().AlwaysRebuild() && |
| 4087 | ExplicitTy == E->getTypeAsWritten() && |
| 4088 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4089 | return SemaRef.Owned(E->Retain()); |
| 4090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4092 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4093 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4094 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4095 | SourceLocation FakeRParenLoc |
| 4096 | = SemaRef.PP.getLocForEndOfToken( |
| 4097 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4098 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4100 | FakeLAngleLoc, |
| 4101 | ExplicitTy, |
| 4102 | FakeRAngleLoc, |
| 4103 | FakeRAngleLoc, |
| 4104 | move(SubExpr), |
| 4105 | FakeRParenLoc); |
| 4106 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | template<typename Derived> |
| 4109 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4111 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4112 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
| 4114 | template<typename Derived> |
| 4115 | Sema::OwningExprResult |
| 4116 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4117 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4118 | } |
| 4119 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4120 | template<typename Derived> |
| 4121 | Sema::OwningExprResult |
| 4122 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4123 | CXXReinterpretCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4124 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4127 | template<typename Derived> |
| 4128 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4130 | return getDerived().TransformCXXNamedCastExpr(E); |
| 4131 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | template<typename Derived> |
| 4134 | Sema::OwningExprResult |
| 4135 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4136 | CXXFunctionalCastExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4137 | QualType ExplicitTy; |
| 4138 | { |
| 4139 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4141 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4142 | if (ExplicitTy.isNull()) |
| 4143 | return SemaRef.ExprError(); |
| 4144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4147 | if (SubExpr.isInvalid()) |
| 4148 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | if (!getDerived().AlwaysRebuild() && |
| 4151 | ExplicitTy == E->getTypeAsWritten() && |
| 4152 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | return SemaRef.Owned(E->Retain()); |
| 4154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4155 | // FIXME: The end of the type's source range is wrong |
| 4156 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4157 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4158 | ExplicitTy, |
| 4159 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4160 | move(SubExpr), |
| 4161 | E->getRParenLoc()); |
| 4162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4163 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4164 | template<typename Derived> |
| 4165 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4167 | if (E->isTypeOperand()) { |
| 4168 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4170 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4171 | if (T.isNull()) |
| 4172 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4175 | T == E->getTypeOperand()) |
| 4176 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4179 | /*FIXME:*/E->getLocStart(), |
| 4180 | T, |
| 4181 | E->getLocEnd()); |
| 4182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4183 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4184 | // We don't know whether the expression is potentially evaluated until |
| 4185 | // after we perform semantic analysis, so the expression is potentially |
| 4186 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4190 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4191 | if (SubExpr.isInvalid()) |
| 4192 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4195 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4196 | return SemaRef.Owned(E->Retain()); |
| 4197 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4199 | /*FIXME:*/E->getLocStart(), |
| 4200 | move(SubExpr), |
| 4201 | E->getLocEnd()); |
| 4202 | } |
| 4203 | |
| 4204 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4205 | Sema::OwningExprResult |
| 4206 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 4207 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4208 | } |
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 | template<typename Derived> |
| 4211 | Sema::OwningExprResult |
| 4212 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | CXXNullPtrLiteralExpr *E) { |
| 4214 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 |
| 4219 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| 4220 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | QualType T = getDerived().TransformType(E->getType()); |
| 4223 | if (T.isNull()) |
| 4224 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4226 | if (!getDerived().AlwaysRebuild() && |
| 4227 | T == E->getType()) |
| 4228 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4229 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4230 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4231 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4232 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4233 | template<typename Derived> |
| 4234 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4235 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4236 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4237 | if (SubExpr.isInvalid()) |
| 4238 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4239 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4240 | if (!getDerived().AlwaysRebuild() && |
| 4241 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4242 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4243 | |
| 4244 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4247 | template<typename Derived> |
| 4248 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4249 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 4250 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4251 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4252 | if (!Param) |
| 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 | Param == E->getParam()) |
| 4257 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4258 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4259 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4260 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4262 | template<typename Derived> |
| 4263 | Sema::OwningExprResult |
| 4264 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
| 4265 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4266 | |
| 4267 | QualType T = getDerived().TransformType(E->getType()); |
| 4268 | if (T.isNull()) |
| 4269 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4270 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | if (!getDerived().AlwaysRebuild() && |
| 4272 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4273 | return SemaRef.Owned(E->Retain()); |
| 4274 | |
| 4275 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4276 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4277 | T, |
| 4278 | E->getRParenLoc()); |
| 4279 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4280 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4281 | template<typename Derived> |
| 4282 | Sema::OwningExprResult |
| 4283 | TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | VarDecl *Var |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4285 | = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4286 | if (!Var) |
| 4287 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4289 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | Var == E->getVarDecl()) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4292 | |
| 4293 | return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4294 | /*FIXME:*/E->getStartLoc(), |
| 4295 | Var); |
| 4296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4297 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4298 | template<typename Derived> |
| 4299 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4300 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | // Transform the type that we're allocating |
| 4302 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4303 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4304 | if (AllocType.isNull()) |
| 4305 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4307 | // Transform the size of the array we're allocating (if any). |
| 4308 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4309 | if (ArraySize.isInvalid()) |
| 4310 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | // Transform the placement arguments (if any). |
| 4313 | bool ArgumentChanged = false; |
| 4314 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4315 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4316 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4317 | if (Arg.isInvalid()) |
| 4318 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4321 | PlacementArgs.push_back(Arg.take()); |
| 4322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4324 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4325 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4326 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4327 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4328 | if (Arg.isInvalid()) |
| 4329 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4332 | ConstructorArgs.push_back(Arg.take()); |
| 4333 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | if (!getDerived().AlwaysRebuild() && |
| 4336 | AllocType == E->getAllocatedType() && |
| 4337 | ArraySize.get() == E->getArraySize() && |
| 4338 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | return SemaRef.Owned(E->Retain()); |
| 4340 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4341 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4342 | E->isGlobalNew(), |
| 4343 | /*FIXME:*/E->getLocStart(), |
| 4344 | move_arg(PlacementArgs), |
| 4345 | /*FIXME:*/E->getLocStart(), |
| 4346 | E->isParenTypeId(), |
| 4347 | AllocType, |
| 4348 | /*FIXME:*/E->getLocStart(), |
| 4349 | /*FIXME:*/SourceRange(), |
| 4350 | move(ArraySize), |
| 4351 | /*FIXME:*/E->getLocStart(), |
| 4352 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4353 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4354 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4356 | template<typename Derived> |
| 4357 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4360 | if (Operand.isInvalid()) |
| 4361 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4363 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4364 | Operand.get() == E->getArgument()) |
| 4365 | return SemaRef.Owned(E->Retain()); |
| 4366 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4368 | E->isGlobalDelete(), |
| 4369 | E->isArrayForm(), |
| 4370 | move(Operand)); |
| 4371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4372 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4373 | template<typename Derived> |
| 4374 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4375 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| 4376 | CXXPseudoDestructorExpr *E) { |
| 4377 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4378 | if (Base.isInvalid()) |
| 4379 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4380 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4381 | NestedNameSpecifier *Qualifier |
| 4382 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4383 | E->getQualifierRange()); |
| 4384 | if (E->getQualifier() && !Qualifier) |
| 4385 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4386 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4387 | QualType DestroyedType; |
| 4388 | { |
| 4389 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4390 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4391 | if (DestroyedType.isNull()) |
| 4392 | return SemaRef.ExprError(); |
| 4393 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4394 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4395 | if (!getDerived().AlwaysRebuild() && |
| 4396 | Base.get() == E->getBase() && |
| 4397 | Qualifier == E->getQualifier() && |
| 4398 | DestroyedType == E->getDestroyedType()) |
| 4399 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4401 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4402 | E->getOperatorLoc(), |
| 4403 | E->isArrow(), |
| 4404 | E->getDestroyedTypeLoc(), |
| 4405 | DestroyedType, |
| 4406 | Qualifier, |
| 4407 | E->getQualifierRange()); |
| 4408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4409 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4410 | template<typename Derived> |
| 4411 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | TreeTransform<Derived>::TransformUnresolvedFunctionNameExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4413 | UnresolvedFunctionNameExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4414 | // There is no transformation we can apply to an unresolved function name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4415 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4416 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4417 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4418 | template<typename Derived> |
| 4419 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4423 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4424 | if (T.isNull()) |
| 4425 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4427 | if (!getDerived().AlwaysRebuild() && |
| 4428 | T == E->getQueriedType()) |
| 4429 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | // FIXME: Bad location information |
| 4432 | SourceLocation FakeLParenLoc |
| 4433 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4434 | |
| 4435 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | E->getLocStart(), |
| 4437 | /*FIXME:*/FakeLParenLoc, |
| 4438 | T, |
| 4439 | E->getLocEnd()); |
| 4440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4442 | template<typename Derived> |
| 4443 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | TreeTransform<Derived>::TransformUnresolvedDeclRefExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4445 | UnresolvedDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4446 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4447 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4448 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4449 | if (!NNS) |
| 4450 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4451 | |
| 4452 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4453 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4454 | if (!Name) |
| 4455 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
| 4457 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | NNS == E->getQualifier() && |
| 4459 | Name == E->getDeclName()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4460 | return SemaRef.Owned(E->Retain()); |
| 4461 | |
| 4462 | return getDerived().RebuildUnresolvedDeclRefExpr(NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4463 | E->getQualifierRange(), |
| 4464 | Name, |
| 4465 | E->getLocation(), |
| 4466 | /*FIXME:*/false); |
| 4467 | } |
| 4468 | |
| 4469 | template<typename Derived> |
| 4470 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4471 | TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E) { |
Douglas Gregor | ba91b89 | 2009-10-29 17:56:10 +0000 | [diff] [blame] | 4472 | TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName()); |
| 4473 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | TemplateName Template |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | = getDerived().TransformTemplateName(E->getTemplateName()); |
| 4476 | if (Template.isNull()) |
| 4477 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4479 | NestedNameSpecifier *Qualifier = 0; |
| 4480 | if (E->getQualifier()) { |
| 4481 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4482 | E->getQualifierRange()); |
| 4483 | if (!Qualifier) |
| 4484 | return SemaRef.ExprError(); |
| 4485 | } |
| 4486 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4487 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4488 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4489 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4490 | TransArgs[I])) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | return SemaRef.ExprError(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | // FIXME: Would like to avoid rebuilding if nothing changed, but we can't |
| 4495 | // compare template arguments (yet). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | |
| 4497 | // 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] | 4498 | // actually refers to a type, in which case the caller is actually dealing |
| 4499 | // with a functional cast. Give a reasonable error message! |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4500 | return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(), |
| 4501 | Template, E->getTemplateNameLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4502 | E->getLAngleLoc(), |
| 4503 | TransArgs.data(), |
| 4504 | TransArgs.size(), |
| 4505 | E->getRAngleLoc()); |
| 4506 | } |
| 4507 | |
| 4508 | template<typename Derived> |
| 4509 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4512 | |
| 4513 | QualType T = getDerived().TransformType(E->getType()); |
| 4514 | if (T.isNull()) |
| 4515 | return SemaRef.ExprError(); |
| 4516 | |
| 4517 | CXXConstructorDecl *Constructor |
| 4518 | = cast_or_null<CXXConstructorDecl>( |
| 4519 | getDerived().TransformDecl(E->getConstructor())); |
| 4520 | if (!Constructor) |
| 4521 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4522 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4523 | bool ArgumentChanged = false; |
| 4524 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4525 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4526 | ArgEnd = E->arg_end(); |
| 4527 | Arg != ArgEnd; ++Arg) { |
| 4528 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4529 | if (TransArg.isInvalid()) |
| 4530 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4533 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4534 | } |
| 4535 | |
| 4536 | if (!getDerived().AlwaysRebuild() && |
| 4537 | T == E->getType() && |
| 4538 | Constructor == E->getConstructor() && |
| 4539 | !ArgumentChanged) |
| 4540 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4541 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4542 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4543 | move_arg(Args)); |
| 4544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4545 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4546 | /// \brief Transform a C++ temporary-binding expression. |
| 4547 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | /// The transformation of a temporary-binding expression always attempts to |
| 4549 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4550 | /// subexpression itself did not change, because the temporary variable itself |
| 4551 | /// must be unique. |
| 4552 | template<typename Derived> |
| 4553 | Sema::OwningExprResult |
| 4554 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 4555 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4556 | if (SubExpr.isInvalid()) |
| 4557 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4559 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4560 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
| 4562 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4563 | /// be destroyed after the expression is evaluated. |
| 4564 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4565 | /// The transformation of a full expression always attempts to build a new |
| 4566 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4567 | /// subexpression itself did not change, because it will need to capture the |
| 4568 | /// the new temporary variables introduced in the subexpression. |
| 4569 | template<typename Derived> |
| 4570 | Sema::OwningExprResult |
| 4571 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4572 | CXXExprWithTemporaries *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4573 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4574 | if (SubExpr.isInvalid()) |
| 4575 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | return SemaRef.Owned( |
| 4578 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4579 | E->shouldDestroyTemporaries())); |
| 4580 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4581 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4582 | template<typename Derived> |
| 4583 | Sema::OwningExprResult |
| 4584 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4585 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4586 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4587 | QualType T = getDerived().TransformType(E->getType()); |
| 4588 | if (T.isNull()) |
| 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 | CXXConstructorDecl *Constructor |
| 4592 | = cast_or_null<CXXConstructorDecl>( |
| 4593 | getDerived().TransformDecl(E->getConstructor())); |
| 4594 | if (!Constructor) |
| 4595 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4596 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4597 | bool ArgumentChanged = false; |
| 4598 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4599 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4600 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | ArgEnd = E->arg_end(); |
| 4602 | Arg != ArgEnd; ++Arg) { |
| 4603 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4604 | if (TransArg.isInvalid()) |
| 4605 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4608 | Args.push_back((Expr *)TransArg.release()); |
| 4609 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4610 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4611 | if (!getDerived().AlwaysRebuild() && |
| 4612 | T == E->getType() && |
| 4613 | Constructor == E->getConstructor() && |
| 4614 | !ArgumentChanged) |
| 4615 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4616 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4617 | // FIXME: Bogus location information |
| 4618 | SourceLocation CommaLoc; |
| 4619 | if (Args.size() > 1) { |
| 4620 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4621 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4623 | } |
| 4624 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4625 | T, |
| 4626 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4627 | move_arg(Args), |
| 4628 | &CommaLoc, |
| 4629 | E->getLocEnd()); |
| 4630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4631 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4632 | template<typename Derived> |
| 4633 | Sema::OwningExprResult |
| 4634 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4635 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4636 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4637 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4638 | if (T.isNull()) |
| 4639 | return SemaRef.ExprError(); |
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 | bool ArgumentChanged = false; |
| 4642 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4643 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4644 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4645 | ArgEnd = E->arg_end(); |
| 4646 | Arg != ArgEnd; ++Arg) { |
| 4647 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4648 | if (TransArg.isInvalid()) |
| 4649 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4652 | FakeCommaLocs.push_back( |
| 4653 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4654 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4656 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | if (!getDerived().AlwaysRebuild() && |
| 4658 | T == E->getTypeAsWritten() && |
| 4659 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4660 | return SemaRef.Owned(E->Retain()); |
| 4661 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4662 | // FIXME: we're faking the locations of the commas |
| 4663 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4664 | T, |
| 4665 | E->getLParenLoc(), |
| 4666 | move_arg(Args), |
| 4667 | FakeCommaLocs.data(), |
| 4668 | E->getRParenLoc()); |
| 4669 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4671 | template<typename Derived> |
| 4672 | Sema::OwningExprResult |
| 4673 | TreeTransform<Derived>::TransformCXXUnresolvedMemberExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4674 | CXXUnresolvedMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4675 | // Transform the base of the expression. |
| 4676 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4677 | if (Base.isInvalid()) |
| 4678 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4680 | // Start the member reference and compute the object's type. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4681 | Sema::TypeTy *ObjectType = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4682 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4683 | E->getOperatorLoc(), |
| 4684 | E->isArrow()? tok::arrow : tok::period, |
| 4685 | ObjectType); |
| 4686 | if (Base.isInvalid()) |
| 4687 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4688 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4689 | // Transform the first part of the nested-name-specifier that qualifies |
| 4690 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4691 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4692 | = getDerived().TransformFirstQualifierInScope( |
| 4693 | E->getFirstQualifierFoundInScope(), |
| 4694 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4695 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4696 | NestedNameSpecifier *Qualifier = 0; |
| 4697 | if (E->getQualifier()) { |
| 4698 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4699 | E->getQualifierRange(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4700 | QualType::getFromOpaquePtr(ObjectType), |
| 4701 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4702 | if (!Qualifier) |
| 4703 | return SemaRef.ExprError(); |
| 4704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4705 | |
| 4706 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4707 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
| 4708 | QualType::getFromOpaquePtr(ObjectType)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4709 | if (!Name) |
| 4710 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4711 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4712 | if (!E->hasExplicitTemplateArgumentList()) { |
| 4713 | // This is a reference to a member without an explicitly-specified |
| 4714 | // template argument list. Optimize for this common case. |
| 4715 | if (!getDerived().AlwaysRebuild() && |
| 4716 | Base.get() == E->getBase() && |
| 4717 | Qualifier == E->getQualifier() && |
| 4718 | Name == E->getMember() && |
| 4719 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4720 | return SemaRef.Owned(E->Retain()); |
| 4721 | |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4722 | return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), |
| 4723 | E->isArrow(), |
| 4724 | E->getOperatorLoc(), |
| 4725 | Qualifier, |
| 4726 | E->getQualifierRange(), |
| 4727 | Name, |
| 4728 | E->getMemberLoc(), |
| 4729 | FirstQualifierInScope); |
| 4730 | } |
| 4731 | |
| 4732 | // FIXME: This is an ugly hack, which forces the same template name to |
| 4733 | // be looked up multiple times. Yuck! |
| 4734 | // FIXME: This also won't work for, e.g., x->template operator+<int> |
| 4735 | TemplateName OrigTemplateName |
| 4736 | = SemaRef.Context.getDependentTemplateName(0, Name.getAsIdentifierInfo()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4737 | |
| 4738 | TemplateName Template |
| 4739 | = getDerived().TransformTemplateName(OrigTemplateName, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4740 | QualType::getFromOpaquePtr(ObjectType)); |
| 4741 | if (Template.isNull()) |
| 4742 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4743 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4744 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4745 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4746 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 4747 | TransArgs[I])) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4748 | return SemaRef.ExprError(); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4749 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4750 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4751 | return getDerived().RebuildCXXUnresolvedMemberExpr(move(Base), |
| 4752 | E->isArrow(), |
| 4753 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4754 | Qualifier, |
| 4755 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4756 | Template, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4757 | E->getMemberLoc(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4758 | FirstQualifierInScope, |
| 4759 | E->getLAngleLoc(), |
| 4760 | TransArgs.data(), |
| 4761 | TransArgs.size(), |
| 4762 | E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | template<typename Derived> |
| 4766 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4767 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| 4768 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4771 | template<typename Derived> |
| 4772 | Sema::OwningExprResult |
| 4773 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | // FIXME: poor source location |
| 4775 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 4776 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 4777 | if (EncodedType.isNull()) |
| 4778 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | if (!getDerived().AlwaysRebuild() && |
| 4781 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4782 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4783 | |
| 4784 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 4785 | EncodedType, |
| 4786 | E->getRParenLoc()); |
| 4787 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | template<typename Derived> |
| 4790 | Sema::OwningExprResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4791 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4792 | // FIXME: Implement this! |
| 4793 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4797 | template<typename Derived> |
| 4798 | Sema::OwningExprResult |
| 4799 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 4800 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | } |
| 4802 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4803 | template<typename Derived> |
| 4804 | Sema::OwningExprResult |
| 4805 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 4806 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | = cast_or_null<ObjCProtocolDecl>( |
| 4808 | getDerived().TransformDecl(E->getProtocol())); |
| 4809 | if (!Protocol) |
| 4810 | return SemaRef.ExprError(); |
| 4811 | |
| 4812 | if (!getDerived().AlwaysRebuild() && |
| 4813 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | return SemaRef.Owned(E->Retain()); |
| 4815 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4816 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 4817 | E->getAtLoc(), |
| 4818 | /*FIXME:*/E->getAtLoc(), |
| 4819 | /*FIXME:*/E->getAtLoc(), |
| 4820 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4824 | template<typename Derived> |
| 4825 | Sema::OwningExprResult |
| 4826 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | // FIXME: Implement this! |
| 4828 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | template<typename Derived> |
| 4833 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4834 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 4835 | // FIXME: Implement this! |
| 4836 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4837 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4840 | template<typename Derived> |
| 4841 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 4842 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | ObjCImplicitSetterGetterRefExpr *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>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4852 | // FIXME: Implement this! |
| 4853 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4857 | template<typename Derived> |
| 4858 | Sema::OwningExprResult |
| 4859 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4860 | // FIXME: Implement this! |
| 4861 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4862 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | template<typename Derived> |
| 4866 | Sema::OwningExprResult |
| 4867 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4868 | bool ArgumentChanged = false; |
| 4869 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 4870 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 4871 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 4872 | if (SubExpr.isInvalid()) |
| 4873 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4874 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4875 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 4876 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 4877 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4878 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4879 | if (!getDerived().AlwaysRebuild() && |
| 4880 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4881 | return SemaRef.Owned(E->Retain()); |
| 4882 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4883 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 4884 | move_arg(SubExprs), |
| 4885 | E->getRParenLoc()); |
| 4886 | } |
| 4887 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4888 | template<typename Derived> |
| 4889 | Sema::OwningExprResult |
| 4890 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | // FIXME: Implement this! |
| 4892 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4893 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4896 | template<typename Derived> |
| 4897 | Sema::OwningExprResult |
| 4898 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4899 | // FIXME: Implement this! |
| 4900 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4902 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4903 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4904 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4905 | // Type reconstruction |
| 4906 | //===----------------------------------------------------------------------===// |
| 4907 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4908 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4909 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4910 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4911 | getDerived().getBaseLocation(), |
| 4912 | getDerived().getBaseEntity()); |
| 4913 | } |
| 4914 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4915 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4916 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4917 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4918 | getDerived().getBaseLocation(), |
| 4919 | getDerived().getBaseEntity()); |
| 4920 | } |
| 4921 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4922 | template<typename Derived> |
| 4923 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4924 | TreeTransform<Derived>::RebuildLValueReferenceType(QualType ReferentType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4925 | return SemaRef.BuildReferenceType(ReferentType, true, 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 |
| 4932 | TreeTransform<Derived>::RebuildRValueReferenceType(QualType ReferentType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4933 | return SemaRef.BuildReferenceType(ReferentType, false, Qualifiers(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | getDerived().getBaseLocation(), |
| 4935 | getDerived().getBaseEntity()); |
| 4936 | } |
| 4937 | |
| 4938 | template<typename Derived> |
| 4939 | QualType TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4940 | QualType ClassType) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4941 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4942 | getDerived().getBaseLocation(), |
| 4943 | getDerived().getBaseEntity()); |
| 4944 | } |
| 4945 | |
| 4946 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4947 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4948 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType) { |
| 4949 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), |
| 4950 | getDerived().getBaseLocation(), |
| 4951 | getDerived().getBaseEntity()); |
| 4952 | } |
| 4953 | |
| 4954 | template<typename Derived> |
| 4955 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4956 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 4957 | ArrayType::ArraySizeModifier SizeMod, |
| 4958 | const llvm::APInt *Size, |
| 4959 | Expr *SizeExpr, |
| 4960 | unsigned IndexTypeQuals, |
| 4961 | SourceRange BracketsRange) { |
| 4962 | if (SizeExpr || !Size) |
| 4963 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 4964 | IndexTypeQuals, BracketsRange, |
| 4965 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4966 | |
| 4967 | QualType Types[] = { |
| 4968 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 4969 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 4970 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4971 | }; |
| 4972 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 4973 | QualType SizeType; |
| 4974 | for (unsigned I = 0; I != NumTypes; ++I) |
| 4975 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 4976 | SizeType = Types[I]; |
| 4977 | break; |
| 4978 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4979 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4980 | if (SizeType.isNull()) |
| 4981 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4982 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4983 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4984 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4985 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4986 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4988 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4989 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4990 | QualType |
| 4991 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4992 | ArrayType::ArraySizeModifier SizeMod, |
| 4993 | const llvm::APInt &Size, |
| 4994 | unsigned IndexTypeQuals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4995 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4996 | IndexTypeQuals, SourceRange()); |
| 4997 | } |
| 4998 | |
| 4999 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5000 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5001 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5002 | ArrayType::ArraySizeModifier SizeMod, |
| 5003 | unsigned IndexTypeQuals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5004 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5005 | IndexTypeQuals, SourceRange()); |
| 5006 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5007 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5008 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5009 | QualType |
| 5010 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5011 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5012 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5013 | unsigned IndexTypeQuals, |
| 5014 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5015 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5016 | SizeExpr.takeAs<Expr>(), |
| 5017 | IndexTypeQuals, BracketsRange); |
| 5018 | } |
| 5019 | |
| 5020 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5021 | QualType |
| 5022 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5023 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5025 | unsigned IndexTypeQuals, |
| 5026 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5027 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5028 | SizeExpr.takeAs<Expr>(), |
| 5029 | IndexTypeQuals, BracketsRange); |
| 5030 | } |
| 5031 | |
| 5032 | template<typename Derived> |
| 5033 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5034 | unsigned NumElements) { |
| 5035 | // FIXME: semantic checking! |
| 5036 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5037 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5038 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5039 | template<typename Derived> |
| 5040 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5041 | unsigned NumElements, |
| 5042 | SourceLocation AttributeLoc) { |
| 5043 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5044 | NumElements, true); |
| 5045 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5046 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5047 | AttributeLoc); |
| 5048 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5049 | AttributeLoc); |
| 5050 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5051 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5052 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | QualType |
| 5054 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5055 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5056 | SourceLocation AttributeLoc) { |
| 5057 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5060 | template<typename Derived> |
| 5061 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5063 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5064 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5065 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5067 | Quals, |
| 5068 | getDerived().getBaseLocation(), |
| 5069 | getDerived().getBaseEntity()); |
| 5070 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5071 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5072 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5073 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5074 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5075 | } |
| 5076 | |
| 5077 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5079 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5080 | } |
| 5081 | |
| 5082 | template<typename Derived> |
| 5083 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5084 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5085 | } |
| 5086 | |
| 5087 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5088 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5089 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5090 | } |
| 5091 | |
| 5092 | template<typename Derived> |
| 5093 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5094 | TemplateName Template, |
| 5095 | SourceLocation TemplateNameLoc, |
| 5096 | SourceLocation LAngleLoc, |
| 5097 | const TemplateArgumentLoc *Args, |
| 5098 | unsigned NumArgs, |
| 5099 | SourceLocation RAngleLoc) { |
| 5100 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, LAngleLoc, |
| 5101 | Args, NumArgs, RAngleLoc); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5102 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5103 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5104 | template<typename Derived> |
| 5105 | NestedNameSpecifier * |
| 5106 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5107 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5108 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5109 | QualType ObjectType, |
| 5110 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5111 | CXXScopeSpec SS; |
| 5112 | // FIXME: The source location information is all wrong. |
| 5113 | SS.setRange(Range); |
| 5114 | SS.setScopeRep(Prefix); |
| 5115 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5117 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5118 | ObjectType, |
| 5119 | FirstQualifierInScope, |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5120 | false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | template<typename Derived> |
| 5124 | NestedNameSpecifier * |
| 5125 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5126 | SourceRange Range, |
| 5127 | NamespaceDecl *NS) { |
| 5128 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5129 | } |
| 5130 | |
| 5131 | template<typename Derived> |
| 5132 | NestedNameSpecifier * |
| 5133 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5134 | SourceRange Range, |
| 5135 | bool TemplateKW, |
| 5136 | QualType T) { |
| 5137 | if (T->isDependentType() || T->isRecordType() || |
| 5138 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5139 | assert(!T.hasQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5140 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5141 | T.getTypePtr()); |
| 5142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5143 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5144 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5145 | return 0; |
| 5146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5147 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5148 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5150 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5151 | bool TemplateKW, |
| 5152 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5153 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5154 | Template); |
| 5155 | } |
| 5156 | |
| 5157 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5159 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5160 | bool TemplateKW, |
| 5161 | OverloadedFunctionDecl *Ovl) { |
| 5162 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl); |
| 5163 | } |
| 5164 | |
| 5165 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5167 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5168 | const IdentifierInfo &II, |
| 5169 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5170 | CXXScopeSpec SS; |
| 5171 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5173 | return getSema().ActOnDependentTemplateName( |
| 5174 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5175 | II, |
| 5176 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5177 | SS, |
| 5178 | ObjectType.getAsOpaquePtr()) |
| 5179 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5182 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5183 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5185 | SourceLocation OpLoc, |
| 5186 | ExprArg Callee, |
| 5187 | ExprArg First, |
| 5188 | ExprArg Second) { |
| 5189 | Expr *FirstExpr = (Expr *)First.get(); |
| 5190 | Expr *SecondExpr = (Expr *)Second.get(); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame^] | 5191 | DeclRefExpr *DRE |
| 5192 | = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5193 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5194 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5195 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame^] | 5196 | if (Op == OO_Subscript) { |
| 5197 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5198 | !SecondExpr->getType()->isOverloadableType()) |
| 5199 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
| 5200 | DRE->getLocStart(), |
| 5201 | move(Second), OpLoc); |
| 5202 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5203 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5204 | // The argument is not of overloadable type, so try to create a |
| 5205 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5206 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5207 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5208 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5209 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5210 | } |
| 5211 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | !SecondExpr->getType()->isOverloadableType()) { |
| 5214 | // Neither of the arguments is an overloadable type, so try to |
| 5215 | // create a built-in binary operation. |
| 5216 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5217 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5218 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5219 | if (Result.isInvalid()) |
| 5220 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5221 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5222 | First.release(); |
| 5223 | Second.release(); |
| 5224 | return move(Result); |
| 5225 | } |
| 5226 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | |
| 5228 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5229 | // used during overload resolution. |
| 5230 | Sema::FunctionSet Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5232 | // FIXME: Do we have to check |
| 5233 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
Douglas Gregor | 32e2c84 | 2009-09-01 16:58:52 +0000 | [diff] [blame] | 5234 | for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5235 | Functions.insert(*F); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | // Add any functions found via argument-dependent lookup. |
| 5238 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5239 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5240 | DeclarationName OpName |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5241 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | c057f42 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5242 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5243 | Functions); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5245 | // Create the overloaded operator invocation for unary operators. |
| 5246 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5247 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5248 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5249 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5251 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame^] | 5252 | if (Op == OO_Subscript) |
| 5253 | return SemaRef.CreateOverloadedArraySubscriptExpr(DRE->getLocStart(), OpLoc, |
| 5254 | move(First),move(Second)); |
| 5255 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5256 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5257 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5258 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5260 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5261 | if (Result.isInvalid()) |
| 5262 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5263 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5264 | First.release(); |
| 5265 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5267 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5268 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5269 | } // end namespace clang |
| 5270 | |
| 5271 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |