John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/ |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements a semantic tree transformation that takes a given |
| 10 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===/ |
| 13 | #ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "Sema.h" |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 17 | #include "clang/Sema/SemaDiagnostic.h" |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprCXX.h" |
| 21 | #include "clang/AST/ExprObjC.h" |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/Stmt.h" |
| 23 | #include "clang/AST/StmtCXX.h" |
| 24 | #include "clang/AST/StmtObjC.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeLocBuilder.h" |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 26 | #include "clang/Parse/Ownership.h" |
| 27 | #include "clang/Parse/Designator.h" |
| 28 | #include "clang/Lex/Preprocessor.h" |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 30 | #include <algorithm> |
| 31 | |
| 32 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 34 | /// \brief A semantic tree transformation that allows one to transform one |
| 35 | /// abstract syntax tree into another. |
| 36 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 38 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 39 | /// behavior specific to that transformation. For example, template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 40 | /// instantiation is implemented as a tree transformation where the |
| 41 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 42 | /// template arguments for their corresponding template parameters; a similar |
| 43 | /// transformation is performed for non-type template parameters and |
| 44 | /// template template parameters. |
| 45 | /// |
| 46 | /// This tree-transformation template uses static polymorphism to allow |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | /// subclasses to customize any of its operations. Thus, a subclass can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 48 | /// override any of the transformation or rebuild operators by providing an |
| 49 | /// operation with the same signature as the default implementation. The |
| 50 | /// overridding function should not be virtual. |
| 51 | /// |
| 52 | /// Semantic tree transformations are split into two stages, either of which |
| 53 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 54 | /// or the parts of an AST node using the various transformation functions, |
| 55 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 56 | /// node of the appropriate kind from the pieces. The default transformation |
| 57 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 58 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 59 | /// were changed by the transformation, invokes the rebuild operation to create |
| 60 | /// a new AST node. |
| 61 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | /// Subclasses can customize the transformation at various levels. The |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 63 | /// most coarse-grained transformations involve replacing TransformType(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 64 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), |
| 65 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 66 | /// new implementations. |
| 67 | /// |
| 68 | /// For more fine-grained transformations, subclasses can replace any of the |
| 69 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 70 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 71 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | /// to substitute template arguments for their corresponding template |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 73 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 74 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 75 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 76 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 77 | /// be able to use more efficient rebuild steps. |
| 78 | /// |
| 79 | /// There are a handful of other functions that can be overridden, allowing one |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | /// to avoid traversing nodes that don't need any transformation |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 82 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 83 | /// default locations and entity names used for type-checking |
| 84 | /// (\c getBaseLocation(), \c getBaseEntity()). |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 85 | template<typename Derived> |
| 86 | class TreeTransform { |
| 87 | protected: |
| 88 | Sema &SemaRef; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | |
| 90 | public: |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 91 | typedef Sema::OwningStmtResult OwningStmtResult; |
| 92 | typedef Sema::OwningExprResult OwningExprResult; |
| 93 | typedef Sema::StmtArg StmtArg; |
| 94 | typedef Sema::ExprArg ExprArg; |
| 95 | typedef Sema::MultiExprArg MultiExprArg; |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 96 | typedef Sema::MultiStmtArg MultiStmtArg; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 98 | /// \brief Initializes a new tree transformer. |
| 99 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 101 | /// \brief Retrieves a reference to the derived class. |
| 102 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 103 | |
| 104 | /// \brief Retrieves a reference to the derived class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | const Derived &getDerived() const { |
| 106 | return static_cast<const Derived&>(*this); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /// \brief Retrieves a reference to the semantic analysis object used for |
| 110 | /// this tree transform. |
| 111 | Sema &getSema() const { return SemaRef; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | /// \brief Whether the transformation should always rebuild AST nodes, even |
| 114 | /// if none of the children have changed. |
| 115 | /// |
| 116 | /// Subclasses may override this function to specify when the transformation |
| 117 | /// should rebuild all AST nodes. |
| 118 | bool AlwaysRebuild() { return false; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 120 | /// \brief Returns the location of the entity being transformed, if that |
| 121 | /// information was not available elsewhere in the AST. |
| 122 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | /// By default, returns no source-location information. Subclasses can |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 124 | /// provide an alternative implementation that provides better location |
| 125 | /// information. |
| 126 | SourceLocation getBaseLocation() { return SourceLocation(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 128 | /// \brief Returns the name of the entity being transformed, if that |
| 129 | /// information was not available elsewhere in the AST. |
| 130 | /// |
| 131 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 132 | /// implementation with a more precise name. |
| 133 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 135 | /// \brief Sets the "base" location and entity when that |
| 136 | /// information is known based on another transformation. |
| 137 | /// |
| 138 | /// By default, the source location and entity are ignored. Subclasses can |
| 139 | /// override this function to provide a customized implementation. |
| 140 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 142 | /// \brief RAII object that temporarily sets the base location and entity |
| 143 | /// used for reporting diagnostics in types. |
| 144 | class TemporaryBase { |
| 145 | TreeTransform &Self; |
| 146 | SourceLocation OldLocation; |
| 147 | DeclarationName OldEntity; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 149 | public: |
| 150 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | DeclarationName Entity) : Self(Self) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 152 | OldLocation = Self.getDerived().getBaseLocation(); |
| 153 | OldEntity = Self.getDerived().getBaseEntity(); |
| 154 | Self.getDerived().setBase(Location, Entity); |
| 155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 157 | ~TemporaryBase() { |
| 158 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 159 | } |
| 160 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
| 162 | /// \brief Determine whether the given type \p T has already been |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 163 | /// transformed. |
| 164 | /// |
| 165 | /// Subclasses can provide an alternative implementation of this routine |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | /// to short-circuit evaluation when it is known that a given type will |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 167 | /// not change. For example, template instantiation need not traverse |
| 168 | /// non-dependent types. |
| 169 | bool AlreadyTransformed(QualType T) { |
| 170 | return T.isNull(); |
| 171 | } |
| 172 | |
| 173 | /// \brief Transforms the given type into another type. |
| 174 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 175 | /// By default, this routine transforms a type by creating a |
| 176 | /// DeclaratorInfo for it and delegating to the appropriate |
| 177 | /// function. This is expensive, but we don't mind, because |
| 178 | /// this method is deprecated anyway; all users should be |
| 179 | /// switched to storing DeclaratorInfos. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 180 | /// |
| 181 | /// \returns the transformed type. |
| 182 | QualType TransformType(QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 184 | /// \brief Transforms the given type-with-location into a new |
| 185 | /// type-with-location. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 186 | /// |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 187 | /// By default, this routine transforms a type by delegating to the |
| 188 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 189 | /// may override this function (to take over all type |
| 190 | /// transformations) or some set of the TransformXXXType functions |
| 191 | /// to alter the transformation. |
| 192 | DeclaratorInfo *TransformType(DeclaratorInfo *DI); |
| 193 | |
| 194 | /// \brief Transform the given type-with-location into a new |
| 195 | /// type, collecting location information in the given builder |
| 196 | /// as necessary. |
| 197 | /// |
| 198 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 200 | /// \brief Transform the given statement. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 201 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | /// By default, this routine transforms a statement by delegating to the |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 203 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 204 | /// statement or the TransformExpr() function to transform an expression. |
| 205 | /// Subclasses may override this function to transform statements using some |
| 206 | /// other mechanism. |
| 207 | /// |
| 208 | /// \returns the transformed statement. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 209 | OwningStmtResult TransformStmt(Stmt *S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 211 | /// \brief Transform the given expression. |
| 212 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 213 | /// By default, this routine transforms an expression by delegating to the |
| 214 | /// appropriate TransformXXXExpr function to build a new expression. |
| 215 | /// Subclasses may override this function to transform expressions using some |
| 216 | /// other mechanism. |
| 217 | /// |
| 218 | /// \returns the transformed expression. |
| 219 | OwningExprResult TransformExpr(Expr *E) { |
| 220 | return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false); |
| 221 | } |
| 222 | |
| 223 | /// \brief Transform the given expression. |
| 224 | /// |
| 225 | /// By default, this routine transforms an expression by delegating to the |
| 226 | /// appropriate TransformXXXExpr function to build a new expression. |
| 227 | /// Subclasses may override this function to transform expressions using some |
| 228 | /// other mechanism. |
| 229 | /// |
| 230 | /// \returns the transformed expression. |
| 231 | OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 233 | /// \brief Transform the given declaration, which is referenced from a type |
| 234 | /// or expression. |
| 235 | /// |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 236 | /// By default, acts as the identity function on declarations. Subclasses |
| 237 | /// may override this function to provide alternate behavior. |
| 238 | Decl *TransformDecl(Decl *D) { return D; } |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 239 | |
| 240 | /// \brief Transform the definition of the given declaration. |
| 241 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | /// By default, invokes TransformDecl() to transform the declaration. |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 243 | /// Subclasses may override this function to provide alternate behavior. |
| 244 | Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 246 | /// \brief Transform the given declaration, which was the first part of a |
| 247 | /// nested-name-specifier in a member access expression. |
| 248 | /// |
| 249 | /// This specific declaration transformation only applies to the first |
| 250 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 251 | /// the \c T in \c x->T::member |
| 252 | /// |
| 253 | /// By default, invokes TransformDecl() to transform the declaration. |
| 254 | /// Subclasses may override this function to provide alternate behavior. |
| 255 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 256 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(D)); |
| 257 | } |
| 258 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 259 | /// \brief Transform the given nested-name-specifier. |
| 260 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | /// By default, transforms all of the types and declarations within the |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 262 | /// nested-name-specifier. Subclasses may override this function to provide |
| 263 | /// alternate behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 264 | NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 265 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 266 | QualType ObjectType = QualType(), |
| 267 | NamedDecl *FirstQualifierInScope = 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 269 | /// \brief Transform the given declaration name. |
| 270 | /// |
| 271 | /// By default, transforms the types of conversion function, constructor, |
| 272 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 273 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 274 | /// override this function to provide alternate behavior. |
| 275 | DeclarationName TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 276 | SourceLocation Loc, |
| 277 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 279 | /// \brief Transform the given template name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | /// |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 281 | /// By default, transforms the template name by transforming the declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | /// and nested-name-specifiers that occur within the template name. |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 283 | /// Subclasses may override this function to provide alternate behavior. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 284 | TemplateName TransformTemplateName(TemplateName Name, |
| 285 | QualType ObjectType = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 287 | /// \brief Transform the given template argument. |
| 288 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | /// By default, this operation transforms the type, expression, or |
| 290 | /// declaration stored within the template argument and constructs a |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 291 | /// new template argument from the transformed result. Subclasses may |
| 292 | /// override this function to provide alternate behavior. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 293 | /// |
| 294 | /// Returns true if there was an error. |
| 295 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 296 | TemplateArgumentLoc &Output); |
| 297 | |
| 298 | /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 299 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 300 | TemplateArgumentLoc &ArgLoc); |
| 301 | |
| 302 | /// \brief Fakes up a DeclaratorInfo for a type. |
| 303 | DeclaratorInfo *InventDeclaratorInfo(QualType T) { |
| 304 | return SemaRef.Context.getTrivialDeclaratorInfo(T, |
| 305 | getDerived().getBaseLocation()); |
| 306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 309 | #define TYPELOC(CLASS, PARENT) \ |
| 310 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 311 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 312 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 313 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 314 | |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 315 | QualType |
| 316 | TransformTemplateSpecializationType(const TemplateSpecializationType *T, |
| 317 | QualType ObjectType); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 318 | |
| 319 | QualType |
| 320 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 321 | TemplateSpecializationTypeLoc TL, |
| 322 | QualType ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 324 | OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 326 | #define STMT(Node, Parent) \ |
| 327 | OwningStmtResult Transform##Node(Node *S); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 328 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 329 | OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 330 | #define ABSTRACT_EXPR(Node, Parent) |
| 331 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 333 | /// \brief Build a new pointer type given its pointee type. |
| 334 | /// |
| 335 | /// By default, performs semantic analysis when building the pointer type. |
| 336 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 337 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | |
| 339 | /// \brief Build a new block pointer type given its pointee type. |
| 340 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 341 | /// By default, performs semantic analysis when building the block pointer |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 342 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 343 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 344 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 345 | /// \brief Build a new reference type given the type it references. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 346 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 347 | /// By default, performs semantic analysis when building the |
| 348 | /// reference type. Subclasses may override this routine to provide |
| 349 | /// different behavior. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 350 | /// |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 351 | /// \param LValue whether the type was written with an lvalue sigil |
| 352 | /// or an rvalue sigil. |
| 353 | QualType RebuildReferenceType(QualType ReferentType, |
| 354 | bool LValue, |
| 355 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 357 | /// \brief Build a new member pointer type given the pointee type and the |
| 358 | /// class type it refers into. |
| 359 | /// |
| 360 | /// By default, performs semantic analysis when building the member pointer |
| 361 | /// type. Subclasses may override this routine to provide different behavior. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 362 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 363 | SourceLocation Sigil); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 365 | /// \brief Build a new Objective C object pointer type. |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 366 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 367 | SourceLocation Sigil); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 369 | /// \brief Build a new array type given the element type, size |
| 370 | /// modifier, size of the array (if known), size expression, and index type |
| 371 | /// qualifiers. |
| 372 | /// |
| 373 | /// By default, performs semantic analysis when building the array type. |
| 374 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | /// Also by default, all of the other Rebuild*Array |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 376 | QualType RebuildArrayType(QualType ElementType, |
| 377 | ArrayType::ArraySizeModifier SizeMod, |
| 378 | const llvm::APInt *Size, |
| 379 | Expr *SizeExpr, |
| 380 | unsigned IndexTypeQuals, |
| 381 | SourceRange BracketsRange); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 383 | /// \brief Build a new constant array type given the element type, size |
| 384 | /// modifier, (known) size of the array, and index type qualifiers. |
| 385 | /// |
| 386 | /// By default, performs semantic analysis when building the array type. |
| 387 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | QualType RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 389 | ArrayType::ArraySizeModifier SizeMod, |
| 390 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 391 | unsigned IndexTypeQuals, |
| 392 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 393 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 394 | /// \brief Build a new incomplete array type given the element type, size |
| 395 | /// modifier, and index type qualifiers. |
| 396 | /// |
| 397 | /// By default, performs semantic analysis when building the array type. |
| 398 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | QualType RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 400 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 401 | unsigned IndexTypeQuals, |
| 402 | SourceRange BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 403 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | /// \brief Build a new variable-length array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 405 | /// size modifier, size expression, and index type qualifiers. |
| 406 | /// |
| 407 | /// By default, performs semantic analysis when building the array type. |
| 408 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | QualType RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 410 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 411 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 412 | unsigned IndexTypeQuals, |
| 413 | SourceRange BracketsRange); |
| 414 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | /// \brief Build a new dependent-sized array type given the element type, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 416 | /// size modifier, size expression, and index type qualifiers. |
| 417 | /// |
| 418 | /// By default, performs semantic analysis when building the array type. |
| 419 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 420 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 421 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 422 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 423 | unsigned IndexTypeQuals, |
| 424 | SourceRange BracketsRange); |
| 425 | |
| 426 | /// \brief Build a new vector type given the element type and |
| 427 | /// number of elements. |
| 428 | /// |
| 429 | /// By default, performs semantic analysis when building the vector type. |
| 430 | /// Subclasses may override this routine to provide different behavior. |
| 431 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 433 | /// \brief Build a new extended vector type given the element type and |
| 434 | /// number of elements. |
| 435 | /// |
| 436 | /// By default, performs semantic analysis when building the vector type. |
| 437 | /// Subclasses may override this routine to provide different behavior. |
| 438 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 439 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Build a new potentially dependently-sized extended vector type |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 442 | /// given the element type and number of elements. |
| 443 | /// |
| 444 | /// By default, performs semantic analysis when building the vector type. |
| 445 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 447 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 448 | SourceLocation AttributeLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 450 | /// \brief Build a new function type. |
| 451 | /// |
| 452 | /// By default, performs semantic analysis when building the function type. |
| 453 | /// Subclasses may override this routine to provide different behavior. |
| 454 | QualType RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 456 | unsigned NumParamTypes, |
| 457 | bool Variadic, unsigned Quals); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 459 | /// \brief Build a new unprototyped function type. |
| 460 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 461 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 462 | /// \brief Build a new typedef type. |
| 463 | QualType RebuildTypedefType(TypedefDecl *Typedef) { |
| 464 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 465 | } |
| 466 | |
| 467 | /// \brief Build a new class/struct/union type. |
| 468 | QualType RebuildRecordType(RecordDecl *Record) { |
| 469 | return SemaRef.Context.getTypeDeclType(Record); |
| 470 | } |
| 471 | |
| 472 | /// \brief Build a new Enum type. |
| 473 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 474 | return SemaRef.Context.getTypeDeclType(Enum); |
| 475 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 476 | |
| 477 | /// \brief Build a new elaborated type. |
| 478 | QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) { |
| 479 | return SemaRef.Context.getElaboratedType(T, Tag); |
| 480 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 481 | |
| 482 | /// \brief Build a new typeof(expr) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 483 | /// |
| 484 | /// By default, performs semantic analysis when building the typeof type. |
| 485 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 486 | QualType RebuildTypeOfExprType(ExprArg Underlying); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 487 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | /// \brief Build a new typeof(type) type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 489 | /// |
| 490 | /// By default, builds a new TypeOfType with the given underlying type. |
| 491 | QualType RebuildTypeOfType(QualType Underlying); |
| 492 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | /// \brief Build a new C++0x decltype type. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// By default, performs semantic analysis when building the decltype type. |
| 496 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 497 | QualType RebuildDecltypeType(ExprArg Underlying); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 499 | /// \brief Build a new template specialization type. |
| 500 | /// |
| 501 | /// By default, performs semantic analysis when building the template |
| 502 | /// specialization type. Subclasses may override this routine to provide |
| 503 | /// different behavior. |
| 504 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 505 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 506 | const TemplateArgumentListInfo &Args); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 508 | /// \brief Build a new qualified name type. |
| 509 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | /// By default, builds a new QualifiedNameType type from the |
| 511 | /// nested-name-specifier and the named type. Subclasses may override |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 512 | /// this routine to provide different behavior. |
| 513 | QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) { |
| 514 | return SemaRef.Context.getQualifiedNameType(NNS, Named); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 516 | |
| 517 | /// \brief Build a new typename type that refers to a template-id. |
| 518 | /// |
| 519 | /// By default, builds a new TypenameType type from the nested-name-specifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | /// and the given type. Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 521 | /// different behavior. |
| 522 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) { |
| 523 | if (NNS->isDependent()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | return SemaRef.Context.getTypenameType(NNS, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 525 | cast<TemplateSpecializationType>(T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 526 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 527 | return SemaRef.Context.getQualifiedNameType(NNS, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 529 | |
| 530 | /// \brief Build a new typename type that refers to an identifier. |
| 531 | /// |
| 532 | /// By default, performs semantic analysis when building the typename type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | /// (or qualified name type). Subclasses may override this routine to provide |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 534 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | QualType RebuildTypenameType(NestedNameSpecifier *NNS, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 536 | const IdentifierInfo *Id, |
| 537 | SourceRange SR) { |
| 538 | return SemaRef.CheckTypenameType(NNS, *Id, SR); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 539 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 541 | /// \brief Build a new nested-name-specifier given the prefix and an |
| 542 | /// identifier that names the next step in the nested-name-specifier. |
| 543 | /// |
| 544 | /// By default, performs semantic analysis when building the new |
| 545 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 546 | /// different behavior. |
| 547 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 548 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 549 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 550 | QualType ObjectType, |
| 551 | NamedDecl *FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 552 | |
| 553 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 554 | /// namespace named in the next step in the nested-name-specifier. |
| 555 | /// |
| 556 | /// By default, performs semantic analysis when building the new |
| 557 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 558 | /// different behavior. |
| 559 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 560 | SourceRange Range, |
| 561 | NamespaceDecl *NS); |
| 562 | |
| 563 | /// \brief Build a new nested-name-specifier given the prefix and the |
| 564 | /// type named in the next step in the nested-name-specifier. |
| 565 | /// |
| 566 | /// By default, performs semantic analysis when building the new |
| 567 | /// nested-name-specifier. Subclasses may override this routine to provide |
| 568 | /// different behavior. |
| 569 | NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 570 | SourceRange Range, |
| 571 | bool TemplateKW, |
| 572 | QualType T); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 573 | |
| 574 | /// \brief Build a new template name given a nested name specifier, a flag |
| 575 | /// indicating whether the "template" keyword was provided, and the template |
| 576 | /// that the template name refers to. |
| 577 | /// |
| 578 | /// By default, builds the new template name directly. Subclasses may override |
| 579 | /// this routine to provide different behavior. |
| 580 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 581 | bool TemplateKW, |
| 582 | TemplateDecl *Template); |
| 583 | |
| 584 | /// \brief Build a new template name given a nested name specifier, a flag |
| 585 | /// indicating whether the "template" keyword was provided, and a set of |
| 586 | /// overloaded function templates. |
| 587 | /// |
| 588 | /// By default, builds the new template name directly. Subclasses may override |
| 589 | /// this routine to provide different behavior. |
| 590 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 591 | bool TemplateKW, |
| 592 | OverloadedFunctionDecl *Ovl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 594 | /// \brief Build a new template name given a nested name specifier and the |
| 595 | /// name that is referred to as a template. |
| 596 | /// |
| 597 | /// By default, performs semantic analysis to determine whether the name can |
| 598 | /// be resolved to a specific template, then builds the appropriate kind of |
| 599 | /// template name. Subclasses may override this routine to provide different |
| 600 | /// behavior. |
| 601 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 602 | const IdentifierInfo &II, |
| 603 | QualType ObjectType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 605 | /// \brief Build a new template name given a nested name specifier and the |
| 606 | /// overloaded operator name that is referred to as a template. |
| 607 | /// |
| 608 | /// By default, performs semantic analysis to determine whether the name can |
| 609 | /// be resolved to a specific template, then builds the appropriate kind of |
| 610 | /// template name. Subclasses may override this routine to provide different |
| 611 | /// behavior. |
| 612 | TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 613 | OverloadedOperatorKind Operator, |
| 614 | QualType ObjectType); |
| 615 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 616 | /// \brief Build a new compound statement. |
| 617 | /// |
| 618 | /// By default, performs semantic analysis to build the new statement. |
| 619 | /// Subclasses may override this routine to provide different behavior. |
| 620 | OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 621 | MultiStmtArg Statements, |
| 622 | SourceLocation RBraceLoc, |
| 623 | bool IsStmtExpr) { |
| 624 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), |
| 625 | IsStmtExpr); |
| 626 | } |
| 627 | |
| 628 | /// \brief Build a new case statement. |
| 629 | /// |
| 630 | /// By default, performs semantic analysis to build the new statement. |
| 631 | /// Subclasses may override this routine to provide different behavior. |
| 632 | OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 633 | ExprArg LHS, |
| 634 | SourceLocation EllipsisLoc, |
| 635 | ExprArg RHS, |
| 636 | SourceLocation ColonLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 637 | return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 638 | ColonLoc); |
| 639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 641 | /// \brief Attach the body to a new case statement. |
| 642 | /// |
| 643 | /// By default, performs semantic analysis to build the new statement. |
| 644 | /// Subclasses may override this routine to provide different behavior. |
| 645 | OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { |
| 646 | getSema().ActOnCaseStmtBody(S.get(), move(Body)); |
| 647 | return move(S); |
| 648 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 650 | /// \brief Build a new default statement. |
| 651 | /// |
| 652 | /// By default, performs semantic analysis to build the new statement. |
| 653 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 654 | OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 655 | SourceLocation ColonLoc, |
| 656 | StmtArg SubStmt) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 658 | /*CurScope=*/0); |
| 659 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 661 | /// \brief Build a new label statement. |
| 662 | /// |
| 663 | /// By default, performs semantic analysis to build the new statement. |
| 664 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 666 | IdentifierInfo *Id, |
| 667 | SourceLocation ColonLoc, |
| 668 | StmtArg SubStmt) { |
| 669 | return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); |
| 670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 672 | /// \brief Build a new "if" statement. |
| 673 | /// |
| 674 | /// By default, performs semantic analysis to build the new statement. |
| 675 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, |
| 677 | StmtArg Then, SourceLocation ElseLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 678 | StmtArg Else) { |
| 679 | return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else)); |
| 680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 682 | /// \brief Start building a new switch statement. |
| 683 | /// |
| 684 | /// By default, performs semantic analysis to build the new statement. |
| 685 | /// Subclasses may override this routine to provide different behavior. |
| 686 | OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) { |
| 687 | return getSema().ActOnStartOfSwitchStmt(move(Cond)); |
| 688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 690 | /// \brief Attach the body to the switch statement. |
| 691 | /// |
| 692 | /// By default, performs semantic analysis to build the new statement. |
| 693 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 695 | StmtArg Switch, StmtArg Body) { |
| 696 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), |
| 697 | move(Body)); |
| 698 | } |
| 699 | |
| 700 | /// \brief Build a new while statement. |
| 701 | /// |
| 702 | /// By default, performs semantic analysis to build the new statement. |
| 703 | /// Subclasses may override this routine to provide different behavior. |
| 704 | OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 705 | Sema::FullExprArg Cond, |
| 706 | StmtArg Body) { |
| 707 | return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body)); |
| 708 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 709 | |
Douglas Gregor | 43959a9 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, |
Douglas Gregor | 43959a9 | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | OwningStmtResult RebuildForStmt(SourceLocation ForLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 728 | SourceLocation LParenLoc, |
| 729 | StmtArg Init, ExprArg Cond, ExprArg Inc, |
| 730 | SourceLocation RParenLoc, StmtArg Body) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 732 | move(Inc), RParenLoc, move(Body)); |
| 733 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 735 | /// \brief Build a new goto statement. |
| 736 | /// |
| 737 | /// By default, performs semantic analysis to build the new statement. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
| 739 | OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc, |
| 740 | SourceLocation LabelLoc, |
| 741 | LabelStmt *Label) { |
| 742 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); |
| 743 | } |
| 744 | |
| 745 | /// \brief Build a new indirect goto statement. |
| 746 | /// |
| 747 | /// By default, performs semantic analysis to build the new statement. |
| 748 | /// Subclasses may override this routine to provide different behavior. |
| 749 | OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 750 | SourceLocation StarLoc, |
| 751 | ExprArg Target) { |
| 752 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); |
| 753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 755 | /// \brief Build a new return statement. |
| 756 | /// |
| 757 | /// By default, performs semantic analysis to build the new statement. |
| 758 | /// Subclasses may override this routine to provide different behavior. |
| 759 | OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, |
| 760 | ExprArg Result) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 762 | return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); |
| 763 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 765 | /// \brief Build a new declaration statement. |
| 766 | /// |
| 767 | /// By default, performs semantic analysis to build the new statement. |
| 768 | /// Subclasses may override this routine to provide different behavior. |
| 769 | OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | SourceLocation StartLoc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 771 | SourceLocation EndLoc) { |
| 772 | return getSema().Owned( |
| 773 | new (getSema().Context) DeclStmt( |
| 774 | DeclGroupRef::Create(getSema().Context, |
| 775 | Decls, NumDecls), |
| 776 | StartLoc, EndLoc)); |
| 777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 779 | /// \brief Build a new C++ exception declaration. |
| 780 | /// |
| 781 | /// By default, performs semantic analysis to build the new decaration. |
| 782 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 784 | DeclaratorInfo *Declarator, |
| 785 | IdentifierInfo *Name, |
| 786 | SourceLocation Loc, |
| 787 | SourceRange TypeRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 788 | return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 789 | TypeRange); |
| 790 | } |
| 791 | |
| 792 | /// \brief Build a new C++ catch statement. |
| 793 | /// |
| 794 | /// By default, performs semantic analysis to build the new statement. |
| 795 | /// Subclasses may override this routine to provide different behavior. |
| 796 | OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 797 | VarDecl *ExceptionDecl, |
| 798 | StmtArg Handler) { |
| 799 | return getSema().Owned( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 801 | Handler.takeAs<Stmt>())); |
| 802 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 804 | /// \brief Build a new C++ try statement. |
| 805 | /// |
| 806 | /// By default, performs semantic analysis to build the new statement. |
| 807 | /// Subclasses may override this routine to provide different behavior. |
| 808 | OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, |
| 809 | StmtArg TryBlock, |
| 810 | MultiStmtArg Handlers) { |
| 811 | return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); |
| 812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 814 | /// \brief Build a new expression that references a declaration. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis to build the new expression. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 818 | OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, |
| 819 | SourceRange QualifierRange, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 820 | NamedDecl *ND, SourceLocation Loc, |
| 821 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 822 | CXXScopeSpec SS; |
| 823 | SS.setScopeRep(Qualifier); |
| 824 | SS.setRange(QualifierRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 825 | return getSema().BuildDeclarationNameExpr(Loc, ND, |
| 826 | /*FIXME:*/false, |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 827 | &SS, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 828 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 831 | /// \brief Build a new expression in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 833 | /// By default, performs semantic analysis to build the new expression. |
| 834 | /// Subclasses may override this routine to provide different behavior. |
| 835 | OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, |
| 836 | SourceLocation RParen) { |
| 837 | return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); |
| 838 | } |
| 839 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 840 | /// \brief Build a new pseudo-destructor expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | /// |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 842 | /// By default, performs semantic analysis to build the new expression. |
| 843 | /// Subclasses may override this routine to provide different behavior. |
| 844 | OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, |
| 845 | SourceLocation OperatorLoc, |
| 846 | bool isArrow, |
| 847 | SourceLocation DestroyedTypeLoc, |
| 848 | QualType DestroyedType, |
| 849 | NestedNameSpecifier *Qualifier, |
| 850 | SourceRange QualifierRange) { |
| 851 | CXXScopeSpec SS; |
| 852 | if (Qualifier) { |
| 853 | SS.setRange(QualifierRange); |
| 854 | SS.setScopeRep(Qualifier); |
| 855 | } |
| 856 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | DeclarationName Name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 858 | = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 859 | SemaRef.Context.getCanonicalType(DestroyedType)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
| 861 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 862 | OperatorLoc, |
| 863 | isArrow? tok::arrow : tok::period, |
| 864 | DestroyedTypeLoc, |
| 865 | Name, |
| 866 | Sema::DeclPtrTy::make((Decl *)0), |
| 867 | &SS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 870 | /// \brief Build a new unary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 871 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 872 | /// By default, performs semantic analysis to build the new expression. |
| 873 | /// Subclasses may override this routine to provide different behavior. |
| 874 | OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 875 | UnaryOperator::Opcode Opc, |
| 876 | ExprArg SubExpr) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 877 | return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 878 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 880 | /// \brief Build a new sizeof or alignof expression with a type argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 881 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 882 | /// By default, performs semantic analysis to build the new expression. |
| 883 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 884 | OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo, |
| 885 | SourceLocation OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 886 | bool isSizeOf, SourceRange R) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 887 | return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | /// \brief Build a new sizeof or alignof expression with an expression |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 891 | /// argument. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 893 | /// By default, performs semantic analysis to build the new expression. |
| 894 | /// Subclasses may override this routine to provide different behavior. |
| 895 | OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, |
| 896 | bool isSizeOf, SourceRange R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 898 | = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), |
| 899 | OpLoc, isSizeOf, R); |
| 900 | if (Result.isInvalid()) |
| 901 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 903 | SubExpr.release(); |
| 904 | return move(Result); |
| 905 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 906 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 907 | /// \brief Build a new array subscript expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 909 | /// By default, performs semantic analysis to build the new expression. |
| 910 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 912 | SourceLocation LBracketLoc, |
| 913 | ExprArg RHS, |
| 914 | SourceLocation RBracketLoc) { |
| 915 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | LBracketLoc, move(RHS), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 917 | RBracketLoc); |
| 918 | } |
| 919 | |
| 920 | /// \brief Build a new call expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | /// |
Douglas Gregor | b98b199 | 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. |
| 924 | OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, |
| 925 | MultiExprArg Args, |
| 926 | SourceLocation *CommaLocs, |
| 927 | SourceLocation RParenLoc) { |
| 928 | return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, |
| 929 | move(Args), CommaLocs, RParenLoc); |
| 930 | } |
| 931 | |
| 932 | /// \brief Build a new member access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 933 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 934 | /// By default, performs semantic analysis to build the new expression. |
| 935 | /// Subclasses may override this routine to provide different behavior. |
| 936 | OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | bool isArrow, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 938 | NestedNameSpecifier *Qualifier, |
| 939 | SourceRange QualifierRange, |
| 940 | SourceLocation MemberLoc, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 941 | NamedDecl *Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 942 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 943 | NamedDecl *FirstQualifierInScope) { |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 944 | if (!Member->getDeclName()) { |
| 945 | // We have a reference to an unnamed field. |
| 946 | assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 947 | |
| 948 | MemberExpr *ME = |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 949 | new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow, |
| 950 | Member, MemberLoc, |
| 951 | cast<FieldDecl>(Member)->getType()); |
| 952 | return getSema().Owned(ME); |
| 953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 955 | CXXScopeSpec SS; |
| 956 | if (Qualifier) { |
| 957 | SS.setRange(QualifierRange); |
| 958 | SS.setScopeRep(Qualifier); |
| 959 | } |
| 960 | |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 961 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 962 | isArrow? tok::arrow : tok::period, |
| 963 | MemberLoc, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 964 | Member->getDeclName(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 965 | ExplicitTemplateArgs, |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 966 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 967 | &SS, |
| 968 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 969 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 970 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 971 | /// \brief Build a new binary operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 973 | /// By default, performs semantic analysis to build the new expression. |
| 974 | /// Subclasses may override this routine to provide different behavior. |
| 975 | OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 976 | BinaryOperator::Opcode Opc, |
| 977 | ExprArg LHS, ExprArg RHS) { |
Douglas Gregor | 6ca7cfb | 2009-11-05 00:51:44 +0000 | [diff] [blame] | 978 | return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, |
| 979 | LHS.takeAs<Expr>(), RHS.takeAs<Expr>()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /// \brief Build a new conditional operator expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 984 | /// By default, performs semantic analysis to build the new expression. |
| 985 | /// Subclasses may override this routine to provide different behavior. |
| 986 | OwningExprResult RebuildConditionalOperator(ExprArg Cond, |
| 987 | SourceLocation QuestionLoc, |
| 988 | ExprArg LHS, |
| 989 | SourceLocation ColonLoc, |
| 990 | ExprArg RHS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 992 | move(LHS), move(RHS)); |
| 993 | } |
| 994 | |
| 995 | /// \brief Build a new implicit cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 997 | /// By default, builds a new implicit cast without any semantic analysis. |
| 998 | /// Subclasses may override this routine to provide different behavior. |
| 999 | OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind, |
| 1000 | ExprArg SubExpr, bool isLvalue) { |
| 1001 | ImplicitCastExpr *ICE |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | = new (getSema().Context) ImplicitCastExpr(T, Kind, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1003 | (Expr *)SubExpr.release(), |
| 1004 | isLvalue); |
| 1005 | return getSema().Owned(ICE); |
| 1006 | } |
| 1007 | |
| 1008 | /// \brief Build a new C-style cast expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1010 | /// By default, performs semantic analysis to build the new expression. |
| 1011 | /// Subclasses may override this routine to provide different behavior. |
| 1012 | OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc, |
| 1013 | QualType ExplicitTy, |
| 1014 | SourceLocation RParenLoc, |
| 1015 | ExprArg SubExpr) { |
| 1016 | return getSema().ActOnCastExpr(/*Scope=*/0, |
| 1017 | LParenLoc, |
| 1018 | ExplicitTy.getAsOpaquePtr(), |
| 1019 | RParenLoc, |
| 1020 | move(SubExpr)); |
| 1021 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1023 | /// \brief Build a new compound literal expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1025 | /// By default, performs semantic analysis to build the new expression. |
| 1026 | /// Subclasses may override this routine to provide different behavior. |
| 1027 | OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 1028 | QualType T, |
| 1029 | SourceLocation RParenLoc, |
| 1030 | ExprArg Init) { |
| 1031 | return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(), |
| 1032 | RParenLoc, move(Init)); |
| 1033 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1035 | /// \brief Build a new extended vector element access expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1037 | /// By default, performs semantic analysis to build the new expression. |
| 1038 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1040 | SourceLocation OpLoc, |
| 1041 | SourceLocation AccessorLoc, |
| 1042 | IdentifierInfo &Accessor) { |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1043 | return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1044 | tok::period, AccessorLoc, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1045 | DeclarationName(&Accessor), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1046 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0)); |
| 1047 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1049 | /// \brief Build a new initializer list expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1051 | /// By default, performs semantic analysis to build the new expression. |
| 1052 | /// Subclasses may override this routine to provide different behavior. |
| 1053 | OwningExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 1054 | MultiExprArg Inits, |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 1055 | SourceLocation RBraceLoc, |
| 1056 | QualType ResultTy) { |
| 1057 | OwningExprResult Result |
| 1058 | = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); |
| 1059 | if (Result.isInvalid() || ResultTy->isDependentType()) |
| 1060 | return move(Result); |
| 1061 | |
| 1062 | // Patch in the result type we were given, which may have been computed |
| 1063 | // when the initial InitListExpr was built. |
| 1064 | InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); |
| 1065 | ILE->setType(ResultTy); |
| 1066 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1069 | /// \brief Build a new designated initializer expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1071 | /// By default, performs semantic analysis to build the new expression. |
| 1072 | /// Subclasses may override this routine to provide different behavior. |
| 1073 | OwningExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 1074 | MultiExprArg ArrayExprs, |
| 1075 | SourceLocation EqualOrColonLoc, |
| 1076 | bool GNUSyntax, |
| 1077 | ExprArg Init) { |
| 1078 | OwningExprResult Result |
| 1079 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 1080 | move(Init)); |
| 1081 | if (Result.isInvalid()) |
| 1082 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1084 | ArrayExprs.release(); |
| 1085 | return move(Result); |
| 1086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1088 | /// \brief Build a new value-initialized expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1089 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1090 | /// By default, builds the implicit value initialization without performing |
| 1091 | /// any semantic analysis. Subclasses may override this routine to provide |
| 1092 | /// different behavior. |
| 1093 | OwningExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 1094 | return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); |
| 1095 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1097 | /// \brief Build a new \c va_arg expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1099 | /// By default, performs semantic analysis to build the new expression. |
| 1100 | /// Subclasses may override this routine to provide different behavior. |
| 1101 | OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr, |
| 1102 | QualType T, SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1104 | RParenLoc); |
| 1105 | } |
| 1106 | |
| 1107 | /// \brief Build a new expression list in parentheses. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1108 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1109 | /// By default, performs semantic analysis to build the new expression. |
| 1110 | /// Subclasses may override this routine to provide different behavior. |
| 1111 | OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 1112 | MultiExprArg SubExprs, |
| 1113 | SourceLocation RParenLoc) { |
| 1114 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); |
| 1115 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1117 | /// \brief Build a new address-of-label expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | /// |
| 1119 | /// By default, performs semantic analysis, using the name of the label |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1120 | /// rather than attempting to map the label statement itself. |
| 1121 | /// Subclasses may override this routine to provide different behavior. |
| 1122 | OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 1123 | SourceLocation LabelLoc, |
| 1124 | LabelStmt *Label) { |
| 1125 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); |
| 1126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1128 | /// \brief Build a new GNU statement expression. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1129 | /// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1130 | /// By default, performs semantic analysis to build the new expression. |
| 1131 | /// Subclasses may override this routine to provide different behavior. |
| 1132 | OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| 1133 | StmtArg SubStmt, |
| 1134 | SourceLocation RParenLoc) { |
| 1135 | return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); |
| 1136 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1138 | /// \brief Build a new __builtin_types_compatible_p expression. |
| 1139 | /// |
| 1140 | /// By default, performs semantic analysis to build the new expression. |
| 1141 | /// Subclasses may override this routine to provide different behavior. |
| 1142 | OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc, |
| 1143 | QualType T1, QualType T2, |
| 1144 | SourceLocation RParenLoc) { |
| 1145 | return getSema().ActOnTypesCompatibleExpr(BuiltinLoc, |
| 1146 | T1.getAsOpaquePtr(), |
| 1147 | T2.getAsOpaquePtr(), |
| 1148 | RParenLoc); |
| 1149 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1151 | /// \brief Build a new __builtin_choose_expr expression. |
| 1152 | /// |
| 1153 | /// By default, performs semantic analysis to build the new expression. |
| 1154 | /// Subclasses may override this routine to provide different behavior. |
| 1155 | OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 1156 | ExprArg Cond, ExprArg LHS, ExprArg RHS, |
| 1157 | SourceLocation RParenLoc) { |
| 1158 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 1159 | move(Cond), move(LHS), move(RHS), |
| 1160 | RParenLoc); |
| 1161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1163 | /// \brief Build a new overloaded operator call expression. |
| 1164 | /// |
| 1165 | /// By default, performs semantic analysis to build the new expression. |
| 1166 | /// The semantic analysis provides the behavior of template instantiation, |
| 1167 | /// copying with transformations that turn what looks like an overloaded |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | /// operator call into a use of a builtin operator, performing |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1169 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 1170 | /// provide different behavior. |
| 1171 | OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 1172 | SourceLocation OpLoc, |
| 1173 | ExprArg Callee, |
| 1174 | ExprArg First, |
| 1175 | ExprArg Second); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | |
| 1177 | /// \brief Build a new C++ "named" cast expression, such as static_cast or |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1178 | /// reinterpret_cast. |
| 1179 | /// |
| 1180 | /// By default, this routine dispatches to one of the more-specific routines |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1182 | /// Subclasses may override this routine to provide different behavior. |
| 1183 | OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 1184 | Stmt::StmtClass Class, |
| 1185 | SourceLocation LAngleLoc, |
| 1186 | QualType T, |
| 1187 | SourceLocation RAngleLoc, |
| 1188 | SourceLocation LParenLoc, |
| 1189 | ExprArg SubExpr, |
| 1190 | SourceLocation RParenLoc) { |
| 1191 | switch (Class) { |
| 1192 | case Stmt::CXXStaticCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T, |
| 1194 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1195 | move(SubExpr), RParenLoc); |
| 1196 | |
| 1197 | case Stmt::CXXDynamicCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T, |
| 1199 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1200 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1202 | case Stmt::CXXReinterpretCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T, |
| 1204 | RAngleLoc, LParenLoc, |
| 1205 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1206 | RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1208 | case Stmt::CXXConstCastExprClass: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T, |
| 1210 | RAngleLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1211 | move(SubExpr), RParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1213 | default: |
| 1214 | assert(false && "Invalid C++ named cast"); |
| 1215 | break; |
| 1216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1218 | return getSema().ExprError(); |
| 1219 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1221 | /// \brief Build a new C++ static_cast expression. |
| 1222 | /// |
| 1223 | /// By default, performs semantic analysis to build the new expression. |
| 1224 | /// Subclasses may override this routine to provide different behavior. |
| 1225 | OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 1226 | SourceLocation LAngleLoc, |
| 1227 | QualType T, |
| 1228 | SourceLocation RAngleLoc, |
| 1229 | SourceLocation LParenLoc, |
| 1230 | ExprArg SubExpr, |
| 1231 | SourceLocation RParenLoc) { |
| 1232 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1234 | LParenLoc, move(SubExpr), RParenLoc); |
| 1235 | } |
| 1236 | |
| 1237 | /// \brief Build a new C++ dynamic_cast expression. |
| 1238 | /// |
| 1239 | /// By default, performs semantic analysis to build the new expression. |
| 1240 | /// Subclasses may override this routine to provide different behavior. |
| 1241 | OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 1242 | SourceLocation LAngleLoc, |
| 1243 | QualType T, |
| 1244 | SourceLocation RAngleLoc, |
| 1245 | SourceLocation LParenLoc, |
| 1246 | ExprArg SubExpr, |
| 1247 | SourceLocation RParenLoc) { |
| 1248 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1249 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1250 | LParenLoc, move(SubExpr), RParenLoc); |
| 1251 | } |
| 1252 | |
| 1253 | /// \brief Build a new C++ reinterpret_cast expression. |
| 1254 | /// |
| 1255 | /// By default, performs semantic analysis to build the new expression. |
| 1256 | /// Subclasses may override this routine to provide different behavior. |
| 1257 | OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 1258 | SourceLocation LAngleLoc, |
| 1259 | QualType T, |
| 1260 | SourceLocation RAngleLoc, |
| 1261 | SourceLocation LParenLoc, |
| 1262 | ExprArg SubExpr, |
| 1263 | SourceLocation RParenLoc) { |
| 1264 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 1265 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
| 1266 | LParenLoc, move(SubExpr), RParenLoc); |
| 1267 | } |
| 1268 | |
| 1269 | /// \brief Build a new C++ const_cast expression. |
| 1270 | /// |
| 1271 | /// By default, performs semantic analysis to build the new expression. |
| 1272 | /// Subclasses may override this routine to provide different behavior. |
| 1273 | OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 1274 | SourceLocation LAngleLoc, |
| 1275 | QualType T, |
| 1276 | SourceLocation RAngleLoc, |
| 1277 | SourceLocation LParenLoc, |
| 1278 | ExprArg SubExpr, |
| 1279 | SourceLocation RParenLoc) { |
| 1280 | return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | LAngleLoc, T.getAsOpaquePtr(), RAngleLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1282 | LParenLoc, move(SubExpr), RParenLoc); |
| 1283 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1285 | /// \brief Build a new C++ functional-style cast expression. |
| 1286 | /// |
| 1287 | /// By default, performs semantic analysis to build the new expression. |
| 1288 | /// Subclasses may override this routine to provide different behavior. |
| 1289 | OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, |
| 1290 | QualType T, |
| 1291 | SourceLocation LParenLoc, |
| 1292 | ExprArg SubExpr, |
| 1293 | SourceLocation RParenLoc) { |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1294 | void *Sub = SubExpr.takeAs<Expr>(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1295 | return getSema().ActOnCXXTypeConstructExpr(TypeRange, |
| 1296 | T.getAsOpaquePtr(), |
| 1297 | LParenLoc, |
Chris Lattner | 88650c3 | 2009-08-24 05:19:01 +0000 | [diff] [blame] | 1298 | Sema::MultiExprArg(getSema(), &Sub, 1), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | /*CommaLocs=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1300 | RParenLoc); |
| 1301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1303 | /// \brief Build a new C++ typeid(type) expression. |
| 1304 | /// |
| 1305 | /// By default, performs semantic analysis to build the new expression. |
| 1306 | /// Subclasses may override this routine to provide different behavior. |
| 1307 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1308 | SourceLocation LParenLoc, |
| 1309 | QualType T, |
| 1310 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1312 | T.getAsOpaquePtr(), RParenLoc); |
| 1313 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1315 | /// \brief Build a new C++ typeid(expr) expression. |
| 1316 | /// |
| 1317 | /// By default, performs semantic analysis to build the new expression. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
| 1319 | OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc, |
| 1320 | SourceLocation LParenLoc, |
| 1321 | ExprArg Operand, |
| 1322 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1324 | = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(), |
| 1325 | RParenLoc); |
| 1326 | if (Result.isInvalid()) |
| 1327 | return getSema().ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1329 | Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership |
| 1330 | return move(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1333 | /// \brief Build a new C++ "this" expression. |
| 1334 | /// |
| 1335 | /// By default, builds a new "this" expression without performing any |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | /// semantic analysis. Subclasses may override this routine to provide |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1337 | /// different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1339 | QualType ThisType) { |
| 1340 | return getSema().Owned( |
| 1341 | new (getSema().Context) CXXThisExpr(ThisLoc, ThisType)); |
| 1342 | } |
| 1343 | |
| 1344 | /// \brief Build a new C++ throw expression. |
| 1345 | /// |
| 1346 | /// By default, performs semantic analysis to build the new expression. |
| 1347 | /// Subclasses may override this routine to provide different behavior. |
| 1348 | OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { |
| 1349 | return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); |
| 1350 | } |
| 1351 | |
| 1352 | /// \brief Build a new C++ default-argument expression. |
| 1353 | /// |
| 1354 | /// By default, builds a new default-argument expression, which does not |
| 1355 | /// require any semantic analysis. Subclasses may override this routine to |
| 1356 | /// provide different behavior. |
| 1357 | OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) { |
Anders Carlsson | f1480ee | 2009-08-14 18:30:22 +0000 | [diff] [blame] | 1358 | return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | /// \brief Build a new C++ zero-initialization expression. |
| 1362 | /// |
| 1363 | /// By default, performs semantic analysis to build the new expression. |
| 1364 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1365 | OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1366 | SourceLocation LParenLoc, |
| 1367 | QualType T, |
| 1368 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc), |
| 1370 | T.getAsOpaquePtr(), LParenLoc, |
| 1371 | MultiExprArg(getSema(), 0, 0), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1372 | 0, RParenLoc); |
| 1373 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1375 | /// \brief Build a new C++ conditional declaration expression. |
| 1376 | /// |
| 1377 | /// By default, performs semantic analysis to build the new expression. |
| 1378 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1380 | SourceLocation EqLoc, |
| 1381 | VarDecl *Var) { |
| 1382 | return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc, |
| 1383 | EqLoc, |
| 1384 | Var)); |
| 1385 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1386 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1387 | /// \brief Build a new C++ "new" expression. |
| 1388 | /// |
| 1389 | /// By default, performs semantic analysis to build the new expression. |
| 1390 | /// Subclasses may override this routine to provide different behavior. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1391 | OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1392 | bool UseGlobal, |
| 1393 | SourceLocation PlacementLParen, |
| 1394 | MultiExprArg PlacementArgs, |
| 1395 | SourceLocation PlacementRParen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | bool ParenTypeId, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1397 | QualType AllocType, |
| 1398 | SourceLocation TypeLoc, |
| 1399 | SourceRange TypeRange, |
| 1400 | ExprArg ArraySize, |
| 1401 | SourceLocation ConstructorLParen, |
| 1402 | MultiExprArg ConstructorArgs, |
| 1403 | SourceLocation ConstructorRParen) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1405 | PlacementLParen, |
| 1406 | move(PlacementArgs), |
| 1407 | PlacementRParen, |
| 1408 | ParenTypeId, |
| 1409 | AllocType, |
| 1410 | TypeLoc, |
| 1411 | TypeRange, |
| 1412 | move(ArraySize), |
| 1413 | ConstructorLParen, |
| 1414 | move(ConstructorArgs), |
| 1415 | ConstructorRParen); |
| 1416 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1418 | /// \brief Build a new C++ "delete" expression. |
| 1419 | /// |
| 1420 | /// By default, performs semantic analysis to build the new expression. |
| 1421 | /// Subclasses may override this routine to provide different behavior. |
| 1422 | OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 1423 | bool IsGlobalDelete, |
| 1424 | bool IsArrayForm, |
| 1425 | ExprArg Operand) { |
| 1426 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 1427 | move(Operand)); |
| 1428 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1430 | /// \brief Build a new unary type trait expression. |
| 1431 | /// |
| 1432 | /// By default, performs semantic analysis to build the new expression. |
| 1433 | /// Subclasses may override this routine to provide different behavior. |
| 1434 | OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, |
| 1435 | SourceLocation StartLoc, |
| 1436 | SourceLocation LParenLoc, |
| 1437 | QualType T, |
| 1438 | SourceLocation RParenLoc) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1440 | T.getAsOpaquePtr(), RParenLoc); |
| 1441 | } |
| 1442 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | /// \brief Build a new (previously unresolved) declaration reference |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1444 | /// expression. |
| 1445 | /// |
| 1446 | /// By default, performs semantic analysis to build the new expression. |
| 1447 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1448 | OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1449 | SourceRange QualifierRange, |
| 1450 | DeclarationName Name, |
| 1451 | SourceLocation Location, |
| 1452 | bool IsAddressOfOperand) { |
| 1453 | CXXScopeSpec SS; |
| 1454 | SS.setRange(QualifierRange); |
| 1455 | SS.setScopeRep(NNS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | return getSema().ActOnDeclarationNameExpr(/*Scope=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1457 | Location, |
| 1458 | Name, |
| 1459 | /*Trailing lparen=*/false, |
| 1460 | &SS, |
| 1461 | IsAddressOfOperand); |
| 1462 | } |
| 1463 | |
| 1464 | /// \brief Build a new template-id expression. |
| 1465 | /// |
| 1466 | /// By default, performs semantic analysis to build the new expression. |
| 1467 | /// Subclasses may override this routine to provide different behavior. |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1468 | OwningExprResult RebuildTemplateIdExpr(NestedNameSpecifier *Qualifier, |
| 1469 | SourceRange QualifierRange, |
| 1470 | TemplateName Template, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1471 | SourceLocation TemplateLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1472 | const TemplateArgumentListInfo &TemplateArgs) { |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 1473 | return getSema().BuildTemplateIdExpr(Qualifier, QualifierRange, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1474 | Template, TemplateLoc, TemplateArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | /// \brief Build a new object-construction expression. |
| 1478 | /// |
| 1479 | /// By default, performs semantic analysis to build the new expression. |
| 1480 | /// Subclasses may override this routine to provide different behavior. |
| 1481 | OwningExprResult RebuildCXXConstructExpr(QualType T, |
| 1482 | CXXConstructorDecl *Constructor, |
| 1483 | bool IsElidable, |
| 1484 | MultiExprArg Args) { |
Anders Carlsson | ec8e5ea | 2009-09-05 07:40:38 +0000 | [diff] [blame] | 1485 | return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/ |
| 1486 | SourceLocation(), |
| 1487 | T, Constructor, IsElidable, |
Anders Carlsson | f47511a | 2009-09-07 22:23:31 +0000 | [diff] [blame] | 1488 | move(Args)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /// \brief Build a new object-construction expression. |
| 1492 | /// |
| 1493 | /// By default, performs semantic analysis to build the new expression. |
| 1494 | /// Subclasses may override this routine to provide different behavior. |
| 1495 | OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc, |
| 1496 | QualType T, |
| 1497 | SourceLocation LParenLoc, |
| 1498 | MultiExprArg Args, |
| 1499 | SourceLocation *Commas, |
| 1500 | SourceLocation RParenLoc) { |
| 1501 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc), |
| 1502 | T.getAsOpaquePtr(), |
| 1503 | LParenLoc, |
| 1504 | move(Args), |
| 1505 | Commas, |
| 1506 | RParenLoc); |
| 1507 | } |
| 1508 | |
| 1509 | /// \brief Build a new object-construction expression. |
| 1510 | /// |
| 1511 | /// By default, performs semantic analysis to build the new expression. |
| 1512 | /// Subclasses may override this routine to provide different behavior. |
| 1513 | OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc, |
| 1514 | QualType T, |
| 1515 | SourceLocation LParenLoc, |
| 1516 | MultiExprArg Args, |
| 1517 | SourceLocation *Commas, |
| 1518 | SourceLocation RParenLoc) { |
| 1519 | return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc, |
| 1520 | /*FIXME*/LParenLoc), |
| 1521 | T.getAsOpaquePtr(), |
| 1522 | LParenLoc, |
| 1523 | move(Args), |
| 1524 | Commas, |
| 1525 | RParenLoc); |
| 1526 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1527 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1528 | /// \brief Build a new member reference expression. |
| 1529 | /// |
| 1530 | /// By default, performs semantic analysis to build the new expression. |
| 1531 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1532 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1533 | bool IsArrow, |
| 1534 | SourceLocation OperatorLoc, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1535 | NestedNameSpecifier *Qualifier, |
| 1536 | SourceRange QualifierRange, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1537 | DeclarationName Name, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1538 | SourceLocation MemberLoc, |
| 1539 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0dec56d | 2009-08-11 15:56:57 +0000 | [diff] [blame] | 1540 | OwningExprResult Base = move(BaseE); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1541 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1542 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1543 | CXXScopeSpec SS; |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1544 | SS.setRange(QualifierRange); |
| 1545 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1547 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1548 | move(Base), OperatorLoc, OpKind, |
Douglas Gregor | 017dde5 | 2009-08-31 20:00:26 +0000 | [diff] [blame] | 1549 | MemberLoc, |
| 1550 | Name, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1551 | /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1552 | &SS, |
| 1553 | FirstQualifierInScope); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1556 | /// \brief Build a new member reference expression with explicit template |
| 1557 | /// arguments. |
| 1558 | /// |
| 1559 | /// By default, performs semantic analysis to build the new expression. |
| 1560 | /// Subclasses may override this routine to provide different behavior. |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 1561 | OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1562 | bool IsArrow, |
| 1563 | SourceLocation OperatorLoc, |
| 1564 | NestedNameSpecifier *Qualifier, |
| 1565 | SourceRange QualifierRange, |
| 1566 | TemplateName Template, |
| 1567 | SourceLocation TemplateNameLoc, |
| 1568 | NamedDecl *FirstQualifierInScope, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1569 | const TemplateArgumentListInfo &TemplateArgs) { |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1570 | OwningExprResult Base = move(BaseE); |
| 1571 | tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1572 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1573 | CXXScopeSpec SS; |
| 1574 | SS.setRange(QualifierRange); |
| 1575 | SS.setScopeRep(Qualifier); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1576 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1577 | // FIXME: We're going to end up looking up the template based on its name, |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1578 | // twice! Also, duplicates part of Sema::BuildMemberAccessExpr. |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1579 | DeclarationName Name; |
| 1580 | if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl()) |
| 1581 | Name = ActualTemplate->getDeclName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1582 | else if (OverloadedFunctionDecl *Ovl |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1583 | = Template.getAsOverloadedFunctionDecl()) |
| 1584 | Name = Ovl->getDeclName(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1585 | else { |
| 1586 | DependentTemplateName *DTN = Template.getAsDependentTemplateName(); |
| 1587 | if (DTN->isIdentifier()) |
| 1588 | Name = DTN->getIdentifier(); |
| 1589 | else |
| 1590 | Name = SemaRef.Context.DeclarationNames.getCXXOperatorName( |
| 1591 | DTN->getOperator()); |
| 1592 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 1593 | return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base), |
| 1594 | OperatorLoc, OpKind, |
| 1595 | TemplateNameLoc, Name, |
| 1596 | &TemplateArgs, |
| 1597 | Sema::DeclPtrTy(), &SS); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1598 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1600 | /// \brief Build a new Objective-C @encode expression. |
| 1601 | /// |
| 1602 | /// By default, performs semantic analysis to build the new expression. |
| 1603 | /// Subclasses may override this routine to provide different behavior. |
| 1604 | OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 1605 | QualType T, |
| 1606 | SourceLocation RParenLoc) { |
| 1607 | return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T, |
| 1608 | RParenLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1609 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1610 | |
| 1611 | /// \brief Build a new Objective-C protocol expression. |
| 1612 | /// |
| 1613 | /// By default, performs semantic analysis to build the new expression. |
| 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol, |
| 1616 | SourceLocation AtLoc, |
| 1617 | SourceLocation ProtoLoc, |
| 1618 | SourceLocation LParenLoc, |
| 1619 | SourceLocation RParenLoc) { |
| 1620 | return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression( |
| 1621 | Protocol->getIdentifier(), |
| 1622 | AtLoc, |
| 1623 | ProtoLoc, |
| 1624 | LParenLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | RParenLoc)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1626 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1628 | /// \brief Build a new shuffle vector expression. |
| 1629 | /// |
| 1630 | /// By default, performs semantic analysis to build the new expression. |
| 1631 | /// Subclasses may override this routine to provide different behavior. |
| 1632 | OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 1633 | MultiExprArg SubExprs, |
| 1634 | SourceLocation RParenLoc) { |
| 1635 | // Find the declaration for __builtin_shufflevector |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | const IdentifierInfo &Name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1637 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 1638 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 1639 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 1640 | assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1642 | // Build a reference to the __builtin_shufflevector builtin |
| 1643 | FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | Expr *Callee |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1645 | = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), |
Douglas Gregor | 0da76df | 2009-11-23 11:41:28 +0000 | [diff] [blame] | 1646 | BuiltinLoc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1647 | SemaRef.UsualUnaryConversions(Callee); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | |
| 1649 | // Build the CallExpr |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1650 | unsigned NumSubExprs = SubExprs.size(); |
| 1651 | Expr **Subs = (Expr **)SubExprs.release(); |
| 1652 | CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, |
| 1653 | Subs, NumSubExprs, |
| 1654 | Builtin->getResultType(), |
| 1655 | RParenLoc); |
| 1656 | OwningExprResult OwnedCall(SemaRef.Owned(TheCall)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1658 | // Type-check the __builtin_shufflevector expression. |
| 1659 | OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); |
| 1660 | if (Result.isInvalid()) |
| 1661 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1663 | OwnedCall.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1664 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1665 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1666 | }; |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1667 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1668 | template<typename Derived> |
| 1669 | Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| 1670 | if (!S) |
| 1671 | return SemaRef.Owned(S); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1672 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1673 | switch (S->getStmtClass()) { |
| 1674 | case Stmt::NoStmtClass: break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1676 | // Transform individual statement nodes |
| 1677 | #define STMT(Node, Parent) \ |
| 1678 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 1679 | #define EXPR(Node, Parent) |
| 1680 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1681 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1682 | // Transform expressions by calling TransformExpr. |
| 1683 | #define STMT(Node, Parent) |
| 1684 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 1685 | #include "clang/AST/StmtNodes.def" |
| 1686 | { |
| 1687 | Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 1688 | if (E.isInvalid()) |
| 1689 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
Douglas Gregor | afe7ec2 | 2009-11-13 18:34:26 +0000 | [diff] [blame] | 1691 | return getSema().ActOnExprStmt(getSema().FullExpr(E)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1692 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1695 | return SemaRef.Owned(S->Retain()); |
| 1696 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1697 | |
| 1698 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1699 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1700 | Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E, |
| 1701 | bool isAddressOfOperand) { |
| 1702 | if (!E) |
| 1703 | return SemaRef.Owned(E); |
| 1704 | |
| 1705 | switch (E->getStmtClass()) { |
| 1706 | case Stmt::NoStmtClass: break; |
| 1707 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 1708 | #define EXPR(Node, Parent) \ |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 1709 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \ |
| 1710 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1711 | #include "clang/AST/StmtNodes.def" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 1714 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | 657c1ac | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | template<typename Derived> |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1718 | NestedNameSpecifier * |
| 1719 | TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1720 | SourceRange Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1721 | QualType ObjectType, |
| 1722 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | 0979c80 | 2009-08-31 21:41:48 +0000 | [diff] [blame] | 1723 | if (!NNS) |
| 1724 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1725 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1726 | // Transform the prefix of this nested name specifier. |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1727 | NestedNameSpecifier *Prefix = NNS->getPrefix(); |
| 1728 | if (Prefix) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1730 | ObjectType, |
| 1731 | FirstQualifierInScope); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1732 | if (!Prefix) |
| 1733 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1734 | |
| 1735 | // Clear out the object type and the first qualifier in scope; they only |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1736 | // apply to the first element in the nested-name-specifier. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1737 | ObjectType = QualType(); |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1738 | FirstQualifierInScope = 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1739 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1741 | switch (NNS->getKind()) { |
| 1742 | case NestedNameSpecifier::Identifier: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | assert((Prefix || !ObjectType.isNull()) && |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1744 | "Identifier nested-name-specifier with no prefix or object type"); |
| 1745 | if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && |
| 1746 | ObjectType.isNull()) |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1747 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1748 | |
| 1749 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 1750 | *NNS->getAsIdentifier(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 1751 | ObjectType, |
| 1752 | FirstQualifierInScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1753 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1754 | case NestedNameSpecifier::Namespace: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | NamespaceDecl *NS |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1756 | = cast_or_null<NamespaceDecl>( |
| 1757 | getDerived().TransformDecl(NNS->getAsNamespace())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1759 | Prefix == NNS->getPrefix() && |
| 1760 | NS == NNS->getAsNamespace()) |
| 1761 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1762 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1763 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); |
| 1764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1765 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1766 | case NestedNameSpecifier::Global: |
| 1767 | // There is no meaningful transformation that one could perform on the |
| 1768 | // global scope. |
| 1769 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1770 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1771 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 1772 | case NestedNameSpecifier::TypeSpec: { |
Douglas Gregor | fbf2c94 | 2009-10-29 22:21:39 +0000 | [diff] [blame] | 1773 | TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1774 | QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0)); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1775 | if (T.isNull()) |
| 1776 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1778 | if (!getDerived().AlwaysRebuild() && |
| 1779 | Prefix == NNS->getPrefix() && |
| 1780 | T == QualType(NNS->getAsType(), 0)) |
| 1781 | return NNS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
| 1783 | return getDerived().RebuildNestedNameSpecifier(Prefix, Range, |
| 1784 | NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1785 | T); |
| 1786 | } |
| 1787 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1788 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1789 | // Required to silence a GCC warning |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | return 0; |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1794 | DeclarationName |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1795 | TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name, |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1796 | SourceLocation Loc, |
| 1797 | QualType ObjectType) { |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1798 | if (!Name) |
| 1799 | return Name; |
| 1800 | |
| 1801 | switch (Name.getNameKind()) { |
| 1802 | case DeclarationName::Identifier: |
| 1803 | case DeclarationName::ObjCZeroArgSelector: |
| 1804 | case DeclarationName::ObjCOneArgSelector: |
| 1805 | case DeclarationName::ObjCMultiArgSelector: |
| 1806 | case DeclarationName::CXXOperatorName: |
| 1807 | case DeclarationName::CXXUsingDirective: |
| 1808 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1810 | case DeclarationName::CXXConstructorName: |
| 1811 | case DeclarationName::CXXDestructorName: |
| 1812 | case DeclarationName::CXXConversionFunctionName: { |
| 1813 | TemporaryBase Rebase(*this, Loc, Name); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1814 | QualType T; |
| 1815 | if (!ObjectType.isNull() && |
| 1816 | isa<TemplateSpecializationType>(Name.getCXXNameType())) { |
| 1817 | TemplateSpecializationType *SpecType |
| 1818 | = cast<TemplateSpecializationType>(Name.getCXXNameType()); |
| 1819 | T = TransformTemplateSpecializationType(SpecType, ObjectType); |
| 1820 | } else |
| 1821 | T = getDerived().TransformType(Name.getCXXNameType()); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1822 | if (T.isNull()) |
| 1823 | return DeclarationName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1825 | return SemaRef.Context.DeclarationNames.getCXXSpecialName( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | Name.getNameKind(), |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1827 | SemaRef.Context.getCanonicalType(T)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 1831 | return DeclarationName(); |
| 1832 | } |
| 1833 | |
| 1834 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | TemplateName |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1836 | TreeTransform<Derived>::TransformTemplateName(TemplateName Name, |
| 1837 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1838 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1840 | = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), |
| 1841 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
| 1842 | if (!NNS) |
| 1843 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1845 | if (TemplateDecl *Template = QTN->getTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1847 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1848 | if (!TransTemplate) |
| 1849 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1851 | if (!getDerived().AlwaysRebuild() && |
| 1852 | NNS == QTN->getQualifier() && |
| 1853 | TransTemplate == Template) |
| 1854 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1856 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1857 | TransTemplate); |
| 1858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1860 | OverloadedFunctionDecl *Ovl = QTN->getOverloadedFunctionDecl(); |
| 1861 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1862 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1863 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1864 | if (!TransOvl) |
| 1865 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1867 | if (!getDerived().AlwaysRebuild() && |
| 1868 | NNS == QTN->getQualifier() && |
| 1869 | TransOvl == Ovl) |
| 1870 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1872 | return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), |
| 1873 | TransOvl); |
| 1874 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1876 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1877 | NestedNameSpecifier *NNS |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1878 | = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(), |
| 1879 | /*FIXME:*/SourceRange(getDerived().getBaseLocation())); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 1880 | if (!NNS && DTN->getQualifier()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1881 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1883 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 1884 | NNS == DTN->getQualifier() && |
| 1885 | ObjectType.isNull()) |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1886 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1888 | if (DTN->isIdentifier()) |
| 1889 | return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(), |
| 1890 | ObjectType); |
| 1891 | |
| 1892 | return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), |
| 1893 | ObjectType); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1894 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1896 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1897 | TemplateDecl *TransTemplate |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1898 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template)); |
| 1899 | if (!TransTemplate) |
| 1900 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1902 | if (!getDerived().AlwaysRebuild() && |
| 1903 | TransTemplate == Template) |
| 1904 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1905 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1906 | return TemplateName(TransTemplate); |
| 1907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1909 | OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl(); |
| 1910 | assert(Ovl && "Not a template name or an overload set?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | OverloadedFunctionDecl *TransOvl |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1912 | = cast_or_null<OverloadedFunctionDecl>(getDerived().TransformDecl(Ovl)); |
| 1913 | if (!TransOvl) |
| 1914 | return TemplateName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1915 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1916 | if (!getDerived().AlwaysRebuild() && |
| 1917 | TransOvl == Ovl) |
| 1918 | return Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1920 | return TemplateName(TransOvl); |
| 1921 | } |
| 1922 | |
| 1923 | template<typename Derived> |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1924 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 1925 | const TemplateArgument &Arg, |
| 1926 | TemplateArgumentLoc &Output) { |
| 1927 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 1928 | switch (Arg.getKind()) { |
| 1929 | case TemplateArgument::Null: |
| 1930 | llvm::llvm_unreachable("null template argument in TreeTransform"); |
| 1931 | break; |
| 1932 | |
| 1933 | case TemplateArgument::Type: |
| 1934 | Output = TemplateArgumentLoc(Arg, |
| 1935 | SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc)); |
| 1936 | |
| 1937 | break; |
| 1938 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1939 | case TemplateArgument::Template: |
| 1940 | Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); |
| 1941 | break; |
| 1942 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1943 | case TemplateArgument::Expression: |
| 1944 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 1945 | break; |
| 1946 | |
| 1947 | case TemplateArgument::Declaration: |
| 1948 | case TemplateArgument::Integral: |
| 1949 | case TemplateArgument::Pack: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1950 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1951 | break; |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | template<typename Derived> |
| 1956 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 1957 | const TemplateArgumentLoc &Input, |
| 1958 | TemplateArgumentLoc &Output) { |
| 1959 | const TemplateArgument &Arg = Input.getArgument(); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1960 | switch (Arg.getKind()) { |
| 1961 | case TemplateArgument::Null: |
| 1962 | case TemplateArgument::Integral: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1963 | Output = Input; |
| 1964 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1965 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1966 | case TemplateArgument::Type: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1967 | DeclaratorInfo *DI = Input.getSourceDeclaratorInfo(); |
| 1968 | if (DI == NULL) |
| 1969 | DI = InventDeclaratorInfo(Input.getArgument().getAsType()); |
| 1970 | |
| 1971 | DI = getDerived().TransformType(DI); |
| 1972 | if (!DI) return true; |
| 1973 | |
| 1974 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 1975 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1977 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1978 | case TemplateArgument::Declaration: { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1979 | // FIXME: we should never have to transform one of these. |
Douglas Gregor | 972e6ce | 2009-10-27 06:26:26 +0000 | [diff] [blame] | 1980 | DeclarationName Name; |
| 1981 | if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) |
| 1982 | Name = ND->getDeclName(); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 1983 | TemporaryBase Rebase(*this, Input.getLocation(), Name); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 1984 | Decl *D = getDerived().TransformDecl(Arg.getAsDecl()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1985 | if (!D) return true; |
| 1986 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 1987 | Expr *SourceExpr = Input.getSourceDeclExpression(); |
| 1988 | if (SourceExpr) { |
| 1989 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
| 1990 | Action::Unevaluated); |
| 1991 | Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); |
| 1992 | if (E.isInvalid()) |
| 1993 | SourceExpr = NULL; |
| 1994 | else { |
| 1995 | SourceExpr = E.takeAs<Expr>(); |
| 1996 | SourceExpr->Retain(); |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2001 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2002 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2004 | case TemplateArgument::Template: { |
| 2005 | TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); |
| 2006 | TemplateName Template |
| 2007 | = getDerived().TransformTemplateName(Arg.getAsTemplate()); |
| 2008 | if (Template.isNull()) |
| 2009 | return true; |
| 2010 | |
| 2011 | Output = TemplateArgumentLoc(TemplateArgument(Template), |
| 2012 | Input.getTemplateQualifierRange(), |
| 2013 | Input.getTemplateNameLoc()); |
| 2014 | return false; |
| 2015 | } |
| 2016 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2017 | case TemplateArgument::Expression: { |
| 2018 | // Template argument expressions are not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2019 | EnterExpressionEvaluationContext Unevaluated(getSema(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2020 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2021 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2022 | Expr *InputExpr = Input.getSourceExpression(); |
| 2023 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 2024 | |
| 2025 | Sema::OwningExprResult E |
| 2026 | = getDerived().TransformExpr(InputExpr); |
| 2027 | if (E.isInvalid()) return true; |
| 2028 | |
| 2029 | Expr *ETaken = E.takeAs<Expr>(); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2030 | ETaken->Retain(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2031 | Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); |
| 2032 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2033 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2035 | case TemplateArgument::Pack: { |
| 2036 | llvm::SmallVector<TemplateArgument, 4> TransformedArgs; |
| 2037 | TransformedArgs.reserve(Arg.pack_size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | for (TemplateArgument::pack_iterator A = Arg.pack_begin(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2039 | AEnd = Arg.pack_end(); |
| 2040 | A != AEnd; ++A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2041 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2042 | // FIXME: preserve source information here when we start |
| 2043 | // caring about parameter packs. |
| 2044 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2045 | TemplateArgumentLoc InputArg; |
| 2046 | TemplateArgumentLoc OutputArg; |
| 2047 | getDerived().InventTemplateArgumentLoc(*A, InputArg); |
| 2048 | if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2049 | return true; |
| 2050 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2051 | TransformedArgs.push_back(OutputArg.getArgument()); |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2052 | } |
| 2053 | TemplateArgument Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2054 | Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(), |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2055 | true); |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2056 | Output = TemplateArgumentLoc(Result, Input.getLocInfo()); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2057 | return false; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2058 | } |
| 2059 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2060 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2061 | // Work around bogus GCC warning |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2062 | return true; |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2065 | //===----------------------------------------------------------------------===// |
| 2066 | // Type transformation |
| 2067 | //===----------------------------------------------------------------------===// |
| 2068 | |
| 2069 | template<typename Derived> |
| 2070 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 2071 | if (getDerived().AlreadyTransformed(T)) |
| 2072 | return T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2073 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2074 | // Temporary workaround. All of these transformations should |
| 2075 | // eventually turn into transformations on TypeLocs. |
| 2076 | DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T); |
John McCall | 4802a31 | 2009-10-21 00:44:26 +0000 | [diff] [blame] | 2077 | DI->getTypeLoc().initialize(getDerived().getBaseLocation()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2078 | |
| 2079 | DeclaratorInfo *NewDI = getDerived().TransformType(DI); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2080 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2081 | if (!NewDI) |
| 2082 | return QualType(); |
| 2083 | |
| 2084 | return NewDI->getType(); |
| 2085 | } |
| 2086 | |
| 2087 | template<typename Derived> |
| 2088 | DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) { |
| 2089 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 2090 | return DI; |
| 2091 | |
| 2092 | TypeLocBuilder TLB; |
| 2093 | |
| 2094 | TypeLoc TL = DI->getTypeLoc(); |
| 2095 | TLB.reserve(TL.getFullDataSize()); |
| 2096 | |
| 2097 | QualType Result = getDerived().TransformType(TLB, TL); |
| 2098 | if (Result.isNull()) |
| 2099 | return 0; |
| 2100 | |
| 2101 | return TLB.getDeclaratorInfo(SemaRef.Context, Result); |
| 2102 | } |
| 2103 | |
| 2104 | template<typename Derived> |
| 2105 | QualType |
| 2106 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 2107 | switch (T.getTypeLocClass()) { |
| 2108 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 2109 | #define TYPELOC(CLASS, PARENT) \ |
| 2110 | case TypeLoc::CLASS: \ |
| 2111 | return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); |
| 2112 | #include "clang/AST/TypeLocNodes.def" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2114 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2115 | llvm::llvm_unreachable("unhandled type loc!"); |
| 2116 | return QualType(); |
| 2117 | } |
| 2118 | |
| 2119 | /// FIXME: By default, this routine adds type qualifiers only to types |
| 2120 | /// that can have qualifiers, and silently suppresses those qualifiers |
| 2121 | /// that are not permitted (e.g., qualifiers on reference or function |
| 2122 | /// types). This is the right thing for template instantiation, but |
| 2123 | /// probably not for other clients. |
| 2124 | template<typename Derived> |
| 2125 | QualType |
| 2126 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 2127 | QualifiedTypeLoc T) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2128 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2129 | |
| 2130 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 2131 | if (Result.isNull()) |
| 2132 | return QualType(); |
| 2133 | |
| 2134 | // Silently suppress qualifiers if the result type can't be qualified. |
| 2135 | // FIXME: this is the right thing for template instantiation, but |
| 2136 | // probably not for other clients. |
| 2137 | if (Result->isFunctionType() || Result->isReferenceType()) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2138 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2139 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2140 | Result = SemaRef.Context.getQualifiedType(Result, Quals); |
| 2141 | |
| 2142 | TLB.push<QualifiedTypeLoc>(Result); |
| 2143 | |
| 2144 | // No location information to preserve. |
| 2145 | |
| 2146 | return Result; |
| 2147 | } |
| 2148 | |
| 2149 | template <class TyLoc> static inline |
| 2150 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 2151 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 2152 | NewT.setNameLoc(T.getNameLoc()); |
| 2153 | return T.getType(); |
| 2154 | } |
| 2155 | |
| 2156 | // Ugly metaprogramming macros because I couldn't be bothered to make |
| 2157 | // the equivalent template version work. |
| 2158 | #define TransformPointerLikeType(TypeClass) do { \ |
| 2159 | QualType PointeeType \ |
| 2160 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); \ |
| 2161 | if (PointeeType.isNull()) \ |
| 2162 | return QualType(); \ |
| 2163 | \ |
| 2164 | QualType Result = TL.getType(); \ |
| 2165 | if (getDerived().AlwaysRebuild() || \ |
| 2166 | PointeeType != TL.getPointeeLoc().getType()) { \ |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2167 | Result = getDerived().Rebuild##TypeClass(PointeeType, \ |
| 2168 | TL.getSigilLoc()); \ |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2169 | if (Result.isNull()) \ |
| 2170 | return QualType(); \ |
| 2171 | } \ |
| 2172 | \ |
| 2173 | TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \ |
| 2174 | NewT.setSigilLoc(TL.getSigilLoc()); \ |
| 2175 | \ |
| 2176 | return Result; \ |
| 2177 | } while(0) |
| 2178 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2179 | template<typename Derived> |
| 2180 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 2181 | BuiltinTypeLoc T) { |
| 2182 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2184 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2185 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2186 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2187 | TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB, |
| 2188 | FixedWidthIntTypeLoc T) { |
| 2189 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2190 | } |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 2191 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2192 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2193 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 2194 | ComplexTypeLoc T) { |
| 2195 | // FIXME: recurse? |
| 2196 | return TransformTypeSpecType(TLB, T); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2197 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2199 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2200 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 2201 | PointerTypeLoc TL) { |
| 2202 | TransformPointerLikeType(PointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | |
| 2205 | template<typename Derived> |
| 2206 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2207 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 2208 | BlockPointerTypeLoc TL) { |
| 2209 | TransformPointerLikeType(BlockPointerType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2212 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 2213 | /// don't care whether the type itself is an l-value type or an r-value |
| 2214 | /// type; we only care if the type was *written* as an l-value type |
| 2215 | /// or an r-value type. |
| 2216 | template<typename Derived> |
| 2217 | QualType |
| 2218 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 2219 | ReferenceTypeLoc TL) { |
| 2220 | const ReferenceType *T = TL.getTypePtr(); |
| 2221 | |
| 2222 | // Note that this works with the pointee-as-written. |
| 2223 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 2224 | if (PointeeType.isNull()) |
| 2225 | return QualType(); |
| 2226 | |
| 2227 | QualType Result = TL.getType(); |
| 2228 | if (getDerived().AlwaysRebuild() || |
| 2229 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 2230 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 2231 | T->isSpelledAsLValue(), |
| 2232 | TL.getSigilLoc()); |
| 2233 | if (Result.isNull()) |
| 2234 | return QualType(); |
| 2235 | } |
| 2236 | |
| 2237 | // r-value references can be rebuilt as l-value references. |
| 2238 | ReferenceTypeLoc NewTL; |
| 2239 | if (isa<LValueReferenceType>(Result)) |
| 2240 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 2241 | else |
| 2242 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 2243 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2244 | |
| 2245 | return Result; |
| 2246 | } |
| 2247 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2248 | template<typename Derived> |
| 2249 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2250 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 2251 | LValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2252 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2255 | template<typename Derived> |
| 2256 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2257 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 2258 | RValueReferenceTypeLoc TL) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2259 | return TransformReferenceType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2260 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2261 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2262 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2263 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2264 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 2265 | MemberPointerTypeLoc TL) { |
| 2266 | MemberPointerType *T = TL.getTypePtr(); |
| 2267 | |
| 2268 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2269 | if (PointeeType.isNull()) |
| 2270 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2271 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2272 | // TODO: preserve source information for this. |
| 2273 | QualType ClassType |
| 2274 | = getDerived().TransformType(QualType(T->getClass(), 0)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2275 | if (ClassType.isNull()) |
| 2276 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2277 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2278 | QualType Result = TL.getType(); |
| 2279 | if (getDerived().AlwaysRebuild() || |
| 2280 | PointeeType != T->getPointeeType() || |
| 2281 | ClassType != QualType(T->getClass(), 0)) { |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2282 | Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, |
| 2283 | TL.getStarLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2284 | if (Result.isNull()) |
| 2285 | return QualType(); |
| 2286 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2287 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2288 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 2289 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 2290 | |
| 2291 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2294 | template<typename Derived> |
| 2295 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2296 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 2297 | ConstantArrayTypeLoc TL) { |
| 2298 | ConstantArrayType *T = TL.getTypePtr(); |
| 2299 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2300 | if (ElementType.isNull()) |
| 2301 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2303 | QualType Result = TL.getType(); |
| 2304 | if (getDerived().AlwaysRebuild() || |
| 2305 | ElementType != T->getElementType()) { |
| 2306 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 2307 | T->getSizeModifier(), |
| 2308 | T->getSize(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2309 | T->getIndexTypeCVRQualifiers(), |
| 2310 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2311 | if (Result.isNull()) |
| 2312 | return QualType(); |
| 2313 | } |
| 2314 | |
| 2315 | ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); |
| 2316 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2317 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2319 | Expr *Size = TL.getSizeExpr(); |
| 2320 | if (Size) { |
| 2321 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2322 | Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); |
| 2323 | } |
| 2324 | NewTL.setSizeExpr(Size); |
| 2325 | |
| 2326 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2327 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2328 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2329 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2330 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2331 | TypeLocBuilder &TLB, |
| 2332 | IncompleteArrayTypeLoc TL) { |
| 2333 | IncompleteArrayType *T = TL.getTypePtr(); |
| 2334 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2335 | if (ElementType.isNull()) |
| 2336 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2337 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2338 | QualType Result = TL.getType(); |
| 2339 | if (getDerived().AlwaysRebuild() || |
| 2340 | ElementType != T->getElementType()) { |
| 2341 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2342 | T->getSizeModifier(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2343 | T->getIndexTypeCVRQualifiers(), |
| 2344 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2345 | if (Result.isNull()) |
| 2346 | return QualType(); |
| 2347 | } |
| 2348 | |
| 2349 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 2350 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2351 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2352 | NewTL.setSizeExpr(0); |
| 2353 | |
| 2354 | return Result; |
| 2355 | } |
| 2356 | |
| 2357 | template<typename Derived> |
| 2358 | QualType |
| 2359 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 2360 | VariableArrayTypeLoc TL) { |
| 2361 | VariableArrayType *T = TL.getTypePtr(); |
| 2362 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2363 | if (ElementType.isNull()) |
| 2364 | return QualType(); |
| 2365 | |
| 2366 | // Array bounds are not potentially evaluated contexts |
| 2367 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2368 | |
| 2369 | Sema::OwningExprResult SizeResult |
| 2370 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2371 | if (SizeResult.isInvalid()) |
| 2372 | return QualType(); |
| 2373 | |
| 2374 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2375 | |
| 2376 | QualType Result = TL.getType(); |
| 2377 | if (getDerived().AlwaysRebuild() || |
| 2378 | ElementType != T->getElementType() || |
| 2379 | Size != T->getSizeExpr()) { |
| 2380 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 2381 | T->getSizeModifier(), |
| 2382 | move(SizeResult), |
| 2383 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2384 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2385 | if (Result.isNull()) |
| 2386 | return QualType(); |
| 2387 | } |
| 2388 | else SizeResult.take(); |
| 2389 | |
| 2390 | VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); |
| 2391 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2392 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2393 | NewTL.setSizeExpr(Size); |
| 2394 | |
| 2395 | return Result; |
| 2396 | } |
| 2397 | |
| 2398 | template<typename Derived> |
| 2399 | QualType |
| 2400 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 2401 | DependentSizedArrayTypeLoc TL) { |
| 2402 | DependentSizedArrayType *T = TL.getTypePtr(); |
| 2403 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 2404 | if (ElementType.isNull()) |
| 2405 | return QualType(); |
| 2406 | |
| 2407 | // Array bounds are not potentially evaluated contexts |
| 2408 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2409 | |
| 2410 | Sema::OwningExprResult SizeResult |
| 2411 | = getDerived().TransformExpr(T->getSizeExpr()); |
| 2412 | if (SizeResult.isInvalid()) |
| 2413 | return QualType(); |
| 2414 | |
| 2415 | Expr *Size = static_cast<Expr*>(SizeResult.get()); |
| 2416 | |
| 2417 | QualType Result = TL.getType(); |
| 2418 | if (getDerived().AlwaysRebuild() || |
| 2419 | ElementType != T->getElementType() || |
| 2420 | Size != T->getSizeExpr()) { |
| 2421 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 2422 | T->getSizeModifier(), |
| 2423 | move(SizeResult), |
| 2424 | T->getIndexTypeCVRQualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 2425 | TL.getBracketsRange()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2426 | if (Result.isNull()) |
| 2427 | return QualType(); |
| 2428 | } |
| 2429 | else SizeResult.take(); |
| 2430 | |
| 2431 | // We might have any sort of array type now, but fortunately they |
| 2432 | // all have the same location layout. |
| 2433 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 2434 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 2435 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 2436 | NewTL.setSizeExpr(Size); |
| 2437 | |
| 2438 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
| 2441 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2442 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2443 | TypeLocBuilder &TLB, |
| 2444 | DependentSizedExtVectorTypeLoc TL) { |
| 2445 | DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 2446 | |
| 2447 | // FIXME: ext vector locs should be nested |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2448 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2449 | if (ElementType.isNull()) |
| 2450 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2452 | // Vector sizes are not potentially evaluated contexts |
| 2453 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 2454 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2455 | Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 2456 | if (Size.isInvalid()) |
| 2457 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2458 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2459 | QualType Result = TL.getType(); |
| 2460 | if (getDerived().AlwaysRebuild() || |
John McCall | eee91c3 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 2461 | ElementType != T->getElementType() || |
| 2462 | Size.get() != T->getSizeExpr()) { |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2463 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2464 | move(Size), |
| 2465 | T->getAttributeLoc()); |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2466 | if (Result.isNull()) |
| 2467 | return QualType(); |
| 2468 | } |
| 2469 | else Size.take(); |
| 2470 | |
| 2471 | // Result might be dependent or not. |
| 2472 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 2473 | DependentSizedExtVectorTypeLoc NewTL |
| 2474 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 2475 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2476 | } else { |
| 2477 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2478 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2479 | } |
| 2480 | |
| 2481 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2483 | |
| 2484 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2485 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 2486 | VectorTypeLoc TL) { |
| 2487 | VectorType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2488 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2489 | if (ElementType.isNull()) |
| 2490 | return QualType(); |
| 2491 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2492 | QualType Result = TL.getType(); |
| 2493 | if (getDerived().AlwaysRebuild() || |
| 2494 | ElementType != T->getElementType()) { |
| 2495 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements()); |
| 2496 | if (Result.isNull()) |
| 2497 | return QualType(); |
| 2498 | } |
| 2499 | |
| 2500 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 2501 | NewTL.setNameLoc(TL.getNameLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2502 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2503 | return Result; |
| 2504 | } |
| 2505 | |
| 2506 | template<typename Derived> |
| 2507 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 2508 | ExtVectorTypeLoc TL) { |
| 2509 | VectorType *T = TL.getTypePtr(); |
| 2510 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 2511 | if (ElementType.isNull()) |
| 2512 | return QualType(); |
| 2513 | |
| 2514 | QualType Result = TL.getType(); |
| 2515 | if (getDerived().AlwaysRebuild() || |
| 2516 | ElementType != T->getElementType()) { |
| 2517 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 2518 | T->getNumElements(), |
| 2519 | /*FIXME*/ SourceLocation()); |
| 2520 | if (Result.isNull()) |
| 2521 | return QualType(); |
| 2522 | } |
| 2523 | |
| 2524 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 2525 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2526 | |
| 2527 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2529 | |
| 2530 | template<typename Derived> |
| 2531 | QualType |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2532 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 2533 | FunctionProtoTypeLoc TL) { |
| 2534 | FunctionProtoType *T = TL.getTypePtr(); |
| 2535 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2536 | if (ResultType.isNull()) |
| 2537 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2538 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2539 | // Transform the parameters. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2540 | llvm::SmallVector<QualType, 4> ParamTypes; |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2541 | llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 2542 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2543 | ParmVarDecl *OldParm = TL.getArg(i); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2544 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2545 | QualType NewType; |
| 2546 | ParmVarDecl *NewParm; |
| 2547 | |
| 2548 | if (OldParm) { |
| 2549 | DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo(); |
| 2550 | assert(OldDI->getType() == T->getArgType(i)); |
| 2551 | |
| 2552 | DeclaratorInfo *NewDI = getDerived().TransformType(OldDI); |
| 2553 | if (!NewDI) |
| 2554 | return QualType(); |
| 2555 | |
| 2556 | if (NewDI == OldDI) |
| 2557 | NewParm = OldParm; |
| 2558 | else |
| 2559 | NewParm = ParmVarDecl::Create(SemaRef.Context, |
| 2560 | OldParm->getDeclContext(), |
| 2561 | OldParm->getLocation(), |
| 2562 | OldParm->getIdentifier(), |
| 2563 | NewDI->getType(), |
| 2564 | NewDI, |
| 2565 | OldParm->getStorageClass(), |
| 2566 | /* DefArg */ NULL); |
| 2567 | NewType = NewParm->getType(); |
| 2568 | |
| 2569 | // Deal with the possibility that we don't have a parameter |
| 2570 | // declaration for this parameter. |
| 2571 | } else { |
| 2572 | NewParm = 0; |
| 2573 | |
| 2574 | QualType OldType = T->getArgType(i); |
| 2575 | NewType = getDerived().TransformType(OldType); |
| 2576 | if (NewType.isNull()) |
| 2577 | return QualType(); |
| 2578 | } |
| 2579 | |
| 2580 | ParamTypes.push_back(NewType); |
| 2581 | ParamDecls.push_back(NewParm); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2582 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2583 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2584 | QualType Result = TL.getType(); |
| 2585 | if (getDerived().AlwaysRebuild() || |
| 2586 | ResultType != T->getResultType() || |
| 2587 | !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { |
| 2588 | Result = getDerived().RebuildFunctionProtoType(ResultType, |
| 2589 | ParamTypes.data(), |
| 2590 | ParamTypes.size(), |
| 2591 | T->isVariadic(), |
| 2592 | T->getTypeQuals()); |
| 2593 | if (Result.isNull()) |
| 2594 | return QualType(); |
| 2595 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2596 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2597 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 2598 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2599 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2600 | for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) |
| 2601 | NewTL.setArg(i, ParamDecls[i]); |
| 2602 | |
| 2603 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2604 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2605 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2606 | template<typename Derived> |
| 2607 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2608 | TypeLocBuilder &TLB, |
| 2609 | FunctionNoProtoTypeLoc TL) { |
| 2610 | FunctionNoProtoType *T = TL.getTypePtr(); |
| 2611 | QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); |
| 2612 | if (ResultType.isNull()) |
| 2613 | return QualType(); |
| 2614 | |
| 2615 | QualType Result = TL.getType(); |
| 2616 | if (getDerived().AlwaysRebuild() || |
| 2617 | ResultType != T->getResultType()) |
| 2618 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 2619 | |
| 2620 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 2621 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 2622 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 2623 | |
| 2624 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2625 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2626 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2627 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2628 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 2629 | TypedefTypeLoc TL) { |
| 2630 | TypedefType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2631 | TypedefDecl *Typedef |
| 2632 | = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl())); |
| 2633 | if (!Typedef) |
| 2634 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2635 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2636 | QualType Result = TL.getType(); |
| 2637 | if (getDerived().AlwaysRebuild() || |
| 2638 | Typedef != T->getDecl()) { |
| 2639 | Result = getDerived().RebuildTypedefType(Typedef); |
| 2640 | if (Result.isNull()) |
| 2641 | return QualType(); |
| 2642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2643 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2644 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 2645 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2646 | |
| 2647 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2648 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2649 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2650 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2651 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 2652 | TypeOfExprTypeLoc TL) { |
| 2653 | TypeOfExprType *T = TL.getTypePtr(); |
| 2654 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2655 | // typeof expressions are not potentially evaluated contexts |
| 2656 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2657 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2658 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2659 | if (E.isInvalid()) |
| 2660 | return QualType(); |
| 2661 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2662 | QualType Result = TL.getType(); |
| 2663 | if (getDerived().AlwaysRebuild() || |
| 2664 | E.get() != T->getUnderlyingExpr()) { |
| 2665 | Result = getDerived().RebuildTypeOfExprType(move(E)); |
| 2666 | if (Result.isNull()) |
| 2667 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2668 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2669 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2670 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2671 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 2672 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2673 | |
| 2674 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2675 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2676 | |
| 2677 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2678 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 2679 | TypeOfTypeLoc TL) { |
| 2680 | TypeOfType *T = TL.getTypePtr(); |
| 2681 | |
| 2682 | // FIXME: should be an inner type, or at least have a DeclaratorInfo. |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2683 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2684 | if (Underlying.isNull()) |
| 2685 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2686 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2687 | QualType Result = TL.getType(); |
| 2688 | if (getDerived().AlwaysRebuild() || |
| 2689 | Underlying != T->getUnderlyingType()) { |
| 2690 | Result = getDerived().RebuildTypeOfType(Underlying); |
| 2691 | if (Result.isNull()) |
| 2692 | return QualType(); |
| 2693 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2694 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2695 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 2696 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2697 | |
| 2698 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
| 2701 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2702 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 2703 | DecltypeTypeLoc TL) { |
| 2704 | DecltypeType *T = TL.getTypePtr(); |
| 2705 | |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 2706 | // decltype expressions are not potentially evaluated contexts |
| 2707 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2708 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2709 | Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 2710 | if (E.isInvalid()) |
| 2711 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2712 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2713 | QualType Result = TL.getType(); |
| 2714 | if (getDerived().AlwaysRebuild() || |
| 2715 | E.get() != T->getUnderlyingExpr()) { |
| 2716 | Result = getDerived().RebuildDecltypeType(move(E)); |
| 2717 | if (Result.isNull()) |
| 2718 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2719 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2720 | else E.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2722 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 2723 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2724 | |
| 2725 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2729 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 2730 | RecordTypeLoc TL) { |
| 2731 | RecordType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2732 | RecordDecl *Record |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2733 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2734 | if (!Record) |
| 2735 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2736 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2737 | QualType Result = TL.getType(); |
| 2738 | if (getDerived().AlwaysRebuild() || |
| 2739 | Record != T->getDecl()) { |
| 2740 | Result = getDerived().RebuildRecordType(Record); |
| 2741 | if (Result.isNull()) |
| 2742 | return QualType(); |
| 2743 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2744 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2745 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 2746 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2747 | |
| 2748 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2749 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2750 | |
| 2751 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2752 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 2753 | EnumTypeLoc TL) { |
| 2754 | EnumType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2755 | EnumDecl *Enum |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2756 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl())); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2757 | if (!Enum) |
| 2758 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2759 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2760 | QualType Result = TL.getType(); |
| 2761 | if (getDerived().AlwaysRebuild() || |
| 2762 | Enum != T->getDecl()) { |
| 2763 | Result = getDerived().RebuildEnumType(Enum); |
| 2764 | if (Result.isNull()) |
| 2765 | return QualType(); |
| 2766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2767 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2768 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 2769 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2770 | |
| 2771 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2772 | } |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2773 | |
| 2774 | template <typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2775 | QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 2776 | ElaboratedTypeLoc TL) { |
| 2777 | ElaboratedType *T = TL.getTypePtr(); |
| 2778 | |
| 2779 | // FIXME: this should be a nested type. |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2780 | QualType Underlying = getDerived().TransformType(T->getUnderlyingType()); |
| 2781 | if (Underlying.isNull()) |
| 2782 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2783 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2784 | QualType Result = TL.getType(); |
| 2785 | if (getDerived().AlwaysRebuild() || |
| 2786 | Underlying != T->getUnderlyingType()) { |
| 2787 | Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind()); |
| 2788 | if (Result.isNull()) |
| 2789 | return QualType(); |
| 2790 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2791 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2792 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 2793 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2794 | |
| 2795 | return Result; |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2796 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2797 | |
| 2798 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2799 | template<typename Derived> |
| 2800 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2801 | TypeLocBuilder &TLB, |
| 2802 | TemplateTypeParmTypeLoc TL) { |
| 2803 | return TransformTypeSpecType(TLB, TL); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2804 | } |
| 2805 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2806 | template<typename Derived> |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2807 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2808 | TypeLocBuilder &TLB, |
| 2809 | SubstTemplateTypeParmTypeLoc TL) { |
| 2810 | return TransformTypeSpecType(TLB, TL); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | template<typename Derived> |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2814 | inline QualType |
| 2815 | TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2816 | TypeLocBuilder &TLB, |
| 2817 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2818 | return TransformTemplateSpecializationType(TLB, TL, QualType()); |
| 2819 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2820 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2821 | template<typename Derived> |
| 2822 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 2823 | const TemplateSpecializationType *TST, |
| 2824 | QualType ObjectType) { |
| 2825 | // FIXME: this entire method is a temporary workaround; callers |
| 2826 | // should be rewritten to provide real type locs. |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2827 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2828 | // Fake up a TemplateSpecializationTypeLoc. |
| 2829 | TypeLocBuilder TLB; |
| 2830 | TemplateSpecializationTypeLoc TL |
| 2831 | = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0)); |
| 2832 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 2833 | SourceLocation BaseLoc = getDerived().getBaseLocation(); |
| 2834 | |
| 2835 | TL.setTemplateNameLoc(BaseLoc); |
| 2836 | TL.setLAngleLoc(BaseLoc); |
| 2837 | TL.setRAngleLoc(BaseLoc); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2838 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
| 2839 | const TemplateArgument &TA = TST->getArg(i); |
| 2840 | TemplateArgumentLoc TAL; |
| 2841 | getDerived().InventTemplateArgumentLoc(TA, TAL); |
| 2842 | TL.setArgLocInfo(i, TAL.getLocInfo()); |
| 2843 | } |
| 2844 | |
| 2845 | TypeLocBuilder IgnoredTLB; |
| 2846 | return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType); |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | template<typename Derived> |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2850 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2851 | TypeLocBuilder &TLB, |
| 2852 | TemplateSpecializationTypeLoc TL, |
| 2853 | QualType ObjectType) { |
| 2854 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 2855 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2856 | TemplateName Template |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 2857 | = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2858 | if (Template.isNull()) |
| 2859 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2860 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2861 | TemplateArgumentListInfo NewTemplateArgs; |
| 2862 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 2863 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 2864 | |
| 2865 | for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) { |
| 2866 | TemplateArgumentLoc Loc; |
| 2867 | if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc)) |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2868 | return QualType(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2869 | NewTemplateArgs.addArgument(Loc); |
| 2870 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2871 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2872 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 2873 | |
| 2874 | QualType Result = |
| 2875 | getDerived().RebuildTemplateSpecializationType(Template, |
| 2876 | TL.getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2877 | NewTemplateArgs); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2878 | |
| 2879 | if (!Result.isNull()) { |
| 2880 | TemplateSpecializationTypeLoc NewTL |
| 2881 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 2882 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 2883 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 2884 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 2885 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 2886 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2888 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2889 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2890 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | |
| 2892 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2893 | QualType |
| 2894 | TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB, |
| 2895 | QualifiedNameTypeLoc TL) { |
| 2896 | QualifiedNameType *T = TL.getTypePtr(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2897 | NestedNameSpecifier *NNS |
| 2898 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), |
| 2899 | SourceRange()); |
| 2900 | if (!NNS) |
| 2901 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2902 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2903 | QualType Named = getDerived().TransformType(T->getNamedType()); |
| 2904 | if (Named.isNull()) |
| 2905 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2906 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2907 | QualType Result = TL.getType(); |
| 2908 | if (getDerived().AlwaysRebuild() || |
| 2909 | NNS != T->getQualifier() || |
| 2910 | Named != T->getNamedType()) { |
| 2911 | Result = getDerived().RebuildQualifiedNameType(NNS, Named); |
| 2912 | if (Result.isNull()) |
| 2913 | return QualType(); |
| 2914 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2915 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2916 | QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result); |
| 2917 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2918 | |
| 2919 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2920 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
| 2922 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2923 | QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB, |
| 2924 | TypenameTypeLoc TL) { |
| 2925 | TypenameType *T = TL.getTypePtr(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2926 | |
| 2927 | /* FIXME: preserve source information better than this */ |
| 2928 | SourceRange SR(TL.getNameLoc()); |
| 2929 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2930 | NestedNameSpecifier *NNS |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2931 | = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2932 | if (!NNS) |
| 2933 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2935 | QualType Result; |
| 2936 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2937 | if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2938 | QualType NewTemplateId |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2939 | = getDerived().TransformType(QualType(TemplateId, 0)); |
| 2940 | if (NewTemplateId.isNull()) |
| 2941 | return QualType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2942 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2943 | if (!getDerived().AlwaysRebuild() && |
| 2944 | NNS == T->getQualifier() && |
| 2945 | NewTemplateId == QualType(TemplateId, 0)) |
| 2946 | return QualType(T, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2947 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2948 | Result = getDerived().RebuildTypenameType(NNS, NewTemplateId); |
| 2949 | } else { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2950 | Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2951 | } |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2952 | if (Result.isNull()) |
| 2953 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2954 | |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2955 | TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result); |
| 2956 | NewTL.setNameLoc(TL.getNameLoc()); |
| 2957 | |
| 2958 | return Result; |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2959 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2960 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2961 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2962 | QualType |
| 2963 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 2964 | ObjCInterfaceTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2965 | assert(false && "TransformObjCInterfaceType unimplemented"); |
| 2966 | return QualType(); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2967 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2968 | |
| 2969 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 2970 | QualType |
| 2971 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 2972 | ObjCObjectPointerTypeLoc TL) { |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 2973 | assert(false && "TransformObjCObjectPointerType unimplemented"); |
| 2974 | return QualType(); |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2977 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2978 | // Statement transformation |
| 2979 | //===----------------------------------------------------------------------===// |
| 2980 | template<typename Derived> |
| 2981 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2982 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 2983 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | template<typename Derived> |
| 2987 | Sema::OwningStmtResult |
| 2988 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 2989 | return getDerived().TransformCompoundStmt(S, false); |
| 2990 | } |
| 2991 | |
| 2992 | template<typename Derived> |
| 2993 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2995 | bool IsStmtExpr) { |
| 2996 | bool SubStmtChanged = false; |
| 2997 | ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema()); |
| 2998 | for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); |
| 2999 | B != BEnd; ++B) { |
| 3000 | OwningStmtResult Result = getDerived().TransformStmt(*B); |
| 3001 | if (Result.isInvalid()) |
| 3002 | return getSema().StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3003 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3004 | SubStmtChanged = SubStmtChanged || Result.get() != *B; |
| 3005 | Statements.push_back(Result.takeAs<Stmt>()); |
| 3006 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3007 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3008 | if (!getDerived().AlwaysRebuild() && |
| 3009 | !SubStmtChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3010 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3011 | |
| 3012 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 3013 | move_arg(Statements), |
| 3014 | S->getRBracLoc(), |
| 3015 | IsStmtExpr); |
| 3016 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3018 | template<typename Derived> |
| 3019 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3021 | OwningExprResult LHS(SemaRef), RHS(SemaRef); |
| 3022 | { |
| 3023 | // The case value expressions are not potentially evaluated. |
| 3024 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3025 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3026 | // Transform the left-hand case value. |
| 3027 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 3028 | if (LHS.isInvalid()) |
| 3029 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3030 | |
Eli Friedman | 264c1f8 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 3031 | // Transform the right-hand case value (for the GNU case-range extension). |
| 3032 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 3033 | if (RHS.isInvalid()) |
| 3034 | return SemaRef.StmtError(); |
| 3035 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3037 | // Build the case statement. |
| 3038 | // Case statements are always rebuilt so that they will attached to their |
| 3039 | // transformed switch statement. |
| 3040 | OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 3041 | move(LHS), |
| 3042 | S->getEllipsisLoc(), |
| 3043 | move(RHS), |
| 3044 | S->getColonLoc()); |
| 3045 | if (Case.isInvalid()) |
| 3046 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3048 | // Transform the statement following the case |
| 3049 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3050 | if (SubStmt.isInvalid()) |
| 3051 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3053 | // Attach the body to the case statement |
| 3054 | return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); |
| 3055 | } |
| 3056 | |
| 3057 | template<typename Derived> |
| 3058 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3059 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3060 | // Transform the statement following the default case |
| 3061 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3062 | if (SubStmt.isInvalid()) |
| 3063 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3064 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3065 | // Default statements are always rebuilt |
| 3066 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 3067 | move(SubStmt)); |
| 3068 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3069 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3070 | template<typename Derived> |
| 3071 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3073 | OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 3074 | if (SubStmt.isInvalid()) |
| 3075 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3076 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3077 | // FIXME: Pass the real colon location in. |
| 3078 | SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); |
| 3079 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, |
| 3080 | move(SubStmt)); |
| 3081 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3082 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3083 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3084 | Sema::OwningStmtResult |
| 3085 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3086 | // Transform the condition |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3087 | OwningExprResult Cond(SemaRef); |
| 3088 | VarDecl *ConditionVar = 0; |
| 3089 | if (S->getConditionVariable()) { |
| 3090 | ConditionVar |
| 3091 | = cast_or_null<VarDecl>( |
| 3092 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3093 | if (!ConditionVar) |
| 3094 | return SemaRef.StmtError(); |
| 3095 | |
| 3096 | Cond = getSema().CheckConditionVariable(ConditionVar); |
| 3097 | } else |
| 3098 | Cond = getDerived().TransformExpr(S->getCond()); |
| 3099 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3100 | if (Cond.isInvalid()) |
| 3101 | return SemaRef.StmtError(); |
Douglas Gregor | 8cfe5a7 | 2009-11-23 23:44:04 +0000 | [diff] [blame] | 3102 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3103 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3104 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3105 | // Transform the "then" branch. |
| 3106 | OwningStmtResult Then = getDerived().TransformStmt(S->getThen()); |
| 3107 | if (Then.isInvalid()) |
| 3108 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3109 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3110 | // Transform the "else" branch. |
| 3111 | OwningStmtResult Else = getDerived().TransformStmt(S->getElse()); |
| 3112 | if (Else.isInvalid()) |
| 3113 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3114 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3115 | if (!getDerived().AlwaysRebuild() && |
| 3116 | FullCond->get() == S->getCond() && |
| 3117 | Then.get() == S->getThen() && |
| 3118 | Else.get() == S->getElse()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | return SemaRef.Owned(S->Retain()); |
| 3120 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3121 | return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3122 | S->getElseLoc(), move(Else)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | template<typename Derived> |
| 3126 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3127 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3128 | // Transform the condition. |
Douglas Gregor | d3d5301 | 2009-11-24 17:07:59 +0000 | [diff] [blame^] | 3129 | OwningExprResult Cond(SemaRef); |
| 3130 | VarDecl *ConditionVar = 0; |
| 3131 | if (S->getConditionVariable()) { |
| 3132 | ConditionVar |
| 3133 | = cast_or_null<VarDecl>( |
| 3134 | getDerived().TransformDefinition(S->getConditionVariable())); |
| 3135 | if (!ConditionVar) |
| 3136 | return SemaRef.StmtError(); |
| 3137 | |
| 3138 | Cond = getSema().CheckConditionVariable(ConditionVar); |
| 3139 | } else |
| 3140 | Cond = getDerived().TransformExpr(S->getCond()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3141 | if (Cond.isInvalid()) |
| 3142 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3143 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3144 | // Rebuild the switch statement. |
| 3145 | OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond)); |
| 3146 | if (Switch.isInvalid()) |
| 3147 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3148 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3149 | // Transform the body of the switch statement. |
| 3150 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3151 | if (Body.isInvalid()) |
| 3152 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3153 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3154 | // Complete the switch statement. |
| 3155 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), |
| 3156 | move(Body)); |
| 3157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3159 | template<typename Derived> |
| 3160 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3161 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3162 | // Transform the condition |
| 3163 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3164 | if (Cond.isInvalid()) |
| 3165 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3166 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3167 | Sema::FullExprArg FullCond(getSema().FullExpr(Cond)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3169 | // Transform the body |
| 3170 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3171 | if (Body.isInvalid()) |
| 3172 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3173 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3174 | if (!getDerived().AlwaysRebuild() && |
| 3175 | FullCond->get() == S->getCond() && |
| 3176 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3177 | return SemaRef.Owned(S->Retain()); |
| 3178 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3179 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body)); |
| 3180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3181 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3182 | template<typename Derived> |
| 3183 | Sema::OwningStmtResult |
| 3184 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 3185 | // Transform the condition |
| 3186 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3187 | if (Cond.isInvalid()) |
| 3188 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3189 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3190 | // Transform the body |
| 3191 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3192 | if (Body.isInvalid()) |
| 3193 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3195 | if (!getDerived().AlwaysRebuild() && |
| 3196 | Cond.get() == S->getCond() && |
| 3197 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3198 | return SemaRef.Owned(S->Retain()); |
| 3199 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3200 | return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), |
| 3201 | /*FIXME:*/S->getWhileLoc(), move(Cond), |
| 3202 | S->getRParenLoc()); |
| 3203 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3205 | template<typename Derived> |
| 3206 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3207 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3208 | // Transform the initialization statement |
| 3209 | OwningStmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 3210 | if (Init.isInvalid()) |
| 3211 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3212 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3213 | // Transform the condition |
| 3214 | OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 3215 | if (Cond.isInvalid()) |
| 3216 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3217 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3218 | // Transform the increment |
| 3219 | OwningExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 3220 | if (Inc.isInvalid()) |
| 3221 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3222 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3223 | // Transform the body |
| 3224 | OwningStmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 3225 | if (Body.isInvalid()) |
| 3226 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3227 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3228 | if (!getDerived().AlwaysRebuild() && |
| 3229 | Init.get() == S->getInit() && |
| 3230 | Cond.get() == S->getCond() && |
| 3231 | Inc.get() == S->getInc() && |
| 3232 | Body.get() == S->getBody()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 | return SemaRef.Owned(S->Retain()); |
| 3234 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3235 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 3236 | move(Init), move(Cond), move(Inc), |
| 3237 | S->getRParenLoc(), move(Body)); |
| 3238 | } |
| 3239 | |
| 3240 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | Sema::OwningStmtResult |
| 3242 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3243 | // Goto statements must always be rebuilt, to resolve the label. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3244 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3245 | S->getLabel()); |
| 3246 | } |
| 3247 | |
| 3248 | template<typename Derived> |
| 3249 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3250 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3251 | OwningExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 3252 | if (Target.isInvalid()) |
| 3253 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3254 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3255 | if (!getDerived().AlwaysRebuild() && |
| 3256 | Target.get() == S->getTarget()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3257 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3258 | |
| 3259 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 3260 | move(Target)); |
| 3261 | } |
| 3262 | |
| 3263 | template<typename Derived> |
| 3264 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 3266 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3268 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3269 | template<typename Derived> |
| 3270 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3271 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 3272 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3273 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3274 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3275 | template<typename Derived> |
| 3276 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3277 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue()); |
| 3279 | if (Result.isInvalid()) |
| 3280 | return SemaRef.StmtError(); |
| 3281 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 | // FIXME: We always rebuild the return statement because there is no way |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3283 | // to tell whether the return type of the function has changed. |
| 3284 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); |
| 3285 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3287 | template<typename Derived> |
| 3288 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3289 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3290 | bool DeclChanged = false; |
| 3291 | llvm::SmallVector<Decl *, 4> Decls; |
| 3292 | for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); |
| 3293 | D != DEnd; ++D) { |
| 3294 | Decl *Transformed = getDerived().TransformDefinition(*D); |
| 3295 | if (!Transformed) |
| 3296 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3298 | if (Transformed != *D) |
| 3299 | DeclChanged = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3300 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3301 | Decls.push_back(Transformed); |
| 3302 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3303 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3304 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | return SemaRef.Owned(S->Retain()); |
| 3306 | |
| 3307 | return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3308 | S->getStartLoc(), S->getEndLoc()); |
| 3309 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3310 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3311 | template<typename Derived> |
| 3312 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3313 | TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3314 | assert(false && "SwitchCase is abstract and cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | template<typename Derived> |
| 3319 | Sema::OwningStmtResult |
| 3320 | TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { |
| 3321 | // FIXME: Implement! |
| 3322 | assert(false && "Inline assembly cannot be transformed"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3323 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | template<typename Derived> |
| 3328 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3329 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3330 | // FIXME: Implement this |
| 3331 | assert(false && "Cannot transform an Objective-C @try statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3333 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3334 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3335 | template<typename Derived> |
| 3336 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3337 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3338 | // FIXME: Implement this |
| 3339 | assert(false && "Cannot transform an Objective-C @catch statement"); |
| 3340 | return SemaRef.Owned(S->Retain()); |
| 3341 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3342 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3343 | template<typename Derived> |
| 3344 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3345 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | // FIXME: Implement this |
| 3347 | assert(false && "Cannot transform an Objective-C @finally statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3350 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3351 | template<typename Derived> |
| 3352 | Sema::OwningStmtResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3353 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | // FIXME: Implement this |
| 3355 | assert(false && "Cannot transform an Objective-C @throw statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3357 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3358 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3359 | template<typename Derived> |
| 3360 | Sema::OwningStmtResult |
| 3361 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | ObjCAtSynchronizedStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | // FIXME: Implement this |
| 3364 | assert(false && "Cannot transform an Objective-C @synchronized statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | template<typename Derived> |
| 3369 | Sema::OwningStmtResult |
| 3370 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3371 | ObjCForCollectionStmt *S) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3372 | // FIXME: Implement this |
| 3373 | assert(false && "Cannot transform an Objective-C for-each statement"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3374 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | |
| 3378 | template<typename Derived> |
| 3379 | Sema::OwningStmtResult |
| 3380 | TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 3381 | // Transform the exception declaration, if any. |
| 3382 | VarDecl *Var = 0; |
| 3383 | if (S->getExceptionDecl()) { |
| 3384 | VarDecl *ExceptionDecl = S->getExceptionDecl(); |
| 3385 | TemporaryBase Rebase(*this, ExceptionDecl->getLocation(), |
| 3386 | ExceptionDecl->getDeclName()); |
| 3387 | |
| 3388 | QualType T = getDerived().TransformType(ExceptionDecl->getType()); |
| 3389 | if (T.isNull()) |
| 3390 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3391 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3392 | Var = getDerived().RebuildExceptionDecl(ExceptionDecl, |
| 3393 | T, |
| 3394 | ExceptionDecl->getDeclaratorInfo(), |
| 3395 | ExceptionDecl->getIdentifier(), |
| 3396 | ExceptionDecl->getLocation(), |
| 3397 | /*FIXME: Inaccurate*/ |
| 3398 | SourceRange(ExceptionDecl->getLocation())); |
| 3399 | if (!Var || Var->isInvalidDecl()) { |
| 3400 | if (Var) |
| 3401 | Var->Destroy(SemaRef.Context); |
| 3402 | return SemaRef.StmtError(); |
| 3403 | } |
| 3404 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3405 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3406 | // Transform the actual exception handler. |
| 3407 | OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 3408 | if (Handler.isInvalid()) { |
| 3409 | if (Var) |
| 3410 | Var->Destroy(SemaRef.Context); |
| 3411 | return SemaRef.StmtError(); |
| 3412 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3413 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3414 | if (!getDerived().AlwaysRebuild() && |
| 3415 | !Var && |
| 3416 | Handler.get() == S->getHandlerBlock()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3417 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3418 | |
| 3419 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), |
| 3420 | Var, |
| 3421 | move(Handler)); |
| 3422 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3423 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3424 | template<typename Derived> |
| 3425 | Sema::OwningStmtResult |
| 3426 | TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 3427 | // Transform the try block itself. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3428 | OwningStmtResult TryBlock |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3429 | = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 3430 | if (TryBlock.isInvalid()) |
| 3431 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3432 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3433 | // Transform the handlers. |
| 3434 | bool HandlerChanged = false; |
| 3435 | ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef); |
| 3436 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3437 | OwningStmtResult Handler |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3438 | = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 3439 | if (Handler.isInvalid()) |
| 3440 | return SemaRef.StmtError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3441 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3442 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 3443 | Handlers.push_back(Handler.takeAs<Stmt>()); |
| 3444 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3445 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3446 | if (!getDerived().AlwaysRebuild() && |
| 3447 | TryBlock.get() == S->getTryBlock() && |
| 3448 | !HandlerChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | return SemaRef.Owned(S->Retain()); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3450 | |
| 3451 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3452 | move_arg(Handlers)); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3453 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3454 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3455 | //===----------------------------------------------------------------------===// |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3456 | // Expression transformation |
| 3457 | //===----------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3458 | template<typename Derived> |
| 3459 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3460 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E, |
| 3461 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3463 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3464 | |
| 3465 | template<typename Derived> |
| 3466 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3467 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E, |
| 3468 | bool isAddressOfOperand) { |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3469 | NestedNameSpecifier *Qualifier = 0; |
| 3470 | if (E->getQualifier()) { |
| 3471 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3472 | E->getQualifierRange()); |
| 3473 | if (!Qualifier) |
| 3474 | return SemaRef.ExprError(); |
| 3475 | } |
| 3476 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3477 | NamedDecl *ND |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3478 | = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl())); |
| 3479 | if (!ND) |
| 3480 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3481 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3482 | if (!getDerived().AlwaysRebuild() && |
| 3483 | Qualifier == E->getQualifier() && |
| 3484 | ND == E->getDecl() && |
| 3485 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3486 | return SemaRef.Owned(E->Retain()); |
| 3487 | |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3488 | // FIXME: We're losing the explicit template arguments in this transformation. |
| 3489 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3490 | llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs()); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3491 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3492 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], |
| 3493 | TransArgs[I])) |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3494 | return SemaRef.ExprError(); |
Douglas Gregor | a2813ce | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | // FIXME: Pass the qualifier/qualifier range along. |
| 3498 | return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3499 | ND, E->getLocation(), |
| 3500 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3502 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3503 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3504 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3505 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E, |
| 3506 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3507 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3508 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3509 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3510 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3511 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3512 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E, |
| 3513 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3514 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3515 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3516 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3517 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3518 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3519 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E, |
| 3520 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3521 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3524 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3525 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3526 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E, |
| 3527 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3528 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3529 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3531 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3532 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3533 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E, |
| 3534 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3535 | return SemaRef.Owned(E->Retain()); |
| 3536 | } |
| 3537 | |
| 3538 | template<typename Derived> |
| 3539 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3540 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E, |
| 3541 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3542 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3543 | if (SubExpr.isInvalid()) |
| 3544 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3545 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3546 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3547 | return SemaRef.Owned(E->Retain()); |
| 3548 | |
| 3549 | return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3550 | E->getRParen()); |
| 3551 | } |
| 3552 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3553 | template<typename Derived> |
| 3554 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3555 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E, |
| 3556 | bool isAddressOfOperand) { |
| 3557 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(), |
| 3558 | E->getOpcode() == UnaryOperator::AddrOf); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3559 | if (SubExpr.isInvalid()) |
| 3560 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3561 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3562 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3563 | return SemaRef.Owned(E->Retain()); |
| 3564 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3565 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 3566 | E->getOpcode(), |
| 3567 | move(SubExpr)); |
| 3568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3569 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3570 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3571 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3572 | TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E, |
| 3573 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3574 | if (E->isArgumentType()) { |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3575 | DeclaratorInfo *OldT = E->getArgumentTypeInfo(); |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3576 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3577 | DeclaratorInfo *NewT = getDerived().TransformType(OldT); |
| 3578 | if (!NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3579 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3580 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3581 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3582 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3583 | |
John McCall | 5ab7517 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 3584 | return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3585 | E->isSizeOf(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3586 | E->getSourceRange()); |
| 3587 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3588 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3589 | Sema::OwningExprResult SubExpr(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3591 | // C++0x [expr.sizeof]p1: |
| 3592 | // The operand is either an expression, which is an unevaluated operand |
| 3593 | // [...] |
| 3594 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3596 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 3597 | if (SubExpr.isInvalid()) |
| 3598 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3600 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 3601 | return SemaRef.Owned(E->Retain()); |
| 3602 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3604 | return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), |
| 3605 | E->isSizeOf(), |
| 3606 | E->getSourceRange()); |
| 3607 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3608 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3609 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3610 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3611 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E, |
| 3612 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3613 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3614 | if (LHS.isInvalid()) |
| 3615 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3616 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3617 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3618 | if (RHS.isInvalid()) |
| 3619 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3620 | |
| 3621 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3622 | if (!getDerived().AlwaysRebuild() && |
| 3623 | LHS.get() == E->getLHS() && |
| 3624 | RHS.get() == E->getRHS()) |
| 3625 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3626 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3627 | return getDerived().RebuildArraySubscriptExpr(move(LHS), |
| 3628 | /*FIXME:*/E->getLHS()->getLocStart(), |
| 3629 | move(RHS), |
| 3630 | E->getRBracketLoc()); |
| 3631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3632 | |
| 3633 | template<typename Derived> |
| 3634 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3635 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E, |
| 3636 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3637 | // Transform the callee. |
| 3638 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 3639 | if (Callee.isInvalid()) |
| 3640 | return SemaRef.ExprError(); |
| 3641 | |
| 3642 | // Transform arguments. |
| 3643 | bool ArgChanged = false; |
| 3644 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 3645 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 3646 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 3647 | OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I)); |
| 3648 | if (Arg.isInvalid()) |
| 3649 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3650 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3651 | // FIXME: Wrong source location information for the ','. |
| 3652 | FakeCommaLocs.push_back( |
| 3653 | SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3654 | |
| 3655 | ArgChanged = ArgChanged || Arg.get() != E->getArg(I); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3656 | Args.push_back(Arg.takeAs<Expr>()); |
| 3657 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3658 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3659 | if (!getDerived().AlwaysRebuild() && |
| 3660 | Callee.get() == E->getCallee() && |
| 3661 | !ArgChanged) |
| 3662 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3663 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3664 | // FIXME: Wrong source location information for the '('. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3665 | SourceLocation FakeLParenLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3666 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 3667 | return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, |
| 3668 | move_arg(Args), |
| 3669 | FakeCommaLocs.data(), |
| 3670 | E->getRParenLoc()); |
| 3671 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | |
| 3673 | template<typename Derived> |
| 3674 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3675 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E, |
| 3676 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3677 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3678 | if (Base.isInvalid()) |
| 3679 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3680 | |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3681 | NestedNameSpecifier *Qualifier = 0; |
| 3682 | if (E->hasQualifier()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3683 | Qualifier |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3684 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 3685 | E->getQualifierRange()); |
Douglas Gregor | c4bf26f | 2009-09-01 00:37:14 +0000 | [diff] [blame] | 3686 | if (Qualifier == 0) |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3687 | return SemaRef.ExprError(); |
| 3688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3689 | |
| 3690 | NamedDecl *Member |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3691 | = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl())); |
| 3692 | if (!Member) |
| 3693 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3694 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3695 | if (!getDerived().AlwaysRebuild() && |
| 3696 | Base.get() == E->getBase() && |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3697 | Qualifier == E->getQualifier() && |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3698 | Member == E->getMemberDecl() && |
| 3699 | !E->hasExplicitTemplateArgumentList()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3700 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3701 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3702 | TemplateArgumentListInfo TransArgs; |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3703 | if (E->hasExplicitTemplateArgumentList()) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3704 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 3705 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3706 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3707 | TemplateArgumentLoc Loc; |
| 3708 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3709 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3710 | TransArgs.addArgument(Loc); |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3711 | } |
| 3712 | } |
| 3713 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3714 | // FIXME: Bogus source location for the operator |
| 3715 | SourceLocation FakeOperatorLoc |
| 3716 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 3717 | |
| 3718 | return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, |
| 3719 | E->isArrow(), |
Douglas Gregor | 83f6faf | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 3720 | Qualifier, |
| 3721 | E->getQualifierRange(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3722 | E->getMemberLoc(), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3723 | Member, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 3724 | (E->hasExplicitTemplateArgumentList() |
| 3725 | ? &TransArgs : 0), |
Douglas Gregor | 8a4386b | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 3726 | 0); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3727 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3728 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3729 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3730 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3731 | TreeTransform<Derived>::TransformCastExpr(CastExpr *E, |
| 3732 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3733 | assert(false && "Cannot transform abstract class"); |
| 3734 | return SemaRef.Owned(E->Retain()); |
| 3735 | } |
| 3736 | |
| 3737 | template<typename Derived> |
| 3738 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3739 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E, |
| 3740 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3741 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3742 | if (LHS.isInvalid()) |
| 3743 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3744 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3745 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3746 | if (RHS.isInvalid()) |
| 3747 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3749 | if (!getDerived().AlwaysRebuild() && |
| 3750 | LHS.get() == E->getLHS() && |
| 3751 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3752 | return SemaRef.Owned(E->Retain()); |
| 3753 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3754 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 3755 | move(LHS), move(RHS)); |
| 3756 | } |
| 3757 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3758 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3759 | Sema::OwningExprResult |
| 3760 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3761 | CompoundAssignOperator *E, |
| 3762 | bool isAddressOfOperand) { |
| 3763 | return getDerived().TransformBinaryOperator(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3764 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3765 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3766 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3767 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3768 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E, |
| 3769 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3770 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 3771 | if (Cond.isInvalid()) |
| 3772 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3773 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3774 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 3775 | if (LHS.isInvalid()) |
| 3776 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3777 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3778 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 3779 | if (RHS.isInvalid()) |
| 3780 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3781 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3782 | if (!getDerived().AlwaysRebuild() && |
| 3783 | Cond.get() == E->getCond() && |
| 3784 | LHS.get() == E->getLHS() && |
| 3785 | RHS.get() == E->getRHS()) |
| 3786 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3787 | |
| 3788 | return getDerived().RebuildConditionalOperator(move(Cond), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3789 | E->getQuestionLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3790 | move(LHS), |
Douglas Gregor | 47e1f7c | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 3791 | E->getColonLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3792 | move(RHS)); |
| 3793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3794 | |
| 3795 | template<typename Derived> |
| 3796 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3797 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E, |
| 3798 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 3799 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 3800 | |
| 3801 | // FIXME: Will we ever have type information here? It seems like we won't, |
| 3802 | // so do we even need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3803 | QualType T = getDerived().TransformType(E->getType()); |
| 3804 | if (T.isNull()) |
| 3805 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3806 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3807 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3808 | if (SubExpr.isInvalid()) |
| 3809 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3810 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3811 | if (!getDerived().AlwaysRebuild() && |
| 3812 | T == E->getType() && |
| 3813 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | return SemaRef.Owned(E->Retain()); |
| 3815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3816 | return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3817 | move(SubExpr), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3818 | E->isLvalueCast()); |
| 3819 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3821 | template<typename Derived> |
| 3822 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3823 | TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E, |
| 3824 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3825 | assert(false && "Cannot transform abstract class"); |
| 3826 | return SemaRef.Owned(E->Retain()); |
| 3827 | } |
| 3828 | |
| 3829 | template<typename Derived> |
| 3830 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3831 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E, |
| 3832 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3833 | QualType T; |
| 3834 | { |
| 3835 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3836 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3837 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3838 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3840 | T = getDerived().TransformType(E->getTypeAsWritten()); |
| 3841 | if (T.isNull()) |
| 3842 | return SemaRef.ExprError(); |
| 3843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3845 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 3846 | if (SubExpr.isInvalid()) |
| 3847 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3848 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3849 | if (!getDerived().AlwaysRebuild() && |
| 3850 | T == E->getTypeAsWritten() && |
| 3851 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3852 | return SemaRef.Owned(E->Retain()); |
| 3853 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3854 | return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T, |
| 3855 | E->getRParenLoc(), |
| 3856 | move(SubExpr)); |
| 3857 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3858 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3859 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3861 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E, |
| 3862 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3863 | QualType T; |
| 3864 | { |
| 3865 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3866 | SourceLocation FakeTypeLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3867 | = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc()); |
| 3868 | TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3869 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3870 | T = getDerived().TransformType(E->getType()); |
| 3871 | if (T.isNull()) |
| 3872 | return SemaRef.ExprError(); |
| 3873 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3874 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3875 | OwningExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 3876 | if (Init.isInvalid()) |
| 3877 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3878 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3879 | if (!getDerived().AlwaysRebuild() && |
| 3880 | T == E->getType() && |
| 3881 | Init.get() == E->getInitializer()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3882 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3883 | |
| 3884 | return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T, |
| 3885 | /*FIXME:*/E->getInitializer()->getLocEnd(), |
| 3886 | move(Init)); |
| 3887 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3888 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3889 | template<typename Derived> |
| 3890 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3891 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E, |
| 3892 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3893 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 3894 | if (Base.isInvalid()) |
| 3895 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3897 | if (!getDerived().AlwaysRebuild() && |
| 3898 | Base.get() == E->getBase()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3899 | return SemaRef.Owned(E->Retain()); |
| 3900 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3901 | // FIXME: Bad source location |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3902 | SourceLocation FakeOperatorLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3903 | = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); |
| 3904 | return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, |
| 3905 | E->getAccessorLoc(), |
| 3906 | E->getAccessor()); |
| 3907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3908 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3909 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3910 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3911 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E, |
| 3912 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3913 | bool InitChanged = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3914 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3915 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 3916 | for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) { |
| 3917 | OwningExprResult Init = getDerived().TransformExpr(E->getInit(I)); |
| 3918 | if (Init.isInvalid()) |
| 3919 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3920 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3921 | InitChanged = InitChanged || Init.get() != E->getInit(I); |
| 3922 | Inits.push_back(Init.takeAs<Expr>()); |
| 3923 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3924 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3925 | if (!getDerived().AlwaysRebuild() && !InitChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | return SemaRef.Owned(E->Retain()); |
| 3927 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3928 | return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), |
Douglas Gregor | e48319a | 2009-11-09 17:16:50 +0000 | [diff] [blame] | 3929 | E->getRBraceLoc(), E->getType()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3930 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3931 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3932 | template<typename Derived> |
| 3933 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 3934 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E, |
| 3935 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3936 | Designation Desig; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3938 | // transform the initializer value |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3939 | OwningExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 3940 | if (Init.isInvalid()) |
| 3941 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3943 | // transform the designators. |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3944 | ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef); |
| 3945 | bool ExprChanged = false; |
| 3946 | for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), |
| 3947 | DEnd = E->designators_end(); |
| 3948 | D != DEnd; ++D) { |
| 3949 | if (D->isFieldDesignator()) { |
| 3950 | Desig.AddDesignator(Designator::getField(D->getFieldName(), |
| 3951 | D->getDotLoc(), |
| 3952 | D->getFieldLoc())); |
| 3953 | continue; |
| 3954 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3955 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3956 | if (D->isArrayDesignator()) { |
| 3957 | OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); |
| 3958 | if (Index.isInvalid()) |
| 3959 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
| 3961 | Desig.AddDesignator(Designator::getArray(Index.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3962 | D->getLBracketLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3963 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3964 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); |
| 3965 | ArrayExprs.push_back(Index.release()); |
| 3966 | continue; |
| 3967 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3968 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3969 | assert(D->isArrayRangeDesignator() && "New kind of designator?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3970 | OwningExprResult Start |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3971 | = getDerived().TransformExpr(E->getArrayRangeStart(*D)); |
| 3972 | if (Start.isInvalid()) |
| 3973 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3974 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3975 | OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); |
| 3976 | if (End.isInvalid()) |
| 3977 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
| 3979 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3980 | End.get(), |
| 3981 | D->getLBracketLoc(), |
| 3982 | D->getEllipsisLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3984 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || |
| 3985 | End.get() != E->getArrayRangeEnd(*D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3986 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3987 | ArrayExprs.push_back(Start.release()); |
| 3988 | ArrayExprs.push_back(End.release()); |
| 3989 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3990 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3991 | if (!getDerived().AlwaysRebuild() && |
| 3992 | Init.get() == E->getInit() && |
| 3993 | !ExprChanged) |
| 3994 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3995 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3996 | return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), |
| 3997 | E->getEqualOrColonLoc(), |
| 3998 | E->usesGNUSyntax(), move(Init)); |
| 3999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4002 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4003 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4004 | ImplicitValueInitExpr *E, |
| 4005 | bool isAddressOfOperand) { |
Douglas Gregor | 5557b25 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 4006 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4007 | |
| 4008 | // FIXME: Will we ever have proper type location here? Will we actually |
| 4009 | // need to transform the type? |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4010 | QualType T = getDerived().TransformType(E->getType()); |
| 4011 | if (T.isNull()) |
| 4012 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4013 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4014 | if (!getDerived().AlwaysRebuild() && |
| 4015 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4016 | return SemaRef.Owned(E->Retain()); |
| 4017 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4018 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 4019 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4020 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4021 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4023 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E, |
| 4024 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4025 | // FIXME: Do we want the type as written? |
| 4026 | QualType T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4027 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4028 | { |
| 4029 | // FIXME: Source location isn't quite accurate. |
| 4030 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
| 4031 | T = getDerived().TransformType(E->getType()); |
| 4032 | if (T.isNull()) |
| 4033 | return SemaRef.ExprError(); |
| 4034 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4035 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4036 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4037 | if (SubExpr.isInvalid()) |
| 4038 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4039 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4040 | if (!getDerived().AlwaysRebuild() && |
| 4041 | T == E->getType() && |
| 4042 | SubExpr.get() == E->getSubExpr()) |
| 4043 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4045 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), |
| 4046 | T, E->getRParenLoc()); |
| 4047 | } |
| 4048 | |
| 4049 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4050 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4051 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E, |
| 4052 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4053 | bool ArgumentChanged = false; |
| 4054 | ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef); |
| 4055 | for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) { |
| 4056 | OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I)); |
| 4057 | if (Init.isInvalid()) |
| 4058 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4059 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4060 | ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); |
| 4061 | Inits.push_back(Init.takeAs<Expr>()); |
| 4062 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4063 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4064 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 4065 | move_arg(Inits), |
| 4066 | E->getRParenLoc()); |
| 4067 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4069 | /// \brief Transform an address-of-label expression. |
| 4070 | /// |
| 4071 | /// By default, the transformation of an address-of-label expression always |
| 4072 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 4073 | /// the corresponding label statement by semantic analysis. |
| 4074 | template<typename Derived> |
| 4075 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4076 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E, |
| 4077 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4078 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 4079 | E->getLabel()); |
| 4080 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4081 | |
| 4082 | template<typename Derived> |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4083 | Sema::OwningExprResult |
| 4084 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E, |
| 4085 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4086 | OwningStmtResult SubStmt |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4087 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 4088 | if (SubStmt.isInvalid()) |
| 4089 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4090 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4091 | if (!getDerived().AlwaysRebuild() && |
| 4092 | SubStmt.get() == E->getSubStmt()) |
| 4093 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4094 | |
| 4095 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4096 | move(SubStmt), |
| 4097 | E->getRParenLoc()); |
| 4098 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4099 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4100 | template<typename Derived> |
| 4101 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4102 | TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E, |
| 4103 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4104 | QualType T1, T2; |
| 4105 | { |
| 4106 | // FIXME: Source location isn't quite accurate. |
| 4107 | TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4108 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4109 | T1 = getDerived().TransformType(E->getArgType1()); |
| 4110 | if (T1.isNull()) |
| 4111 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4112 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4113 | T2 = getDerived().TransformType(E->getArgType2()); |
| 4114 | if (T2.isNull()) |
| 4115 | return SemaRef.ExprError(); |
| 4116 | } |
| 4117 | |
| 4118 | if (!getDerived().AlwaysRebuild() && |
| 4119 | T1 == E->getArgType1() && |
| 4120 | T2 == E->getArgType2()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4121 | return SemaRef.Owned(E->Retain()); |
| 4122 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4123 | return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(), |
| 4124 | T1, T2, E->getRParenLoc()); |
| 4125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4126 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4127 | template<typename Derived> |
| 4128 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4129 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E, |
| 4130 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4131 | OwningExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 4132 | if (Cond.isInvalid()) |
| 4133 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4134 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4135 | OwningExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 4136 | if (LHS.isInvalid()) |
| 4137 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4138 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4139 | OwningExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 4140 | if (RHS.isInvalid()) |
| 4141 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4142 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4143 | if (!getDerived().AlwaysRebuild() && |
| 4144 | Cond.get() == E->getCond() && |
| 4145 | LHS.get() == E->getLHS() && |
| 4146 | RHS.get() == E->getRHS()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4147 | return SemaRef.Owned(E->Retain()); |
| 4148 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4149 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 4150 | move(Cond), move(LHS), move(RHS), |
| 4151 | E->getRParenLoc()); |
| 4152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4154 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4155 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4156 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E, |
| 4157 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4158 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | template<typename Derived> |
| 4162 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4163 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E, |
| 4164 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4165 | OwningExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 4166 | if (Callee.isInvalid()) |
| 4167 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4168 | |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4169 | OwningExprResult First |
| 4170 | = getDerived().TransformExpr(E->getArg(0), |
| 4171 | E->getNumArgs() == 1 && E->getOperator() == OO_Amp); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4172 | if (First.isInvalid()) |
| 4173 | return SemaRef.ExprError(); |
| 4174 | |
| 4175 | OwningExprResult Second(SemaRef); |
| 4176 | if (E->getNumArgs() == 2) { |
| 4177 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 4178 | if (Second.isInvalid()) |
| 4179 | return SemaRef.ExprError(); |
| 4180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4181 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4182 | if (!getDerived().AlwaysRebuild() && |
| 4183 | Callee.get() == E->getCallee() && |
| 4184 | First.get() == E->getArg(0) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4185 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 4186 | return SemaRef.Owned(E->Retain()); |
| 4187 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4188 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 4189 | E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4190 | move(Callee), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4191 | move(First), |
| 4192 | move(Second)); |
| 4193 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4194 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4195 | template<typename Derived> |
| 4196 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4197 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E, |
| 4198 | bool isAddressOfOperand) { |
| 4199 | return getDerived().TransformCallExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4200 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4202 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4203 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4204 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E, |
| 4205 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4206 | QualType ExplicitTy; |
| 4207 | { |
| 4208 | // FIXME: Source location isn't quite accurate. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 | SourceLocation TypeStartLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4210 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4211 | TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4212 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4213 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4214 | if (ExplicitTy.isNull()) |
| 4215 | return SemaRef.ExprError(); |
| 4216 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4217 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4218 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4219 | if (SubExpr.isInvalid()) |
| 4220 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4221 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4222 | if (!getDerived().AlwaysRebuild() && |
| 4223 | ExplicitTy == E->getTypeAsWritten() && |
| 4224 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | return SemaRef.Owned(E->Retain()); |
| 4226 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4227 | // FIXME: Poor source location information here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4228 | SourceLocation FakeLAngleLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4229 | = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); |
| 4230 | SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); |
| 4231 | SourceLocation FakeRParenLoc |
| 4232 | = SemaRef.PP.getLocForEndOfToken( |
| 4233 | E->getSubExpr()->getSourceRange().getEnd()); |
| 4234 | return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4235 | E->getStmtClass(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4236 | FakeLAngleLoc, |
| 4237 | ExplicitTy, |
| 4238 | FakeRAngleLoc, |
| 4239 | FakeRAngleLoc, |
| 4240 | move(SubExpr), |
| 4241 | FakeRParenLoc); |
| 4242 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4243 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4244 | template<typename Derived> |
| 4245 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4246 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E, |
| 4247 | bool isAddressOfOperand) { |
| 4248 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4250 | |
| 4251 | template<typename Derived> |
| 4252 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4253 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E, |
| 4254 | bool isAddressOfOperand) { |
| 4255 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4258 | template<typename Derived> |
| 4259 | Sema::OwningExprResult |
| 4260 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4261 | CXXReinterpretCastExpr *E, |
| 4262 | bool isAddressOfOperand) { |
| 4263 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4264 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4266 | template<typename Derived> |
| 4267 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4268 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E, |
| 4269 | bool isAddressOfOperand) { |
| 4270 | return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4272 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4273 | template<typename Derived> |
| 4274 | Sema::OwningExprResult |
| 4275 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4276 | CXXFunctionalCastExpr *E, |
| 4277 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4278 | QualType ExplicitTy; |
| 4279 | { |
| 4280 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4281 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4282 | ExplicitTy = getDerived().TransformType(E->getTypeAsWritten()); |
| 4283 | if (ExplicitTy.isNull()) |
| 4284 | return SemaRef.ExprError(); |
| 4285 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4286 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4287 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4288 | if (SubExpr.isInvalid()) |
| 4289 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4290 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4291 | if (!getDerived().AlwaysRebuild() && |
| 4292 | ExplicitTy == E->getTypeAsWritten() && |
| 4293 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4294 | return SemaRef.Owned(E->Retain()); |
| 4295 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4296 | // FIXME: The end of the type's source range is wrong |
| 4297 | return getDerived().RebuildCXXFunctionalCastExpr( |
| 4298 | /*FIXME:*/SourceRange(E->getTypeBeginLoc()), |
| 4299 | ExplicitTy, |
| 4300 | /*FIXME:*/E->getSubExpr()->getLocStart(), |
| 4301 | move(SubExpr), |
| 4302 | E->getRParenLoc()); |
| 4303 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4304 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4305 | template<typename Derived> |
| 4306 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4307 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E, |
| 4308 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4309 | if (E->isTypeOperand()) { |
| 4310 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4312 | QualType T = getDerived().TransformType(E->getTypeOperand()); |
| 4313 | if (T.isNull()) |
| 4314 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4315 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4316 | if (!getDerived().AlwaysRebuild() && |
| 4317 | T == E->getTypeOperand()) |
| 4318 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4320 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4321 | /*FIXME:*/E->getLocStart(), |
| 4322 | T, |
| 4323 | E->getLocEnd()); |
| 4324 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4325 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4326 | // We don't know whether the expression is potentially evaluated until |
| 4327 | // after we perform semantic analysis, so the expression is potentially |
| 4328 | // potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4330 | Action::PotentiallyPotentiallyEvaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4331 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4332 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 4333 | if (SubExpr.isInvalid()) |
| 4334 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4335 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4336 | if (!getDerived().AlwaysRebuild() && |
| 4337 | SubExpr.get() == E->getExprOperand()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4338 | return SemaRef.Owned(E->Retain()); |
| 4339 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4340 | return getDerived().RebuildCXXTypeidExpr(E->getLocStart(), |
| 4341 | /*FIXME:*/E->getLocStart(), |
| 4342 | move(SubExpr), |
| 4343 | E->getLocEnd()); |
| 4344 | } |
| 4345 | |
| 4346 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4347 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4348 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E, |
| 4349 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4350 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4352 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4353 | template<typename Derived> |
| 4354 | Sema::OwningExprResult |
| 4355 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4356 | CXXNullPtrLiteralExpr *E, |
| 4357 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4358 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4359 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4360 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4361 | template<typename Derived> |
| 4362 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4363 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E, |
| 4364 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4365 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4367 | QualType T = getDerived().TransformType(E->getType()); |
| 4368 | if (T.isNull()) |
| 4369 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4371 | if (!getDerived().AlwaysRebuild() && |
| 4372 | T == E->getType()) |
| 4373 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4374 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4375 | return getDerived().RebuildCXXThisExpr(E->getLocStart(), T); |
| 4376 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4378 | template<typename Derived> |
| 4379 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4380 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E, |
| 4381 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4382 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4383 | if (SubExpr.isInvalid()) |
| 4384 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4386 | if (!getDerived().AlwaysRebuild() && |
| 4387 | SubExpr.get() == E->getSubExpr()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4388 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4389 | |
| 4390 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); |
| 4391 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4392 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4393 | template<typename Derived> |
| 4394 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4395 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E, |
| 4396 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4397 | ParmVarDecl *Param |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4398 | = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam())); |
| 4399 | if (!Param) |
| 4400 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4402 | if (getDerived().AlwaysRebuild() && |
| 4403 | Param == E->getParam()) |
| 4404 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4405 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4406 | return getDerived().RebuildCXXDefaultArgExpr(Param); |
| 4407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4409 | template<typename Derived> |
| 4410 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4411 | TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E, |
| 4412 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4413 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4414 | |
| 4415 | QualType T = getDerived().TransformType(E->getType()); |
| 4416 | if (T.isNull()) |
| 4417 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4418 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4419 | if (!getDerived().AlwaysRebuild() && |
| 4420 | T == E->getType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4421 | return SemaRef.Owned(E->Retain()); |
| 4422 | |
| 4423 | return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4424 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4425 | T, |
| 4426 | E->getRParenLoc()); |
| 4427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4429 | template<typename Derived> |
| 4430 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4431 | TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E, |
| 4432 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4433 | VarDecl *Var |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4434 | = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4435 | if (!Var) |
| 4436 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4438 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4439 | Var == E->getVarDecl()) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4440 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4441 | |
| 4442 | return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4443 | /*FIXME:*/E->getStartLoc(), |
| 4444 | Var); |
| 4445 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4446 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4447 | template<typename Derived> |
| 4448 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4449 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E, |
| 4450 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4451 | // Transform the type that we're allocating |
| 4452 | TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); |
| 4453 | QualType AllocType = getDerived().TransformType(E->getAllocatedType()); |
| 4454 | if (AllocType.isNull()) |
| 4455 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4456 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4457 | // Transform the size of the array we're allocating (if any). |
| 4458 | OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| 4459 | if (ArraySize.isInvalid()) |
| 4460 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4461 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4462 | // Transform the placement arguments (if any). |
| 4463 | bool ArgumentChanged = false; |
| 4464 | ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef); |
| 4465 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 4466 | OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I)); |
| 4467 | if (Arg.isInvalid()) |
| 4468 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4469 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4470 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I); |
| 4471 | PlacementArgs.push_back(Arg.take()); |
| 4472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 4474 | // transform the constructor arguments (if any). |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4475 | ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef); |
| 4476 | for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) { |
| 4477 | OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I)); |
| 4478 | if (Arg.isInvalid()) |
| 4479 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4480 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4481 | ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I); |
| 4482 | ConstructorArgs.push_back(Arg.take()); |
| 4483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4484 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4485 | if (!getDerived().AlwaysRebuild() && |
| 4486 | AllocType == E->getAllocatedType() && |
| 4487 | ArraySize.get() == E->getArraySize() && |
| 4488 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4489 | return SemaRef.Owned(E->Retain()); |
| 4490 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4491 | return getDerived().RebuildCXXNewExpr(E->getLocStart(), |
| 4492 | E->isGlobalNew(), |
| 4493 | /*FIXME:*/E->getLocStart(), |
| 4494 | move_arg(PlacementArgs), |
| 4495 | /*FIXME:*/E->getLocStart(), |
| 4496 | E->isParenTypeId(), |
| 4497 | AllocType, |
| 4498 | /*FIXME:*/E->getLocStart(), |
| 4499 | /*FIXME:*/SourceRange(), |
| 4500 | move(ArraySize), |
| 4501 | /*FIXME:*/E->getLocStart(), |
| 4502 | move_arg(ConstructorArgs), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4503 | E->getLocEnd()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4504 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4505 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4506 | template<typename Derived> |
| 4507 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4508 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E, |
| 4509 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4510 | OwningExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 4511 | if (Operand.isInvalid()) |
| 4512 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4513 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4514 | if (!getDerived().AlwaysRebuild() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | Operand.get() == E->getArgument()) |
| 4516 | return SemaRef.Owned(E->Retain()); |
| 4517 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4518 | return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), |
| 4519 | E->isGlobalDelete(), |
| 4520 | E->isArrayForm(), |
| 4521 | move(Operand)); |
| 4522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4523 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4524 | template<typename Derived> |
| 4525 | Sema::OwningExprResult |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4526 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4527 | CXXPseudoDestructorExpr *E, |
| 4528 | bool isAddressOfOperand) { |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4529 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4530 | if (Base.isInvalid()) |
| 4531 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4532 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4533 | NestedNameSpecifier *Qualifier |
| 4534 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4535 | E->getQualifierRange()); |
| 4536 | if (E->getQualifier() && !Qualifier) |
| 4537 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4538 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4539 | QualType DestroyedType; |
| 4540 | { |
| 4541 | TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName()); |
| 4542 | DestroyedType = getDerived().TransformType(E->getDestroyedType()); |
| 4543 | if (DestroyedType.isNull()) |
| 4544 | return SemaRef.ExprError(); |
| 4545 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4546 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4547 | if (!getDerived().AlwaysRebuild() && |
| 4548 | Base.get() == E->getBase() && |
| 4549 | Qualifier == E->getQualifier() && |
| 4550 | DestroyedType == E->getDestroyedType()) |
| 4551 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4552 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4553 | return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), |
| 4554 | E->getOperatorLoc(), |
| 4555 | E->isArrow(), |
| 4556 | E->getDestroyedTypeLoc(), |
| 4557 | DestroyedType, |
| 4558 | Qualifier, |
| 4559 | E->getQualifierRange()); |
| 4560 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4561 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 4562 | template<typename Derived> |
| 4563 | Sema::OwningExprResult |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4564 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| 4565 | UnresolvedLookupExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4566 | bool isAddressOfOperand) { |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 4567 | // There is no transformation we can apply to an unresolved lookup. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4568 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4569 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4570 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4571 | template<typename Derived> |
| 4572 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4573 | TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E, |
| 4574 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4575 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4576 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4577 | QualType T = getDerived().TransformType(E->getQueriedType()); |
| 4578 | if (T.isNull()) |
| 4579 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4580 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4581 | if (!getDerived().AlwaysRebuild() && |
| 4582 | T == E->getQueriedType()) |
| 4583 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4584 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4585 | // FIXME: Bad location information |
| 4586 | SourceLocation FakeLParenLoc |
| 4587 | = SemaRef.PP.getLocForEndOfToken(E->getLocStart()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4588 | |
| 4589 | return getDerived().RebuildUnaryTypeTrait(E->getTrait(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4590 | E->getLocStart(), |
| 4591 | /*FIXME:*/FakeLParenLoc, |
| 4592 | T, |
| 4593 | E->getLocEnd()); |
| 4594 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4595 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4596 | template<typename Derived> |
| 4597 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4598 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 4599 | DependentScopeDeclRefExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4600 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4601 | NestedNameSpecifier *NNS |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4602 | = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4603 | E->getQualifierRange()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4604 | if (!NNS) |
| 4605 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4606 | |
| 4607 | DeclarationName Name |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4608 | = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation()); |
| 4609 | if (!Name) |
| 4610 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4611 | |
| 4612 | if (!getDerived().AlwaysRebuild() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4613 | NNS == E->getQualifier() && |
| 4614 | Name == E->getDeclName()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4615 | return SemaRef.Owned(E->Retain()); |
| 4616 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4617 | return getDerived().RebuildDependentScopeDeclRefExpr(NNS, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4618 | E->getQualifierRange(), |
| 4619 | Name, |
| 4620 | E->getLocation(), |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4621 | isAddressOfOperand); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | template<typename Derived> |
| 4625 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4626 | TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E, |
| 4627 | bool isAddressOfOperand) { |
Douglas Gregor | fd2300e | 2009-10-29 17:56:10 +0000 | [diff] [blame] | 4628 | TemporaryBase Rebase(*this, E->getTemplateNameLoc(), DeclarationName()); |
| 4629 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4630 | TemplateName Template |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4631 | = getDerived().TransformTemplateName(E->getTemplateName()); |
| 4632 | if (Template.isNull()) |
| 4633 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4634 | |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4635 | NestedNameSpecifier *Qualifier = 0; |
| 4636 | if (E->getQualifier()) { |
| 4637 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4638 | E->getQualifierRange()); |
| 4639 | if (!Qualifier) |
| 4640 | return SemaRef.ExprError(); |
| 4641 | } |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4642 | |
| 4643 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4644 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4645 | TemplateArgumentLoc Loc; |
| 4646 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4647 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4648 | TransArgs.addArgument(Loc); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | // FIXME: Would like to avoid rebuilding if nothing changed, but we can't |
| 4652 | // compare template arguments (yet). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
| 4654 | // FIXME: It's possible that we'll find out now that the template name |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4655 | // actually refers to a type, in which case the caller is actually dealing |
| 4656 | // with a functional cast. Give a reasonable error message! |
Douglas Gregor | f17bb74 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 4657 | return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(), |
| 4658 | Template, E->getTemplateNameLoc(), |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4659 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | template<typename Derived> |
| 4663 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4664 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E, |
| 4665 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4666 | TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); |
| 4667 | |
| 4668 | QualType T = getDerived().TransformType(E->getType()); |
| 4669 | if (T.isNull()) |
| 4670 | return SemaRef.ExprError(); |
| 4671 | |
| 4672 | CXXConstructorDecl *Constructor |
| 4673 | = cast_or_null<CXXConstructorDecl>( |
| 4674 | getDerived().TransformDecl(E->getConstructor())); |
| 4675 | if (!Constructor) |
| 4676 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4677 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4678 | bool ArgumentChanged = false; |
| 4679 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4680 | for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4681 | ArgEnd = E->arg_end(); |
| 4682 | Arg != ArgEnd; ++Arg) { |
| 4683 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4684 | if (TransArg.isInvalid()) |
| 4685 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4686 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4687 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4688 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4689 | } |
| 4690 | |
| 4691 | if (!getDerived().AlwaysRebuild() && |
| 4692 | T == E->getType() && |
| 4693 | Constructor == E->getConstructor() && |
| 4694 | !ArgumentChanged) |
| 4695 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4696 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4697 | return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(), |
| 4698 | move_arg(Args)); |
| 4699 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4700 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4701 | /// \brief Transform a C++ temporary-binding expression. |
| 4702 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4703 | /// The transformation of a temporary-binding expression always attempts to |
| 4704 | /// bind a new temporary variable to its subexpression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4705 | /// subexpression itself did not change, because the temporary variable itself |
| 4706 | /// must be unique. |
| 4707 | template<typename Derived> |
| 4708 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4709 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E, |
| 4710 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4711 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4712 | if (SubExpr.isInvalid()) |
| 4713 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4714 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4715 | return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>()); |
| 4716 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4717 | |
| 4718 | /// \brief Transform a C++ expression that contains temporaries that should |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4719 | /// be destroyed after the expression is evaluated. |
| 4720 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4721 | /// The transformation of a full expression always attempts to build a new |
| 4722 | /// CXXExprWithTemporaries expression, even if the |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4723 | /// subexpression itself did not change, because it will need to capture the |
| 4724 | /// the new temporary variables introduced in the subexpression. |
| 4725 | template<typename Derived> |
| 4726 | Sema::OwningExprResult |
| 4727 | TreeTransform<Derived>::TransformCXXExprWithTemporaries( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4728 | CXXExprWithTemporaries *E, |
| 4729 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4730 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 4731 | if (SubExpr.isInvalid()) |
| 4732 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4733 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4734 | return SemaRef.Owned( |
| 4735 | SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(), |
| 4736 | E->shouldDestroyTemporaries())); |
| 4737 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4739 | template<typename Derived> |
| 4740 | Sema::OwningExprResult |
| 4741 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4742 | CXXTemporaryObjectExpr *E, |
| 4743 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4744 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4745 | QualType T = getDerived().TransformType(E->getType()); |
| 4746 | if (T.isNull()) |
| 4747 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4748 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4749 | CXXConstructorDecl *Constructor |
| 4750 | = cast_or_null<CXXConstructorDecl>( |
| 4751 | getDerived().TransformDecl(E->getConstructor())); |
| 4752 | if (!Constructor) |
| 4753 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4754 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4755 | bool ArgumentChanged = false; |
| 4756 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4757 | Args.reserve(E->getNumArgs()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4758 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4759 | ArgEnd = E->arg_end(); |
| 4760 | Arg != ArgEnd; ++Arg) { |
| 4761 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4762 | if (TransArg.isInvalid()) |
| 4763 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4764 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4765 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4766 | Args.push_back((Expr *)TransArg.release()); |
| 4767 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4768 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4769 | if (!getDerived().AlwaysRebuild() && |
| 4770 | T == E->getType() && |
| 4771 | Constructor == E->getConstructor() && |
| 4772 | !ArgumentChanged) |
| 4773 | return SemaRef.Owned(E->Retain()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4774 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4775 | // FIXME: Bogus location information |
| 4776 | SourceLocation CommaLoc; |
| 4777 | if (Args.size() > 1) { |
| 4778 | Expr *First = (Expr *)Args[0]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4779 | CommaLoc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4780 | = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd()); |
| 4781 | } |
| 4782 | return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(), |
| 4783 | T, |
| 4784 | /*FIXME:*/E->getTypeBeginLoc(), |
| 4785 | move_arg(Args), |
| 4786 | &CommaLoc, |
| 4787 | E->getLocEnd()); |
| 4788 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4789 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4790 | template<typename Derived> |
| 4791 | Sema::OwningExprResult |
| 4792 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4793 | CXXUnresolvedConstructExpr *E, |
| 4794 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4795 | TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName()); |
| 4796 | QualType T = getDerived().TransformType(E->getTypeAsWritten()); |
| 4797 | if (T.isNull()) |
| 4798 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4799 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4800 | bool ArgumentChanged = false; |
| 4801 | ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef); |
| 4802 | llvm::SmallVector<SourceLocation, 8> FakeCommaLocs; |
| 4803 | for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(), |
| 4804 | ArgEnd = E->arg_end(); |
| 4805 | Arg != ArgEnd; ++Arg) { |
| 4806 | OwningExprResult TransArg = getDerived().TransformExpr(*Arg); |
| 4807 | if (TransArg.isInvalid()) |
| 4808 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4809 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4810 | ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; |
| 4811 | FakeCommaLocs.push_back( |
| 4812 | SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); |
| 4813 | Args.push_back(TransArg.takeAs<Expr>()); |
| 4814 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4815 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4816 | if (!getDerived().AlwaysRebuild() && |
| 4817 | T == E->getTypeAsWritten() && |
| 4818 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4819 | return SemaRef.Owned(E->Retain()); |
| 4820 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4821 | // FIXME: we're faking the locations of the commas |
| 4822 | return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(), |
| 4823 | T, |
| 4824 | E->getLParenLoc(), |
| 4825 | move_arg(Args), |
| 4826 | FakeCommaLocs.data(), |
| 4827 | E->getRParenLoc()); |
| 4828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4829 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4830 | template<typename Derived> |
| 4831 | Sema::OwningExprResult |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4832 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 4833 | CXXDependentScopeMemberExpr *E, |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4834 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4835 | // Transform the base of the expression. |
| 4836 | OwningExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 4837 | if (Base.isInvalid()) |
| 4838 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4839 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4840 | // Start the member reference and compute the object's type. |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4841 | Sema::TypeTy *ObjectType = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4842 | Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4843 | E->getOperatorLoc(), |
| 4844 | E->isArrow()? tok::arrow : tok::period, |
| 4845 | ObjectType); |
| 4846 | if (Base.isInvalid()) |
| 4847 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4848 | |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4849 | // Transform the first part of the nested-name-specifier that qualifies |
| 4850 | // the member name. |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4851 | NamedDecl *FirstQualifierInScope |
Douglas Gregor | 6cd2198 | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 4852 | = getDerived().TransformFirstQualifierInScope( |
| 4853 | E->getFirstQualifierFoundInScope(), |
| 4854 | E->getQualifierRange().getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4855 | |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4856 | NestedNameSpecifier *Qualifier = 0; |
| 4857 | if (E->getQualifier()) { |
| 4858 | Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), |
| 4859 | E->getQualifierRange(), |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4860 | QualType::getFromOpaquePtr(ObjectType), |
| 4861 | FirstQualifierInScope); |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4862 | if (!Qualifier) |
| 4863 | return SemaRef.ExprError(); |
| 4864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4865 | |
| 4866 | DeclarationName Name |
Douglas Gregor | dd62b15 | 2009-10-19 22:04:39 +0000 | [diff] [blame] | 4867 | = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(), |
| 4868 | QualType::getFromOpaquePtr(ObjectType)); |
Douglas Gregor | 81499bb | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 4869 | if (!Name) |
| 4870 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4871 | |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4872 | if (!E->hasExplicitTemplateArgumentList()) { |
| 4873 | // This is a reference to a member without an explicitly-specified |
| 4874 | // template argument list. Optimize for this common case. |
| 4875 | if (!getDerived().AlwaysRebuild() && |
| 4876 | Base.get() == E->getBase() && |
| 4877 | Qualifier == E->getQualifier() && |
| 4878 | Name == E->getMember() && |
| 4879 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4880 | return SemaRef.Owned(E->Retain()); |
| 4881 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4882 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4883 | E->isArrow(), |
| 4884 | E->getOperatorLoc(), |
| 4885 | Qualifier, |
| 4886 | E->getQualifierRange(), |
| 4887 | Name, |
| 4888 | E->getMemberLoc(), |
| 4889 | FirstQualifierInScope); |
| 4890 | } |
| 4891 | |
| 4892 | // FIXME: This is an ugly hack, which forces the same template name to |
| 4893 | // be looked up multiple times. Yuck! |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 4894 | TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName()); |
| 4895 | TemplateName OrigTemplateName; |
| 4896 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) |
| 4897 | OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II); |
| 4898 | else |
| 4899 | OrigTemplateName |
| 4900 | = SemaRef.Context.getDependentTemplateName(0, |
| 4901 | Name.getCXXOverloadedOperator()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4902 | |
| 4903 | TemplateName Template |
| 4904 | = getDerived().TransformTemplateName(OrigTemplateName, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4905 | QualType::getFromOpaquePtr(ObjectType)); |
| 4906 | if (Template.isNull()) |
| 4907 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4908 | |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4909 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4910 | for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) { |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4911 | TemplateArgumentLoc Loc; |
| 4912 | if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc)) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4913 | return SemaRef.ExprError(); |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4914 | TransArgs.addArgument(Loc); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4916 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 4917 | return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4918 | E->isArrow(), |
| 4919 | E->getOperatorLoc(), |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 4920 | Qualifier, |
| 4921 | E->getQualifierRange(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4922 | Template, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 4923 | E->getMemberLoc(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 4924 | FirstQualifierInScope, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 4925 | TransArgs); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | template<typename Derived> |
| 4929 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4930 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E, |
| 4931 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4932 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | template<typename Derived> |
| 4936 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4937 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E, |
| 4938 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4939 | // FIXME: poor source location |
| 4940 | TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName()); |
| 4941 | QualType EncodedType = getDerived().TransformType(E->getEncodedType()); |
| 4942 | if (EncodedType.isNull()) |
| 4943 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4945 | if (!getDerived().AlwaysRebuild() && |
| 4946 | EncodedType == E->getEncodedType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4947 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4948 | |
| 4949 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 4950 | EncodedType, |
| 4951 | E->getRParenLoc()); |
| 4952 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4953 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4954 | template<typename Derived> |
| 4955 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4956 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E, |
| 4957 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4958 | // FIXME: Implement this! |
| 4959 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4960 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4963 | template<typename Derived> |
| 4964 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4965 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E, |
| 4966 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4967 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4968 | } |
| 4969 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4970 | template<typename Derived> |
| 4971 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4972 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E, |
| 4973 | bool isAddressOfOperand) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4974 | ObjCProtocolDecl *Protocol |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4975 | = cast_or_null<ObjCProtocolDecl>( |
| 4976 | getDerived().TransformDecl(E->getProtocol())); |
| 4977 | if (!Protocol) |
| 4978 | return SemaRef.ExprError(); |
| 4979 | |
| 4980 | if (!getDerived().AlwaysRebuild() && |
| 4981 | Protocol == E->getProtocol()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4982 | return SemaRef.Owned(E->Retain()); |
| 4983 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4984 | return getDerived().RebuildObjCProtocolExpr(Protocol, |
| 4985 | E->getAtLoc(), |
| 4986 | /*FIXME:*/E->getAtLoc(), |
| 4987 | /*FIXME:*/E->getAtLoc(), |
| 4988 | E->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4989 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4990 | } |
| 4991 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | template<typename Derived> |
| 4993 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 4994 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E, |
| 4995 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4996 | // FIXME: Implement this! |
| 4997 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4998 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 4999 | } |
| 5000 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5001 | template<typename Derived> |
| 5002 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5003 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E, |
| 5004 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5005 | // FIXME: Implement this! |
| 5006 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5007 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5010 | template<typename Derived> |
| 5011 | Sema::OwningExprResult |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 5012 | TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr( |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5013 | ObjCImplicitSetterGetterRefExpr *E, |
| 5014 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5015 | // FIXME: Implement this! |
| 5016 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5017 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5018 | } |
| 5019 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5020 | template<typename Derived> |
| 5021 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5022 | TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E, |
| 5023 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5024 | // FIXME: Implement this! |
| 5025 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5026 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5029 | template<typename Derived> |
| 5030 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5031 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E, |
| 5032 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5033 | // FIXME: Implement this! |
| 5034 | assert(false && "Cannot transform Objective-C expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5035 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5038 | template<typename Derived> |
| 5039 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5040 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E, |
| 5041 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5042 | bool ArgumentChanged = false; |
| 5043 | ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef); |
| 5044 | for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) { |
| 5045 | OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I)); |
| 5046 | if (SubExpr.isInvalid()) |
| 5047 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5048 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5049 | ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); |
| 5050 | SubExprs.push_back(SubExpr.takeAs<Expr>()); |
| 5051 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5052 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5053 | if (!getDerived().AlwaysRebuild() && |
| 5054 | !ArgumentChanged) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5055 | return SemaRef.Owned(E->Retain()); |
| 5056 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5057 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 5058 | move_arg(SubExprs), |
| 5059 | E->getRParenLoc()); |
| 5060 | } |
| 5061 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5062 | template<typename Derived> |
| 5063 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5064 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E, |
| 5065 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5066 | // FIXME: Implement this! |
| 5067 | assert(false && "Cannot transform block expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5068 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5071 | template<typename Derived> |
| 5072 | Sema::OwningExprResult |
Douglas Gregor | c86a6e9 | 2009-11-04 07:01:15 +0000 | [diff] [blame] | 5073 | TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E, |
| 5074 | bool isAddressOfOperand) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5075 | // FIXME: Implement this! |
| 5076 | assert(false && "Cannot transform block-related expressions yet"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5077 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5078 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5079 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5080 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5081 | // Type reconstruction |
| 5082 | //===----------------------------------------------------------------------===// |
| 5083 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5084 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5085 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 5086 | SourceLocation Star) { |
| 5087 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5088 | getDerived().getBaseEntity()); |
| 5089 | } |
| 5090 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5091 | template<typename Derived> |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5092 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 5093 | SourceLocation Star) { |
| 5094 | return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5095 | getDerived().getBaseEntity()); |
| 5096 | } |
| 5097 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5098 | template<typename Derived> |
| 5099 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5100 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 5101 | bool WrittenAsLValue, |
| 5102 | SourceLocation Sigil) { |
| 5103 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(), |
| 5104 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5108 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5109 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 5110 | QualType ClassType, |
| 5111 | SourceLocation Sigil) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5112 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(), |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5113 | Sigil, getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5117 | QualType |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5118 | TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType, |
| 5119 | SourceLocation Sigil) { |
| 5120 | return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil, |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5121 | getDerived().getBaseEntity()); |
| 5122 | } |
| 5123 | |
| 5124 | template<typename Derived> |
| 5125 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5126 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 5127 | ArrayType::ArraySizeModifier SizeMod, |
| 5128 | const llvm::APInt *Size, |
| 5129 | Expr *SizeExpr, |
| 5130 | unsigned IndexTypeQuals, |
| 5131 | SourceRange BracketsRange) { |
| 5132 | if (SizeExpr || !Size) |
| 5133 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 5134 | IndexTypeQuals, BracketsRange, |
| 5135 | getDerived().getBaseEntity()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5136 | |
| 5137 | QualType Types[] = { |
| 5138 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 5139 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 5140 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5141 | }; |
| 5142 | const unsigned NumTypes = sizeof(Types) / sizeof(QualType); |
| 5143 | QualType SizeType; |
| 5144 | for (unsigned I = 0; I != NumTypes; ++I) |
| 5145 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 5146 | SizeType = Types[I]; |
| 5147 | break; |
| 5148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5149 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5150 | if (SizeType.isNull()) |
| 5151 | SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5152 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5153 | IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5154 | return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5155 | IndexTypeQuals, BracketsRange, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5156 | getDerived().getBaseEntity()); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5158 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5159 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5160 | QualType |
| 5161 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5162 | ArrayType::ArraySizeModifier SizeMod, |
| 5163 | const llvm::APInt &Size, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5164 | unsigned IndexTypeQuals, |
| 5165 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5166 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5167 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5171 | QualType |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5172 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5173 | ArrayType::ArraySizeModifier SizeMod, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5174 | unsigned IndexTypeQuals, |
| 5175 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5176 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, |
John McCall | 85737a7 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 5177 | IndexTypeQuals, BracketsRange); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5179 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5180 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5181 | QualType |
| 5182 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5183 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5184 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5185 | unsigned IndexTypeQuals, |
| 5186 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5187 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5188 | SizeExpr.takeAs<Expr>(), |
| 5189 | IndexTypeQuals, BracketsRange); |
| 5190 | } |
| 5191 | |
| 5192 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5193 | QualType |
| 5194 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5195 | ArrayType::ArraySizeModifier SizeMod, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5196 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5197 | unsigned IndexTypeQuals, |
| 5198 | SourceRange BracketsRange) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5199 | return getDerived().RebuildArrayType(ElementType, SizeMod, 0, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5200 | SizeExpr.takeAs<Expr>(), |
| 5201 | IndexTypeQuals, BracketsRange); |
| 5202 | } |
| 5203 | |
| 5204 | template<typename Derived> |
| 5205 | QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 5206 | unsigned NumElements) { |
| 5207 | // FIXME: semantic checking! |
| 5208 | return SemaRef.Context.getVectorType(ElementType, NumElements); |
| 5209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5210 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5211 | template<typename Derived> |
| 5212 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 5213 | unsigned NumElements, |
| 5214 | SourceLocation AttributeLoc) { |
| 5215 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 5216 | NumElements, true); |
| 5217 | IntegerLiteral *VectorSize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5218 | = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5219 | AttributeLoc); |
| 5220 | return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), |
| 5221 | AttributeLoc); |
| 5222 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5223 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5224 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5225 | QualType |
| 5226 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5227 | ExprArg SizeExpr, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5228 | SourceLocation AttributeLoc) { |
| 5229 | return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); |
| 5230 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5231 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5232 | template<typename Derived> |
| 5233 | QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5234 | QualType *ParamTypes, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5235 | unsigned NumParamTypes, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5236 | bool Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5237 | unsigned Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5238 | return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5239 | Quals, |
| 5240 | getDerived().getBaseLocation(), |
| 5241 | getDerived().getBaseEntity()); |
| 5242 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5243 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5244 | template<typename Derived> |
John McCall | a2becad | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5245 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 5246 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 5247 | } |
| 5248 | |
| 5249 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5250 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5251 | return SemaRef.BuildTypeofExprType(E.takeAs<Expr>()); |
| 5252 | } |
| 5253 | |
| 5254 | template<typename Derived> |
| 5255 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 5256 | return SemaRef.Context.getTypeOfType(Underlying); |
| 5257 | } |
| 5258 | |
| 5259 | template<typename Derived> |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5260 | QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5261 | return SemaRef.BuildDecltypeType(E.takeAs<Expr>()); |
| 5262 | } |
| 5263 | |
| 5264 | template<typename Derived> |
| 5265 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5266 | TemplateName Template, |
| 5267 | SourceLocation TemplateNameLoc, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5268 | const TemplateArgumentListInfo &TemplateArgs) { |
| 5269 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5270 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5271 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5272 | template<typename Derived> |
| 5273 | NestedNameSpecifier * |
| 5274 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5275 | SourceRange Range, |
Douglas Gregor | a38c687 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 5276 | IdentifierInfo &II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5277 | QualType ObjectType, |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5278 | NamedDecl *FirstQualifierInScope) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5279 | CXXScopeSpec SS; |
| 5280 | // FIXME: The source location information is all wrong. |
| 5281 | SS.setRange(Range); |
| 5282 | SS.setScopeRep(Prefix); |
| 5283 | return static_cast<NestedNameSpecifier *>( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5284 | SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5285 | Range.getEnd(), II, |
Douglas Gregor | c68afe2 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 5286 | ObjectType, |
| 5287 | FirstQualifierInScope, |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 5288 | false)); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | template<typename Derived> |
| 5292 | NestedNameSpecifier * |
| 5293 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5294 | SourceRange Range, |
| 5295 | NamespaceDecl *NS) { |
| 5296 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); |
| 5297 | } |
| 5298 | |
| 5299 | template<typename Derived> |
| 5300 | NestedNameSpecifier * |
| 5301 | TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, |
| 5302 | SourceRange Range, |
| 5303 | bool TemplateKW, |
| 5304 | QualType T) { |
| 5305 | if (T->isDependentType() || T->isRecordType() || |
| 5306 | (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 5307 | assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5308 | return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, |
| 5309 | T.getTypePtr()); |
| 5310 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 5312 | SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; |
| 5313 | return 0; |
| 5314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5315 | |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5316 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5318 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5319 | bool TemplateKW, |
| 5320 | TemplateDecl *Template) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5321 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5322 | Template); |
| 5323 | } |
| 5324 | |
| 5325 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5326 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5327 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5328 | bool TemplateKW, |
| 5329 | OverloadedFunctionDecl *Ovl) { |
| 5330 | return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, Ovl); |
| 5331 | } |
| 5332 | |
| 5333 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5334 | TemplateName |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5335 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5336 | const IdentifierInfo &II, |
| 5337 | QualType ObjectType) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5338 | CXXScopeSpec SS; |
| 5339 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5340 | SS.setScopeRep(Qualifier); |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5341 | UnqualifiedId Name; |
| 5342 | Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5343 | return getSema().ActOnDependentTemplateName( |
| 5344 | /*FIXME:*/getDerived().getBaseLocation(), |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5345 | SS, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 5346 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5347 | ObjectType.getAsOpaquePtr(), |
| 5348 | /*EnteringContext=*/false) |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 5349 | .template getAsVal<TemplateName>(); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 5350 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5351 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5352 | template<typename Derived> |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5353 | TemplateName |
| 5354 | TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, |
| 5355 | OverloadedOperatorKind Operator, |
| 5356 | QualType ObjectType) { |
| 5357 | CXXScopeSpec SS; |
| 5358 | SS.setRange(SourceRange(getDerived().getBaseLocation())); |
| 5359 | SS.setScopeRep(Qualifier); |
| 5360 | UnqualifiedId Name; |
| 5361 | SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. |
| 5362 | Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), |
| 5363 | Operator, SymbolLocations); |
| 5364 | return getSema().ActOnDependentTemplateName( |
| 5365 | /*FIXME:*/getDerived().getBaseLocation(), |
| 5366 | SS, |
| 5367 | Name, |
Douglas Gregor | a481edb | 2009-11-20 23:39:24 +0000 | [diff] [blame] | 5368 | ObjectType.getAsOpaquePtr(), |
| 5369 | /*EnteringContext=*/false) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 5370 | .template getAsVal<TemplateName>(); |
| 5371 | } |
| 5372 | |
| 5373 | template<typename Derived> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5374 | Sema::OwningExprResult |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5375 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 5376 | SourceLocation OpLoc, |
| 5377 | ExprArg Callee, |
| 5378 | ExprArg First, |
| 5379 | ExprArg Second) { |
| 5380 | Expr *FirstExpr = (Expr *)First.get(); |
| 5381 | Expr *SecondExpr = (Expr *)Second.get(); |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5382 | Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5383 | bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5384 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5385 | // Determine whether this should be a builtin operation. |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5386 | if (Op == OO_Subscript) { |
| 5387 | if (!FirstExpr->getType()->isOverloadableType() && |
| 5388 | !SecondExpr->getType()->isOverloadableType()) |
| 5389 | return getSema().CreateBuiltinArraySubscriptExpr(move(First), |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5390 | CalleeExpr->getLocStart(), |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5391 | move(Second), OpLoc); |
Eli Friedman | 1a3c75f | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 5392 | } else if (Op == OO_Arrow) { |
| 5393 | // -> is never a builtin operation. |
| 5394 | return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5395 | } else if (SecondExpr == 0 || isPostIncDec) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5396 | if (!FirstExpr->getType()->isOverloadableType()) { |
| 5397 | // The argument is not of overloadable type, so try to create a |
| 5398 | // built-in unary operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5399 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5400 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5401 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5402 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); |
| 5403 | } |
| 5404 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5405 | if (!FirstExpr->getType()->isOverloadableType() && |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5406 | !SecondExpr->getType()->isOverloadableType()) { |
| 5407 | // Neither of the arguments is an overloadable type, so try to |
| 5408 | // create a built-in binary operation. |
| 5409 | BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5410 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5411 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); |
| 5412 | if (Result.isInvalid()) |
| 5413 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5414 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5415 | First.release(); |
| 5416 | Second.release(); |
| 5417 | return move(Result); |
| 5418 | } |
| 5419 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5420 | |
| 5421 | // Compute the transformed set of functions (and function templates) to be |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5422 | // used during overload resolution. |
| 5423 | Sema::FunctionSet Functions; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5425 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) { |
| 5426 | assert(ULE->requiresADL()); |
| 5427 | |
| 5428 | // FIXME: Do we have to check |
| 5429 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 5430 | for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), |
| 5431 | E = ULE->decls_end(); I != E; ++I) |
| 5432 | Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I)); |
| 5433 | } else { |
| 5434 | Functions.insert(AnyFunctionDecl::getFromNamedDecl( |
| 5435 | cast<DeclRefExpr>(CalleeExpr)->getDecl())); |
| 5436 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5437 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5438 | // Add any functions found via argument-dependent lookup. |
| 5439 | Expr *Args[2] = { FirstExpr, SecondExpr }; |
| 5440 | unsigned NumArgs = 1 + (SecondExpr != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5441 | DeclarationName OpName |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5442 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op); |
Sebastian Redl | 644be85 | 2009-10-23 19:23:15 +0000 | [diff] [blame] | 5443 | SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, |
| 5444 | Functions); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5445 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5446 | // Create the overloaded operator invocation for unary operators. |
| 5447 | if (NumArgs == 1 || isPostIncDec) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5448 | UnaryOperator::Opcode Opc |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5449 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 5450 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); |
| 5451 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5452 | |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5453 | if (Op == OO_Subscript) |
John McCall | ba13543 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 5454 | return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), |
| 5455 | OpLoc, |
| 5456 | move(First), |
| 5457 | move(Second)); |
Sebastian Redl | f322ed6 | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 5458 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5459 | // Create the overloaded operator invocation for binary operators. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5460 | BinaryOperator::Opcode Opc = |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5461 | BinaryOperator::getOverloadedOpcode(Op); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5462 | OwningExprResult Result |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5463 | = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); |
| 5464 | if (Result.isInvalid()) |
| 5465 | return SemaRef.ExprError(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5466 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5467 | First.release(); |
| 5468 | Second.release(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5469 | return move(Result); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 5470 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5471 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5472 | } // end namespace clang |
| 5473 | |
| 5474 | #endif // LLVM_CLANG_SEMA_TREETRANSFORM_H |