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" |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 17 | #include "Lookup.h" |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 18 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 23 | #include "clang/AST/Stmt.h" |
| 24 | #include "clang/AST/StmtCXX.h" |
| 25 | #include "clang/AST/StmtObjC.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 26 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 27 | #include "clang/Parse/Ownership.h" |
| 28 | #include "clang/Parse/Designator.h" |
| 29 | #include "clang/Lex/Preprocessor.h" |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 31 | #include <algorithm> |
| 32 | |
| 33 | namespace clang { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 35 | /// \brief A semantic tree transformation that allows one to transform one |
| 36 | /// abstract syntax tree into another. |
| 37 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 39 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 40 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 41 | /// instantiation is implemented as a tree transformation where the |
| 42 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 43 | /// template arguments for their corresponding template parameters; a similar |
| 44 | /// transformation is performed for non-type template parameters and |
| 45 | /// template template parameters. |
| 46 | /// |
| 47 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// override any of the transformation or rebuild operators by providing an |
| 50 | /// operation with the same signature as the default implementation. The |
| 51 | /// overridding function should not be virtual. |
| 52 | /// |
| 53 | /// Semantic tree transformations are split into two stages, either of which |
| 54 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 55 | /// or the parts of an AST node using the various transformation functions, |
| 56 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 57 | /// node of the appropriate kind from the pieces. The default transformation |
| 58 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 59 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 60 | /// were changed by the transformation, invokes the rebuild operation to create |
| 61 | /// a new AST node. |
| 62 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 64 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 65 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 66 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 67 | /// new implementations. |
| 68 | /// |
| 69 | /// For more fine-grained transformations, subclasses can replace any of the |
| 70 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 71 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 72 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 75 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 76 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 77 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 78 | /// be able to use more efficient rebuild steps. |
| 79 | /// |
| 80 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 83 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 84 | /// default locations and entity names used for type-checking |
| 85 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 86 | template<typename Derived> |
| 87 | class TreeTransform { |
| 88 | protected: |
| 89 | Sema &SemaRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
| 91 | public: |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 92 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 93 | typedef Sema::OwningExprResult OwningExprResult; |
| 94 | typedef Sema::StmtArg StmtArg; |
| 95 | typedef Sema::ExprArg ExprArg; |
| 96 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 97 | typedef Sema::MultiStmtArg MultiStmtArg; |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 98 | typedef Sema::DeclPtrTy DeclPtrTy; |
| 99 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 100 | /// \brief Initializes a new tree transformer. |
| 101 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 103 | /// \brief Retrieves a reference to the derived class. |
| 104 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 105 | |
| 106 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | const Derived &getDerived() const { |
| 108 | return static_cast<const Derived&>(*this); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 112 | /// this tree transform. |
| 113 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 115 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 116 | /// if none of the children have changed. |
| 117 | /// |
| 118 | /// Subclasses may override this function to specify when the transformation |
| 119 | /// should rebuild all AST nodes. |
| 120 | bool AlwaysRebuild() { return false; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 122 | /// \brief Returns the location of the entity being transformed, if that |
| 123 | /// information was not available elsewhere in the AST. |
| 124 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 126 | /// provide an alternative implementation that provides better location |
| 127 | /// information. |
| 128 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 130 | /// \brief Returns the name of the entity being transformed, if that |
| 131 | /// information was not available elsewhere in the AST. |
| 132 | /// |
| 133 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 134 | /// implementation with a more precise name. |
| 135 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 136 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 137 | /// \brief Sets the "base" location and entity when that |
| 138 | /// information is known based on another transformation. |
| 139 | /// |
| 140 | /// By default, the source location and entity are ignored. Subclasses can |
| 141 | /// override this function to provide a customized implementation. |
| 142 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 144 | /// \brief RAII object that temporarily sets the base location and entity |
| 145 | /// used for reporting diagnostics in types. |
| 146 | class TemporaryBase { |
| 147 | TreeTransform &Self; |
| 148 | SourceLocation OldLocation; |
| 149 | DeclarationName OldEntity; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 151 | public: |
| 152 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 154 | OldLocation = Self.getDerived().getBaseLocation(); |
| 155 | OldEntity = Self.getDerived().getBaseEntity(); |
| 156 | Self.getDerived().setBase(Location, Entity); |
| 157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 159 | ~TemporaryBase() { |
| 160 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 161 | } |
| 162 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| 164 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// transformed. |
| 166 | /// |
| 167 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 169 | /// not change. For example, template instantiation need not traverse |
| 170 | /// non-dependent types. |
| 171 | bool AlreadyTransformed(QualType T) { |
| 172 | return T.isNull(); |
| 173 | } |
| 174 | |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 175 | /// \brief Determine whether the given call argument should be dropped, e.g., |
| 176 | /// because it is a default argument. |
| 177 | /// |
| 178 | /// Subclasses can provide an alternative implementation of this routine to |
| 179 | /// determine which kinds of call arguments get dropped. By default, |
| 180 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 181 | bool DropCallArgument(Expr *E) { |
| 182 | return E->isDefaultArgument(); |
| 183 | } |
| 184 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 185 | /// \brief Transforms the given type into another type. |
| 186 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 188 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// function. This is expensive, but we don't mind, because |
| 190 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 191 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 192 | /// |
| 193 | /// \returns the transformed type. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 194 | QualType TransformType(QualType T, QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 196 | /// \brief Transforms the given type-with-location into a new |
| 197 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 198 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 199 | /// By default, this routine transforms a type by delegating to the |
| 200 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 201 | /// may override this function (to take over all type |
| 202 | /// transformations) or some set of the TransformXXXType functions |
| 203 | /// to alter the transformation. |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 204 | TypeSourceInfo *TransformType(TypeSourceInfo *DI, |
| 205 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 206 | |
| 207 | /// \brief Transform the given type-with-location into a new |
| 208 | /// type, collecting location information in the given builder |
| 209 | /// as necessary. |
| 210 | /// |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 211 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL, |
| 212 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 214 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 215 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 217 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 218 | /// statement or the TransformExpr() function to transform an expression. |
| 219 | /// Subclasses may override this function to transform statements using some |
| 220 | /// other mechanism. |
| 221 | /// |
| 222 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 223 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 225 | /// \brief Transform the given expression. |
| 226 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 227 | /// By default, this routine transforms an expression by delegating to the |
| 228 | /// appropriate TransformXXXExpr function to build a new expression. |
| 229 | /// Subclasses may override this function to transform expressions using some |
| 230 | /// other mechanism. |
| 231 | /// |
| 232 | /// \returns the transformed expression. |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 233 | OwningExprResult TransformExpr(Expr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 235 | /// \brief Transform the given declaration, which is referenced from a type |
| 236 | /// or expression. |
| 237 | /// |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 238 | /// By default, acts as the identity function on declarations. Subclasses |
| 239 | /// may override this function to provide alternate behavior. |
| 240 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Transform the definition of the given declaration. |
| 243 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 245 | /// Subclasses may override this function to provide alternate behavior. |
| 246 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 248 | /// \brief Transform the given declaration, which was the first part of a |
| 249 | /// nested-name-specifier in a member access expression. |
| 250 | /// |
| 251 | /// This specific declaration transformation only applies to the first |
| 252 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 253 | /// the \c T in \c x->T::member |
| 254 | /// |
| 255 | /// By default, invokes TransformDecl() to transform the declaration. |
| 256 | /// Subclasses may override this function to provide alternate behavior. |
| 257 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 258 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 259 | } |
| 260 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 261 | /// \brief Transform the given nested-name-specifier. |
| 262 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 264 | /// nested-name-specifier. Subclasses may override this function to provide |
| 265 | /// alternate behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 266 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 267 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 268 | QualType ObjectType = QualType(), |
| 269 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 271 | /// \brief Transform the given declaration name. |
| 272 | /// |
| 273 | /// By default, transforms the types of conversion function, constructor, |
| 274 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 275 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 276 | /// override this function to provide alternate behavior. |
| 277 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 278 | SourceLocation Loc, |
| 279 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 281 | /// \brief Transform the given template name. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 285 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 286 | TemplateName TransformTemplateName(TemplateName Name, |
| 287 | QualType ObjectType = QualType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// \brief Transform the given template argument. |
| 290 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | /// By default, this operation transforms the type, expression, or |
| 292 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 293 | /// new template argument from the transformed result. Subclasses may |
| 294 | /// override this function to provide alternate behavior. |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 295 | /// |
| 296 | /// Returns true if there was an error. |
| 297 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 298 | TemplateArgumentLoc &Output); |
| 299 | |
| 300 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 301 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 302 | TemplateArgumentLoc &ArgLoc); |
| 303 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 304 | /// \brief Fakes up a TypeSourceInfo for a type. |
| 305 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 306 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 307 | getDerived().getBaseLocation()); |
| 308 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 310 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 311 | #define TYPELOC(CLASS, PARENT) \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 312 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \ |
| 313 | QualType ObjectType = QualType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 314 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 315 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 316 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL, |
| 317 | QualType ObjectType); |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 318 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 319 | QualType |
| 320 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 321 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 323 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 325 | #define STMT(Node, Parent) \ |
| 326 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 327 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 328 | OwningExprResult Transform##Node(Node *E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 329 | #define ABSTRACT_EXPR(Node, Parent) |
| 330 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 332 | /// \brief Build a new pointer type given its pointee type. |
| 333 | /// |
| 334 | /// By default, performs semantic analysis when building the pointer type. |
| 335 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 336 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 337 | |
| 338 | /// \brief Build a new block pointer type given its pointee type. |
| 339 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 340 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 341 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 342 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 343 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 344 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 345 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 346 | /// By default, performs semantic analysis when building the |
| 347 | /// reference type. Subclasses may override this routine to provide |
| 348 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 349 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 350 | /// \param LValue whether the type was written with an lvalue sigil |
| 351 | /// or an rvalue sigil. |
| 352 | QualType RebuildReferenceType(QualType ReferentType, |
| 353 | bool LValue, |
| 354 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 356 | /// \brief Build a new member pointer type given the pointee type and the |
| 357 | /// class type it refers into. |
| 358 | /// |
| 359 | /// By default, performs semantic analysis when building the member pointer |
| 360 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 361 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 362 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 364 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 365 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 366 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 367 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 368 | /// \brief Build a new array type given the element type, size |
| 369 | /// modifier, size of the array (if known), size expression, and index type |
| 370 | /// qualifiers. |
| 371 | /// |
| 372 | /// By default, performs semantic analysis when building the array type. |
| 373 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 375 | QualType RebuildArrayType(QualType ElementType, |
| 376 | ArrayType::ArraySizeModifier SizeMod, |
| 377 | const llvm::APInt *Size, |
| 378 | Expr *SizeExpr, |
| 379 | unsigned IndexTypeQuals, |
| 380 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 382 | /// \brief Build a new constant array type given the element type, size |
| 383 | /// modifier, (known) size of the array, and index type qualifiers. |
| 384 | /// |
| 385 | /// By default, performs semantic analysis when building the array type. |
| 386 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 388 | ArrayType::ArraySizeModifier SizeMod, |
| 389 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 390 | unsigned IndexTypeQuals, |
| 391 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 392 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | /// \brief Build a new incomplete array type given the element type, size |
| 394 | /// modifier, and index type qualifiers. |
| 395 | /// |
| 396 | /// By default, performs semantic analysis when building the array type. |
| 397 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 399 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 400 | unsigned IndexTypeQuals, |
| 401 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 404 | /// size modifier, size expression, and index type qualifiers. |
| 405 | /// |
| 406 | /// By default, performs semantic analysis when building the array type. |
| 407 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 409 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 410 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 411 | unsigned IndexTypeQuals, |
| 412 | SourceRange BracketsRange); |
| 413 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 414 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 415 | /// size modifier, size expression, and index type qualifiers. |
| 416 | /// |
| 417 | /// By default, performs semantic analysis when building the array type. |
| 418 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 420 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 421 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 422 | unsigned IndexTypeQuals, |
| 423 | SourceRange BracketsRange); |
| 424 | |
| 425 | /// \brief Build a new vector type given the element type and |
| 426 | /// number of elements. |
| 427 | /// |
| 428 | /// By default, performs semantic analysis when building the vector type. |
| 429 | /// Subclasses may override this routine to provide different behavior. |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 430 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 431 | bool IsAltiVec, bool IsPixel); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | /// \brief Build a new extended vector type given the element type and |
| 434 | /// number of elements. |
| 435 | /// |
| 436 | /// By default, performs semantic analysis when building the vector type. |
| 437 | /// Subclasses may override this routine to provide different behavior. |
| 438 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 439 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | /// given the element type and number of elements. |
| 443 | /// |
| 444 | /// By default, performs semantic analysis when building the vector type. |
| 445 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 448 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new function type. |
| 451 | /// |
| 452 | /// By default, performs semantic analysis when building the function type. |
| 453 | /// Subclasses may override this routine to provide different behavior. |
| 454 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | unsigned NumParamTypes, |
| 457 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 459 | /// \brief Build a new unprototyped function type. |
| 460 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 461 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 462 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 463 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 464 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 465 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 466 | /// \brief Build a new typedef type. |
| 467 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 468 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 469 | } |
| 470 | |
| 471 | /// \brief Build a new class/struct/union type. |
| 472 | QualType RebuildRecordType(RecordDecl *Record) { |
| 473 | return SemaRef.Context.getTypeDeclType(Record); |
| 474 | } |
| 475 | |
| 476 | /// \brief Build a new Enum type. |
| 477 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 478 | return SemaRef.Context.getTypeDeclType(Enum); |
| 479 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 480 | |
| 481 | /// \brief Build a new elaborated type. |
| 482 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 483 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
| 486 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 487 | /// |
| 488 | /// By default, performs semantic analysis when building the typeof type. |
| 489 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 490 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 491 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | /// |
| 494 | /// By default, builds a new TypeOfType with the given underlying type. |
| 495 | QualType RebuildTypeOfType(QualType Underlying); |
| 496 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 498 | /// |
| 499 | /// By default, performs semantic analysis when building the decltype type. |
| 500 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 501 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 503 | /// \brief Build a new template specialization type. |
| 504 | /// |
| 505 | /// By default, performs semantic analysis when building the template |
| 506 | /// specialization type. Subclasses may override this routine to provide |
| 507 | /// different behavior. |
| 508 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 509 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 510 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// \brief Build a new qualified name type. |
| 513 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | /// By default, builds a new QualifiedNameType type from the |
| 515 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 516 | /// this routine to provide different behavior. |
| 517 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 518 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 520 | |
| 521 | /// \brief Build a new typename type that refers to a template-id. |
| 522 | /// |
| 523 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 525 | /// different behavior. |
| 526 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 527 | if (NNS->isDependent()) { |
| 528 | CXXScopeSpec SS; |
| 529 | SS.setScopeRep(NNS); |
| 530 | if (!SemaRef.computeDeclContext(SS)) |
| 531 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 532 | cast<TemplateSpecializationType>(T)); |
Douglas Gregor | 04922cb | 2010-02-13 06:05:33 +0000 | [diff] [blame] | 533 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 534 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 535 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 537 | |
| 538 | /// \brief Build a new typename type that refers to an identifier. |
| 539 | /// |
| 540 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 541 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 542 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 544 | const IdentifierInfo *Id, |
| 545 | SourceRange SR) { |
| 546 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 549 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 550 | /// identifier that names the next step in the nested-name-specifier. |
| 551 | /// |
| 552 | /// By default, performs semantic analysis when building the new |
| 553 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 554 | /// different behavior. |
| 555 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 556 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 557 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 558 | QualType ObjectType, |
| 559 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 560 | |
| 561 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 562 | /// namespace named in the next step in the nested-name-specifier. |
| 563 | /// |
| 564 | /// By default, performs semantic analysis when building the new |
| 565 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 566 | /// different behavior. |
| 567 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 568 | SourceRange Range, |
| 569 | NamespaceDecl *NS); |
| 570 | |
| 571 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 572 | /// type named in the next step in the nested-name-specifier. |
| 573 | /// |
| 574 | /// By default, performs semantic analysis when building the new |
| 575 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 576 | /// different behavior. |
| 577 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 578 | SourceRange Range, |
| 579 | bool TemplateKW, |
| 580 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 581 | |
| 582 | /// \brief Build a new template name given a nested name specifier, a flag |
| 583 | /// indicating whether the "template" keyword was provided, and the template |
| 584 | /// that the template name refers to. |
| 585 | /// |
| 586 | /// By default, builds the new template name directly. Subclasses may override |
| 587 | /// this routine to provide different behavior. |
| 588 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 589 | bool TemplateKW, |
| 590 | TemplateDecl *Template); |
| 591 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 592 | /// \brief Build a new template name given a nested name specifier and the |
| 593 | /// name that is referred to as a template. |
| 594 | /// |
| 595 | /// By default, performs semantic analysis to determine whether the name can |
| 596 | /// be resolved to a specific template, then builds the appropriate kind of |
| 597 | /// template name. Subclasses may override this routine to provide different |
| 598 | /// behavior. |
| 599 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 600 | const IdentifierInfo &II, |
| 601 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 603 | /// \brief Build a new template name given a nested name specifier and the |
| 604 | /// overloaded operator name that is referred to as a template. |
| 605 | /// |
| 606 | /// By default, performs semantic analysis to determine whether the name can |
| 607 | /// be resolved to a specific template, then builds the appropriate kind of |
| 608 | /// template name. Subclasses may override this routine to provide different |
| 609 | /// behavior. |
| 610 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 611 | OverloadedOperatorKind Operator, |
| 612 | QualType ObjectType); |
| 613 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 614 | /// \brief Build a new compound statement. |
| 615 | /// |
| 616 | /// By default, performs semantic analysis to build the new statement. |
| 617 | /// Subclasses may override this routine to provide different behavior. |
| 618 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 619 | MultiStmtArg Statements, |
| 620 | SourceLocation RBraceLoc, |
| 621 | bool IsStmtExpr) { |
| 622 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 623 | IsStmtExpr); |
| 624 | } |
| 625 | |
| 626 | /// \brief Build a new case statement. |
| 627 | /// |
| 628 | /// By default, performs semantic analysis to build the new statement. |
| 629 | /// Subclasses may override this routine to provide different behavior. |
| 630 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 631 | ExprArg LHS, |
| 632 | SourceLocation EllipsisLoc, |
| 633 | ExprArg RHS, |
| 634 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 636 | ColonLoc); |
| 637 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 639 | /// \brief Attach the body to a new case statement. |
| 640 | /// |
| 641 | /// By default, performs semantic analysis to build the new statement. |
| 642 | /// Subclasses may override this routine to provide different behavior. |
| 643 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 644 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 645 | return move(S); |
| 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 default 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 RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 653 | SourceLocation ColonLoc, |
| 654 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 656 | /*CurScope=*/0); |
| 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 label 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 RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 664 | IdentifierInfo *Id, |
| 665 | SourceLocation ColonLoc, |
| 666 | StmtArg SubStmt) { |
| 667 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 670 | /// \brief Build a new "if" statement. |
| 671 | /// |
| 672 | /// By default, performs semantic analysis to build the new statement. |
| 673 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 675 | VarDecl *CondVar, StmtArg Then, |
| 676 | SourceLocation ElseLoc, StmtArg Else) { |
| 677 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 678 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 679 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 680 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 681 | /// \brief Start building a new switch statement. |
| 682 | /// |
| 683 | /// By default, performs semantic analysis to build the new statement. |
| 684 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 685 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 686 | VarDecl *CondVar) { |
| 687 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 688 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 690 | /// \brief Attach the body to the switch statement. |
| 691 | /// |
| 692 | /// By default, performs semantic analysis to build the new statement. |
| 693 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 695 | StmtArg Switch, StmtArg Body) { |
| 696 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 697 | move(Body)); |
| 698 | } |
| 699 | |
| 700 | /// \brief Build a new while statement. |
| 701 | /// |
| 702 | /// By default, performs semantic analysis to build the new statement. |
| 703 | /// Subclasses may override this routine to provide different behavior. |
| 704 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 705 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 706 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 707 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 708 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 709 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 710 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 712 | /// \brief Build a new do-while statement. |
| 713 | /// |
| 714 | /// By default, performs semantic analysis to build the new statement. |
| 715 | /// Subclasses may override this routine to provide different behavior. |
| 716 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 717 | SourceLocation WhileLoc, |
| 718 | SourceLocation LParenLoc, |
| 719 | ExprArg Cond, |
| 720 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 722 | move(Cond), RParenLoc); |
| 723 | } |
| 724 | |
| 725 | /// \brief Build a new for statement. |
| 726 | /// |
| 727 | /// By default, performs semantic analysis to build the new statement. |
| 728 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 730 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 731 | StmtArg Init, Sema::FullExprArg Cond, |
| 732 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 733 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 734 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 735 | DeclPtrTy::make(CondVar), |
| 736 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 737 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 739 | /// \brief Build a new goto statement. |
| 740 | /// |
| 741 | /// By default, performs semantic analysis to build the new statement. |
| 742 | /// Subclasses may override this routine to provide different behavior. |
| 743 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 744 | SourceLocation LabelLoc, |
| 745 | LabelStmt *Label) { |
| 746 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 747 | } |
| 748 | |
| 749 | /// \brief Build a new indirect goto statement. |
| 750 | /// |
| 751 | /// By default, performs semantic analysis to build the new statement. |
| 752 | /// Subclasses may override this routine to provide different behavior. |
| 753 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 754 | SourceLocation StarLoc, |
| 755 | ExprArg Target) { |
| 756 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 757 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 759 | /// \brief Build a new return statement. |
| 760 | /// |
| 761 | /// By default, performs semantic analysis to build the new statement. |
| 762 | /// Subclasses may override this routine to provide different behavior. |
| 763 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 764 | ExprArg Result) { |
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 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 769 | /// \brief Build a new declaration statement. |
| 770 | /// |
| 771 | /// By default, performs semantic analysis to build the new statement. |
| 772 | /// Subclasses may override this routine to provide different behavior. |
| 773 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 775 | SourceLocation EndLoc) { |
| 776 | return getSema().Owned( |
| 777 | new (getSema().Context) DeclStmt( |
| 778 | DeclGroupRef::Create(getSema().Context, |
| 779 | Decls, NumDecls), |
| 780 | StartLoc, EndLoc)); |
| 781 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 783 | /// \brief Build a new inline asm statement. |
| 784 | /// |
| 785 | /// By default, performs semantic analysis to build the new statement. |
| 786 | /// Subclasses may override this routine to provide different behavior. |
| 787 | OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc, |
| 788 | bool IsSimple, |
| 789 | bool IsVolatile, |
| 790 | unsigned NumOutputs, |
| 791 | unsigned NumInputs, |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 792 | IdentifierInfo **Names, |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 793 | MultiExprArg Constraints, |
| 794 | MultiExprArg Exprs, |
| 795 | ExprArg AsmString, |
| 796 | MultiExprArg Clobbers, |
| 797 | SourceLocation RParenLoc, |
| 798 | bool MSAsm) { |
| 799 | return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 800 | NumInputs, Names, move(Constraints), |
| 801 | move(Exprs), move(AsmString), move(Clobbers), |
| 802 | RParenLoc, MSAsm); |
| 803 | } |
| 804 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 805 | /// \brief Build a new C++ exception declaration. |
| 806 | /// |
| 807 | /// By default, performs semantic analysis to build the new decaration. |
| 808 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 810 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 811 | IdentifierInfo *Name, |
| 812 | SourceLocation Loc, |
| 813 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 814 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 815 | TypeRange); |
| 816 | } |
| 817 | |
| 818 | /// \brief Build a new C++ catch statement. |
| 819 | /// |
| 820 | /// By default, performs semantic analysis to build the new statement. |
| 821 | /// Subclasses may override this routine to provide different behavior. |
| 822 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 823 | VarDecl *ExceptionDecl, |
| 824 | StmtArg Handler) { |
| 825 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 827 | Handler.takeAs<Stmt>())); |
| 828 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 830 | /// \brief Build a new C++ try statement. |
| 831 | /// |
| 832 | /// By default, performs semantic analysis to build the new statement. |
| 833 | /// Subclasses may override this routine to provide different behavior. |
| 834 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 835 | StmtArg TryBlock, |
| 836 | MultiStmtArg Handlers) { |
| 837 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 840 | /// \brief Build a new expression that references a declaration. |
| 841 | /// |
| 842 | /// By default, performs semantic analysis to build the new expression. |
| 843 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 844 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 845 | LookupResult &R, |
| 846 | bool RequiresADL) { |
| 847 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /// \brief Build a new expression that references a declaration. |
| 852 | /// |
| 853 | /// By default, performs semantic analysis to build the new expression. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 855 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 856 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 857 | ValueDecl *VD, SourceLocation Loc, |
| 858 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 859 | CXXScopeSpec SS; |
| 860 | SS.setScopeRep(Qualifier); |
| 861 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 862 | |
| 863 | // FIXME: loses template args. |
| 864 | |
| 865 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 866 | } |
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 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 870 | /// By default, performs semantic analysis to build the new expression. |
| 871 | /// Subclasses may override this routine to provide different behavior. |
| 872 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 873 | SourceLocation RParen) { |
| 874 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 875 | } |
| 876 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 877 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 878 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 879 | /// By default, performs semantic analysis to build the new expression. |
| 880 | /// Subclasses may override this routine to provide different behavior. |
| 881 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 882 | SourceLocation OperatorLoc, |
| 883 | bool isArrow, |
| 884 | SourceLocation DestroyedTypeLoc, |
| 885 | QualType DestroyedType, |
| 886 | NestedNameSpecifier *Qualifier, |
| 887 | SourceRange QualifierRange) { |
| 888 | CXXScopeSpec SS; |
| 889 | if (Qualifier) { |
| 890 | SS.setRange(QualifierRange); |
| 891 | SS.setScopeRep(Qualifier); |
| 892 | } |
| 893 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 894 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 895 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 896 | DeclarationName Name |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 897 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 898 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 899 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 900 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 901 | OperatorLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 902 | SS, /*FIXME: FirstQualifier*/ 0, |
| 903 | Name, DestroyedTypeLoc, |
| 904 | /*TemplateArgs*/ 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 907 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | /// By default, performs semantic analysis to build the new expression. |
| 910 | /// Subclasses may override this routine to provide different behavior. |
| 911 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 912 | UnaryOperator::Opcode Opc, |
| 913 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 914 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 915 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 917 | /// \brief Build a new sizeof or alignof expression with a type argument. |
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. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 921 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 922 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 923 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 924 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 928 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 930 | /// By default, performs semantic analysis to build the new expression. |
| 931 | /// Subclasses may override this routine to provide different behavior. |
| 932 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 933 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 935 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 936 | OpLoc, isSizeOf, R); |
| 937 | if (Result.isInvalid()) |
| 938 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 940 | SubExpr.release(); |
| 941 | return move(Result); |
| 942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 944 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 945 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 946 | /// By default, performs semantic analysis to build the new expression. |
| 947 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 949 | SourceLocation LBracketLoc, |
| 950 | ExprArg RHS, |
| 951 | SourceLocation RBracketLoc) { |
| 952 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 954 | RBracketLoc); |
| 955 | } |
| 956 | |
| 957 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 959 | /// By default, performs semantic analysis to build the new expression. |
| 960 | /// Subclasses may override this routine to provide different behavior. |
| 961 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 962 | MultiExprArg Args, |
| 963 | SourceLocation *CommaLocs, |
| 964 | SourceLocation RParenLoc) { |
| 965 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 966 | move(Args), CommaLocs, RParenLoc); |
| 967 | } |
| 968 | |
| 969 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 971 | /// By default, performs semantic analysis to build the new expression. |
| 972 | /// Subclasses may override this routine to provide different behavior. |
| 973 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 975 | NestedNameSpecifier *Qualifier, |
| 976 | SourceRange QualifierRange, |
| 977 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 978 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 979 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 980 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 981 | if (!Member->getDeclName()) { |
| 982 | // We have a reference to an unnamed field. |
| 983 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 985 | Expr *BaseExpr = Base.takeAs<Expr>(); |
| 986 | if (getSema().PerformObjectMemberConversion(BaseExpr, Member)) |
| 987 | return getSema().ExprError(); |
Douglas Gregor | 4b65441 | 2009-12-24 20:23:34 +0000 | [diff] [blame] | 988 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | MemberExpr *ME = |
Douglas Gregor | 8e8eaa1 | 2009-12-24 20:02:50 +0000 | [diff] [blame] | 990 | new (getSema().Context) MemberExpr(BaseExpr, isArrow, |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 991 | Member, MemberLoc, |
| 992 | cast<FieldDecl>(Member)->getType()); |
| 993 | return getSema().Owned(ME); |
| 994 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 996 | CXXScopeSpec SS; |
| 997 | if (Qualifier) { |
| 998 | SS.setRange(QualifierRange); |
| 999 | SS.setScopeRep(Qualifier); |
| 1000 | } |
| 1001 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1002 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1003 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1004 | LookupResult R(getSema(), Member->getDeclName(), MemberLoc, |
| 1005 | Sema::LookupMemberName); |
| 1006 | R.addDecl(Member); |
| 1007 | R.resolveKind(); |
| 1008 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1009 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 1010 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1011 | SS, FirstQualifierInScope, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1012 | R, ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1013 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1015 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1016 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1017 | /// By default, performs semantic analysis to build the new expression. |
| 1018 | /// Subclasses may override this routine to provide different behavior. |
| 1019 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 1020 | BinaryOperator::Opcode Opc, |
| 1021 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 1022 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 1023 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1028 | /// By default, performs semantic analysis to build the new expression. |
| 1029 | /// Subclasses may override this routine to provide different behavior. |
| 1030 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1031 | SourceLocation QuestionLoc, |
| 1032 | ExprArg LHS, |
| 1033 | SourceLocation ColonLoc, |
| 1034 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1036 | move(LHS), move(RHS)); |
| 1037 | } |
| 1038 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1039 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1041 | /// By default, performs semantic analysis to build the new expression. |
| 1042 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1043 | OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 1044 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1045 | SourceLocation RParenLoc, |
| 1046 | ExprArg SubExpr) { |
John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 1047 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 1048 | move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1051 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | /// By default, performs semantic analysis to build the new expression. |
| 1054 | /// Subclasses may override this routine to provide different behavior. |
| 1055 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1056 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1057 | SourceLocation RParenLoc, |
| 1058 | ExprArg Init) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 1059 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 1060 | move(Init)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1063 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1065 | /// By default, performs semantic analysis to build the new expression. |
| 1066 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1068 | SourceLocation OpLoc, |
| 1069 | SourceLocation AccessorLoc, |
| 1070 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1071 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1072 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1073 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1074 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1075 | OpLoc, /*IsArrow*/ false, |
| 1076 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1077 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1078 | AccessorLoc, |
| 1079 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1080 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1082 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1084 | /// By default, performs semantic analysis to build the new expression. |
| 1085 | /// Subclasses may override this routine to provide different behavior. |
| 1086 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1087 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1088 | SourceLocation RBraceLoc, |
| 1089 | QualType ResultTy) { |
| 1090 | OwningExprResult Result |
| 1091 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1092 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1093 | return move(Result); |
| 1094 | |
| 1095 | // Patch in the result type we were given, which may have been computed |
| 1096 | // when the initial InitListExpr was built. |
| 1097 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1098 | ILE->setType(ResultTy); |
| 1099 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1100 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1102 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | /// By default, performs semantic analysis to build the new expression. |
| 1105 | /// Subclasses may override this routine to provide different behavior. |
| 1106 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1107 | MultiExprArg ArrayExprs, |
| 1108 | SourceLocation EqualOrColonLoc, |
| 1109 | bool GNUSyntax, |
| 1110 | ExprArg Init) { |
| 1111 | OwningExprResult Result |
| 1112 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1113 | move(Init)); |
| 1114 | if (Result.isInvalid()) |
| 1115 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | ArrayExprs.release(); |
| 1118 | return move(Result); |
| 1119 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1121 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1123 | /// By default, builds the implicit value initialization without performing |
| 1124 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1125 | /// different behavior. |
| 1126 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1127 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1128 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1132 | /// By default, performs semantic analysis to build the new expression. |
| 1133 | /// Subclasses may override this routine to provide different behavior. |
| 1134 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1135 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1137 | RParenLoc); |
| 1138 | } |
| 1139 | |
| 1140 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1142 | /// By default, performs semantic analysis to build the new expression. |
| 1143 | /// Subclasses may override this routine to provide different behavior. |
| 1144 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1145 | MultiExprArg SubExprs, |
| 1146 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1147 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1148 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1152 | /// |
| 1153 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1154 | /// rather than attempting to map the label statement itself. |
| 1155 | /// Subclasses may override this routine to provide different behavior. |
| 1156 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1157 | SourceLocation LabelLoc, |
| 1158 | LabelStmt *Label) { |
| 1159 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1160 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1162 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1164 | /// By default, performs semantic analysis to build the new expression. |
| 1165 | /// Subclasses may override this routine to provide different behavior. |
| 1166 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1167 | StmtArg SubStmt, |
| 1168 | SourceLocation RParenLoc) { |
| 1169 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1170 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1172 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1173 | /// |
| 1174 | /// By default, performs semantic analysis to build the new expression. |
| 1175 | /// Subclasses may override this routine to provide different behavior. |
| 1176 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1177 | QualType T1, QualType T2, |
| 1178 | SourceLocation RParenLoc) { |
| 1179 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1180 | T1.getAsOpaquePtr(), |
| 1181 | T2.getAsOpaquePtr(), |
| 1182 | RParenLoc); |
| 1183 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1185 | /// \brief Build a new __builtin_choose_expr expression. |
| 1186 | /// |
| 1187 | /// By default, performs semantic analysis to build the new expression. |
| 1188 | /// Subclasses may override this routine to provide different behavior. |
| 1189 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1190 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1191 | SourceLocation RParenLoc) { |
| 1192 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1193 | move(Cond), move(LHS), move(RHS), |
| 1194 | RParenLoc); |
| 1195 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1197 | /// \brief Build a new overloaded operator call expression. |
| 1198 | /// |
| 1199 | /// By default, performs semantic analysis to build the new expression. |
| 1200 | /// The semantic analysis provides the behavior of template instantiation, |
| 1201 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1203 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1204 | /// provide different behavior. |
| 1205 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1206 | SourceLocation OpLoc, |
| 1207 | ExprArg Callee, |
| 1208 | ExprArg First, |
| 1209 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | |
| 1211 | /// \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] | 1212 | /// reinterpret_cast. |
| 1213 | /// |
| 1214 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1216 | /// Subclasses may override this routine to provide different behavior. |
| 1217 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1218 | Stmt::StmtClass Class, |
| 1219 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1220 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | SourceLocation RAngleLoc, |
| 1222 | SourceLocation LParenLoc, |
| 1223 | ExprArg SubExpr, |
| 1224 | SourceLocation RParenLoc) { |
| 1225 | switch (Class) { |
| 1226 | case Stmt::CXXStaticCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1227 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1229 | move(SubExpr), RParenLoc); |
| 1230 | |
| 1231 | case Stmt::CXXDynamicCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1232 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1236 | case Stmt::CXXReinterpretCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1237 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | RAngleLoc, LParenLoc, |
| 1239 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1242 | case Stmt::CXXConstCastExprClass: |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1243 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1245 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1247 | default: |
| 1248 | assert(false && "Invalid C++ named cast"); |
| 1249 | break; |
| 1250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1252 | return getSema().ExprError(); |
| 1253 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1255 | /// \brief Build a new C++ static_cast expression. |
| 1256 | /// |
| 1257 | /// By default, performs semantic analysis to build the new expression. |
| 1258 | /// Subclasses may override this routine to provide different behavior. |
| 1259 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1260 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1261 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1262 | SourceLocation RAngleLoc, |
| 1263 | SourceLocation LParenLoc, |
| 1264 | ExprArg SubExpr, |
| 1265 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1266 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 1267 | TInfo, move(SubExpr), |
| 1268 | SourceRange(LAngleLoc, RAngleLoc), |
| 1269 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /// \brief Build a new C++ dynamic_cast expression. |
| 1273 | /// |
| 1274 | /// By default, performs semantic analysis to build the new expression. |
| 1275 | /// Subclasses may override this routine to provide different behavior. |
| 1276 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1277 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1278 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1279 | SourceLocation RAngleLoc, |
| 1280 | SourceLocation LParenLoc, |
| 1281 | ExprArg SubExpr, |
| 1282 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1283 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 1284 | TInfo, move(SubExpr), |
| 1285 | SourceRange(LAngleLoc, RAngleLoc), |
| 1286 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to build the new expression. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1294 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1295 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1296 | SourceLocation RAngleLoc, |
| 1297 | SourceLocation LParenLoc, |
| 1298 | ExprArg SubExpr, |
| 1299 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1300 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1301 | TInfo, move(SubExpr), |
| 1302 | SourceRange(LAngleLoc, RAngleLoc), |
| 1303 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /// \brief Build a new C++ const_cast expression. |
| 1307 | /// |
| 1308 | /// By default, performs semantic analysis to build the new expression. |
| 1309 | /// Subclasses may override this routine to provide different behavior. |
| 1310 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1311 | SourceLocation LAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1312 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1313 | SourceLocation RAngleLoc, |
| 1314 | SourceLocation LParenLoc, |
| 1315 | ExprArg SubExpr, |
| 1316 | SourceLocation RParenLoc) { |
John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 1317 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 1318 | TInfo, move(SubExpr), |
| 1319 | SourceRange(LAngleLoc, RAngleLoc), |
| 1320 | SourceRange(LParenLoc, RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1321 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1323 | /// \brief Build a new C++ functional-style cast expression. |
| 1324 | /// |
| 1325 | /// By default, performs semantic analysis to build the new expression. |
| 1326 | /// Subclasses may override this routine to provide different behavior. |
| 1327 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1328 | TypeSourceInfo *TInfo, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | SourceLocation LParenLoc, |
| 1330 | ExprArg SubExpr, |
| 1331 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1332 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 1334 | TInfo->getType().getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1335 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1336 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1337 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1338 | RParenLoc); |
| 1339 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1341 | /// \brief Build a new C++ typeid(type) expression. |
| 1342 | /// |
| 1343 | /// By default, performs semantic analysis to build the new expression. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| 1345 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1346 | SourceLocation LParenLoc, |
| 1347 | QualType T, |
| 1348 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1350 | T.getAsOpaquePtr(), 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++ typeid(expr) expression. |
| 1354 | /// |
| 1355 | /// By default, performs semantic analysis to build the new expression. |
| 1356 | /// Subclasses may override this routine to provide different behavior. |
| 1357 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1358 | SourceLocation LParenLoc, |
| 1359 | ExprArg Operand, |
| 1360 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1361 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1362 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1363 | RParenLoc); |
| 1364 | if (Result.isInvalid()) |
| 1365 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1367 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1368 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1371 | /// \brief Build a new C++ "this" expression. |
| 1372 | /// |
| 1373 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1377 | QualType ThisType, |
| 1378 | bool isImplicit) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1379 | return getSema().Owned( |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 1380 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, |
| 1381 | isImplicit)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /// \brief Build a new C++ throw expression. |
| 1385 | /// |
| 1386 | /// By default, performs semantic analysis to build the new expression. |
| 1387 | /// Subclasses may override this routine to provide different behavior. |
| 1388 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1389 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1390 | } |
| 1391 | |
| 1392 | /// \brief Build a new C++ default-argument expression. |
| 1393 | /// |
| 1394 | /// By default, builds a new default-argument expression, which does not |
| 1395 | /// require any semantic analysis. Subclasses may override this routine to |
| 1396 | /// provide different behavior. |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 1397 | OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| 1398 | ParmVarDecl *Param) { |
| 1399 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, |
| 1400 | Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | /// \brief Build a new C++ zero-initialization expression. |
| 1404 | /// |
| 1405 | /// By default, performs semantic analysis to build the new expression. |
| 1406 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1408 | SourceLocation LParenLoc, |
| 1409 | QualType T, |
| 1410 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1412 | T.getAsOpaquePtr(), LParenLoc, |
| 1413 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1414 | 0, RParenLoc); |
| 1415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1417 | /// \brief Build a new C++ "new" expression. |
| 1418 | /// |
| 1419 | /// By default, performs semantic analysis to build the new expression. |
| 1420 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1421 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1422 | bool UseGlobal, |
| 1423 | SourceLocation PlacementLParen, |
| 1424 | MultiExprArg PlacementArgs, |
| 1425 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1426 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1427 | QualType AllocType, |
| 1428 | SourceLocation TypeLoc, |
| 1429 | SourceRange TypeRange, |
| 1430 | ExprArg ArraySize, |
| 1431 | SourceLocation ConstructorLParen, |
| 1432 | MultiExprArg ConstructorArgs, |
| 1433 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1435 | PlacementLParen, |
| 1436 | move(PlacementArgs), |
| 1437 | PlacementRParen, |
| 1438 | ParenTypeId, |
| 1439 | AllocType, |
| 1440 | TypeLoc, |
| 1441 | TypeRange, |
| 1442 | move(ArraySize), |
| 1443 | ConstructorLParen, |
| 1444 | move(ConstructorArgs), |
| 1445 | ConstructorRParen); |
| 1446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1448 | /// \brief Build a new C++ "delete" expression. |
| 1449 | /// |
| 1450 | /// By default, performs semantic analysis to build the new expression. |
| 1451 | /// Subclasses may override this routine to provide different behavior. |
| 1452 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1453 | bool IsGlobalDelete, |
| 1454 | bool IsArrayForm, |
| 1455 | ExprArg Operand) { |
| 1456 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1457 | move(Operand)); |
| 1458 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1459 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | /// \brief Build a new unary type trait expression. |
| 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new expression. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
| 1464 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1465 | SourceLocation StartLoc, |
| 1466 | SourceLocation LParenLoc, |
| 1467 | QualType T, |
| 1468 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1469 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1470 | T.getAsOpaquePtr(), RParenLoc); |
| 1471 | } |
| 1472 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1474 | /// expression. |
| 1475 | /// |
| 1476 | /// By default, performs semantic analysis to build the new expression. |
| 1477 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1478 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1479 | SourceRange QualifierRange, |
| 1480 | DeclarationName Name, |
| 1481 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1482 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1483 | CXXScopeSpec SS; |
| 1484 | SS.setRange(QualifierRange); |
| 1485 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1486 | |
| 1487 | if (TemplateArgs) |
| 1488 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1489 | *TemplateArgs); |
| 1490 | |
| 1491 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /// \brief Build a new template-id expression. |
| 1495 | /// |
| 1496 | /// By default, performs semantic analysis to build the new expression. |
| 1497 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1498 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1499 | LookupResult &R, |
| 1500 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1501 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1502 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | /// \brief Build a new object-construction expression. |
| 1506 | /// |
| 1507 | /// By default, performs semantic analysis to build the new expression. |
| 1508 | /// Subclasses may override this routine to provide different behavior. |
| 1509 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1510 | SourceLocation Loc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1511 | CXXConstructorDecl *Constructor, |
| 1512 | bool IsElidable, |
| 1513 | MultiExprArg Args) { |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 1514 | ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef); |
| 1515 | if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, |
| 1516 | ConvertedArgs)) |
| 1517 | return getSema().ExprError(); |
| 1518 | |
| 1519 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, |
| 1520 | move_arg(ConvertedArgs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /// \brief Build a new object-construction expression. |
| 1524 | /// |
| 1525 | /// By default, performs semantic analysis to build the new expression. |
| 1526 | /// Subclasses may override this routine to provide different behavior. |
| 1527 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1528 | QualType T, |
| 1529 | SourceLocation LParenLoc, |
| 1530 | MultiExprArg Args, |
| 1531 | SourceLocation *Commas, |
| 1532 | SourceLocation RParenLoc) { |
| 1533 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1534 | T.getAsOpaquePtr(), |
| 1535 | LParenLoc, |
| 1536 | move(Args), |
| 1537 | Commas, |
| 1538 | RParenLoc); |
| 1539 | } |
| 1540 | |
| 1541 | /// \brief Build a new object-construction expression. |
| 1542 | /// |
| 1543 | /// By default, performs semantic analysis to build the new expression. |
| 1544 | /// Subclasses may override this routine to provide different behavior. |
| 1545 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1546 | QualType T, |
| 1547 | SourceLocation LParenLoc, |
| 1548 | MultiExprArg Args, |
| 1549 | SourceLocation *Commas, |
| 1550 | SourceLocation RParenLoc) { |
| 1551 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1552 | /*FIXME*/LParenLoc), |
| 1553 | T.getAsOpaquePtr(), |
| 1554 | LParenLoc, |
| 1555 | move(Args), |
| 1556 | Commas, |
| 1557 | RParenLoc); |
| 1558 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1560 | /// \brief Build a new member reference expression. |
| 1561 | /// |
| 1562 | /// By default, performs semantic analysis to build the new expression. |
| 1563 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1564 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1565 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1566 | bool IsArrow, |
| 1567 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1568 | NestedNameSpecifier *Qualifier, |
| 1569 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1570 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1571 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1572 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1573 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1574 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1575 | SS.setRange(QualifierRange); |
| 1576 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1578 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1579 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1580 | SS, FirstQualifierInScope, |
| 1581 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1584 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1585 | /// |
| 1586 | /// By default, performs semantic analysis to build the new expression. |
| 1587 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1588 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1589 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1590 | SourceLocation OperatorLoc, |
| 1591 | bool IsArrow, |
| 1592 | NestedNameSpecifier *Qualifier, |
| 1593 | SourceRange QualifierRange, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1594 | NamedDecl *FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1595 | LookupResult &R, |
| 1596 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1597 | CXXScopeSpec SS; |
| 1598 | SS.setRange(QualifierRange); |
| 1599 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1600 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1601 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1602 | OperatorLoc, IsArrow, |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 1603 | SS, FirstQualifierInScope, |
| 1604 | R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1605 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1607 | /// \brief Build a new Objective-C @encode expression. |
| 1608 | /// |
| 1609 | /// By default, performs semantic analysis to build the new expression. |
| 1610 | /// Subclasses may override this routine to provide different behavior. |
| 1611 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1612 | QualType T, |
| 1613 | SourceLocation RParenLoc) { |
| 1614 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1615 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1617 | |
| 1618 | /// \brief Build a new Objective-C protocol expression. |
| 1619 | /// |
| 1620 | /// By default, performs semantic analysis to build the new expression. |
| 1621 | /// Subclasses may override this routine to provide different behavior. |
| 1622 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1623 | SourceLocation AtLoc, |
| 1624 | SourceLocation ProtoLoc, |
| 1625 | SourceLocation LParenLoc, |
| 1626 | SourceLocation RParenLoc) { |
| 1627 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1628 | Protocol->getIdentifier(), |
| 1629 | AtLoc, |
| 1630 | ProtoLoc, |
| 1631 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1632 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1633 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1635 | /// \brief Build a new shuffle vector expression. |
| 1636 | /// |
| 1637 | /// By default, performs semantic analysis to build the new expression. |
| 1638 | /// Subclasses may override this routine to provide different behavior. |
| 1639 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1640 | MultiExprArg SubExprs, |
| 1641 | SourceLocation RParenLoc) { |
| 1642 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1644 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1645 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1646 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1647 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1649 | // Build a reference to the __builtin_shufflevector builtin |
| 1650 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1652 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1653 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1654 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
| 1656 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1657 | unsigned NumSubExprs = SubExprs.size(); |
| 1658 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1659 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1660 | Subs, NumSubExprs, |
| 1661 | Builtin->getResultType(), |
| 1662 | RParenLoc); |
| 1663 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1665 | // Type-check the __builtin_shufflevector expression. |
| 1666 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1667 | if (Result.isInvalid()) |
| 1668 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1669 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1670 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1672 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1673 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1674 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1675 | template<typename Derived> |
| 1676 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1677 | if (!S) |
| 1678 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1680 | switch (S->getStmtClass()) { |
| 1681 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1683 | // Transform individual statement nodes |
| 1684 | #define STMT(Node, Parent) \ |
| 1685 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1686 | #define EXPR(Node, Parent) |
| 1687 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1688 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1689 | // Transform expressions by calling TransformExpr. |
| 1690 | #define STMT(Node, Parent) |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1691 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1692 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1693 | #include "clang/AST/StmtNodes.def" |
| 1694 | { |
| 1695 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1696 | if (E.isInvalid()) |
| 1697 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 1699 | return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1700 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1703 | return SemaRef.Owned(S->Retain()); |
| 1704 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | |
| 1706 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1707 | template<typename Derived> |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1708 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1709 | if (!E) |
| 1710 | return SemaRef.Owned(E); |
| 1711 | |
| 1712 | switch (E->getStmtClass()) { |
| 1713 | case Stmt::NoStmtClass: break; |
| 1714 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
John McCall | 2adddca | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1715 | #define ABSTRACT_EXPR(Node, Parent) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1716 | #define EXPR(Node, Parent) \ |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 1717 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1718 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1721 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1725 | NestedNameSpecifier * |
| 1726 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1727 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1728 | QualType ObjectType, |
| 1729 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1730 | if (!NNS) |
| 1731 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1733 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1735 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1737 | ObjectType, |
| 1738 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1739 | if (!Prefix) |
| 1740 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
| 1742 | // 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] | 1743 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1744 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1745 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 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 | switch (NNS->getKind()) { |
| 1749 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1751 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1752 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1753 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1754 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
| 1756 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1757 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1758 | ObjectType, |
| 1759 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1761 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | = cast_or_null<NamespaceDecl>( |
| 1764 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1765 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1766 | Prefix == NNS->getPrefix() && |
| 1767 | NS == NNS->getAsNamespace()) |
| 1768 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1770 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1771 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1773 | case NestedNameSpecifier::Global: |
| 1774 | // There is no meaningful transformation that one could perform on the |
| 1775 | // global scope. |
| 1776 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1778 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1779 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1780 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 1781 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0), |
| 1782 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1783 | if (T.isNull()) |
| 1784 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1785 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1786 | if (!getDerived().AlwaysRebuild() && |
| 1787 | Prefix == NNS->getPrefix() && |
| 1788 | T == QualType(NNS->getAsType(), 0)) |
| 1789 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | |
| 1791 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1792 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1793 | T); |
| 1794 | } |
| 1795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1797 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1802 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1803 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1804 | SourceLocation Loc, |
| 1805 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | if (!Name) |
| 1807 | return Name; |
| 1808 | |
| 1809 | switch (Name.getNameKind()) { |
| 1810 | case DeclarationName::Identifier: |
| 1811 | case DeclarationName::ObjCZeroArgSelector: |
| 1812 | case DeclarationName::ObjCOneArgSelector: |
| 1813 | case DeclarationName::ObjCMultiArgSelector: |
| 1814 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1815 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1816 | case DeclarationName::CXXUsingDirective: |
| 1817 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1819 | case DeclarationName::CXXConstructorName: |
| 1820 | case DeclarationName::CXXDestructorName: |
| 1821 | case DeclarationName::CXXConversionFunctionName: { |
| 1822 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 1823 | QualType T = getDerived().TransformType(Name.getCXXNameType(), |
| 1824 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1825 | if (T.isNull()) |
| 1826 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1827 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1828 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1830 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1831 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1834 | return DeclarationName(); |
| 1835 | } |
| 1836 | |
| 1837 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1839 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1840 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1843 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 1844 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1845 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1846 | if (!NNS) |
| 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 (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1851 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1852 | if (!TransTemplate) |
| 1853 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1855 | if (!getDerived().AlwaysRebuild() && |
| 1856 | NNS == QTN->getQualifier() && |
| 1857 | TransTemplate == Template) |
| 1858 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1860 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1861 | TransTemplate); |
| 1862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1864 | // These should be getting filtered out before they make it into the AST. |
| 1865 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1866 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1867 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1868 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1869 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1870 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 1871 | /*FIXME:*/SourceRange(getDerived().getBaseLocation()), |
| 1872 | ObjectType); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1873 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1874 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1877 | NNS == DTN->getQualifier() && |
| 1878 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1879 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1881 | if (DTN->isIdentifier()) |
| 1882 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1883 | ObjectType); |
| 1884 | |
| 1885 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1886 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1887 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1889 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1890 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1891 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1892 | if (!TransTemplate) |
| 1893 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1894 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1895 | if (!getDerived().AlwaysRebuild() && |
| 1896 | TransTemplate == Template) |
| 1897 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1899 | return TemplateName(TransTemplate); |
| 1900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1902 | // These should be getting filtered out before they reach the AST. |
| 1903 | assert(false && "overloaded function decl survived to here"); |
| 1904 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1908 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1909 | const TemplateArgument &Arg, |
| 1910 | TemplateArgumentLoc &Output) { |
| 1911 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1912 | switch (Arg.getKind()) { |
| 1913 | case TemplateArgument::Null: |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1914 | llvm_unreachable("null template argument in TreeTransform"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1915 | break; |
| 1916 | |
| 1917 | case TemplateArgument::Type: |
| 1918 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1919 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1920 | |
| 1921 | break; |
| 1922 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1923 | case TemplateArgument::Template: |
| 1924 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1925 | break; |
| 1926 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1927 | case TemplateArgument::Expression: |
| 1928 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1929 | break; |
| 1930 | |
| 1931 | case TemplateArgument::Declaration: |
| 1932 | case TemplateArgument::Integral: |
| 1933 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1934 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1935 | break; |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | template<typename Derived> |
| 1940 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1941 | const TemplateArgumentLoc &Input, |
| 1942 | TemplateArgumentLoc &Output) { |
| 1943 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1944 | switch (Arg.getKind()) { |
| 1945 | case TemplateArgument::Null: |
| 1946 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1947 | Output = Input; |
| 1948 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1949 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1950 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1951 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1952 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1953 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1954 | |
| 1955 | DI = getDerived().TransformType(DI); |
| 1956 | if (!DI) return true; |
| 1957 | |
| 1958 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1959 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1962 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1963 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1964 | DeclarationName Name; |
| 1965 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1966 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1967 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1968 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1969 | if (!D) return true; |
| 1970 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1971 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1972 | if (SourceExpr) { |
| 1973 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1974 | Action::Unevaluated); |
| 1975 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1976 | if (E.isInvalid()) |
| 1977 | SourceExpr = NULL; |
| 1978 | else { |
| 1979 | SourceExpr = E.takeAs<Expr>(); |
| 1980 | SourceExpr->Retain(); |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1985 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1987 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1988 | case TemplateArgument::Template: { |
| 1989 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1990 | TemplateName Template |
| 1991 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1992 | if (Template.isNull()) |
| 1993 | return true; |
| 1994 | |
| 1995 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1996 | Input.getTemplateQualifierRange(), |
| 1997 | Input.getTemplateNameLoc()); |
| 1998 | return false; |
| 1999 | } |
| 2000 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2001 | case TemplateArgument::Expression: { |
| 2002 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2004 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2005 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2006 | Expr *InputExpr = Input.getSourceExpression(); |
| 2007 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2008 | |
| 2009 | Sema::OwningExprResult E |
| 2010 | = getDerived().TransformExpr(InputExpr); |
| 2011 | if (E.isInvalid()) return true; |
| 2012 | |
| 2013 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2014 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2016 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2017 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2019 | case TemplateArgument::Pack: { |
| 2020 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2021 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2023 | AEnd = Arg.pack_end(); |
| 2024 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2026 | // FIXME: preserve source information here when we start |
| 2027 | // caring about parameter packs. |
| 2028 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2029 | TemplateArgumentLoc InputArg; |
| 2030 | TemplateArgumentLoc OutputArg; |
| 2031 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2032 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2033 | return true; |
| 2034 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2035 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2036 | } |
| 2037 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2039 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2040 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2041 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2042 | } |
| 2043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2045 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2046 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2049 | //===----------------------------------------------------------------------===// |
| 2050 | // Type transformation |
| 2051 | //===----------------------------------------------------------------------===// |
| 2052 | |
| 2053 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2054 | QualType TreeTransform<Derived>::TransformType(QualType T, |
| 2055 | QualType ObjectType) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2056 | if (getDerived().AlreadyTransformed(T)) |
| 2057 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2059 | // Temporary workaround. All of these transformations should |
| 2060 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2061 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2062 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2063 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2064 | TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2065 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2066 | if (!NewDI) |
| 2067 | return QualType(); |
| 2068 | |
| 2069 | return NewDI->getType(); |
| 2070 | } |
| 2071 | |
| 2072 | template<typename Derived> |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2073 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI, |
| 2074 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2075 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2076 | return DI; |
| 2077 | |
| 2078 | TypeLocBuilder TLB; |
| 2079 | |
| 2080 | TypeLoc TL = DI->getTypeLoc(); |
| 2081 | TLB.reserve(TL.getFullDataSize()); |
| 2082 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2083 | QualType Result = getDerived().TransformType(TLB, TL, ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2084 | if (Result.isNull()) |
| 2085 | return 0; |
| 2086 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2087 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | template<typename Derived> |
| 2091 | QualType |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2092 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T, |
| 2093 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2094 | switch (T.getTypeLocClass()) { |
| 2095 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2096 | #define TYPELOC(CLASS, PARENT) \ |
| 2097 | case TypeLoc::CLASS: \ |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2098 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \ |
| 2099 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2100 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2101 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2102 | |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 2103 | llvm_unreachable("unhandled type loc!"); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2104 | return QualType(); |
| 2105 | } |
| 2106 | |
| 2107 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2108 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2109 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2110 | /// types). This is the right thing for template instantiation, but |
| 2111 | /// probably not for other clients. |
| 2112 | template<typename Derived> |
| 2113 | QualType |
| 2114 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2115 | QualifiedTypeLoc T, |
| 2116 | QualType ObjectType) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2117 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2118 | |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2119 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(), |
| 2120 | ObjectType); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2121 | if (Result.isNull()) |
| 2122 | return QualType(); |
| 2123 | |
| 2124 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2125 | // FIXME: this is the right thing for template instantiation, but |
| 2126 | // probably not for other clients. |
| 2127 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2128 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2129 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2130 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2131 | |
| 2132 | TLB.push<QualifiedTypeLoc>(Result); |
| 2133 | |
| 2134 | // No location information to preserve. |
| 2135 | |
| 2136 | return Result; |
| 2137 | } |
| 2138 | |
| 2139 | template <class TyLoc> static inline |
| 2140 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2141 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2142 | NewT.setNameLoc(T.getNameLoc()); |
| 2143 | return T.getType(); |
| 2144 | } |
| 2145 | |
| 2146 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2147 | // the equivalent template version work. |
| 2148 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2149 | QualType PointeeType \ |
| 2150 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2151 | if (PointeeType.isNull()) \ |
| 2152 | return QualType(); \ |
| 2153 | \ |
| 2154 | QualType Result = TL.getType(); \ |
| 2155 | if (getDerived().AlwaysRebuild() || \ |
| 2156 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2157 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2158 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2159 | if (Result.isNull()) \ |
| 2160 | return QualType(); \ |
| 2161 | } \ |
| 2162 | \ |
| 2163 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2164 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2165 | \ |
| 2166 | return Result; \ |
| 2167 | } while(0) |
| 2168 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2169 | template<typename Derived> |
| 2170 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2171 | BuiltinTypeLoc T, |
| 2172 | QualType ObjectType) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2173 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 2174 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 2175 | if (T.needsExtraLocalData()) |
| 2176 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 2177 | return T.getType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +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, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2182 | ComplexTypeLoc T, |
| 2183 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2184 | // FIXME: recurse? |
| 2185 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2186 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2187 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2188 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2189 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2190 | PointerTypeLoc TL, |
| 2191 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2192 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2193 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2194 | |
| 2195 | template<typename Derived> |
| 2196 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2197 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2198 | BlockPointerTypeLoc TL, |
| 2199 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2200 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2203 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2204 | /// don't care whether the type itself is an l-value type or an r-value |
| 2205 | /// type; we only care if the type was *written* as an l-value type |
| 2206 | /// or an r-value type. |
| 2207 | template<typename Derived> |
| 2208 | QualType |
| 2209 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2210 | ReferenceTypeLoc TL, |
| 2211 | QualType ObjectType) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2212 | const ReferenceType *T = TL.getTypePtr(); |
| 2213 | |
| 2214 | // Note that this works with the pointee-as-written. |
| 2215 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2216 | if (PointeeType.isNull()) |
| 2217 | return QualType(); |
| 2218 | |
| 2219 | QualType Result = TL.getType(); |
| 2220 | if (getDerived().AlwaysRebuild() || |
| 2221 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2222 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2223 | T->isSpelledAsLValue(), |
| 2224 | TL.getSigilLoc()); |
| 2225 | if (Result.isNull()) |
| 2226 | return QualType(); |
| 2227 | } |
| 2228 | |
| 2229 | // r-value references can be rebuilt as l-value references. |
| 2230 | ReferenceTypeLoc NewTL; |
| 2231 | if (isa<LValueReferenceType>(Result)) |
| 2232 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2233 | else |
| 2234 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2235 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2236 | |
| 2237 | return Result; |
| 2238 | } |
| 2239 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | template<typename Derived> |
| 2241 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2242 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2243 | LValueReferenceTypeLoc TL, |
| 2244 | QualType ObjectType) { |
| 2245 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2248 | template<typename Derived> |
| 2249 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2251 | RValueReferenceTypeLoc TL, |
| 2252 | QualType ObjectType) { |
| 2253 | return TransformReferenceType(TLB, TL, ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2256 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2257 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2258 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2259 | MemberPointerTypeLoc TL, |
| 2260 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2261 | MemberPointerType *T = TL.getTypePtr(); |
| 2262 | |
| 2263 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2264 | if (PointeeType.isNull()) |
| 2265 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2266 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2267 | // TODO: preserve source information for this. |
| 2268 | QualType ClassType |
| 2269 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2270 | if (ClassType.isNull()) |
| 2271 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2272 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2273 | QualType Result = TL.getType(); |
| 2274 | if (getDerived().AlwaysRebuild() || |
| 2275 | PointeeType != T->getPointeeType() || |
| 2276 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2277 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2278 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2279 | if (Result.isNull()) |
| 2280 | return QualType(); |
| 2281 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2282 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2283 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2284 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2285 | |
| 2286 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2289 | template<typename Derived> |
| 2290 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2291 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2292 | ConstantArrayTypeLoc TL, |
| 2293 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2294 | ConstantArrayType *T = TL.getTypePtr(); |
| 2295 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2296 | if (ElementType.isNull()) |
| 2297 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2298 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2299 | QualType Result = TL.getType(); |
| 2300 | if (getDerived().AlwaysRebuild() || |
| 2301 | ElementType != T->getElementType()) { |
| 2302 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2303 | T->getSizeModifier(), |
| 2304 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2305 | T->getIndexTypeCVRQualifiers(), |
| 2306 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2307 | if (Result.isNull()) |
| 2308 | return QualType(); |
| 2309 | } |
| 2310 | |
| 2311 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2312 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2313 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2314 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2315 | Expr *Size = TL.getSizeExpr(); |
| 2316 | if (Size) { |
| 2317 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2318 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2319 | } |
| 2320 | NewTL.setSizeExpr(Size); |
| 2321 | |
| 2322 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2323 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2324 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2325 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2326 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2327 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2328 | IncompleteArrayTypeLoc TL, |
| 2329 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2330 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2331 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2332 | if (ElementType.isNull()) |
| 2333 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2334 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2335 | QualType Result = TL.getType(); |
| 2336 | if (getDerived().AlwaysRebuild() || |
| 2337 | ElementType != T->getElementType()) { |
| 2338 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2339 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2340 | T->getIndexTypeCVRQualifiers(), |
| 2341 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2342 | if (Result.isNull()) |
| 2343 | return QualType(); |
| 2344 | } |
| 2345 | |
| 2346 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2347 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2348 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2349 | NewTL.setSizeExpr(0); |
| 2350 | |
| 2351 | return Result; |
| 2352 | } |
| 2353 | |
| 2354 | template<typename Derived> |
| 2355 | QualType |
| 2356 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2357 | VariableArrayTypeLoc TL, |
| 2358 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2359 | VariableArrayType *T = TL.getTypePtr(); |
| 2360 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2361 | if (ElementType.isNull()) |
| 2362 | return QualType(); |
| 2363 | |
| 2364 | // Array bounds are not potentially evaluated contexts |
| 2365 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2366 | |
| 2367 | Sema::OwningExprResult SizeResult |
| 2368 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2369 | if (SizeResult.isInvalid()) |
| 2370 | return QualType(); |
| 2371 | |
| 2372 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2373 | |
| 2374 | QualType Result = TL.getType(); |
| 2375 | if (getDerived().AlwaysRebuild() || |
| 2376 | ElementType != T->getElementType() || |
| 2377 | Size != T->getSizeExpr()) { |
| 2378 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2379 | T->getSizeModifier(), |
| 2380 | move(SizeResult), |
| 2381 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2382 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2383 | if (Result.isNull()) |
| 2384 | return QualType(); |
| 2385 | } |
| 2386 | else SizeResult.take(); |
| 2387 | |
| 2388 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2389 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2390 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2391 | NewTL.setSizeExpr(Size); |
| 2392 | |
| 2393 | return Result; |
| 2394 | } |
| 2395 | |
| 2396 | template<typename Derived> |
| 2397 | QualType |
| 2398 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2399 | DependentSizedArrayTypeLoc TL, |
| 2400 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2401 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2402 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2403 | if (ElementType.isNull()) |
| 2404 | return QualType(); |
| 2405 | |
| 2406 | // Array bounds are not potentially evaluated contexts |
| 2407 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2408 | |
| 2409 | Sema::OwningExprResult SizeResult |
| 2410 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2411 | if (SizeResult.isInvalid()) |
| 2412 | return QualType(); |
| 2413 | |
| 2414 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2415 | |
| 2416 | QualType Result = TL.getType(); |
| 2417 | if (getDerived().AlwaysRebuild() || |
| 2418 | ElementType != T->getElementType() || |
| 2419 | Size != T->getSizeExpr()) { |
| 2420 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2421 | T->getSizeModifier(), |
| 2422 | move(SizeResult), |
| 2423 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2424 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2425 | if (Result.isNull()) |
| 2426 | return QualType(); |
| 2427 | } |
| 2428 | else SizeResult.take(); |
| 2429 | |
| 2430 | // We might have any sort of array type now, but fortunately they |
| 2431 | // all have the same location layout. |
| 2432 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2433 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2434 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2435 | NewTL.setSizeExpr(Size); |
| 2436 | |
| 2437 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2438 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | |
| 2440 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2441 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2442 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2443 | DependentSizedExtVectorTypeLoc TL, |
| 2444 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2445 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2446 | |
| 2447 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2448 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2449 | if (ElementType.isNull()) |
| 2450 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2452 | // Vector sizes are not potentially evaluated contexts |
| 2453 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2454 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2455 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2456 | if (Size.isInvalid()) |
| 2457 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2458 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2459 | QualType Result = TL.getType(); |
| 2460 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2461 | ElementType != T->getElementType() || |
| 2462 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2464 | move(Size), |
| 2465 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2466 | if (Result.isNull()) |
| 2467 | return QualType(); |
| 2468 | } |
| 2469 | else Size.take(); |
| 2470 | |
| 2471 | // Result might be dependent or not. |
| 2472 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2473 | DependentSizedExtVectorTypeLoc NewTL |
| 2474 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2475 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2476 | } else { |
| 2477 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2478 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2479 | } |
| 2480 | |
| 2481 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2482 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2483 | |
| 2484 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2485 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2486 | VectorTypeLoc TL, |
| 2487 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2488 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2489 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2490 | if (ElementType.isNull()) |
| 2491 | return QualType(); |
| 2492 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2493 | QualType Result = TL.getType(); |
| 2494 | if (getDerived().AlwaysRebuild() || |
| 2495 | ElementType != T->getElementType()) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2496 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 2497 | T->isAltiVec(), T->isPixel()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2498 | if (Result.isNull()) |
| 2499 | return QualType(); |
| 2500 | } |
| 2501 | |
| 2502 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2503 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2504 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2505 | return Result; |
| 2506 | } |
| 2507 | |
| 2508 | template<typename Derived> |
| 2509 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2510 | ExtVectorTypeLoc TL, |
| 2511 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2512 | VectorType *T = TL.getTypePtr(); |
| 2513 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2514 | if (ElementType.isNull()) |
| 2515 | return QualType(); |
| 2516 | |
| 2517 | QualType Result = TL.getType(); |
| 2518 | if (getDerived().AlwaysRebuild() || |
| 2519 | ElementType != T->getElementType()) { |
| 2520 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2521 | T->getNumElements(), |
| 2522 | /*FIXME*/ SourceLocation()); |
| 2523 | if (Result.isNull()) |
| 2524 | return QualType(); |
| 2525 | } |
| 2526 | |
| 2527 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2528 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2529 | |
| 2530 | return Result; |
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 | |
| 2533 | template<typename Derived> |
| 2534 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2535 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2536 | FunctionProtoTypeLoc TL, |
| 2537 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2538 | FunctionProtoType *T = TL.getTypePtr(); |
| 2539 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | if (ResultType.isNull()) |
| 2541 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2542 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2543 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2544 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2545 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2546 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2547 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2548 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2549 | QualType NewType; |
| 2550 | ParmVarDecl *NewParm; |
| 2551 | |
| 2552 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2553 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2554 | assert(OldDI->getType() == T->getArgType(i)); |
| 2555 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2556 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2557 | if (!NewDI) |
| 2558 | return QualType(); |
| 2559 | |
| 2560 | if (NewDI == OldDI) |
| 2561 | NewParm = OldParm; |
| 2562 | else |
| 2563 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2564 | OldParm->getDeclContext(), |
| 2565 | OldParm->getLocation(), |
| 2566 | OldParm->getIdentifier(), |
| 2567 | NewDI->getType(), |
| 2568 | NewDI, |
| 2569 | OldParm->getStorageClass(), |
| 2570 | /* DefArg */ NULL); |
| 2571 | NewType = NewParm->getType(); |
| 2572 | |
| 2573 | // Deal with the possibility that we don't have a parameter |
| 2574 | // declaration for this parameter. |
| 2575 | } else { |
| 2576 | NewParm = 0; |
| 2577 | |
| 2578 | QualType OldType = T->getArgType(i); |
| 2579 | NewType = getDerived().TransformType(OldType); |
| 2580 | if (NewType.isNull()) |
| 2581 | return QualType(); |
| 2582 | } |
| 2583 | |
| 2584 | ParamTypes.push_back(NewType); |
| 2585 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2586 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2587 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2588 | QualType Result = TL.getType(); |
| 2589 | if (getDerived().AlwaysRebuild() || |
| 2590 | ResultType != T->getResultType() || |
| 2591 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2592 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2593 | ParamTypes.data(), |
| 2594 | ParamTypes.size(), |
| 2595 | T->isVariadic(), |
| 2596 | T->getTypeQuals()); |
| 2597 | if (Result.isNull()) |
| 2598 | return QualType(); |
| 2599 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2601 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2602 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2603 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2604 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2605 | NewTL.setArg(i, ParamDecls[i]); |
| 2606 | |
| 2607 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2609 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2610 | template<typename Derived> |
| 2611 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2612 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2613 | FunctionNoProtoTypeLoc TL, |
| 2614 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2615 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2616 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2617 | if (ResultType.isNull()) |
| 2618 | return QualType(); |
| 2619 | |
| 2620 | QualType Result = TL.getType(); |
| 2621 | if (getDerived().AlwaysRebuild() || |
| 2622 | ResultType != T->getResultType()) |
| 2623 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2624 | |
| 2625 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2626 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2627 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2628 | |
| 2629 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2630 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2631 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2632 | template<typename Derived> QualType |
| 2633 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2634 | UnresolvedUsingTypeLoc TL, |
| 2635 | QualType ObjectType) { |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2636 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2637 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2638 | if (!D) |
| 2639 | return QualType(); |
| 2640 | |
| 2641 | QualType Result = TL.getType(); |
| 2642 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2643 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2644 | if (Result.isNull()) |
| 2645 | return QualType(); |
| 2646 | } |
| 2647 | |
| 2648 | // We might get an arbitrary type spec type back. We should at |
| 2649 | // least always get a type spec type, though. |
| 2650 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2651 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2652 | |
| 2653 | return Result; |
| 2654 | } |
| 2655 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2656 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2657 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2658 | TypedefTypeLoc TL, |
| 2659 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2660 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2661 | TypedefDecl *Typedef |
| 2662 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2663 | if (!Typedef) |
| 2664 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2665 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2666 | QualType Result = TL.getType(); |
| 2667 | if (getDerived().AlwaysRebuild() || |
| 2668 | Typedef != T->getDecl()) { |
| 2669 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2670 | if (Result.isNull()) |
| 2671 | return QualType(); |
| 2672 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2673 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2674 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2675 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2676 | |
| 2677 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2678 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2679 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2681 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2682 | TypeOfExprTypeLoc TL, |
| 2683 | QualType ObjectType) { |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2684 | // typeof expressions are not potentially evaluated contexts |
| 2685 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2686 | |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2687 | Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2688 | if (E.isInvalid()) |
| 2689 | return QualType(); |
| 2690 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2691 | QualType Result = TL.getType(); |
| 2692 | if (getDerived().AlwaysRebuild() || |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2693 | E.get() != TL.getUnderlyingExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2695 | if (Result.isNull()) |
| 2696 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2697 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2698 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2699 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2700 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2701 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2702 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2703 | NewTL.setRParenLoc(TL.getRParenLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2704 | |
| 2705 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2706 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2707 | |
| 2708 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2709 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2710 | TypeOfTypeLoc TL, |
| 2711 | QualType ObjectType) { |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2712 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 2713 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 2714 | if (!New_Under_TI) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2715 | return QualType(); |
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 | QualType Result = TL.getType(); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2718 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 2719 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2720 | if (Result.isNull()) |
| 2721 | return QualType(); |
| 2722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2723 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2724 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 2725 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 2726 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2727 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2728 | NewTL.setUnderlyingTInfo(New_Under_TI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2729 | |
| 2730 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2732 | |
| 2733 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2734 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2735 | DecltypeTypeLoc TL, |
| 2736 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2737 | DecltypeType *T = TL.getTypePtr(); |
| 2738 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2739 | // decltype expressions are not potentially evaluated contexts |
| 2740 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2742 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2743 | if (E.isInvalid()) |
| 2744 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2745 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2746 | QualType Result = TL.getType(); |
| 2747 | if (getDerived().AlwaysRebuild() || |
| 2748 | E.get() != T->getUnderlyingExpr()) { |
| 2749 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2750 | if (Result.isNull()) |
| 2751 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2752 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2753 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2755 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2756 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2757 | |
| 2758 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2762 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2763 | RecordTypeLoc TL, |
| 2764 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2765 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2766 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2767 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2768 | if (!Record) |
| 2769 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2770 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2771 | QualType Result = TL.getType(); |
| 2772 | if (getDerived().AlwaysRebuild() || |
| 2773 | Record != T->getDecl()) { |
| 2774 | Result = getDerived().RebuildRecordType(Record); |
| 2775 | if (Result.isNull()) |
| 2776 | return QualType(); |
| 2777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2778 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2779 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2780 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2781 | |
| 2782 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2784 | |
| 2785 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2786 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2787 | EnumTypeLoc TL, |
| 2788 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2789 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2790 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2791 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2792 | if (!Enum) |
| 2793 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2795 | QualType Result = TL.getType(); |
| 2796 | if (getDerived().AlwaysRebuild() || |
| 2797 | Enum != T->getDecl()) { |
| 2798 | Result = getDerived().RebuildEnumType(Enum); |
| 2799 | if (Result.isNull()) |
| 2800 | return QualType(); |
| 2801 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2802 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2803 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2804 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2805 | |
| 2806 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2807 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2808 | |
| 2809 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2810 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2811 | ElaboratedTypeLoc TL, |
| 2812 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2813 | ElaboratedType *T = TL.getTypePtr(); |
| 2814 | |
| 2815 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2816 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2817 | if (Underlying.isNull()) |
| 2818 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2819 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2820 | QualType Result = TL.getType(); |
| 2821 | if (getDerived().AlwaysRebuild() || |
| 2822 | Underlying != T->getUnderlyingType()) { |
| 2823 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2824 | if (Result.isNull()) |
| 2825 | return QualType(); |
| 2826 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2827 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2828 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2829 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2830 | |
| 2831 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2833 | |
| 2834 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2835 | template<typename Derived> |
| 2836 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2837 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2838 | TemplateTypeParmTypeLoc TL, |
| 2839 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2840 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2843 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2844 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2845 | TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2846 | SubstTemplateTypeParmTypeLoc TL, |
| 2847 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2848 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2852 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2853 | const TemplateSpecializationType *TST, |
| 2854 | QualType ObjectType) { |
| 2855 | // FIXME: this entire method is a temporary workaround; callers |
| 2856 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2857 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2858 | // Fake up a TemplateSpecializationTypeLoc. |
| 2859 | TypeLocBuilder TLB; |
| 2860 | TemplateSpecializationTypeLoc TL |
| 2861 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2862 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2863 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2864 | |
| 2865 | TL.setTemplateNameLoc(BaseLoc); |
| 2866 | TL.setLAngleLoc(BaseLoc); |
| 2867 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2868 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2869 | const TemplateArgument &TA = TST->getArg(i); |
| 2870 | TemplateArgumentLoc TAL; |
| 2871 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2872 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2873 | } |
| 2874 | |
| 2875 | TypeLocBuilder IgnoredTLB; |
| 2876 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2880 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2881 | TypeLocBuilder &TLB, |
| 2882 | TemplateSpecializationTypeLoc TL, |
| 2883 | QualType ObjectType) { |
| 2884 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2885 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2886 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2887 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2888 | if (Template.isNull()) |
| 2889 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2890 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2891 | TemplateArgumentListInfo NewTemplateArgs; |
| 2892 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2893 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2894 | |
| 2895 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2896 | TemplateArgumentLoc Loc; |
| 2897 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2898 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2899 | NewTemplateArgs.addArgument(Loc); |
| 2900 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2901 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2902 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2903 | |
| 2904 | QualType Result = |
| 2905 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2906 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2907 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2908 | |
| 2909 | if (!Result.isNull()) { |
| 2910 | TemplateSpecializationTypeLoc NewTL |
| 2911 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2912 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2913 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2914 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2915 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2916 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2917 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2918 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2919 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
| 2922 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2923 | QualType |
| 2924 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2925 | QualifiedNameTypeLoc TL, |
| 2926 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2927 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2928 | NestedNameSpecifier *NNS |
| 2929 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2930 | SourceRange(), |
| 2931 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2932 | if (!NNS) |
| 2933 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2935 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2936 | if (Named.isNull()) |
| 2937 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2938 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2939 | QualType Result = TL.getType(); |
| 2940 | if (getDerived().AlwaysRebuild() || |
| 2941 | NNS != T->getQualifier() || |
| 2942 | Named != T->getNamedType()) { |
| 2943 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2944 | if (Result.isNull()) |
| 2945 | return QualType(); |
| 2946 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2947 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2948 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2949 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2950 | |
| 2951 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2952 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | |
| 2954 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2955 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2956 | TypenameTypeLoc TL, |
| 2957 | QualType ObjectType) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2958 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2959 | |
| 2960 | /* FIXME: preserve source information better than this */ |
| 2961 | SourceRange SR(TL.getNameLoc()); |
| 2962 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2963 | NestedNameSpecifier *NNS |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2964 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR, |
| 2965 | ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2966 | if (!NNS) |
| 2967 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2969 | QualType Result; |
| 2970 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2971 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2972 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2973 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2974 | if (NewTemplateId.isNull()) |
| 2975 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2977 | if (!getDerived().AlwaysRebuild() && |
| 2978 | NNS == T->getQualifier() && |
| 2979 | NewTemplateId == QualType(TemplateId, 0)) |
| 2980 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2981 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2982 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2983 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2984 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2985 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2986 | if (Result.isNull()) |
| 2987 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2988 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2989 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2990 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2991 | |
| 2992 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2993 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2995 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2996 | QualType |
| 2997 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 2998 | ObjCInterfaceTypeLoc TL, |
| 2999 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3000 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 3001 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | |
| 3004 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 3005 | QualType |
| 3006 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame^] | 3007 | ObjCObjectPointerTypeLoc TL, |
| 3008 | QualType ObjectType) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3009 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 3010 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3013 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3014 | // Statement transformation |
| 3015 | //===----------------------------------------------------------------------===// |
| 3016 | template<typename Derived> |
| 3017 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 3019 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | template<typename Derived> |
| 3023 | Sema::OwningStmtResult |
| 3024 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 3025 | return getDerived().TransformCompoundStmt(S, false); |
| 3026 | } |
| 3027 | |
| 3028 | template<typename Derived> |
| 3029 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3030 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3031 | bool IsStmtExpr) { |
| 3032 | bool SubStmtChanged = false; |
| 3033 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 3034 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 3035 | B != BEnd; ++B) { |
| 3036 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3037 | if (Result.isInvalid()) |
| 3038 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3040 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3041 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3042 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3043 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3044 | if (!getDerived().AlwaysRebuild() && |
| 3045 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3047 | |
| 3048 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3049 | move_arg(Statements), |
| 3050 | S->getRBracLoc(), |
| 3051 | IsStmtExpr); |
| 3052 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3054 | template<typename Derived> |
| 3055 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3056 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3057 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3058 | { |
| 3059 | // The case value expressions are not potentially evaluated. |
| 3060 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3062 | // Transform the left-hand case value. |
| 3063 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3064 | if (LHS.isInvalid()) |
| 3065 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3067 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3068 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3069 | if (RHS.isInvalid()) |
| 3070 | return SemaRef.StmtError(); |
| 3071 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3073 | // Build the case statement. |
| 3074 | // Case statements are always rebuilt so that they will attached to their |
| 3075 | // transformed switch statement. |
| 3076 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3077 | move(LHS), |
| 3078 | S->getEllipsisLoc(), |
| 3079 | move(RHS), |
| 3080 | S->getColonLoc()); |
| 3081 | if (Case.isInvalid()) |
| 3082 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3083 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3084 | // Transform the statement following the case |
| 3085 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3086 | if (SubStmt.isInvalid()) |
| 3087 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3088 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3089 | // Attach the body to the case statement |
| 3090 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3091 | } |
| 3092 | |
| 3093 | template<typename Derived> |
| 3094 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3095 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3096 | // Transform the statement following the default case |
| 3097 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3098 | if (SubStmt.isInvalid()) |
| 3099 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3101 | // Default statements are always rebuilt |
| 3102 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3103 | move(SubStmt)); |
| 3104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3105 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3106 | template<typename Derived> |
| 3107 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3108 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3109 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3110 | if (SubStmt.isInvalid()) |
| 3111 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3112 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3113 | // FIXME: Pass the real colon location in. |
| 3114 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3115 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3116 | move(SubStmt)); |
| 3117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3118 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3119 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3120 | Sema::OwningStmtResult |
| 3121 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3122 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3123 | OwningExprResult Cond(SemaRef); |
| 3124 | VarDecl *ConditionVar = 0; |
| 3125 | if (S->getConditionVariable()) { |
| 3126 | ConditionVar |
| 3127 | = cast_or_null<VarDecl>( |
| 3128 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3129 | if (!ConditionVar) |
| 3130 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3131 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3132 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3133 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3134 | if (Cond.isInvalid()) |
| 3135 | return SemaRef.StmtError(); |
| 3136 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3137 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3138 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3139 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3140 | // Transform the "then" branch. |
| 3141 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3142 | if (Then.isInvalid()) |
| 3143 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3144 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3145 | // Transform the "else" branch. |
| 3146 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3147 | if (Else.isInvalid()) |
| 3148 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3150 | if (!getDerived().AlwaysRebuild() && |
| 3151 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3152 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3153 | Then.get() == S->getThen() && |
| 3154 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3155 | return SemaRef.Owned(S->Retain()); |
| 3156 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3157 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3158 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3159 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | template<typename Derived> |
| 3163 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3165 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3166 | OwningExprResult Cond(SemaRef); |
| 3167 | VarDecl *ConditionVar = 0; |
| 3168 | if (S->getConditionVariable()) { |
| 3169 | ConditionVar |
| 3170 | = cast_or_null<VarDecl>( |
| 3171 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3172 | if (!ConditionVar) |
| 3173 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3174 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3175 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3176 | |
| 3177 | if (Cond.isInvalid()) |
| 3178 | return SemaRef.StmtError(); |
| 3179 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3180 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3181 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3182 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3183 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3184 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3185 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3186 | if (Switch.isInvalid()) |
| 3187 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3189 | // Transform the body of the switch statement. |
| 3190 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3191 | if (Body.isInvalid()) |
| 3192 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3193 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3194 | // Complete the switch statement. |
| 3195 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3196 | move(Body)); |
| 3197 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3199 | template<typename Derived> |
| 3200 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3202 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3203 | OwningExprResult Cond(SemaRef); |
| 3204 | VarDecl *ConditionVar = 0; |
| 3205 | if (S->getConditionVariable()) { |
| 3206 | ConditionVar |
| 3207 | = cast_or_null<VarDecl>( |
| 3208 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3209 | if (!ConditionVar) |
| 3210 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3211 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3212 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3213 | |
| 3214 | if (Cond.isInvalid()) |
| 3215 | return SemaRef.StmtError(); |
| 3216 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3218 | Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3219 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3220 | // Transform the body |
| 3221 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3222 | if (Body.isInvalid()) |
| 3223 | return SemaRef.StmtError(); |
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() && |
| 3226 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3227 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3228 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3229 | return SemaRef.Owned(S->Retain()); |
| 3230 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3231 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3232 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3233 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | template<typename Derived> |
| 3236 | Sema::OwningStmtResult |
| 3237 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3238 | // Transform the condition |
| 3239 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3240 | if (Cond.isInvalid()) |
| 3241 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3242 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3243 | // Transform the body |
| 3244 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3245 | if (Body.isInvalid()) |
| 3246 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | if (!getDerived().AlwaysRebuild() && |
| 3249 | Cond.get() == S->getCond() && |
| 3250 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3251 | return SemaRef.Owned(S->Retain()); |
| 3252 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3253 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3254 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3255 | S->getRParenLoc()); |
| 3256 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3258 | template<typename Derived> |
| 3259 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3260 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3261 | // Transform the initialization statement |
| 3262 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3263 | if (Init.isInvalid()) |
| 3264 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3266 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3267 | OwningExprResult Cond(SemaRef); |
| 3268 | VarDecl *ConditionVar = 0; |
| 3269 | if (S->getConditionVariable()) { |
| 3270 | ConditionVar |
| 3271 | = cast_or_null<VarDecl>( |
| 3272 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3273 | if (!ConditionVar) |
| 3274 | return SemaRef.StmtError(); |
| 3275 | } else { |
| 3276 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3277 | |
| 3278 | if (Cond.isInvalid()) |
| 3279 | return SemaRef.StmtError(); |
| 3280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3282 | // Transform the increment |
| 3283 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3284 | if (Inc.isInvalid()) |
| 3285 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | // Transform the body |
| 3288 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3289 | if (Body.isInvalid()) |
| 3290 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3291 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | if (!getDerived().AlwaysRebuild() && |
| 3293 | Init.get() == S->getInit() && |
| 3294 | Cond.get() == S->getCond() && |
| 3295 | Inc.get() == S->getInc() && |
| 3296 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | return SemaRef.Owned(S->Retain()); |
| 3298 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3299 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3300 | move(Init), getSema().MakeFullExpr(Cond), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3301 | ConditionVar, |
Anders Carlsson | afb2dad | 2009-12-16 02:09:40 +0000 | [diff] [blame] | 3302 | getSema().MakeFullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3303 | S->getRParenLoc(), move(Body)); |
| 3304 | } |
| 3305 | |
| 3306 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3307 | Sema::OwningStmtResult |
| 3308 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3311 | S->getLabel()); |
| 3312 | } |
| 3313 | |
| 3314 | template<typename Derived> |
| 3315 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3317 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3318 | if (Target.isInvalid()) |
| 3319 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3321 | if (!getDerived().AlwaysRebuild() && |
| 3322 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3323 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3324 | |
| 3325 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3326 | move(Target)); |
| 3327 | } |
| 3328 | |
| 3329 | template<typename Derived> |
| 3330 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3331 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3332 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | template<typename Derived> |
| 3336 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3338 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3341 | template<typename Derived> |
| 3342 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3345 | if (Result.isInvalid()) |
| 3346 | return SemaRef.StmtError(); |
| 3347 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | // to tell whether the return type of the function has changed. |
| 3350 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3351 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | template<typename Derived> |
| 3354 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | bool DeclChanged = false; |
| 3357 | llvm::SmallVector<Decl *, 4> Decls; |
| 3358 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3359 | D != DEnd; ++D) { |
| 3360 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3361 | if (!Transformed) |
| 3362 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3363 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3364 | if (Transformed != *D) |
| 3365 | DeclChanged = true; |
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 | Decls.push_back(Transformed); |
| 3368 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3370 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | return SemaRef.Owned(S->Retain()); |
| 3372 | |
| 3373 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | S->getStartLoc(), S->getEndLoc()); |
| 3375 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3377 | template<typename Derived> |
| 3378 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3380 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3381 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | template<typename Derived> |
| 3385 | Sema::OwningStmtResult |
| 3386 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3387 | |
| 3388 | ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema()); |
| 3389 | ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema()); |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3390 | llvm::SmallVector<IdentifierInfo *, 4> Names; |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3391 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3392 | OwningExprResult AsmString(SemaRef); |
| 3393 | ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema()); |
| 3394 | |
| 3395 | bool ExprsChanged = false; |
| 3396 | |
| 3397 | // Go through the outputs. |
| 3398 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3399 | Names.push_back(S->getOutputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3400 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3401 | // No need to transform the constraint literal. |
| 3402 | Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain()); |
| 3403 | |
| 3404 | // Transform the output expr. |
| 3405 | Expr *OutputExpr = S->getOutputExpr(I); |
| 3406 | OwningExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 3407 | if (Result.isInvalid()) |
| 3408 | return SemaRef.StmtError(); |
| 3409 | |
| 3410 | ExprsChanged |= Result.get() != OutputExpr; |
| 3411 | |
| 3412 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3413 | } |
| 3414 | |
| 3415 | // Go through the inputs. |
| 3416 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 3417 | Names.push_back(S->getInputIdentifier(I)); |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3418 | |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3419 | // No need to transform the constraint literal. |
| 3420 | Constraints.push_back(S->getInputConstraintLiteral(I)->Retain()); |
| 3421 | |
| 3422 | // Transform the input expr. |
| 3423 | Expr *InputExpr = S->getInputExpr(I); |
| 3424 | OwningExprResult Result = getDerived().TransformExpr(InputExpr); |
| 3425 | if (Result.isInvalid()) |
| 3426 | return SemaRef.StmtError(); |
| 3427 | |
| 3428 | ExprsChanged |= Result.get() != InputExpr; |
| 3429 | |
| 3430 | Exprs.push_back(Result.takeAs<Expr>()); |
| 3431 | } |
| 3432 | |
| 3433 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 3434 | return SemaRef.Owned(S->Retain()); |
| 3435 | |
| 3436 | // Go through the clobbers. |
| 3437 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 3438 | Clobbers.push_back(S->getClobber(I)->Retain()); |
| 3439 | |
| 3440 | // No need to transform the asm string literal. |
| 3441 | AsmString = SemaRef.Owned(S->getAsmString()); |
| 3442 | |
| 3443 | return getDerived().RebuildAsmStmt(S->getAsmLoc(), |
| 3444 | S->isSimple(), |
| 3445 | S->isVolatile(), |
| 3446 | S->getNumOutputs(), |
| 3447 | S->getNumInputs(), |
Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 3448 | Names.data(), |
Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 3449 | move_arg(Constraints), |
| 3450 | move_arg(Exprs), |
| 3451 | move(AsmString), |
| 3452 | move_arg(Clobbers), |
| 3453 | S->getRParenLoc(), |
| 3454 | S->isMSAsm()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | |
| 3458 | template<typename Derived> |
| 3459 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3460 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3461 | // FIXME: Implement this |
| 3462 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3465 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3466 | template<typename Derived> |
| 3467 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3468 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3469 | // FIXME: Implement this |
| 3470 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3471 | return SemaRef.Owned(S->Retain()); |
| 3472 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3474 | template<typename Derived> |
| 3475 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3476 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3477 | // FIXME: Implement this |
| 3478 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3479 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3480 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3481 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3482 | template<typename Derived> |
| 3483 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3484 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3485 | // FIXME: Implement this |
| 3486 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3487 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3488 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3489 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3490 | template<typename Derived> |
| 3491 | Sema::OwningStmtResult |
| 3492 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3493 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3494 | // FIXME: Implement this |
| 3495 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3496 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | template<typename Derived> |
| 3500 | Sema::OwningStmtResult |
| 3501 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3503 | // FIXME: Implement this |
| 3504 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3505 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | |
| 3509 | template<typename Derived> |
| 3510 | Sema::OwningStmtResult |
| 3511 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3512 | // Transform the exception declaration, if any. |
| 3513 | VarDecl *Var = 0; |
| 3514 | if (S->getExceptionDecl()) { |
| 3515 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3516 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3517 | ExceptionDecl->getDeclName()); |
| 3518 | |
| 3519 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3520 | if (T.isNull()) |
| 3521 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3522 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3523 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3524 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3525 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3526 | ExceptionDecl->getIdentifier(), |
| 3527 | ExceptionDecl->getLocation(), |
| 3528 | /*FIXME: Inaccurate*/ |
| 3529 | SourceRange(ExceptionDecl->getLocation())); |
| 3530 | if (!Var || Var->isInvalidDecl()) { |
| 3531 | if (Var) |
| 3532 | Var->Destroy(SemaRef.Context); |
| 3533 | return SemaRef.StmtError(); |
| 3534 | } |
| 3535 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3537 | // Transform the actual exception handler. |
| 3538 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3539 | if (Handler.isInvalid()) { |
| 3540 | if (Var) |
| 3541 | Var->Destroy(SemaRef.Context); |
| 3542 | return SemaRef.StmtError(); |
| 3543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3545 | if (!getDerived().AlwaysRebuild() && |
| 3546 | !Var && |
| 3547 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3548 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3549 | |
| 3550 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3551 | Var, |
| 3552 | move(Handler)); |
| 3553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3555 | template<typename Derived> |
| 3556 | Sema::OwningStmtResult |
| 3557 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3558 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3559 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3560 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3561 | if (TryBlock.isInvalid()) |
| 3562 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3564 | // Transform the handlers. |
| 3565 | bool HandlerChanged = false; |
| 3566 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3567 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3568 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3569 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3570 | if (Handler.isInvalid()) |
| 3571 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3573 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3574 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3575 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3576 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3577 | if (!getDerived().AlwaysRebuild() && |
| 3578 | TryBlock.get() == S->getTryBlock() && |
| 3579 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3581 | |
| 3582 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | move_arg(Handlers)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3586 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3587 | // Expression transformation |
| 3588 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3589 | template<typename Derived> |
| 3590 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3591 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3592 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3594 | |
| 3595 | template<typename Derived> |
| 3596 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3597 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3598 | NestedNameSpecifier *Qualifier = 0; |
| 3599 | if (E->getQualifier()) { |
| 3600 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3601 | E->getQualifierRange()); |
| 3602 | if (!Qualifier) |
| 3603 | return SemaRef.ExprError(); |
| 3604 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3605 | |
| 3606 | ValueDecl *ND |
| 3607 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3608 | if (!ND) |
| 3609 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3611 | if (!getDerived().AlwaysRebuild() && |
| 3612 | Qualifier == E->getQualifier() && |
| 3613 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3614 | !E->hasExplicitTemplateArgumentList()) { |
| 3615 | |
| 3616 | // Mark it referenced in the new context regardless. |
| 3617 | // FIXME: this is a bit instantiation-specific. |
| 3618 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3619 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3621 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3622 | |
| 3623 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3624 | if (E->hasExplicitTemplateArgumentList()) { |
| 3625 | TemplateArgs = &TransArgs; |
| 3626 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3627 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3628 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3629 | TemplateArgumentLoc Loc; |
| 3630 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3631 | return SemaRef.ExprError(); |
| 3632 | TransArgs.addArgument(Loc); |
| 3633 | } |
| 3634 | } |
| 3635 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3636 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 3637 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3638 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3640 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3641 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3642 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3643 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3645 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3646 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3647 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3648 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3649 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3652 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3653 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3654 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3655 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3657 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3658 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3659 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3660 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3661 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3662 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3666 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3667 | return SemaRef.Owned(E->Retain()); |
| 3668 | } |
| 3669 | |
| 3670 | template<typename Derived> |
| 3671 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3672 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3673 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3674 | if (SubExpr.isInvalid()) |
| 3675 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3676 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3677 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3678 | return SemaRef.Owned(E->Retain()); |
| 3679 | |
| 3680 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3681 | E->getRParen()); |
| 3682 | } |
| 3683 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | template<typename Derived> |
| 3685 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3686 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 3687 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3688 | if (SubExpr.isInvalid()) |
| 3689 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | return SemaRef.Owned(E->Retain()); |
| 3693 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3694 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3695 | E->getOpcode(), |
| 3696 | move(SubExpr)); |
| 3697 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3698 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3699 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3701 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3702 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3703 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3704 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3705 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3706 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3707 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3709 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3710 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3711 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3712 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3714 | E->getSourceRange()); |
| 3715 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3716 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3717 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3718 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3719 | // C++0x [expr.sizeof]p1: |
| 3720 | // The operand is either an expression, which is an unevaluated operand |
| 3721 | // [...] |
| 3722 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3723 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3724 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3725 | if (SubExpr.isInvalid()) |
| 3726 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3729 | return SemaRef.Owned(E->Retain()); |
| 3730 | } |
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 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3733 | E->isSizeOf(), |
| 3734 | E->getSourceRange()); |
| 3735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3737 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3738 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3739 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3740 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3741 | if (LHS.isInvalid()) |
| 3742 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3743 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3744 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3745 | if (RHS.isInvalid()) |
| 3746 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
| 3748 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3749 | if (!getDerived().AlwaysRebuild() && |
| 3750 | LHS.get() == E->getLHS() && |
| 3751 | RHS.get() == E->getRHS()) |
| 3752 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3753 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3755 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3756 | move(RHS), |
| 3757 | E->getRBracketLoc()); |
| 3758 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3759 | |
| 3760 | template<typename Derived> |
| 3761 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3762 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3763 | // Transform the callee. |
| 3764 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3765 | if (Callee.isInvalid()) |
| 3766 | return SemaRef.ExprError(); |
| 3767 | |
| 3768 | // Transform arguments. |
| 3769 | bool ArgChanged = false; |
| 3770 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3771 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3772 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3773 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3774 | if (Arg.isInvalid()) |
| 3775 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3776 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3777 | // FIXME: Wrong source location information for the ','. |
| 3778 | FakeCommaLocs.push_back( |
| 3779 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3780 | |
| 3781 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3782 | Args.push_back(Arg.takeAs<Expr>()); |
| 3783 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3785 | if (!getDerived().AlwaysRebuild() && |
| 3786 | Callee.get() == E->getCallee() && |
| 3787 | !ArgChanged) |
| 3788 | return SemaRef.Owned(E->Retain()); |
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 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3793 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3794 | move_arg(Args), |
| 3795 | FakeCommaLocs.data(), |
| 3796 | E->getRParenLoc()); |
| 3797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | |
| 3799 | template<typename Derived> |
| 3800 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3801 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3802 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3803 | if (Base.isInvalid()) |
| 3804 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3805 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3806 | NestedNameSpecifier *Qualifier = 0; |
| 3807 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3809 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3810 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3811 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3812 | return SemaRef.ExprError(); |
| 3813 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3815 | ValueDecl *Member |
| 3816 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3817 | if (!Member) |
| 3818 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3819 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3820 | if (!getDerived().AlwaysRebuild() && |
| 3821 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3822 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3823 | Member == E->getMemberDecl() && |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3824 | !E->hasExplicitTemplateArgumentList()) { |
| 3825 | |
| 3826 | // Mark it referenced in the new context regardless. |
| 3827 | // FIXME: this is a bit instantiation-specific. |
| 3828 | SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | return SemaRef.Owned(E->Retain()); |
Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 3830 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3831 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3832 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3833 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3834 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3835 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3836 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3837 | TemplateArgumentLoc Loc; |
| 3838 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3839 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3840 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3844 | // FIXME: Bogus source location for the operator |
| 3845 | SourceLocation FakeOperatorLoc |
| 3846 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3847 | |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3848 | // FIXME: to do this check properly, we will need to preserve the |
| 3849 | // first-qualifier-in-scope here, just in case we had a dependent |
| 3850 | // base (and therefore couldn't do the check) and a |
| 3851 | // nested-name-qualifier (and therefore could do the lookup). |
| 3852 | NamedDecl *FirstQualifierInScope = 0; |
| 3853 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3855 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3856 | Qualifier, |
| 3857 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3858 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3859 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3860 | (E->hasExplicitTemplateArgumentList() |
| 3861 | ? &TransArgs : 0), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 3862 | FirstQualifierInScope); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3864 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3865 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3866 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3867 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3869 | if (LHS.isInvalid()) |
| 3870 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3872 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3873 | if (RHS.isInvalid()) |
| 3874 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3875 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3876 | if (!getDerived().AlwaysRebuild() && |
| 3877 | LHS.get() == E->getLHS() && |
| 3878 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | return SemaRef.Owned(E->Retain()); |
| 3880 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3881 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3882 | move(LHS), move(RHS)); |
| 3883 | } |
| 3884 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3886 | Sema::OwningExprResult |
| 3887 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3888 | CompoundAssignOperator *E) { |
| 3889 | return getDerived().TransformBinaryOperator(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3890 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3894 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3895 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3896 | if (Cond.isInvalid()) |
| 3897 | return SemaRef.ExprError(); |
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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3900 | if (LHS.isInvalid()) |
| 3901 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3902 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3903 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3904 | if (RHS.isInvalid()) |
| 3905 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3906 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3907 | if (!getDerived().AlwaysRebuild() && |
| 3908 | Cond.get() == E->getCond() && |
| 3909 | LHS.get() == E->getLHS() && |
| 3910 | RHS.get() == E->getRHS()) |
| 3911 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3912 | |
| 3913 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3914 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3916 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3917 | move(RHS)); |
| 3918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3919 | |
| 3920 | template<typename Derived> |
| 3921 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3922 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3923 | // Implicit casts are eliminated during transformation, since they |
| 3924 | // will be recomputed by semantic analysis after transformation. |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3925 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3926 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3927 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3928 | template<typename Derived> |
| 3929 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3930 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3931 | TypeSourceInfo *OldT; |
| 3932 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3933 | { |
| 3934 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3935 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3937 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3938 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3939 | OldT = E->getTypeInfoAsWritten(); |
| 3940 | NewT = getDerived().TransformType(OldT); |
| 3941 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3942 | return SemaRef.ExprError(); |
| 3943 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 3945 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 3946 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | if (SubExpr.isInvalid()) |
| 3948 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3950 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3951 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3952 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3953 | return SemaRef.Owned(E->Retain()); |
| 3954 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 3955 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 3956 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3957 | E->getRParenLoc(), |
| 3958 | move(SubExpr)); |
| 3959 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3961 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3962 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3963 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3964 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 3965 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 3966 | if (!NewT) |
| 3967 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3970 | if (Init.isInvalid()) |
| 3971 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3974 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3976 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3977 | |
John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 3978 | // Note: the expression type doesn't necessarily match the |
| 3979 | // type-as-written, but that's okay, because it should always be |
| 3980 | // derivable from the initializer. |
| 3981 | |
John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 3982 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3983 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3984 | move(Init)); |
| 3985 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3987 | template<typename Derived> |
| 3988 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3989 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3991 | if (Base.isInvalid()) |
| 3992 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3993 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3994 | if (!getDerived().AlwaysRebuild() && |
| 3995 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3996 | return SemaRef.Owned(E->Retain()); |
| 3997 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3998 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4000 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 4001 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 4002 | E->getAccessorLoc(), |
| 4003 | E->getAccessor()); |
| 4004 | } |
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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4007 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4008 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4009 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4010 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4011 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4012 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 4013 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 4014 | if (Init.isInvalid()) |
| 4015 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4016 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4017 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 4018 | Inits.push_back(Init.takeAs<Expr>()); |
| 4019 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4020 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4021 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | return SemaRef.Owned(E->Retain()); |
| 4023 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4024 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 4025 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4026 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | template<typename Derived> |
| 4029 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4030 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4031 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4033 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4034 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 4035 | if (Init.isInvalid()) |
| 4036 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4038 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4039 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 4040 | bool ExprChanged = false; |
| 4041 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 4042 | DEnd = E->designators_end(); |
| 4043 | D != DEnd; ++D) { |
| 4044 | if (D->isFieldDesignator()) { |
| 4045 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 4046 | D->getDotLoc(), |
| 4047 | D->getFieldLoc())); |
| 4048 | continue; |
| 4049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4051 | if (D->isArrayDesignator()) { |
| 4052 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 4053 | if (Index.isInvalid()) |
| 4054 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4055 | |
| 4056 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4057 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4059 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 4060 | ArrayExprs.push_back(Index.release()); |
| 4061 | continue; |
| 4062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4065 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4066 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 4067 | if (Start.isInvalid()) |
| 4068 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4070 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 4071 | if (End.isInvalid()) |
| 4072 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
| 4074 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4075 | End.get(), |
| 4076 | D->getLBracketLoc(), |
| 4077 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4078 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4079 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4080 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4082 | ArrayExprs.push_back(Start.release()); |
| 4083 | ArrayExprs.push_back(End.release()); |
| 4084 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4085 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4086 | if (!getDerived().AlwaysRebuild() && |
| 4087 | Init.get() == E->getInit() && |
| 4088 | !ExprChanged) |
| 4089 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4092 | E->getEqualOrColonLoc(), |
| 4093 | E->usesGNUSyntax(), move(Init)); |
| 4094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4095 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4096 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4097 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4098 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4099 | ImplicitValueInitExpr *E) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4100 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4101 | |
| 4102 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4103 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | QualType T = getDerived().TransformType(E->getType()); |
| 4105 | if (T.isNull()) |
| 4106 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4107 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4108 | if (!getDerived().AlwaysRebuild() && |
| 4109 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4110 | return SemaRef.Owned(E->Retain()); |
| 4111 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4112 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4115 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4116 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4117 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4118 | // FIXME: Do we want the type as written? |
| 4119 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4120 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4121 | { |
| 4122 | // FIXME: Source location isn't quite accurate. |
| 4123 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4124 | T = getDerived().TransformType(E->getType()); |
| 4125 | if (T.isNull()) |
| 4126 | return SemaRef.ExprError(); |
| 4127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4128 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4129 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4130 | if (SubExpr.isInvalid()) |
| 4131 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4132 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4133 | if (!getDerived().AlwaysRebuild() && |
| 4134 | T == E->getType() && |
| 4135 | SubExpr.get() == E->getSubExpr()) |
| 4136 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4137 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4138 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4139 | T, E->getRParenLoc()); |
| 4140 | } |
| 4141 | |
| 4142 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4143 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4144 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4145 | bool ArgumentChanged = false; |
| 4146 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4147 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4148 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4149 | if (Init.isInvalid()) |
| 4150 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4151 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4152 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4153 | Inits.push_back(Init.takeAs<Expr>()); |
| 4154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4156 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4157 | move_arg(Inits), |
| 4158 | E->getRParenLoc()); |
| 4159 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4160 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4161 | /// \brief Transform an address-of-label expression. |
| 4162 | /// |
| 4163 | /// By default, the transformation of an address-of-label expression always |
| 4164 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4165 | /// the corresponding label statement by semantic analysis. |
| 4166 | template<typename Derived> |
| 4167 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4168 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4169 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4170 | E->getLabel()); |
| 4171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4172 | |
| 4173 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4174 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4175 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4176 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4177 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4178 | if (SubStmt.isInvalid()) |
| 4179 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4180 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4181 | if (!getDerived().AlwaysRebuild() && |
| 4182 | SubStmt.get() == E->getSubStmt()) |
| 4183 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4184 | |
| 4185 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4186 | move(SubStmt), |
| 4187 | E->getRParenLoc()); |
| 4188 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4189 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4190 | template<typename Derived> |
| 4191 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4192 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4193 | QualType T1, T2; |
| 4194 | { |
| 4195 | // FIXME: Source location isn't quite accurate. |
| 4196 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4197 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4198 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4199 | if (T1.isNull()) |
| 4200 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4203 | if (T2.isNull()) |
| 4204 | return SemaRef.ExprError(); |
| 4205 | } |
| 4206 | |
| 4207 | if (!getDerived().AlwaysRebuild() && |
| 4208 | T1 == E->getArgType1() && |
| 4209 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4210 | return SemaRef.Owned(E->Retain()); |
| 4211 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4212 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4213 | T1, T2, E->getRParenLoc()); |
| 4214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4215 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4216 | template<typename Derived> |
| 4217 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4218 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4220 | if (Cond.isInvalid()) |
| 4221 | return SemaRef.ExprError(); |
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 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4224 | if (LHS.isInvalid()) |
| 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 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4228 | if (RHS.isInvalid()) |
| 4229 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4232 | Cond.get() == E->getCond() && |
| 4233 | LHS.get() == E->getLHS() && |
| 4234 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4235 | return SemaRef.Owned(E->Retain()); |
| 4236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4238 | move(Cond), move(LHS), move(RHS), |
| 4239 | E->getRParenLoc()); |
| 4240 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4242 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4244 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4245 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | template<typename Derived> |
| 4249 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4250 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4251 | switch (E->getOperator()) { |
| 4252 | case OO_New: |
| 4253 | case OO_Delete: |
| 4254 | case OO_Array_New: |
| 4255 | case OO_Array_Delete: |
| 4256 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 4257 | return SemaRef.ExprError(); |
| 4258 | |
| 4259 | case OO_Call: { |
| 4260 | // This is a call to an object's operator(). |
| 4261 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 4262 | |
| 4263 | // Transform the object itself. |
| 4264 | OwningExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 4265 | if (Object.isInvalid()) |
| 4266 | return SemaRef.ExprError(); |
| 4267 | |
| 4268 | // FIXME: Poor location information |
| 4269 | SourceLocation FakeLParenLoc |
| 4270 | = SemaRef.PP.getLocForEndOfToken( |
| 4271 | static_cast<Expr *>(Object.get())->getLocEnd()); |
| 4272 | |
| 4273 | // Transform the call arguments. |
| 4274 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4275 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 4276 | for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4277 | if (getDerived().DropCallArgument(E->getArg(I))) |
| 4278 | break; |
| 4279 | |
Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 4280 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 4281 | if (Arg.isInvalid()) |
| 4282 | return SemaRef.ExprError(); |
| 4283 | |
| 4284 | // FIXME: Poor source location information. |
| 4285 | SourceLocation FakeCommaLoc |
| 4286 | = SemaRef.PP.getLocForEndOfToken( |
| 4287 | static_cast<Expr *>(Arg.get())->getLocEnd()); |
| 4288 | FakeCommaLocs.push_back(FakeCommaLoc); |
| 4289 | Args.push_back(Arg.release()); |
| 4290 | } |
| 4291 | |
| 4292 | return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, |
| 4293 | move_arg(Args), |
| 4294 | FakeCommaLocs.data(), |
| 4295 | E->getLocEnd()); |
| 4296 | } |
| 4297 | |
| 4298 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 4299 | case OO_##Name: |
| 4300 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 4301 | #include "clang/Basic/OperatorKinds.def" |
| 4302 | case OO_Subscript: |
| 4303 | // Handled below. |
| 4304 | break; |
| 4305 | |
| 4306 | case OO_Conditional: |
| 4307 | llvm_unreachable("conditional operator is not actually overloadable"); |
| 4308 | return SemaRef.ExprError(); |
| 4309 | |
| 4310 | case OO_None: |
| 4311 | case NUM_OVERLOADED_OPERATORS: |
| 4312 | llvm_unreachable("not an overloaded operator?"); |
| 4313 | return SemaRef.ExprError(); |
| 4314 | } |
| 4315 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4317 | if (Callee.isInvalid()) |
| 4318 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 | |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4320 | OwningExprResult First = getDerived().TransformExpr(E->getArg(0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4321 | if (First.isInvalid()) |
| 4322 | return SemaRef.ExprError(); |
| 4323 | |
| 4324 | OwningExprResult Second(SemaRef); |
| 4325 | if (E->getNumArgs() == 2) { |
| 4326 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4327 | if (Second.isInvalid()) |
| 4328 | return SemaRef.ExprError(); |
| 4329 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4330 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4331 | if (!getDerived().AlwaysRebuild() && |
| 4332 | Callee.get() == E->getCallee() && |
| 4333 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4335 | return SemaRef.Owned(E->Retain()); |
| 4336 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4337 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4338 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | move(First), |
| 4341 | move(Second)); |
| 4342 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4343 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4344 | template<typename Derived> |
| 4345 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4346 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 4347 | return getDerived().TransformCallExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4349 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4350 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4351 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4352 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4353 | TypeSourceInfo *OldT; |
| 4354 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | { |
| 4356 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4358 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4359 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4360 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4361 | OldT = E->getTypeInfoAsWritten(); |
| 4362 | NewT = getDerived().TransformType(OldT); |
| 4363 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4364 | return SemaRef.ExprError(); |
| 4365 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4367 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4368 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4369 | if (SubExpr.isInvalid()) |
| 4370 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4372 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4373 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4374 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4375 | return SemaRef.Owned(E->Retain()); |
| 4376 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4377 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4378 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4379 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4380 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4381 | SourceLocation FakeRParenLoc |
| 4382 | = SemaRef.PP.getLocForEndOfToken( |
| 4383 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4384 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | FakeLAngleLoc, |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4387 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4388 | FakeRAngleLoc, |
| 4389 | FakeRAngleLoc, |
| 4390 | move(SubExpr), |
| 4391 | FakeRParenLoc); |
| 4392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4393 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4394 | template<typename Derived> |
| 4395 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4396 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 4397 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4399 | |
| 4400 | template<typename Derived> |
| 4401 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4402 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 4403 | return getDerived().TransformCXXNamedCastExpr(E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | template<typename Derived> |
| 4407 | Sema::OwningExprResult |
| 4408 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4409 | CXXReinterpretCastExpr *E) { |
| 4410 | return getDerived().TransformCXXNamedCastExpr(E); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4412 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | template<typename Derived> |
| 4414 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4415 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 4416 | return getDerived().TransformCXXNamedCastExpr(E); |
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 |
| 4421 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4422 | CXXFunctionalCastExpr *E) { |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4423 | TypeSourceInfo *OldT; |
| 4424 | TypeSourceInfo *NewT; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | { |
| 4426 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4427 | |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4428 | OldT = E->getTypeInfoAsWritten(); |
| 4429 | NewT = getDerived().TransformType(OldT); |
| 4430 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4431 | return SemaRef.ExprError(); |
| 4432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | |
Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 4434 | OwningExprResult SubExpr |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4435 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4436 | if (SubExpr.isInvalid()) |
| 4437 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4438 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4439 | if (!getDerived().AlwaysRebuild() && |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4440 | OldT == NewT && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4441 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4442 | return SemaRef.Owned(E->Retain()); |
| 4443 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4444 | // FIXME: The end of the type's source range is wrong |
| 4445 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4446 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 4447 | NewT, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4449 | move(SubExpr), |
| 4450 | E->getRParenLoc()); |
| 4451 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4453 | template<typename Derived> |
| 4454 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4455 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4456 | if (E->isTypeOperand()) { |
| 4457 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4458 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4459 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4460 | if (T.isNull()) |
| 4461 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4462 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4463 | if (!getDerived().AlwaysRebuild() && |
| 4464 | T == E->getTypeOperand()) |
| 4465 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4466 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4467 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4468 | /*FIXME:*/E->getLocStart(), |
| 4469 | T, |
| 4470 | E->getLocEnd()); |
| 4471 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4472 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4473 | // We don't know whether the expression is potentially evaluated until |
| 4474 | // after we perform semantic analysis, so the expression is potentially |
| 4475 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4476 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4477 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4478 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4479 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4480 | if (SubExpr.isInvalid()) |
| 4481 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4482 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4483 | if (!getDerived().AlwaysRebuild() && |
| 4484 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | return SemaRef.Owned(E->Retain()); |
| 4486 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4487 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4488 | /*FIXME:*/E->getLocStart(), |
| 4489 | move(SubExpr), |
| 4490 | E->getLocEnd()); |
| 4491 | } |
| 4492 | |
| 4493 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4494 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4495 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4496 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4497 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4498 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4499 | template<typename Derived> |
| 4500 | Sema::OwningExprResult |
| 4501 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4502 | CXXNullPtrLiteralExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4504 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | template<typename Derived> |
| 4507 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4508 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4509 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4510 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | QualType T = getDerived().TransformType(E->getType()); |
| 4512 | if (T.isNull()) |
| 4513 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4514 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4515 | if (!getDerived().AlwaysRebuild() && |
| 4516 | T == E->getType()) |
| 4517 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4518 | |
Douglas Gregor | b15af89 | 2010-01-07 23:12:05 +0000 | [diff] [blame] | 4519 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4521 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4522 | template<typename Derived> |
| 4523 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4524 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4525 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4526 | if (SubExpr.isInvalid()) |
| 4527 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4529 | if (!getDerived().AlwaysRebuild() && |
| 4530 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4531 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4532 | |
| 4533 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4536 | template<typename Derived> |
| 4537 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4538 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4540 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4541 | if (!Param) |
| 4542 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4543 | |
Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 4544 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4545 | Param == E->getParam()) |
| 4546 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 4548 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4549 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4550 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4551 | template<typename Derived> |
| 4552 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4553 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4554 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4555 | |
| 4556 | QualType T = getDerived().TransformType(E->getType()); |
| 4557 | if (T.isNull()) |
| 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 | if (!getDerived().AlwaysRebuild() && |
| 4561 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | return SemaRef.Owned(E->Retain()); |
| 4563 | |
| 4564 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4565 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4566 | T, |
| 4567 | E->getRParenLoc()); |
| 4568 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4569 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4570 | template<typename Derived> |
| 4571 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4572 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4573 | // Transform the type that we're allocating |
| 4574 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4575 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4576 | if (AllocType.isNull()) |
| 4577 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4578 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4579 | // Transform the size of the array we're allocating (if any). |
| 4580 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4581 | if (ArraySize.isInvalid()) |
| 4582 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4584 | // Transform the placement arguments (if any). |
| 4585 | bool ArgumentChanged = false; |
| 4586 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4587 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4588 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4589 | if (Arg.isInvalid()) |
| 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 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4593 | PlacementArgs.push_back(Arg.take()); |
| 4594 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4596 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4597 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4598 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4599 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4600 | if (Arg.isInvalid()) |
| 4601 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4602 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4603 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4604 | ConstructorArgs.push_back(Arg.take()); |
| 4605 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4607 | if (!getDerived().AlwaysRebuild() && |
| 4608 | AllocType == E->getAllocatedType() && |
| 4609 | ArraySize.get() == E->getArraySize() && |
| 4610 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | return SemaRef.Owned(E->Retain()); |
| 4612 | |
Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 4613 | if (!ArraySize.get()) { |
| 4614 | // If no array size was specified, but the new expression was |
| 4615 | // instantiated with an array type (e.g., "new T" where T is |
| 4616 | // instantiated with "int[4]"), extract the outer bound from the |
| 4617 | // array type as our array size. We do this with constant and |
| 4618 | // dependently-sized array types. |
| 4619 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 4620 | if (!ArrayT) { |
| 4621 | // Do nothing |
| 4622 | } else if (const ConstantArrayType *ConsArrayT |
| 4623 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 4624 | ArraySize |
| 4625 | = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
| 4626 | ConsArrayT->getSize(), |
| 4627 | SemaRef.Context.getSizeType(), |
| 4628 | /*FIXME:*/E->getLocStart())); |
| 4629 | AllocType = ConsArrayT->getElementType(); |
| 4630 | } else if (const DependentSizedArrayType *DepArrayT |
| 4631 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 4632 | if (DepArrayT->getSizeExpr()) { |
| 4633 | ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain()); |
| 4634 | AllocType = DepArrayT->getElementType(); |
| 4635 | } |
| 4636 | } |
| 4637 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4638 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4639 | E->isGlobalNew(), |
| 4640 | /*FIXME:*/E->getLocStart(), |
| 4641 | move_arg(PlacementArgs), |
| 4642 | /*FIXME:*/E->getLocStart(), |
| 4643 | E->isParenTypeId(), |
| 4644 | AllocType, |
| 4645 | /*FIXME:*/E->getLocStart(), |
| 4646 | /*FIXME:*/SourceRange(), |
| 4647 | move(ArraySize), |
| 4648 | /*FIXME:*/E->getLocStart(), |
| 4649 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4650 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4651 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4652 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4653 | template<typename Derived> |
| 4654 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4655 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4656 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4657 | if (Operand.isInvalid()) |
| 4658 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4659 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4661 | Operand.get() == E->getArgument()) |
| 4662 | return SemaRef.Owned(E->Retain()); |
| 4663 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4664 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4665 | E->isGlobalDelete(), |
| 4666 | E->isArrayForm(), |
| 4667 | move(Operand)); |
| 4668 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4669 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4670 | template<typename Derived> |
| 4671 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4672 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4673 | CXXPseudoDestructorExpr *E) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4674 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4675 | if (Base.isInvalid()) |
| 4676 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4678 | NestedNameSpecifier *Qualifier |
| 4679 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4680 | E->getQualifierRange()); |
| 4681 | if (E->getQualifier() && !Qualifier) |
| 4682 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4683 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4684 | QualType DestroyedType; |
| 4685 | { |
| 4686 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4687 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4688 | if (DestroyedType.isNull()) |
| 4689 | return SemaRef.ExprError(); |
| 4690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4691 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4692 | if (!getDerived().AlwaysRebuild() && |
| 4693 | Base.get() == E->getBase() && |
| 4694 | Qualifier == E->getQualifier() && |
| 4695 | DestroyedType == E->getDestroyedType()) |
| 4696 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4697 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4698 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4699 | E->getOperatorLoc(), |
| 4700 | E->isArrow(), |
| 4701 | E->getDestroyedTypeLoc(), |
| 4702 | DestroyedType, |
| 4703 | Qualifier, |
| 4704 | E->getQualifierRange()); |
| 4705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4707 | template<typename Derived> |
| 4708 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4709 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4710 | UnresolvedLookupExpr *Old) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4711 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4712 | |
| 4713 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4714 | Sema::LookupOrdinaryName); |
| 4715 | |
| 4716 | // Transform all the decls. |
| 4717 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4718 | E = Old->decls_end(); I != E; ++I) { |
| 4719 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 4720 | if (!InstD) { |
| 4721 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 4722 | // This can happen because of dependent hiding. |
| 4723 | if (isa<UsingShadowDecl>(*I)) |
| 4724 | continue; |
| 4725 | else |
| 4726 | return SemaRef.ExprError(); |
| 4727 | } |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4728 | |
| 4729 | // Expand using declarations. |
| 4730 | if (isa<UsingDecl>(InstD)) { |
| 4731 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4732 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4733 | E = UD->shadow_end(); I != E; ++I) |
| 4734 | R.addDecl(*I); |
| 4735 | continue; |
| 4736 | } |
| 4737 | |
| 4738 | R.addDecl(InstD); |
| 4739 | } |
| 4740 | |
| 4741 | // Resolve a kind, but don't do any further analysis. If it's |
| 4742 | // ambiguous, the callee needs to deal with it. |
| 4743 | R.resolveKind(); |
| 4744 | |
| 4745 | // Rebuild the nested-name qualifier, if present. |
| 4746 | CXXScopeSpec SS; |
| 4747 | NestedNameSpecifier *Qualifier = 0; |
| 4748 | if (Old->getQualifier()) { |
| 4749 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4750 | Old->getQualifierRange()); |
| 4751 | if (!Qualifier) |
| 4752 | return SemaRef.ExprError(); |
| 4753 | |
| 4754 | SS.setScopeRep(Qualifier); |
| 4755 | SS.setRange(Old->getQualifierRange()); |
| 4756 | } |
| 4757 | |
| 4758 | // If we have no template arguments, it's a normal declaration name. |
| 4759 | if (!Old->hasExplicitTemplateArgs()) |
| 4760 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4761 | |
| 4762 | // If we have template arguments, rebuild them, then rebuild the |
| 4763 | // templateid expression. |
| 4764 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4765 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4766 | TemplateArgumentLoc Loc; |
| 4767 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4768 | return SemaRef.ExprError(); |
| 4769 | TransArgs.addArgument(Loc); |
| 4770 | } |
| 4771 | |
| 4772 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4773 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4774 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4775 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | template<typename Derived> |
| 4777 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4778 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4779 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4782 | if (T.isNull()) |
| 4783 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4784 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4785 | if (!getDerived().AlwaysRebuild() && |
| 4786 | T == E->getQueriedType()) |
| 4787 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4788 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4789 | // FIXME: Bad location information |
| 4790 | SourceLocation FakeLParenLoc |
| 4791 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4792 | |
| 4793 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4794 | E->getLocStart(), |
| 4795 | /*FIXME:*/FakeLParenLoc, |
| 4796 | T, |
| 4797 | E->getLocEnd()); |
| 4798 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4799 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | template<typename Derived> |
| 4801 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4802 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4803 | DependentScopeDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4804 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4805 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4806 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | if (!NNS) |
| 4808 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4809 | |
| 4810 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4811 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4812 | if (!Name) |
| 4813 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4814 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4815 | if (!E->hasExplicitTemplateArgs()) { |
| 4816 | if (!getDerived().AlwaysRebuild() && |
| 4817 | NNS == E->getQualifier() && |
| 4818 | Name == E->getDeclName()) |
| 4819 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4820 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4821 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4822 | E->getQualifierRange(), |
| 4823 | Name, E->getLocation(), |
| 4824 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4825 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4826 | |
| 4827 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4828 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4829 | TemplateArgumentLoc Loc; |
| 4830 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4831 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4832 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4835 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4836 | E->getQualifierRange(), |
| 4837 | Name, E->getLocation(), |
| 4838 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | template<typename Derived> |
| 4842 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4843 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 4844 | // CXXConstructExprs are always implicit, so when we have a |
| 4845 | // 1-argument construction we just transform that argument. |
| 4846 | if (E->getNumArgs() == 1 || |
| 4847 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) |
| 4848 | return getDerived().TransformExpr(E->getArg(0)); |
| 4849 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4850 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4851 | |
| 4852 | QualType T = getDerived().TransformType(E->getType()); |
| 4853 | if (T.isNull()) |
| 4854 | return SemaRef.ExprError(); |
| 4855 | |
| 4856 | CXXConstructorDecl *Constructor |
| 4857 | = cast_or_null<CXXConstructorDecl>( |
| 4858 | getDerived().TransformDecl(E->getConstructor())); |
| 4859 | if (!Constructor) |
| 4860 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4862 | bool ArgumentChanged = false; |
| 4863 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4864 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4865 | ArgEnd = E->arg_end(); |
| 4866 | Arg != ArgEnd; ++Arg) { |
Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 4867 | if (getDerived().DropCallArgument(*Arg)) { |
| 4868 | ArgumentChanged = true; |
| 4869 | break; |
| 4870 | } |
| 4871 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4872 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4873 | if (TransArg.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 || TransArg.get() != *Arg; |
| 4877 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4878 | } |
| 4879 | |
| 4880 | if (!getDerived().AlwaysRebuild() && |
| 4881 | T == E->getType() && |
| 4882 | Constructor == E->getConstructor() && |
| 4883 | !ArgumentChanged) |
| 4884 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4885 | |
Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 4886 | return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), |
| 4887 | Constructor, E->isElidable(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4888 | move_arg(Args)); |
| 4889 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4890 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4891 | /// \brief Transform a C++ temporary-binding expression. |
| 4892 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4893 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 4894 | /// transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4895 | template<typename Derived> |
| 4896 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4897 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4898 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4899 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | |
Anders Carlsson | ba6c437 | 2010-01-29 02:39:32 +0000 | [diff] [blame] | 4901 | /// \brief Transform a C++ reference-binding expression. |
| 4902 | /// |
| 4903 | /// Since CXXBindReferenceExpr nodes are implicitly generated, we just |
| 4904 | /// transform the subexpression and return that. |
| 4905 | template<typename Derived> |
| 4906 | Sema::OwningExprResult |
| 4907 | TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) { |
| 4908 | return getDerived().TransformExpr(E->getSubExpr()); |
| 4909 | } |
| 4910 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4911 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4912 | /// be destroyed after the expression is evaluated. |
| 4913 | /// |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4914 | /// Since CXXExprWithTemporaries nodes are implicitly generated, we |
| 4915 | /// just transform the subexpression and return that. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4916 | template<typename Derived> |
| 4917 | Sema::OwningExprResult |
| 4918 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 4919 | CXXExprWithTemporaries *E) { |
| 4920 | return getDerived().TransformExpr(E->getSubExpr()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4921 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4922 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4923 | template<typename Derived> |
| 4924 | Sema::OwningExprResult |
| 4925 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4926 | CXXTemporaryObjectExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4927 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4928 | QualType T = getDerived().TransformType(E->getType()); |
| 4929 | if (T.isNull()) |
| 4930 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4931 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4932 | CXXConstructorDecl *Constructor |
| 4933 | = cast_or_null<CXXConstructorDecl>( |
| 4934 | getDerived().TransformDecl(E->getConstructor())); |
| 4935 | if (!Constructor) |
| 4936 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4937 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4938 | bool ArgumentChanged = false; |
| 4939 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4940 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4941 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4942 | ArgEnd = E->arg_end(); |
| 4943 | Arg != ArgEnd; ++Arg) { |
| 4944 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4945 | if (TransArg.isInvalid()) |
| 4946 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4947 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4949 | Args.push_back((Expr *)TransArg.release()); |
| 4950 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4951 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4952 | if (!getDerived().AlwaysRebuild() && |
| 4953 | T == E->getType() && |
| 4954 | Constructor == E->getConstructor() && |
| 4955 | !ArgumentChanged) |
| 4956 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4957 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4958 | // FIXME: Bogus location information |
| 4959 | SourceLocation CommaLoc; |
| 4960 | if (Args.size() > 1) { |
| 4961 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4962 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4963 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4964 | } |
| 4965 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4966 | T, |
| 4967 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4968 | move_arg(Args), |
| 4969 | &CommaLoc, |
| 4970 | E->getLocEnd()); |
| 4971 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4972 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4973 | template<typename Derived> |
| 4974 | Sema::OwningExprResult |
| 4975 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 4976 | CXXUnresolvedConstructExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4977 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4978 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4979 | if (T.isNull()) |
| 4980 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4981 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4982 | bool ArgumentChanged = false; |
| 4983 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4984 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4985 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4986 | ArgEnd = E->arg_end(); |
| 4987 | Arg != ArgEnd; ++Arg) { |
| 4988 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4989 | if (TransArg.isInvalid()) |
| 4990 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4991 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4992 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4993 | FakeCommaLocs.push_back( |
| 4994 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4995 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4996 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4997 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4998 | if (!getDerived().AlwaysRebuild() && |
| 4999 | T == E->getTypeAsWritten() && |
| 5000 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5001 | return SemaRef.Owned(E->Retain()); |
| 5002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5003 | // FIXME: we're faking the locations of the commas |
| 5004 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 5005 | T, |
| 5006 | E->getLParenLoc(), |
| 5007 | move_arg(Args), |
| 5008 | FakeCommaLocs.data(), |
| 5009 | E->getRParenLoc()); |
| 5010 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5011 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5012 | template<typename Derived> |
| 5013 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5014 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5015 | CXXDependentScopeMemberExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5016 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5017 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5018 | Expr *OldBase; |
| 5019 | QualType BaseType; |
| 5020 | QualType ObjectType; |
| 5021 | if (!E->isImplicitAccess()) { |
| 5022 | OldBase = E->getBase(); |
| 5023 | Base = getDerived().TransformExpr(OldBase); |
| 5024 | if (Base.isInvalid()) |
| 5025 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5027 | // Start the member reference and compute the object's type. |
| 5028 | Sema::TypeTy *ObjectTy = 0; |
| 5029 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 5030 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5031 | E->isArrow()? tok::arrow : tok::period, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5032 | ObjectTy); |
| 5033 | if (Base.isInvalid()) |
| 5034 | return SemaRef.ExprError(); |
| 5035 | |
| 5036 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 5037 | BaseType = ((Expr*) Base.get())->getType(); |
| 5038 | } else { |
| 5039 | OldBase = 0; |
| 5040 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 5041 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 5042 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5044 | // Transform the first part of the nested-name-specifier that qualifies |
| 5045 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5046 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 5047 | = getDerived().TransformFirstQualifierInScope( |
| 5048 | E->getFirstQualifierFoundInScope(), |
| 5049 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5051 | NestedNameSpecifier *Qualifier = 0; |
| 5052 | if (E->getQualifier()) { |
| 5053 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 5054 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5055 | ObjectType, |
| 5056 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5057 | if (!Qualifier) |
| 5058 | return SemaRef.ExprError(); |
| 5059 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5060 | |
| 5061 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 5062 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5063 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 5064 | if (!Name) |
| 5065 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5067 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5068 | // This is a reference to a member without an explicitly-specified |
| 5069 | // template argument list. Optimize for this common case. |
| 5070 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5071 | Base.get() == OldBase && |
| 5072 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5073 | Qualifier == E->getQualifier() && |
| 5074 | Name == E->getMember() && |
| 5075 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5076 | return SemaRef.Owned(E->Retain()); |
| 5077 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5078 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5079 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5080 | E->isArrow(), |
| 5081 | E->getOperatorLoc(), |
| 5082 | Qualifier, |
| 5083 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5084 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5085 | Name, |
| 5086 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5087 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5090 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5091 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5092 | TemplateArgumentLoc Loc; |
| 5093 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5094 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5095 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5096 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5097 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 5098 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5099 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5100 | E->isArrow(), |
| 5101 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5102 | Qualifier, |
| 5103 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5104 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5105 | Name, |
| 5106 | E->getMemberLoc(), |
| 5107 | &TransArgs); |
| 5108 | } |
| 5109 | |
| 5110 | template<typename Derived> |
| 5111 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5112 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5113 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5114 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 5115 | QualType BaseType; |
| 5116 | if (!Old->isImplicitAccess()) { |
| 5117 | Base = getDerived().TransformExpr(Old->getBase()); |
| 5118 | if (Base.isInvalid()) |
| 5119 | return SemaRef.ExprError(); |
| 5120 | BaseType = ((Expr*) Base.get())->getType(); |
| 5121 | } else { |
| 5122 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 5123 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5124 | |
| 5125 | NestedNameSpecifier *Qualifier = 0; |
| 5126 | if (Old->getQualifier()) { |
| 5127 | Qualifier |
| 5128 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 5129 | Old->getQualifierRange()); |
| 5130 | if (Qualifier == 0) |
| 5131 | return SemaRef.ExprError(); |
| 5132 | } |
| 5133 | |
| 5134 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 5135 | Sema::LookupOrdinaryName); |
| 5136 | |
| 5137 | // Transform all the decls. |
| 5138 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 5139 | E = Old->decls_end(); I != E; ++I) { |
| 5140 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
John McCall | 84d8767 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 5141 | if (!InstD) { |
| 5142 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 5143 | // This can happen because of dependent hiding. |
| 5144 | if (isa<UsingShadowDecl>(*I)) |
| 5145 | continue; |
| 5146 | else |
| 5147 | return SemaRef.ExprError(); |
| 5148 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5149 | |
| 5150 | // Expand using declarations. |
| 5151 | if (isa<UsingDecl>(InstD)) { |
| 5152 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 5153 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5154 | E = UD->shadow_end(); I != E; ++I) |
| 5155 | R.addDecl(*I); |
| 5156 | continue; |
| 5157 | } |
| 5158 | |
| 5159 | R.addDecl(InstD); |
| 5160 | } |
| 5161 | |
| 5162 | R.resolveKind(); |
| 5163 | |
| 5164 | TemplateArgumentListInfo TransArgs; |
| 5165 | if (Old->hasExplicitTemplateArgs()) { |
| 5166 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5167 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5168 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5169 | TemplateArgumentLoc Loc; |
| 5170 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5171 | Loc)) |
| 5172 | return SemaRef.ExprError(); |
| 5173 | TransArgs.addArgument(Loc); |
| 5174 | } |
| 5175 | } |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5176 | |
| 5177 | // FIXME: to do this check properly, we will need to preserve the |
| 5178 | // first-qualifier-in-scope here, just in case we had a dependent |
| 5179 | // base (and therefore couldn't do the check) and a |
| 5180 | // nested-name-qualifier (and therefore could do the lookup). |
| 5181 | NamedDecl *FirstQualifierInScope = 0; |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5182 | |
| 5183 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5184 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5185 | Old->getOperatorLoc(), |
| 5186 | Old->isArrow(), |
| 5187 | Qualifier, |
| 5188 | Old->getQualifierRange(), |
John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 5189 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5190 | R, |
| 5191 | (Old->hasExplicitTemplateArgs() |
| 5192 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | template<typename Derived> |
| 5196 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5197 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5201 | template<typename Derived> |
| 5202 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5203 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5204 | // FIXME: poor source location |
| 5205 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5206 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5207 | if (EncodedType.isNull()) |
| 5208 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 5211 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5212 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5213 | |
| 5214 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5215 | EncodedType, |
| 5216 | E->getRParenLoc()); |
| 5217 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5219 | template<typename Derived> |
| 5220 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5221 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5222 | // FIXME: Implement this! |
| 5223 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5224 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5227 | template<typename Derived> |
| 5228 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5229 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5230 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5231 | } |
| 5232 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5233 | template<typename Derived> |
| 5234 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5235 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5237 | = cast_or_null<ObjCProtocolDecl>( |
| 5238 | getDerived().TransformDecl(E->getProtocol())); |
| 5239 | if (!Protocol) |
| 5240 | return SemaRef.ExprError(); |
| 5241 | |
| 5242 | if (!getDerived().AlwaysRebuild() && |
| 5243 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5244 | return SemaRef.Owned(E->Retain()); |
| 5245 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5246 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5247 | E->getAtLoc(), |
| 5248 | /*FIXME:*/E->getAtLoc(), |
| 5249 | /*FIXME:*/E->getAtLoc(), |
| 5250 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5251 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5254 | template<typename Derived> |
| 5255 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5256 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5257 | // FIXME: Implement this! |
| 5258 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5259 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5260 | } |
| 5261 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5262 | template<typename Derived> |
| 5263 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5264 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5265 | // FIXME: Implement this! |
| 5266 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5267 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5270 | template<typename Derived> |
| 5271 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5272 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5273 | ObjCImplicitSetterGetterRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5274 | // FIXME: Implement this! |
| 5275 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5276 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5279 | template<typename Derived> |
| 5280 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5281 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5282 | // FIXME: Implement this! |
| 5283 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | template<typename Derived> |
| 5288 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5289 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | // FIXME: Implement this! |
| 5291 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5292 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5295 | template<typename Derived> |
| 5296 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5297 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5298 | bool ArgumentChanged = false; |
| 5299 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5300 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5301 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5302 | if (SubExpr.isInvalid()) |
| 5303 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5304 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5305 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5306 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5308 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5309 | if (!getDerived().AlwaysRebuild() && |
| 5310 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | return SemaRef.Owned(E->Retain()); |
| 5312 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5313 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5314 | move_arg(SubExprs), |
| 5315 | E->getRParenLoc()); |
| 5316 | } |
| 5317 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5318 | template<typename Derived> |
| 5319 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5320 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5321 | // FIXME: Implement this! |
| 5322 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5323 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | template<typename Derived> |
| 5327 | Sema::OwningExprResult |
John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 5328 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5329 | // FIXME: Implement this! |
| 5330 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5333 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5334 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5335 | // Type reconstruction |
| 5336 | //===----------------------------------------------------------------------===// |
| 5337 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5338 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5339 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5340 | SourceLocation Star) { |
| 5341 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5342 | getDerived().getBaseEntity()); |
| 5343 | } |
| 5344 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5345 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5346 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5347 | SourceLocation Star) { |
| 5348 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5349 | getDerived().getBaseEntity()); |
| 5350 | } |
| 5351 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5352 | template<typename Derived> |
| 5353 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5354 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5355 | bool WrittenAsLValue, |
| 5356 | SourceLocation Sigil) { |
| 5357 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5358 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5362 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5363 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5364 | QualType ClassType, |
| 5365 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5366 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5367 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5371 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5372 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5373 | SourceLocation Sigil) { |
| 5374 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5375 | getDerived().getBaseEntity()); |
| 5376 | } |
| 5377 | |
| 5378 | template<typename Derived> |
| 5379 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5380 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5381 | ArrayType::ArraySizeModifier SizeMod, |
| 5382 | const llvm::APInt *Size, |
| 5383 | Expr *SizeExpr, |
| 5384 | unsigned IndexTypeQuals, |
| 5385 | SourceRange BracketsRange) { |
| 5386 | if (SizeExpr || !Size) |
| 5387 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5388 | IndexTypeQuals, BracketsRange, |
| 5389 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5390 | |
| 5391 | QualType Types[] = { |
| 5392 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5393 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5394 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5395 | }; |
| 5396 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5397 | QualType SizeType; |
| 5398 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5399 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5400 | SizeType = Types[I]; |
| 5401 | break; |
| 5402 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5403 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5404 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5406 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5407 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5408 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5409 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5410 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5411 | QualType |
| 5412 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5413 | ArrayType::ArraySizeModifier SizeMod, |
| 5414 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5415 | unsigned IndexTypeQuals, |
| 5416 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5417 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5418 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5422 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5423 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5424 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5425 | unsigned IndexTypeQuals, |
| 5426 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5427 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5428 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5429 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5431 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5432 | QualType |
| 5433 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5434 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5435 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5436 | unsigned IndexTypeQuals, |
| 5437 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5438 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5439 | SizeExpr.takeAs<Expr>(), |
| 5440 | IndexTypeQuals, BracketsRange); |
| 5441 | } |
| 5442 | |
| 5443 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5444 | QualType |
| 5445 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5446 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5447 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5448 | unsigned IndexTypeQuals, |
| 5449 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5450 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5451 | SizeExpr.takeAs<Expr>(), |
| 5452 | IndexTypeQuals, BracketsRange); |
| 5453 | } |
| 5454 | |
| 5455 | template<typename Derived> |
| 5456 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5457 | unsigned NumElements, |
| 5458 | bool IsAltiVec, bool IsPixel) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5459 | // FIXME: semantic checking! |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5460 | return SemaRef.Context.getVectorType(ElementType, NumElements, |
| 5461 | IsAltiVec, IsPixel); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5462 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5463 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5464 | template<typename Derived> |
| 5465 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5466 | unsigned NumElements, |
| 5467 | SourceLocation AttributeLoc) { |
| 5468 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5469 | NumElements, true); |
| 5470 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5472 | AttributeLoc); |
| 5473 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5474 | AttributeLoc); |
| 5475 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5477 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5478 | QualType |
| 5479 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5480 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5481 | SourceLocation AttributeLoc) { |
| 5482 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5484 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5485 | template<typename Derived> |
| 5486 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5487 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5488 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5489 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5490 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5491 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5492 | Quals, |
| 5493 | getDerived().getBaseLocation(), |
| 5494 | getDerived().getBaseEntity()); |
| 5495 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5496 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5497 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5498 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5499 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5500 | } |
| 5501 | |
| 5502 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5503 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5504 | assert(D && "no decl found"); |
| 5505 | if (D->isInvalidDecl()) return QualType(); |
| 5506 | |
| 5507 | TypeDecl *Ty; |
| 5508 | if (isa<UsingDecl>(D)) { |
| 5509 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5510 | assert(Using->isTypeName() && |
| 5511 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5512 | |
| 5513 | // A valid resolved using typename decl points to exactly one type decl. |
| 5514 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5515 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5516 | |
| 5517 | } else { |
| 5518 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5519 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5520 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5521 | } |
| 5522 | |
| 5523 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5524 | } |
| 5525 | |
| 5526 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5527 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5528 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5529 | } |
| 5530 | |
| 5531 | template<typename Derived> |
| 5532 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5533 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5534 | } |
| 5535 | |
| 5536 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5538 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5539 | } |
| 5540 | |
| 5541 | template<typename Derived> |
| 5542 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5543 | TemplateName Template, |
| 5544 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5545 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5546 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5548 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5549 | template<typename Derived> |
| 5550 | NestedNameSpecifier * |
| 5551 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5552 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5553 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5554 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5555 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5556 | CXXScopeSpec SS; |
| 5557 | // FIXME: The source location information is all wrong. |
| 5558 | SS.setRange(Range); |
| 5559 | SS.setScopeRep(Prefix); |
| 5560 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5561 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5562 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5563 | ObjectType, |
| 5564 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5565 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | template<typename Derived> |
| 5569 | NestedNameSpecifier * |
| 5570 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5571 | SourceRange Range, |
| 5572 | NamespaceDecl *NS) { |
| 5573 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5574 | } |
| 5575 | |
| 5576 | template<typename Derived> |
| 5577 | NestedNameSpecifier * |
| 5578 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5579 | SourceRange Range, |
| 5580 | bool TemplateKW, |
| 5581 | QualType T) { |
| 5582 | if (T->isDependentType() || T->isRecordType() || |
| 5583 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5584 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5585 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5586 | T.getTypePtr()); |
| 5587 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5588 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5589 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5590 | return 0; |
| 5591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5592 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5593 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5595 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5596 | bool TemplateKW, |
| 5597 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5598 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5599 | Template); |
| 5600 | } |
| 5601 | |
| 5602 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5603 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5604 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5605 | const IdentifierInfo &II, |
| 5606 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5607 | CXXScopeSpec SS; |
| 5608 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5609 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5610 | UnqualifiedId Name; |
| 5611 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5612 | return getSema().ActOnDependentTemplateName( |
| 5613 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5614 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5615 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5616 | ObjectType.getAsOpaquePtr(), |
| 5617 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5618 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5619 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5620 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5621 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5622 | TemplateName |
| 5623 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5624 | OverloadedOperatorKind Operator, |
| 5625 | QualType ObjectType) { |
| 5626 | CXXScopeSpec SS; |
| 5627 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5628 | SS.setScopeRep(Qualifier); |
| 5629 | UnqualifiedId Name; |
| 5630 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5631 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5632 | Operator, SymbolLocations); |
| 5633 | return getSema().ActOnDependentTemplateName( |
| 5634 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5635 | SS, |
| 5636 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5637 | ObjectType.getAsOpaquePtr(), |
| 5638 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5639 | .template getAsVal<TemplateName>(); |
| 5640 | } |
| 5641 | |
| 5642 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5643 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5644 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5645 | SourceLocation OpLoc, |
| 5646 | ExprArg Callee, |
| 5647 | ExprArg First, |
| 5648 | ExprArg Second) { |
| 5649 | Expr *FirstExpr = (Expr *)First.get(); |
| 5650 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5651 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5652 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5653 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5654 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5655 | if (Op == OO_Subscript) { |
| 5656 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5657 | !SecondExpr->getType()->isOverloadableType()) |
| 5658 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5659 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5660 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5661 | } else if (Op == OO_Arrow) { |
| 5662 | // -> is never a builtin operation. |
| 5663 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5664 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5665 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5666 | // The argument is not of overloadable type, so try to create a |
| 5667 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5668 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5669 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5671 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5672 | } |
| 5673 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5675 | !SecondExpr->getType()->isOverloadableType()) { |
| 5676 | // Neither of the arguments is an overloadable type, so try to |
| 5677 | // create a built-in binary operation. |
| 5678 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5679 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5680 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5681 | if (Result.isInvalid()) |
| 5682 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5683 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5684 | First.release(); |
| 5685 | Second.release(); |
| 5686 | return move(Result); |
| 5687 | } |
| 5688 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5689 | |
| 5690 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5691 | // used during overload resolution. |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5692 | UnresolvedSet<16> Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5693 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5694 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5695 | assert(ULE->requiresADL()); |
| 5696 | |
| 5697 | // FIXME: Do we have to check |
| 5698 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5699 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5700 | } else { |
John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 5701 | Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl()); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5702 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5703 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5704 | // Add any functions found via argument-dependent lookup. |
| 5705 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5706 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5708 | // Create the overloaded operator invocation for unary operators. |
| 5709 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5710 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5711 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5712 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5713 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5714 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5715 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5716 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5717 | OpLoc, |
| 5718 | move(First), |
| 5719 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5720 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5721 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5722 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5723 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5724 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5725 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5726 | if (Result.isInvalid()) |
| 5727 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5728 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5729 | First.release(); |
| 5730 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5731 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5732 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5733 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5734 | } // end namespace clang |
| 5735 | |
| 5736 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |