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