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 | |
| 175 | /// \brief Transforms the given type into another type. |
| 176 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 177 | /// By default, this routine transforms a type by creating a |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 178 | /// TypeSourceInfo for it and delegating to the appropriate |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 179 | /// function. This is expensive, but we don't mind, because |
| 180 | /// this method is deprecated anyway; all users should be |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 181 | /// switched to storing TypeSourceInfos. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 182 | /// |
| 183 | /// \returns the transformed type. |
| 184 | QualType TransformType(QualType T); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 186 | /// \brief Transforms the given type-with-location into a new |
| 187 | /// type-with-location. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 188 | /// |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 189 | /// By default, this routine transforms a type by delegating to the |
| 190 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 191 | /// may override this function (to take over all type |
| 192 | /// transformations) or some set of the TransformXXXType functions |
| 193 | /// to alter the transformation. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 194 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 195 | |
| 196 | /// \brief Transform the given type-with-location into a new |
| 197 | /// type, collecting location information in the given builder |
| 198 | /// as necessary. |
| 199 | /// |
| 200 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 202 | /// \brief Transform the given statement. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 203 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 205 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 206 | /// statement or the TransformExpr() function to transform an expression. |
| 207 | /// Subclasses may override this function to transform statements using some |
| 208 | /// other mechanism. |
| 209 | /// |
| 210 | /// \returns the transformed statement. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 211 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 213 | /// \brief Transform the given expression. |
| 214 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 215 | /// By default, this routine transforms an expression by delegating to the |
| 216 | /// appropriate TransformXXXExpr function to build a new expression. |
| 217 | /// Subclasses may override this function to transform expressions using some |
| 218 | /// other mechanism. |
| 219 | /// |
| 220 | /// \returns the transformed expression. |
| 221 | OwningExprResult TransformExpr(Expr *E) { |
| 222 | return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false); |
| 223 | } |
| 224 | |
| 225 | /// \brief Transform the given expression. |
| 226 | /// |
| 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. |
| 233 | OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand); |
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) \ |
| 312 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 313 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 314 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 315 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 316 | |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 317 | QualType |
| 318 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 319 | QualType ObjectType); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 320 | |
| 321 | QualType |
| 322 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 323 | TemplateSpecializationTypeLoc TL, |
| 324 | QualType ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 328 | #define STMT(Node, Parent) \ |
| 329 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 331 | OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 332 | #define ABSTRACT_EXPR(Node, Parent) |
| 333 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 335 | /// \brief Build a new pointer type given its pointee type. |
| 336 | /// |
| 337 | /// By default, performs semantic analysis when building the pointer type. |
| 338 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 339 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 340 | |
| 341 | /// \brief Build a new block pointer type given its pointee type. |
| 342 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 348 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 349 | /// By default, performs semantic analysis when building the |
| 350 | /// reference type. Subclasses may override this routine to provide |
| 351 | /// different behavior. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 352 | /// |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 353 | /// \param LValue whether the type was written with an lvalue sigil |
| 354 | /// or an rvalue sigil. |
| 355 | QualType RebuildReferenceType(QualType ReferentType, |
| 356 | bool LValue, |
| 357 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 359 | /// \brief Build a new member pointer type given the pointee type and the |
| 360 | /// class type it refers into. |
| 361 | /// |
| 362 | /// By default, performs semantic analysis when building the member pointer |
| 363 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 364 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 365 | SourceLocation Sigil); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 367 | /// \brief Build a new Objective C object pointer type. |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 368 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 369 | SourceLocation Sigil); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 370 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 371 | /// \brief Build a new array type given the element type, size |
| 372 | /// modifier, size of the array (if known), size expression, and index type |
| 373 | /// qualifiers. |
| 374 | /// |
| 375 | /// By default, performs semantic analysis when building the array type. |
| 376 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 378 | QualType RebuildArrayType(QualType ElementType, |
| 379 | ArrayType::ArraySizeModifier SizeMod, |
| 380 | const llvm::APInt *Size, |
| 381 | Expr *SizeExpr, |
| 382 | unsigned IndexTypeQuals, |
| 383 | SourceRange BracketsRange); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | /// \brief Build a new constant array type given the element type, size |
| 386 | /// modifier, (known) size of the array, and index type qualifiers. |
| 387 | /// |
| 388 | /// By default, performs semantic analysis when building the array type. |
| 389 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 391 | ArrayType::ArraySizeModifier SizeMod, |
| 392 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 393 | unsigned IndexTypeQuals, |
| 394 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 395 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 396 | /// \brief Build a new incomplete array type given the element type, size |
| 397 | /// modifier, and index type qualifiers. |
| 398 | /// |
| 399 | /// By default, performs semantic analysis when building the array type. |
| 400 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 402 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 403 | unsigned IndexTypeQuals, |
| 404 | SourceRange BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 407 | /// size modifier, size expression, and index type qualifiers. |
| 408 | /// |
| 409 | /// By default, performs semantic analysis when building the array type. |
| 410 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 413 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 414 | unsigned IndexTypeQuals, |
| 415 | SourceRange BracketsRange); |
| 416 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 418 | /// size modifier, size expression, and index type qualifiers. |
| 419 | /// |
| 420 | /// By default, performs semantic analysis when building the array type. |
| 421 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 424 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 425 | unsigned IndexTypeQuals, |
| 426 | SourceRange BracketsRange); |
| 427 | |
| 428 | /// \brief Build a new vector type given the element type and |
| 429 | /// number of elements. |
| 430 | /// |
| 431 | /// By default, performs semantic analysis when building the vector type. |
| 432 | /// Subclasses may override this routine to provide different behavior. |
| 433 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 435 | /// \brief Build a new extended vector type given the element type and |
| 436 | /// number of elements. |
| 437 | /// |
| 438 | /// By default, performs semantic analysis when building the vector type. |
| 439 | /// Subclasses may override this routine to provide different behavior. |
| 440 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 441 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
| 443 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 444 | /// given the element type and number of elements. |
| 445 | /// |
| 446 | /// By default, performs semantic analysis when building the vector type. |
| 447 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 449 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | SourceLocation AttributeLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 451 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 452 | /// \brief Build a new function type. |
| 453 | /// |
| 454 | /// By default, performs semantic analysis when building the function type. |
| 455 | /// Subclasses may override this routine to provide different behavior. |
| 456 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 458 | unsigned NumParamTypes, |
| 459 | bool Variadic, unsigned Quals); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 461 | /// \brief Build a new unprototyped function type. |
| 462 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 463 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 464 | /// \brief Rebuild an unresolved typename type, given the decl that |
| 465 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 466 | QualType RebuildUnresolvedUsingType(Decl *D); |
| 467 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 468 | /// \brief Build a new typedef type. |
| 469 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 470 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 471 | } |
| 472 | |
| 473 | /// \brief Build a new class/struct/union type. |
| 474 | QualType RebuildRecordType(RecordDecl *Record) { |
| 475 | return SemaRef.Context.getTypeDeclType(Record); |
| 476 | } |
| 477 | |
| 478 | /// \brief Build a new Enum type. |
| 479 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 480 | return SemaRef.Context.getTypeDeclType(Enum); |
| 481 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 482 | |
| 483 | /// \brief Build a new elaborated type. |
| 484 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 485 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
| 488 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 489 | /// |
| 490 | /// By default, performs semantic analysis when building the typeof type. |
| 491 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 492 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 493 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 494 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 495 | /// |
| 496 | /// By default, builds a new TypeOfType with the given underlying type. |
| 497 | QualType RebuildTypeOfType(QualType Underlying); |
| 498 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 500 | /// |
| 501 | /// By default, performs semantic analysis when building the decltype type. |
| 502 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 503 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 505 | /// \brief Build a new template specialization type. |
| 506 | /// |
| 507 | /// By default, performs semantic analysis when building the template |
| 508 | /// specialization type. Subclasses may override this routine to provide |
| 509 | /// different behavior. |
| 510 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 511 | SourceLocation TemplateLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 512 | const TemplateArgumentListInfo &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 514 | /// \brief Build a new qualified name type. |
| 515 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | /// By default, builds a new QualifiedNameType type from the |
| 517 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 518 | /// this routine to provide different behavior. |
| 519 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 520 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 521 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 522 | |
| 523 | /// \brief Build a new typename type that refers to a template-id. |
| 524 | /// |
| 525 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 527 | /// different behavior. |
| 528 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 529 | if (NNS->isDependent()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 531 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 533 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
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 | |
| 536 | /// \brief Build a new typename type that refers to an identifier. |
| 537 | /// |
| 538 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 540 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 541 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 542 | const IdentifierInfo *Id, |
| 543 | SourceRange SR) { |
| 544 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 545 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 547 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 548 | /// identifier that names the next step in the nested-name-specifier. |
| 549 | /// |
| 550 | /// By default, performs semantic analysis when building the new |
| 551 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 552 | /// different behavior. |
| 553 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 554 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 555 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 556 | QualType ObjectType, |
| 557 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 558 | |
| 559 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 560 | /// namespace named in the next step in the nested-name-specifier. |
| 561 | /// |
| 562 | /// By default, performs semantic analysis when building the new |
| 563 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 564 | /// different behavior. |
| 565 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 566 | SourceRange Range, |
| 567 | NamespaceDecl *NS); |
| 568 | |
| 569 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 570 | /// type named in the next step in the nested-name-specifier. |
| 571 | /// |
| 572 | /// By default, performs semantic analysis when building the new |
| 573 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 574 | /// different behavior. |
| 575 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 576 | SourceRange Range, |
| 577 | bool TemplateKW, |
| 578 | QualType T); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 579 | |
| 580 | /// \brief Build a new template name given a nested name specifier, a flag |
| 581 | /// indicating whether the "template" keyword was provided, and the template |
| 582 | /// that the template name refers to. |
| 583 | /// |
| 584 | /// By default, builds the new template name directly. Subclasses may override |
| 585 | /// this routine to provide different behavior. |
| 586 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 587 | bool TemplateKW, |
| 588 | TemplateDecl *Template); |
| 589 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 590 | /// \brief Build a new template name given a nested name specifier and the |
| 591 | /// name that is referred to as a template. |
| 592 | /// |
| 593 | /// By default, performs semantic analysis to determine whether the name can |
| 594 | /// be resolved to a specific template, then builds the appropriate kind of |
| 595 | /// template name. Subclasses may override this routine to provide different |
| 596 | /// behavior. |
| 597 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 598 | const IdentifierInfo &II, |
| 599 | QualType ObjectType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 600 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 601 | /// \brief Build a new template name given a nested name specifier and the |
| 602 | /// overloaded operator name that is referred to as a template. |
| 603 | /// |
| 604 | /// By default, performs semantic analysis to determine whether the name can |
| 605 | /// be resolved to a specific template, then builds the appropriate kind of |
| 606 | /// template name. Subclasses may override this routine to provide different |
| 607 | /// behavior. |
| 608 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 609 | OverloadedOperatorKind Operator, |
| 610 | QualType ObjectType); |
| 611 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 612 | /// \brief Build a new compound statement. |
| 613 | /// |
| 614 | /// By default, performs semantic analysis to build the new statement. |
| 615 | /// Subclasses may override this routine to provide different behavior. |
| 616 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 617 | MultiStmtArg Statements, |
| 618 | SourceLocation RBraceLoc, |
| 619 | bool IsStmtExpr) { |
| 620 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 621 | IsStmtExpr); |
| 622 | } |
| 623 | |
| 624 | /// \brief Build a new case statement. |
| 625 | /// |
| 626 | /// By default, performs semantic analysis to build the new statement. |
| 627 | /// Subclasses may override this routine to provide different behavior. |
| 628 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 629 | ExprArg LHS, |
| 630 | SourceLocation EllipsisLoc, |
| 631 | ExprArg RHS, |
| 632 | SourceLocation ColonLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 634 | ColonLoc); |
| 635 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 637 | /// \brief Attach the body to a new case statement. |
| 638 | /// |
| 639 | /// By default, performs semantic analysis to build the new statement. |
| 640 | /// Subclasses may override this routine to provide different behavior. |
| 641 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 642 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 643 | return move(S); |
| 644 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 646 | /// \brief Build a new default statement. |
| 647 | /// |
| 648 | /// By default, performs semantic analysis to build the new statement. |
| 649 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 651 | SourceLocation ColonLoc, |
| 652 | StmtArg SubStmt) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 653 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 654 | /*CurScope=*/0); |
| 655 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 656 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 657 | /// \brief Build a new label statement. |
| 658 | /// |
| 659 | /// By default, performs semantic analysis to build the new statement. |
| 660 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 662 | IdentifierInfo *Id, |
| 663 | SourceLocation ColonLoc, |
| 664 | StmtArg SubStmt) { |
| 665 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 666 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 668 | /// \brief Build a new "if" statement. |
| 669 | /// |
| 670 | /// By default, performs semantic analysis to build the new statement. |
| 671 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 673 | VarDecl *CondVar, StmtArg Then, |
| 674 | SourceLocation ElseLoc, StmtArg Else) { |
| 675 | return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar), |
| 676 | move(Then), ElseLoc, move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 677 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 678 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 679 | /// \brief Start building a new switch statement. |
| 680 | /// |
| 681 | /// By default, performs semantic analysis to build the new statement. |
| 682 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 683 | OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond, |
| 684 | VarDecl *CondVar) { |
| 685 | return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 686 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 688 | /// \brief Attach the body to the switch statement. |
| 689 | /// |
| 690 | /// By default, performs semantic analysis to build the new statement. |
| 691 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 693 | StmtArg Switch, StmtArg Body) { |
| 694 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 695 | move(Body)); |
| 696 | } |
| 697 | |
| 698 | /// \brief Build a new while statement. |
| 699 | /// |
| 700 | /// By default, performs semantic analysis to build the new statement. |
| 701 | /// Subclasses may override this routine to provide different behavior. |
| 702 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 703 | Sema::FullExprArg Cond, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 704 | VarDecl *CondVar, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 705 | StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 706 | return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar), |
| 707 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 708 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 709 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 710 | /// \brief Build a new do-while statement. |
| 711 | /// |
| 712 | /// By default, performs semantic analysis to build the new statement. |
| 713 | /// Subclasses may override this routine to provide different behavior. |
| 714 | OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, |
| 715 | SourceLocation WhileLoc, |
| 716 | SourceLocation LParenLoc, |
| 717 | ExprArg Cond, |
| 718 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 720 | move(Cond), RParenLoc); |
| 721 | } |
| 722 | |
| 723 | /// \brief Build a new for statement. |
| 724 | /// |
| 725 | /// By default, performs semantic analysis to build the new statement. |
| 726 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 728 | SourceLocation LParenLoc, |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 729 | StmtArg Init, Sema::FullExprArg Cond, |
| 730 | VarDecl *CondVar, Sema::FullExprArg Inc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 731 | SourceLocation RParenLoc, StmtArg Body) { |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 732 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, |
| 733 | DeclPtrTy::make(CondVar), |
| 734 | Inc, RParenLoc, move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 737 | /// \brief Build a new goto statement. |
| 738 | /// |
| 739 | /// By default, performs semantic analysis to build the new statement. |
| 740 | /// Subclasses may override this routine to provide different behavior. |
| 741 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 742 | SourceLocation LabelLoc, |
| 743 | LabelStmt *Label) { |
| 744 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 745 | } |
| 746 | |
| 747 | /// \brief Build a new indirect goto statement. |
| 748 | /// |
| 749 | /// By default, performs semantic analysis to build the new statement. |
| 750 | /// Subclasses may override this routine to provide different behavior. |
| 751 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 752 | SourceLocation StarLoc, |
| 753 | ExprArg Target) { |
| 754 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 755 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 757 | /// \brief Build a new return statement. |
| 758 | /// |
| 759 | /// By default, performs semantic analysis to build the new statement. |
| 760 | /// Subclasses may override this routine to provide different behavior. |
| 761 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 762 | ExprArg Result) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 764 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 765 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 767 | /// \brief Build a new declaration statement. |
| 768 | /// |
| 769 | /// By default, performs semantic analysis to build the new statement. |
| 770 | /// Subclasses may override this routine to provide different behavior. |
| 771 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 772 | SourceLocation StartLoc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 773 | SourceLocation EndLoc) { |
| 774 | return getSema().Owned( |
| 775 | new (getSema().Context) DeclStmt( |
| 776 | DeclGroupRef::Create(getSema().Context, |
| 777 | Decls, NumDecls), |
| 778 | StartLoc, EndLoc)); |
| 779 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 780 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 781 | /// \brief Build a new C++ exception declaration. |
| 782 | /// |
| 783 | /// By default, performs semantic analysis to build the new decaration. |
| 784 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 786 | TypeSourceInfo *Declarator, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 787 | IdentifierInfo *Name, |
| 788 | SourceLocation Loc, |
| 789 | SourceRange TypeRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 791 | TypeRange); |
| 792 | } |
| 793 | |
| 794 | /// \brief Build a new C++ catch statement. |
| 795 | /// |
| 796 | /// By default, performs semantic analysis to build the new statement. |
| 797 | /// Subclasses may override this routine to provide different behavior. |
| 798 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 799 | VarDecl *ExceptionDecl, |
| 800 | StmtArg Handler) { |
| 801 | return getSema().Owned( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 802 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 803 | Handler.takeAs<Stmt>())); |
| 804 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 806 | /// \brief Build a new C++ try statement. |
| 807 | /// |
| 808 | /// By default, performs semantic analysis to build the new statement. |
| 809 | /// Subclasses may override this routine to provide different behavior. |
| 810 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 811 | StmtArg TryBlock, |
| 812 | MultiStmtArg Handlers) { |
| 813 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 814 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 815 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 816 | /// \brief Build a new expression that references a declaration. |
| 817 | /// |
| 818 | /// By default, performs semantic analysis to build the new expression. |
| 819 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 820 | OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 821 | LookupResult &R, |
| 822 | bool RequiresADL) { |
| 823 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 824 | } |
| 825 | |
| 826 | |
| 827 | /// \brief Build a new expression that references a declaration. |
| 828 | /// |
| 829 | /// By default, performs semantic analysis to build the new expression. |
| 830 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 831 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 832 | SourceRange QualifierRange, |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 833 | ValueDecl *VD, SourceLocation Loc, |
| 834 | TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 835 | CXXScopeSpec SS; |
| 836 | SS.setScopeRep(Qualifier); |
| 837 | SS.setRange(QualifierRange); |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 838 | |
| 839 | // FIXME: loses template args. |
| 840 | |
| 841 | return getSema().BuildDeclarationNameExpr(SS, Loc, VD); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 844 | /// \brief Build a new expression in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 846 | /// By default, performs semantic analysis to build the new expression. |
| 847 | /// Subclasses may override this routine to provide different behavior. |
| 848 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 849 | SourceLocation RParen) { |
| 850 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 851 | } |
| 852 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 853 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | /// |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 855 | /// By default, performs semantic analysis to build the new expression. |
| 856 | /// Subclasses may override this routine to provide different behavior. |
| 857 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 858 | SourceLocation OperatorLoc, |
| 859 | bool isArrow, |
| 860 | SourceLocation DestroyedTypeLoc, |
| 861 | QualType DestroyedType, |
| 862 | NestedNameSpecifier *Qualifier, |
| 863 | SourceRange QualifierRange) { |
| 864 | CXXScopeSpec SS; |
| 865 | if (Qualifier) { |
| 866 | SS.setRange(QualifierRange); |
| 867 | SS.setScopeRep(Qualifier); |
| 868 | } |
| 869 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 870 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 871 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | DeclarationName Name |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 873 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 874 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 875 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 876 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 877 | OperatorLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 878 | SS, /*FIXME: FirstQualifier*/ 0, |
| 879 | Name, DestroyedTypeLoc, |
| 880 | /*TemplateArgs*/ 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 883 | /// \brief Build a new unary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 885 | /// By default, performs semantic analysis to build the new expression. |
| 886 | /// Subclasses may override this routine to provide different behavior. |
| 887 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 888 | UnaryOperator::Opcode Opc, |
| 889 | ExprArg SubExpr) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 890 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 895 | /// By default, performs semantic analysis to build the new expression. |
| 896 | /// Subclasses may override this routine to provide different behavior. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 897 | OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 898 | SourceLocation OpLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 899 | bool isSizeOf, SourceRange R) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 900 | return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 904 | /// argument. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 906 | /// By default, performs semantic analysis to build the new expression. |
| 907 | /// Subclasses may override this routine to provide different behavior. |
| 908 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 909 | bool isSizeOf, SourceRange R) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 910 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 911 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 912 | OpLoc, isSizeOf, R); |
| 913 | if (Result.isInvalid()) |
| 914 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 916 | SubExpr.release(); |
| 917 | return move(Result); |
| 918 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 920 | /// \brief Build a new array subscript expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 922 | /// By default, performs semantic analysis to build the new expression. |
| 923 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 925 | SourceLocation LBracketLoc, |
| 926 | ExprArg RHS, |
| 927 | SourceLocation RBracketLoc) { |
| 928 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | LBracketLoc, move(RHS), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 930 | RBracketLoc); |
| 931 | } |
| 932 | |
| 933 | /// \brief Build a new call expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 935 | /// By default, performs semantic analysis to build the new expression. |
| 936 | /// Subclasses may override this routine to provide different behavior. |
| 937 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 938 | MultiExprArg Args, |
| 939 | SourceLocation *CommaLocs, |
| 940 | SourceLocation RParenLoc) { |
| 941 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 942 | move(Args), CommaLocs, RParenLoc); |
| 943 | } |
| 944 | |
| 945 | /// \brief Build a new member access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 946 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 947 | /// By default, performs semantic analysis to build the new expression. |
| 948 | /// Subclasses may override this routine to provide different behavior. |
| 949 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | bool isArrow, |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 951 | NestedNameSpecifier *Qualifier, |
| 952 | SourceRange QualifierRange, |
| 953 | SourceLocation MemberLoc, |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 954 | ValueDecl *Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 955 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 956 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 957 | if (!Member->getDeclName()) { |
| 958 | // We have a reference to an unnamed field. |
| 959 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | |
| 961 | MemberExpr *ME = |
Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 962 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 963 | Member, MemberLoc, |
| 964 | cast<FieldDecl>(Member)->getType()); |
| 965 | return getSema().Owned(ME); |
| 966 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 968 | CXXScopeSpec SS; |
| 969 | if (Qualifier) { |
| 970 | SS.setRange(QualifierRange); |
| 971 | SS.setScopeRep(Qualifier); |
| 972 | } |
| 973 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 974 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 975 | |
| 976 | // FIXME: wait, this is re-performing lookup? |
| 977 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
| 978 | OpLoc, isArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 979 | SS, FirstQualifierInScope, |
| 980 | Member->getDeclName(), MemberLoc, |
| 981 | ExplicitTemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 982 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 984 | /// \brief Build a new binary operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 986 | /// By default, performs semantic analysis to build the new expression. |
| 987 | /// Subclasses may override this routine to provide different behavior. |
| 988 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 989 | BinaryOperator::Opcode Opc, |
| 990 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 5287f09 | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 991 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 992 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /// \brief Build a new conditional operator expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 997 | /// By default, performs semantic analysis to build the new expression. |
| 998 | /// Subclasses may override this routine to provide different behavior. |
| 999 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 1000 | SourceLocation QuestionLoc, |
| 1001 | ExprArg LHS, |
| 1002 | SourceLocation ColonLoc, |
| 1003 | ExprArg RHS) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1005 | move(LHS), move(RHS)); |
| 1006 | } |
| 1007 | |
| 1008 | /// \brief Build a new implicit cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | /// By default, builds a new implicit cast without any semantic analysis. |
| 1011 | /// Subclasses may override this routine to provide different behavior. |
| 1012 | OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, |
| 1013 | ExprArg SubExpr, bool isLvalue) { |
| 1014 | ImplicitCastExpr *ICE |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1015 | = new (getSema().Context) ImplicitCastExpr(T, Kind, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1016 | (Expr *)SubExpr.release(), |
| 1017 | isLvalue); |
| 1018 | return getSema().Owned(ICE); |
| 1019 | } |
| 1020 | |
| 1021 | /// \brief Build a new C-style cast expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | /// By default, performs semantic analysis to build the new expression. |
| 1024 | /// Subclasses may override this routine to provide different behavior. |
| 1025 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1026 | QualType ExplicitTy, |
| 1027 | SourceLocation RParenLoc, |
| 1028 | ExprArg SubExpr) { |
| 1029 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1030 | LParenLoc, |
| 1031 | ExplicitTy.getAsOpaquePtr(), |
| 1032 | RParenLoc, |
| 1033 | move(SubExpr)); |
| 1034 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1036 | /// \brief Build a new compound literal expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1038 | /// By default, performs semantic analysis to build the new expression. |
| 1039 | /// Subclasses may override this routine to provide different behavior. |
| 1040 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1041 | QualType T, |
| 1042 | SourceLocation RParenLoc, |
| 1043 | ExprArg Init) { |
| 1044 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1045 | RParenLoc, move(Init)); |
| 1046 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1048 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1050 | /// By default, performs semantic analysis to build the new expression. |
| 1051 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1053 | SourceLocation OpLoc, |
| 1054 | SourceLocation AccessorLoc, |
| 1055 | IdentifierInfo &Accessor) { |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1056 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1057 | CXXScopeSpec SS; |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1058 | QualType BaseType = ((Expr*) Base.get())->getType(); |
| 1059 | return getSema().BuildMemberReferenceExpr(move(Base), BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1060 | OpLoc, /*IsArrow*/ false, |
| 1061 | SS, /*FirstQualifierInScope*/ 0, |
Douglas Gregor | 30d60cb | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1062 | DeclarationName(&Accessor), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1063 | AccessorLoc, |
| 1064 | /* TemplateArgs */ 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1065 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1067 | /// \brief Build a new initializer list expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | /// By default, performs semantic analysis to build the new expression. |
| 1070 | /// Subclasses may override this routine to provide different behavior. |
| 1071 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1072 | MultiExprArg Inits, |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1073 | SourceLocation RBraceLoc, |
| 1074 | QualType ResultTy) { |
| 1075 | OwningExprResult Result |
| 1076 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1077 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1078 | return move(Result); |
| 1079 | |
| 1080 | // Patch in the result type we were given, which may have been computed |
| 1081 | // when the initial InitListExpr was built. |
| 1082 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1083 | ILE->setType(ResultTy); |
| 1084 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1085 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1087 | /// \brief Build a new designated initializer expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1088 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1089 | /// By default, performs semantic analysis to build the new expression. |
| 1090 | /// Subclasses may override this routine to provide different behavior. |
| 1091 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1092 | MultiExprArg ArrayExprs, |
| 1093 | SourceLocation EqualOrColonLoc, |
| 1094 | bool GNUSyntax, |
| 1095 | ExprArg Init) { |
| 1096 | OwningExprResult Result |
| 1097 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1098 | move(Init)); |
| 1099 | if (Result.isInvalid()) |
| 1100 | return SemaRef.ExprError(); |
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 | ArrayExprs.release(); |
| 1103 | return move(Result); |
| 1104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1106 | /// \brief Build a new value-initialized expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1108 | /// By default, builds the implicit value initialization without performing |
| 1109 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1110 | /// different behavior. |
| 1111 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1112 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1113 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1115 | /// \brief Build a new \c va_arg expression. |
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 | /// By default, performs semantic analysis to build the new expression. |
| 1118 | /// Subclasses may override this routine to provide different behavior. |
| 1119 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1120 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1122 | RParenLoc); |
| 1123 | } |
| 1124 | |
| 1125 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1127 | /// By default, performs semantic analysis to build the new expression. |
| 1128 | /// Subclasses may override this routine to provide different behavior. |
| 1129 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1130 | MultiExprArg SubExprs, |
| 1131 | SourceLocation RParenLoc) { |
Fariborz Jahanian | 906d871 | 2009-11-25 01:26:41 +0000 | [diff] [blame] | 1132 | return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, |
| 1133 | move(SubExprs)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1134 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1136 | /// \brief Build a new address-of-label expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | /// |
| 1138 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1139 | /// rather than attempting to map the label statement itself. |
| 1140 | /// Subclasses may override this routine to provide different behavior. |
| 1141 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1142 | SourceLocation LabelLoc, |
| 1143 | LabelStmt *Label) { |
| 1144 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1145 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1146 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1147 | /// \brief Build a new GNU statement expression. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1148 | /// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1149 | /// By default, performs semantic analysis to build the new expression. |
| 1150 | /// Subclasses may override this routine to provide different behavior. |
| 1151 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1152 | StmtArg SubStmt, |
| 1153 | SourceLocation RParenLoc) { |
| 1154 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1156 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1157 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1158 | /// |
| 1159 | /// By default, performs semantic analysis to build the new expression. |
| 1160 | /// Subclasses may override this routine to provide different behavior. |
| 1161 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1162 | QualType T1, QualType T2, |
| 1163 | SourceLocation RParenLoc) { |
| 1164 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1165 | T1.getAsOpaquePtr(), |
| 1166 | T2.getAsOpaquePtr(), |
| 1167 | RParenLoc); |
| 1168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1170 | /// \brief Build a new __builtin_choose_expr expression. |
| 1171 | /// |
| 1172 | /// By default, performs semantic analysis to build the new expression. |
| 1173 | /// Subclasses may override this routine to provide different behavior. |
| 1174 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1175 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1176 | SourceLocation RParenLoc) { |
| 1177 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1178 | move(Cond), move(LHS), move(RHS), |
| 1179 | RParenLoc); |
| 1180 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1182 | /// \brief Build a new overloaded operator call expression. |
| 1183 | /// |
| 1184 | /// By default, performs semantic analysis to build the new expression. |
| 1185 | /// The semantic analysis provides the behavior of template instantiation, |
| 1186 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1188 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1189 | /// provide different behavior. |
| 1190 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1191 | SourceLocation OpLoc, |
| 1192 | ExprArg Callee, |
| 1193 | ExprArg First, |
| 1194 | ExprArg Second); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1195 | |
| 1196 | /// \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] | 1197 | /// reinterpret_cast. |
| 1198 | /// |
| 1199 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1201 | /// Subclasses may override this routine to provide different behavior. |
| 1202 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1203 | Stmt::StmtClass Class, |
| 1204 | SourceLocation LAngleLoc, |
| 1205 | QualType T, |
| 1206 | SourceLocation RAngleLoc, |
| 1207 | SourceLocation LParenLoc, |
| 1208 | ExprArg SubExpr, |
| 1209 | SourceLocation RParenLoc) { |
| 1210 | switch (Class) { |
| 1211 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1213 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1214 | move(SubExpr), RParenLoc); |
| 1215 | |
| 1216 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1218 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1219 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1223 | RAngleLoc, LParenLoc, |
| 1224 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1225 | RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1227 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1229 | RAngleLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1230 | move(SubExpr), RParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1232 | default: |
| 1233 | assert(false && "Invalid C++ named cast"); |
| 1234 | break; |
| 1235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1237 | return getSema().ExprError(); |
| 1238 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1239 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1240 | /// \brief Build a new C++ static_cast expression. |
| 1241 | /// |
| 1242 | /// By default, performs semantic analysis to build the new expression. |
| 1243 | /// Subclasses may override this routine to provide different behavior. |
| 1244 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1245 | SourceLocation LAngleLoc, |
| 1246 | QualType T, |
| 1247 | SourceLocation RAngleLoc, |
| 1248 | SourceLocation LParenLoc, |
| 1249 | ExprArg SubExpr, |
| 1250 | SourceLocation RParenLoc) { |
| 1251 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1253 | LParenLoc, move(SubExpr), RParenLoc); |
| 1254 | } |
| 1255 | |
| 1256 | /// \brief Build a new C++ dynamic_cast expression. |
| 1257 | /// |
| 1258 | /// By default, performs semantic analysis to build the new expression. |
| 1259 | /// Subclasses may override this routine to provide different behavior. |
| 1260 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1261 | SourceLocation LAngleLoc, |
| 1262 | QualType T, |
| 1263 | SourceLocation RAngleLoc, |
| 1264 | SourceLocation LParenLoc, |
| 1265 | ExprArg SubExpr, |
| 1266 | SourceLocation RParenLoc) { |
| 1267 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1268 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1269 | LParenLoc, move(SubExpr), RParenLoc); |
| 1270 | } |
| 1271 | |
| 1272 | /// \brief Build a new C++ reinterpret_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 RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1277 | SourceLocation LAngleLoc, |
| 1278 | QualType T, |
| 1279 | SourceLocation RAngleLoc, |
| 1280 | SourceLocation LParenLoc, |
| 1281 | ExprArg SubExpr, |
| 1282 | SourceLocation RParenLoc) { |
| 1283 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1284 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1285 | LParenLoc, move(SubExpr), RParenLoc); |
| 1286 | } |
| 1287 | |
| 1288 | /// \brief Build a new C++ const_cast expression. |
| 1289 | /// |
| 1290 | /// By default, performs semantic analysis to build the new expression. |
| 1291 | /// Subclasses may override this routine to provide different behavior. |
| 1292 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1293 | SourceLocation LAngleLoc, |
| 1294 | QualType T, |
| 1295 | SourceLocation RAngleLoc, |
| 1296 | SourceLocation LParenLoc, |
| 1297 | ExprArg SubExpr, |
| 1298 | SourceLocation RParenLoc) { |
| 1299 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1301 | LParenLoc, move(SubExpr), RParenLoc); |
| 1302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1304 | /// \brief Build a new C++ functional-style cast expression. |
| 1305 | /// |
| 1306 | /// By default, performs semantic analysis to build the new expression. |
| 1307 | /// Subclasses may override this routine to provide different behavior. |
| 1308 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1309 | QualType T, |
| 1310 | SourceLocation LParenLoc, |
| 1311 | ExprArg SubExpr, |
| 1312 | SourceLocation RParenLoc) { |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1313 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1314 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1315 | T.getAsOpaquePtr(), |
| 1316 | LParenLoc, |
Chris Lattner | dca1959 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1317 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | /*CommaLocs=*/0, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1319 | RParenLoc); |
| 1320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1321 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1322 | /// \brief Build a new C++ typeid(type) expression. |
| 1323 | /// |
| 1324 | /// By default, performs semantic analysis to build the new expression. |
| 1325 | /// Subclasses may override this routine to provide different behavior. |
| 1326 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1327 | SourceLocation LParenLoc, |
| 1328 | QualType T, |
| 1329 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1331 | T.getAsOpaquePtr(), RParenLoc); |
| 1332 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1334 | /// \brief Build a new C++ typeid(expr) expression. |
| 1335 | /// |
| 1336 | /// By default, performs semantic analysis to build the new expression. |
| 1337 | /// Subclasses may override this routine to provide different behavior. |
| 1338 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1339 | SourceLocation LParenLoc, |
| 1340 | ExprArg Operand, |
| 1341 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1343 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1344 | RParenLoc); |
| 1345 | if (Result.isInvalid()) |
| 1346 | return getSema().ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1348 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1349 | return move(Result); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1352 | /// \brief Build a new C++ "this" expression. |
| 1353 | /// |
| 1354 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1356 | /// different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1358 | QualType ThisType) { |
| 1359 | return getSema().Owned( |
| 1360 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1361 | } |
| 1362 | |
| 1363 | /// \brief Build a new C++ throw expression. |
| 1364 | /// |
| 1365 | /// By default, performs semantic analysis to build the new expression. |
| 1366 | /// Subclasses may override this routine to provide different behavior. |
| 1367 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1368 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1369 | } |
| 1370 | |
| 1371 | /// \brief Build a new C++ default-argument expression. |
| 1372 | /// |
| 1373 | /// By default, builds a new default-argument expression, which does not |
| 1374 | /// require any semantic analysis. Subclasses may override this routine to |
| 1375 | /// provide different behavior. |
| 1376 | OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) { |
Anders Carlsson | e827123 | 2009-08-14 18:30:22 +0000 | [diff] [blame] | 1377 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | /// \brief Build a new C++ zero-initialization expression. |
| 1381 | /// |
| 1382 | /// By default, performs semantic analysis to build the new expression. |
| 1383 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1384 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1385 | SourceLocation LParenLoc, |
| 1386 | QualType T, |
| 1387 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1389 | T.getAsOpaquePtr(), LParenLoc, |
| 1390 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1391 | 0, RParenLoc); |
| 1392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1394 | /// \brief Build a new C++ "new" expression. |
| 1395 | /// |
| 1396 | /// By default, performs semantic analysis to build the new expression. |
| 1397 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1399 | bool UseGlobal, |
| 1400 | SourceLocation PlacementLParen, |
| 1401 | MultiExprArg PlacementArgs, |
| 1402 | SourceLocation PlacementRParen, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1403 | bool ParenTypeId, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1404 | QualType AllocType, |
| 1405 | SourceLocation TypeLoc, |
| 1406 | SourceRange TypeRange, |
| 1407 | ExprArg ArraySize, |
| 1408 | SourceLocation ConstructorLParen, |
| 1409 | MultiExprArg ConstructorArgs, |
| 1410 | SourceLocation ConstructorRParen) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1411 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1412 | PlacementLParen, |
| 1413 | move(PlacementArgs), |
| 1414 | PlacementRParen, |
| 1415 | ParenTypeId, |
| 1416 | AllocType, |
| 1417 | TypeLoc, |
| 1418 | TypeRange, |
| 1419 | move(ArraySize), |
| 1420 | ConstructorLParen, |
| 1421 | move(ConstructorArgs), |
| 1422 | ConstructorRParen); |
| 1423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1425 | /// \brief Build a new C++ "delete" expression. |
| 1426 | /// |
| 1427 | /// By default, performs semantic analysis to build the new expression. |
| 1428 | /// Subclasses may override this routine to provide different behavior. |
| 1429 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1430 | bool IsGlobalDelete, |
| 1431 | bool IsArrayForm, |
| 1432 | ExprArg Operand) { |
| 1433 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1434 | move(Operand)); |
| 1435 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1436 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1437 | /// \brief Build a new unary type trait expression. |
| 1438 | /// |
| 1439 | /// By default, performs semantic analysis to build the new expression. |
| 1440 | /// Subclasses may override this routine to provide different behavior. |
| 1441 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1442 | SourceLocation StartLoc, |
| 1443 | SourceLocation LParenLoc, |
| 1444 | QualType T, |
| 1445 | SourceLocation RParenLoc) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1446 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1447 | T.getAsOpaquePtr(), RParenLoc); |
| 1448 | } |
| 1449 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1451 | /// expression. |
| 1452 | /// |
| 1453 | /// By default, performs semantic analysis to build the new expression. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1455 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1456 | SourceRange QualifierRange, |
| 1457 | DeclarationName Name, |
| 1458 | SourceLocation Location, |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1459 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1460 | CXXScopeSpec SS; |
| 1461 | SS.setRange(QualifierRange); |
| 1462 | SS.setScopeRep(NNS); |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1463 | |
| 1464 | if (TemplateArgs) |
| 1465 | return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location, |
| 1466 | *TemplateArgs); |
| 1467 | |
| 1468 | return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | /// \brief Build a new template-id expression. |
| 1472 | /// |
| 1473 | /// By default, performs semantic analysis to build the new expression. |
| 1474 | /// Subclasses may override this routine to provide different behavior. |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1475 | OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 1476 | LookupResult &R, |
| 1477 | bool RequiresADL, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1478 | const TemplateArgumentListInfo &TemplateArgs) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1479 | return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /// \brief Build a new object-construction expression. |
| 1483 | /// |
| 1484 | /// By default, performs semantic analysis to build the new expression. |
| 1485 | /// Subclasses may override this routine to provide different behavior. |
| 1486 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
| 1487 | CXXConstructorDecl *Constructor, |
| 1488 | bool IsElidable, |
| 1489 | MultiExprArg Args) { |
Anders Carlsson | 1b4ebfa | 2009-09-05 07:40:38 +0000 | [diff] [blame] | 1490 | return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/ |
| 1491 | SourceLocation(), |
| 1492 | T, Constructor, IsElidable, |
Anders Carlsson | 5995a3e | 2009-09-07 22:23:31 +0000 | [diff] [blame] | 1493 | move(Args)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /// \brief Build a new object-construction expression. |
| 1497 | /// |
| 1498 | /// By default, performs semantic analysis to build the new expression. |
| 1499 | /// Subclasses may override this routine to provide different behavior. |
| 1500 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1501 | QualType T, |
| 1502 | SourceLocation LParenLoc, |
| 1503 | MultiExprArg Args, |
| 1504 | SourceLocation *Commas, |
| 1505 | SourceLocation RParenLoc) { |
| 1506 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1507 | T.getAsOpaquePtr(), |
| 1508 | LParenLoc, |
| 1509 | move(Args), |
| 1510 | Commas, |
| 1511 | RParenLoc); |
| 1512 | } |
| 1513 | |
| 1514 | /// \brief Build a new object-construction expression. |
| 1515 | /// |
| 1516 | /// By default, performs semantic analysis to build the new expression. |
| 1517 | /// Subclasses may override this routine to provide different behavior. |
| 1518 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1519 | QualType T, |
| 1520 | SourceLocation LParenLoc, |
| 1521 | MultiExprArg Args, |
| 1522 | SourceLocation *Commas, |
| 1523 | SourceLocation RParenLoc) { |
| 1524 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1525 | /*FIXME*/LParenLoc), |
| 1526 | T.getAsOpaquePtr(), |
| 1527 | LParenLoc, |
| 1528 | move(Args), |
| 1529 | Commas, |
| 1530 | RParenLoc); |
| 1531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | /// \brief Build a new member reference expression. |
| 1534 | /// |
| 1535 | /// By default, performs semantic analysis to build the new expression. |
| 1536 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1537 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1538 | QualType BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1539 | bool IsArrow, |
| 1540 | SourceLocation OperatorLoc, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1541 | NestedNameSpecifier *Qualifier, |
| 1542 | SourceRange QualifierRange, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1543 | NamedDecl *FirstQualifierInScope, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1544 | DeclarationName Name, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1545 | SourceLocation MemberLoc, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1546 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1547 | CXXScopeSpec SS; |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1548 | SS.setRange(QualifierRange); |
| 1549 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1551 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1552 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1553 | SS, FirstQualifierInScope, |
| 1554 | Name, MemberLoc, TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1557 | /// \brief Build a new member reference expression. |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1558 | /// |
| 1559 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1561 | OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1562 | QualType BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1563 | SourceLocation OperatorLoc, |
| 1564 | bool IsArrow, |
| 1565 | NestedNameSpecifier *Qualifier, |
| 1566 | SourceRange QualifierRange, |
| 1567 | LookupResult &R, |
| 1568 | const TemplateArgumentListInfo *TemplateArgs) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1569 | CXXScopeSpec SS; |
| 1570 | SS.setRange(QualifierRange); |
| 1571 | SS.setScopeRep(Qualifier); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 1573 | return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, |
| 1574 | OperatorLoc, IsArrow, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 1575 | SS, R, TemplateArgs); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1576 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1578 | /// \brief Build a new Objective-C @encode expression. |
| 1579 | /// |
| 1580 | /// By default, performs semantic analysis to build the new expression. |
| 1581 | /// Subclasses may override this routine to provide different behavior. |
| 1582 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1583 | QualType T, |
| 1584 | SourceLocation RParenLoc) { |
| 1585 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1586 | RParenLoc)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1587 | } |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1588 | |
| 1589 | /// \brief Build a new Objective-C protocol expression. |
| 1590 | /// |
| 1591 | /// By default, performs semantic analysis to build the new expression. |
| 1592 | /// Subclasses may override this routine to provide different behavior. |
| 1593 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1594 | SourceLocation AtLoc, |
| 1595 | SourceLocation ProtoLoc, |
| 1596 | SourceLocation LParenLoc, |
| 1597 | SourceLocation RParenLoc) { |
| 1598 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1599 | Protocol->getIdentifier(), |
| 1600 | AtLoc, |
| 1601 | ProtoLoc, |
| 1602 | LParenLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1603 | RParenLoc)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1606 | /// \brief Build a new shuffle vector expression. |
| 1607 | /// |
| 1608 | /// By default, performs semantic analysis to build the new expression. |
| 1609 | /// Subclasses may override this routine to provide different behavior. |
| 1610 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1611 | MultiExprArg SubExprs, |
| 1612 | SourceLocation RParenLoc) { |
| 1613 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1614 | const IdentifierInfo &Name |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1615 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1616 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1617 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1618 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1619 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1620 | // Build a reference to the __builtin_shufflevector builtin |
| 1621 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1622 | Expr *Callee |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1623 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | ed6c744 | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1624 | BuiltinLoc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1625 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | |
| 1627 | // Build the CallExpr |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | unsigned NumSubExprs = SubExprs.size(); |
| 1629 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1630 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1631 | Subs, NumSubExprs, |
| 1632 | Builtin->getResultType(), |
| 1633 | RParenLoc); |
| 1634 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1636 | // Type-check the __builtin_shufflevector expression. |
| 1637 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1638 | if (Result.isInvalid()) |
| 1639 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1641 | OwnedCall.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1642 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1643 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1644 | }; |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1646 | template<typename Derived> |
| 1647 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1648 | if (!S) |
| 1649 | return SemaRef.Owned(S); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1651 | switch (S->getStmtClass()) { |
| 1652 | case Stmt::NoStmtClass: break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1653 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1654 | // Transform individual statement nodes |
| 1655 | #define STMT(Node, Parent) \ |
| 1656 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1657 | #define EXPR(Node, Parent) |
| 1658 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1660 | // Transform expressions by calling TransformExpr. |
| 1661 | #define STMT(Node, Parent) |
| 1662 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1663 | #include "clang/AST/StmtNodes.def" |
| 1664 | { |
| 1665 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1666 | if (E.isInvalid()) |
| 1667 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Douglas Gregor | 07eae02 | 2009-11-13 18:34:26 +0000 | [diff] [blame] | 1669 | return getSema().ActOnExprStmt(getSema().FullExpr(E)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1673 | return SemaRef.Owned(S->Retain()); |
| 1674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
| 1676 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1677 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1678 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, |
| 1679 | bool isAddressOfOperand) { |
| 1680 | if (!E) |
| 1681 | return SemaRef.Owned(E); |
| 1682 | |
| 1683 | switch (E->getStmtClass()) { |
| 1684 | case Stmt::NoStmtClass: break; |
| 1685 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1686 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 1687 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \ |
| 1688 | isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1689 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1692 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | template<typename Derived> |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1696 | NestedNameSpecifier * |
| 1697 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1698 | SourceRange Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1699 | QualType ObjectType, |
| 1700 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 96ee789 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1701 | if (!NNS) |
| 1702 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1703 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1704 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1705 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1706 | if (Prefix) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1707 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1708 | ObjectType, |
| 1709 | FirstQualifierInScope); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1710 | if (!Prefix) |
| 1711 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | |
| 1713 | // 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] | 1714 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1715 | ObjectType = QualType(); |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1716 | FirstQualifierInScope = 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1717 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1719 | switch (NNS->getKind()) { |
| 1720 | case NestedNameSpecifier::Identifier: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1721 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1722 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1723 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1724 | ObjectType.isNull()) |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1725 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1726 | |
| 1727 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1728 | *NNS->getAsIdentifier(), |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1729 | ObjectType, |
| 1730 | FirstQualifierInScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1732 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1733 | NamespaceDecl *NS |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1734 | = cast_or_null<NamespaceDecl>( |
| 1735 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1736 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1737 | Prefix == NNS->getPrefix() && |
| 1738 | NS == NNS->getAsNamespace()) |
| 1739 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1741 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1742 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1744 | case NestedNameSpecifier::Global: |
| 1745 | // There is no meaningful transformation that one could perform on the |
| 1746 | // global scope. |
| 1747 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1749 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1750 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | 07cc4ac | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1751 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1752 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1753 | if (T.isNull()) |
| 1754 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1756 | if (!getDerived().AlwaysRebuild() && |
| 1757 | Prefix == NNS->getPrefix() && |
| 1758 | T == QualType(NNS->getAsType(), 0)) |
| 1759 | return NNS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1760 | |
| 1761 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1762 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | T); |
| 1764 | } |
| 1765 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1767 | // Required to silence a GCC warning |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | return 0; |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1772 | DeclarationName |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1773 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1774 | SourceLocation Loc, |
| 1775 | QualType ObjectType) { |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1776 | if (!Name) |
| 1777 | return Name; |
| 1778 | |
| 1779 | switch (Name.getNameKind()) { |
| 1780 | case DeclarationName::Identifier: |
| 1781 | case DeclarationName::ObjCZeroArgSelector: |
| 1782 | case DeclarationName::ObjCOneArgSelector: |
| 1783 | case DeclarationName::ObjCMultiArgSelector: |
| 1784 | case DeclarationName::CXXOperatorName: |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 1785 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1786 | case DeclarationName::CXXUsingDirective: |
| 1787 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1788 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1789 | case DeclarationName::CXXConstructorName: |
| 1790 | case DeclarationName::CXXDestructorName: |
| 1791 | case DeclarationName::CXXConversionFunctionName: { |
| 1792 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1793 | QualType T; |
| 1794 | if (!ObjectType.isNull() && |
| 1795 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1796 | TemplateSpecializationType *SpecType |
| 1797 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1798 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1799 | } else |
| 1800 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1801 | if (T.isNull()) |
| 1802 | return DeclarationName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1804 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1805 | Name.getNameKind(), |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1806 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1807 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1810 | return DeclarationName(); |
| 1811 | } |
| 1812 | |
| 1813 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | TemplateName |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1815 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1816 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1817 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1818 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1819 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1820 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1821 | if (!NNS) |
| 1822 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1824 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1826 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1827 | if (!TransTemplate) |
| 1828 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1830 | if (!getDerived().AlwaysRebuild() && |
| 1831 | NNS == QTN->getQualifier() && |
| 1832 | TransTemplate == Template) |
| 1833 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1834 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1835 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1836 | TransTemplate); |
| 1837 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1839 | // These should be getting filtered out before they make it into the AST. |
| 1840 | assert(false && "overloaded template name survived to here"); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1841 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1843 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | NestedNameSpecifier *NNS |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1845 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1846 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1847 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1848 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1850 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1851 | NNS == DTN->getQualifier() && |
| 1852 | ObjectType.isNull()) |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1853 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1855 | if (DTN->isIdentifier()) |
| 1856 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1857 | ObjectType); |
| 1858 | |
| 1859 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1860 | ObjectType); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1864 | TemplateDecl *TransTemplate |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1865 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1866 | if (!TransTemplate) |
| 1867 | return TemplateName(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1869 | if (!getDerived().AlwaysRebuild() && |
| 1870 | TransTemplate == Template) |
| 1871 | return Name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1873 | return TemplateName(TransTemplate); |
| 1874 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 1876 | // These should be getting filtered out before they reach the AST. |
| 1877 | assert(false && "overloaded function decl survived to here"); |
| 1878 | return TemplateName(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | template<typename Derived> |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1882 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1883 | const TemplateArgument &Arg, |
| 1884 | TemplateArgumentLoc &Output) { |
| 1885 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1886 | switch (Arg.getKind()) { |
| 1887 | case TemplateArgument::Null: |
| 1888 | llvm::llvm_unreachable("null template argument in TreeTransform"); |
| 1889 | break; |
| 1890 | |
| 1891 | case TemplateArgument::Type: |
| 1892 | Output = TemplateArgumentLoc(Arg, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1893 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1894 | |
| 1895 | break; |
| 1896 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1897 | case TemplateArgument::Template: |
| 1898 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1899 | break; |
| 1900 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1901 | case TemplateArgument::Expression: |
| 1902 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1903 | break; |
| 1904 | |
| 1905 | case TemplateArgument::Declaration: |
| 1906 | case TemplateArgument::Integral: |
| 1907 | case TemplateArgument::Pack: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1908 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | template<typename Derived> |
| 1914 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1915 | const TemplateArgumentLoc &Input, |
| 1916 | TemplateArgumentLoc &Output) { |
| 1917 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1918 | switch (Arg.getKind()) { |
| 1919 | case TemplateArgument::Null: |
| 1920 | case TemplateArgument::Integral: |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1921 | Output = Input; |
| 1922 | return false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1923 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1924 | case TemplateArgument::Type: { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1925 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1926 | if (DI == NULL) |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1927 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1928 | |
| 1929 | DI = getDerived().TransformType(DI); |
| 1930 | if (!DI) return true; |
| 1931 | |
| 1932 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1933 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1934 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1936 | case TemplateArgument::Declaration: { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1937 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | ef6ab41 | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1938 | DeclarationName Name; |
| 1939 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1940 | Name = ND->getDeclName(); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1941 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1942 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1943 | if (!D) return true; |
| 1944 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1945 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1946 | if (SourceExpr) { |
| 1947 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1948 | Action::Unevaluated); |
| 1949 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1950 | if (E.isInvalid()) |
| 1951 | SourceExpr = NULL; |
| 1952 | else { |
| 1953 | SourceExpr = E.takeAs<Expr>(); |
| 1954 | SourceExpr->Retain(); |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 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 | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1962 | case TemplateArgument::Template: { |
| 1963 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 1964 | TemplateName Template |
| 1965 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 1966 | if (Template.isNull()) |
| 1967 | return true; |
| 1968 | |
| 1969 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 1970 | Input.getTemplateQualifierRange(), |
| 1971 | Input.getTemplateNameLoc()); |
| 1972 | return false; |
| 1973 | } |
| 1974 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1975 | case TemplateArgument::Expression: { |
| 1976 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1978 | Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1979 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1980 | Expr *InputExpr = Input.getSourceExpression(); |
| 1981 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 1982 | |
| 1983 | Sema::OwningExprResult E |
| 1984 | = getDerived().TransformExpr(InputExpr); |
| 1985 | if (E.isInvalid()) return true; |
| 1986 | |
| 1987 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1988 | ETaken->Retain(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1989 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 1990 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1991 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1993 | case TemplateArgument::Pack: { |
| 1994 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 1995 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1997 | AEnd = Arg.pack_end(); |
| 1998 | A != AEnd; ++A) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2000 | // FIXME: preserve source information here when we start |
| 2001 | // caring about parameter packs. |
| 2002 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2003 | TemplateArgumentLoc InputArg; |
| 2004 | TemplateArgumentLoc OutputArg; |
| 2005 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2006 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2007 | return true; |
| 2008 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2009 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2010 | } |
| 2011 | TemplateArgument Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2013 | true); |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2014 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2015 | return false; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2016 | } |
| 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 | // Work around bogus GCC warning |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2020 | return true; |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2023 | //===----------------------------------------------------------------------===// |
| 2024 | // Type transformation |
| 2025 | //===----------------------------------------------------------------------===// |
| 2026 | |
| 2027 | template<typename Derived> |
| 2028 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2029 | if (getDerived().AlreadyTransformed(T)) |
| 2030 | return T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2031 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2032 | // Temporary workaround. All of these transformations should |
| 2033 | // eventually turn into transformations on TypeLocs. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2034 | TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); |
John McCall | de88989 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2035 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2036 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2037 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2038 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2039 | if (!NewDI) |
| 2040 | return QualType(); |
| 2041 | |
| 2042 | return NewDI->getType(); |
| 2043 | } |
| 2044 | |
| 2045 | template<typename Derived> |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2046 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2047 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2048 | return DI; |
| 2049 | |
| 2050 | TypeLocBuilder TLB; |
| 2051 | |
| 2052 | TypeLoc TL = DI->getTypeLoc(); |
| 2053 | TLB.reserve(TL.getFullDataSize()); |
| 2054 | |
| 2055 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2056 | if (Result.isNull()) |
| 2057 | return 0; |
| 2058 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2059 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | template<typename Derived> |
| 2063 | QualType |
| 2064 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2065 | switch (T.getTypeLocClass()) { |
| 2066 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2067 | #define TYPELOC(CLASS, PARENT) \ |
| 2068 | case TypeLoc::CLASS: \ |
| 2069 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2070 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2071 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2072 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2073 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2074 | return QualType(); |
| 2075 | } |
| 2076 | |
| 2077 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2078 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2079 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2080 | /// types). This is the right thing for template instantiation, but |
| 2081 | /// probably not for other clients. |
| 2082 | template<typename Derived> |
| 2083 | QualType |
| 2084 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2085 | QualifiedTypeLoc T) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2086 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2087 | |
| 2088 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2089 | if (Result.isNull()) |
| 2090 | return QualType(); |
| 2091 | |
| 2092 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2093 | // FIXME: this is the right thing for template instantiation, but |
| 2094 | // probably not for other clients. |
| 2095 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2096 | return Result; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2097 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2098 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2099 | |
| 2100 | TLB.push<QualifiedTypeLoc>(Result); |
| 2101 | |
| 2102 | // No location information to preserve. |
| 2103 | |
| 2104 | return Result; |
| 2105 | } |
| 2106 | |
| 2107 | template <class TyLoc> static inline |
| 2108 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2109 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2110 | NewT.setNameLoc(T.getNameLoc()); |
| 2111 | return T.getType(); |
| 2112 | } |
| 2113 | |
| 2114 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2115 | // the equivalent template version work. |
| 2116 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2117 | QualType PointeeType \ |
| 2118 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2119 | if (PointeeType.isNull()) \ |
| 2120 | return QualType(); \ |
| 2121 | \ |
| 2122 | QualType Result = TL.getType(); \ |
| 2123 | if (getDerived().AlwaysRebuild() || \ |
| 2124 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2125 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2126 | TL.getSigilLoc()); \ |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2127 | if (Result.isNull()) \ |
| 2128 | return QualType(); \ |
| 2129 | } \ |
| 2130 | \ |
| 2131 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2132 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2133 | \ |
| 2134 | return Result; \ |
| 2135 | } while(0) |
| 2136 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2137 | template<typename Derived> |
| 2138 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2139 | BuiltinTypeLoc T) { |
| 2140 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2143 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2144 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2145 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2146 | FixedWidthIntTypeLoc T) { |
| 2147 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2148 | } |
Argyrios Kyrtzidis | e918926 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2149 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2150 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2151 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2152 | ComplexTypeLoc T) { |
| 2153 | // FIXME: recurse? |
| 2154 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2155 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2156 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2157 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2158 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2159 | PointerTypeLoc TL) { |
| 2160 | TransformPointerLikeType(PointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | |
| 2163 | template<typename Derived> |
| 2164 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2165 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2166 | BlockPointerTypeLoc TL) { |
| 2167 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2170 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2171 | /// don't care whether the type itself is an l-value type or an r-value |
| 2172 | /// type; we only care if the type was *written* as an l-value type |
| 2173 | /// or an r-value type. |
| 2174 | template<typename Derived> |
| 2175 | QualType |
| 2176 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2177 | ReferenceTypeLoc TL) { |
| 2178 | const ReferenceType *T = TL.getTypePtr(); |
| 2179 | |
| 2180 | // Note that this works with the pointee-as-written. |
| 2181 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2182 | if (PointeeType.isNull()) |
| 2183 | return QualType(); |
| 2184 | |
| 2185 | QualType Result = TL.getType(); |
| 2186 | if (getDerived().AlwaysRebuild() || |
| 2187 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2188 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2189 | T->isSpelledAsLValue(), |
| 2190 | TL.getSigilLoc()); |
| 2191 | if (Result.isNull()) |
| 2192 | return QualType(); |
| 2193 | } |
| 2194 | |
| 2195 | // r-value references can be rebuilt as l-value references. |
| 2196 | ReferenceTypeLoc NewTL; |
| 2197 | if (isa<LValueReferenceType>(Result)) |
| 2198 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2199 | else |
| 2200 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2201 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2202 | |
| 2203 | return Result; |
| 2204 | } |
| 2205 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2206 | template<typename Derived> |
| 2207 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2208 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2209 | LValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2210 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2213 | template<typename Derived> |
| 2214 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2215 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2216 | RValueReferenceTypeLoc TL) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2217 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2218 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2219 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2220 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2221 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2222 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2223 | MemberPointerTypeLoc TL) { |
| 2224 | MemberPointerType *T = TL.getTypePtr(); |
| 2225 | |
| 2226 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2227 | if (PointeeType.isNull()) |
| 2228 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2229 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2230 | // TODO: preserve source information for this. |
| 2231 | QualType ClassType |
| 2232 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2233 | if (ClassType.isNull()) |
| 2234 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2235 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2236 | QualType Result = TL.getType(); |
| 2237 | if (getDerived().AlwaysRebuild() || |
| 2238 | PointeeType != T->getPointeeType() || |
| 2239 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2240 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2241 | TL.getStarLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2242 | if (Result.isNull()) |
| 2243 | return QualType(); |
| 2244 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2245 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2246 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2247 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2248 | |
| 2249 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | template<typename Derived> |
| 2253 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2254 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2255 | ConstantArrayTypeLoc TL) { |
| 2256 | ConstantArrayType *T = TL.getTypePtr(); |
| 2257 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2258 | if (ElementType.isNull()) |
| 2259 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2261 | QualType Result = TL.getType(); |
| 2262 | if (getDerived().AlwaysRebuild() || |
| 2263 | ElementType != T->getElementType()) { |
| 2264 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2265 | T->getSizeModifier(), |
| 2266 | T->getSize(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2267 | T->getIndexTypeCVRQualifiers(), |
| 2268 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2269 | if (Result.isNull()) |
| 2270 | return QualType(); |
| 2271 | } |
| 2272 | |
| 2273 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2274 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2275 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2276 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2277 | Expr *Size = TL.getSizeExpr(); |
| 2278 | if (Size) { |
| 2279 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2280 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2281 | } |
| 2282 | NewTL.setSizeExpr(Size); |
| 2283 | |
| 2284 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2285 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2287 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2288 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2289 | TypeLocBuilder &TLB, |
| 2290 | IncompleteArrayTypeLoc TL) { |
| 2291 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2292 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2293 | if (ElementType.isNull()) |
| 2294 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2295 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2296 | QualType Result = TL.getType(); |
| 2297 | if (getDerived().AlwaysRebuild() || |
| 2298 | ElementType != T->getElementType()) { |
| 2299 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2300 | T->getSizeModifier(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2301 | T->getIndexTypeCVRQualifiers(), |
| 2302 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2303 | if (Result.isNull()) |
| 2304 | return QualType(); |
| 2305 | } |
| 2306 | |
| 2307 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2308 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2309 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2310 | NewTL.setSizeExpr(0); |
| 2311 | |
| 2312 | return Result; |
| 2313 | } |
| 2314 | |
| 2315 | template<typename Derived> |
| 2316 | QualType |
| 2317 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2318 | VariableArrayTypeLoc TL) { |
| 2319 | VariableArrayType *T = TL.getTypePtr(); |
| 2320 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2321 | if (ElementType.isNull()) |
| 2322 | return QualType(); |
| 2323 | |
| 2324 | // Array bounds are not potentially evaluated contexts |
| 2325 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2326 | |
| 2327 | Sema::OwningExprResult SizeResult |
| 2328 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2329 | if (SizeResult.isInvalid()) |
| 2330 | return QualType(); |
| 2331 | |
| 2332 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2333 | |
| 2334 | QualType Result = TL.getType(); |
| 2335 | if (getDerived().AlwaysRebuild() || |
| 2336 | ElementType != T->getElementType() || |
| 2337 | Size != T->getSizeExpr()) { |
| 2338 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2339 | T->getSizeModifier(), |
| 2340 | move(SizeResult), |
| 2341 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2342 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2343 | if (Result.isNull()) |
| 2344 | return QualType(); |
| 2345 | } |
| 2346 | else SizeResult.take(); |
| 2347 | |
| 2348 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2349 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2350 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2351 | NewTL.setSizeExpr(Size); |
| 2352 | |
| 2353 | return Result; |
| 2354 | } |
| 2355 | |
| 2356 | template<typename Derived> |
| 2357 | QualType |
| 2358 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2359 | DependentSizedArrayTypeLoc TL) { |
| 2360 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2361 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2362 | if (ElementType.isNull()) |
| 2363 | return QualType(); |
| 2364 | |
| 2365 | // Array bounds are not potentially evaluated contexts |
| 2366 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2367 | |
| 2368 | Sema::OwningExprResult SizeResult |
| 2369 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2370 | if (SizeResult.isInvalid()) |
| 2371 | return QualType(); |
| 2372 | |
| 2373 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2374 | |
| 2375 | QualType Result = TL.getType(); |
| 2376 | if (getDerived().AlwaysRebuild() || |
| 2377 | ElementType != T->getElementType() || |
| 2378 | Size != T->getSizeExpr()) { |
| 2379 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2380 | T->getSizeModifier(), |
| 2381 | move(SizeResult), |
| 2382 | T->getIndexTypeCVRQualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2383 | TL.getBracketsRange()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2384 | if (Result.isNull()) |
| 2385 | return QualType(); |
| 2386 | } |
| 2387 | else SizeResult.take(); |
| 2388 | |
| 2389 | // We might have any sort of array type now, but fortunately they |
| 2390 | // all have the same location layout. |
| 2391 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2392 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2393 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2394 | NewTL.setSizeExpr(Size); |
| 2395 | |
| 2396 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2398 | |
| 2399 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2400 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2401 | TypeLocBuilder &TLB, |
| 2402 | DependentSizedExtVectorTypeLoc TL) { |
| 2403 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2404 | |
| 2405 | // FIXME: ext vector locs should be nested |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2406 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2407 | if (ElementType.isNull()) |
| 2408 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2409 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2410 | // Vector sizes are not potentially evaluated contexts |
| 2411 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2412 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2413 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2414 | if (Size.isInvalid()) |
| 2415 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2417 | QualType Result = TL.getType(); |
| 2418 | if (getDerived().AlwaysRebuild() || |
John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2419 | ElementType != T->getElementType() || |
| 2420 | Size.get() != T->getSizeExpr()) { |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2421 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2422 | move(Size), |
| 2423 | T->getAttributeLoc()); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2424 | if (Result.isNull()) |
| 2425 | return QualType(); |
| 2426 | } |
| 2427 | else Size.take(); |
| 2428 | |
| 2429 | // Result might be dependent or not. |
| 2430 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2431 | DependentSizedExtVectorTypeLoc NewTL |
| 2432 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2433 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2434 | } else { |
| 2435 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2436 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2437 | } |
| 2438 | |
| 2439 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2441 | |
| 2442 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2443 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2444 | VectorTypeLoc TL) { |
| 2445 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2446 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2447 | if (ElementType.isNull()) |
| 2448 | return QualType(); |
| 2449 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2450 | QualType Result = TL.getType(); |
| 2451 | if (getDerived().AlwaysRebuild() || |
| 2452 | ElementType != T->getElementType()) { |
| 2453 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2454 | if (Result.isNull()) |
| 2455 | return QualType(); |
| 2456 | } |
| 2457 | |
| 2458 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2459 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2460 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2461 | return Result; |
| 2462 | } |
| 2463 | |
| 2464 | template<typename Derived> |
| 2465 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2466 | ExtVectorTypeLoc TL) { |
| 2467 | VectorType *T = TL.getTypePtr(); |
| 2468 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2469 | if (ElementType.isNull()) |
| 2470 | return QualType(); |
| 2471 | |
| 2472 | QualType Result = TL.getType(); |
| 2473 | if (getDerived().AlwaysRebuild() || |
| 2474 | ElementType != T->getElementType()) { |
| 2475 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2476 | T->getNumElements(), |
| 2477 | /*FIXME*/ SourceLocation()); |
| 2478 | if (Result.isNull()) |
| 2479 | return QualType(); |
| 2480 | } |
| 2481 | |
| 2482 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2483 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2484 | |
| 2485 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2486 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2487 | |
| 2488 | template<typename Derived> |
| 2489 | QualType |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2490 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2491 | FunctionProtoTypeLoc TL) { |
| 2492 | FunctionProtoType *T = TL.getTypePtr(); |
| 2493 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2494 | if (ResultType.isNull()) |
| 2495 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2496 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2497 | // Transform the parameters. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2498 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2499 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2500 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2501 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2502 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2503 | QualType NewType; |
| 2504 | ParmVarDecl *NewParm; |
| 2505 | |
| 2506 | if (OldParm) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2507 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2508 | assert(OldDI->getType() == T->getArgType(i)); |
| 2509 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2510 | TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2511 | if (!NewDI) |
| 2512 | return QualType(); |
| 2513 | |
| 2514 | if (NewDI == OldDI) |
| 2515 | NewParm = OldParm; |
| 2516 | else |
| 2517 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2518 | OldParm->getDeclContext(), |
| 2519 | OldParm->getLocation(), |
| 2520 | OldParm->getIdentifier(), |
| 2521 | NewDI->getType(), |
| 2522 | NewDI, |
| 2523 | OldParm->getStorageClass(), |
| 2524 | /* DefArg */ NULL); |
| 2525 | NewType = NewParm->getType(); |
| 2526 | |
| 2527 | // Deal with the possibility that we don't have a parameter |
| 2528 | // declaration for this parameter. |
| 2529 | } else { |
| 2530 | NewParm = 0; |
| 2531 | |
| 2532 | QualType OldType = T->getArgType(i); |
| 2533 | NewType = getDerived().TransformType(OldType); |
| 2534 | if (NewType.isNull()) |
| 2535 | return QualType(); |
| 2536 | } |
| 2537 | |
| 2538 | ParamTypes.push_back(NewType); |
| 2539 | ParamDecls.push_back(NewParm); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2542 | QualType Result = TL.getType(); |
| 2543 | if (getDerived().AlwaysRebuild() || |
| 2544 | ResultType != T->getResultType() || |
| 2545 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2546 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2547 | ParamTypes.data(), |
| 2548 | ParamTypes.size(), |
| 2549 | T->isVariadic(), |
| 2550 | T->getTypeQuals()); |
| 2551 | if (Result.isNull()) |
| 2552 | return QualType(); |
| 2553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2555 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2556 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2557 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2558 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2559 | NewTL.setArg(i, ParamDecls[i]); |
| 2560 | |
| 2561 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2562 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2563 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2564 | template<typename Derived> |
| 2565 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2566 | TypeLocBuilder &TLB, |
| 2567 | FunctionNoProtoTypeLoc TL) { |
| 2568 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2569 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2570 | if (ResultType.isNull()) |
| 2571 | return QualType(); |
| 2572 | |
| 2573 | QualType Result = TL.getType(); |
| 2574 | if (getDerived().AlwaysRebuild() || |
| 2575 | ResultType != T->getResultType()) |
| 2576 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2577 | |
| 2578 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2579 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2580 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2581 | |
| 2582 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2583 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2584 | |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2585 | template<typename Derived> QualType |
| 2586 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 2587 | UnresolvedUsingTypeLoc TL) { |
| 2588 | UnresolvedUsingType *T = TL.getTypePtr(); |
| 2589 | Decl *D = getDerived().TransformDecl(T->getDecl()); |
| 2590 | if (!D) |
| 2591 | return QualType(); |
| 2592 | |
| 2593 | QualType Result = TL.getType(); |
| 2594 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 2595 | Result = getDerived().RebuildUnresolvedUsingType(D); |
| 2596 | if (Result.isNull()) |
| 2597 | return QualType(); |
| 2598 | } |
| 2599 | |
| 2600 | // We might get an arbitrary type spec type back. We should at |
| 2601 | // least always get a type spec type, though. |
| 2602 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 2603 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2604 | |
| 2605 | return Result; |
| 2606 | } |
| 2607 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2608 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2609 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2610 | TypedefTypeLoc TL) { |
| 2611 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2612 | TypedefDecl *Typedef |
| 2613 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2614 | if (!Typedef) |
| 2615 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2616 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2617 | QualType Result = TL.getType(); |
| 2618 | if (getDerived().AlwaysRebuild() || |
| 2619 | Typedef != T->getDecl()) { |
| 2620 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2621 | if (Result.isNull()) |
| 2622 | return QualType(); |
| 2623 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2624 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2625 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2626 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2627 | |
| 2628 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2629 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2630 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2631 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2632 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2633 | TypeOfExprTypeLoc TL) { |
| 2634 | TypeOfExprType *T = TL.getTypePtr(); |
| 2635 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2636 | // typeof expressions are not potentially evaluated contexts |
| 2637 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2638 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2639 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2640 | if (E.isInvalid()) |
| 2641 | return QualType(); |
| 2642 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2643 | QualType Result = TL.getType(); |
| 2644 | if (getDerived().AlwaysRebuild() || |
| 2645 | E.get() != T->getUnderlyingExpr()) { |
| 2646 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2647 | if (Result.isNull()) |
| 2648 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2649 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2650 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2651 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2652 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2653 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2654 | |
| 2655 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2656 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2657 | |
| 2658 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2659 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2660 | TypeOfTypeLoc TL) { |
| 2661 | TypeOfType *T = TL.getTypePtr(); |
| 2662 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2663 | // FIXME: should be an inner type, or at least have a TypeSourceInfo. |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2664 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2665 | if (Underlying.isNull()) |
| 2666 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2667 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2668 | QualType Result = TL.getType(); |
| 2669 | if (getDerived().AlwaysRebuild() || |
| 2670 | Underlying != T->getUnderlyingType()) { |
| 2671 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2672 | if (Result.isNull()) |
| 2673 | return QualType(); |
| 2674 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2675 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2676 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2677 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2678 | |
| 2679 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2680 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2681 | |
| 2682 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2683 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2684 | DecltypeTypeLoc TL) { |
| 2685 | DecltypeType *T = TL.getTypePtr(); |
| 2686 | |
Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2687 | // decltype expressions are not potentially evaluated contexts |
| 2688 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2689 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2690 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2691 | if (E.isInvalid()) |
| 2692 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2693 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2694 | QualType Result = TL.getType(); |
| 2695 | if (getDerived().AlwaysRebuild() || |
| 2696 | E.get() != T->getUnderlyingExpr()) { |
| 2697 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2698 | if (Result.isNull()) |
| 2699 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2700 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2701 | else E.take(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2702 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2703 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2704 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2705 | |
| 2706 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2710 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2711 | RecordTypeLoc TL) { |
| 2712 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2713 | RecordDecl *Record |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2714 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2715 | if (!Record) |
| 2716 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2717 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2718 | QualType Result = TL.getType(); |
| 2719 | if (getDerived().AlwaysRebuild() || |
| 2720 | Record != T->getDecl()) { |
| 2721 | Result = getDerived().RebuildRecordType(Record); |
| 2722 | if (Result.isNull()) |
| 2723 | return QualType(); |
| 2724 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2725 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2726 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2727 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2728 | |
| 2729 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2730 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2731 | |
| 2732 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2733 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2734 | EnumTypeLoc TL) { |
| 2735 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2736 | EnumDecl *Enum |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2737 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2738 | if (!Enum) |
| 2739 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2740 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2741 | QualType Result = TL.getType(); |
| 2742 | if (getDerived().AlwaysRebuild() || |
| 2743 | Enum != T->getDecl()) { |
| 2744 | Result = getDerived().RebuildEnumType(Enum); |
| 2745 | if (Result.isNull()) |
| 2746 | return QualType(); |
| 2747 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2748 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2749 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2750 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2751 | |
| 2752 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2753 | } |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2754 | |
| 2755 | template <typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2756 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2757 | ElaboratedTypeLoc TL) { |
| 2758 | ElaboratedType *T = TL.getTypePtr(); |
| 2759 | |
| 2760 | // FIXME: this should be a nested type. |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2761 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2762 | if (Underlying.isNull()) |
| 2763 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2764 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2765 | QualType Result = TL.getType(); |
| 2766 | if (getDerived().AlwaysRebuild() || |
| 2767 | Underlying != T->getUnderlyingType()) { |
| 2768 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2769 | if (Result.isNull()) |
| 2770 | return QualType(); |
| 2771 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2772 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2773 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2774 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2775 | |
| 2776 | return Result; |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2778 | |
| 2779 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2780 | template<typename Derived> |
| 2781 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2782 | TypeLocBuilder &TLB, |
| 2783 | TemplateTypeParmTypeLoc TL) { |
| 2784 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2787 | template<typename Derived> |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2788 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2789 | TypeLocBuilder &TLB, |
| 2790 | SubstTemplateTypeParmTypeLoc TL) { |
| 2791 | return TransformTypeSpecType(TLB, TL); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | template<typename Derived> |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2795 | inline QualType |
| 2796 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2797 | TypeLocBuilder &TLB, |
| 2798 | TemplateSpecializationTypeLoc TL) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2799 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2800 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2801 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2802 | template<typename Derived> |
| 2803 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2804 | const TemplateSpecializationType *TST, |
| 2805 | QualType ObjectType) { |
| 2806 | // FIXME: this entire method is a temporary workaround; callers |
| 2807 | // should be rewritten to provide real type locs. |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2808 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2809 | // Fake up a TemplateSpecializationTypeLoc. |
| 2810 | TypeLocBuilder TLB; |
| 2811 | TemplateSpecializationTypeLoc TL |
| 2812 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2813 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2814 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2815 | |
| 2816 | TL.setTemplateNameLoc(BaseLoc); |
| 2817 | TL.setLAngleLoc(BaseLoc); |
| 2818 | TL.setRAngleLoc(BaseLoc); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2819 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2820 | const TemplateArgument &TA = TST->getArg(i); |
| 2821 | TemplateArgumentLoc TAL; |
| 2822 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2823 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2824 | } |
| 2825 | |
| 2826 | TypeLocBuilder IgnoredTLB; |
| 2827 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | template<typename Derived> |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2831 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2832 | TypeLocBuilder &TLB, |
| 2833 | TemplateSpecializationTypeLoc TL, |
| 2834 | QualType ObjectType) { |
| 2835 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2836 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2837 | TemplateName Template |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2838 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2839 | if (Template.isNull()) |
| 2840 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2841 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2842 | TemplateArgumentListInfo NewTemplateArgs; |
| 2843 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2844 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2845 | |
| 2846 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2847 | TemplateArgumentLoc Loc; |
| 2848 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2849 | return QualType(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2850 | NewTemplateArgs.addArgument(Loc); |
| 2851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2852 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2853 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2854 | |
| 2855 | QualType Result = |
| 2856 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2857 | TL.getTemplateNameLoc(), |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2858 | NewTemplateArgs); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2859 | |
| 2860 | if (!Result.isNull()) { |
| 2861 | TemplateSpecializationTypeLoc NewTL |
| 2862 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2863 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2864 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2865 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2866 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2867 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2868 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2869 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2870 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2871 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2872 | |
| 2873 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2874 | QualType |
| 2875 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2876 | QualifiedNameTypeLoc TL) { |
| 2877 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2878 | NestedNameSpecifier *NNS |
| 2879 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2880 | SourceRange()); |
| 2881 | if (!NNS) |
| 2882 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2883 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2884 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2885 | if (Named.isNull()) |
| 2886 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2887 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2888 | QualType Result = TL.getType(); |
| 2889 | if (getDerived().AlwaysRebuild() || |
| 2890 | NNS != T->getQualifier() || |
| 2891 | Named != T->getNamedType()) { |
| 2892 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2893 | if (Result.isNull()) |
| 2894 | return QualType(); |
| 2895 | } |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2896 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2897 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2898 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2899 | |
| 2900 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2901 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2902 | |
| 2903 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2904 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2905 | TypenameTypeLoc TL) { |
| 2906 | TypenameType *T = TL.getTypePtr(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2907 | |
| 2908 | /* FIXME: preserve source information better than this */ |
| 2909 | SourceRange SR(TL.getNameLoc()); |
| 2910 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2911 | NestedNameSpecifier *NNS |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2912 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2913 | if (!NNS) |
| 2914 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2915 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2916 | QualType Result; |
| 2917 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2918 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2919 | QualType NewTemplateId |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2921 | if (NewTemplateId.isNull()) |
| 2922 | return QualType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2923 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2924 | if (!getDerived().AlwaysRebuild() && |
| 2925 | NNS == T->getQualifier() && |
| 2926 | NewTemplateId == QualType(TemplateId, 0)) |
| 2927 | return QualType(T, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2928 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2929 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2930 | } else { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2931 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2932 | } |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2933 | if (Result.isNull()) |
| 2934 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2935 | |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2936 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2937 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2938 | |
| 2939 | return Result; |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2940 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2941 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2942 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2943 | QualType |
| 2944 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2945 | ObjCInterfaceTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2946 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2947 | return QualType(); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2948 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2949 | |
| 2950 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2951 | QualType |
| 2952 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2953 | ObjCObjectPointerTypeLoc TL) { |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2954 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2955 | return QualType(); |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2958 | //===----------------------------------------------------------------------===// |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2959 | // Statement transformation |
| 2960 | //===----------------------------------------------------------------------===// |
| 2961 | template<typename Derived> |
| 2962 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2963 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2964 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | template<typename Derived> |
| 2968 | Sema::OwningStmtResult |
| 2969 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2970 | return getDerived().TransformCompoundStmt(S, false); |
| 2971 | } |
| 2972 | |
| 2973 | template<typename Derived> |
| 2974 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2975 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2976 | bool IsStmtExpr) { |
| 2977 | bool SubStmtChanged = false; |
| 2978 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2979 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2980 | B != BEnd; ++B) { |
| 2981 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 2982 | if (Result.isInvalid()) |
| 2983 | return getSema().StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2984 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2985 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 2986 | Statements.push_back(Result.takeAs<Stmt>()); |
| 2987 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2988 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2989 | if (!getDerived().AlwaysRebuild() && |
| 2990 | !SubStmtChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2992 | |
| 2993 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 2994 | move_arg(Statements), |
| 2995 | S->getRBracLoc(), |
| 2996 | IsStmtExpr); |
| 2997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2998 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2999 | template<typename Derived> |
| 3000 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3002 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3003 | { |
| 3004 | // The case value expressions are not potentially evaluated. |
| 3005 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3006 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3007 | // Transform the left-hand case value. |
| 3008 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3009 | if (LHS.isInvalid()) |
| 3010 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3011 | |
Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3012 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3013 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3014 | if (RHS.isInvalid()) |
| 3015 | return SemaRef.StmtError(); |
| 3016 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3018 | // Build the case statement. |
| 3019 | // Case statements are always rebuilt so that they will attached to their |
| 3020 | // transformed switch statement. |
| 3021 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3022 | move(LHS), |
| 3023 | S->getEllipsisLoc(), |
| 3024 | move(RHS), |
| 3025 | S->getColonLoc()); |
| 3026 | if (Case.isInvalid()) |
| 3027 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3028 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3029 | // Transform the statement following the case |
| 3030 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3031 | if (SubStmt.isInvalid()) |
| 3032 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3034 | // Attach the body to the case statement |
| 3035 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3036 | } |
| 3037 | |
| 3038 | template<typename Derived> |
| 3039 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3040 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3041 | // Transform the statement following the default case |
| 3042 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3043 | if (SubStmt.isInvalid()) |
| 3044 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3046 | // Default statements are always rebuilt |
| 3047 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3048 | move(SubStmt)); |
| 3049 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3050 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3051 | template<typename Derived> |
| 3052 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3053 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3054 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3055 | if (SubStmt.isInvalid()) |
| 3056 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3058 | // FIXME: Pass the real colon location in. |
| 3059 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3060 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3061 | move(SubStmt)); |
| 3062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3063 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3064 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3065 | Sema::OwningStmtResult |
| 3066 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3067 | // Transform the condition |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3068 | OwningExprResult Cond(SemaRef); |
| 3069 | VarDecl *ConditionVar = 0; |
| 3070 | if (S->getConditionVariable()) { |
| 3071 | ConditionVar |
| 3072 | = cast_or_null<VarDecl>( |
| 3073 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3074 | if (!ConditionVar) |
| 3075 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3076 | } else { |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3077 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3078 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3079 | if (Cond.isInvalid()) |
| 3080 | return SemaRef.StmtError(); |
| 3081 | } |
Douglas Gregor | 633caca | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3084 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3085 | // Transform the "then" branch. |
| 3086 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3087 | if (Then.isInvalid()) |
| 3088 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3089 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3090 | // Transform the "else" branch. |
| 3091 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3092 | if (Else.isInvalid()) |
| 3093 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3094 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3095 | if (!getDerived().AlwaysRebuild() && |
| 3096 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3097 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3098 | Then.get() == S->getThen() && |
| 3099 | Else.get() == S->getElse()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3100 | return SemaRef.Owned(S->Retain()); |
| 3101 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3102 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, |
| 3103 | move(Then), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | S->getElseLoc(), move(Else)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | template<typename Derived> |
| 3108 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3110 | // Transform the condition. |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3111 | OwningExprResult Cond(SemaRef); |
| 3112 | VarDecl *ConditionVar = 0; |
| 3113 | if (S->getConditionVariable()) { |
| 3114 | ConditionVar |
| 3115 | = cast_or_null<VarDecl>( |
| 3116 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3117 | if (!ConditionVar) |
| 3118 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3119 | } else { |
Douglas Gregor | dcf1962 | 2009-11-24 17:07:59 +0000 | [diff] [blame] | 3120 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3121 | |
| 3122 | if (Cond.isInvalid()) |
| 3123 | return SemaRef.StmtError(); |
| 3124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3126 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
| 3127 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Rebuild the switch statement. |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3129 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond, |
| 3130 | ConditionVar); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3131 | if (Switch.isInvalid()) |
| 3132 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3134 | // Transform the body of the switch statement. |
| 3135 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3136 | if (Body.isInvalid()) |
| 3137 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3139 | // Complete the switch statement. |
| 3140 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3141 | move(Body)); |
| 3142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3144 | template<typename Derived> |
| 3145 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3146 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3147 | // Transform the condition |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3148 | OwningExprResult Cond(SemaRef); |
| 3149 | VarDecl *ConditionVar = 0; |
| 3150 | if (S->getConditionVariable()) { |
| 3151 | ConditionVar |
| 3152 | = cast_or_null<VarDecl>( |
| 3153 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3154 | if (!ConditionVar) |
| 3155 | return SemaRef.StmtError(); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3156 | } else { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 3157 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3158 | |
| 3159 | if (Cond.isInvalid()) |
| 3160 | return SemaRef.StmtError(); |
| 3161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3162 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3163 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3164 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3165 | // Transform the body |
| 3166 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3167 | if (Body.isInvalid()) |
| 3168 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3170 | if (!getDerived().AlwaysRebuild() && |
| 3171 | FullCond->get() == S->getCond() && |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3172 | ConditionVar == S->getConditionVariable() && |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3173 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3174 | return SemaRef.Owned(S->Retain()); |
| 3175 | |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3176 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar, |
| 3177 | move(Body)); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3178 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3179 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3180 | template<typename Derived> |
| 3181 | Sema::OwningStmtResult |
| 3182 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3183 | // Transform the condition |
| 3184 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3185 | if (Cond.isInvalid()) |
| 3186 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3187 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3188 | // Transform the body |
| 3189 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3190 | if (Body.isInvalid()) |
| 3191 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3192 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3193 | if (!getDerived().AlwaysRebuild() && |
| 3194 | Cond.get() == S->getCond() && |
| 3195 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | return SemaRef.Owned(S->Retain()); |
| 3197 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3198 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3199 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3200 | S->getRParenLoc()); |
| 3201 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3202 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3203 | template<typename Derived> |
| 3204 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3205 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3206 | // Transform the initialization statement |
| 3207 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3208 | if (Init.isInvalid()) |
| 3209 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3210 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3211 | // Transform the condition |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3212 | OwningExprResult Cond(SemaRef); |
| 3213 | VarDecl *ConditionVar = 0; |
| 3214 | if (S->getConditionVariable()) { |
| 3215 | ConditionVar |
| 3216 | = cast_or_null<VarDecl>( |
| 3217 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3218 | if (!ConditionVar) |
| 3219 | return SemaRef.StmtError(); |
| 3220 | } else { |
| 3221 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3222 | |
| 3223 | if (Cond.isInvalid()) |
| 3224 | return SemaRef.StmtError(); |
| 3225 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3226 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3227 | // Transform the increment |
| 3228 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3229 | if (Inc.isInvalid()) |
| 3230 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3231 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3232 | // Transform the body |
| 3233 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3234 | if (Body.isInvalid()) |
| 3235 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3236 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3237 | if (!getDerived().AlwaysRebuild() && |
| 3238 | Init.get() == S->getInit() && |
| 3239 | Cond.get() == S->getCond() && |
| 3240 | Inc.get() == S->getInc() && |
| 3241 | Body.get() == S->getBody()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3242 | return SemaRef.Owned(S->Retain()); |
| 3243 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3244 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
Douglas Gregor | 7bab5ff | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 3245 | move(Init), getSema().FullExpr(Cond), |
| 3246 | ConditionVar, |
| 3247 | getSema().FullExpr(Inc), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3248 | S->getRParenLoc(), move(Body)); |
| 3249 | } |
| 3250 | |
| 3251 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3252 | Sema::OwningStmtResult |
| 3253 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3254 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3255 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3256 | S->getLabel()); |
| 3257 | } |
| 3258 | |
| 3259 | template<typename Derived> |
| 3260 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3261 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3262 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3263 | if (Target.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 | if (!getDerived().AlwaysRebuild() && |
| 3267 | Target.get() == S->getTarget()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3269 | |
| 3270 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3271 | move(Target)); |
| 3272 | } |
| 3273 | |
| 3274 | template<typename Derived> |
| 3275 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3276 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3277 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3280 | template<typename Derived> |
| 3281 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3283 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3285 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | template<typename Derived> |
| 3287 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3288 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3289 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3290 | if (Result.isInvalid()) |
| 3291 | return SemaRef.StmtError(); |
| 3292 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3294 | // to tell whether the return type of the function has changed. |
| 3295 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3296 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3298 | template<typename Derived> |
| 3299 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3301 | bool DeclChanged = false; |
| 3302 | llvm::SmallVector<Decl *, 4> Decls; |
| 3303 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3304 | D != DEnd; ++D) { |
| 3305 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3306 | if (!Transformed) |
| 3307 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3308 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3309 | if (Transformed != *D) |
| 3310 | DeclChanged = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3311 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3312 | Decls.push_back(Transformed); |
| 3313 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3314 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3315 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 | return SemaRef.Owned(S->Retain()); |
| 3317 | |
| 3318 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3319 | S->getStartLoc(), S->getEndLoc()); |
| 3320 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3321 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3322 | template<typename Derived> |
| 3323 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3325 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3326 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | template<typename Derived> |
| 3330 | Sema::OwningStmtResult |
| 3331 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3332 | // FIXME: Implement! |
| 3333 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | |
| 3338 | template<typename Derived> |
| 3339 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3340 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3341 | // FIXME: Implement this |
| 3342 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3343 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | template<typename Derived> |
| 3347 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | // FIXME: Implement this |
| 3350 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3351 | return SemaRef.Owned(S->Retain()); |
| 3352 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | template<typename Derived> |
| 3355 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | // FIXME: Implement this |
| 3358 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3359 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3361 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3362 | template<typename Derived> |
| 3363 | Sema::OwningStmtResult |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3364 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3365 | // FIXME: Implement this |
| 3366 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3367 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 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 | template<typename Derived> |
| 3371 | Sema::OwningStmtResult |
| 3372 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3373 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | // FIXME: Implement this |
| 3375 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | template<typename Derived> |
| 3380 | Sema::OwningStmtResult |
| 3381 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3382 | ObjCForCollectionStmt *S) { |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3383 | // FIXME: Implement this |
| 3384 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3385 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | |
| 3389 | template<typename Derived> |
| 3390 | Sema::OwningStmtResult |
| 3391 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3392 | // Transform the exception declaration, if any. |
| 3393 | VarDecl *Var = 0; |
| 3394 | if (S->getExceptionDecl()) { |
| 3395 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3396 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3397 | ExceptionDecl->getDeclName()); |
| 3398 | |
| 3399 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3400 | if (T.isNull()) |
| 3401 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3402 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3403 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3404 | T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3405 | ExceptionDecl->getTypeSourceInfo(), |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | ExceptionDecl->getIdentifier(), |
| 3407 | ExceptionDecl->getLocation(), |
| 3408 | /*FIXME: Inaccurate*/ |
| 3409 | SourceRange(ExceptionDecl->getLocation())); |
| 3410 | if (!Var || Var->isInvalidDecl()) { |
| 3411 | if (Var) |
| 3412 | Var->Destroy(SemaRef.Context); |
| 3413 | return SemaRef.StmtError(); |
| 3414 | } |
| 3415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3416 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3417 | // Transform the actual exception handler. |
| 3418 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3419 | if (Handler.isInvalid()) { |
| 3420 | if (Var) |
| 3421 | Var->Destroy(SemaRef.Context); |
| 3422 | return SemaRef.StmtError(); |
| 3423 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3424 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3425 | if (!getDerived().AlwaysRebuild() && |
| 3426 | !Var && |
| 3427 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | |
| 3430 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3431 | Var, |
| 3432 | move(Handler)); |
| 3433 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3434 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3435 | template<typename Derived> |
| 3436 | Sema::OwningStmtResult |
| 3437 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3438 | // Transform the try block itself. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3439 | OwningStmtResult TryBlock |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3440 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3441 | if (TryBlock.isInvalid()) |
| 3442 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3444 | // Transform the handlers. |
| 3445 | bool HandlerChanged = false; |
| 3446 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3447 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3448 | OwningStmtResult Handler |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3449 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3450 | if (Handler.isInvalid()) |
| 3451 | return SemaRef.StmtError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3454 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3456 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3457 | if (!getDerived().AlwaysRebuild() && |
| 3458 | TryBlock.get() == S->getTryBlock() && |
| 3459 | !HandlerChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3460 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3461 | |
| 3462 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3463 | move_arg(Handlers)); |
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 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3467 | // Expression transformation |
| 3468 | //===----------------------------------------------------------------------===// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3469 | template<typename Derived> |
| 3470 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3471 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E, |
| 3472 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3473 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3475 | |
| 3476 | template<typename Derived> |
| 3477 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3478 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E, |
| 3479 | bool isAddressOfOperand) { |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3480 | NestedNameSpecifier *Qualifier = 0; |
| 3481 | if (E->getQualifier()) { |
| 3482 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3483 | E->getQualifierRange()); |
| 3484 | if (!Qualifier) |
| 3485 | return SemaRef.ExprError(); |
| 3486 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 3487 | |
| 3488 | ValueDecl *ND |
| 3489 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3490 | if (!ND) |
| 3491 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3492 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3493 | if (!getDerived().AlwaysRebuild() && |
| 3494 | Qualifier == E->getQualifier() && |
| 3495 | ND == E->getDecl() && |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 3496 | !E->hasExplicitTemplateArgumentList()) { |
| 3497 | |
| 3498 | // Mark it referenced in the new context regardless. |
| 3499 | // FIXME: this is a bit instantiation-specific. |
| 3500 | SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); |
| 3501 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3503 | } |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 3504 | |
| 3505 | TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; |
| 3506 | if (E->hasExplicitTemplateArgumentList()) { |
| 3507 | TemplateArgs = &TransArgs; |
| 3508 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3509 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 3510 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
| 3511 | TemplateArgumentLoc Loc; |
| 3512 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
| 3513 | return SemaRef.ExprError(); |
| 3514 | TransArgs.addArgument(Loc); |
| 3515 | } |
| 3516 | } |
| 3517 | |
Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3518 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame^] | 3519 | ND, E->getLocation(), TemplateArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3520 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3522 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3524 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E, |
| 3525 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3526 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3527 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3529 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3531 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E, |
| 3532 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3533 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3536 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3537 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3538 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E, |
| 3539 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3540 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3542 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3543 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3544 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3545 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E, |
| 3546 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3549 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3550 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3551 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3552 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E, |
| 3553 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3554 | return SemaRef.Owned(E->Retain()); |
| 3555 | } |
| 3556 | |
| 3557 | template<typename Derived> |
| 3558 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3559 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E, |
| 3560 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3561 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3562 | if (SubExpr.isInvalid()) |
| 3563 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3565 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3566 | return SemaRef.Owned(E->Retain()); |
| 3567 | |
| 3568 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3569 | E->getRParen()); |
| 3570 | } |
| 3571 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3572 | template<typename Derived> |
| 3573 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3574 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E, |
| 3575 | bool isAddressOfOperand) { |
| 3576 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(), |
| 3577 | E->getOpcode() == UnaryOperator::AddrOf); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3578 | if (SubExpr.isInvalid()) |
| 3579 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3581 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3582 | return SemaRef.Owned(E->Retain()); |
| 3583 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3584 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3585 | E->getOpcode(), |
| 3586 | move(SubExpr)); |
| 3587 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3589 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3591 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, |
| 3592 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3593 | if (E->isArgumentType()) { |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3594 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3595 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3596 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3597 | if (!NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3598 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3600 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3601 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3602 | |
John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3603 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3604 | E->isSizeOf(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3605 | E->getSourceRange()); |
| 3606 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3607 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3608 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3609 | { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3610 | // C++0x [expr.sizeof]p1: |
| 3611 | // The operand is either an expression, which is an unevaluated operand |
| 3612 | // [...] |
| 3613 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3614 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3615 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3616 | if (SubExpr.isInvalid()) |
| 3617 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3618 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3619 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3620 | return SemaRef.Owned(E->Retain()); |
| 3621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3622 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3623 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3624 | E->isSizeOf(), |
| 3625 | E->getSourceRange()); |
| 3626 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3627 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3628 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3629 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3630 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E, |
| 3631 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3632 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3633 | if (LHS.isInvalid()) |
| 3634 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3635 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3636 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3637 | if (RHS.isInvalid()) |
| 3638 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3639 | |
| 3640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3641 | if (!getDerived().AlwaysRebuild() && |
| 3642 | LHS.get() == E->getLHS() && |
| 3643 | RHS.get() == E->getRHS()) |
| 3644 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3647 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3648 | move(RHS), |
| 3649 | E->getRBracketLoc()); |
| 3650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3651 | |
| 3652 | template<typename Derived> |
| 3653 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3654 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E, |
| 3655 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | // Transform the callee. |
| 3657 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3658 | if (Callee.isInvalid()) |
| 3659 | return SemaRef.ExprError(); |
| 3660 | |
| 3661 | // Transform arguments. |
| 3662 | bool ArgChanged = false; |
| 3663 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3664 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3665 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3666 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3667 | if (Arg.isInvalid()) |
| 3668 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3669 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3670 | // FIXME: Wrong source location information for the ','. |
| 3671 | FakeCommaLocs.push_back( |
| 3672 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3673 | |
| 3674 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3675 | Args.push_back(Arg.takeAs<Expr>()); |
| 3676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3678 | if (!getDerived().AlwaysRebuild() && |
| 3679 | Callee.get() == E->getCallee() && |
| 3680 | !ArgChanged) |
| 3681 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3682 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3683 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3684 | SourceLocation FakeLParenLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3685 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3686 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3687 | move_arg(Args), |
| 3688 | FakeCommaLocs.data(), |
| 3689 | E->getRParenLoc()); |
| 3690 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3691 | |
| 3692 | template<typename Derived> |
| 3693 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3694 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E, |
| 3695 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3696 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3697 | if (Base.isInvalid()) |
| 3698 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3699 | |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3700 | NestedNameSpecifier *Qualifier = 0; |
| 3701 | if (E->hasQualifier()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3702 | Qualifier |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3703 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3704 | E->getQualifierRange()); |
Douglas Gregor | 84f14dd | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3705 | if (Qualifier == 0) |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3706 | return SemaRef.ExprError(); |
| 3707 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3708 | |
Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 3709 | ValueDecl *Member |
| 3710 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3711 | if (!Member) |
| 3712 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3713 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3714 | if (!getDerived().AlwaysRebuild() && |
| 3715 | Base.get() == E->getBase() && |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3716 | Qualifier == E->getQualifier() && |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3717 | Member == E->getMemberDecl() && |
| 3718 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3719 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3720 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3721 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3722 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3723 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3724 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3725 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3726 | TemplateArgumentLoc Loc; |
| 3727 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3728 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3729 | TransArgs.addArgument(Loc); |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3733 | // FIXME: Bogus source location for the operator |
| 3734 | SourceLocation FakeOperatorLoc |
| 3735 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3736 | |
| 3737 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3738 | E->isArrow(), |
Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3739 | Qualifier, |
| 3740 | E->getQualifierRange(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | E->getMemberLoc(), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3742 | Member, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3743 | (E->hasExplicitTemplateArgumentList() |
| 3744 | ? &TransArgs : 0), |
Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3745 | 0); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3746 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3747 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3748 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3749 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3750 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E, |
| 3751 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | assert(false && "Cannot transform abstract class"); |
| 3753 | return SemaRef.Owned(E->Retain()); |
| 3754 | } |
| 3755 | |
| 3756 | template<typename Derived> |
| 3757 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3758 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E, |
| 3759 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3760 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3761 | if (LHS.isInvalid()) |
| 3762 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3764 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3765 | if (RHS.isInvalid()) |
| 3766 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3768 | if (!getDerived().AlwaysRebuild() && |
| 3769 | LHS.get() == E->getLHS() && |
| 3770 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3771 | return SemaRef.Owned(E->Retain()); |
| 3772 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3773 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3774 | move(LHS), move(RHS)); |
| 3775 | } |
| 3776 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3778 | Sema::OwningExprResult |
| 3779 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3780 | CompoundAssignOperator *E, |
| 3781 | bool isAddressOfOperand) { |
| 3782 | return getDerived().TransformBinaryOperator(E, isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 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 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3786 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3787 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E, |
| 3788 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3789 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3790 | if (Cond.isInvalid()) |
| 3791 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3792 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3793 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3794 | if (LHS.isInvalid()) |
| 3795 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3797 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3798 | if (RHS.isInvalid()) |
| 3799 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3801 | if (!getDerived().AlwaysRebuild() && |
| 3802 | Cond.get() == E->getCond() && |
| 3803 | LHS.get() == E->getLHS() && |
| 3804 | RHS.get() == E->getRHS()) |
| 3805 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3806 | |
| 3807 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3808 | E->getQuestionLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | move(LHS), |
Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3810 | E->getColonLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3811 | move(RHS)); |
| 3812 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
| 3814 | template<typename Derived> |
| 3815 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3816 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E, |
| 3817 | bool isAddressOfOperand) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3818 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3819 | |
| 3820 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3821 | // so do we even need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3822 | QualType T = getDerived().TransformType(E->getType()); |
| 3823 | if (T.isNull()) |
| 3824 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3826 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3827 | if (SubExpr.isInvalid()) |
| 3828 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3829 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3830 | if (!getDerived().AlwaysRebuild() && |
| 3831 | T == E->getType() && |
| 3832 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3833 | return SemaRef.Owned(E->Retain()); |
| 3834 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3835 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | move(SubExpr), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | E->isLvalueCast()); |
| 3838 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | template<typename Derived> |
| 3841 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3842 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E, |
| 3843 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | assert(false && "Cannot transform abstract class"); |
| 3845 | return SemaRef.Owned(E->Retain()); |
| 3846 | } |
| 3847 | |
| 3848 | template<typename Derived> |
| 3849 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3850 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E, |
| 3851 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3852 | QualType T; |
| 3853 | { |
| 3854 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3855 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3856 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3857 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3860 | if (T.isNull()) |
| 3861 | return SemaRef.ExprError(); |
| 3862 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3863 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3864 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3865 | if (SubExpr.isInvalid()) |
| 3866 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3867 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3868 | if (!getDerived().AlwaysRebuild() && |
| 3869 | T == E->getTypeAsWritten() && |
| 3870 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3871 | return SemaRef.Owned(E->Retain()); |
| 3872 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3873 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3874 | E->getRParenLoc(), |
| 3875 | move(SubExpr)); |
| 3876 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3877 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3878 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3879 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3880 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E, |
| 3881 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3882 | QualType T; |
| 3883 | { |
| 3884 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3885 | SourceLocation FakeTypeLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3886 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3887 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3889 | T = getDerived().TransformType(E->getType()); |
| 3890 | if (T.isNull()) |
| 3891 | return SemaRef.ExprError(); |
| 3892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3893 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3894 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3895 | if (Init.isInvalid()) |
| 3896 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3898 | if (!getDerived().AlwaysRebuild() && |
| 3899 | T == E->getType() && |
| 3900 | Init.get() == E->getInitializer()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3902 | |
| 3903 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3904 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3905 | move(Init)); |
| 3906 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3907 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3908 | template<typename Derived> |
| 3909 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3910 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E, |
| 3911 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3912 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3913 | if (Base.isInvalid()) |
| 3914 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3916 | if (!getDerived().AlwaysRebuild() && |
| 3917 | Base.get() == E->getBase()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3918 | return SemaRef.Owned(E->Retain()); |
| 3919 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3920 | // FIXME: Bad source location |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3921 | SourceLocation FakeOperatorLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3922 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3923 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3924 | E->getAccessorLoc(), |
| 3925 | E->getAccessor()); |
| 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> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3929 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3930 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E, |
| 3931 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3932 | bool InitChanged = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3933 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3934 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3935 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3936 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3937 | if (Init.isInvalid()) |
| 3938 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3939 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3940 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3941 | Inits.push_back(Init.takeAs<Expr>()); |
| 3942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3943 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | return SemaRef.Owned(E->Retain()); |
| 3946 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3947 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | d3d9306 | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3948 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3950 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3951 | template<typename Derived> |
| 3952 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3953 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E, |
| 3954 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3955 | Designation Desig; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3956 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3957 | // transform the initializer value |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3958 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3959 | if (Init.isInvalid()) |
| 3960 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3962 | // transform the designators. |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3963 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3964 | bool ExprChanged = false; |
| 3965 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3966 | DEnd = E->designators_end(); |
| 3967 | D != DEnd; ++D) { |
| 3968 | if (D->isFieldDesignator()) { |
| 3969 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3970 | D->getDotLoc(), |
| 3971 | D->getFieldLoc())); |
| 3972 | continue; |
| 3973 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | if (D->isArrayDesignator()) { |
| 3976 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3977 | if (Index.isInvalid()) |
| 3978 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3979 | |
| 3980 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3981 | D->getLBracketLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3982 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3983 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3984 | ArrayExprs.push_back(Index.release()); |
| 3985 | continue; |
| 3986 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3987 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3988 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3989 | OwningExprResult Start |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3990 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3991 | if (Start.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 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3995 | if (End.isInvalid()) |
| 3996 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3997 | |
| 3998 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3999 | End.get(), |
| 4000 | D->getLBracketLoc(), |
| 4001 | D->getEllipsisLoc())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 4004 | End.get() != E->getArrayRangeEnd(*D); |
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 | ArrayExprs.push_back(Start.release()); |
| 4007 | ArrayExprs.push_back(End.release()); |
| 4008 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4009 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | if (!getDerived().AlwaysRebuild() && |
| 4011 | Init.get() == E->getInit() && |
| 4012 | !ExprChanged) |
| 4013 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4015 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 4016 | E->getEqualOrColonLoc(), |
| 4017 | E->usesGNUSyntax(), move(Init)); |
| 4018 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4019 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4020 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4021 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4022 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4023 | ImplicitValueInitExpr *E, |
| 4024 | bool isAddressOfOperand) { |
Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4025 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4026 | |
| 4027 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4028 | // need to transform the type? |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4029 | QualType T = getDerived().TransformType(E->getType()); |
| 4030 | if (T.isNull()) |
| 4031 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4033 | if (!getDerived().AlwaysRebuild() && |
| 4034 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | return SemaRef.Owned(E->Retain()); |
| 4036 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4037 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4038 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4040 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4041 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4042 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E, |
| 4043 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4044 | // FIXME: Do we want the type as written? |
| 4045 | QualType T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4046 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4047 | { |
| 4048 | // FIXME: Source location isn't quite accurate. |
| 4049 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4050 | T = getDerived().TransformType(E->getType()); |
| 4051 | if (T.isNull()) |
| 4052 | return SemaRef.ExprError(); |
| 4053 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4054 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4055 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4056 | if (SubExpr.isInvalid()) |
| 4057 | return SemaRef.ExprError(); |
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 | if (!getDerived().AlwaysRebuild() && |
| 4060 | T == E->getType() && |
| 4061 | SubExpr.get() == E->getSubExpr()) |
| 4062 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4065 | T, E->getRParenLoc()); |
| 4066 | } |
| 4067 | |
| 4068 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4069 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4070 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E, |
| 4071 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4072 | bool ArgumentChanged = false; |
| 4073 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4074 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4075 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4076 | if (Init.isInvalid()) |
| 4077 | return SemaRef.ExprError(); |
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 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4080 | Inits.push_back(Init.takeAs<Expr>()); |
| 4081 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4082 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4083 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4084 | move_arg(Inits), |
| 4085 | E->getRParenLoc()); |
| 4086 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4088 | /// \brief Transform an address-of-label expression. |
| 4089 | /// |
| 4090 | /// By default, the transformation of an address-of-label expression always |
| 4091 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4092 | /// the corresponding label statement by semantic analysis. |
| 4093 | template<typename Derived> |
| 4094 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4095 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E, |
| 4096 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4097 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4098 | E->getLabel()); |
| 4099 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4100 | |
| 4101 | template<typename Derived> |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4102 | Sema::OwningExprResult |
| 4103 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E, |
| 4104 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4105 | OwningStmtResult SubStmt |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4106 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4107 | if (SubStmt.isInvalid()) |
| 4108 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4110 | if (!getDerived().AlwaysRebuild() && |
| 4111 | SubStmt.get() == E->getSubStmt()) |
| 4112 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4113 | |
| 4114 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4115 | move(SubStmt), |
| 4116 | E->getRParenLoc()); |
| 4117 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4118 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4119 | template<typename Derived> |
| 4120 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4121 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E, |
| 4122 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4123 | QualType T1, T2; |
| 4124 | { |
| 4125 | // FIXME: Source location isn't quite accurate. |
| 4126 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4128 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4129 | if (T1.isNull()) |
| 4130 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4132 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4133 | if (T2.isNull()) |
| 4134 | return SemaRef.ExprError(); |
| 4135 | } |
| 4136 | |
| 4137 | if (!getDerived().AlwaysRebuild() && |
| 4138 | T1 == E->getArgType1() && |
| 4139 | T2 == E->getArgType2()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4140 | return SemaRef.Owned(E->Retain()); |
| 4141 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4142 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4143 | T1, T2, E->getRParenLoc()); |
| 4144 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4145 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4146 | template<typename Derived> |
| 4147 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4148 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E, |
| 4149 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4150 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4151 | if (Cond.isInvalid()) |
| 4152 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4155 | if (LHS.isInvalid()) |
| 4156 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4157 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4158 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4159 | if (RHS.isInvalid()) |
| 4160 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4161 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4162 | if (!getDerived().AlwaysRebuild() && |
| 4163 | Cond.get() == E->getCond() && |
| 4164 | LHS.get() == E->getLHS() && |
| 4165 | RHS.get() == E->getRHS()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4166 | return SemaRef.Owned(E->Retain()); |
| 4167 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4168 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4169 | move(Cond), move(LHS), move(RHS), |
| 4170 | E->getRParenLoc()); |
| 4171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4172 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4173 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4175 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E, |
| 4176 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4177 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | template<typename Derived> |
| 4181 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4182 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E, |
| 4183 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4184 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4185 | if (Callee.isInvalid()) |
| 4186 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4187 | |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4188 | OwningExprResult First |
| 4189 | = getDerived().TransformExpr(E->getArg(0), |
| 4190 | E->getNumArgs() == 1 && E->getOperator() == OO_Amp); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4191 | if (First.isInvalid()) |
| 4192 | return SemaRef.ExprError(); |
| 4193 | |
| 4194 | OwningExprResult Second(SemaRef); |
| 4195 | if (E->getNumArgs() == 2) { |
| 4196 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4197 | if (Second.isInvalid()) |
| 4198 | return SemaRef.ExprError(); |
| 4199 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4200 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4201 | if (!getDerived().AlwaysRebuild() && |
| 4202 | Callee.get() == E->getCallee() && |
| 4203 | First.get() == E->getArg(0) && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4204 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4205 | return SemaRef.Owned(E->Retain()); |
| 4206 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4207 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4208 | E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | move(Callee), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | move(First), |
| 4211 | move(Second)); |
| 4212 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4213 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4214 | template<typename Derived> |
| 4215 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4216 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E, |
| 4217 | bool isAddressOfOperand) { |
| 4218 | return getDerived().TransformCallExpr(E, isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4219 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4220 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4221 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4222 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4223 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E, |
| 4224 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4225 | QualType ExplicitTy; |
| 4226 | { |
| 4227 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | SourceLocation TypeStartLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4230 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4231 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4232 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4233 | if (ExplicitTy.isNull()) |
| 4234 | return SemaRef.ExprError(); |
| 4235 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4237 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4238 | if (SubExpr.isInvalid()) |
| 4239 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4240 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4241 | if (!getDerived().AlwaysRebuild() && |
| 4242 | ExplicitTy == E->getTypeAsWritten() && |
| 4243 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 | return SemaRef.Owned(E->Retain()); |
| 4245 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4246 | // FIXME: Poor source location information here. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 | SourceLocation FakeLAngleLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4248 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4249 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4250 | SourceLocation FakeRParenLoc |
| 4251 | = SemaRef.PP.getLocForEndOfToken( |
| 4252 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4253 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4254 | E->getStmtClass(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4255 | FakeLAngleLoc, |
| 4256 | ExplicitTy, |
| 4257 | FakeRAngleLoc, |
| 4258 | FakeRAngleLoc, |
| 4259 | move(SubExpr), |
| 4260 | FakeRParenLoc); |
| 4261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4262 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4263 | template<typename Derived> |
| 4264 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4265 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E, |
| 4266 | bool isAddressOfOperand) { |
| 4267 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4268 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4269 | |
| 4270 | template<typename Derived> |
| 4271 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4272 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E, |
| 4273 | bool isAddressOfOperand) { |
| 4274 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4277 | template<typename Derived> |
| 4278 | Sema::OwningExprResult |
| 4279 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4280 | CXXReinterpretCastExpr *E, |
| 4281 | bool isAddressOfOperand) { |
| 4282 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4283 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4284 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4285 | template<typename Derived> |
| 4286 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4287 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E, |
| 4288 | bool isAddressOfOperand) { |
| 4289 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4290 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4291 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4292 | template<typename Derived> |
| 4293 | Sema::OwningExprResult |
| 4294 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4295 | CXXFunctionalCastExpr *E, |
| 4296 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4297 | QualType ExplicitTy; |
| 4298 | { |
| 4299 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4300 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4301 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4302 | if (ExplicitTy.isNull()) |
| 4303 | return SemaRef.ExprError(); |
| 4304 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4305 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4306 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4307 | if (SubExpr.isInvalid()) |
| 4308 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4309 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4310 | if (!getDerived().AlwaysRebuild() && |
| 4311 | ExplicitTy == E->getTypeAsWritten() && |
| 4312 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4313 | return SemaRef.Owned(E->Retain()); |
| 4314 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4315 | // FIXME: The end of the type's source range is wrong |
| 4316 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4317 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4318 | ExplicitTy, |
| 4319 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4320 | move(SubExpr), |
| 4321 | E->getRParenLoc()); |
| 4322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4323 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4324 | template<typename Derived> |
| 4325 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4326 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E, |
| 4327 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4328 | if (E->isTypeOperand()) { |
| 4329 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
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 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4332 | if (T.isNull()) |
| 4333 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4334 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4335 | if (!getDerived().AlwaysRebuild() && |
| 4336 | T == E->getTypeOperand()) |
| 4337 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4339 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4340 | /*FIXME:*/E->getLocStart(), |
| 4341 | T, |
| 4342 | E->getLocEnd()); |
| 4343 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4345 | // We don't know whether the expression is potentially evaluated until |
| 4346 | // after we perform semantic analysis, so the expression is potentially |
| 4347 | // potentially evaluated. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4348 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4349 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4352 | if (SubExpr.isInvalid()) |
| 4353 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4355 | if (!getDerived().AlwaysRebuild() && |
| 4356 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4357 | return SemaRef.Owned(E->Retain()); |
| 4358 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4360 | /*FIXME:*/E->getLocStart(), |
| 4361 | move(SubExpr), |
| 4362 | E->getLocEnd()); |
| 4363 | } |
| 4364 | |
| 4365 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4367 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E, |
| 4368 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4369 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4370 | } |
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 | template<typename Derived> |
| 4373 | Sema::OwningExprResult |
| 4374 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4375 | CXXNullPtrLiteralExpr *E, |
| 4376 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4379 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4380 | template<typename Derived> |
| 4381 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4382 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E, |
| 4383 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4384 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | QualType T = getDerived().TransformType(E->getType()); |
| 4387 | if (T.isNull()) |
| 4388 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4389 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4390 | if (!getDerived().AlwaysRebuild() && |
| 4391 | T == E->getType()) |
| 4392 | return SemaRef.Owned(E->Retain()); |
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 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4397 | template<typename Derived> |
| 4398 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4399 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E, |
| 4400 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4401 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4402 | if (SubExpr.isInvalid()) |
| 4403 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4405 | if (!getDerived().AlwaysRebuild() && |
| 4406 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4407 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4408 | |
| 4409 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4410 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4411 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4412 | template<typename Derived> |
| 4413 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4414 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E, |
| 4415 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4416 | ParmVarDecl *Param |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4417 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4418 | if (!Param) |
| 4419 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4420 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4421 | if (getDerived().AlwaysRebuild() && |
| 4422 | Param == E->getParam()) |
| 4423 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4424 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4425 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4426 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4427 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4428 | template<typename Derived> |
| 4429 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4430 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E, |
| 4431 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4432 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4433 | |
| 4434 | QualType T = getDerived().TransformType(E->getType()); |
| 4435 | if (T.isNull()) |
| 4436 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | if (!getDerived().AlwaysRebuild() && |
| 4439 | T == E->getType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4440 | return SemaRef.Owned(E->Retain()); |
| 4441 | |
| 4442 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4444 | T, |
| 4445 | E->getRParenLoc()); |
| 4446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4448 | template<typename Derived> |
| 4449 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4450 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E, |
| 4451 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4452 | // Transform the type that we're allocating |
| 4453 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4454 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4455 | if (AllocType.isNull()) |
| 4456 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4457 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4458 | // Transform the size of the array we're allocating (if any). |
| 4459 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4460 | if (ArraySize.isInvalid()) |
| 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 | // Transform the placement arguments (if any). |
| 4464 | bool ArgumentChanged = false; |
| 4465 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4466 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4467 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4468 | if (Arg.isInvalid()) |
| 4469 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4470 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4471 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4472 | PlacementArgs.push_back(Arg.take()); |
| 4473 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4474 | |
Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4475 | // transform the constructor arguments (if any). |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4476 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4477 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4478 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4479 | if (Arg.isInvalid()) |
| 4480 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4482 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4483 | ConstructorArgs.push_back(Arg.take()); |
| 4484 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4486 | if (!getDerived().AlwaysRebuild() && |
| 4487 | AllocType == E->getAllocatedType() && |
| 4488 | ArraySize.get() == E->getArraySize() && |
| 4489 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4490 | return SemaRef.Owned(E->Retain()); |
| 4491 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4492 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4493 | E->isGlobalNew(), |
| 4494 | /*FIXME:*/E->getLocStart(), |
| 4495 | move_arg(PlacementArgs), |
| 4496 | /*FIXME:*/E->getLocStart(), |
| 4497 | E->isParenTypeId(), |
| 4498 | AllocType, |
| 4499 | /*FIXME:*/E->getLocStart(), |
| 4500 | /*FIXME:*/SourceRange(), |
| 4501 | move(ArraySize), |
| 4502 | /*FIXME:*/E->getLocStart(), |
| 4503 | move_arg(ConstructorArgs), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4504 | E->getLocEnd()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4505 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4507 | template<typename Derived> |
| 4508 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4509 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E, |
| 4510 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4511 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4512 | if (Operand.isInvalid()) |
| 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() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4516 | Operand.get() == E->getArgument()) |
| 4517 | return SemaRef.Owned(E->Retain()); |
| 4518 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4519 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4520 | E->isGlobalDelete(), |
| 4521 | E->isArrayForm(), |
| 4522 | move(Operand)); |
| 4523 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4524 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4525 | template<typename Derived> |
| 4526 | Sema::OwningExprResult |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4527 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4528 | CXXPseudoDestructorExpr *E, |
| 4529 | bool isAddressOfOperand) { |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4530 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4531 | if (Base.isInvalid()) |
| 4532 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4534 | NestedNameSpecifier *Qualifier |
| 4535 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4536 | E->getQualifierRange()); |
| 4537 | if (E->getQualifier() && !Qualifier) |
| 4538 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4539 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4540 | QualType DestroyedType; |
| 4541 | { |
| 4542 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4543 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4544 | if (DestroyedType.isNull()) |
| 4545 | return SemaRef.ExprError(); |
| 4546 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4548 | if (!getDerived().AlwaysRebuild() && |
| 4549 | Base.get() == E->getBase() && |
| 4550 | Qualifier == E->getQualifier() && |
| 4551 | DestroyedType == E->getDestroyedType()) |
| 4552 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4553 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4554 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4555 | E->getOperatorLoc(), |
| 4556 | E->isArrow(), |
| 4557 | E->getDestroyedTypeLoc(), |
| 4558 | DestroyedType, |
| 4559 | Qualifier, |
| 4560 | E->getQualifierRange()); |
| 4561 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4562 | |
Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4563 | template<typename Derived> |
| 4564 | Sema::OwningExprResult |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4565 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4566 | UnresolvedLookupExpr *Old, |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4567 | bool isAddressOfOperand) { |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4568 | TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); |
| 4569 | |
| 4570 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 4571 | Sema::LookupOrdinaryName); |
| 4572 | |
| 4573 | // Transform all the decls. |
| 4574 | for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), |
| 4575 | E = Old->decls_end(); I != E; ++I) { |
| 4576 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
| 4577 | if (!InstD) |
| 4578 | return SemaRef.ExprError(); |
| 4579 | |
| 4580 | // Expand using declarations. |
| 4581 | if (isa<UsingDecl>(InstD)) { |
| 4582 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4583 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 4584 | E = UD->shadow_end(); I != E; ++I) |
| 4585 | R.addDecl(*I); |
| 4586 | continue; |
| 4587 | } |
| 4588 | |
| 4589 | R.addDecl(InstD); |
| 4590 | } |
| 4591 | |
| 4592 | // Resolve a kind, but don't do any further analysis. If it's |
| 4593 | // ambiguous, the callee needs to deal with it. |
| 4594 | R.resolveKind(); |
| 4595 | |
| 4596 | // Rebuild the nested-name qualifier, if present. |
| 4597 | CXXScopeSpec SS; |
| 4598 | NestedNameSpecifier *Qualifier = 0; |
| 4599 | if (Old->getQualifier()) { |
| 4600 | Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4601 | Old->getQualifierRange()); |
| 4602 | if (!Qualifier) |
| 4603 | return SemaRef.ExprError(); |
| 4604 | |
| 4605 | SS.setScopeRep(Qualifier); |
| 4606 | SS.setRange(Old->getQualifierRange()); |
| 4607 | } |
| 4608 | |
| 4609 | // If we have no template arguments, it's a normal declaration name. |
| 4610 | if (!Old->hasExplicitTemplateArgs()) |
| 4611 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 4612 | |
| 4613 | // If we have template arguments, rebuild them, then rebuild the |
| 4614 | // templateid expression. |
| 4615 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 4616 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 4617 | TemplateArgumentLoc Loc; |
| 4618 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc)) |
| 4619 | return SemaRef.ExprError(); |
| 4620 | TransArgs.addArgument(Loc); |
| 4621 | } |
| 4622 | |
| 4623 | return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), |
| 4624 | TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4625 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4626 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4627 | template<typename Derived> |
| 4628 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4629 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E, |
| 4630 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4631 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4633 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4634 | if (T.isNull()) |
| 4635 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4636 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4637 | if (!getDerived().AlwaysRebuild() && |
| 4638 | T == E->getQueriedType()) |
| 4639 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4640 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4641 | // FIXME: Bad location information |
| 4642 | SourceLocation FakeLParenLoc |
| 4643 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4644 | |
| 4645 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4646 | E->getLocStart(), |
| 4647 | /*FIXME:*/FakeLParenLoc, |
| 4648 | T, |
| 4649 | E->getLocEnd()); |
| 4650 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4651 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4652 | template<typename Derived> |
| 4653 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4654 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 4655 | DependentScopeDeclRefExpr *E, |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4656 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4657 | NestedNameSpecifier *NNS |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4658 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4659 | E->getQualifierRange()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | if (!NNS) |
| 4661 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4662 | |
| 4663 | DeclarationName Name |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4664 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4665 | if (!Name) |
| 4666 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4667 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4668 | if (!E->hasExplicitTemplateArgs()) { |
| 4669 | if (!getDerived().AlwaysRebuild() && |
| 4670 | NNS == E->getQualifier() && |
| 4671 | Name == E->getDeclName()) |
| 4672 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4673 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4674 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4675 | E->getQualifierRange(), |
| 4676 | Name, E->getLocation(), |
| 4677 | /*TemplateArgs*/ 0); |
Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4678 | } |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4679 | |
| 4680 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4682 | TemplateArgumentLoc Loc; |
| 4683 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4684 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4685 | TransArgs.addArgument(Loc); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 4688 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
| 4689 | E->getQualifierRange(), |
| 4690 | Name, E->getLocation(), |
| 4691 | &TransArgs); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | template<typename Derived> |
| 4695 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4696 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E, |
| 4697 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4698 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4699 | |
| 4700 | QualType T = getDerived().TransformType(E->getType()); |
| 4701 | if (T.isNull()) |
| 4702 | return SemaRef.ExprError(); |
| 4703 | |
| 4704 | CXXConstructorDecl *Constructor |
| 4705 | = cast_or_null<CXXConstructorDecl>( |
| 4706 | getDerived().TransformDecl(E->getConstructor())); |
| 4707 | if (!Constructor) |
| 4708 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4709 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4710 | bool ArgumentChanged = false; |
| 4711 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4712 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4713 | ArgEnd = E->arg_end(); |
| 4714 | Arg != ArgEnd; ++Arg) { |
| 4715 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4716 | if (TransArg.isInvalid()) |
| 4717 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4720 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4721 | } |
| 4722 | |
| 4723 | if (!getDerived().AlwaysRebuild() && |
| 4724 | T == E->getType() && |
| 4725 | Constructor == E->getConstructor() && |
| 4726 | !ArgumentChanged) |
| 4727 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4728 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4729 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4730 | move_arg(Args)); |
| 4731 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4732 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4733 | /// \brief Transform a C++ temporary-binding expression. |
| 4734 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4735 | /// The transformation of a temporary-binding expression always attempts to |
| 4736 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4737 | /// subexpression itself did not change, because the temporary variable itself |
| 4738 | /// must be unique. |
| 4739 | template<typename Derived> |
| 4740 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4741 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E, |
| 4742 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4743 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4744 | if (SubExpr.isInvalid()) |
| 4745 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4747 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4748 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4749 | |
| 4750 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4751 | /// be destroyed after the expression is evaluated. |
| 4752 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4753 | /// The transformation of a full expression always attempts to build a new |
| 4754 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | /// subexpression itself did not change, because it will need to capture the |
| 4756 | /// the new temporary variables introduced in the subexpression. |
| 4757 | template<typename Derived> |
| 4758 | Sema::OwningExprResult |
| 4759 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4760 | CXXExprWithTemporaries *E, |
| 4761 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4762 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4763 | if (SubExpr.isInvalid()) |
| 4764 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4765 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4766 | return SemaRef.Owned( |
| 4767 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4768 | E->shouldDestroyTemporaries())); |
| 4769 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4770 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4771 | template<typename Derived> |
| 4772 | Sema::OwningExprResult |
| 4773 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4774 | CXXTemporaryObjectExpr *E, |
| 4775 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4776 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4777 | QualType T = getDerived().TransformType(E->getType()); |
| 4778 | if (T.isNull()) |
| 4779 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4780 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4781 | CXXConstructorDecl *Constructor |
| 4782 | = cast_or_null<CXXConstructorDecl>( |
| 4783 | getDerived().TransformDecl(E->getConstructor())); |
| 4784 | if (!Constructor) |
| 4785 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4786 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4787 | bool ArgumentChanged = false; |
| 4788 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4789 | Args.reserve(E->getNumArgs()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4790 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4791 | ArgEnd = E->arg_end(); |
| 4792 | Arg != ArgEnd; ++Arg) { |
| 4793 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4794 | if (TransArg.isInvalid()) |
| 4795 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4797 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4798 | Args.push_back((Expr *)TransArg.release()); |
| 4799 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4800 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4801 | if (!getDerived().AlwaysRebuild() && |
| 4802 | T == E->getType() && |
| 4803 | Constructor == E->getConstructor() && |
| 4804 | !ArgumentChanged) |
| 4805 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4807 | // FIXME: Bogus location information |
| 4808 | SourceLocation CommaLoc; |
| 4809 | if (Args.size() > 1) { |
| 4810 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4811 | CommaLoc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4812 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4813 | } |
| 4814 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4815 | T, |
| 4816 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4817 | move_arg(Args), |
| 4818 | &CommaLoc, |
| 4819 | E->getLocEnd()); |
| 4820 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4821 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4822 | template<typename Derived> |
| 4823 | Sema::OwningExprResult |
| 4824 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4825 | CXXUnresolvedConstructExpr *E, |
| 4826 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4827 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4828 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4829 | if (T.isNull()) |
| 4830 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4831 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4832 | bool ArgumentChanged = false; |
| 4833 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4834 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4835 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4836 | ArgEnd = E->arg_end(); |
| 4837 | Arg != ArgEnd; ++Arg) { |
| 4838 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4839 | if (TransArg.isInvalid()) |
| 4840 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4841 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4842 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4843 | FakeCommaLocs.push_back( |
| 4844 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4845 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4846 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4847 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4848 | if (!getDerived().AlwaysRebuild() && |
| 4849 | T == E->getTypeAsWritten() && |
| 4850 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4851 | return SemaRef.Owned(E->Retain()); |
| 4852 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4853 | // FIXME: we're faking the locations of the commas |
| 4854 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4855 | T, |
| 4856 | E->getLParenLoc(), |
| 4857 | move_arg(Args), |
| 4858 | FakeCommaLocs.data(), |
| 4859 | E->getRParenLoc()); |
| 4860 | } |
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 | template<typename Derived> |
| 4863 | Sema::OwningExprResult |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4864 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 4865 | CXXDependentScopeMemberExpr *E, |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4866 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4867 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4868 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4869 | Expr *OldBase; |
| 4870 | QualType BaseType; |
| 4871 | QualType ObjectType; |
| 4872 | if (!E->isImplicitAccess()) { |
| 4873 | OldBase = E->getBase(); |
| 4874 | Base = getDerived().TransformExpr(OldBase); |
| 4875 | if (Base.isInvalid()) |
| 4876 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4877 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4878 | // Start the member reference and compute the object's type. |
| 4879 | Sema::TypeTy *ObjectTy = 0; |
| 4880 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
| 4881 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4882 | E->isArrow()? tok::arrow : tok::period, |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4883 | ObjectTy); |
| 4884 | if (Base.isInvalid()) |
| 4885 | return SemaRef.ExprError(); |
| 4886 | |
| 4887 | ObjectType = QualType::getFromOpaquePtr(ObjectTy); |
| 4888 | BaseType = ((Expr*) Base.get())->getType(); |
| 4889 | } else { |
| 4890 | OldBase = 0; |
| 4891 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 4892 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 4893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4894 | |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4895 | // Transform the first part of the nested-name-specifier that qualifies |
| 4896 | // the member name. |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4897 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4898 | = getDerived().TransformFirstQualifierInScope( |
| 4899 | E->getFirstQualifierFoundInScope(), |
| 4900 | E->getQualifierRange().getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4901 | |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4902 | NestedNameSpecifier *Qualifier = 0; |
| 4903 | if (E->getQualifier()) { |
| 4904 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4905 | E->getQualifierRange(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4906 | ObjectType, |
| 4907 | FirstQualifierInScope); |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4908 | if (!Qualifier) |
| 4909 | return SemaRef.ExprError(); |
| 4910 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4911 | |
| 4912 | DeclarationName Name |
Douglas Gregor | c59e561 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4913 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4914 | ObjectType); |
Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4915 | if (!Name) |
| 4916 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4917 | |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4918 | if (!E->hasExplicitTemplateArgs()) { |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4919 | // This is a reference to a member without an explicitly-specified |
| 4920 | // template argument list. Optimize for this common case. |
| 4921 | if (!getDerived().AlwaysRebuild() && |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4922 | Base.get() == OldBase && |
| 4923 | BaseType == E->getBaseType() && |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4924 | Qualifier == E->getQualifier() && |
| 4925 | Name == E->getMember() && |
| 4926 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4927 | return SemaRef.Owned(E->Retain()); |
| 4928 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4929 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4930 | BaseType, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4931 | E->isArrow(), |
| 4932 | E->getOperatorLoc(), |
| 4933 | Qualifier, |
| 4934 | E->getQualifierRange(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4935 | FirstQualifierInScope, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4936 | Name, |
| 4937 | E->getMemberLoc(), |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4938 | /*TemplateArgs*/ 0); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4939 | } |
| 4940 | |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4941 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4942 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4943 | TemplateArgumentLoc Loc; |
| 4944 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4945 | return SemaRef.ExprError(); |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4946 | TransArgs.addArgument(Loc); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4947 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | |
John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4949 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4950 | BaseType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4951 | E->isArrow(), |
| 4952 | E->getOperatorLoc(), |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4953 | Qualifier, |
| 4954 | E->getQualifierRange(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4955 | FirstQualifierInScope, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4956 | Name, |
| 4957 | E->getMemberLoc(), |
| 4958 | &TransArgs); |
| 4959 | } |
| 4960 | |
| 4961 | template<typename Derived> |
| 4962 | Sema::OwningExprResult |
| 4963 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old, |
| 4964 | bool isAddressOfOperand) { |
| 4965 | // Transform the base of the expression. |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 4966 | OwningExprResult Base(SemaRef, (Expr*) 0); |
| 4967 | QualType BaseType; |
| 4968 | if (!Old->isImplicitAccess()) { |
| 4969 | Base = getDerived().TransformExpr(Old->getBase()); |
| 4970 | if (Base.isInvalid()) |
| 4971 | return SemaRef.ExprError(); |
| 4972 | BaseType = ((Expr*) Base.get())->getType(); |
| 4973 | } else { |
| 4974 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 4975 | } |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 4976 | |
| 4977 | NestedNameSpecifier *Qualifier = 0; |
| 4978 | if (Old->getQualifier()) { |
| 4979 | Qualifier |
| 4980 | = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), |
| 4981 | Old->getQualifierRange()); |
| 4982 | if (Qualifier == 0) |
| 4983 | return SemaRef.ExprError(); |
| 4984 | } |
| 4985 | |
| 4986 | LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(), |
| 4987 | Sema::LookupOrdinaryName); |
| 4988 | |
| 4989 | // Transform all the decls. |
| 4990 | for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), |
| 4991 | E = Old->decls_end(); I != E; ++I) { |
| 4992 | NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I)); |
| 4993 | if (!InstD) |
| 4994 | return SemaRef.ExprError(); |
| 4995 | |
| 4996 | // Expand using declarations. |
| 4997 | if (isa<UsingDecl>(InstD)) { |
| 4998 | UsingDecl *UD = cast<UsingDecl>(InstD); |
| 4999 | for (UsingDecl::shadow_iterator I = UD->shadow_begin(), |
| 5000 | E = UD->shadow_end(); I != E; ++I) |
| 5001 | R.addDecl(*I); |
| 5002 | continue; |
| 5003 | } |
| 5004 | |
| 5005 | R.addDecl(InstD); |
| 5006 | } |
| 5007 | |
| 5008 | R.resolveKind(); |
| 5009 | |
| 5010 | TemplateArgumentListInfo TransArgs; |
| 5011 | if (Old->hasExplicitTemplateArgs()) { |
| 5012 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 5013 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 5014 | for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) { |
| 5015 | TemplateArgumentLoc Loc; |
| 5016 | if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], |
| 5017 | Loc)) |
| 5018 | return SemaRef.ExprError(); |
| 5019 | TransArgs.addArgument(Loc); |
| 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | return getDerived().RebuildUnresolvedMemberExpr(move(Base), |
John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 5024 | BaseType, |
John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 5025 | Old->getOperatorLoc(), |
| 5026 | Old->isArrow(), |
| 5027 | Qualifier, |
| 5028 | Old->getQualifierRange(), |
| 5029 | R, |
| 5030 | (Old->hasExplicitTemplateArgs() |
| 5031 | ? &TransArgs : 0)); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | template<typename Derived> |
| 5035 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5036 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E, |
| 5037 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5038 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5039 | } |
| 5040 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5041 | template<typename Derived> |
| 5042 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5043 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E, |
| 5044 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5045 | // FIXME: poor source location |
| 5046 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 5047 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 5048 | if (EncodedType.isNull()) |
| 5049 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5050 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5051 | if (!getDerived().AlwaysRebuild() && |
| 5052 | EncodedType == E->getEncodedType()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5053 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5054 | |
| 5055 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 5056 | EncodedType, |
| 5057 | E->getRParenLoc()); |
| 5058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5059 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5060 | template<typename Derived> |
| 5061 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5062 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E, |
| 5063 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5064 | // FIXME: Implement this! |
| 5065 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5066 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5067 | } |
| 5068 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5069 | template<typename Derived> |
| 5070 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5071 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E, |
| 5072 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5073 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5074 | } |
| 5075 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5076 | template<typename Derived> |
| 5077 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5078 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E, |
| 5079 | bool isAddressOfOperand) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5080 | ObjCProtocolDecl *Protocol |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5081 | = cast_or_null<ObjCProtocolDecl>( |
| 5082 | getDerived().TransformDecl(E->getProtocol())); |
| 5083 | if (!Protocol) |
| 5084 | return SemaRef.ExprError(); |
| 5085 | |
| 5086 | if (!getDerived().AlwaysRebuild() && |
| 5087 | Protocol == E->getProtocol()) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5088 | return SemaRef.Owned(E->Retain()); |
| 5089 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5090 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 5091 | E->getAtLoc(), |
| 5092 | /*FIXME:*/E->getAtLoc(), |
| 5093 | /*FIXME:*/E->getAtLoc(), |
| 5094 | E->getRParenLoc()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5095 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | template<typename Derived> |
| 5099 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5100 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E, |
| 5101 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5102 | // FIXME: Implement this! |
| 5103 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5104 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5107 | template<typename Derived> |
| 5108 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5109 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E, |
| 5110 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5111 | // FIXME: Implement this! |
| 5112 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5113 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5114 | } |
| 5115 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5116 | template<typename Derived> |
| 5117 | Sema::OwningExprResult |
Fariborz Jahanian | 9a84665 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5118 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5119 | ObjCImplicitSetterGetterRefExpr *E, |
| 5120 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5121 | // FIXME: Implement this! |
| 5122 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5123 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5126 | template<typename Derived> |
| 5127 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5128 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E, |
| 5129 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5130 | // FIXME: Implement this! |
| 5131 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5132 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5135 | template<typename Derived> |
| 5136 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5137 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E, |
| 5138 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5139 | // FIXME: Implement this! |
| 5140 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5141 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5144 | template<typename Derived> |
| 5145 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5146 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E, |
| 5147 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5148 | bool ArgumentChanged = false; |
| 5149 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5150 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5151 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5152 | if (SubExpr.isInvalid()) |
| 5153 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5155 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5156 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5157 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5159 | if (!getDerived().AlwaysRebuild() && |
| 5160 | !ArgumentChanged) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5161 | return SemaRef.Owned(E->Retain()); |
| 5162 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5163 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5164 | move_arg(SubExprs), |
| 5165 | E->getRParenLoc()); |
| 5166 | } |
| 5167 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5168 | template<typename Derived> |
| 5169 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5170 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E, |
| 5171 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5172 | // FIXME: Implement this! |
| 5173 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5174 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5175 | } |
| 5176 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5177 | template<typename Derived> |
| 5178 | Sema::OwningExprResult |
Douglas Gregor | c95a1fa | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5179 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E, |
| 5180 | bool isAddressOfOperand) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5181 | // FIXME: Implement this! |
| 5182 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5183 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5185 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5186 | //===----------------------------------------------------------------------===// |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5187 | // Type reconstruction |
| 5188 | //===----------------------------------------------------------------------===// |
| 5189 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5190 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5191 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5192 | SourceLocation Star) { |
| 5193 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5194 | getDerived().getBaseEntity()); |
| 5195 | } |
| 5196 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5197 | template<typename Derived> |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5198 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5199 | SourceLocation Star) { |
| 5200 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5201 | getDerived().getBaseEntity()); |
| 5202 | } |
| 5203 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5204 | template<typename Derived> |
| 5205 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5206 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5207 | bool WrittenAsLValue, |
| 5208 | SourceLocation Sigil) { |
| 5209 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5210 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5214 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5215 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5216 | QualType ClassType, |
| 5217 | SourceLocation Sigil) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5218 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5219 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | QualType |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5224 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5225 | SourceLocation Sigil) { |
| 5226 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5227 | getDerived().getBaseEntity()); |
| 5228 | } |
| 5229 | |
| 5230 | template<typename Derived> |
| 5231 | QualType |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5232 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5233 | ArrayType::ArraySizeModifier SizeMod, |
| 5234 | const llvm::APInt *Size, |
| 5235 | Expr *SizeExpr, |
| 5236 | unsigned IndexTypeQuals, |
| 5237 | SourceRange BracketsRange) { |
| 5238 | if (SizeExpr || !Size) |
| 5239 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5240 | IndexTypeQuals, BracketsRange, |
| 5241 | getDerived().getBaseEntity()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5242 | |
| 5243 | QualType Types[] = { |
| 5244 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5245 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5246 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5247 | }; |
| 5248 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5249 | QualType SizeType; |
| 5250 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5251 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5252 | SizeType = Types[I]; |
| 5253 | break; |
| 5254 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5255 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5256 | if (SizeType.isNull()) |
| 5257 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5258 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5259 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5260 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5261 | IndexTypeQuals, BracketsRange, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5262 | getDerived().getBaseEntity()); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5263 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5264 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5265 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5266 | QualType |
| 5267 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5268 | ArrayType::ArraySizeModifier SizeMod, |
| 5269 | const llvm::APInt &Size, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5270 | unsigned IndexTypeQuals, |
| 5271 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5272 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5273 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5277 | QualType |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5278 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5279 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5280 | unsigned IndexTypeQuals, |
| 5281 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5282 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5283 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5284 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5285 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5286 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5287 | QualType |
| 5288 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5289 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5290 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5291 | unsigned IndexTypeQuals, |
| 5292 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5293 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5294 | SizeExpr.takeAs<Expr>(), |
| 5295 | IndexTypeQuals, BracketsRange); |
| 5296 | } |
| 5297 | |
| 5298 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5299 | QualType |
| 5300 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5301 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5302 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5303 | unsigned IndexTypeQuals, |
| 5304 | SourceRange BracketsRange) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5306 | SizeExpr.takeAs<Expr>(), |
| 5307 | IndexTypeQuals, BracketsRange); |
| 5308 | } |
| 5309 | |
| 5310 | template<typename Derived> |
| 5311 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5312 | unsigned NumElements) { |
| 5313 | // FIXME: semantic checking! |
| 5314 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5315 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5316 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5317 | template<typename Derived> |
| 5318 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5319 | unsigned NumElements, |
| 5320 | SourceLocation AttributeLoc) { |
| 5321 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5322 | NumElements, true); |
| 5323 | IntegerLiteral *VectorSize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5324 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5325 | AttributeLoc); |
| 5326 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5327 | AttributeLoc); |
| 5328 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5329 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5330 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5331 | QualType |
| 5332 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5333 | ExprArg SizeExpr, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5334 | SourceLocation AttributeLoc) { |
| 5335 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5336 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5337 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5338 | template<typename Derived> |
| 5339 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | QualType *ParamTypes, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5341 | unsigned NumParamTypes, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5342 | bool Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5343 | unsigned Quals) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5344 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5345 | Quals, |
| 5346 | getDerived().getBaseLocation(), |
| 5347 | getDerived().getBaseEntity()); |
| 5348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5349 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5350 | template<typename Derived> |
John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5351 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5352 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5353 | } |
| 5354 | |
| 5355 | template<typename Derived> |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5356 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { |
| 5357 | assert(D && "no decl found"); |
| 5358 | if (D->isInvalidDecl()) return QualType(); |
| 5359 | |
| 5360 | TypeDecl *Ty; |
| 5361 | if (isa<UsingDecl>(D)) { |
| 5362 | UsingDecl *Using = cast<UsingDecl>(D); |
| 5363 | assert(Using->isTypeName() && |
| 5364 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 5365 | |
| 5366 | // A valid resolved using typename decl points to exactly one type decl. |
| 5367 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 5368 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 5369 | |
| 5370 | } else { |
| 5371 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 5372 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 5373 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 5374 | } |
| 5375 | |
| 5376 | return SemaRef.Context.getTypeDeclType(Ty); |
| 5377 | } |
| 5378 | |
| 5379 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5380 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5381 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5382 | } |
| 5383 | |
| 5384 | template<typename Derived> |
| 5385 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5386 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5387 | } |
| 5388 | |
| 5389 | template<typename Derived> |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5390 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5391 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5392 | } |
| 5393 | |
| 5394 | template<typename Derived> |
| 5395 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5396 | TemplateName Template, |
| 5397 | SourceLocation TemplateNameLoc, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5398 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5399 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5400 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5402 | template<typename Derived> |
| 5403 | NestedNameSpecifier * |
| 5404 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5405 | SourceRange Range, |
Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5406 | IdentifierInfo &II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5407 | QualType ObjectType, |
John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5408 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5409 | CXXScopeSpec SS; |
| 5410 | // FIXME: The source location information is all wrong. |
| 5411 | SS.setRange(Range); |
| 5412 | SS.setScopeRep(Prefix); |
| 5413 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | e861bac | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5415 | Range.getEnd(), II, |
Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5416 | ObjectType, |
| 5417 | FirstQualifierInScope, |
Chris Lattner | 1c42803 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 5418 | false, false)); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | template<typename Derived> |
| 5422 | NestedNameSpecifier * |
| 5423 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5424 | SourceRange Range, |
| 5425 | NamespaceDecl *NS) { |
| 5426 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5427 | } |
| 5428 | |
| 5429 | template<typename Derived> |
| 5430 | NestedNameSpecifier * |
| 5431 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5432 | SourceRange Range, |
| 5433 | bool TemplateKW, |
| 5434 | QualType T) { |
| 5435 | if (T->isDependentType() || T->isRecordType() || |
| 5436 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5437 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5438 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5439 | T.getTypePtr()); |
| 5440 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | |
Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5442 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5443 | return 0; |
| 5444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5445 | |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5446 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5447 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5448 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5449 | bool TemplateKW, |
| 5450 | TemplateDecl *Template) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5451 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5452 | Template); |
| 5453 | } |
| 5454 | |
| 5455 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5456 | TemplateName |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5457 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5458 | const IdentifierInfo &II, |
| 5459 | QualType ObjectType) { |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5460 | CXXScopeSpec SS; |
| 5461 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5463 | UnqualifiedId Name; |
| 5464 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5465 | return getSema().ActOnDependentTemplateName( |
| 5466 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5467 | SS, |
Douglas Gregor | 3cf8131 | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5468 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5469 | ObjectType.getAsOpaquePtr(), |
| 5470 | /*EnteringContext=*/false) |
Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5471 | .template getAsVal<TemplateName>(); |
Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5472 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5473 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5474 | template<typename Derived> |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5475 | TemplateName |
| 5476 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5477 | OverloadedOperatorKind Operator, |
| 5478 | QualType ObjectType) { |
| 5479 | CXXScopeSpec SS; |
| 5480 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5481 | SS.setScopeRep(Qualifier); |
| 5482 | UnqualifiedId Name; |
| 5483 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5484 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5485 | Operator, SymbolLocations); |
| 5486 | return getSema().ActOnDependentTemplateName( |
| 5487 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5488 | SS, |
| 5489 | Name, |
Douglas Gregor | ade9bcd | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5490 | ObjectType.getAsOpaquePtr(), |
| 5491 | /*EnteringContext=*/false) |
Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5492 | .template getAsVal<TemplateName>(); |
| 5493 | } |
| 5494 | |
| 5495 | template<typename Derived> |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5496 | Sema::OwningExprResult |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5497 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5498 | SourceLocation OpLoc, |
| 5499 | ExprArg Callee, |
| 5500 | ExprArg First, |
| 5501 | ExprArg Second) { |
| 5502 | Expr *FirstExpr = (Expr *)First.get(); |
| 5503 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5504 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5505 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5506 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5507 | // Determine whether this should be a builtin operation. |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5508 | if (Op == OO_Subscript) { |
| 5509 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5510 | !SecondExpr->getType()->isOverloadableType()) |
| 5511 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5512 | CalleeExpr->getLocStart(), |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5513 | move(Second), OpLoc); |
Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5514 | } else if (Op == OO_Arrow) { |
| 5515 | // -> is never a builtin operation. |
| 5516 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5517 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5518 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5519 | // The argument is not of overloadable type, so try to create a |
| 5520 | // built-in unary operation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5521 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5522 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5523 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5524 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5525 | } |
| 5526 | } else { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5527 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5528 | !SecondExpr->getType()->isOverloadableType()) { |
| 5529 | // Neither of the arguments is an overloadable type, so try to |
| 5530 | // create a built-in binary operation. |
| 5531 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5532 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5533 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5534 | if (Result.isInvalid()) |
| 5535 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5536 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5537 | First.release(); |
| 5538 | Second.release(); |
| 5539 | return move(Result); |
| 5540 | } |
| 5541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | |
| 5543 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5544 | // used during overload resolution. |
| 5545 | Sema::FunctionSet Functions; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5546 | |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5547 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5548 | assert(ULE->requiresADL()); |
| 5549 | |
| 5550 | // FIXME: Do we have to check |
| 5551 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5552 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5553 | E = ULE->decls_end(); I != E; ++I) |
| 5554 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5555 | } else { |
| 5556 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5557 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5558 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5559 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5560 | // Add any functions found via argument-dependent lookup. |
| 5561 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5562 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5563 | DeclarationName OpName |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5564 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | c057f42 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5565 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5566 | Functions); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5567 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5568 | // Create the overloaded operator invocation for unary operators. |
| 5569 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5570 | UnaryOperator::Opcode Opc |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5571 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5572 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5573 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5574 | |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5575 | if (Op == OO_Subscript) |
John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5576 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5577 | OpLoc, |
| 5578 | move(First), |
| 5579 | move(Second)); |
Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5580 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5581 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5582 | BinaryOperator::Opcode Opc = |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5583 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5584 | OwningExprResult Result |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5585 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5586 | if (Result.isInvalid()) |
| 5587 | return SemaRef.ExprError(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5588 | |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5589 | First.release(); |
| 5590 | Second.release(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5591 | return move(Result); |
Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5594 | } // end namespace clang |
| 5595 | |
| 5596 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |