| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 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 | // |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 15 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 16 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 17 | #include "CoroutineStmtBuilder.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "TypeLocBuilder.h" |
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
| John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclObjC.h" |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclTemplate.h" |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 22 | #include "clang/AST/Expr.h" |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 23 | #include "clang/AST/ExprCXX.h" |
| 24 | #include "clang/AST/ExprObjC.h" |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprOpenMP.h" |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 26 | #include "clang/AST/Stmt.h" |
| 27 | #include "clang/AST/StmtCXX.h" |
| 28 | #include "clang/AST/StmtObjC.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/AST/StmtOpenMP.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Designator.h" |
| 31 | #include "clang/Sema/Lookup.h" |
| 32 | #include "clang/Sema/Ownership.h" |
| 33 | #include "clang/Sema/ParsedTemplate.h" |
| 34 | #include "clang/Sema/ScopeInfo.h" |
| 35 | #include "clang/Sema/SemaDiagnostic.h" |
| 36 | #include "clang/Sema/SemaInternal.h" |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/ArrayRef.h" |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 38 | #include "llvm/Support/ErrorHandling.h" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 39 | #include <algorithm> |
| 40 | |
| 41 | namespace clang { |
| John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 42 | using namespace sema; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 44 | /// A semantic tree transformation that allows one to transform one |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 45 | /// abstract syntax tree into another. |
| 46 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 48 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 49 | /// behavior specific to that transformation. For example, template |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 50 | /// instantiation is implemented as a tree transformation where the |
| 51 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 52 | /// template arguments for their corresponding template parameters; a similar |
| 53 | /// transformation is performed for non-type template parameters and |
| 54 | /// template template parameters. |
| 55 | /// |
| 56 | /// This tree-transformation template uses static polymorphism to allow |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 57 | /// subclasses to customize any of its operations. Thus, a subclass can |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 58 | /// override any of the transformation or rebuild operators by providing an |
| 59 | /// operation with the same signature as the default implementation. The |
| Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 60 | /// overriding function should not be virtual. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 61 | /// |
| 62 | /// Semantic tree transformations are split into two stages, either of which |
| 63 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 64 | /// or the parts of an AST node using the various transformation functions, |
| 65 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 66 | /// node of the appropriate kind from the pieces. The default transformation |
| 67 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 68 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 69 | /// were changed by the transformation, invokes the rebuild operation to create |
| 70 | /// a new AST node. |
| 71 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | /// Subclasses can customize the transformation at various levels. The |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 73 | /// most coarse-grained transformations involve replacing TransformType(), |
| Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 74 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 75 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 76 | /// new implementations. |
| 77 | /// |
| 78 | /// For more fine-grained transformations, subclasses can replace any of the |
| 79 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 80 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 81 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 82 | /// to substitute template arguments for their corresponding template |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 83 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 84 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 85 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 86 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 87 | /// be able to use more efficient rebuild steps. |
| 88 | /// |
| 89 | /// There are a handful of other functions that can be overridden, allowing one |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | /// to avoid traversing nodes that don't need any transformation |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 91 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 92 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 93 | /// default locations and entity names used for type-checking |
| 94 | /// (\c getBaseLocation(), \c getBaseEntity()). |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 95 | template<typename Derived> |
| 96 | class TreeTransform { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 97 | /// Private RAII object that helps us forget and then re-remember |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 98 | /// the template argument corresponding to a partially-substituted parameter |
| 99 | /// pack. |
| 100 | class ForgetPartiallySubstitutedPackRAII { |
| 101 | Derived &Self; |
| 102 | TemplateArgument Old; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 103 | |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 104 | public: |
| 105 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 106 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 107 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 108 | |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 109 | ~ForgetPartiallySubstitutedPackRAII() { |
| 110 | Self.RememberPartiallySubstitutedPack(Old); |
| 111 | } |
| 112 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 113 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 114 | protected: |
| 115 | Sema &SemaRef; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 116 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 117 | /// The set of local declarations that have been transformed, for |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 118 | /// cases where we are forced to build new declarations within the transformer |
| 119 | /// rather than in the subclass (e.g., lambda closure types). |
| 120 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 121 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | public: |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 123 | /// Initializes a new tree transformer. |
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 124 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 126 | /// Retrieves a reference to the derived class. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 127 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 128 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 129 | /// Retrieves a reference to the derived class. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | const Derived &getDerived() const { |
| 131 | return static_cast<const Derived&>(*this); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 134 | static inline ExprResult Owned(Expr *E) { return E; } |
| 135 | static inline StmtResult Owned(Stmt *S) { return S; } |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 136 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 137 | /// Retrieves a reference to the semantic analysis object used for |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 138 | /// this tree transform. |
| 139 | Sema &getSema() const { return SemaRef; } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 140 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 141 | /// Whether the transformation should always rebuild AST nodes, even |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 142 | /// if none of the children have changed. |
| 143 | /// |
| 144 | /// Subclasses may override this function to specify when the transformation |
| 145 | /// should rebuild all AST nodes. |
| Richard Smith | 2aa81a7 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 146 | /// |
| 147 | /// We must always rebuild all AST nodes when performing variadic template |
| 148 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 149 | /// statement node appears at most once in its containing declaration. |
| 150 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 152 | /// Returns the location of the entity being transformed, if that |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 153 | /// information was not available elsewhere in the AST. |
| 154 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | /// By default, returns no source-location information. Subclasses can |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 156 | /// provide an alternative implementation that provides better location |
| 157 | /// information. |
| 158 | SourceLocation getBaseLocation() { return SourceLocation(); } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 159 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 160 | /// Returns the name of the entity being transformed, if that |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 161 | /// information was not available elsewhere in the AST. |
| 162 | /// |
| 163 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 164 | /// implementation with a more precise name. |
| 165 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 166 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 167 | /// Sets the "base" location and entity when that |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 168 | /// information is known based on another transformation. |
| 169 | /// |
| 170 | /// By default, the source location and entity are ignored. Subclasses can |
| 171 | /// override this function to provide a customized implementation. |
| 172 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 174 | /// RAII object that temporarily sets the base location and entity |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 175 | /// used for reporting diagnostics in types. |
| 176 | class TemporaryBase { |
| 177 | TreeTransform &Self; |
| 178 | SourceLocation OldLocation; |
| 179 | DeclarationName OldEntity; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 181 | public: |
| 182 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | DeclarationName Entity) : Self(Self) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 184 | OldLocation = Self.getDerived().getBaseLocation(); |
| 185 | OldEntity = Self.getDerived().getBaseEntity(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 186 | |
| Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 187 | if (Location.isValid()) |
| 188 | Self.getDerived().setBase(Location, Entity); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 189 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 191 | ~TemporaryBase() { |
| 192 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 193 | } |
| 194 | }; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 196 | /// Determine whether the given type \p T has already been |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 197 | /// transformed. |
| 198 | /// |
| 199 | /// Subclasses can provide an alternative implementation of this routine |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 200 | /// to short-circuit evaluation when it is known that a given type will |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 201 | /// not change. For example, template instantiation need not traverse |
| 202 | /// non-dependent types. |
| 203 | bool AlreadyTransformed(QualType T) { |
| 204 | return T.isNull(); |
| 205 | } |
| 206 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 207 | /// Determine whether the given call argument should be dropped, e.g., |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 208 | /// because it is a default argument. |
| 209 | /// |
| 210 | /// Subclasses can provide an alternative implementation of this routine to |
| 211 | /// determine which kinds of call arguments get dropped. By default, |
| 212 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 213 | bool DropCallArgument(Expr *E) { |
| 214 | return E->isDefaultArgument(); |
| 215 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 216 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 217 | /// Determine whether we should expand a pack expansion with the |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 218 | /// given set of parameter packs into separate arguments by repeatedly |
| 219 | /// transforming the pattern. |
| 220 | /// |
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 221 | /// By default, the transformer never tries to expand pack expansions. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 222 | /// Subclasses can override this routine to provide different behavior. |
| 223 | /// |
| 224 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 225 | /// pack expansion. |
| 226 | /// |
| 227 | /// \param PatternRange The source range that covers the entire pattern of |
| 228 | /// the pack expansion. |
| 229 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 230 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 231 | /// pattern. |
| 232 | /// |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 233 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 234 | /// expand the corresponding pack expansions into separate arguments. When |
| 235 | /// set, \c NumExpansions must also be set. |
| 236 | /// |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 237 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 238 | /// pack expansion after all of the expanded arguments. This is used |
| 239 | /// when extending explicitly-specified template argument packs per |
| 240 | /// C++0x [temp.arg.explicit]p9. |
| 241 | /// |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 242 | /// \param NumExpansions The number of separate arguments that will be in |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 243 | /// the expanded form of the corresponding pack expansion. This is both an |
| 244 | /// input and an output parameter, which can be set by the caller if the |
| 245 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 246 | /// and will be set by the callee when the number of expansions is known. |
| 247 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 248 | /// set this value in other cases. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 249 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 250 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 251 | /// are to be instantiated with arguments of different lengths), false |
| 252 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 253 | /// must be set. |
| 254 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 255 | SourceRange PatternRange, |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 256 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 257 | bool &ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 258 | bool &RetainExpansion, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 259 | Optional<unsigned> &NumExpansions) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 260 | ShouldExpand = false; |
| 261 | return false; |
| 262 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 263 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 264 | /// "Forget" about the partially-substituted pack template argument, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 265 | /// when performing an instantiation that must preserve the parameter pack |
| 266 | /// use. |
| 267 | /// |
| 268 | /// This routine is meant to be overridden by the template instantiator. |
| 269 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 270 | return TemplateArgument(); |
| 271 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 272 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 273 | /// "Remember" the partially-substituted pack template argument |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 274 | /// after performing an instantiation that must preserve the parameter pack |
| 275 | /// use. |
| 276 | /// |
| 277 | /// This routine is meant to be overridden by the template instantiator. |
| 278 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 279 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 280 | /// Note to the derived class when a function parameter pack is |
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 281 | /// being expanded. |
| 282 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 283 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 284 | /// Transforms the given type into another type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 285 | /// |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 286 | /// By default, this routine transforms a type by creating a |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 287 | /// TypeSourceInfo for it and delegating to the appropriate |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 288 | /// function. This is expensive, but we don't mind, because |
| 289 | /// this method is deprecated anyway; all users should be |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 290 | /// switched to storing TypeSourceInfos. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 291 | /// |
| 292 | /// \returns the transformed type. |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 293 | QualType TransformType(QualType T); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 294 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 295 | /// Transforms the given type-with-location into a new |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 296 | /// type-with-location. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 297 | /// |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 298 | /// By default, this routine transforms a type by delegating to the |
| 299 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 300 | /// may override this function (to take over all type |
| 301 | /// transformations) or some set of the TransformXXXType functions |
| 302 | /// to alter the transformation. |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 303 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 304 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 305 | /// Transform the given type-with-location into a new |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 306 | /// type, collecting location information in the given builder |
| 307 | /// as necessary. |
| 308 | /// |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 309 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 311 | /// Transform a type that is permitted to produce a |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 312 | /// DeducedTemplateSpecializationType. |
| 313 | /// |
| 314 | /// This is used in the (relatively rare) contexts where it is acceptable |
| 315 | /// for transformation to produce a class template type with deduced |
| 316 | /// template arguments. |
| 317 | /// @{ |
| 318 | QualType TransformTypeWithDeducedTST(QualType T); |
| 319 | TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); |
| 320 | /// @} |
| 321 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 322 | /// Transform the given statement. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 323 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | /// By default, this routine transforms a statement by delegating to the |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 325 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 326 | /// statement or the TransformExpr() function to transform an expression. |
| 327 | /// Subclasses may override this function to transform statements using some |
| 328 | /// other mechanism. |
| 329 | /// |
| 330 | /// \returns the transformed statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 331 | StmtResult TransformStmt(Stmt *S); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 333 | /// Transform the given statement. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 334 | /// |
| 335 | /// By default, this routine transforms a statement by delegating to the |
| 336 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 337 | /// of clause. Subclasses may override this function to transform statements |
| 338 | /// using some other mechanism. |
| 339 | /// |
| 340 | /// \returns the transformed OpenMP clause. |
| 341 | OMPClause *TransformOMPClause(OMPClause *S); |
| 342 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 343 | /// Transform the given attribute. |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 344 | /// |
| 345 | /// By default, this routine transforms a statement by delegating to the |
| 346 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 347 | /// of attribute. Subclasses may override this function to transform |
| 348 | /// attributed statements using some other mechanism. |
| 349 | /// |
| 350 | /// \returns the transformed attribute |
| 351 | const Attr *TransformAttr(const Attr *S); |
| 352 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 353 | /// Transform the specified attribute. |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 354 | /// |
| 355 | /// Subclasses should override the transformation of attributes with a pragma |
| 356 | /// spelling to transform expressions stored within the attribute. |
| 357 | /// |
| 358 | /// \returns the transformed attribute. |
| 359 | #define ATTR(X) |
| 360 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 361 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 362 | #include "clang/Basic/AttrList.inc" |
| 363 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 364 | /// Transform the given expression. |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 365 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 366 | /// By default, this routine transforms an expression by delegating to the |
| 367 | /// appropriate TransformXXXExpr function to build a new expression. |
| 368 | /// Subclasses may override this function to transform expressions using some |
| 369 | /// other mechanism. |
| 370 | /// |
| 371 | /// \returns the transformed expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 372 | ExprResult TransformExpr(Expr *E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 374 | /// Transform the given initializer. |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 375 | /// |
| 376 | /// By default, this routine transforms an initializer by stripping off the |
| 377 | /// semantic nodes added by initialization, then passing the result to |
| 378 | /// TransformExpr or TransformExprs. |
| 379 | /// |
| 380 | /// \returns the transformed initializer. |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 381 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 382 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 383 | /// Transform the given list of expressions. |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 384 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 385 | /// This routine transforms a list of expressions by invoking |
| 386 | /// \c TransformExpr() for each subexpression. However, it also provides |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 387 | /// support for variadic templates by expanding any pack expansions (if the |
| 388 | /// derived class permits such expansion) along the way. When pack expansions |
| 389 | /// are present, the number of outputs may not equal the number of inputs. |
| 390 | /// |
| 391 | /// \param Inputs The set of expressions to be transformed. |
| 392 | /// |
| 393 | /// \param NumInputs The number of expressions in \c Inputs. |
| 394 | /// |
| 395 | /// \param IsCall If \c true, then this transform is being performed on |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 396 | /// function-call arguments, and any arguments that should be dropped, will |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 397 | /// be. |
| 398 | /// |
| 399 | /// \param Outputs The transformed input expressions will be added to this |
| 400 | /// vector. |
| 401 | /// |
| 402 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 403 | /// due to transformation. |
| 404 | /// |
| 405 | /// \returns true if an error occurred, false otherwise. |
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 406 | bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 407 | SmallVectorImpl<Expr *> &Outputs, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 408 | bool *ArgChanged = nullptr); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 409 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 410 | /// Transform the given declaration, which is referenced from a type |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 411 | /// or expression. |
| 412 | /// |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 413 | /// By default, acts as the identity function on declarations, unless the |
| 414 | /// transformer has had to transform the declaration itself. Subclasses |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 415 | /// may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 416 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 417 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 418 | = TransformedLocalDecls.find(D); |
| 419 | if (Known != TransformedLocalDecls.end()) |
| 420 | return Known->second; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 421 | |
| 422 | return D; |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 423 | } |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 424 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 425 | /// Transform the specified condition. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 426 | /// |
| 427 | /// By default, this transforms the variable and expression and rebuilds |
| 428 | /// the condition. |
| 429 | Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
| 430 | Expr *Expr, |
| 431 | Sema::ConditionKind Kind); |
| 432 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 433 | /// Transform the attributes associated with the given declaration and |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 434 | /// place them on the new declaration. |
| 435 | /// |
| 436 | /// By default, this operation does nothing. Subclasses may override this |
| 437 | /// behavior to transform attributes. |
| 438 | void transformAttrs(Decl *Old, Decl *New) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 439 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 440 | /// Note that a local declaration has been transformed by this |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 441 | /// transformer. |
| 442 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 443 | /// Local declarations are typically transformed via a call to |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 444 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 445 | /// the transformer itself has to transform the declarations. This routine |
| 446 | /// can be overridden by a subclass that keeps track of such mappings. |
| 447 | void transformedLocalDecl(Decl *Old, Decl *New) { |
| 448 | TransformedLocalDecls[Old] = New; |
| 449 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 450 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 451 | /// Transform the definition of the given declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 452 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 453 | /// By default, invokes TransformDecl() to transform the declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 454 | /// Subclasses may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 455 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 456 | return getDerived().TransformDecl(Loc, D); |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 457 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 459 | /// Transform the given declaration, which was the first part of a |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 460 | /// nested-name-specifier in a member access expression. |
| 461 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 462 | /// This specific declaration transformation only applies to the first |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 463 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 464 | /// the \c T in \c x->T::member |
| 465 | /// |
| 466 | /// By default, invokes TransformDecl() to transform the declaration. |
| 467 | /// Subclasses may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 468 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 469 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 470 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 471 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 472 | /// Transform the set of declarations in an OverloadExpr. |
| 473 | bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, |
| 474 | LookupResult &R); |
| 475 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 476 | /// Transform the given nested-name-specifier with source-location |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 477 | /// information. |
| 478 | /// |
| 479 | /// By default, transforms all of the types and declarations within the |
| 480 | /// nested-name-specifier. Subclasses may override this function to provide |
| 481 | /// alternate behavior. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 482 | NestedNameSpecifierLoc |
| 483 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 484 | QualType ObjectType = QualType(), |
| 485 | NamedDecl *FirstQualifierInScope = nullptr); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 486 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 487 | /// Transform the given declaration name. |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 488 | /// |
| 489 | /// By default, transforms the types of conversion function, constructor, |
| 490 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 491 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 492 | /// override this function to provide alternate behavior. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 493 | DeclarationNameInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 494 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 496 | /// Transform the given template name. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | /// |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 498 | /// \param SS The nested-name-specifier that qualifies the template |
| 499 | /// name. This nested-name-specifier must already have been transformed. |
| 500 | /// |
| 501 | /// \param Name The template name to transform. |
| 502 | /// |
| 503 | /// \param NameLoc The source location of the template name. |
| 504 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 505 | /// \param ObjectType If we're translating a template name within a member |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 506 | /// access expression, this is the type of the object whose member template |
| 507 | /// is being referenced. |
| 508 | /// |
| 509 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 510 | /// also refers to a name within the current (lexical) scope, this is the |
| 511 | /// declaration it refers to. |
| 512 | /// |
| 513 | /// By default, transforms the template name by transforming the declarations |
| 514 | /// and nested-name-specifiers that occur within the template name. |
| 515 | /// Subclasses may override this function to provide alternate behavior. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 516 | TemplateName |
| 517 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 518 | SourceLocation NameLoc, |
| 519 | QualType ObjectType = QualType(), |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 520 | NamedDecl *FirstQualifierInScope = nullptr, |
| 521 | bool AllowInjectedClassName = false); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 522 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 523 | /// Transform the given template argument. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 524 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | /// By default, this operation transforms the type, expression, or |
| 526 | /// declaration stored within the template argument and constructs a |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 527 | /// new template argument from the transformed result. Subclasses may |
| 528 | /// override this function to provide alternate behavior. |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 529 | /// |
| 530 | /// Returns true if there was an error. |
| 531 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 532 | TemplateArgumentLoc &Output, |
| 533 | bool Uneval = false); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 534 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 535 | /// Transform the given set of template arguments. |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 536 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 537 | /// By default, this operation transforms all of the template arguments |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 538 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 539 | /// the transformed arguments to the output list. |
| 540 | /// |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 541 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 542 | /// a convenience function. Subclasses that wish to override this behavior |
| 543 | /// should override the iterator-based member template version. |
| 544 | /// |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 545 | /// \param Inputs The set of template arguments to be transformed. |
| 546 | /// |
| 547 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 548 | /// |
| 549 | /// \param Outputs The set of transformed template arguments output by this |
| 550 | /// routine. |
| 551 | /// |
| 552 | /// Returns true if an error occurred. |
| 553 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 554 | unsigned NumInputs, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 555 | TemplateArgumentListInfo &Outputs, |
| 556 | bool Uneval = false) { |
| 557 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 558 | Uneval); |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 559 | } |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 560 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 561 | /// Transform the given set of template arguments. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 562 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 563 | /// By default, this operation transforms all of the template arguments |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 564 | /// in the input set using \c TransformTemplateArgument(), and appends |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 565 | /// the transformed arguments to the output list. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 566 | /// |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 567 | /// \param First An iterator to the first template argument. |
| 568 | /// |
| 569 | /// \param Last An iterator one step past the last template argument. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 570 | /// |
| 571 | /// \param Outputs The set of transformed template arguments output by this |
| 572 | /// routine. |
| 573 | /// |
| 574 | /// Returns true if an error occurred. |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 575 | template<typename InputIterator> |
| 576 | bool TransformTemplateArguments(InputIterator First, |
| 577 | InputIterator Last, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 578 | TemplateArgumentListInfo &Outputs, |
| 579 | bool Uneval = false); |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 580 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 581 | /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 582 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 583 | TemplateArgumentLoc &ArgLoc); |
| 584 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 585 | /// Fakes up a TypeSourceInfo for a type. |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 586 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 587 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 588 | getDerived().getBaseLocation()); |
| 589 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 590 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 591 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 592 | #define TYPELOC(CLASS, PARENT) \ |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 593 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 594 | #include "clang/AST/TypeLocNodes.def" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 595 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 596 | template<typename Fn> |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 597 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 598 | FunctionProtoTypeLoc TL, |
| 599 | CXXRecordDecl *ThisContext, |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 600 | unsigned ThisTypeQuals, |
| 601 | Fn TransformExceptionSpec); |
| 602 | |
| 603 | bool TransformExceptionSpec(SourceLocation Loc, |
| 604 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 605 | SmallVectorImpl<QualType> &Exceptions, |
| 606 | bool &Changed); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 607 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 608 | StmtResult TransformSEHHandler(Stmt *Handler); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 609 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 610 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 611 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 612 | TemplateSpecializationTypeLoc TL, |
| 613 | TemplateName Template); |
| 614 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 615 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 616 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 617 | DependentTemplateSpecializationTypeLoc TL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 618 | TemplateName Template, |
| 619 | CXXScopeSpec &SS); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 620 | |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 621 | QualType TransformDependentTemplateSpecializationType( |
| 622 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 623 | NestedNameSpecifierLoc QualifierLoc); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 624 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 625 | /// Transforms the parameters of a function type into the |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 626 | /// given vectors. |
| 627 | /// |
| 628 | /// The result vectors should be kept in sync; null entries in the |
| 629 | /// variables vector are acceptable. |
| 630 | /// |
| 631 | /// Return true on error. |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 632 | bool TransformFunctionTypeParams( |
| 633 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 634 | const QualType *ParamTypes, |
| 635 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 636 | SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 637 | Sema::ExtParameterInfoBuilder &PInfos); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 638 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 639 | /// Transforms a single function-type parameter. Return null |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 640 | /// on error. |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 641 | /// |
| 642 | /// \param indexAdjustment - A number to add to the parameter's |
| 643 | /// scope index; can be negative |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 644 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 645 | int indexAdjustment, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 646 | Optional<unsigned> NumExpansions, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 647 | bool ExpectParameterPack); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 648 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 649 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 650 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 651 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 652 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
| Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 653 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 654 | TemplateParameterList *TransformTemplateParameterList( |
| 655 | TemplateParameterList *TPL) { |
| 656 | return TPL; |
| 657 | } |
| 658 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 659 | ExprResult TransformAddressOfOperand(Expr *E); |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 660 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 661 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 662 | bool IsAddressOfOperand, |
| 663 | TypeSourceInfo **RecoveryTSI); |
| 664 | |
| 665 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 666 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 667 | TypeSourceInfo **RecoveryTSI); |
| 668 | |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 669 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 670 | |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 671 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 672 | // amount of stack usage with clang. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 673 | #define STMT(Node, Parent) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 674 | LLVM_ATTRIBUTE_NOINLINE \ |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 675 | StmtResult Transform##Node(Node *S); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 676 | #define EXPR(Node, Parent) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 677 | LLVM_ATTRIBUTE_NOINLINE \ |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 678 | ExprResult Transform##Node(Node *E); |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 679 | #define ABSTRACT_STMT(Stmt) |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 680 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 682 | #define OPENMP_CLAUSE(Name, Class) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 683 | LLVM_ATTRIBUTE_NOINLINE \ |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 684 | OMPClause *Transform ## Class(Class *S); |
| 685 | #include "clang/Basic/OpenMPKinds.def" |
| 686 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 687 | /// Build a new qualified type given its unqualified type and type |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 688 | /// qualifiers. |
| 689 | /// |
| 690 | /// By default, this routine adds type qualifiers only to types that can |
| 691 | /// have qualifiers, and silently suppresses those qualifiers that are not |
| 692 | /// permitted. Subclasses may override this routine to provide different |
| 693 | /// behavior. |
| 694 | QualType RebuildQualifiedType(QualType T, SourceLocation Loc, |
| 695 | Qualifiers Quals); |
| 696 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 697 | /// Build a new pointer type given its pointee type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 698 | /// |
| 699 | /// By default, performs semantic analysis when building the pointer type. |
| 700 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 701 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 702 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 703 | /// Build a new block pointer type given its pointee type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 704 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | /// By default, performs semantic analysis when building the block pointer |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 706 | /// type. Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 707 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 708 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 709 | /// Build a new reference type given the type it references. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 710 | /// |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 711 | /// By default, performs semantic analysis when building the |
| 712 | /// reference type. Subclasses may override this routine to provide |
| 713 | /// different behavior. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 714 | /// |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 715 | /// \param LValue whether the type was written with an lvalue sigil |
| 716 | /// or an rvalue sigil. |
| 717 | QualType RebuildReferenceType(QualType ReferentType, |
| 718 | bool LValue, |
| 719 | SourceLocation Sigil); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 721 | /// Build a new member pointer type given the pointee type and the |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 722 | /// class type it refers into. |
| 723 | /// |
| 724 | /// By default, performs semantic analysis when building the member pointer |
| 725 | /// type. Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 726 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 727 | SourceLocation Sigil); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 729 | QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 730 | SourceLocation ProtocolLAngleLoc, |
| 731 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 732 | ArrayRef<SourceLocation> ProtocolLocs, |
| 733 | SourceLocation ProtocolRAngleLoc); |
| 734 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 735 | /// Build an Objective-C object type. |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 736 | /// |
| 737 | /// By default, performs semantic analysis when building the object type. |
| 738 | /// Subclasses may override this routine to provide different behavior. |
| 739 | QualType RebuildObjCObjectType(QualType BaseType, |
| 740 | SourceLocation Loc, |
| 741 | SourceLocation TypeArgsLAngleLoc, |
| 742 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 743 | SourceLocation TypeArgsRAngleLoc, |
| 744 | SourceLocation ProtocolLAngleLoc, |
| 745 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 746 | ArrayRef<SourceLocation> ProtocolLocs, |
| 747 | SourceLocation ProtocolRAngleLoc); |
| 748 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 749 | /// Build a new Objective-C object pointer type given the pointee type. |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 750 | /// |
| 751 | /// By default, directly builds the pointer type, with no additional semantic |
| 752 | /// analysis. |
| 753 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 754 | SourceLocation Star); |
| 755 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 756 | /// Build a new array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 757 | /// modifier, size of the array (if known), size expression, and index type |
| 758 | /// qualifiers. |
| 759 | /// |
| 760 | /// By default, performs semantic analysis when building the array type. |
| 761 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | /// Also by default, all of the other Rebuild*Array |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 763 | QualType RebuildArrayType(QualType ElementType, |
| 764 | ArrayType::ArraySizeModifier SizeMod, |
| 765 | const llvm::APInt *Size, |
| 766 | Expr *SizeExpr, |
| 767 | unsigned IndexTypeQuals, |
| 768 | SourceRange BracketsRange); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 769 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 770 | /// Build a new constant array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 771 | /// modifier, (known) size of the array, and index type qualifiers. |
| 772 | /// |
| 773 | /// By default, performs semantic analysis when building the array type. |
| 774 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | QualType RebuildConstantArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 776 | ArrayType::ArraySizeModifier SizeMod, |
| 777 | const llvm::APInt &Size, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 778 | unsigned IndexTypeQuals, |
| 779 | SourceRange BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 780 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 781 | /// Build a new incomplete array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 782 | /// modifier, and index type qualifiers. |
| 783 | /// |
| 784 | /// By default, performs semantic analysis when building the array type. |
| 785 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | QualType RebuildIncompleteArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 787 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 788 | unsigned IndexTypeQuals, |
| 789 | SourceRange BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 790 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 791 | /// Build a new variable-length array type given the element type, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 792 | /// size modifier, size expression, and index type qualifiers. |
| 793 | /// |
| 794 | /// By default, performs semantic analysis when building the array type. |
| 795 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | QualType RebuildVariableArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 797 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 798 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 799 | unsigned IndexTypeQuals, |
| 800 | SourceRange BracketsRange); |
| 801 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 802 | /// Build a new dependent-sized array type given the element type, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 803 | /// size modifier, size expression, and index type qualifiers. |
| 804 | /// |
| 805 | /// By default, performs semantic analysis when building the array type. |
| 806 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 808 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 809 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 810 | unsigned IndexTypeQuals, |
| 811 | SourceRange BracketsRange); |
| 812 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 813 | /// Build a new vector type given the element type and |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 814 | /// number of elements. |
| 815 | /// |
| 816 | /// By default, performs semantic analysis when building the vector type. |
| 817 | /// Subclasses may override this routine to provide different behavior. |
| John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 818 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 819 | VectorType::VectorKind VecKind); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 820 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 821 | /// Build a new potentially dependently-sized extended vector type |
| 822 | /// given the element type and number of elements. |
| 823 | /// |
| 824 | /// By default, performs semantic analysis when building the vector type. |
| 825 | /// Subclasses may override this routine to provide different behavior. |
| 826 | QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, |
| 827 | SourceLocation AttributeLoc, |
| 828 | VectorType::VectorKind); |
| 829 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 830 | /// Build a new extended vector type given the element type and |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 831 | /// number of elements. |
| 832 | /// |
| 833 | /// By default, performs semantic analysis when building the vector type. |
| 834 | /// Subclasses may override this routine to provide different behavior. |
| 835 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 836 | SourceLocation AttributeLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 838 | /// Build a new potentially dependently-sized extended vector type |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 839 | /// given the element type and number of elements. |
| 840 | /// |
| 841 | /// By default, performs semantic analysis when building the vector type. |
| 842 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 844 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 845 | SourceLocation AttributeLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 847 | /// Build a new DependentAddressSpaceType or return the pointee |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 848 | /// type variable with the correct address space (retrieved from |
| 849 | /// AddrSpaceExpr) applied to it. The former will be returned in cases |
| 850 | /// where the address space remains dependent. |
| 851 | /// |
| 852 | /// By default, performs semantic analysis when building the type with address |
| 853 | /// space applied. Subclasses may override this routine to provide different |
| 854 | /// behavior. |
| 855 | QualType RebuildDependentAddressSpaceType(QualType PointeeType, |
| 856 | Expr *AddrSpaceExpr, |
| 857 | SourceLocation AttributeLoc); |
| 858 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 859 | /// Build a new function type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 860 | /// |
| 861 | /// By default, performs semantic analysis when building the function type. |
| 862 | /// Subclasses may override this routine to provide different behavior. |
| 863 | QualType RebuildFunctionProtoType(QualType T, |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 864 | MutableArrayRef<QualType> ParamTypes, |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 865 | const FunctionProtoType::ExtProtoInfo &EPI); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 866 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 867 | /// Build a new unprototyped function type. |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 868 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 869 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 870 | /// Rebuild an unresolved typename type, given the decl that |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 871 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 872 | QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 873 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 874 | /// Build a new typedef type. |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 875 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 876 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 877 | } |
| 878 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 879 | /// Build a new class/struct/union type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 880 | QualType RebuildRecordType(RecordDecl *Record) { |
| 881 | return SemaRef.Context.getTypeDeclType(Record); |
| 882 | } |
| 883 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 884 | /// Build a new Enum type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 885 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 886 | return SemaRef.Context.getTypeDeclType(Enum); |
| 887 | } |
| John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 888 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 889 | /// Build a new typeof(expr) type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 890 | /// |
| 891 | /// By default, performs semantic analysis when building the typeof type. |
| 892 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 893 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 894 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 895 | /// Build a new typeof(type) type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 896 | /// |
| 897 | /// By default, builds a new TypeOfType with the given underlying type. |
| 898 | QualType RebuildTypeOfType(QualType Underlying); |
| 899 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 900 | /// Build a new unary transform type. |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 901 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 902 | UnaryTransformType::UTTKind UKind, |
| 903 | SourceLocation Loc); |
| 904 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 905 | /// Build a new C++11 decltype type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 906 | /// |
| 907 | /// By default, performs semantic analysis when building the decltype type. |
| 908 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 909 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 910 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 911 | /// Build a new C++11 auto type. |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 912 | /// |
| 913 | /// By default, builds a new AutoType with the given deduced type. |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 914 | QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) { |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 915 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 916 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 917 | // that we'll retry deduction after the transformation. |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 918 | return SemaRef.Context.getAutoType(Deduced, Keyword, |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 919 | /*IsDependent*/ false); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 922 | /// By default, builds a new DeducedTemplateSpecializationType with the given |
| 923 | /// deduced type. |
| 924 | QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, |
| 925 | QualType Deduced) { |
| 926 | return SemaRef.Context.getDeducedTemplateSpecializationType( |
| 927 | Template, Deduced, /*IsDependent*/ false); |
| 928 | } |
| 929 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 930 | /// Build a new template specialization type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 931 | /// |
| 932 | /// By default, performs semantic analysis when building the template |
| 933 | /// specialization type. Subclasses may override this routine to provide |
| 934 | /// different behavior. |
| 935 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 936 | SourceLocation TemplateLoc, |
| Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 937 | TemplateArgumentListInfo &Args); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 938 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 939 | /// Build a new parenthesized type. |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 940 | /// |
| 941 | /// By default, builds a new ParenType type from the inner type. |
| 942 | /// Subclasses may override this routine to provide different behavior. |
| 943 | QualType RebuildParenType(QualType InnerType) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 944 | return SemaRef.BuildParenType(InnerType); |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 947 | /// Build a new qualified name type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 948 | /// |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 949 | /// By default, builds a new ElaboratedType type from the keyword, |
| 950 | /// the nested-name-specifier and the named type. |
| 951 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 952 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 953 | ElaboratedTypeKeyword Keyword, |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 954 | NestedNameSpecifierLoc QualifierLoc, |
| 955 | QualType Named) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 956 | return SemaRef.Context.getElaboratedType(Keyword, |
| 957 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 958 | Named); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 959 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 960 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 961 | /// Build a new typename type that refers to a template-id. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 962 | /// |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 963 | /// By default, builds a new DependentNameType type from the |
| 964 | /// nested-name-specifier and the given type. Subclasses may override |
| 965 | /// this routine to provide different behavior. |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 966 | QualType RebuildDependentTemplateSpecializationType( |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 967 | ElaboratedTypeKeyword Keyword, |
| 968 | NestedNameSpecifierLoc QualifierLoc, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 969 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 970 | const IdentifierInfo *Name, |
| 971 | SourceLocation NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 972 | TemplateArgumentListInfo &Args, |
| 973 | bool AllowInjectedClassName) { |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 974 | // Rebuild the template name. |
| 975 | // TODO: avoid TemplateName abstraction |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 976 | CXXScopeSpec SS; |
| 977 | SS.Adopt(QualifierLoc); |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 978 | TemplateName InstName = getDerived().RebuildTemplateName( |
| 979 | SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, |
| 980 | AllowInjectedClassName); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 981 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 982 | if (InstName.isNull()) |
| 983 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 984 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 985 | // If it's still dependent, make a dependent specialization. |
| 986 | if (InstName.getAsDependentTemplateName()) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 987 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 988 | QualifierLoc.getNestedNameSpecifier(), |
| 989 | Name, |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 990 | Args); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 991 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 992 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 993 | // specialization. |
| 994 | QualType T = |
| 995 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 996 | if (T.isNull()) return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 997 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 998 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 999 | return T; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1000 | |
| 1001 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1002 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1003 | T); |
| 1004 | } |
| 1005 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1006 | /// Build a new typename type that refers to an identifier. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1007 | /// |
| 1008 | /// By default, performs semantic analysis when building the typename type |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1009 | /// (or elaborated type). Subclasses may override this routine to provide |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1010 | /// different behavior. |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1011 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1012 | SourceLocation KeywordLoc, |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1013 | NestedNameSpecifierLoc QualifierLoc, |
| 1014 | const IdentifierInfo *Id, |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1015 | SourceLocation IdLoc, |
| 1016 | bool DeducedTSTContext) { |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1017 | CXXScopeSpec SS; |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1018 | SS.Adopt(QualifierLoc); |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1019 | |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1020 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1021 | // If the name is still dependent, just build a new dependent name type. |
| 1022 | if (!SemaRef.computeDeclContext(SS)) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1023 | return SemaRef.Context.getDependentNameType(Keyword, |
| 1024 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1025 | Id); |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1028 | if (Keyword == ETK_None || Keyword == ETK_Typename) { |
| 1029 | QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
| 1030 | *Id, IdLoc); |
| 1031 | // If a dependent name resolves to a deduced template specialization type, |
| 1032 | // check that we're in one of the syntactic contexts permitting it. |
| 1033 | if (!DeducedTSTContext) { |
| 1034 | if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>( |
| 1035 | T.isNull() ? nullptr : T->getContainedDeducedType())) { |
| 1036 | SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst) |
| 1037 | << (int)SemaRef.getTemplateNameKindForDiagnostics( |
| 1038 | Deduced->getTemplateName()) |
| 1039 | << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0); |
| 1040 | if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl()) |
| 1041 | SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here); |
| 1042 | return QualType(); |
| 1043 | } |
| 1044 | } |
| 1045 | return T; |
| 1046 | } |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1047 | |
| 1048 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 1049 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1050 | // We had a dependent elaborated-type-specifier that has been transformed |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1051 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 1052 | // referring to. |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1053 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1054 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 1055 | if (!DC) |
| 1056 | return QualType(); |
| 1057 | |
| John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 1058 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 1059 | return QualType(); |
| 1060 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1061 | TagDecl *Tag = nullptr; |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1062 | SemaRef.LookupQualifiedName(Result, DC); |
| 1063 | switch (Result.getResultKind()) { |
| 1064 | case LookupResult::NotFound: |
| 1065 | case LookupResult::NotFoundInCurrentInstantiation: |
| 1066 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1067 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1068 | case LookupResult::Found: |
| 1069 | Tag = Result.getAsSingle<TagDecl>(); |
| 1070 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1071 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1072 | case LookupResult::FoundOverloaded: |
| 1073 | case LookupResult::FoundUnresolvedValue: |
| 1074 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1075 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1076 | case LookupResult::Ambiguous: |
| 1077 | // Let the LookupResult structure handle ambiguities. |
| 1078 | return QualType(); |
| 1079 | } |
| 1080 | |
| 1081 | if (!Tag) { |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1082 | // Check where the name exists but isn't a tag type and use that to emit |
| 1083 | // better diagnostics. |
| 1084 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1085 | SemaRef.LookupQualifiedName(Result, DC); |
| 1086 | switch (Result.getResultKind()) { |
| 1087 | case LookupResult::Found: |
| 1088 | case LookupResult::FoundOverloaded: |
| 1089 | case LookupResult::FoundUnresolvedValue: { |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1090 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| Reid Kleckner | 1a4ab7e | 2016-12-09 19:47:58 +0000 | [diff] [blame] | 1091 | Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); |
| 1092 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl |
| 1093 | << NTK << Kind; |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1094 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1095 | break; |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1096 | } |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1097 | default: |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1098 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 1099 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1100 | break; |
| 1101 | } |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1102 | return QualType(); |
| 1103 | } |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1104 | |
| Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1105 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1106 | IdLoc, Id)) { |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1107 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1108 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1109 | return QualType(); |
| 1110 | } |
| 1111 | |
| 1112 | // Build the elaborated-type-specifier type. |
| 1113 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1114 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1115 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1116 | T); |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1117 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1118 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1119 | /// Build a new pack expansion type. |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1120 | /// |
| 1121 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1122 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1123 | QualType RebuildPackExpansionType(QualType Pattern, |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1124 | SourceRange PatternRange, |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1125 | SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1126 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1127 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1128 | NumExpansions); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1131 | /// Build a new atomic type given its value type. |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1132 | /// |
| 1133 | /// By default, performs semantic analysis when building the atomic type. |
| 1134 | /// Subclasses may override this routine to provide different behavior. |
| 1135 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1136 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1137 | /// Build a new pipe type given its value type. |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 1138 | QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, |
| 1139 | bool isReadPipe); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 1140 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1141 | /// Build a new template name given a nested name specifier, a flag |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1142 | /// indicating whether the "template" keyword was provided, and the template |
| 1143 | /// that the template name refers to. |
| 1144 | /// |
| 1145 | /// By default, builds the new template name directly. Subclasses may override |
| 1146 | /// this routine to provide different behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1147 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1148 | bool TemplateKW, |
| 1149 | TemplateDecl *Template); |
| 1150 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1151 | /// Build a new template name given a nested name specifier and the |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1152 | /// name that is referred to as a template. |
| 1153 | /// |
| 1154 | /// By default, performs semantic analysis to determine whether the name can |
| 1155 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1156 | /// template name. Subclasses may override this routine to provide different |
| 1157 | /// behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1158 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1159 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1160 | const IdentifierInfo &Name, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1161 | SourceLocation NameLoc, QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1162 | NamedDecl *FirstQualifierInScope, |
| 1163 | bool AllowInjectedClassName); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1165 | /// Build a new template name given a nested name specifier and the |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1166 | /// overloaded operator name that is referred to as a template. |
| 1167 | /// |
| 1168 | /// By default, performs semantic analysis to determine whether the name can |
| 1169 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1170 | /// template name. Subclasses may override this routine to provide different |
| 1171 | /// behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1172 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1173 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1174 | OverloadedOperatorKind Operator, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1175 | SourceLocation NameLoc, QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1176 | bool AllowInjectedClassName); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1177 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1178 | /// Build a new template name given a template template parameter pack |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1179 | /// and the |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1180 | /// |
| 1181 | /// By default, performs semantic analysis to determine whether the name can |
| 1182 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1183 | /// template name. Subclasses may override this routine to provide different |
| 1184 | /// behavior. |
| 1185 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1186 | const TemplateArgument &ArgPack) { |
| 1187 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1188 | } |
| 1189 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1190 | /// Build a new compound statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1191 | /// |
| 1192 | /// By default, performs semantic analysis to build the new statement. |
| 1193 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1194 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1195 | MultiStmtArg Statements, |
| 1196 | SourceLocation RBraceLoc, |
| 1197 | bool IsStmtExpr) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1198 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1199 | IsStmtExpr); |
| 1200 | } |
| 1201 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1202 | /// Build a new case statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1203 | /// |
| 1204 | /// By default, performs semantic analysis to build the new statement. |
| 1205 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1206 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1207 | Expr *LHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1208 | SourceLocation EllipsisLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1209 | Expr *RHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1210 | SourceLocation ColonLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1211 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1212 | ColonLoc); |
| 1213 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1215 | /// Attach the body to a new case statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1216 | /// |
| 1217 | /// By default, performs semantic analysis to build the new statement. |
| 1218 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1219 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1220 | getSema().ActOnCaseStmtBody(S, Body); |
| 1221 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1222 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1224 | /// Build a new default statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1225 | /// |
| 1226 | /// By default, performs semantic analysis to build the new statement. |
| 1227 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1228 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1229 | SourceLocation ColonLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1230 | Stmt *SubStmt) { |
| 1231 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1232 | /*CurScope=*/nullptr); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1233 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1235 | /// Build a new label statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1236 | /// |
| 1237 | /// By default, performs semantic analysis to build the new statement. |
| 1238 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1239 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1240 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1241 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1242 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1244 | /// Build a new label statement. |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1245 | /// |
| 1246 | /// By default, performs semantic analysis to build the new statement. |
| 1247 | /// Subclasses may override this routine to provide different behavior. |
| Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1248 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1249 | ArrayRef<const Attr*> Attrs, |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1250 | Stmt *SubStmt) { |
| 1251 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1252 | } |
| 1253 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1254 | /// Build a new "if" statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1255 | /// |
| 1256 | /// By default, performs semantic analysis to build the new statement. |
| 1257 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 1258 | StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1259 | Sema::ConditionResult Cond, Stmt *Init, Stmt *Then, |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 1260 | SourceLocation ElseLoc, Stmt *Else) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1261 | return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then, |
| Richard Smith | c7a05a9 | 2016-06-29 21:17:59 +0000 | [diff] [blame] | 1262 | ElseLoc, Else); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1263 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1265 | /// Start building a new switch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1266 | /// |
| 1267 | /// By default, performs semantic analysis to build the new statement. |
| 1268 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1269 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1270 | Sema::ConditionResult Cond) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1271 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1272 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1273 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1274 | /// Attach the body to the switch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1275 | /// |
| 1276 | /// By default, performs semantic analysis to build the new statement. |
| 1277 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1278 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1279 | Stmt *Switch, Stmt *Body) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1280 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1283 | /// Build a new while statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1284 | /// |
| 1285 | /// By default, performs semantic analysis to build the new statement. |
| 1286 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1287 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 1288 | Sema::ConditionResult Cond, Stmt *Body) { |
| 1289 | return getSema().ActOnWhileStmt(WhileLoc, Cond, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1290 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1292 | /// Build a new do-while statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1293 | /// |
| 1294 | /// By default, performs semantic analysis to build the new statement. |
| 1295 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1296 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1297 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1298 | Expr *Cond, SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1299 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1300 | Cond, RParenLoc); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1303 | /// Build a new for statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1304 | /// |
| 1305 | /// By default, performs semantic analysis to build the new statement. |
| 1306 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1307 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1308 | Stmt *Init, Sema::ConditionResult Cond, |
| 1309 | Sema::FullExprArg Inc, SourceLocation RParenLoc, |
| 1310 | Stmt *Body) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1311 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1312 | Inc, RParenLoc, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1313 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1315 | /// Build a new goto statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1316 | /// |
| 1317 | /// By default, performs semantic analysis to build the new statement. |
| 1318 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1319 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1320 | LabelDecl *Label) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1321 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1324 | /// Build a new indirect goto statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1325 | /// |
| 1326 | /// By default, performs semantic analysis to build the new statement. |
| 1327 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1328 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1329 | SourceLocation StarLoc, |
| 1330 | Expr *Target) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1331 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1332 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1334 | /// Build a new return statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1335 | /// |
| 1336 | /// By default, performs semantic analysis to build the new statement. |
| 1337 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1338 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
| Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1339 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1340 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1341 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1342 | /// Build a new declaration statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1343 | /// |
| 1344 | /// By default, performs semantic analysis to build the new statement. |
| 1345 | /// Subclasses may override this routine to provide different behavior. |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1346 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
| Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1347 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1348 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
| Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1349 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1350 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1351 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1352 | /// Build a new inline asm statement. |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1353 | /// |
| 1354 | /// By default, performs semantic analysis to build the new statement. |
| 1355 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1356 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1357 | bool IsVolatile, unsigned NumOutputs, |
| 1358 | unsigned NumInputs, IdentifierInfo **Names, |
| 1359 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1360 | Expr *AsmString, MultiExprArg Clobbers, |
| 1361 | SourceLocation RParenLoc) { |
| 1362 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1363 | NumInputs, Names, Constraints, Exprs, |
| 1364 | AsmString, Clobbers, RParenLoc); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1365 | } |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1366 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1367 | /// Build a new MS style inline asm statement. |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1368 | /// |
| 1369 | /// By default, performs semantic analysis to build the new statement. |
| 1370 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1371 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1372 | ArrayRef<Token> AsmToks, |
| 1373 | StringRef AsmString, |
| 1374 | unsigned NumOutputs, unsigned NumInputs, |
| 1375 | ArrayRef<StringRef> Constraints, |
| 1376 | ArrayRef<StringRef> Clobbers, |
| 1377 | ArrayRef<Expr*> Exprs, |
| 1378 | SourceLocation EndLoc) { |
| 1379 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1380 | NumOutputs, NumInputs, |
| 1381 | Constraints, Clobbers, Exprs, EndLoc); |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1384 | /// Build a new co_return statement. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1385 | /// |
| 1386 | /// By default, performs semantic analysis to build the new statement. |
| 1387 | /// Subclasses may override this routine to provide different behavior. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1388 | StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, |
| 1389 | bool IsImplicit) { |
| 1390 | return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1393 | /// Build a new co_await expression. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1394 | /// |
| 1395 | /// By default, performs semantic analysis to build the new expression. |
| 1396 | /// Subclasses may override this routine to provide different behavior. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1397 | ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, |
| 1398 | bool IsImplicit) { |
| 1399 | return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit); |
| 1400 | } |
| 1401 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1402 | /// Build a new co_await expression. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1403 | /// |
| 1404 | /// By default, performs semantic analysis to build the new expression. |
| 1405 | /// Subclasses may override this routine to provide different behavior. |
| 1406 | ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, |
| 1407 | Expr *Result, |
| 1408 | UnresolvedLookupExpr *Lookup) { |
| 1409 | return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1412 | /// Build a new co_yield expression. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1413 | /// |
| 1414 | /// By default, performs semantic analysis to build the new expression. |
| 1415 | /// Subclasses may override this routine to provide different behavior. |
| 1416 | ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
| 1417 | return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
| 1418 | } |
| 1419 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1420 | StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { |
| 1421 | return getSema().BuildCoroutineBodyStmt(Args); |
| 1422 | } |
| 1423 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1424 | /// Build a new Objective-C \@try statement. |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1425 | /// |
| 1426 | /// By default, performs semantic analysis to build the new statement. |
| 1427 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1428 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1429 | Stmt *TryBody, |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1430 | MultiStmtArg CatchStmts, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1431 | Stmt *Finally) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1432 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1433 | Finally); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1436 | /// Rebuild an Objective-C exception declaration. |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1437 | /// |
| 1438 | /// By default, performs semantic analysis to build the new declaration. |
| 1439 | /// Subclasses may override this routine to provide different behavior. |
| 1440 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1441 | TypeSourceInfo *TInfo, QualType T) { |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1442 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1443 | ExceptionDecl->getInnerLocStart(), |
| 1444 | ExceptionDecl->getLocation(), |
| 1445 | ExceptionDecl->getIdentifier()); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1446 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1447 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1448 | /// Build a new Objective-C \@catch statement. |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1449 | /// |
| 1450 | /// By default, performs semantic analysis to build the new statement. |
| 1451 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1452 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1453 | SourceLocation RParenLoc, |
| 1454 | VarDecl *Var, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1455 | Stmt *Body) { |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1456 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1457 | Var, Body); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1458 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1459 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1460 | /// Build a new Objective-C \@finally statement. |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1461 | /// |
| 1462 | /// By default, performs semantic analysis to build the new statement. |
| 1463 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1464 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1465 | Stmt *Body) { |
| 1466 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1467 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1468 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1469 | /// Build a new Objective-C \@throw statement. |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1470 | /// |
| 1471 | /// By default, performs semantic analysis to build the new statement. |
| 1472 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1473 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1474 | Expr *Operand) { |
| 1475 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1476 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1477 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1478 | /// Build a new OpenMP executable directive. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1479 | /// |
| 1480 | /// By default, performs semantic analysis to build the new statement. |
| 1481 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1482 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1483 | DeclarationNameInfo DirName, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1484 | OpenMPDirectiveKind CancelRegion, |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1485 | ArrayRef<OMPClause *> Clauses, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1486 | Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1487 | SourceLocation EndLoc) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1488 | return getSema().ActOnOpenMPExecutableDirective( |
| 1489 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1492 | /// Build a new OpenMP 'if' clause. |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1493 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1494 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1495 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1496 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1497 | Expr *Condition, SourceLocation StartLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1498 | SourceLocation LParenLoc, |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1499 | SourceLocation NameModifierLoc, |
| 1500 | SourceLocation ColonLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1501 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1502 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
| 1503 | LParenLoc, NameModifierLoc, ColonLoc, |
| 1504 | EndLoc); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1507 | /// Build a new OpenMP 'final' clause. |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1508 | /// |
| 1509 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1510 | /// Subclasses may override this routine to provide different behavior. |
| 1511 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1512 | SourceLocation LParenLoc, |
| 1513 | SourceLocation EndLoc) { |
| 1514 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1515 | EndLoc); |
| 1516 | } |
| 1517 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1518 | /// Build a new OpenMP 'num_threads' clause. |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1519 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1520 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1521 | /// Subclasses may override this routine to provide different behavior. |
| 1522 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1523 | SourceLocation StartLoc, |
| 1524 | SourceLocation LParenLoc, |
| 1525 | SourceLocation EndLoc) { |
| 1526 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1527 | LParenLoc, EndLoc); |
| 1528 | } |
| 1529 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1530 | /// Build a new OpenMP 'safelen' clause. |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1531 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1532 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1533 | /// Subclasses may override this routine to provide different behavior. |
| 1534 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1535 | SourceLocation LParenLoc, |
| 1536 | SourceLocation EndLoc) { |
| 1537 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1538 | } |
| 1539 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1540 | /// Build a new OpenMP 'simdlen' clause. |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1541 | /// |
| 1542 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1543 | /// Subclasses may override this routine to provide different behavior. |
| 1544 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1545 | SourceLocation LParenLoc, |
| 1546 | SourceLocation EndLoc) { |
| 1547 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1548 | } |
| 1549 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1550 | /// Build a new OpenMP 'collapse' clause. |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1551 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1552 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1553 | /// Subclasses may override this routine to provide different behavior. |
| 1554 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1555 | SourceLocation LParenLoc, |
| 1556 | SourceLocation EndLoc) { |
| 1557 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1558 | EndLoc); |
| 1559 | } |
| 1560 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1561 | /// Build a new OpenMP 'default' clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1562 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1563 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1564 | /// Subclasses may override this routine to provide different behavior. |
| 1565 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1566 | SourceLocation KindKwLoc, |
| 1567 | SourceLocation StartLoc, |
| 1568 | SourceLocation LParenLoc, |
| 1569 | SourceLocation EndLoc) { |
| 1570 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1571 | StartLoc, LParenLoc, EndLoc); |
| 1572 | } |
| 1573 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1574 | /// Build a new OpenMP 'proc_bind' clause. |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1575 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1576 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1577 | /// Subclasses may override this routine to provide different behavior. |
| 1578 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1579 | SourceLocation KindKwLoc, |
| 1580 | SourceLocation StartLoc, |
| 1581 | SourceLocation LParenLoc, |
| 1582 | SourceLocation EndLoc) { |
| 1583 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1584 | StartLoc, LParenLoc, EndLoc); |
| 1585 | } |
| 1586 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1587 | /// Build a new OpenMP 'schedule' clause. |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1588 | /// |
| 1589 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1590 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1591 | OMPClause *RebuildOMPScheduleClause( |
| 1592 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 1593 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 1594 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 1595 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1596 | return getSema().ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1597 | M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
| 1598 | CommaLoc, EndLoc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1601 | /// Build a new OpenMP 'ordered' clause. |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1602 | /// |
| 1603 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1604 | /// Subclasses may override this routine to provide different behavior. |
| 1605 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1606 | SourceLocation EndLoc, |
| 1607 | SourceLocation LParenLoc, Expr *Num) { |
| 1608 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1609 | } |
| 1610 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1611 | /// Build a new OpenMP 'private' clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1612 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1613 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1616 | SourceLocation StartLoc, |
| 1617 | SourceLocation LParenLoc, |
| 1618 | SourceLocation EndLoc) { |
| 1619 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1620 | EndLoc); |
| 1621 | } |
| 1622 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1623 | /// Build a new OpenMP 'firstprivate' clause. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1624 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1625 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1626 | /// Subclasses may override this routine to provide different behavior. |
| 1627 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1628 | SourceLocation StartLoc, |
| 1629 | SourceLocation LParenLoc, |
| 1630 | SourceLocation EndLoc) { |
| 1631 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1632 | EndLoc); |
| 1633 | } |
| 1634 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1635 | /// Build a new OpenMP 'lastprivate' clause. |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1636 | /// |
| 1637 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1638 | /// Subclasses may override this routine to provide different behavior. |
| 1639 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1640 | SourceLocation StartLoc, |
| 1641 | SourceLocation LParenLoc, |
| 1642 | SourceLocation EndLoc) { |
| 1643 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1644 | EndLoc); |
| 1645 | } |
| 1646 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1647 | /// Build a new OpenMP 'shared' clause. |
| Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1648 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1649 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1650 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1651 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1652 | SourceLocation StartLoc, |
| 1653 | SourceLocation LParenLoc, |
| 1654 | SourceLocation EndLoc) { |
| 1655 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1656 | EndLoc); |
| 1657 | } |
| 1658 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1659 | /// Build a new OpenMP 'reduction' clause. |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1660 | /// |
| 1661 | /// By default, performs semantic analysis to build the new statement. |
| 1662 | /// Subclasses may override this routine to provide different behavior. |
| 1663 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1664 | SourceLocation StartLoc, |
| 1665 | SourceLocation LParenLoc, |
| 1666 | SourceLocation ColonLoc, |
| 1667 | SourceLocation EndLoc, |
| 1668 | CXXScopeSpec &ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1669 | const DeclarationNameInfo &ReductionId, |
| 1670 | ArrayRef<Expr *> UnresolvedReductions) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1671 | return getSema().ActOnOpenMPReductionClause( |
| 1672 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1673 | ReductionId, UnresolvedReductions); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 1676 | /// Build a new OpenMP 'task_reduction' clause. |
| 1677 | /// |
| 1678 | /// By default, performs semantic analysis to build the new statement. |
| 1679 | /// Subclasses may override this routine to provide different behavior. |
| 1680 | OMPClause *RebuildOMPTaskReductionClause( |
| 1681 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1682 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 1683 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1684 | const DeclarationNameInfo &ReductionId, |
| 1685 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1686 | return getSema().ActOnOpenMPTaskReductionClause( |
| 1687 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1688 | ReductionId, UnresolvedReductions); |
| 1689 | } |
| 1690 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1691 | /// Build a new OpenMP 'in_reduction' clause. |
| 1692 | /// |
| 1693 | /// By default, performs semantic analysis to build the new statement. |
| 1694 | /// Subclasses may override this routine to provide different behavior. |
| 1695 | OMPClause * |
| 1696 | RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1697 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1698 | SourceLocation EndLoc, |
| 1699 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1700 | const DeclarationNameInfo &ReductionId, |
| 1701 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1702 | return getSema().ActOnOpenMPInReductionClause( |
| 1703 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1704 | ReductionId, UnresolvedReductions); |
| 1705 | } |
| 1706 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1707 | /// Build a new OpenMP 'linear' clause. |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1708 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1709 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1710 | /// Subclasses may override this routine to provide different behavior. |
| 1711 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1712 | SourceLocation StartLoc, |
| 1713 | SourceLocation LParenLoc, |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1714 | OpenMPLinearClauseKind Modifier, |
| 1715 | SourceLocation ModifierLoc, |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1716 | SourceLocation ColonLoc, |
| 1717 | SourceLocation EndLoc) { |
| 1718 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1719 | Modifier, ModifierLoc, ColonLoc, |
| 1720 | EndLoc); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1723 | /// Build a new OpenMP 'aligned' clause. |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1724 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1725 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1726 | /// Subclasses may override this routine to provide different behavior. |
| 1727 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1728 | SourceLocation StartLoc, |
| 1729 | SourceLocation LParenLoc, |
| 1730 | SourceLocation ColonLoc, |
| 1731 | SourceLocation EndLoc) { |
| 1732 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1733 | LParenLoc, ColonLoc, EndLoc); |
| 1734 | } |
| 1735 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1736 | /// Build a new OpenMP 'copyin' clause. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1737 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1738 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1739 | /// Subclasses may override this routine to provide different behavior. |
| 1740 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1741 | SourceLocation StartLoc, |
| 1742 | SourceLocation LParenLoc, |
| 1743 | SourceLocation EndLoc) { |
| 1744 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1745 | EndLoc); |
| 1746 | } |
| 1747 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1748 | /// Build a new OpenMP 'copyprivate' clause. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1749 | /// |
| 1750 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1751 | /// Subclasses may override this routine to provide different behavior. |
| 1752 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1753 | SourceLocation StartLoc, |
| 1754 | SourceLocation LParenLoc, |
| 1755 | SourceLocation EndLoc) { |
| 1756 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1757 | EndLoc); |
| 1758 | } |
| 1759 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1760 | /// Build a new OpenMP 'flush' pseudo clause. |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1761 | /// |
| 1762 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1763 | /// Subclasses may override this routine to provide different behavior. |
| 1764 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1765 | SourceLocation StartLoc, |
| 1766 | SourceLocation LParenLoc, |
| 1767 | SourceLocation EndLoc) { |
| 1768 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1769 | EndLoc); |
| 1770 | } |
| 1771 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1772 | /// Build a new OpenMP 'depend' pseudo clause. |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1773 | /// |
| 1774 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1775 | /// Subclasses may override this routine to provide different behavior. |
| 1776 | OMPClause * |
| 1777 | RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1778 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1779 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1780 | SourceLocation EndLoc) { |
| 1781 | return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, |
| 1782 | StartLoc, LParenLoc, EndLoc); |
| 1783 | } |
| 1784 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1785 | /// Build a new OpenMP 'device' clause. |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1786 | /// |
| 1787 | /// By default, performs semantic analysis to build the new statement. |
| 1788 | /// Subclasses may override this routine to provide different behavior. |
| 1789 | OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 1790 | SourceLocation LParenLoc, |
| 1791 | SourceLocation EndLoc) { |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1792 | return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1793 | EndLoc); |
| 1794 | } |
| 1795 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1796 | /// Build a new OpenMP 'map' clause. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1797 | /// |
| 1798 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1799 | /// Subclasses may override this routine to provide different behavior. |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1800 | OMPClause * |
| 1801 | RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 1802 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 1803 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 1804 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1805 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 1806 | return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType, |
| 1807 | IsMapTypeImplicit, MapLoc, ColonLoc, |
| 1808 | VarList, StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1811 | /// Build a new OpenMP 'num_teams' clause. |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1812 | /// |
| 1813 | /// By default, performs semantic analysis to build the new statement. |
| 1814 | /// Subclasses may override this routine to provide different behavior. |
| 1815 | OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
| 1816 | SourceLocation LParenLoc, |
| 1817 | SourceLocation EndLoc) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1818 | return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1819 | EndLoc); |
| 1820 | } |
| 1821 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1822 | /// Build a new OpenMP 'thread_limit' clause. |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1823 | /// |
| 1824 | /// By default, performs semantic analysis to build the new statement. |
| 1825 | /// Subclasses may override this routine to provide different behavior. |
| 1826 | OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, |
| 1827 | SourceLocation StartLoc, |
| 1828 | SourceLocation LParenLoc, |
| 1829 | SourceLocation EndLoc) { |
| 1830 | return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, |
| 1831 | LParenLoc, EndLoc); |
| 1832 | } |
| 1833 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1834 | /// Build a new OpenMP 'priority' clause. |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1835 | /// |
| 1836 | /// By default, performs semantic analysis to build the new statement. |
| 1837 | /// Subclasses may override this routine to provide different behavior. |
| 1838 | OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 1839 | SourceLocation LParenLoc, |
| 1840 | SourceLocation EndLoc) { |
| 1841 | return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, |
| 1842 | EndLoc); |
| 1843 | } |
| 1844 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1845 | /// Build a new OpenMP 'grainsize' clause. |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1846 | /// |
| 1847 | /// By default, performs semantic analysis to build the new statement. |
| 1848 | /// Subclasses may override this routine to provide different behavior. |
| 1849 | OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, |
| 1850 | SourceLocation LParenLoc, |
| 1851 | SourceLocation EndLoc) { |
| 1852 | return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, |
| 1853 | EndLoc); |
| 1854 | } |
| 1855 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1856 | /// Build a new OpenMP 'num_tasks' clause. |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1857 | /// |
| 1858 | /// By default, performs semantic analysis to build the new statement. |
| 1859 | /// Subclasses may override this routine to provide different behavior. |
| 1860 | OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
| 1861 | SourceLocation LParenLoc, |
| 1862 | SourceLocation EndLoc) { |
| 1863 | return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, |
| 1864 | EndLoc); |
| 1865 | } |
| 1866 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1867 | /// Build a new OpenMP 'hint' clause. |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1868 | /// |
| 1869 | /// By default, performs semantic analysis to build the new statement. |
| 1870 | /// Subclasses may override this routine to provide different behavior. |
| 1871 | OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 1872 | SourceLocation LParenLoc, |
| 1873 | SourceLocation EndLoc) { |
| 1874 | return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); |
| 1875 | } |
| 1876 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1877 | /// Build a new OpenMP 'dist_schedule' clause. |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1878 | /// |
| 1879 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1880 | /// Subclasses may override this routine to provide different behavior. |
| 1881 | OMPClause * |
| 1882 | RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
| 1883 | Expr *ChunkSize, SourceLocation StartLoc, |
| 1884 | SourceLocation LParenLoc, SourceLocation KindLoc, |
| 1885 | SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 1886 | return getSema().ActOnOpenMPDistScheduleClause( |
| 1887 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1888 | } |
| 1889 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1890 | /// Build a new OpenMP 'to' clause. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1891 | /// |
| 1892 | /// By default, performs semantic analysis to build the new statement. |
| 1893 | /// Subclasses may override this routine to provide different behavior. |
| 1894 | OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList, |
| 1895 | SourceLocation StartLoc, |
| 1896 | SourceLocation LParenLoc, |
| 1897 | SourceLocation EndLoc) { |
| 1898 | return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 1899 | } |
| 1900 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1901 | /// Build a new OpenMP 'from' clause. |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1902 | /// |
| 1903 | /// By default, performs semantic analysis to build the new statement. |
| 1904 | /// Subclasses may override this routine to provide different behavior. |
| 1905 | OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList, |
| 1906 | SourceLocation StartLoc, |
| 1907 | SourceLocation LParenLoc, |
| 1908 | SourceLocation EndLoc) { |
| 1909 | return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, |
| 1910 | EndLoc); |
| 1911 | } |
| 1912 | |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1913 | /// Build a new OpenMP 'use_device_ptr' clause. |
| 1914 | /// |
| 1915 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1916 | /// Subclasses may override this routine to provide different behavior. |
| 1917 | OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 1918 | SourceLocation StartLoc, |
| 1919 | SourceLocation LParenLoc, |
| 1920 | SourceLocation EndLoc) { |
| 1921 | return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, |
| 1922 | EndLoc); |
| 1923 | } |
| 1924 | |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1925 | /// Build a new OpenMP 'is_device_ptr' clause. |
| 1926 | /// |
| 1927 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1928 | /// Subclasses may override this routine to provide different behavior. |
| 1929 | OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 1930 | SourceLocation StartLoc, |
| 1931 | SourceLocation LParenLoc, |
| 1932 | SourceLocation EndLoc) { |
| 1933 | return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, |
| 1934 | EndLoc); |
| 1935 | } |
| 1936 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1937 | /// Rebuild the operand to an Objective-C \@synchronized statement. |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1938 | /// |
| 1939 | /// By default, performs semantic analysis to build the new statement. |
| 1940 | /// Subclasses may override this routine to provide different behavior. |
| 1941 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1942 | Expr *object) { |
| 1943 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1944 | } |
| 1945 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1946 | /// Build a new Objective-C \@synchronized statement. |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1947 | /// |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1948 | /// By default, performs semantic analysis to build the new statement. |
| 1949 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1950 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1951 | Expr *Object, Stmt *Body) { |
| 1952 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1953 | } |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1954 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1955 | /// Build a new Objective-C \@autoreleasepool statement. |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1956 | /// |
| 1957 | /// By default, performs semantic analysis to build the new statement. |
| 1958 | /// Subclasses may override this routine to provide different behavior. |
| 1959 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 1960 | Stmt *Body) { |
| 1961 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 1962 | } |
| John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 1963 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1964 | /// Build a new Objective-C fast enumeration statement. |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1965 | /// |
| 1966 | /// By default, performs semantic analysis to build the new statement. |
| 1967 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1968 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1969 | Stmt *Element, |
| 1970 | Expr *Collection, |
| 1971 | SourceLocation RParenLoc, |
| 1972 | Stmt *Body) { |
| Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 1973 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
| Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1974 | Element, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1975 | Collection, |
| Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 1976 | RParenLoc); |
| 1977 | if (ForEachStmt.isInvalid()) |
| 1978 | return StmtError(); |
| 1979 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1980 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 1981 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1982 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1983 | /// Build a new C++ exception declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1984 | /// |
| 1985 | /// By default, performs semantic analysis to build the new decaration. |
| 1986 | /// Subclasses may override this routine to provide different behavior. |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1987 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1988 | TypeSourceInfo *Declarator, |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1989 | SourceLocation StartLoc, |
| 1990 | SourceLocation IdLoc, |
| 1991 | IdentifierInfo *Id) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1992 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
| Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 1993 | StartLoc, IdLoc, Id); |
| 1994 | if (Var) |
| 1995 | getSema().CurContext->addDecl(Var); |
| 1996 | return Var; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1999 | /// Build a new C++ catch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2000 | /// |
| 2001 | /// By default, performs semantic analysis to build the new statement. |
| 2002 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2003 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2004 | VarDecl *ExceptionDecl, |
| 2005 | Stmt *Handler) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2006 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 2007 | Handler)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2008 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2010 | /// Build a new C++ try statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2011 | /// |
| 2012 | /// By default, performs semantic analysis to build the new statement. |
| 2013 | /// Subclasses may override this routine to provide different behavior. |
| Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 2014 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 2015 | ArrayRef<Stmt *> Handlers) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2016 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2017 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2019 | /// Build a new C++0x range-based for statement. |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2020 | /// |
| 2021 | /// By default, performs semantic analysis to build the new statement. |
| 2022 | /// Subclasses may override this routine to provide different behavior. |
| 2023 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 2024 | SourceLocation CoawaitLoc, |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2025 | SourceLocation ColonLoc, |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 2026 | Stmt *Range, Stmt *Begin, Stmt *End, |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2027 | Expr *Cond, Expr *Inc, |
| 2028 | Stmt *LoopVar, |
| 2029 | SourceLocation RParenLoc) { |
| Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 2030 | // If we've just learned that the range is actually an Objective-C |
| 2031 | // collection, treat this as an Objective-C fast enumeration loop. |
| 2032 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 2033 | if (RangeStmt->isSingleDecl()) { |
| 2034 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 2035 | if (RangeVar->isInvalidDecl()) |
| 2036 | return StmtError(); |
| 2037 | |
| Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 2038 | Expr *RangeExpr = RangeVar->getInit(); |
| 2039 | if (!RangeExpr->isTypeDependent() && |
| 2040 | RangeExpr->getType()->isObjCObjectPointerType()) |
| 2041 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr, |
| 2042 | RParenLoc); |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 2047 | return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc, |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 2048 | Range, Begin, End, |
| Richard Smith | a05b3b5 | 2012-09-20 21:52:32 +0000 | [diff] [blame] | 2049 | Cond, Inc, LoopVar, RParenLoc, |
| 2050 | Sema::BFRK_Rebuild); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2051 | } |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2052 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2053 | /// Build a new C++0x range-based for statement. |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2054 | /// |
| 2055 | /// By default, performs semantic analysis to build the new statement. |
| 2056 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2057 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2058 | bool IsIfExists, |
| 2059 | NestedNameSpecifierLoc QualifierLoc, |
| 2060 | DeclarationNameInfo NameInfo, |
| 2061 | Stmt *Nested) { |
| 2062 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 2063 | QualifierLoc, NameInfo, Nested); |
| 2064 | } |
| 2065 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2066 | /// Attach body to a C++0x range-based for statement. |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2067 | /// |
| 2068 | /// By default, performs semantic analysis to finish the new statement. |
| 2069 | /// Subclasses may override this routine to provide different behavior. |
| 2070 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 2071 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 2072 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2073 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2074 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 2075 | Stmt *TryBlock, Stmt *Handler) { |
| 2076 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2079 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2080 | Stmt *Block) { |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2081 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2084 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| Nico Weber | d64657f | 2015-03-09 02:47:59 +0000 | [diff] [blame] | 2085 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2088 | /// Build a new predefined expression. |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 2089 | /// |
| 2090 | /// By default, performs semantic analysis to build the new expression. |
| 2091 | /// Subclasses may override this routine to provide different behavior. |
| 2092 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 2093 | PredefinedExpr::IdentType IT) { |
| 2094 | return getSema().BuildPredefinedExpr(Loc, IT); |
| 2095 | } |
| 2096 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2097 | /// Build a new expression that references a declaration. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2098 | /// |
| 2099 | /// By default, performs semantic analysis to build the new expression. |
| 2100 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2101 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2102 | LookupResult &R, |
| 2103 | bool RequiresADL) { |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2104 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 2105 | } |
| 2106 | |
| 2107 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2108 | /// Build a new expression that references a declaration. |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2109 | /// |
| 2110 | /// By default, performs semantic analysis to build the new expression. |
| 2111 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2112 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2113 | ValueDecl *VD, |
| 2114 | const DeclarationNameInfo &NameInfo, |
| 2115 | TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 2116 | CXXScopeSpec SS; |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2117 | SS.Adopt(QualifierLoc); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 2118 | |
| 2119 | // FIXME: loses template args. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2120 | |
| 2121 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2122 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2123 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2124 | /// Build a new expression in parentheses. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2125 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2126 | /// By default, performs semantic analysis to build the new expression. |
| 2127 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2128 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2129 | SourceLocation RParen) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2130 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2133 | /// Build a new pseudo-destructor expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2134 | /// |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 2135 | /// By default, performs semantic analysis to build the new expression. |
| 2136 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2137 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 2138 | SourceLocation OperatorLoc, |
| 2139 | bool isArrow, |
| 2140 | CXXScopeSpec &SS, |
| 2141 | TypeSourceInfo *ScopeType, |
| 2142 | SourceLocation CCLoc, |
| 2143 | SourceLocation TildeLoc, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 2144 | PseudoDestructorTypeStorage Destroyed); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2146 | /// Build a new unary operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2147 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2148 | /// By default, performs semantic analysis to build the new expression. |
| 2149 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2150 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2151 | UnaryOperatorKind Opc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2152 | Expr *SubExpr) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2153 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2154 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2155 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2156 | /// Build a new builtin offsetof expression. |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2157 | /// |
| 2158 | /// By default, performs semantic analysis to build the new expression. |
| 2159 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2160 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2161 | TypeSourceInfo *Type, |
| 2162 | ArrayRef<Sema::OffsetOfComponent> Components, |
| 2163 | SourceLocation RParenLoc) { |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2164 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2165 | RParenLoc); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2166 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2167 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2168 | /// Build a new sizeof, alignof or vec_step expression with a |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2169 | /// type argument. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2171 | /// By default, performs semantic analysis to build the new expression. |
| 2172 | /// Subclasses may override this routine to provide different behavior. |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2173 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 2174 | SourceLocation OpLoc, |
| 2175 | UnaryExprOrTypeTrait ExprKind, |
| 2176 | SourceRange R) { |
| 2177 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2180 | /// Build a new sizeof, alignof or vec step expression with an |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2181 | /// expression argument. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2182 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2183 | /// By default, performs semantic analysis to build the new expression. |
| 2184 | /// Subclasses may override this routine to provide different behavior. |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2185 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 2186 | UnaryExprOrTypeTrait ExprKind, |
| 2187 | SourceRange R) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2188 | ExprResult Result |
| Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 2189 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2190 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2191 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2192 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2193 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2194 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2195 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2196 | /// Build a new array subscript expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2197 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2198 | /// By default, performs semantic analysis to build the new expression. |
| 2199 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2200 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2201 | SourceLocation LBracketLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2202 | Expr *RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2203 | SourceLocation RBracketLoc) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2204 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2205 | LBracketLoc, RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2206 | RBracketLoc); |
| 2207 | } |
| 2208 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2209 | /// Build a new array section expression. |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 2210 | /// |
| 2211 | /// By default, performs semantic analysis to build the new expression. |
| 2212 | /// Subclasses may override this routine to provide different behavior. |
| 2213 | ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, |
| 2214 | Expr *LowerBound, |
| 2215 | SourceLocation ColonLoc, Expr *Length, |
| 2216 | SourceLocation RBracketLoc) { |
| 2217 | return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, |
| 2218 | ColonLoc, Length, RBracketLoc); |
| 2219 | } |
| 2220 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2221 | /// Build a new call expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2223 | /// By default, performs semantic analysis to build the new expression. |
| 2224 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2225 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2226 | MultiExprArg Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 2227 | SourceLocation RParenLoc, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2228 | Expr *ExecConfig = nullptr) { |
| 2229 | return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2230 | Args, RParenLoc, ExecConfig); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2233 | /// Build a new member access expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2234 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2235 | /// By default, performs semantic analysis to build the new expression. |
| 2236 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2237 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2238 | bool isArrow, |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2239 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2240 | SourceLocation TemplateKWLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2241 | const DeclarationNameInfo &MemberNameInfo, |
| 2242 | ValueDecl *Member, |
| 2243 | NamedDecl *FoundDecl, |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2244 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2245 | NamedDecl *FirstQualifierInScope) { |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2246 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 2247 | isArrow); |
| Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2248 | if (!Member->getDeclName()) { |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2249 | // We have a reference to an unnamed field. This is always the |
| 2250 | // base of an anonymous struct/union member access, i.e. the |
| 2251 | // field is always of record type. |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2252 | assert(Member->getType()->isRecordType() && |
| 2253 | "unnamed member not of record type?"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2254 | |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2255 | BaseResult = |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2256 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
| John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2257 | QualifierLoc.getNestedNameSpecifier(), |
| 2258 | FoundDecl, Member); |
| 2259 | if (BaseResult.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2260 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2261 | Base = BaseResult.get(); |
| Eric Fiselier | 8439361 | 2018-04-08 05:11:59 +0000 | [diff] [blame] | 2262 | |
| 2263 | CXXScopeSpec EmptySS; |
| 2264 | return getSema().BuildFieldReferenceExpr( |
| 2265 | Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), |
| 2266 | DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo); |
| Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2267 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2268 | |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2269 | CXXScopeSpec SS; |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2270 | SS.Adopt(QualifierLoc); |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2271 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2272 | Base = BaseResult.get(); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2273 | QualType BaseType = Base->getType(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2274 | |
| Saleem Abdulrasool | 1f5f5c2 | 2017-04-20 22:23:10 +0000 | [diff] [blame] | 2275 | if (isArrow && !BaseType->isPointerType()) |
| 2276 | return ExprError(); |
| 2277 | |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2278 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 2279 | // cases; we should avoid this when possible. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2280 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2281 | R.addDecl(FoundDecl); |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2282 | R.resolveKind(); |
| 2283 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2284 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2285 | SS, TemplateKWLoc, |
| 2286 | FirstQualifierInScope, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2287 | R, ExplicitTemplateArgs, |
| 2288 | /*S*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2289 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2290 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2291 | /// Build a new binary operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2292 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2293 | /// By default, performs semantic analysis to build the new expression. |
| 2294 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2295 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2296 | BinaryOperatorKind Opc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2297 | Expr *LHS, Expr *RHS) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2298 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2301 | /// Build a new conditional operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2303 | /// By default, performs semantic analysis to build the new expression. |
| 2304 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2305 | ExprResult RebuildConditionalOperator(Expr *Cond, |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2306 | SourceLocation QuestionLoc, |
| 2307 | Expr *LHS, |
| 2308 | SourceLocation ColonLoc, |
| 2309 | Expr *RHS) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2310 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 2311 | LHS, RHS); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2314 | /// Build a new C-style cast expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2315 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2316 | /// By default, performs semantic analysis to build the new expression. |
| 2317 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2318 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2319 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2320 | SourceLocation RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2321 | Expr *SubExpr) { |
| John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 2322 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2323 | SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2324 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2325 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2326 | /// Build a new compound literal expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2327 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2328 | /// By default, performs semantic analysis to build the new expression. |
| 2329 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2330 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2331 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2332 | SourceLocation RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2333 | Expr *Init) { |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2334 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2335 | Init); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2336 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2337 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2338 | /// Build a new extended vector element access expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2339 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2340 | /// By default, performs semantic analysis to build the new expression. |
| 2341 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2342 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2343 | SourceLocation OpLoc, |
| 2344 | SourceLocation AccessorLoc, |
| 2345 | IdentifierInfo &Accessor) { |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2346 | |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2347 | CXXScopeSpec SS; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2348 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2349 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2350 | OpLoc, /*IsArrow*/ false, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2351 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2352 | /*FirstQualifierInScope*/ nullptr, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2353 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2354 | /* TemplateArgs */ nullptr, |
| 2355 | /*S*/ nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2356 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2357 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2358 | /// Build a new initializer list expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2360 | /// By default, performs semantic analysis to build the new expression. |
| 2361 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2362 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
| John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2363 | MultiExprArg Inits, |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 2364 | SourceLocation RBraceLoc) { |
| 2365 | return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2366 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2368 | /// Build a new designated initializer expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2369 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2370 | /// By default, performs semantic analysis to build the new expression. |
| 2371 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2372 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2373 | MultiExprArg ArrayExprs, |
| 2374 | SourceLocation EqualOrColonLoc, |
| 2375 | bool GNUSyntax, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2376 | Expr *Init) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2377 | ExprResult Result |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2378 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2379 | Init); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2380 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2381 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2382 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2383 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2384 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2385 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2386 | /// Build a new value-initialized expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2387 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2388 | /// By default, builds the implicit value initialization without performing |
| 2389 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2390 | /// different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2391 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2392 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2393 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2394 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2395 | /// Build a new \c va_arg expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2396 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2397 | /// By default, performs semantic analysis to build the new expression. |
| 2398 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2399 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2400 | Expr *SubExpr, TypeSourceInfo *TInfo, |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2401 | SourceLocation RParenLoc) { |
| 2402 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2403 | SubExpr, TInfo, |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2404 | RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2407 | /// Build a new expression list in parentheses. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2408 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2411 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2412 | MultiExprArg SubExprs, |
| 2413 | SourceLocation RParenLoc) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2414 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2415 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2416 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2417 | /// Build a new address-of-label expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2418 | /// |
| 2419 | /// By default, performs semantic analysis, using the name of the label |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2420 | /// rather than attempting to map the label statement itself. |
| 2421 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2422 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2423 | SourceLocation LabelLoc, LabelDecl *Label) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2424 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2425 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2426 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2427 | /// Build a new GNU statement expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2428 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2429 | /// By default, performs semantic analysis to build the new expression. |
| 2430 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2431 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2432 | Stmt *SubStmt, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2433 | SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2434 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2435 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2436 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2437 | /// Build a new __builtin_choose_expr expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2438 | /// |
| 2439 | /// By default, performs semantic analysis to build the new expression. |
| 2440 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2441 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2442 | Expr *Cond, Expr *LHS, Expr *RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2443 | SourceLocation RParenLoc) { |
| 2444 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2445 | Cond, LHS, RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2446 | RParenLoc); |
| 2447 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2448 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2449 | /// Build a new generic selection expression. |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2450 | /// |
| 2451 | /// By default, performs semantic analysis to build the new expression. |
| 2452 | /// Subclasses may override this routine to provide different behavior. |
| 2453 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2454 | SourceLocation DefaultLoc, |
| 2455 | SourceLocation RParenLoc, |
| 2456 | Expr *ControllingExpr, |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2457 | ArrayRef<TypeSourceInfo *> Types, |
| 2458 | ArrayRef<Expr *> Exprs) { |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2459 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2460 | ControllingExpr, Types, Exprs); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2463 | /// Build a new overloaded operator call expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2464 | /// |
| 2465 | /// By default, performs semantic analysis to build the new expression. |
| 2466 | /// The semantic analysis provides the behavior of template instantiation, |
| 2467 | /// copying with transformations that turn what looks like an overloaded |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2468 | /// operator call into a use of a builtin operator, performing |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2469 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2470 | /// provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2471 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2472 | SourceLocation OpLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2473 | Expr *Callee, |
| 2474 | Expr *First, |
| 2475 | Expr *Second); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2476 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2477 | /// Build a new C++ "named" cast expression, such as static_cast or |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2478 | /// reinterpret_cast. |
| 2479 | /// |
| 2480 | /// By default, this routine dispatches to one of the more-specific routines |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2481 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2482 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2483 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2484 | Stmt::StmtClass Class, |
| 2485 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2486 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2487 | SourceLocation RAngleLoc, |
| 2488 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2489 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2490 | SourceLocation RParenLoc) { |
| 2491 | switch (Class) { |
| 2492 | case Stmt::CXXStaticCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2493 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2494 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2495 | SubExpr, RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2496 | |
| 2497 | case Stmt::CXXDynamicCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2498 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2499 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2500 | SubExpr, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2501 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2502 | case Stmt::CXXReinterpretCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2503 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2504 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2505 | SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2506 | RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2507 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2508 | case Stmt::CXXConstCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2509 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2510 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2511 | SubExpr, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2512 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2513 | default: |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2514 | llvm_unreachable("Invalid C++ named cast"); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2515 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2516 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2517 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2518 | /// Build a new C++ static_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2519 | /// |
| 2520 | /// By default, performs semantic analysis to build the new expression. |
| 2521 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2522 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2523 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2524 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2525 | SourceLocation RAngleLoc, |
| 2526 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2527 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2528 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2529 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2530 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2531 | SourceRange(LAngleLoc, RAngleLoc), |
| 2532 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2533 | } |
| 2534 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2535 | /// Build a new C++ dynamic_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2536 | /// |
| 2537 | /// By default, performs semantic analysis to build the new expression. |
| 2538 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2539 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2540 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2541 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2542 | SourceLocation RAngleLoc, |
| 2543 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2544 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2545 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2546 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2547 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2548 | SourceRange(LAngleLoc, RAngleLoc), |
| 2549 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2552 | /// Build a new C++ reinterpret_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2553 | /// |
| 2554 | /// By default, performs semantic analysis to build the new expression. |
| 2555 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2556 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2557 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2558 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2559 | SourceLocation RAngleLoc, |
| 2560 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2561 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2562 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2563 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2564 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2565 | SourceRange(LAngleLoc, RAngleLoc), |
| 2566 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2569 | /// Build a new C++ const_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2570 | /// |
| 2571 | /// By default, performs semantic analysis to build the new expression. |
| 2572 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2573 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2574 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2575 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2576 | SourceLocation RAngleLoc, |
| 2577 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2578 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2579 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2580 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2581 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2582 | SourceRange(LAngleLoc, RAngleLoc), |
| 2583 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2584 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2585 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2586 | /// Build a new C++ functional-style cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2587 | /// |
| 2588 | /// By default, performs semantic analysis to build the new expression. |
| 2589 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2590 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2591 | SourceLocation LParenLoc, |
| 2592 | Expr *Sub, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2593 | SourceLocation RParenLoc, |
| 2594 | bool ListInitialization) { |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2595 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2596 | MultiExprArg(&Sub, 1), RParenLoc, |
| 2597 | ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2598 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2599 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2600 | /// Build a new C++ typeid(type) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2601 | /// |
| 2602 | /// By default, performs semantic analysis to build the new expression. |
| 2603 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2604 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2605 | SourceLocation TypeidLoc, |
| 2606 | TypeSourceInfo *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2607 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2608 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2609 | RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2610 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2611 | |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2612 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2613 | /// Build a new C++ typeid(expr) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2614 | /// |
| 2615 | /// By default, performs semantic analysis to build the new expression. |
| 2616 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2617 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2618 | SourceLocation TypeidLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2619 | Expr *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2620 | SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2621 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2622 | RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2625 | /// Build a new C++ __uuidof(type) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2626 | /// |
| 2627 | /// By default, performs semantic analysis to build the new expression. |
| 2628 | /// Subclasses may override this routine to provide different behavior. |
| 2629 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2630 | SourceLocation TypeidLoc, |
| 2631 | TypeSourceInfo *Operand, |
| 2632 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2633 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2634 | RParenLoc); |
| 2635 | } |
| 2636 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2637 | /// Build a new C++ __uuidof(expr) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2638 | /// |
| 2639 | /// By default, performs semantic analysis to build the new expression. |
| 2640 | /// Subclasses may override this routine to provide different behavior. |
| 2641 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2642 | SourceLocation TypeidLoc, |
| 2643 | Expr *Operand, |
| 2644 | SourceLocation RParenLoc) { |
| 2645 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2646 | RParenLoc); |
| 2647 | } |
| 2648 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2649 | /// Build a new C++ "this" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2650 | /// |
| 2651 | /// By default, builds a new "this" expression without performing any |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2652 | /// semantic analysis. Subclasses may override this routine to provide |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2653 | /// different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2654 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2655 | QualType ThisType, |
| 2656 | bool isImplicit) { |
| Eli Friedman | 20139d3 | 2012-01-11 02:36:31 +0000 | [diff] [blame] | 2657 | getSema().CheckCXXThisCapture(ThisLoc); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2658 | return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2661 | /// Build a new C++ throw expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2662 | /// |
| 2663 | /// By default, performs semantic analysis to build the new expression. |
| 2664 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2665 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2666 | bool IsThrownVariableInScope) { |
| 2667 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2670 | /// Build a new C++ default-argument expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2671 | /// |
| 2672 | /// By default, builds a new default-argument expression, which does not |
| 2673 | /// require any semantic analysis. Subclasses may override this routine to |
| 2674 | /// provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2675 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, |
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 2676 | ParmVarDecl *Param) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2677 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2680 | /// Build a new C++11 default-initialization expression. |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2681 | /// |
| 2682 | /// By default, builds a new default field initialization expression, which |
| 2683 | /// does not require any semantic analysis. Subclasses may override this |
| 2684 | /// routine to provide different behavior. |
| 2685 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2686 | FieldDecl *Field) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2687 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2690 | /// Build a new C++ zero-initialization expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2691 | /// |
| 2692 | /// By default, performs semantic analysis to build the new expression. |
| 2693 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2694 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2695 | SourceLocation LParenLoc, |
| 2696 | SourceLocation RParenLoc) { |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2697 | return getSema().BuildCXXTypeConstructExpr( |
| 2698 | TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2699 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2700 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2701 | /// Build a new C++ "new" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2702 | /// |
| 2703 | /// By default, performs semantic analysis to build the new expression. |
| 2704 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2705 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2706 | bool UseGlobal, |
| 2707 | SourceLocation PlacementLParen, |
| 2708 | MultiExprArg PlacementArgs, |
| 2709 | SourceLocation PlacementRParen, |
| 2710 | SourceRange TypeIdParens, |
| 2711 | QualType AllocatedType, |
| 2712 | TypeSourceInfo *AllocatedTypeInfo, |
| 2713 | Expr *ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2714 | SourceRange DirectInitRange, |
| 2715 | Expr *Initializer) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2716 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2717 | PlacementLParen, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2718 | PlacementArgs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2719 | PlacementRParen, |
| Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2720 | TypeIdParens, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2721 | AllocatedType, |
| 2722 | AllocatedTypeInfo, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2723 | ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2724 | DirectInitRange, |
| 2725 | Initializer); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2726 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2727 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2728 | /// Build a new C++ "delete" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2729 | /// |
| 2730 | /// By default, performs semantic analysis to build the new expression. |
| 2731 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2732 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2733 | bool IsGlobalDelete, |
| 2734 | bool IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2735 | Expr *Operand) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2736 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2737 | Operand); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2738 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2739 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2740 | /// Build a new type trait expression. |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2741 | /// |
| 2742 | /// By default, performs semantic analysis to build the new expression. |
| 2743 | /// Subclasses may override this routine to provide different behavior. |
| 2744 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2745 | SourceLocation StartLoc, |
| 2746 | ArrayRef<TypeSourceInfo *> Args, |
| 2747 | SourceLocation RParenLoc) { |
| 2748 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2749 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2750 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2751 | /// Build a new array type trait expression. |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2752 | /// |
| 2753 | /// By default, performs semantic analysis to build the new expression. |
| 2754 | /// Subclasses may override this routine to provide different behavior. |
| 2755 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2756 | SourceLocation StartLoc, |
| 2757 | TypeSourceInfo *TSInfo, |
| 2758 | Expr *DimExpr, |
| 2759 | SourceLocation RParenLoc) { |
| 2760 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2761 | } |
| 2762 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2763 | /// Build a new expression trait expression. |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2764 | /// |
| 2765 | /// By default, performs semantic analysis to build the new expression. |
| 2766 | /// Subclasses may override this routine to provide different behavior. |
| 2767 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2768 | SourceLocation StartLoc, |
| 2769 | Expr *Queried, |
| 2770 | SourceLocation RParenLoc) { |
| 2771 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2772 | } |
| 2773 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2774 | /// Build a new (previously unresolved) declaration reference |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2775 | /// expression. |
| 2776 | /// |
| 2777 | /// By default, performs semantic analysis to build the new expression. |
| 2778 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2779 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2780 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2781 | SourceLocation TemplateKWLoc, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2782 | const DeclarationNameInfo &NameInfo, |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2783 | const TemplateArgumentListInfo *TemplateArgs, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2784 | bool IsAddressOfOperand, |
| 2785 | TypeSourceInfo **RecoveryTSI) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2786 | CXXScopeSpec SS; |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2787 | SS.Adopt(QualifierLoc); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2788 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2789 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2790 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2791 | TemplateArgs); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2792 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2793 | return getSema().BuildQualifiedDeclarationNameExpr( |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2794 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2797 | /// Build a new template-id expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2798 | /// |
| 2799 | /// By default, performs semantic analysis to build the new expression. |
| 2800 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2801 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2802 | SourceLocation TemplateKWLoc, |
| 2803 | LookupResult &R, |
| 2804 | bool RequiresADL, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2805 | const TemplateArgumentListInfo *TemplateArgs) { |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2806 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2807 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2810 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2811 | /// |
| 2812 | /// By default, performs semantic analysis to build the new expression. |
| 2813 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2814 | ExprResult RebuildCXXConstructExpr(QualType T, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2815 | SourceLocation Loc, |
| 2816 | CXXConstructorDecl *Constructor, |
| 2817 | bool IsElidable, |
| 2818 | MultiExprArg Args, |
| 2819 | bool HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2820 | bool ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2821 | bool StdInitListInitialization, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2822 | bool RequiresZeroInit, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2823 | CXXConstructExpr::ConstructionKind ConstructKind, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2824 | SourceRange ParenRange) { |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2825 | SmallVector<Expr*, 8> ConvertedArgs; |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2826 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
| Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2827 | ConvertedArgs)) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2828 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2829 | |
| Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 2830 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
| Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 2831 | IsElidable, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2832 | ConvertedArgs, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2833 | HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2834 | ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2835 | StdInitListInitialization, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2836 | RequiresZeroInit, ConstructKind, |
| 2837 | ParenRange); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2838 | } |
| 2839 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2840 | /// Build a new implicit construction via inherited constructor |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2841 | /// expression. |
| 2842 | ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 2843 | CXXConstructorDecl *Constructor, |
| 2844 | bool ConstructsVBase, |
| 2845 | bool InheritedFromVBase) { |
| 2846 | return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 2847 | Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 2848 | } |
| 2849 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2850 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2851 | /// |
| 2852 | /// By default, performs semantic analysis to build the new expression. |
| 2853 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2854 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2855 | SourceLocation LParenOrBraceLoc, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2856 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2857 | SourceLocation RParenOrBraceLoc, |
| 2858 | bool ListInitialization) { |
| 2859 | return getSema().BuildCXXTypeConstructExpr( |
| 2860 | TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2863 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2864 | /// |
| 2865 | /// By default, performs semantic analysis to build the new expression. |
| 2866 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2867 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2868 | SourceLocation LParenLoc, |
| 2869 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2870 | SourceLocation RParenLoc, |
| 2871 | bool ListInitialization) { |
| 2872 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, |
| 2873 | RParenLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2874 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2875 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2876 | /// Build a new member reference expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2877 | /// |
| 2878 | /// By default, performs semantic analysis to build the new expression. |
| 2879 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2880 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2881 | QualType BaseType, |
| 2882 | bool IsArrow, |
| 2883 | SourceLocation OperatorLoc, |
| 2884 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2885 | SourceLocation TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2886 | NamedDecl *FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2887 | const DeclarationNameInfo &MemberNameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2888 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2889 | CXXScopeSpec SS; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2890 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2891 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2892 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2893 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2894 | SS, TemplateKWLoc, |
| 2895 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2896 | MemberNameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2897 | TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2900 | /// Build a new member reference expression. |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2901 | /// |
| 2902 | /// By default, performs semantic analysis to build the new expression. |
| 2903 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2904 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2905 | SourceLocation OperatorLoc, |
| 2906 | bool IsArrow, |
| 2907 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2908 | SourceLocation TemplateKWLoc, |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2909 | NamedDecl *FirstQualifierInScope, |
| 2910 | LookupResult &R, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2911 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2912 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2913 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2914 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2915 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2916 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2917 | SS, TemplateKWLoc, |
| 2918 | FirstQualifierInScope, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2919 | R, TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2920 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2921 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2922 | /// Build a new noexcept expression. |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2923 | /// |
| 2924 | /// By default, performs semantic analysis to build the new expression. |
| 2925 | /// Subclasses may override this routine to provide different behavior. |
| 2926 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2927 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2928 | } |
| 2929 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2930 | /// Build a new expression to compute the length of a parameter pack. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2931 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 2932 | NamedDecl *Pack, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2933 | SourceLocation PackLoc, |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2934 | SourceLocation RParenLoc, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2935 | Optional<unsigned> Length, |
| 2936 | ArrayRef<TemplateArgument> PartialArgs) { |
| 2937 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 2938 | RParenLoc, Length, PartialArgs); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2939 | } |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2940 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2941 | /// Build a new Objective-C boxed expression. |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2942 | /// |
| 2943 | /// By default, performs semantic analysis to build the new expression. |
| 2944 | /// Subclasses may override this routine to provide different behavior. |
| 2945 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 2946 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 2947 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2948 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2949 | /// Build a new Objective-C array literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2950 | /// |
| 2951 | /// By default, performs semantic analysis to build the new expression. |
| 2952 | /// Subclasses may override this routine to provide different behavior. |
| 2953 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 2954 | Expr **Elements, unsigned NumElements) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2955 | return getSema().BuildObjCArrayLiteral(Range, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2956 | MultiExprArg(Elements, NumElements)); |
| 2957 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2958 | |
| 2959 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2960 | Expr *Base, Expr *Key, |
| 2961 | ObjCMethodDecl *getterMethod, |
| 2962 | ObjCMethodDecl *setterMethod) { |
| 2963 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 2964 | getterMethod, setterMethod); |
| 2965 | } |
| 2966 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2967 | /// Build a new Objective-C dictionary literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2968 | /// |
| 2969 | /// By default, performs semantic analysis to build the new expression. |
| 2970 | /// Subclasses may override this routine to provide different behavior. |
| 2971 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 2972 | MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 2973 | return getSema().BuildObjCDictionaryLiteral(Range, Elements); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2974 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2975 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2976 | /// Build a new Objective-C \@encode expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2977 | /// |
| 2978 | /// By default, performs semantic analysis to build the new expression. |
| 2979 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2980 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 2981 | TypeSourceInfo *EncodeTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2982 | SourceLocation RParenLoc) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2983 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2984 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2985 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2986 | /// Build a new Objective-C class message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2987 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2988 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2989 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2990 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2991 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2992 | MultiExprArg Args, |
| 2993 | SourceLocation RBracLoc) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2994 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 2995 | ReceiverTypeInfo->getType(), |
| 2996 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 2997 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2998 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3001 | /// Build a new Objective-C instance message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3002 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3003 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3004 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3005 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3006 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3007 | MultiExprArg Args, |
| 3008 | SourceLocation RBracLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3009 | return SemaRef.BuildInstanceMessage(Receiver, |
| 3010 | Receiver->getType(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3011 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3012 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3013 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3016 | /// Build a new Objective-C instance/class message to 'super'. |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3017 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 3018 | Selector Sel, |
| 3019 | ArrayRef<SourceLocation> SelectorLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3020 | QualType SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3021 | ObjCMethodDecl *Method, |
| 3022 | SourceLocation LBracLoc, |
| 3023 | MultiExprArg Args, |
| 3024 | SourceLocation RBracLoc) { |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3025 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3026 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3027 | SuperLoc, |
| 3028 | Sel, Method, LBracLoc, SelectorLocs, |
| 3029 | RBracLoc, Args) |
| 3030 | : SemaRef.BuildClassMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3031 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3032 | SuperLoc, |
| 3033 | Sel, Method, LBracLoc, SelectorLocs, |
| 3034 | RBracLoc, Args); |
| 3035 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3036 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3039 | /// Build a new Objective-C ivar reference expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3040 | /// |
| 3041 | /// By default, performs semantic analysis to build the new expression. |
| 3042 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3043 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3044 | SourceLocation IvarLoc, |
| 3045 | bool IsArrow, bool IsFreeIvar) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3046 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3047 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| Alex Lorenz | 776b417 | 2017-02-03 14:22:33 +0000 | [diff] [blame] | 3048 | ExprResult Result = getSema().BuildMemberReferenceExpr( |
| 3049 | BaseArg, BaseArg->getType(), |
| 3050 | /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), |
| 3051 | /*FirstQualifierInScope=*/nullptr, NameInfo, |
| 3052 | /*TemplateArgs=*/nullptr, |
| 3053 | /*S=*/nullptr); |
| 3054 | if (IsFreeIvar && Result.isUsable()) |
| 3055 | cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); |
| 3056 | return Result; |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3057 | } |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3058 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3059 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3060 | /// |
| 3061 | /// By default, performs semantic analysis to build the new expression. |
| 3062 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3063 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 3064 | ObjCPropertyDecl *Property, |
| 3065 | SourceLocation PropertyLoc) { |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3066 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3067 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 3068 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3069 | /*FIXME:*/PropertyLoc, |
| 3070 | /*IsArrow=*/false, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3071 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3072 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3073 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3074 | /*TemplateArgs=*/nullptr, |
| 3075 | /*S=*/nullptr); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3076 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3077 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3078 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3079 | /// |
| 3080 | /// By default, performs semantic analysis to build the new expression. |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 3081 | /// Subclasses may override this routine to provide different behavior. |
| 3082 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 3083 | ObjCMethodDecl *Getter, |
| 3084 | ObjCMethodDecl *Setter, |
| 3085 | SourceLocation PropertyLoc) { |
| 3086 | // Since these expressions can only be value-dependent, we do not |
| 3087 | // need to perform semantic analysis again. |
| 3088 | return Owned( |
| 3089 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 3090 | VK_LValue, OK_ObjCProperty, |
| 3091 | PropertyLoc, Base)); |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3094 | /// Build a new Objective-C "isa" expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3095 | /// |
| 3096 | /// By default, performs semantic analysis to build the new expression. |
| 3097 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3098 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3099 | SourceLocation OpLoc, bool IsArrow) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3100 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3101 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 3102 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 3103 | OpLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3104 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3105 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3106 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3107 | /*TemplateArgs=*/nullptr, |
| 3108 | /*S=*/nullptr); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3109 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3110 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3111 | /// Build a new shuffle vector expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3112 | /// |
| 3113 | /// By default, performs semantic analysis to build the new expression. |
| 3114 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3115 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 3116 | MultiExprArg SubExprs, |
| 3117 | SourceLocation RParenLoc) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3118 | // Find the declaration for __builtin_shufflevector |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3119 | const IdentifierInfo &Name |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3120 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 3121 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 3122 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3123 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3124 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3125 | // Build a reference to the __builtin_shufflevector builtin |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3126 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
| Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 3127 | Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false, |
| 3128 | SemaRef.Context.BuiltinFnTy, |
| 3129 | VK_RValue, BuiltinLoc); |
| 3130 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 3131 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3132 | CK_BuiltinFnToFnPtr).get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3133 | |
| 3134 | // Build the CallExpr |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3135 | ExprResult TheCall = new (SemaRef.Context) CallExpr( |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3136 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3137 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3138 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3139 | // Type-check the __builtin_shufflevector expression. |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3140 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3141 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3142 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3143 | /// Build a new convert vector expression. |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 3144 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 3145 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 3146 | SourceLocation RParenLoc) { |
| 3147 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 3148 | BuiltinLoc, RParenLoc); |
| 3149 | } |
| 3150 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3151 | /// Build a new template argument pack expansion. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3152 | /// |
| 3153 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3154 | /// for a template argument. Subclasses may override this routine to provide |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3155 | /// different behavior. |
| 3156 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3157 | SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3158 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3159 | switch (Pattern.getArgument().getKind()) { |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3160 | case TemplateArgument::Expression: { |
| 3161 | ExprResult Result |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3162 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 3163 | EllipsisLoc, NumExpansions); |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3164 | if (Result.isInvalid()) |
| 3165 | return TemplateArgumentLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3166 | |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3167 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 3168 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3169 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3170 | case TemplateArgument::Template: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3171 | return TemplateArgumentLoc(TemplateArgument( |
| 3172 | Pattern.getArgument().getAsTemplate(), |
| Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3173 | NumExpansions), |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3174 | Pattern.getTemplateQualifierLoc(), |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3175 | Pattern.getTemplateNameLoc(), |
| 3176 | EllipsisLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3177 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3178 | case TemplateArgument::Null: |
| 3179 | case TemplateArgument::Integral: |
| 3180 | case TemplateArgument::Declaration: |
| 3181 | case TemplateArgument::Pack: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3182 | case TemplateArgument::TemplateExpansion: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3183 | case TemplateArgument::NullPtr: |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3184 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3185 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3186 | case TemplateArgument::Type: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3187 | if (TypeSourceInfo *Expansion |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3188 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3189 | EllipsisLoc, |
| 3190 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3191 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 3192 | Expansion); |
| 3193 | break; |
| 3194 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3195 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3196 | return TemplateArgumentLoc(); |
| 3197 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3198 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3199 | /// Build a new expression pack expansion. |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3200 | /// |
| 3201 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3202 | /// for an expression. Subclasses may override this routine to provide |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3203 | /// different behavior. |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3204 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3205 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3206 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3207 | } |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3208 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3209 | /// Build a new C++1z fold-expression. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3210 | /// |
| 3211 | /// By default, performs semantic analysis in order to build a new fold |
| 3212 | /// expression. |
| 3213 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 3214 | BinaryOperatorKind Operator, |
| 3215 | SourceLocation EllipsisLoc, Expr *RHS, |
| 3216 | SourceLocation RParenLoc) { |
| 3217 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| 3218 | RHS, RParenLoc); |
| 3219 | } |
| 3220 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3221 | /// Build an empty C++1z fold-expression with the given operator. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3222 | /// |
| 3223 | /// By default, produces the fallback value for the fold-expression, or |
| 3224 | /// produce an error if there is no fallback value. |
| 3225 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 3226 | BinaryOperatorKind Operator) { |
| 3227 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 3228 | } |
| 3229 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3230 | /// Build a new atomic operation expression. |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3231 | /// |
| 3232 | /// By default, performs semantic analysis to build the new expression. |
| 3233 | /// Subclasses may override this routine to provide different behavior. |
| 3234 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 3235 | MultiExprArg SubExprs, |
| 3236 | QualType RetTy, |
| 3237 | AtomicExpr::AtomicOp Op, |
| 3238 | SourceLocation RParenLoc) { |
| 3239 | // Just create the expression; there is not any interesting semantic |
| 3240 | // analysis here because we can't actually build an AtomicExpr until |
| 3241 | // we are sure it is semantically sound. |
| Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 3242 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3243 | RParenLoc); |
| 3244 | } |
| 3245 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3246 | private: |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3247 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 3248 | QualType ObjectType, |
| 3249 | NamedDecl *FirstQualifierInScope, |
| 3250 | CXXScopeSpec &SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3251 | |
| 3252 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3253 | QualType ObjectType, |
| 3254 | NamedDecl *FirstQualifierInScope, |
| 3255 | CXXScopeSpec &SS); |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3256 | |
| 3257 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 3258 | NamedDecl *FirstQualifierInScope, |
| 3259 | CXXScopeSpec &SS); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 3260 | |
| 3261 | QualType TransformDependentNameType(TypeLocBuilder &TLB, |
| 3262 | DependentNameTypeLoc TL, |
| 3263 | bool DeducibleTSTContext); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3264 | }; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3265 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3266 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3267 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3268 | if (!S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3269 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3270 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3271 | switch (S->getStmtClass()) { |
| 3272 | case Stmt::NoStmtClass: break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3274 | // Transform individual statement nodes |
| 3275 | #define STMT(Node, Parent) \ |
| 3276 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3277 | #define ABSTRACT_STMT(Node) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3278 | #define EXPR(Node, Parent) |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3279 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3280 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3281 | // Transform expressions by calling TransformExpr. |
| 3282 | #define STMT(Node, Parent) |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3283 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3284 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3285 | #include "clang/AST/StmtNodes.inc" |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3286 | { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3287 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3288 | if (E.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 3289 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | |
| Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 3291 | return getSema().ActOnExprStmt(E); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3292 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3295 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3296 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3298 | template<typename Derived> |
| 3299 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 3300 | if (!S) |
| 3301 | return S; |
| 3302 | |
| 3303 | switch (S->getClauseKind()) { |
| 3304 | default: break; |
| 3305 | // Transform individual clause nodes |
| 3306 | #define OPENMP_CLAUSE(Name, Class) \ |
| 3307 | case OMPC_ ## Name : \ |
| 3308 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 3309 | #include "clang/Basic/OpenMPKinds.def" |
| 3310 | } |
| 3311 | |
| 3312 | return S; |
| 3313 | } |
| 3314 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3316 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3317 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3318 | if (!E) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3319 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3320 | |
| 3321 | switch (E->getStmtClass()) { |
| 3322 | case Stmt::NoStmtClass: break; |
| 3323 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3324 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3325 | #define EXPR(Node, Parent) \ |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3326 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3327 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3330 | return E; |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | template<typename Derived> |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3334 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3335 | bool NotCopyInit) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3336 | // Initializers are instantiated like expressions, except that various outer |
| 3337 | // layers are stripped. |
| 3338 | if (!Init) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3339 | return Init; |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3340 | |
| 3341 | if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init)) |
| 3342 | Init = ExprTemp->getSubExpr(); |
| 3343 | |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 3344 | if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) |
| 3345 | Init = AIL->getCommonExpr(); |
| 3346 | |
| Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 3347 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3348 | Init = MTE->GetTemporaryExpr(); |
| 3349 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3350 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3351 | Init = Binder->getSubExpr(); |
| 3352 | |
| 3353 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3354 | Init = ICE->getSubExprAsWritten(); |
| 3355 | |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3356 | if (CXXStdInitializerListExpr *ILE = |
| 3357 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3358 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3359 | |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3360 | // If this is copy-initialization, we only need to reconstruct |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3361 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3362 | // the initializer is already the right type. |
| 3363 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3364 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3365 | return getDerived().TransformExpr(Init); |
| 3366 | |
| 3367 | // Revert value-initialization back to empty parens. |
| 3368 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3369 | SourceRange Parens = VIE->getSourceRange(); |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3370 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3371 | Parens.getEnd()); |
| 3372 | } |
| 3373 | |
| 3374 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3375 | if (isa<ImplicitValueInitExpr>(Init)) |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3376 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3377 | SourceLocation()); |
| 3378 | |
| 3379 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3380 | // of expressions. Any other form of initializer can just be reused directly. |
| 3381 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3382 | return getDerived().TransformExpr(Init); |
| 3383 | |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3384 | // If the initialization implicitly converted an initializer list to a |
| 3385 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3386 | if (Construct && Construct->isStdInitListInitialization()) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3387 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3388 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3389 | SmallVector<Expr*, 8> NewArgs; |
| 3390 | bool ArgChanged = false; |
| 3391 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3392 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3393 | return ExprError(); |
| 3394 | |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 3395 | // If this was list initialization, revert to syntactic list form. |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3396 | if (Construct->isListInitialization()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3397 | return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3398 | Construct->getEndLoc()); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3399 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3400 | // Build a ParenListExpr to represent anything else. |
| Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3401 | SourceRange Parens = Construct->getParenOrBraceRange(); |
| Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3402 | if (Parens.isInvalid()) { |
| 3403 | // This was a variable declaration's initialization for which no initializer |
| 3404 | // was specified. |
| 3405 | assert(NewArgs.empty() && |
| 3406 | "no parens or braces but have direct init with arguments?"); |
| 3407 | return ExprEmpty(); |
| 3408 | } |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3409 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3410 | Parens.getEnd()); |
| 3411 | } |
| 3412 | |
| 3413 | template<typename Derived> |
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 3414 | bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3415 | unsigned NumInputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3416 | bool IsCall, |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3417 | SmallVectorImpl<Expr *> &Outputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3418 | bool *ArgChanged) { |
| 3419 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3420 | // If requested, drop call arguments that need to be dropped. |
| 3421 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3422 | if (ArgChanged) |
| 3423 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3424 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3425 | break; |
| 3426 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3427 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3428 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3429 | Expr *Pattern = Expansion->getPattern(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3430 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3431 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3432 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3433 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3434 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3435 | // Determine whether the set of unexpanded parameter packs can and should |
| 3436 | // be expanded. |
| 3437 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3438 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3439 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3440 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3441 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3442 | Pattern->getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3443 | Unexpanded, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3444 | Expand, RetainExpansion, |
| 3445 | NumExpansions)) |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3446 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3447 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3448 | if (!Expand) { |
| 3449 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3450 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3451 | // expansion. |
| 3452 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3453 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3454 | if (OutPattern.isInvalid()) |
| 3455 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3456 | |
| 3457 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3458 | Expansion->getEllipsisLoc(), |
| 3459 | NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3460 | if (Out.isInvalid()) |
| 3461 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3462 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3463 | if (ArgChanged) |
| 3464 | *ArgChanged = true; |
| 3465 | Outputs.push_back(Out.get()); |
| 3466 | continue; |
| 3467 | } |
| John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3468 | |
| 3469 | // Record right away that the argument was changed. This needs |
| 3470 | // to happen even if the array expands to nothing. |
| 3471 | if (ArgChanged) *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3472 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3473 | // The transform has determined that we should perform an elementwise |
| 3474 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3475 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3476 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3477 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3478 | if (Out.isInvalid()) |
| 3479 | return true; |
| 3480 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3481 | if (Out.get()->containsUnexpandedParameterPack()) { |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3482 | Out = getDerived().RebuildPackExpansion( |
| 3483 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3484 | if (Out.isInvalid()) |
| 3485 | return true; |
| 3486 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3487 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3488 | Outputs.push_back(Out.get()); |
| 3489 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3490 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3491 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3492 | // forgetting the partially-substituted parameter pack. |
| 3493 | if (RetainExpansion) { |
| 3494 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3495 | |
| 3496 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3497 | if (Out.isInvalid()) |
| 3498 | return true; |
| 3499 | |
| 3500 | Out = getDerived().RebuildPackExpansion( |
| 3501 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3502 | if (Out.isInvalid()) |
| 3503 | return true; |
| 3504 | |
| 3505 | Outputs.push_back(Out.get()); |
| 3506 | } |
| 3507 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3508 | continue; |
| 3509 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3510 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3511 | ExprResult Result = |
| 3512 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3513 | : getDerived().TransformExpr(Inputs[I]); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3514 | if (Result.isInvalid()) |
| 3515 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3516 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3517 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3518 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3519 | |
| 3520 | Outputs.push_back(Result.get()); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3521 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3522 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3523 | return false; |
| 3524 | } |
| 3525 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 3526 | template <typename Derived> |
| 3527 | Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 3528 | SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 3529 | if (Var) { |
| 3530 | VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 3531 | getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 3532 | |
| 3533 | if (!ConditionVar) |
| 3534 | return Sema::ConditionError(); |
| 3535 | |
| 3536 | return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 3537 | } |
| 3538 | |
| 3539 | if (Expr) { |
| 3540 | ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 3541 | |
| 3542 | if (CondExpr.isInvalid()) |
| 3543 | return Sema::ConditionError(); |
| 3544 | |
| 3545 | return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); |
| 3546 | } |
| 3547 | |
| 3548 | return Sema::ConditionResult(); |
| 3549 | } |
| 3550 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3551 | template<typename Derived> |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3552 | NestedNameSpecifierLoc |
| 3553 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3554 | NestedNameSpecifierLoc NNS, |
| 3555 | QualType ObjectType, |
| 3556 | NamedDecl *FirstQualifierInScope) { |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3557 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3558 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3559 | Qualifier = Qualifier.getPrefix()) |
| 3560 | Qualifiers.push_back(Qualifier); |
| 3561 | |
| 3562 | CXXScopeSpec SS; |
| 3563 | while (!Qualifiers.empty()) { |
| 3564 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3565 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3566 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3567 | switch (QNNS->getKind()) { |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3568 | case NestedNameSpecifier::Identifier: { |
| 3569 | Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), |
| 3570 | Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType); |
| 3571 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, |
| 3572 | SS, FirstQualifierInScope, false)) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3573 | return NestedNameSpecifierLoc(); |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3574 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3575 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3576 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3577 | case NestedNameSpecifier::Namespace: { |
| 3578 | NamespaceDecl *NS |
| 3579 | = cast_or_null<NamespaceDecl>( |
| 3580 | getDerived().TransformDecl( |
| 3581 | Q.getLocalBeginLoc(), |
| 3582 | QNNS->getAsNamespace())); |
| 3583 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3584 | break; |
| 3585 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3586 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3587 | case NestedNameSpecifier::NamespaceAlias: { |
| 3588 | NamespaceAliasDecl *Alias |
| 3589 | = cast_or_null<NamespaceAliasDecl>( |
| 3590 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3591 | QNNS->getAsNamespaceAlias())); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3592 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3593 | Q.getLocalEndLoc()); |
| 3594 | break; |
| 3595 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3596 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3597 | case NestedNameSpecifier::Global: |
| 3598 | // There is no meaningful transformation that one could perform on the |
| 3599 | // global scope. |
| 3600 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3601 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3602 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3603 | case NestedNameSpecifier::Super: { |
| 3604 | CXXRecordDecl *RD = |
| 3605 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3606 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3607 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3608 | break; |
| 3609 | } |
| 3610 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3611 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3612 | case NestedNameSpecifier::TypeSpec: { |
| 3613 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3614 | FirstQualifierInScope, SS); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3615 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3616 | if (!TL) |
| 3617 | return NestedNameSpecifierLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3618 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3619 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3620 | (SemaRef.getLangOpts().CPlusPlus11 && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3621 | TL.getType()->isEnumeralType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3622 | assert(!TL.getType().hasLocalQualifiers() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3623 | "Can't get cv-qualifiers here"); |
| Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3624 | if (TL.getType()->isEnumeralType()) |
| 3625 | SemaRef.Diag(TL.getBeginLoc(), |
| 3626 | diag::warn_cxx98_compat_enum_nested_name_spec); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3627 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3628 | Q.getLocalEndLoc()); |
| 3629 | break; |
| 3630 | } |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3631 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3632 | // error because a previous error should have already been emitted. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3633 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3634 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3635 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3636 | << TL.getType() << SS.getRange(); |
| 3637 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3638 | return NestedNameSpecifierLoc(); |
| 3639 | } |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3640 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3641 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3642 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3643 | FirstQualifierInScope = nullptr; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3644 | ObjectType = QualType(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3645 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3646 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3647 | // Don't rebuild the nested-name-specifier if we don't have to. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3648 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3649 | !getDerived().AlwaysRebuild()) |
| 3650 | return NNS; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3651 | |
| 3652 | // If we can re-use the source-location data from the original |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3653 | // nested-name-specifier, do so. |
| 3654 | if (SS.location_size() == NNS.getDataLength() && |
| 3655 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3656 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3657 | |
| 3658 | // Allocate new nested-name-specifier location information. |
| 3659 | return SS.getWithLocInContext(SemaRef.Context); |
| 3660 | } |
| 3661 | |
| 3662 | template<typename Derived> |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3663 | DeclarationNameInfo |
| 3664 | TreeTransform<Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3665 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3666 | DeclarationName Name = NameInfo.getName(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3667 | if (!Name) |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3668 | return DeclarationNameInfo(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3669 | |
| 3670 | switch (Name.getNameKind()) { |
| 3671 | case DeclarationName::Identifier: |
| 3672 | case DeclarationName::ObjCZeroArgSelector: |
| 3673 | case DeclarationName::ObjCOneArgSelector: |
| 3674 | case DeclarationName::ObjCMultiArgSelector: |
| 3675 | case DeclarationName::CXXOperatorName: |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3676 | case DeclarationName::CXXLiteralOperatorName: |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3677 | case DeclarationName::CXXUsingDirective: |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3678 | return NameInfo; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3679 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3680 | case DeclarationName::CXXDeductionGuideName: { |
| 3681 | TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); |
| 3682 | TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( |
| 3683 | getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); |
| 3684 | if (!NewTemplate) |
| 3685 | return DeclarationNameInfo(); |
| 3686 | |
| 3687 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3688 | NewNameInfo.setName( |
| 3689 | SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); |
| 3690 | return NewNameInfo; |
| 3691 | } |
| 3692 | |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3693 | case DeclarationName::CXXConstructorName: |
| 3694 | case DeclarationName::CXXDestructorName: |
| 3695 | case DeclarationName::CXXConversionFunctionName: { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3696 | TypeSourceInfo *NewTInfo; |
| 3697 | CanQualType NewCanTy; |
| 3698 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3699 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3700 | if (!NewTInfo) |
| 3701 | return DeclarationNameInfo(); |
| 3702 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3703 | } |
| 3704 | else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3705 | NewTInfo = nullptr; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3706 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3707 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3708 | if (NewT.isNull()) |
| 3709 | return DeclarationNameInfo(); |
| 3710 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3711 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3712 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3713 | DeclarationName NewName |
| 3714 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3715 | NewCanTy); |
| 3716 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3717 | NewNameInfo.setName(NewName); |
| 3718 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3719 | return NewNameInfo; |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3720 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3723 | llvm_unreachable("Unknown name kind."); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3728 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3729 | TemplateName Name, |
| 3730 | SourceLocation NameLoc, |
| 3731 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3732 | NamedDecl *FirstQualifierInScope, |
| 3733 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3734 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3735 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3736 | assert(Template && "qualified template name must refer to a template"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3737 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3738 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3739 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3740 | Template)); |
| 3741 | if (!TransTemplate) |
| 3742 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3743 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3744 | if (!getDerived().AlwaysRebuild() && |
| 3745 | SS.getScopeRep() == QTN->getQualifier() && |
| 3746 | TransTemplate == Template) |
| 3747 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3748 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3749 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3750 | TransTemplate); |
| 3751 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3752 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3753 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3754 | if (SS.getScopeRep()) { |
| 3755 | // These apply to the scope specifier, not the template. |
| 3756 | ObjectType = QualType(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3757 | FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3760 | if (!getDerived().AlwaysRebuild() && |
| 3761 | SS.getScopeRep() == DTN->getQualifier() && |
| 3762 | ObjectType.isNull()) |
| 3763 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3764 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3765 | // FIXME: Preserve the location of the "template" keyword. |
| 3766 | SourceLocation TemplateKWLoc = NameLoc; |
| 3767 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3768 | if (DTN->isIdentifier()) { |
| 3769 | return getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3770 | TemplateKWLoc, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3771 | *DTN->getIdentifier(), |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3772 | NameLoc, |
| 3773 | ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3774 | FirstQualifierInScope, |
| 3775 | AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3776 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3777 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3778 | return getDerived().RebuildTemplateName(SS, TemplateKWLoc, |
| 3779 | DTN->getOperator(), NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3780 | ObjectType, AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3781 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3782 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3783 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3784 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3785 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3786 | Template)); |
| 3787 | if (!TransTemplate) |
| 3788 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3789 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3790 | if (!getDerived().AlwaysRebuild() && |
| 3791 | TransTemplate == Template) |
| 3792 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3793 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3794 | return TemplateName(TransTemplate); |
| 3795 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3796 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3797 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3798 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3799 | TemplateTemplateParmDecl *TransParam |
| 3800 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3801 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3802 | if (!TransParam) |
| 3803 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3804 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3805 | if (!getDerived().AlwaysRebuild() && |
| 3806 | TransParam == SubstPack->getParameterPack()) |
| 3807 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3808 | |
| 3809 | return getDerived().RebuildTemplateName(TransParam, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3810 | SubstPack->getArgumentPack()); |
| 3811 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3812 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3813 | // These should be getting filtered out before they reach the AST. |
| 3814 | llvm_unreachable("overloaded function decl survived to here"); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3818 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3819 | const TemplateArgument &Arg, |
| 3820 | TemplateArgumentLoc &Output) { |
| 3821 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3822 | switch (Arg.getKind()) { |
| 3823 | case TemplateArgument::Null: |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3824 | llvm_unreachable("null template argument in TreeTransform"); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3825 | break; |
| 3826 | |
| 3827 | case TemplateArgument::Type: |
| 3828 | Output = TemplateArgumentLoc(Arg, |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3829 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3830 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3831 | break; |
| 3832 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3833 | case TemplateArgument::Template: |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3834 | case TemplateArgument::TemplateExpansion: { |
| 3835 | NestedNameSpecifierLocBuilder Builder; |
| Manuel Klimek | 4c67fa7 | 2016-01-11 11:39:00 +0000 | [diff] [blame] | 3836 | TemplateName Template = Arg.getAsTemplateOrTemplatePattern(); |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3837 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3838 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3839 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3840 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3841 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3842 | if (Arg.getKind() == TemplateArgument::Template) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3843 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3844 | Builder.getWithLocInContext(SemaRef.Context), |
| 3845 | Loc); |
| 3846 | else |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3847 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3848 | Builder.getWithLocInContext(SemaRef.Context), |
| 3849 | Loc, Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3850 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3851 | break; |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3852 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3853 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3854 | case TemplateArgument::Expression: |
| 3855 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3856 | break; |
| 3857 | |
| 3858 | case TemplateArgument::Declaration: |
| 3859 | case TemplateArgument::Integral: |
| 3860 | case TemplateArgument::Pack: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3861 | case TemplateArgument::NullPtr: |
| John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3862 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3863 | break; |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | template<typename Derived> |
| 3868 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3869 | const TemplateArgumentLoc &Input, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3870 | TemplateArgumentLoc &Output, bool Uneval) { |
| Nicolas Lesser | b6d5c58 | 2018-07-12 18:45:41 +0000 | [diff] [blame] | 3871 | EnterExpressionEvaluationContext EEEC( |
| 3872 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 3873 | /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ |
| 3874 | Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3875 | const TemplateArgument &Arg = Input.getArgument(); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3876 | switch (Arg.getKind()) { |
| 3877 | case TemplateArgument::Null: |
| 3878 | case TemplateArgument::Integral: |
| Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3879 | case TemplateArgument::Pack: |
| 3880 | case TemplateArgument::Declaration: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3881 | case TemplateArgument::NullPtr: |
| 3882 | llvm_unreachable("Unexpected TemplateArgument"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3883 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3884 | case TemplateArgument::Type: { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3885 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3886 | if (!DI) |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3887 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3888 | |
| 3889 | DI = getDerived().TransformType(DI); |
| 3890 | if (!DI) return true; |
| 3891 | |
| 3892 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3893 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3894 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3895 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3896 | case TemplateArgument::Template: { |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3897 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3898 | if (QualifierLoc) { |
| 3899 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3900 | if (!QualifierLoc) |
| 3901 | return true; |
| 3902 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3903 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3904 | CXXScopeSpec SS; |
| 3905 | SS.Adopt(QualifierLoc); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3906 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3907 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3908 | Input.getTemplateNameLoc()); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3909 | if (Template.isNull()) |
| 3910 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3911 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3912 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3913 | Input.getTemplateNameLoc()); |
| 3914 | return false; |
| 3915 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3916 | |
| 3917 | case TemplateArgument::TemplateExpansion: |
| 3918 | llvm_unreachable("Caller should expand pack expansions"); |
| 3919 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3920 | case TemplateArgument::Expression: { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3921 | // Template argument expressions are constant expressions. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3922 | EnterExpressionEvaluationContext Unevaluated( |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 3923 | getSema(), Uneval |
| 3924 | ? Sema::ExpressionEvaluationContext::Unevaluated |
| 3925 | : Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3926 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3927 | Expr *InputExpr = Input.getSourceExpression(); |
| 3928 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 3929 | |
| Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 3930 | ExprResult E = getDerived().TransformExpr(InputExpr); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 3931 | E = SemaRef.ActOnConstantExpression(E); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3932 | if (E.isInvalid()) return true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3933 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3934 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3935 | } |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3936 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3938 | // Work around bogus GCC warning |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3939 | return true; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3942 | /// Iterator adaptor that invents template argument location information |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3943 | /// for each of the template arguments in its underlying iterator. |
| 3944 | template<typename Derived, typename InputIterator> |
| 3945 | class TemplateArgumentLocInventIterator { |
| 3946 | TreeTransform<Derived> &Self; |
| 3947 | InputIterator Iter; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3948 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3949 | public: |
| 3950 | typedef TemplateArgumentLoc value_type; |
| 3951 | typedef TemplateArgumentLoc reference; |
| 3952 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 3953 | difference_type; |
| 3954 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3955 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3956 | class pointer { |
| 3957 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3958 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3959 | public: |
| 3960 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3961 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3962 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 3963 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3964 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 3965 | TemplateArgumentLocInventIterator() { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3966 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3967 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 3968 | InputIterator Iter) |
| 3969 | : Self(Self), Iter(Iter) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3970 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3971 | TemplateArgumentLocInventIterator &operator++() { |
| 3972 | ++Iter; |
| 3973 | return *this; |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3974 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3975 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3976 | TemplateArgumentLocInventIterator operator++(int) { |
| 3977 | TemplateArgumentLocInventIterator Old(*this); |
| 3978 | ++(*this); |
| 3979 | return Old; |
| 3980 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3981 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3982 | reference operator*() const { |
| 3983 | TemplateArgumentLoc Result; |
| 3984 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 3985 | return Result; |
| 3986 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3987 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3988 | pointer operator->() const { return pointer(**this); } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3989 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3990 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 3991 | const TemplateArgumentLocInventIterator &Y) { |
| 3992 | return X.Iter == Y.Iter; |
| 3993 | } |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 3994 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 3995 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 3996 | const TemplateArgumentLocInventIterator &Y) { |
| 3997 | return X.Iter != Y.Iter; |
| 3998 | } |
| 3999 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4000 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4001 | template<typename Derived> |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4002 | template<typename InputIterator> |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4003 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 4004 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 4005 | bool Uneval) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4006 | for (; First != Last; ++First) { |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4007 | TemplateArgumentLoc Out; |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4008 | TemplateArgumentLoc In = *First; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4009 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4010 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 4011 | // Unpack argument packs, which we translate them into separate |
| 4012 | // arguments. |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4013 | // FIXME: We could do much better if we could guarantee that the |
| 4014 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 4015 | // all of the template arguments in the argument pack. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4016 | typedef TemplateArgumentLocInventIterator<Derived, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4017 | TemplateArgument::pack_iterator> |
| 4018 | PackLocIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4019 | if (TransformTemplateArguments(PackLocIterator(*this, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4020 | In.getArgument().pack_begin()), |
| 4021 | PackLocIterator(*this, |
| 4022 | In.getArgument().pack_end()), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4023 | Outputs, Uneval)) |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4024 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4025 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4026 | continue; |
| 4027 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4028 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4029 | if (In.getArgument().isPackExpansion()) { |
| 4030 | // We have a pack expansion, for which we will be substituting into |
| 4031 | // the pattern. |
| 4032 | SourceLocation Ellipsis; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4033 | Optional<unsigned> OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4034 | TemplateArgumentLoc Pattern |
| Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 4035 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 4036 | In, Ellipsis, OrigNumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4037 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4038 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4039 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4040 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4041 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4042 | // Determine whether the set of unexpanded parameter packs can and should |
| 4043 | // be expanded. |
| 4044 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4045 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4046 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4047 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 4048 | Pattern.getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4049 | Unexpanded, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4050 | Expand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4051 | RetainExpansion, |
| 4052 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4053 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4054 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4055 | if (!Expand) { |
| 4056 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4057 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4058 | // expansion. |
| 4059 | TemplateArgumentLoc OutPattern; |
| 4060 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4061 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4062 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4063 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4064 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 4065 | NumExpansions); |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4066 | if (Out.getArgument().isNull()) |
| 4067 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4068 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4069 | Outputs.addArgument(Out); |
| 4070 | continue; |
| 4071 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4072 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4073 | // The transform has determined that we should perform an elementwise |
| 4074 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4075 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4076 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4077 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4078 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4079 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4080 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4081 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4082 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4083 | OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4084 | if (Out.getArgument().isNull()) |
| 4085 | return true; |
| 4086 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4087 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4088 | Outputs.addArgument(Out); |
| 4089 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4090 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4091 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4092 | // forgetting the partially-substituted parameter pack. |
| 4093 | if (RetainExpansion) { |
| 4094 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4095 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4096 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4097 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4098 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4099 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4100 | OrigNumExpansions); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4101 | if (Out.getArgument().isNull()) |
| 4102 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4103 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4104 | Outputs.addArgument(Out); |
| 4105 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4106 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4107 | continue; |
| 4108 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4109 | |
| 4110 | // The simple case: |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4111 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4112 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4113 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4114 | Outputs.addArgument(Out); |
| 4115 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4116 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4117 | return false; |
| 4118 | |
| 4119 | } |
| 4120 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4121 | //===----------------------------------------------------------------------===// |
| 4122 | // Type transformation |
| 4123 | //===----------------------------------------------------------------------===// |
| 4124 | |
| 4125 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4126 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4127 | if (getDerived().AlreadyTransformed(T)) |
| 4128 | return T; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4129 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4130 | // Temporary workaround. All of these transformations should |
| 4131 | // eventually turn into transformations on TypeLocs. |
| Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 4132 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4133 | getDerived().getBaseLocation()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4134 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4135 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4136 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4137 | if (!NewDI) |
| 4138 | return QualType(); |
| 4139 | |
| 4140 | return NewDI->getType(); |
| 4141 | } |
| 4142 | |
| 4143 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4144 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4145 | // Refine the base location to the type's location. |
| 4146 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4147 | getDerived().getBaseEntity()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4148 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4149 | return DI; |
| 4150 | |
| 4151 | TypeLocBuilder TLB; |
| 4152 | |
| 4153 | TypeLoc TL = DI->getTypeLoc(); |
| 4154 | TLB.reserve(TL.getFullDataSize()); |
| 4155 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4156 | QualType Result = getDerived().TransformType(TLB, TL); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4157 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4158 | return nullptr; |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4159 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4160 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | template<typename Derived> |
| 4164 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4165 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4166 | switch (T.getTypeLocClass()) { |
| 4167 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4168 | #define TYPELOC(CLASS, PARENT) \ |
| 4169 | case TypeLoc::CLASS: \ |
| 4170 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 4171 | T.castAs<CLASS##TypeLoc>()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4172 | #include "clang/AST/TypeLocNodes.def" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4173 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4174 | |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4175 | llvm_unreachable("unhandled type loc!"); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4176 | } |
| 4177 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4178 | template<typename Derived> |
| 4179 | QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { |
| 4180 | if (!isa<DependentNameType>(T)) |
| 4181 | return TransformType(T); |
| 4182 | |
| 4183 | if (getDerived().AlreadyTransformed(T)) |
| 4184 | return T; |
| 4185 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4186 | getDerived().getBaseLocation()); |
| 4187 | TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); |
| 4188 | return NewDI ? NewDI->getType() : QualType(); |
| 4189 | } |
| 4190 | |
| 4191 | template<typename Derived> |
| 4192 | TypeSourceInfo * |
| 4193 | TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { |
| 4194 | if (!isa<DependentNameType>(DI->getType())) |
| 4195 | return TransformType(DI); |
| 4196 | |
| 4197 | // Refine the base location to the type's location. |
| 4198 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4199 | getDerived().getBaseEntity()); |
| 4200 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4201 | return DI; |
| 4202 | |
| 4203 | TypeLocBuilder TLB; |
| 4204 | |
| 4205 | TypeLoc TL = DI->getTypeLoc(); |
| 4206 | TLB.reserve(TL.getFullDataSize()); |
| 4207 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4208 | auto QTL = TL.getAs<QualifiedTypeLoc>(); |
| 4209 | if (QTL) |
| 4210 | TL = QTL.getUnqualifiedLoc(); |
| 4211 | |
| 4212 | auto DNTL = TL.castAs<DependentNameTypeLoc>(); |
| 4213 | |
| 4214 | QualType Result = getDerived().TransformDependentNameType( |
| 4215 | TLB, DNTL, /*DeducedTSTContext*/true); |
| 4216 | if (Result.isNull()) |
| 4217 | return nullptr; |
| 4218 | |
| 4219 | if (QTL) { |
| 4220 | Result = getDerived().RebuildQualifiedType( |
| 4221 | Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers()); |
| 4222 | TLB.TypeWasModifiedSafely(Result); |
| 4223 | } |
| 4224 | |
| 4225 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4226 | } |
| 4227 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4228 | template<typename Derived> |
| 4229 | QualType |
| 4230 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4231 | QualifiedTypeLoc T) { |
| Douglas Gregor | 1b8fe5b7 | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 4232 | Qualifiers Quals = T.getType().getLocalQualifiers(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4233 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4234 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4235 | if (Result.isNull()) |
| 4236 | return QualType(); |
| 4237 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4238 | Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals); |
| 4239 | |
| 4240 | // RebuildQualifiedType might have updated the type, but not in a way |
| 4241 | // that invalidates the TypeLoc. (There's no location information for |
| 4242 | // qualifiers.) |
| 4243 | TLB.TypeWasModifiedSafely(Result); |
| 4244 | |
| 4245 | return Result; |
| 4246 | } |
| 4247 | |
| 4248 | template<typename Derived> |
| 4249 | QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, |
| 4250 | SourceLocation Loc, |
| 4251 | Qualifiers Quals) { |
| 4252 | // C++ [dcl.fct]p7: |
| 4253 | // [When] adding cv-qualifications on top of the function type [...] the |
| 4254 | // cv-qualifiers are ignored. |
| 4255 | // C++ [dcl.ref]p1: |
| 4256 | // when the cv-qualifiers are introduced through the use of a typedef-name |
| 4257 | // or decltype-specifier [...] the cv-qualifiers are ignored. |
| 4258 | // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be |
| 4259 | // applied to a reference type. |
| 4260 | // FIXME: This removes all qualifiers, not just cv-qualifiers! |
| 4261 | if (T->isFunctionType() || T->isReferenceType()) |
| 4262 | return T; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4263 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4264 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4265 | // resulting type. |
| 4266 | if (Quals.hasObjCLifetime()) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4267 | if (!T->isObjCLifetimeType() && !T->isDependentType()) |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4268 | Quals.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4269 | else if (T.getObjCLifetime()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4270 | // Objective-C ARC: |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4271 | // A lifetime qualifier applied to a substituted template parameter |
| 4272 | // overrides the lifetime qualifier from the template argument. |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4273 | const AutoType *AutoTy; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4274 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4275 | = dyn_cast<SubstTemplateTypeParmType>(T)) { |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4276 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 4277 | Qualifiers Qs = Replacement.getQualifiers(); |
| 4278 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4279 | Replacement = SemaRef.Context.getQualifiedType( |
| 4280 | Replacement.getUnqualifiedType(), Qs); |
| 4281 | T = SemaRef.Context.getSubstTemplateTypeParmType( |
| 4282 | SubstTypeParam->getReplacedParameter(), Replacement); |
| 4283 | } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4284 | // 'auto' types behave the same way as template parameters. |
| 4285 | QualType Deduced = AutoTy->getDeducedType(); |
| 4286 | Qualifiers Qs = Deduced.getQualifiers(); |
| 4287 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4288 | Deduced = |
| 4289 | SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); |
| 4290 | T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
| 4291 | AutoTy->isDependentType()); |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4292 | } else { |
| Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4293 | // Otherwise, complain about the addition of a qualifier to an |
| 4294 | // already-qualified type. |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4295 | // FIXME: Why is this check not in Sema::BuildQualifiedType? |
| 4296 | SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4297 | Quals.removeObjCLifetime(); |
| 4298 | } |
| 4299 | } |
| 4300 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4301 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4302 | return SemaRef.BuildQualifiedType(T, Loc, Quals); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4305 | template<typename Derived> |
| 4306 | TypeLoc |
| 4307 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 4308 | QualType ObjectType, |
| 4309 | NamedDecl *UnqualLookup, |
| 4310 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4311 | if (getDerived().AlreadyTransformed(TL.getType())) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4312 | return TL; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4313 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4314 | TypeSourceInfo *TSI = |
| 4315 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 4316 | if (TSI) |
| 4317 | return TSI->getTypeLoc(); |
| 4318 | return TypeLoc(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4321 | template<typename Derived> |
| 4322 | TypeSourceInfo * |
| 4323 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4324 | QualType ObjectType, |
| 4325 | NamedDecl *UnqualLookup, |
| 4326 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4327 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4328 | return TSInfo; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4329 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4330 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 4331 | UnqualLookup, SS); |
| 4332 | } |
| 4333 | |
| 4334 | template <typename Derived> |
| 4335 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 4336 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 4337 | CXXScopeSpec &SS) { |
| 4338 | QualType T = TL.getType(); |
| 4339 | assert(!getDerived().AlreadyTransformed(T)); |
| 4340 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4341 | TypeLocBuilder TLB; |
| 4342 | QualType Result; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4343 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4344 | if (isa<TemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4345 | TemplateSpecializationTypeLoc SpecTL = |
| 4346 | TL.castAs<TemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4347 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4348 | TemplateName Template = getDerived().TransformTemplateName( |
| 4349 | SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), |
| 4350 | ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4351 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4352 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4353 | |
| 4354 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4355 | Template); |
| 4356 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4357 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 4358 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4359 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4360 | TemplateName Template |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4361 | = getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 4362 | SpecTL.getTemplateKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4363 | *SpecTL.getTypePtr()->getIdentifier(), |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4364 | SpecTL.getTemplateNameLoc(), |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4365 | ObjectType, UnqualLookup, |
| 4366 | /*AllowInjectedClassName*/true); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4367 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4368 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4369 | |
| 4370 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4371 | SpecTL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4372 | Template, |
| 4373 | SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4374 | } else { |
| 4375 | // Nothing special needs to be done for these. |
| 4376 | Result = getDerived().TransformType(TLB, TL); |
| 4377 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4378 | |
| 4379 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4380 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4381 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4382 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4383 | } |
| 4384 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4385 | template <class TyLoc> static inline |
| 4386 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 4387 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 4388 | NewT.setNameLoc(T.getNameLoc()); |
| 4389 | return T.getType(); |
| 4390 | } |
| 4391 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4392 | template<typename Derived> |
| 4393 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4394 | BuiltinTypeLoc T) { |
| Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4395 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 4396 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 4397 | if (T.needsExtraLocalData()) |
| 4398 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 4399 | return T.getType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4400 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4401 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4402 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4403 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4404 | ComplexTypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4405 | // FIXME: recurse? |
| 4406 | return TransformTypeSpecType(TLB, T); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4407 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4408 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4409 | template <typename Derived> |
| 4410 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 4411 | AdjustedTypeLoc TL) { |
| 4412 | // Adjustments applied during transformation are handled elsewhere. |
| 4413 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4414 | } |
| 4415 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4416 | template<typename Derived> |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4417 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4418 | DecayedTypeLoc TL) { |
| 4419 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4420 | if (OriginalType.isNull()) |
| 4421 | return QualType(); |
| 4422 | |
| 4423 | QualType Result = TL.getType(); |
| 4424 | if (getDerived().AlwaysRebuild() || |
| 4425 | OriginalType != TL.getOriginalLoc().getType()) |
| 4426 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4427 | TLB.push<DecayedTypeLoc>(Result); |
| 4428 | // Nothing to set for DecayedTypeLoc. |
| 4429 | return Result; |
| 4430 | } |
| 4431 | |
| 4432 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4433 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4434 | PointerTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4435 | QualType PointeeType |
| 4436 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4437 | if (PointeeType.isNull()) |
| 4438 | return QualType(); |
| 4439 | |
| 4440 | QualType Result = TL.getType(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4441 | if (PointeeType->getAs<ObjCObjectType>()) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4442 | // A dependent pointer type 'T *' has is being transformed such |
| 4443 | // that an Objective-C class type is being replaced for 'T'. The |
| 4444 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4445 | // PointerType. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4446 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4447 | |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4448 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4449 | NewT.setStarLoc(TL.getStarLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4450 | return Result; |
| 4451 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4452 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4453 | if (getDerived().AlwaysRebuild() || |
| 4454 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4455 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4456 | if (Result.isNull()) |
| 4457 | return QualType(); |
| 4458 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4459 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4460 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4461 | // pointing to. |
| 4462 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4463 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4464 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4465 | NewT.setSigilLoc(TL.getSigilLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4466 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4467 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4468 | |
| 4469 | template<typename Derived> |
| 4470 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4471 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4472 | BlockPointerTypeLoc TL) { |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4473 | QualType PointeeType |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4474 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4475 | if (PointeeType.isNull()) |
| 4476 | return QualType(); |
| 4477 | |
| 4478 | QualType Result = TL.getType(); |
| 4479 | if (getDerived().AlwaysRebuild() || |
| 4480 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4481 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4482 | TL.getSigilLoc()); |
| 4483 | if (Result.isNull()) |
| 4484 | return QualType(); |
| 4485 | } |
| 4486 | |
| Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4487 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4488 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4489 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4492 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4493 | /// don't care whether the type itself is an l-value type or an r-value |
| 4494 | /// type; we only care if the type was *written* as an l-value type |
| 4495 | /// or an r-value type. |
| 4496 | template<typename Derived> |
| 4497 | QualType |
| 4498 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4499 | ReferenceTypeLoc TL) { |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4500 | const ReferenceType *T = TL.getTypePtr(); |
| 4501 | |
| 4502 | // Note that this works with the pointee-as-written. |
| 4503 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4504 | if (PointeeType.isNull()) |
| 4505 | return QualType(); |
| 4506 | |
| 4507 | QualType Result = TL.getType(); |
| 4508 | if (getDerived().AlwaysRebuild() || |
| 4509 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4510 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4511 | T->isSpelledAsLValue(), |
| 4512 | TL.getSigilLoc()); |
| 4513 | if (Result.isNull()) |
| 4514 | return QualType(); |
| 4515 | } |
| 4516 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4517 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4518 | // referring to. |
| 4519 | TLB.TypeWasModifiedSafely( |
| 4520 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4521 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4522 | // r-value references can be rebuilt as l-value references. |
| 4523 | ReferenceTypeLoc NewTL; |
| 4524 | if (isa<LValueReferenceType>(Result)) |
| 4525 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4526 | else |
| 4527 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4528 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4529 | |
| 4530 | return Result; |
| 4531 | } |
| 4532 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4533 | template<typename Derived> |
| 4534 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4535 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4536 | LValueReferenceTypeLoc TL) { |
| 4537 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4540 | template<typename Derived> |
| 4541 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4542 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4543 | RValueReferenceTypeLoc TL) { |
| 4544 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4545 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4546 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4547 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4548 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4549 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4550 | MemberPointerTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4551 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4552 | if (PointeeType.isNull()) |
| 4553 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4554 | |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4555 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4556 | TypeSourceInfo *NewClsTInfo = nullptr; |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4557 | if (OldClsTInfo) { |
| 4558 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4559 | if (!NewClsTInfo) |
| 4560 | return QualType(); |
| 4561 | } |
| 4562 | |
| 4563 | const MemberPointerType *T = TL.getTypePtr(); |
| 4564 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4565 | QualType NewClsType; |
| 4566 | if (NewClsTInfo) |
| 4567 | NewClsType = NewClsTInfo->getType(); |
| 4568 | else { |
| 4569 | NewClsType = getDerived().TransformType(OldClsType); |
| 4570 | if (NewClsType.isNull()) |
| 4571 | return QualType(); |
| 4572 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4573 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4574 | QualType Result = TL.getType(); |
| 4575 | if (getDerived().AlwaysRebuild() || |
| 4576 | PointeeType != T->getPointeeType() || |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4577 | NewClsType != OldClsType) { |
| 4578 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4579 | TL.getStarLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4580 | if (Result.isNull()) |
| 4581 | return QualType(); |
| 4582 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4583 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4584 | // If we had to adjust the pointee type when building a member pointer, make |
| 4585 | // sure to push TypeLoc info for it. |
| 4586 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4587 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4588 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4589 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4590 | } |
| 4591 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4592 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4593 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4594 | NewTL.setClassTInfo(NewClsTInfo); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4595 | |
| 4596 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4597 | } |
| 4598 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4599 | template<typename Derived> |
| 4600 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4601 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4602 | ConstantArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4603 | const ConstantArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4604 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4605 | if (ElementType.isNull()) |
| 4606 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4607 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4608 | QualType Result = TL.getType(); |
| 4609 | if (getDerived().AlwaysRebuild() || |
| 4610 | ElementType != T->getElementType()) { |
| 4611 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4612 | T->getSizeModifier(), |
| 4613 | T->getSize(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4614 | T->getIndexTypeCVRQualifiers(), |
| 4615 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4616 | if (Result.isNull()) |
| 4617 | return QualType(); |
| 4618 | } |
| Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4619 | |
| 4620 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4621 | // a ConstantArrayType is allowed to have an element type which is a |
| 4622 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4623 | // types have the same location layout. |
| 4624 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4625 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4626 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4627 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4628 | Expr *Size = TL.getSizeExpr(); |
| 4629 | if (Size) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4630 | EnterExpressionEvaluationContext Unevaluated( |
| 4631 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4632 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4633 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4634 | } |
| 4635 | NewTL.setSizeExpr(Size); |
| 4636 | |
| 4637 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4638 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4640 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4641 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4642 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4643 | IncompleteArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4644 | const IncompleteArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4645 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4646 | if (ElementType.isNull()) |
| 4647 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4648 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4649 | QualType Result = TL.getType(); |
| 4650 | if (getDerived().AlwaysRebuild() || |
| 4651 | ElementType != T->getElementType()) { |
| 4652 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4653 | T->getSizeModifier(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4654 | T->getIndexTypeCVRQualifiers(), |
| 4655 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4656 | if (Result.isNull()) |
| 4657 | return QualType(); |
| 4658 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4659 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4660 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4661 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4662 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4663 | NewTL.setSizeExpr(nullptr); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4664 | |
| 4665 | return Result; |
| 4666 | } |
| 4667 | |
| 4668 | template<typename Derived> |
| 4669 | QualType |
| 4670 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4671 | VariableArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4672 | const VariableArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4673 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4674 | if (ElementType.isNull()) |
| 4675 | return QualType(); |
| 4676 | |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4677 | ExprResult SizeResult; |
| 4678 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4679 | EnterExpressionEvaluationContext Context( |
| 4680 | SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4681 | SizeResult = getDerived().TransformExpr(T->getSizeExpr()); |
| 4682 | } |
| 4683 | if (SizeResult.isInvalid()) |
| 4684 | return QualType(); |
| 4685 | SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4686 | if (SizeResult.isInvalid()) |
| 4687 | return QualType(); |
| 4688 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4689 | Expr *Size = SizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4690 | |
| 4691 | QualType Result = TL.getType(); |
| 4692 | if (getDerived().AlwaysRebuild() || |
| 4693 | ElementType != T->getElementType() || |
| 4694 | Size != T->getSizeExpr()) { |
| 4695 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4696 | T->getSizeModifier(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4697 | Size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4698 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4699 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4700 | if (Result.isNull()) |
| 4701 | return QualType(); |
| 4702 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4703 | |
| Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4704 | // We might have constant size array now, but fortunately it has the same |
| 4705 | // location layout. |
| 4706 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4707 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4708 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4709 | NewTL.setSizeExpr(Size); |
| 4710 | |
| 4711 | return Result; |
| 4712 | } |
| 4713 | |
| 4714 | template<typename Derived> |
| 4715 | QualType |
| 4716 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4717 | DependentSizedArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4718 | const DependentSizedArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4719 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4720 | if (ElementType.isNull()) |
| 4721 | return QualType(); |
| 4722 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4723 | // Array bounds are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4724 | EnterExpressionEvaluationContext Unevaluated( |
| 4725 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4726 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4727 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4728 | Expr *origSize = TL.getSizeExpr(); |
| 4729 | if (!origSize) origSize = T->getSizeExpr(); |
| 4730 | |
| 4731 | ExprResult sizeResult |
| 4732 | = getDerived().TransformExpr(origSize); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4733 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4734 | if (sizeResult.isInvalid()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4735 | return QualType(); |
| 4736 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4737 | Expr *size = sizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4738 | |
| 4739 | QualType Result = TL.getType(); |
| 4740 | if (getDerived().AlwaysRebuild() || |
| 4741 | ElementType != T->getElementType() || |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4742 | size != origSize) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4743 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4744 | T->getSizeModifier(), |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4745 | size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4746 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4747 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4748 | if (Result.isNull()) |
| 4749 | return QualType(); |
| 4750 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4751 | |
| 4752 | // We might have any sort of array type now, but fortunately they |
| 4753 | // all have the same location layout. |
| 4754 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4755 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4756 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4757 | NewTL.setSizeExpr(size); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4758 | |
| 4759 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4760 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4761 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 4762 | template <typename Derived> |
| 4763 | QualType TreeTransform<Derived>::TransformDependentVectorType( |
| 4764 | TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { |
| 4765 | const DependentVectorType *T = TL.getTypePtr(); |
| 4766 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4767 | if (ElementType.isNull()) |
| 4768 | return QualType(); |
| 4769 | |
| 4770 | EnterExpressionEvaluationContext Unevaluated( |
| 4771 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4772 | |
| 4773 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 4774 | Size = SemaRef.ActOnConstantExpression(Size); |
| 4775 | if (Size.isInvalid()) |
| 4776 | return QualType(); |
| 4777 | |
| 4778 | QualType Result = TL.getType(); |
| 4779 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 4780 | Size.get() != T->getSizeExpr()) { |
| 4781 | Result = getDerived().RebuildDependentVectorType( |
| 4782 | ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); |
| 4783 | if (Result.isNull()) |
| 4784 | return QualType(); |
| 4785 | } |
| 4786 | |
| 4787 | // Result might be dependent or not. |
| 4788 | if (isa<DependentVectorType>(Result)) { |
| 4789 | DependentVectorTypeLoc NewTL = |
| 4790 | TLB.push<DependentVectorTypeLoc>(Result); |
| 4791 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4792 | } else { |
| 4793 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4794 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4795 | } |
| 4796 | |
| 4797 | return Result; |
| 4798 | } |
| 4799 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4800 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4801 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4802 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4803 | DependentSizedExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4804 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4805 | |
| 4806 | // FIXME: ext vector locs should be nested |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4807 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4808 | if (ElementType.isNull()) |
| 4809 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4810 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4811 | // Vector sizes are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4812 | EnterExpressionEvaluationContext Unevaluated( |
| 4813 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4814 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4815 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4816 | Size = SemaRef.ActOnConstantExpression(Size); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4817 | if (Size.isInvalid()) |
| 4818 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4819 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4820 | QualType Result = TL.getType(); |
| 4821 | if (getDerived().AlwaysRebuild() || |
| John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4822 | ElementType != T->getElementType() || |
| 4823 | Size.get() != T->getSizeExpr()) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4824 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4825 | Size.get(), |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4826 | T->getAttributeLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4827 | if (Result.isNull()) |
| 4828 | return QualType(); |
| 4829 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4830 | |
| 4831 | // Result might be dependent or not. |
| 4832 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4833 | DependentSizedExtVectorTypeLoc NewTL |
| 4834 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4835 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4836 | } else { |
| 4837 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4838 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4839 | } |
| 4840 | |
| 4841 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4842 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 4844 | template <typename Derived> |
| 4845 | QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( |
| 4846 | TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { |
| 4847 | const DependentAddressSpaceType *T = TL.getTypePtr(); |
| 4848 | |
| 4849 | QualType pointeeType = getDerived().TransformType(T->getPointeeType()); |
| 4850 | |
| 4851 | if (pointeeType.isNull()) |
| 4852 | return QualType(); |
| 4853 | |
| 4854 | // Address spaces are constant expressions. |
| 4855 | EnterExpressionEvaluationContext Unevaluated( |
| 4856 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4857 | |
| 4858 | ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); |
| 4859 | AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); |
| 4860 | if (AddrSpace.isInvalid()) |
| 4861 | return QualType(); |
| 4862 | |
| 4863 | QualType Result = TL.getType(); |
| 4864 | if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || |
| 4865 | AddrSpace.get() != T->getAddrSpaceExpr()) { |
| 4866 | Result = getDerived().RebuildDependentAddressSpaceType( |
| 4867 | pointeeType, AddrSpace.get(), T->getAttributeLoc()); |
| 4868 | if (Result.isNull()) |
| 4869 | return QualType(); |
| 4870 | } |
| 4871 | |
| 4872 | // Result might be dependent or not. |
| 4873 | if (isa<DependentAddressSpaceType>(Result)) { |
| 4874 | DependentAddressSpaceTypeLoc NewTL = |
| 4875 | TLB.push<DependentAddressSpaceTypeLoc>(Result); |
| 4876 | |
| 4877 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4878 | NewTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4879 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4880 | |
| 4881 | } else { |
| 4882 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( |
| 4883 | Result, getDerived().getBaseLocation()); |
| 4884 | TransformType(TLB, DI->getTypeLoc()); |
| 4885 | } |
| 4886 | |
| 4887 | return Result; |
| 4888 | } |
| 4889 | |
| 4890 | template <typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4891 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4892 | VectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4893 | const VectorType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4894 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4895 | if (ElementType.isNull()) |
| 4896 | return QualType(); |
| 4897 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4898 | QualType Result = TL.getType(); |
| 4899 | if (getDerived().AlwaysRebuild() || |
| 4900 | ElementType != T->getElementType()) { |
| John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 4901 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 4902 | T->getVectorKind()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4903 | if (Result.isNull()) |
| 4904 | return QualType(); |
| 4905 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4906 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4907 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4908 | NewTL.setNameLoc(TL.getNameLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4909 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4910 | return Result; |
| 4911 | } |
| 4912 | |
| 4913 | template<typename Derived> |
| 4914 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4915 | ExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4916 | const VectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4917 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4918 | if (ElementType.isNull()) |
| 4919 | return QualType(); |
| 4920 | |
| 4921 | QualType Result = TL.getType(); |
| 4922 | if (getDerived().AlwaysRebuild() || |
| 4923 | ElementType != T->getElementType()) { |
| 4924 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 4925 | T->getNumElements(), |
| 4926 | /*FIXME*/ SourceLocation()); |
| 4927 | if (Result.isNull()) |
| 4928 | return QualType(); |
| 4929 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4930 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4931 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4932 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4933 | |
| 4934 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4935 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4936 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4937 | template <typename Derived> |
| 4938 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 4939 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 4940 | bool ExpectParameterPack) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4941 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4942 | TypeSourceInfo *NewDI = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4943 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4944 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4945 | // If we're substituting into a pack expansion type and we know the |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 4946 | // length we want to expand to, just substitute for the pattern. |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4947 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4948 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4949 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4950 | TypeLocBuilder TLB; |
| 4951 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 4952 | TLB.reserve(NewTL.getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4953 | |
| 4954 | QualType Result = getDerived().TransformType(TLB, |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4955 | OldExpansionTL.getPatternLoc()); |
| 4956 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4957 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4958 | |
| 4959 | Result = RebuildPackExpansionType(Result, |
| 4960 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4961 | OldExpansionTL.getEllipsisLoc(), |
| 4962 | NumExpansions); |
| 4963 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4964 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4965 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 4966 | PackExpansionTypeLoc NewExpansionTL |
| 4967 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 4968 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 4969 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4970 | } else |
| 4971 | NewDI = getDerived().TransformType(OldDI); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4972 | if (!NewDI) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4973 | return nullptr; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4974 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4975 | if (NewDI == OldDI && indexAdjustment == 0) |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4976 | return OldParm; |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4977 | |
| 4978 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 4979 | OldParm->getDeclContext(), |
| 4980 | OldParm->getInnerLocStart(), |
| 4981 | OldParm->getLocation(), |
| 4982 | OldParm->getIdentifier(), |
| 4983 | NewDI->getType(), |
| 4984 | NewDI, |
| 4985 | OldParm->getStorageClass(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4986 | /* DefArg */ nullptr); |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 4987 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 4988 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 4989 | return newParm; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 4990 | } |
| 4991 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4992 | template <typename Derived> |
| 4993 | bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 4994 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 4995 | const QualType *ParamTypes, |
| 4996 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 4997 | SmallVectorImpl<QualType> &OutParamTypes, |
| 4998 | SmallVectorImpl<ParmVarDecl *> *PVars, |
| 4999 | Sema::ExtParameterInfoBuilder &PInfos) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5000 | int indexAdjustment = 0; |
| 5001 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5002 | unsigned NumParams = Params.size(); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5003 | for (unsigned i = 0; i != NumParams; ++i) { |
| 5004 | if (ParmVarDecl *OldParm = Params[i]) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5005 | assert(OldParm->getFunctionScopeIndex() == i); |
| 5006 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5007 | Optional<unsigned> NumExpansions; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5008 | ParmVarDecl *NewParm = nullptr; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5009 | if (OldParm->isParameterPack()) { |
| 5010 | // We have a function parameter pack that may need to be expanded. |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5011 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5012 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5013 | // Find the parameter packs that could be expanded. |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5014 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 5015 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5016 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 5017 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5018 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 5019 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5020 | // Determine whether we should expand the parameter packs. |
| 5021 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5022 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5023 | Optional<unsigned> OrigNumExpansions = |
| 5024 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5025 | NumExpansions = OrigNumExpansions; |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5026 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 5027 | Pattern.getSourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5028 | Unexpanded, |
| 5029 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5030 | RetainExpansion, |
| 5031 | NumExpansions)) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5032 | return true; |
| 5033 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5034 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5035 | if (ShouldExpand) { |
| 5036 | // Expand the function parameter pack into multiple, separate |
| 5037 | // parameters. |
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 5038 | getDerived().ExpandingFunctionParameterPack(OldParm); |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5039 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5040 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5041 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5042 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5043 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5044 | OrigNumExpansions, |
| 5045 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5046 | if (!NewParm) |
| 5047 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5048 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5049 | if (ParamInfos) |
| 5050 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5051 | OutParamTypes.push_back(NewParm->getType()); |
| 5052 | if (PVars) |
| 5053 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5054 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5055 | |
| 5056 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5057 | // forgetting the partially-substituted parameter pack. |
| 5058 | if (RetainExpansion) { |
| 5059 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5060 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5061 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5062 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5063 | OrigNumExpansions, |
| 5064 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5065 | if (!NewParm) |
| 5066 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5067 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5068 | if (ParamInfos) |
| 5069 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5070 | OutParamTypes.push_back(NewParm->getType()); |
| 5071 | if (PVars) |
| 5072 | PVars->push_back(NewParm); |
| 5073 | } |
| 5074 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5075 | // The next parameter should have the same adjustment as the |
| 5076 | // last thing we pushed, but we post-incremented indexAdjustment |
| 5077 | // on every push. Also, if we push nothing, the adjustment should |
| 5078 | // go down by one. |
| 5079 | indexAdjustment--; |
| 5080 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5081 | // We're done with the pack expansion. |
| 5082 | continue; |
| 5083 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5084 | |
| 5085 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5086 | // expansion. |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5087 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5088 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5089 | indexAdjustment, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5090 | NumExpansions, |
| 5091 | /*ExpectParameterPack=*/true); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5092 | } else { |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5093 | NewParm = getDerived().TransformFunctionTypeParam( |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 5094 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5095 | } |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5096 | |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5097 | if (!NewParm) |
| 5098 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5099 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5100 | if (ParamInfos) |
| 5101 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5102 | OutParamTypes.push_back(NewParm->getType()); |
| 5103 | if (PVars) |
| 5104 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5105 | continue; |
| 5106 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5107 | |
| 5108 | // Deal with the possibility that we don't have a parameter |
| 5109 | // declaration for this parameter. |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5110 | QualType OldType = ParamTypes[i]; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5111 | bool IsPackExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5112 | Optional<unsigned> NumExpansions; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5113 | QualType NewType; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5114 | if (const PackExpansionType *Expansion |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5115 | = dyn_cast<PackExpansionType>(OldType)) { |
| 5116 | // We have a function parameter pack that may need to be expanded. |
| 5117 | QualType Pattern = Expansion->getPattern(); |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5118 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5119 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5120 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5121 | // Determine whether we should expand the parameter packs. |
| 5122 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5123 | bool RetainExpansion = false; |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5124 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5125 | Unexpanded, |
| 5126 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5127 | RetainExpansion, |
| 5128 | NumExpansions)) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5129 | return true; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5130 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5131 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5132 | if (ShouldExpand) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5133 | // Expand the function parameter pack into multiple, separate |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5134 | // parameters. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5135 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5136 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 5137 | QualType NewType = getDerived().TransformType(Pattern); |
| 5138 | if (NewType.isNull()) |
| 5139 | return true; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5140 | |
| Erik Pilkington | f1bd000 | 2016-07-05 17:57:24 +0000 | [diff] [blame] | 5141 | if (NewType->containsUnexpandedParameterPack()) { |
| 5142 | NewType = |
| 5143 | getSema().getASTContext().getPackExpansionType(NewType, None); |
| 5144 | |
| 5145 | if (NewType.isNull()) |
| 5146 | return true; |
| 5147 | } |
| 5148 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5149 | if (ParamInfos) |
| 5150 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5151 | OutParamTypes.push_back(NewType); |
| 5152 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5153 | PVars->push_back(nullptr); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5154 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5155 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5156 | // We're done with the pack expansion. |
| 5157 | continue; |
| 5158 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5159 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5160 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5161 | // forgetting the partially-substituted parameter pack. |
| 5162 | if (RetainExpansion) { |
| 5163 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5164 | QualType NewType = getDerived().TransformType(Pattern); |
| 5165 | if (NewType.isNull()) |
| 5166 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5167 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5168 | if (ParamInfos) |
| 5169 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5170 | OutParamTypes.push_back(NewType); |
| 5171 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5172 | PVars->push_back(nullptr); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5173 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5174 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5175 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5176 | // expansion. |
| 5177 | OldType = Expansion->getPattern(); |
| 5178 | IsPackExpansion = true; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5179 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5180 | NewType = getDerived().TransformType(OldType); |
| 5181 | } else { |
| 5182 | NewType = getDerived().TransformType(OldType); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5183 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5184 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5185 | if (NewType.isNull()) |
| 5186 | return true; |
| 5187 | |
| 5188 | if (IsPackExpansion) |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5189 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 5190 | NumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5191 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5192 | if (ParamInfos) |
| 5193 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5194 | OutParamTypes.push_back(NewType); |
| 5195 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5196 | PVars->push_back(nullptr); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5197 | } |
| 5198 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5199 | #ifndef NDEBUG |
| 5200 | if (PVars) { |
| 5201 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 5202 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 5203 | assert(parm->getFunctionScopeIndex() == i); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5204 | } |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5205 | #endif |
| 5206 | |
| 5207 | return false; |
| 5208 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5209 | |
| 5210 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5211 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5212 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5213 | FunctionProtoTypeLoc TL) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5214 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5215 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5216 | return getDerived().TransformFunctionProtoType( |
| 5217 | TLB, TL, nullptr, 0, |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5218 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 5219 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 5220 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5221 | }); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5224 | template<typename Derived> template<typename Fn> |
| 5225 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 5226 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 5227 | unsigned ThisTypeQuals, Fn TransformExceptionSpec) { |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5228 | |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5229 | // Transform the parameters and return type. |
| 5230 | // |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5231 | // We are required to instantiate the params and return type in source order. |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5232 | // When the function has a trailing return type, we instantiate the |
| 5233 | // parameters before the return type, since the return type can then refer |
| 5234 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 5235 | // |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5236 | SmallVector<QualType, 4> ParamTypes; |
| 5237 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5238 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5239 | const FunctionProtoType *T = TL.getTypePtr(); |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5240 | |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5241 | QualType ResultType; |
| 5242 | |
| Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 5243 | if (T->hasTrailingReturn()) { |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5244 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5245 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5246 | TL.getTypePtr()->param_type_begin(), |
| 5247 | T->getExtParameterInfosOrNull(), |
| 5248 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5249 | return QualType(); |
| 5250 | |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5251 | { |
| 5252 | // C++11 [expr.prim.general]p3: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5253 | // If a declaration declares a member function or member function |
| 5254 | // template of a class X, the expression this is a prvalue of type |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5255 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5256 | // and the end of the function-definition, member-declarator, or |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5257 | // declarator. |
| 5258 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5259 | |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5260 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5261 | if (ResultType.isNull()) |
| 5262 | return QualType(); |
| 5263 | } |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5264 | } |
| 5265 | else { |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5266 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5267 | if (ResultType.isNull()) |
| 5268 | return QualType(); |
| 5269 | |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5270 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5271 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5272 | TL.getTypePtr()->param_type_begin(), |
| 5273 | T->getExtParameterInfosOrNull(), |
| 5274 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5275 | return QualType(); |
| 5276 | } |
| 5277 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5278 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 5279 | |
| 5280 | bool EPIChanged = false; |
| 5281 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 5282 | return QualType(); |
| 5283 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5284 | // Handle extended parameter information. |
| 5285 | if (auto NewExtParamInfos = |
| 5286 | ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 5287 | if (!EPI.ExtParameterInfos || |
| 5288 | llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) |
| 5289 | != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 5290 | EPIChanged = true; |
| 5291 | } |
| 5292 | EPI.ExtParameterInfos = NewExtParamInfos; |
| 5293 | } else if (EPI.ExtParameterInfos) { |
| 5294 | EPIChanged = true; |
| 5295 | EPI.ExtParameterInfos = nullptr; |
| 5296 | } |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5297 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5298 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5299 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
| Benjamin Kramer | e1c08b0 | 2015-08-18 08:10:39 +0000 | [diff] [blame] | 5300 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5301 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5302 | if (Result.isNull()) |
| 5303 | return QualType(); |
| 5304 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5305 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5306 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5307 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5308 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5309 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 5310 | NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5311 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 5312 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 5313 | NewTL.setParam(i, ParamDecls[i]); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5314 | |
| 5315 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5316 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5317 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5318 | template<typename Derived> |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5319 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 5320 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 5321 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 5322 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 5323 | |
| 5324 | // Instantiate a dynamic noexcept expression, if any. |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5325 | if (isComputedNoexcept(ESI.Type)) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5326 | EnterExpressionEvaluationContext Unevaluated( |
| 5327 | getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5328 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 5329 | if (NoexceptExpr.isInvalid()) |
| 5330 | return true; |
| 5331 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5332 | ExceptionSpecificationType EST = ESI.Type; |
| 5333 | NoexceptExpr = |
| 5334 | getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5335 | if (NoexceptExpr.isInvalid()) |
| 5336 | return true; |
| 5337 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5338 | if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5339 | Changed = true; |
| 5340 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5341 | ESI.Type = EST; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | if (ESI.Type != EST_Dynamic) |
| 5345 | return false; |
| 5346 | |
| 5347 | // Instantiate a dynamic exception specification's type. |
| 5348 | for (QualType T : ESI.Exceptions) { |
| 5349 | if (const PackExpansionType *PackExpansion = |
| 5350 | T->getAs<PackExpansionType>()) { |
| 5351 | Changed = true; |
| 5352 | |
| 5353 | // We have a pack expansion. Instantiate it. |
| 5354 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5355 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5356 | Unexpanded); |
| 5357 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5358 | |
| 5359 | // Determine whether the set of unexpanded parameter packs can and |
| 5360 | // should |
| 5361 | // be expanded. |
| 5362 | bool Expand = false; |
| 5363 | bool RetainExpansion = false; |
| 5364 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5365 | // FIXME: Track the location of the ellipsis (and track source location |
| 5366 | // information for the types in the exception specification in general). |
| 5367 | if (getDerived().TryExpandParameterPacks( |
| 5368 | Loc, SourceRange(), Unexpanded, Expand, |
| 5369 | RetainExpansion, NumExpansions)) |
| 5370 | return true; |
| 5371 | |
| 5372 | if (!Expand) { |
| 5373 | // We can't expand this pack expansion into separate arguments yet; |
| 5374 | // just substitute into the pattern and create a new pack expansion |
| 5375 | // type. |
| 5376 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5377 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5378 | if (U.isNull()) |
| 5379 | return true; |
| 5380 | |
| 5381 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 5382 | Exceptions.push_back(U); |
| 5383 | continue; |
| 5384 | } |
| 5385 | |
| 5386 | // Substitute into the pack expansion pattern for each slice of the |
| 5387 | // pack. |
| 5388 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5389 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5390 | |
| 5391 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5392 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5393 | return true; |
| 5394 | |
| 5395 | Exceptions.push_back(U); |
| 5396 | } |
| 5397 | } else { |
| 5398 | QualType U = getDerived().TransformType(T); |
| 5399 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5400 | return true; |
| 5401 | if (T != U) |
| 5402 | Changed = true; |
| 5403 | |
| 5404 | Exceptions.push_back(U); |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | ESI.Exceptions = Exceptions; |
| Richard Smith | fda59e5 | 2016-10-26 01:05:54 +0000 | [diff] [blame] | 5409 | if (ESI.Exceptions.empty()) |
| 5410 | ESI.Type = EST_DynamicNone; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5411 | return false; |
| 5412 | } |
| 5413 | |
| 5414 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5415 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5416 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5417 | FunctionNoProtoTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5418 | const FunctionNoProtoType *T = TL.getTypePtr(); |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5419 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5420 | if (ResultType.isNull()) |
| 5421 | return QualType(); |
| 5422 | |
| 5423 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5424 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5425 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 5426 | |
| 5427 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5428 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5429 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5430 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5431 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5432 | |
| 5433 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5434 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5435 | |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5436 | template<typename Derived> QualType |
| 5437 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5438 | UnresolvedUsingTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5439 | const UnresolvedUsingType *T = TL.getTypePtr(); |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5440 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5441 | if (!D) |
| 5442 | return QualType(); |
| 5443 | |
| 5444 | QualType Result = TL.getType(); |
| 5445 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 5446 | Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5447 | if (Result.isNull()) |
| 5448 | return QualType(); |
| 5449 | } |
| 5450 | |
| 5451 | // We might get an arbitrary type spec type back. We should at |
| 5452 | // least always get a type spec type, though. |
| 5453 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 5454 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5455 | |
| 5456 | return Result; |
| 5457 | } |
| 5458 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5459 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5460 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5461 | TypedefTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5462 | const TypedefType *T = TL.getTypePtr(); |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5463 | TypedefNameDecl *Typedef |
| 5464 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5465 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5466 | if (!Typedef) |
| 5467 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5468 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5469 | QualType Result = TL.getType(); |
| 5470 | if (getDerived().AlwaysRebuild() || |
| 5471 | Typedef != T->getDecl()) { |
| 5472 | Result = getDerived().RebuildTypedefType(Typedef); |
| 5473 | if (Result.isNull()) |
| 5474 | return QualType(); |
| 5475 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5476 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5477 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 5478 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5479 | |
| 5480 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5481 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5482 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5483 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5484 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5485 | TypeOfExprTypeLoc TL) { |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5486 | // typeof expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5487 | EnterExpressionEvaluationContext Unevaluated( |
| 5488 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 5489 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5490 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5491 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5492 | if (E.isInvalid()) |
| 5493 | return QualType(); |
| 5494 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 5495 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 5496 | if (E.isInvalid()) |
| 5497 | return QualType(); |
| 5498 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5499 | QualType Result = TL.getType(); |
| 5500 | if (getDerived().AlwaysRebuild() || |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5501 | E.get() != TL.getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5502 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5503 | if (Result.isNull()) |
| 5504 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5505 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5506 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5507 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5508 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5509 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5510 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5511 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5512 | |
| 5513 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5514 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5515 | |
| 5516 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5517 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5518 | TypeOfTypeLoc TL) { |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5519 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 5520 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 5521 | if (!New_Under_TI) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5522 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5523 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5524 | QualType Result = TL.getType(); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5525 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 5526 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5527 | if (Result.isNull()) |
| 5528 | return QualType(); |
| 5529 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5530 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5531 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5532 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5533 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5534 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5535 | NewTL.setUnderlyingTInfo(New_Under_TI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5536 | |
| 5537 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5538 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5539 | |
| 5540 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5541 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5542 | DecltypeTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5543 | const DecltypeType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5544 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5545 | // decltype expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5546 | EnterExpressionEvaluationContext Unevaluated( |
| 5547 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| Nicolas Lesser | b6d5c58 | 2018-07-12 18:45:41 +0000 | [diff] [blame] | 5548 | Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5549 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5550 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5551 | if (E.isInvalid()) |
| 5552 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5553 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5554 | E = getSema().ActOnDecltypeExpression(E.get()); |
| Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 5555 | if (E.isInvalid()) |
| 5556 | return QualType(); |
| 5557 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5558 | QualType Result = TL.getType(); |
| 5559 | if (getDerived().AlwaysRebuild() || |
| 5560 | E.get() != T->getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5561 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5562 | if (Result.isNull()) |
| 5563 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5564 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5565 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5566 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5567 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 5568 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5569 | |
| 5570 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5574 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5575 | TypeLocBuilder &TLB, |
| 5576 | UnaryTransformTypeLoc TL) { |
| 5577 | QualType Result = TL.getType(); |
| 5578 | if (Result->isDependentType()) { |
| 5579 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5580 | QualType NewBase = |
| 5581 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5582 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5583 | T->getUTTKind(), |
| 5584 | TL.getKWLoc()); |
| 5585 | if (Result.isNull()) |
| 5586 | return QualType(); |
| 5587 | } |
| 5588 | |
| 5589 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5590 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5591 | NewTL.setParensRange(TL.getParensRange()); |
| 5592 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5593 | return Result; |
| 5594 | } |
| 5595 | |
| 5596 | template<typename Derived> |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5597 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5598 | AutoTypeLoc TL) { |
| 5599 | const AutoType *T = TL.getTypePtr(); |
| 5600 | QualType OldDeduced = T->getDeducedType(); |
| 5601 | QualType NewDeduced; |
| 5602 | if (!OldDeduced.isNull()) { |
| 5603 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5604 | if (NewDeduced.isNull()) |
| 5605 | return QualType(); |
| 5606 | } |
| 5607 | |
| 5608 | QualType Result = TL.getType(); |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5609 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5610 | T->isDependentType()) { |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5611 | Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword()); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5612 | if (Result.isNull()) |
| 5613 | return QualType(); |
| 5614 | } |
| 5615 | |
| 5616 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5617 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5618 | |
| 5619 | return Result; |
| 5620 | } |
| 5621 | |
| 5622 | template<typename Derived> |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 5623 | QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( |
| 5624 | TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { |
| 5625 | const DeducedTemplateSpecializationType *T = TL.getTypePtr(); |
| 5626 | |
| 5627 | CXXScopeSpec SS; |
| 5628 | TemplateName TemplateName = getDerived().TransformTemplateName( |
| 5629 | SS, T->getTemplateName(), TL.getTemplateNameLoc()); |
| 5630 | if (TemplateName.isNull()) |
| 5631 | return QualType(); |
| 5632 | |
| 5633 | QualType OldDeduced = T->getDeducedType(); |
| 5634 | QualType NewDeduced; |
| 5635 | if (!OldDeduced.isNull()) { |
| 5636 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5637 | if (NewDeduced.isNull()) |
| 5638 | return QualType(); |
| 5639 | } |
| 5640 | |
| 5641 | QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( |
| 5642 | TemplateName, NewDeduced); |
| 5643 | if (Result.isNull()) |
| 5644 | return QualType(); |
| 5645 | |
| 5646 | DeducedTemplateSpecializationTypeLoc NewTL = |
| 5647 | TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 5648 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5649 | |
| 5650 | return Result; |
| 5651 | } |
| 5652 | |
| 5653 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5654 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5655 | RecordTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5656 | const RecordType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5657 | RecordDecl *Record |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5658 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5659 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5660 | if (!Record) |
| 5661 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5663 | QualType Result = TL.getType(); |
| 5664 | if (getDerived().AlwaysRebuild() || |
| 5665 | Record != T->getDecl()) { |
| 5666 | Result = getDerived().RebuildRecordType(Record); |
| 5667 | if (Result.isNull()) |
| 5668 | return QualType(); |
| 5669 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5670 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5671 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5672 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5673 | |
| 5674 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5675 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5676 | |
| 5677 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5678 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5679 | EnumTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5680 | const EnumType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5681 | EnumDecl *Enum |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5682 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5683 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5684 | if (!Enum) |
| 5685 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5686 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5687 | QualType Result = TL.getType(); |
| 5688 | if (getDerived().AlwaysRebuild() || |
| 5689 | Enum != T->getDecl()) { |
| 5690 | Result = getDerived().RebuildEnumType(Enum); |
| 5691 | if (Result.isNull()) |
| 5692 | return QualType(); |
| 5693 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5694 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5695 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5696 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5697 | |
| 5698 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5699 | } |
| John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5700 | |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5701 | template<typename Derived> |
| 5702 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5703 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5704 | InjectedClassNameTypeLoc TL) { |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5705 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5706 | TL.getTypePtr()->getDecl()); |
| 5707 | if (!D) return QualType(); |
| 5708 | |
| 5709 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5710 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5711 | return T; |
| 5712 | } |
| 5713 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5714 | template<typename Derived> |
| 5715 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5716 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5717 | TemplateTypeParmTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5718 | return TransformTypeSpecType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5721 | template<typename Derived> |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5722 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5723 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5724 | SubstTemplateTypeParmTypeLoc TL) { |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5725 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5726 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5727 | // Substitute into the replacement type, which itself might involve something |
| 5728 | // that needs to be transformed. This only tends to occur with default |
| 5729 | // template arguments of template template parameters. |
| 5730 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5731 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5732 | if (Replacement.isNull()) |
| 5733 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5734 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5735 | // Always canonicalize the replacement type. |
| 5736 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5737 | QualType Result |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5738 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5739 | Replacement); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5740 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5741 | // Propagate type-source information. |
| 5742 | SubstTemplateTypeParmTypeLoc NewTL |
| 5743 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5744 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5745 | return Result; |
| 5746 | |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | template<typename Derived> |
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5750 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5751 | TypeLocBuilder &TLB, |
| 5752 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5753 | return TransformTypeSpecType(TLB, TL); |
| 5754 | } |
| 5755 | |
| 5756 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5757 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5758 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5759 | TemplateSpecializationTypeLoc TL) { |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5760 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5761 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5762 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5763 | // because we can't have a dependent nested-name-specifier anyway. |
| 5764 | CXXScopeSpec SS; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5765 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5766 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5767 | TL.getTemplateNameLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5768 | if (Template.isNull()) |
| 5769 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5770 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5771 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5772 | } |
| 5773 | |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5774 | template<typename Derived> |
| 5775 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5776 | AtomicTypeLoc TL) { |
| 5777 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5778 | if (ValueType.isNull()) |
| 5779 | return QualType(); |
| 5780 | |
| 5781 | QualType Result = TL.getType(); |
| 5782 | if (getDerived().AlwaysRebuild() || |
| 5783 | ValueType != TL.getValueLoc().getType()) { |
| 5784 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5785 | if (Result.isNull()) |
| 5786 | return QualType(); |
| 5787 | } |
| 5788 | |
| 5789 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5790 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5791 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5792 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5793 | |
| 5794 | return Result; |
| 5795 | } |
| 5796 | |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5797 | template <typename Derived> |
| 5798 | QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 5799 | PipeTypeLoc TL) { |
| 5800 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5801 | if (ValueType.isNull()) |
| 5802 | return QualType(); |
| 5803 | |
| 5804 | QualType Result = TL.getType(); |
| 5805 | if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 5806 | const PipeType *PT = Result->getAs<PipeType>(); |
| 5807 | bool isReadPipe = PT->isReadOnly(); |
| 5808 | Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5809 | if (Result.isNull()) |
| 5810 | return QualType(); |
| 5811 | } |
| 5812 | |
| 5813 | PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 5814 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5815 | |
| 5816 | return Result; |
| 5817 | } |
| 5818 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5819 | /// Simple iterator that traverses the template arguments in a |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5820 | /// container that provides a \c getArgLoc() member function. |
| 5821 | /// |
| 5822 | /// This iterator is intended to be used with the iterator form of |
| 5823 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5824 | template<typename ArgLocContainer> |
| 5825 | class TemplateArgumentLocContainerIterator { |
| 5826 | ArgLocContainer *Container; |
| 5827 | unsigned Index; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5828 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5829 | public: |
| 5830 | typedef TemplateArgumentLoc value_type; |
| 5831 | typedef TemplateArgumentLoc reference; |
| 5832 | typedef int difference_type; |
| 5833 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5834 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5835 | class pointer { |
| 5836 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5837 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5838 | public: |
| 5839 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5840 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5841 | const TemplateArgumentLoc *operator->() const { |
| 5842 | return &Arg; |
| 5843 | } |
| 5844 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5845 | |
| 5846 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5847 | TemplateArgumentLocContainerIterator() {} |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5848 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5849 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5850 | unsigned Index) |
| 5851 | : Container(&Container), Index(Index) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5852 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5853 | TemplateArgumentLocContainerIterator &operator++() { |
| 5854 | ++Index; |
| 5855 | return *this; |
| 5856 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5857 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5858 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5859 | TemplateArgumentLocContainerIterator Old(*this); |
| 5860 | ++(*this); |
| 5861 | return Old; |
| 5862 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5863 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5864 | TemplateArgumentLoc operator*() const { |
| 5865 | return Container->getArgLoc(Index); |
| 5866 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5867 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5868 | pointer operator->() const { |
| 5869 | return pointer(Container->getArgLoc(Index)); |
| 5870 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5871 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5872 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5873 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5874 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5875 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5876 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5877 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5878 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5879 | return !(X == Y); |
| 5880 | } |
| 5881 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5882 | |
| 5883 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5884 | template <typename Derived> |
| 5885 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5886 | TypeLocBuilder &TLB, |
| 5887 | TemplateSpecializationTypeLoc TL, |
| 5888 | TemplateName Template) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5889 | TemplateArgumentListInfo NewTemplateArgs; |
| 5890 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5891 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5892 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 5893 | ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5894 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5895 | ArgIterator(TL, TL.getNumArgs()), |
| 5896 | NewTemplateArgs)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 5897 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5898 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5899 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 5900 | |
| 5901 | QualType Result = |
| 5902 | getDerived().RebuildTemplateSpecializationType(Template, |
| 5903 | TL.getTemplateNameLoc(), |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5904 | NewTemplateArgs); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5905 | |
| 5906 | if (!Result.isNull()) { |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5907 | // Specializations of template template parameters are represented as |
| 5908 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 5909 | // within a dependent context can transform them into |
| 5910 | // DependentTemplateSpecializationTypes. |
| 5911 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 5912 | DependentTemplateSpecializationTypeLoc NewTL |
| 5913 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5914 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5915 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5916 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5917 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 5918 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5919 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5920 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5921 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5922 | return Result; |
| 5923 | } |
| 5924 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5925 | TemplateSpecializationTypeLoc NewTL |
| 5926 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5927 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5928 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5929 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5930 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5931 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5932 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5933 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5934 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5935 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5936 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5937 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5938 | template <typename Derived> |
| 5939 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 5940 | TypeLocBuilder &TLB, |
| 5941 | DependentTemplateSpecializationTypeLoc TL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 5942 | TemplateName Template, |
| 5943 | CXXScopeSpec &SS) { |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5944 | TemplateArgumentListInfo NewTemplateArgs; |
| 5945 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5946 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 5947 | typedef TemplateArgumentLocContainerIterator< |
| 5948 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5949 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5950 | ArgIterator(TL, TL.getNumArgs()), |
| 5951 | NewTemplateArgs)) |
| 5952 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5953 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5954 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5955 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5956 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 5957 | QualType Result |
| 5958 | = getSema().Context.getDependentTemplateSpecializationType( |
| 5959 | TL.getTypePtr()->getKeyword(), |
| 5960 | DTN->getQualifier(), |
| 5961 | DTN->getIdentifier(), |
| 5962 | NewTemplateArgs); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5963 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5964 | DependentTemplateSpecializationTypeLoc NewTL |
| 5965 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5966 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 5967 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5968 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5969 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5970 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5971 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5972 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5973 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5974 | return Result; |
| 5975 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5976 | |
| 5977 | QualType Result |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5978 | = getDerived().RebuildTemplateSpecializationType(Template, |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5979 | TL.getTemplateNameLoc(), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5980 | NewTemplateArgs); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5981 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5982 | if (!Result.isNull()) { |
| 5983 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 5984 | TemplateSpecializationTypeLoc NewTL |
| 5985 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 5986 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 5987 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5988 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 5989 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 5990 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 5991 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 5992 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5993 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 5994 | return Result; |
| 5995 | } |
| 5996 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5997 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5998 | QualType |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 5999 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6000 | ElaboratedTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6001 | const ElaboratedType *T = TL.getTypePtr(); |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6002 | |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6003 | NestedNameSpecifierLoc QualifierLoc; |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6004 | // NOTE: the qualifier in an ElaboratedType is optional. |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6005 | if (TL.getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6006 | QualifierLoc |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6007 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6008 | if (!QualifierLoc) |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6009 | return QualType(); |
| 6010 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6011 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6012 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 6013 | if (NamedT.isNull()) |
| 6014 | return QualType(); |
| Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 6015 | |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6016 | // C++0x [dcl.type.elab]p2: |
| 6017 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 6018 | // resolves to an alias template specialization, the |
| 6019 | // elaborated-type-specifier is ill-formed. |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6020 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 6021 | if (const TemplateSpecializationType *TST = |
| 6022 | NamedT->getAs<TemplateSpecializationType>()) { |
| 6023 | TemplateName Template = TST->getTemplateName(); |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 6024 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 6025 | Template.getAsTemplateDecl())) { |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6026 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| Reid Kleckner | f33bfcb0 | 2016-10-03 18:34:23 +0000 | [diff] [blame] | 6027 | diag::err_tag_reference_non_tag) |
| Reid Kleckner | 1a4ab7e | 2016-12-09 19:47:58 +0000 | [diff] [blame] | 6028 | << TAT << Sema::NTK_TypeAliasTemplate |
| 6029 | << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6030 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 6031 | } |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6032 | } |
| 6033 | } |
| 6034 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6035 | QualType Result = TL.getType(); |
| 6036 | if (getDerived().AlwaysRebuild() || |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6037 | QualifierLoc != TL.getQualifierLoc() || |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6038 | NamedT != T->getNamedType()) { |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6039 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6040 | T->getKeyword(), |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6041 | QualifierLoc, NamedT); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6042 | if (Result.isNull()) |
| 6043 | return QualType(); |
| 6044 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6045 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6046 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6047 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6048 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6049 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6050 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6051 | |
| 6052 | template<typename Derived> |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6053 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 6054 | TypeLocBuilder &TLB, |
| 6055 | AttributedTypeLoc TL) { |
| 6056 | const AttributedType *oldType = TL.getTypePtr(); |
| 6057 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 6058 | if (modifiedType.isNull()) |
| 6059 | return QualType(); |
| 6060 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6061 | // oldAttr can be null if we started with a QualType rather than a TypeLoc. |
| 6062 | const Attr *oldAttr = TL.getAttr(); |
| 6063 | const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; |
| 6064 | if (oldAttr && !newAttr) |
| 6065 | return QualType(); |
| 6066 | |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6067 | QualType result = TL.getType(); |
| 6068 | |
| 6069 | // FIXME: dependent operand expressions? |
| 6070 | if (getDerived().AlwaysRebuild() || |
| 6071 | modifiedType != oldType->getModifiedType()) { |
| 6072 | // TODO: this is really lame; we should really be rebuilding the |
| 6073 | // equivalent type from first principles. |
| 6074 | QualType equivalentType |
| 6075 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 6076 | if (equivalentType.isNull()) |
| 6077 | return QualType(); |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6078 | |
| 6079 | // Check whether we can add nullability; it is only represented as |
| 6080 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 6081 | if (auto nullability = oldType->getImmediateNullability()) { |
| 6082 | if (!modifiedType->canHaveNullability()) { |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6083 | SemaRef.Diag(TL.getAttr()->getLocation(), |
| 6084 | diag::err_nullability_nonpointer) |
| 6085 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6086 | return QualType(); |
| 6087 | } |
| 6088 | } |
| 6089 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6090 | result = SemaRef.Context.getAttributedType(TL.getAttrKind(), |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6091 | modifiedType, |
| 6092 | equivalentType); |
| 6093 | } |
| 6094 | |
| 6095 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6096 | newTL.setAttr(newAttr); |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6097 | return result; |
| 6098 | } |
| 6099 | |
| 6100 | template<typename Derived> |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 6101 | QualType |
| 6102 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 6103 | ParenTypeLoc TL) { |
| 6104 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6105 | if (Inner.isNull()) |
| 6106 | return QualType(); |
| 6107 | |
| 6108 | QualType Result = TL.getType(); |
| 6109 | if (getDerived().AlwaysRebuild() || |
| 6110 | Inner != TL.getInnerLoc().getType()) { |
| 6111 | Result = getDerived().RebuildParenType(Inner); |
| 6112 | if (Result.isNull()) |
| 6113 | return QualType(); |
| 6114 | } |
| 6115 | |
| 6116 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 6117 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6118 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6119 | return Result; |
| 6120 | } |
| 6121 | |
| 6122 | template<typename Derived> |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6123 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6124 | TypeLocBuilder &TLB, DependentNameTypeLoc TL) { |
| 6125 | return TransformDependentNameType(TLB, TL, false); |
| 6126 | } |
| 6127 | |
| 6128 | template<typename Derived> |
| 6129 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6130 | TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6131 | const DependentNameType *T = TL.getTypePtr(); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6132 | |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6133 | NestedNameSpecifierLoc QualifierLoc |
| 6134 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6135 | if (!QualifierLoc) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6136 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6137 | |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6138 | QualType Result |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6139 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6140 | TL.getElaboratedKeywordLoc(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6141 | QualifierLoc, |
| 6142 | T->getIdentifier(), |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6143 | TL.getNameLoc(), |
| 6144 | DeducedTSTContext); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6145 | if (Result.isNull()) |
| 6146 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6147 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6148 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 6149 | QualType NamedT = ElabT->getNamedType(); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6150 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 6151 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6152 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6153 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6154 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6155 | } else { |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6156 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6157 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6158 | NewTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6159 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6160 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6161 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6162 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6163 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6164 | template<typename Derived> |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6165 | QualType TreeTransform<Derived>:: |
| 6166 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6167 | DependentTemplateSpecializationTypeLoc TL) { |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6168 | NestedNameSpecifierLoc QualifierLoc; |
| 6169 | if (TL.getQualifierLoc()) { |
| 6170 | QualifierLoc |
| 6171 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6172 | if (!QualifierLoc) |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6173 | return QualType(); |
| 6174 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6175 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6176 | return getDerived() |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6177 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | template<typename Derived> |
| 6181 | QualType TreeTransform<Derived>:: |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6182 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 6183 | DependentTemplateSpecializationTypeLoc TL, |
| 6184 | NestedNameSpecifierLoc QualifierLoc) { |
| 6185 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6186 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6187 | TemplateArgumentListInfo NewTemplateArgs; |
| 6188 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6189 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6190 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6191 | typedef TemplateArgumentLocContainerIterator< |
| 6192 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 6193 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6194 | ArgIterator(TL, TL.getNumArgs()), |
| 6195 | NewTemplateArgs)) |
| 6196 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6197 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6198 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 6199 | T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), |
| 6200 | T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6201 | /*AllowInjectedClassName*/ false); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6202 | if (Result.isNull()) |
| 6203 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6204 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6205 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 6206 | QualType NamedT = ElabT->getNamedType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6207 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6208 | // Copy information relevant to the template specialization. |
| 6209 | TemplateSpecializationTypeLoc NamedTL |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6210 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6211 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6212 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6213 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6214 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6215 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6216 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6217 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6218 | // Copy information relevant to the elaborated type. |
| 6219 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6220 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6221 | NewTL.setQualifierLoc(QualifierLoc); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6222 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6223 | DependentTemplateSpecializationTypeLoc SpecTL |
| 6224 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6225 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6226 | SpecTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6227 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6228 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6229 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6230 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6231 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6232 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6233 | } else { |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6234 | TemplateSpecializationTypeLoc SpecTL |
| 6235 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6236 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6237 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6238 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6239 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6240 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6241 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6242 | } |
| 6243 | return Result; |
| 6244 | } |
| 6245 | |
| 6246 | template<typename Derived> |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6247 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 6248 | PackExpansionTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6249 | QualType Pattern |
| 6250 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6251 | if (Pattern.isNull()) |
| 6252 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6253 | |
| 6254 | QualType Result = TL.getType(); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6255 | if (getDerived().AlwaysRebuild() || |
| 6256 | Pattern != TL.getPatternLoc().getType()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6257 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6258 | TL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6259 | TL.getEllipsisLoc(), |
| 6260 | TL.getTypePtr()->getNumExpansions()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6261 | if (Result.isNull()) |
| 6262 | return QualType(); |
| 6263 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6264 | |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6265 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 6266 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 6267 | return Result; |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6268 | } |
| 6269 | |
| 6270 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6271 | QualType |
| 6272 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6273 | ObjCInterfaceTypeLoc TL) { |
| Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6274 | // ObjCInterfaceType is never dependent. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6275 | TLB.pushFullCopy(TL); |
| 6276 | return TL.getType(); |
| 6277 | } |
| 6278 | |
| 6279 | template<typename Derived> |
| 6280 | QualType |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6281 | TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, |
| 6282 | ObjCTypeParamTypeLoc TL) { |
| 6283 | const ObjCTypeParamType *T = TL.getTypePtr(); |
| 6284 | ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( |
| 6285 | getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); |
| 6286 | if (!OTP) |
| 6287 | return QualType(); |
| 6288 | |
| 6289 | QualType Result = TL.getType(); |
| 6290 | if (getDerived().AlwaysRebuild() || |
| 6291 | OTP != T->getDecl()) { |
| 6292 | Result = getDerived().RebuildObjCTypeParamType(OTP, |
| 6293 | TL.getProtocolLAngleLoc(), |
| 6294 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 6295 | TL.getNumProtocols()), |
| 6296 | TL.getProtocolLocs(), |
| 6297 | TL.getProtocolRAngleLoc()); |
| 6298 | if (Result.isNull()) |
| 6299 | return QualType(); |
| 6300 | } |
| 6301 | |
| 6302 | ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); |
| 6303 | if (TL.getNumProtocols()) { |
| 6304 | NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6305 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6306 | NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6307 | NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6308 | } |
| 6309 | return Result; |
| 6310 | } |
| 6311 | |
| 6312 | template<typename Derived> |
| 6313 | QualType |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6314 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6315 | ObjCObjectTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6316 | // Transform base type. |
| 6317 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 6318 | if (BaseType.isNull()) |
| 6319 | return QualType(); |
| 6320 | |
| 6321 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 6322 | |
| 6323 | // Transform type arguments. |
| 6324 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 6325 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 6326 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 6327 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 6328 | QualType TypeArg = TypeArgInfo->getType(); |
| 6329 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 6330 | AnyChanged = true; |
| 6331 | |
| 6332 | // We have a pack expansion. Instantiate it. |
| 6333 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 6334 | ->castAs<PackExpansionType>(); |
| 6335 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6336 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 6337 | Unexpanded); |
| 6338 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 6339 | |
| 6340 | // Determine whether the set of unexpanded parameter packs can |
| 6341 | // and should be expanded. |
| 6342 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 6343 | bool Expand = false; |
| 6344 | bool RetainExpansion = false; |
| 6345 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 6346 | if (getDerived().TryExpandParameterPacks( |
| 6347 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 6348 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 6349 | return QualType(); |
| 6350 | |
| 6351 | if (!Expand) { |
| 6352 | // We can't expand this pack expansion into separate arguments yet; |
| 6353 | // just substitute into the pattern and create a new pack expansion |
| 6354 | // type. |
| 6355 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 6356 | |
| 6357 | TypeLocBuilder TypeArgBuilder; |
| 6358 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6359 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6360 | PatternLoc); |
| 6361 | if (NewPatternType.isNull()) |
| 6362 | return QualType(); |
| 6363 | |
| 6364 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 6365 | NewPatternType, NumExpansions); |
| 6366 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 6367 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 6368 | NewTypeArgInfos.push_back( |
| 6369 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 6370 | continue; |
| 6371 | } |
| 6372 | |
| 6373 | // Substitute into the pack expansion pattern for each slice of the |
| 6374 | // pack. |
| 6375 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 6376 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 6377 | |
| 6378 | TypeLocBuilder TypeArgBuilder; |
| 6379 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 6380 | |
| 6381 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 6382 | PatternLoc); |
| 6383 | if (NewTypeArg.isNull()) |
| 6384 | return QualType(); |
| 6385 | |
| 6386 | NewTypeArgInfos.push_back( |
| 6387 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6388 | } |
| 6389 | |
| 6390 | continue; |
| 6391 | } |
| 6392 | |
| 6393 | TypeLocBuilder TypeArgBuilder; |
| 6394 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 6395 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 6396 | if (NewTypeArg.isNull()) |
| 6397 | return QualType(); |
| 6398 | |
| 6399 | // If nothing changed, just keep the old TypeSourceInfo. |
| 6400 | if (NewTypeArg == TypeArg) { |
| 6401 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 6402 | continue; |
| 6403 | } |
| 6404 | |
| 6405 | NewTypeArgInfos.push_back( |
| 6406 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6407 | AnyChanged = true; |
| 6408 | } |
| 6409 | |
| 6410 | QualType Result = TL.getType(); |
| 6411 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 6412 | // Rebuild the type. |
| 6413 | Result = getDerived().RebuildObjCObjectType( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6414 | BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, |
| 6415 | TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), |
| 6416 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 6417 | TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6418 | |
| 6419 | if (Result.isNull()) |
| 6420 | return QualType(); |
| 6421 | } |
| 6422 | |
| 6423 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6424 | NewT.setHasBaseTypeAsWritten(true); |
| 6425 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 6426 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 6427 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 6428 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 6429 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6430 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6431 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6432 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6433 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6434 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6435 | |
| 6436 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6437 | QualType |
| 6438 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6439 | ObjCObjectPointerTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6440 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 6441 | if (PointeeType.isNull()) |
| 6442 | return QualType(); |
| 6443 | |
| 6444 | QualType Result = TL.getType(); |
| 6445 | if (getDerived().AlwaysRebuild() || |
| 6446 | PointeeType != TL.getPointeeLoc().getType()) { |
| 6447 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 6448 | TL.getStarLoc()); |
| 6449 | if (Result.isNull()) |
| 6450 | return QualType(); |
| 6451 | } |
| 6452 | |
| 6453 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 6454 | NewT.setStarLoc(TL.getStarLoc()); |
| 6455 | return Result; |
| Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 6456 | } |
| 6457 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6458 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6459 | // Statement transformation |
| 6460 | //===----------------------------------------------------------------------===// |
| 6461 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6462 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6463 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6464 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6468 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6469 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 6470 | return getDerived().TransformCompoundStmt(S, false); |
| 6471 | } |
| 6472 | |
| 6473 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6474 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6475 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6476 | bool IsStmtExpr) { |
| Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 6477 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6478 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6479 | bool SubStmtInvalid = false; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6480 | bool SubStmtChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6481 | SmallVector<Stmt*, 8> Statements; |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6482 | for (auto *B : S->body()) { |
| 6483 | StmtResult Result = getDerived().TransformStmt(B); |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6484 | if (Result.isInvalid()) { |
| 6485 | // Immediately fail if this was a DeclStmt, since it's very |
| 6486 | // likely that this will cause problems for future statements. |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6487 | if (isa<DeclStmt>(B)) |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6488 | return StmtError(); |
| 6489 | |
| 6490 | // Otherwise, just keep processing substatements and fail later. |
| 6491 | SubStmtInvalid = true; |
| 6492 | continue; |
| 6493 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6494 | |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6495 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6496 | Statements.push_back(Result.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6497 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6498 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6499 | if (SubStmtInvalid) |
| 6500 | return StmtError(); |
| 6501 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6502 | if (!getDerived().AlwaysRebuild() && |
| 6503 | !SubStmtChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6504 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6505 | |
| 6506 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6507 | Statements, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6508 | S->getRBracLoc(), |
| 6509 | IsStmtExpr); |
| 6510 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6511 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6512 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6513 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6514 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6515 | ExprResult LHS, RHS; |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6516 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 6517 | EnterExpressionEvaluationContext Unevaluated( |
| 6518 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6519 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6520 | // Transform the left-hand case value. |
| 6521 | LHS = getDerived().TransformExpr(S->getLHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6522 | LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6523 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6524 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6525 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6526 | // Transform the right-hand case value (for the GNU case-range extension). |
| 6527 | RHS = getDerived().TransformExpr(S->getRHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6528 | RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6529 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6530 | return StmtError(); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6531 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6532 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6533 | // Build the case statement. |
| 6534 | // Case statements are always rebuilt so that they will attached to their |
| 6535 | // transformed switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6536 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6537 | LHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6538 | S->getEllipsisLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6539 | RHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6540 | S->getColonLoc()); |
| 6541 | if (Case.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6542 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6543 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6544 | // Transform the statement following the case |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6545 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6546 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6547 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6548 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6549 | // Attach the body to the case statement |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6550 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6551 | } |
| 6552 | |
| 6553 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6554 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6555 | TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6556 | // Transform the statement following the default case |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6557 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6558 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6559 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6560 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6561 | // Default statements are always rebuilt |
| 6562 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6563 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6564 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6565 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6566 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6567 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6568 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6569 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6570 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6571 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6572 | |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6573 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 6574 | S->getDecl()); |
| 6575 | if (!LD) |
| 6576 | return StmtError(); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6577 | |
| 6578 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6579 | // FIXME: Pass the real colon location in. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 6580 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6581 | cast<LabelDecl>(LD), SourceLocation(), |
| 6582 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6583 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6584 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6585 | template <typename Derived> |
| 6586 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 6587 | if (!R) |
| 6588 | return R; |
| 6589 | |
| 6590 | switch (R->getKind()) { |
| 6591 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 6592 | #define ATTR(X) |
| 6593 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 6594 | case attr::X: \ |
| 6595 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 6596 | #include "clang/Basic/AttrList.inc" |
| 6597 | default: |
| 6598 | return R; |
| 6599 | } |
| 6600 | } |
| 6601 | |
| 6602 | template <typename Derived> |
| 6603 | StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { |
| 6604 | bool AttrsChanged = false; |
| 6605 | SmallVector<const Attr *, 1> Attrs; |
| 6606 | |
| 6607 | // Visit attributes and keep track if any are transformed. |
| 6608 | for (const auto *I : S->getAttrs()) { |
| 6609 | const Attr *R = getDerived().TransformAttr(I); |
| 6610 | AttrsChanged |= (I != R); |
| 6611 | Attrs.push_back(R); |
| 6612 | } |
| 6613 | |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6614 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); |
| 6615 | if (SubStmt.isInvalid()) |
| 6616 | return StmtError(); |
| 6617 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6618 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6619 | return S; |
| 6620 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6621 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6622 | SubStmt.get()); |
| 6623 | } |
| 6624 | |
| 6625 | template<typename Derived> |
| 6626 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6627 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6628 | // Transform the initialization statement |
| 6629 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6630 | if (Init.isInvalid()) |
| 6631 | return StmtError(); |
| 6632 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6633 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6634 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6635 | S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6636 | S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 6637 | : Sema::ConditionKind::Boolean); |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6638 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6639 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6640 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6641 | // If this is a constexpr if, determine which arm we should instantiate. |
| 6642 | llvm::Optional<bool> ConstexprConditionValue; |
| 6643 | if (S->isConstexpr()) |
| 6644 | ConstexprConditionValue = Cond.getKnownValue(); |
| 6645 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6646 | // Transform the "then" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6647 | StmtResult Then; |
| 6648 | if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 6649 | Then = getDerived().TransformStmt(S->getThen()); |
| 6650 | if (Then.isInvalid()) |
| 6651 | return StmtError(); |
| 6652 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6653 | Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6654 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6655 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6656 | // Transform the "else" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6657 | StmtResult Else; |
| 6658 | if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 6659 | Else = getDerived().TransformStmt(S->getElse()); |
| 6660 | if (Else.isInvalid()) |
| 6661 | return StmtError(); |
| 6662 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6663 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6664 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6665 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6666 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6667 | Then.get() == S->getThen() && |
| 6668 | Else.get() == S->getElse()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6669 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6670 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6671 | return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond, |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6672 | Init.get(), Then.get(), S->getElseLoc(), |
| 6673 | Else.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6677 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6678 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6679 | // Transform the initialization statement |
| 6680 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6681 | if (Init.isInvalid()) |
| 6682 | return StmtError(); |
| 6683 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6684 | // Transform the condition. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6685 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6686 | S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 6687 | Sema::ConditionKind::Switch); |
| 6688 | if (Cond.isInvalid()) |
| 6689 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6690 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6691 | // Rebuild the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6692 | StmtResult Switch |
| Volodymyr Sapsai | ddf524c | 2017-09-21 17:58:27 +0000 | [diff] [blame] | 6693 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6694 | if (Switch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6695 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6696 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6697 | // Transform the body of the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6698 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6699 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6700 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6701 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6702 | // Complete the switch statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6703 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6704 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6705 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6706 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6707 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6708 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6709 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6710 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6711 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6712 | S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 6713 | Sema::ConditionKind::Boolean); |
| 6714 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6715 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6716 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6717 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6718 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6719 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6720 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6721 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6722 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6723 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6724 | Body.get() == S->getBody()) |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6725 | return Owned(S); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6726 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6727 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6728 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6729 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6730 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6731 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6732 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6733 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6734 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6735 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6736 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6737 | |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6738 | // Transform the condition |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6739 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6740 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6741 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6742 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6743 | if (!getDerived().AlwaysRebuild() && |
| 6744 | Cond.get() == S->getCond() && |
| 6745 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6746 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6747 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6748 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6749 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6750 | S->getRParenLoc()); |
| 6751 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6752 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6753 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6754 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6755 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6756 | // Transform the initialization statement |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6757 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6758 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6759 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6760 | |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6761 | // In OpenMP loop region loop control variable must be captured and be |
| 6762 | // private. Perform analysis of first part (if any). |
| 6763 | if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 6764 | getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); |
| 6765 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6766 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6767 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6768 | S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 6769 | Sema::ConditionKind::Boolean); |
| 6770 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6771 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6772 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6773 | // Transform the increment |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6774 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6775 | if (Inc.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6776 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6777 | |
| Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6778 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6779 | if (S->getInc() && !FullInc.get()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6780 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6781 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6782 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6783 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6784 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6785 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6786 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6787 | if (!getDerived().AlwaysRebuild() && |
| 6788 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6789 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6790 | Inc.get() == S->getInc() && |
| 6791 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6792 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6793 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6794 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6795 | Init.get(), Cond, FullInc, |
| 6796 | S->getRParenLoc(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6800 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6801 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6802 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6803 | S->getLabel()); |
| 6804 | if (!LD) |
| 6805 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6806 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6807 | // Goto statements must always be rebuilt, to resolve the label. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6808 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6809 | cast<LabelDecl>(LD)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6813 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6814 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6815 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6816 | if (Target.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6817 | return StmtError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6818 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6819 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6820 | if (!getDerived().AlwaysRebuild() && |
| 6821 | Target.get() == S->getTarget()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6822 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6823 | |
| 6824 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6825 | Target.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6829 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6830 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6831 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6832 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6833 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6834 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6835 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6836 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6837 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6838 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6839 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6840 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6841 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6842 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
| Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 6843 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 6844 | /*NotCopyInit*/false); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6845 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6846 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6847 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6848 | // FIXME: We always rebuild the return statement because there is no way |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6849 | // to tell whether the return type of the function has changed. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6850 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6851 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6852 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6853 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6854 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6855 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6856 | bool DeclChanged = false; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6857 | SmallVector<Decl *, 4> Decls; |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6858 | for (auto *D : S->decls()) { |
| 6859 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6860 | if (!Transformed) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6861 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6862 | |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 6863 | if (Transformed != D) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6864 | DeclChanged = true; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6865 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6866 | Decls.push_back(Transformed); |
| 6867 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6868 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6869 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6870 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6871 | |
| Stephen Kelly | a6e4358 | 2018-08-09 21:05:56 +0000 | [diff] [blame] | 6872 | return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6873 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6874 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6875 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6876 | StmtResult |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6877 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6878 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6879 | SmallVector<Expr*, 8> Constraints; |
| 6880 | SmallVector<Expr*, 8> Exprs; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6881 | SmallVector<IdentifierInfo *, 4> Names; |
| Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 6882 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6883 | ExprResult AsmString; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6884 | SmallVector<Expr*, 8> Clobbers; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6885 | |
| 6886 | bool ExprsChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6887 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6888 | // Go through the outputs. |
| 6889 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6890 | Names.push_back(S->getOutputIdentifier(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6891 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6892 | // No need to transform the constraint literal. |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6893 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6894 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6895 | // Transform the output expr. |
| 6896 | Expr *OutputExpr = S->getOutputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6897 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6898 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6899 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6900 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6901 | ExprsChanged |= Result.get() != OutputExpr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6902 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6903 | Exprs.push_back(Result.get()); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6904 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6905 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6906 | // Go through the inputs. |
| 6907 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 6908 | Names.push_back(S->getInputIdentifier(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6909 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6910 | // No need to transform the constraint literal. |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 6911 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6912 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6913 | // Transform the input expr. |
| 6914 | Expr *InputExpr = S->getInputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6915 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6916 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6917 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6918 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6919 | ExprsChanged |= Result.get() != InputExpr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6920 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6921 | Exprs.push_back(Result.get()); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6922 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6923 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6924 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6925 | return S; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6926 | |
| 6927 | // Go through the clobbers. |
| 6928 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 6929 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 6930 | |
| 6931 | // No need to transform the asm string literal. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6932 | AsmString = S->getAsmString(); |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 6933 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 6934 | S->isVolatile(), S->getNumOutputs(), |
| 6935 | S->getNumInputs(), Names.data(), |
| 6936 | Constraints, Exprs, AsmString.get(), |
| 6937 | Clobbers, S->getRParenLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6938 | } |
| 6939 | |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6940 | template<typename Derived> |
| 6941 | StmtResult |
| 6942 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 6943 | ArrayRef<Token> AsmToks = |
| 6944 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
| Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 6945 | |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6946 | bool HadError = false, HadChange = false; |
| 6947 | |
| 6948 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 6949 | SmallVector<Expr*, 8> TransformedExprs; |
| 6950 | TransformedExprs.reserve(SrcExprs.size()); |
| 6951 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 6952 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 6953 | if (!Result.isUsable()) { |
| 6954 | HadError = true; |
| 6955 | } else { |
| 6956 | HadChange |= (Result.get() != SrcExprs[i]); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6957 | TransformedExprs.push_back(Result.get()); |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | if (HadError) return StmtError(); |
| 6962 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 6963 | return Owned(S); |
| 6964 | |
| Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 6965 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 6966 | AsmToks, S->getAsmString(), |
| 6967 | S->getNumOutputs(), S->getNumInputs(), |
| 6968 | S->getAllConstraints(), S->getClobbers(), |
| 6969 | TransformedExprs, S->getEndLoc()); |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 6970 | } |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6971 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 6972 | // C++ Coroutines TS |
| 6973 | |
| 6974 | template<typename Derived> |
| 6975 | StmtResult |
| 6976 | TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 6977 | auto *ScopeInfo = SemaRef.getCurFunction(); |
| 6978 | auto *FD = cast<FunctionDecl>(SemaRef.CurContext); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 6979 | assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 6980 | ScopeInfo->NeedsCoroutineSuspends && |
| 6981 | ScopeInfo->CoroutineSuspends.first == nullptr && |
| 6982 | ScopeInfo->CoroutineSuspends.second == nullptr && |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 6983 | "expected clean scope info"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 6984 | |
| 6985 | // Set that we have (possibly-invalid) suspend points before we do anything |
| 6986 | // that may fail. |
| 6987 | ScopeInfo->setNeedsCoroutineSuspends(false); |
| 6988 | |
| 6989 | // The new CoroutinePromise object needs to be built and put into the current |
| 6990 | // FunctionScopeInfo before any transformations or rebuilding occurs. |
| Brian Gesiak | 61f4ac9 | 2018-01-24 22:15:42 +0000 | [diff] [blame] | 6991 | if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) |
| 6992 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 6993 | auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); |
| 6994 | if (!Promise) |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 6995 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 6996 | getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise); |
| 6997 | ScopeInfo->CoroutinePromise = Promise; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 6998 | |
| 6999 | // Transform the implicit coroutine statements we built during the initial |
| 7000 | // parse. |
| 7001 | StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); |
| 7002 | if (InitSuspend.isInvalid()) |
| 7003 | return StmtError(); |
| 7004 | StmtResult FinalSuspend = |
| 7005 | getDerived().TransformStmt(S->getFinalSuspendStmt()); |
| 7006 | if (FinalSuspend.isInvalid()) |
| 7007 | return StmtError(); |
| 7008 | ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); |
| 7009 | assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7010 | |
| 7011 | StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); |
| 7012 | if (BodyRes.isInvalid()) |
| 7013 | return StmtError(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7014 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7015 | CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); |
| 7016 | if (Builder.isInvalid()) |
| 7017 | return StmtError(); |
| 7018 | |
| 7019 | Expr *ReturnObject = S->getReturnValueInit(); |
| 7020 | assert(ReturnObject && "the return object is expected to be valid"); |
| 7021 | ExprResult Res = getDerived().TransformInitializer(ReturnObject, |
| 7022 | /*NoCopyInit*/ false); |
| 7023 | if (Res.isInvalid()) |
| 7024 | return StmtError(); |
| 7025 | Builder.ReturnValue = Res.get(); |
| 7026 | |
| 7027 | if (S->hasDependentPromiseType()) { |
| 7028 | assert(!Promise->getType()->isDependentType() && |
| 7029 | "the promise type must no longer be dependent"); |
| 7030 | assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && |
| 7031 | !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && |
| 7032 | "these nodes should not have been built yet"); |
| 7033 | if (!Builder.buildDependentStatements()) |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7034 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7035 | } else { |
| 7036 | if (auto *OnFallthrough = S->getFallthroughHandler()) { |
| 7037 | StmtResult Res = getDerived().TransformStmt(OnFallthrough); |
| 7038 | if (Res.isInvalid()) |
| 7039 | return StmtError(); |
| 7040 | Builder.OnFallthrough = Res.get(); |
| 7041 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7042 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7043 | if (auto *OnException = S->getExceptionHandler()) { |
| 7044 | StmtResult Res = getDerived().TransformStmt(OnException); |
| 7045 | if (Res.isInvalid()) |
| 7046 | return StmtError(); |
| 7047 | Builder.OnException = Res.get(); |
| 7048 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7049 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7050 | if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { |
| 7051 | StmtResult Res = getDerived().TransformStmt(OnAllocFailure); |
| 7052 | if (Res.isInvalid()) |
| 7053 | return StmtError(); |
| 7054 | Builder.ReturnStmtOnAllocFailure = Res.get(); |
| 7055 | } |
| 7056 | |
| 7057 | // Transform any additional statements we may have already built |
| 7058 | assert(S->getAllocate() && S->getDeallocate() && |
| 7059 | "allocation and deallocation calls must already be built"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7060 | ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); |
| 7061 | if (AllocRes.isInvalid()) |
| 7062 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7063 | Builder.Allocate = AllocRes.get(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7064 | |
| 7065 | ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); |
| 7066 | if (DeallocRes.isInvalid()) |
| 7067 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7068 | Builder.Deallocate = DeallocRes.get(); |
| Gor Nishanov | afff89e | 2017-05-24 15:44:57 +0000 | [diff] [blame] | 7069 | |
| 7070 | assert(S->getResultDecl() && "ResultDecl must already be built"); |
| 7071 | StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl()); |
| 7072 | if (ResultDecl.isInvalid()) |
| 7073 | return StmtError(); |
| 7074 | Builder.ResultDecl = ResultDecl.get(); |
| 7075 | |
| 7076 | if (auto *ReturnStmt = S->getReturnStmt()) { |
| 7077 | StmtResult Res = getDerived().TransformStmt(ReturnStmt); |
| 7078 | if (Res.isInvalid()) |
| 7079 | return StmtError(); |
| 7080 | Builder.ReturnStmt = Res.get(); |
| 7081 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7082 | } |
| 7083 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7084 | return getDerived().RebuildCoroutineBodyStmt(Builder); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | template<typename Derived> |
| 7088 | StmtResult |
| 7089 | TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 7090 | ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 7091 | /*NotCopyInit*/false); |
| 7092 | if (Result.isInvalid()) |
| 7093 | return StmtError(); |
| 7094 | |
| 7095 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7096 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7097 | return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), |
| 7098 | S->isImplicit()); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7099 | } |
| 7100 | |
| 7101 | template<typename Derived> |
| 7102 | ExprResult |
| 7103 | TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 7104 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7105 | /*NotCopyInit*/false); |
| 7106 | if (Result.isInvalid()) |
| 7107 | return ExprError(); |
| 7108 | |
| 7109 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7110 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7111 | return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(), |
| 7112 | E->isImplicit()); |
| 7113 | } |
| 7114 | |
| 7115 | template <typename Derived> |
| 7116 | ExprResult |
| 7117 | TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { |
| 7118 | ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), |
| 7119 | /*NotCopyInit*/ false); |
| 7120 | if (OperandResult.isInvalid()) |
| 7121 | return ExprError(); |
| 7122 | |
| 7123 | ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( |
| 7124 | E->getOperatorCoawaitLookup()); |
| 7125 | |
| 7126 | if (LookupResult.isInvalid()) |
| 7127 | return ExprError(); |
| 7128 | |
| 7129 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7130 | // context or if the promise type has changed. |
| 7131 | return getDerived().RebuildDependentCoawaitExpr( |
| 7132 | E->getKeywordLoc(), OperandResult.get(), |
| 7133 | cast<UnresolvedLookupExpr>(LookupResult.get())); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | template<typename Derived> |
| 7137 | ExprResult |
| 7138 | TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 7139 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7140 | /*NotCopyInit*/false); |
| 7141 | if (Result.isInvalid()) |
| 7142 | return ExprError(); |
| 7143 | |
| 7144 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7145 | // context or if the promise type has changed. |
| 7146 | return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 7147 | } |
| 7148 | |
| 7149 | // Objective-C Statements. |
| 7150 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7151 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7152 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7153 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7154 | // Transform the body of the @try. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7155 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7156 | if (TryBody.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7157 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7158 | |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7159 | // Transform the @catch statements (if present). |
| 7160 | bool AnyCatchChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7161 | SmallVector<Stmt*, 8> CatchStmts; |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7162 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7163 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7164 | if (Catch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7165 | return StmtError(); |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7166 | if (Catch.get() != S->getCatchStmt(I)) |
| 7167 | AnyCatchChanged = true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7168 | CatchStmts.push_back(Catch.get()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7169 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7170 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7171 | // Transform the @finally statement (if present). |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7172 | StmtResult Finally; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7173 | if (S->getFinallyStmt()) { |
| 7174 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 7175 | if (Finally.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7176 | return StmtError(); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | // If nothing changed, just retain this statement. |
| 7180 | if (!getDerived().AlwaysRebuild() && |
| 7181 | TryBody.get() == S->getTryBody() && |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7182 | !AnyCatchChanged && |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7183 | Finally.get() == S->getFinallyStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7184 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7185 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7186 | // Build a new statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7187 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7188 | CatchStmts, Finally.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7189 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7190 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7191 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7192 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7193 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7194 | // Transform the @catch parameter, if there is one. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7195 | VarDecl *Var = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7196 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7197 | TypeSourceInfo *TSInfo = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7198 | if (FromVar->getTypeSourceInfo()) { |
| 7199 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 7200 | if (!TSInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7201 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7202 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7203 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7204 | QualType T; |
| 7205 | if (TSInfo) |
| 7206 | T = TSInfo->getType(); |
| 7207 | else { |
| 7208 | T = getDerived().TransformType(FromVar->getType()); |
| 7209 | if (T.isNull()) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7210 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7211 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7212 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7213 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 7214 | if (!Var) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7215 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7216 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7217 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7218 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7219 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7220 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7221 | |
| 7222 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7223 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7224 | Var, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7225 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7226 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7227 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7228 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7229 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7230 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7231 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7232 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7233 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7234 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7235 | // If nothing changed, just retain this statement. |
| 7236 | if (!getDerived().AlwaysRebuild() && |
| 7237 | Body.get() == S->getFinallyBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7238 | return S; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7239 | |
| 7240 | // Build a new statement. |
| 7241 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7242 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7243 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7244 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7245 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7246 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7247 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7248 | ExprResult Operand; |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7249 | if (S->getThrowExpr()) { |
| 7250 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 7251 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7252 | return StmtError(); |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7253 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7254 | |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7255 | if (!getDerived().AlwaysRebuild() && |
| 7256 | Operand.get() == S->getThrowExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7257 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7258 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7259 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7260 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7261 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7262 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7263 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7264 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7265 | ObjCAtSynchronizedStmt *S) { |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7266 | // Transform the object we are locking. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7267 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7268 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7269 | return StmtError(); |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 7270 | Object = |
| 7271 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 7272 | Object.get()); |
| 7273 | if (Object.isInvalid()) |
| 7274 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7275 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7276 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7277 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7278 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7279 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7280 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7281 | // If nothing change, just retain the current statement. |
| 7282 | if (!getDerived().AlwaysRebuild() && |
| 7283 | Object.get() == S->getSynchExpr() && |
| 7284 | Body.get() == S->getSynchBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7285 | return S; |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7286 | |
| 7287 | // Build a new statement. |
| 7288 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7289 | Object.get(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7290 | } |
| 7291 | |
| 7292 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7293 | StmtResult |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7294 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 7295 | ObjCAutoreleasePoolStmt *S) { |
| 7296 | // Transform the body. |
| 7297 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 7298 | if (Body.isInvalid()) |
| 7299 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7300 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7301 | // If nothing changed, just retain this statement. |
| 7302 | if (!getDerived().AlwaysRebuild() && |
| 7303 | Body.get() == S->getSubStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7304 | return S; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7305 | |
| 7306 | // Build a new statement. |
| 7307 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 7308 | S->getAtLoc(), Body.get()); |
| 7309 | } |
| 7310 | |
| 7311 | template<typename Derived> |
| 7312 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7313 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7314 | ObjCForCollectionStmt *S) { |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7315 | // Transform the element statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7316 | StmtResult Element = getDerived().TransformStmt(S->getElement()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7317 | if (Element.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7318 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7319 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7320 | // Transform the collection expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7321 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7322 | if (Collection.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7323 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7324 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7325 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7326 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7327 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7328 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7329 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7330 | // If nothing changed, just retain this statement. |
| 7331 | if (!getDerived().AlwaysRebuild() && |
| 7332 | Element.get() == S->getElement() && |
| 7333 | Collection.get() == S->getCollection() && |
| 7334 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7335 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7336 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7337 | // Build a new statement. |
| 7338 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7339 | Element.get(), |
| 7340 | Collection.get(), |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7341 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7342 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7343 | } |
| 7344 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7345 | template <typename Derived> |
| 7346 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7347 | // Transform the exception declaration, if any. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7348 | VarDecl *Var = nullptr; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7349 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 7350 | TypeSourceInfo *T = |
| 7351 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
| Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 7352 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7353 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7354 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7355 | Var = getDerived().RebuildExceptionDecl( |
| 7356 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 7357 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7358 | if (!Var || Var->isInvalidDecl()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7359 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7360 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7361 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7362 | // Transform the actual exception handler. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7363 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7364 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7365 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7366 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7367 | if (!getDerived().AlwaysRebuild() && !Var && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7368 | Handler.get() == S->getHandlerBlock()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7369 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7370 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7371 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7372 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7373 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7374 | template <typename Derived> |
| 7375 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7376 | // Transform the try block itself. |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7377 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7378 | if (TryBlock.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7379 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7380 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7381 | // Transform the handlers. |
| 7382 | bool HandlerChanged = false; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7383 | SmallVector<Stmt *, 8> Handlers; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7384 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7385 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7386 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7387 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7388 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7389 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7390 | Handlers.push_back(Handler.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7391 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7392 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7393 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7394 | !HandlerChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7395 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7396 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7397 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7398 | Handlers); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7399 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7400 | |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7401 | template<typename Derived> |
| 7402 | StmtResult |
| 7403 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 7404 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 7405 | if (Range.isInvalid()) |
| 7406 | return StmtError(); |
| 7407 | |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7408 | StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 7409 | if (Begin.isInvalid()) |
| 7410 | return StmtError(); |
| 7411 | StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 7412 | if (End.isInvalid()) |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7413 | return StmtError(); |
| 7414 | |
| 7415 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 7416 | if (Cond.isInvalid()) |
| 7417 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7418 | if (Cond.get()) |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7419 | Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7420 | if (Cond.isInvalid()) |
| 7421 | return StmtError(); |
| 7422 | if (Cond.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7423 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7424 | |
| 7425 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 7426 | if (Inc.isInvalid()) |
| 7427 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7428 | if (Inc.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7429 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7430 | |
| 7431 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 7432 | if (LoopVar.isInvalid()) |
| 7433 | return StmtError(); |
| 7434 | |
| 7435 | StmtResult NewStmt = S; |
| 7436 | if (getDerived().AlwaysRebuild() || |
| 7437 | Range.get() != S->getRangeStmt() || |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7438 | Begin.get() != S->getBeginStmt() || |
| 7439 | End.get() != S->getEndStmt() || |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7440 | Cond.get() != S->getCond() || |
| 7441 | Inc.get() != S->getInc() || |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7442 | LoopVar.get() != S->getLoopVarStmt()) { |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7443 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7444 | S->getCoawaitLoc(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7445 | S->getColonLoc(), Range.get(), |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7446 | Begin.get(), End.get(), |
| 7447 | Cond.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7448 | Inc.get(), LoopVar.get(), |
| 7449 | S->getRParenLoc()); |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7450 | if (NewStmt.isInvalid()) |
| 7451 | return StmtError(); |
| 7452 | } |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7453 | |
| 7454 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7455 | if (Body.isInvalid()) |
| 7456 | return StmtError(); |
| 7457 | |
| 7458 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 7459 | // it now so we have a new statement to attach the body to. |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7460 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7461 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7462 | S->getCoawaitLoc(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7463 | S->getColonLoc(), Range.get(), |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7464 | Begin.get(), End.get(), |
| 7465 | Cond.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7466 | Inc.get(), LoopVar.get(), |
| 7467 | S->getRParenLoc()); |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7468 | if (NewStmt.isInvalid()) |
| 7469 | return StmtError(); |
| 7470 | } |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7471 | |
| 7472 | if (NewStmt.get() == S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7473 | return S; |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7474 | |
| 7475 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 7476 | } |
| 7477 | |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7478 | template<typename Derived> |
| 7479 | StmtResult |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7480 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 7481 | MSDependentExistsStmt *S) { |
| 7482 | // Transform the nested-name-specifier, if any. |
| 7483 | NestedNameSpecifierLoc QualifierLoc; |
| 7484 | if (S->getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7485 | QualifierLoc |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7486 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 7487 | if (!QualifierLoc) |
| 7488 | return StmtError(); |
| 7489 | } |
| 7490 | |
| 7491 | // Transform the declaration name. |
| 7492 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 7493 | if (NameInfo.getName()) { |
| 7494 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7495 | if (!NameInfo.getName()) |
| 7496 | return StmtError(); |
| 7497 | } |
| 7498 | |
| 7499 | // Check whether anything changed. |
| 7500 | if (!getDerived().AlwaysRebuild() && |
| 7501 | QualifierLoc == S->getQualifierLoc() && |
| 7502 | NameInfo.getName() == S->getNameInfo().getName()) |
| 7503 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7504 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7505 | // Determine whether this name exists, if we can. |
| 7506 | CXXScopeSpec SS; |
| 7507 | SS.Adopt(QualifierLoc); |
| 7508 | bool Dependent = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7509 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7510 | case Sema::IER_Exists: |
| 7511 | if (S->isIfExists()) |
| 7512 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7513 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7514 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 7515 | |
| 7516 | case Sema::IER_DoesNotExist: |
| 7517 | if (S->isIfNotExists()) |
| 7518 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7519 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7520 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7521 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7522 | case Sema::IER_Dependent: |
| 7523 | Dependent = true; |
| 7524 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7525 | |
| Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 7526 | case Sema::IER_Error: |
| 7527 | return StmtError(); |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7528 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7529 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7530 | // We need to continue with the instantiation, so do so now. |
| 7531 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 7532 | if (SubStmt.isInvalid()) |
| 7533 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7534 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7535 | // If we have resolved the name, just transform to the substatement. |
| 7536 | if (!Dependent) |
| 7537 | return SubStmt; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7538 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7539 | // The name is still dependent, so build a dependent expression again. |
| 7540 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 7541 | S->isIfExists(), |
| 7542 | QualifierLoc, |
| 7543 | NameInfo, |
| 7544 | SubStmt.get()); |
| 7545 | } |
| 7546 | |
| 7547 | template<typename Derived> |
| John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 7548 | ExprResult |
| 7549 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 7550 | NestedNameSpecifierLoc QualifierLoc; |
| 7551 | if (E->getQualifierLoc()) { |
| 7552 | QualifierLoc |
| 7553 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7554 | if (!QualifierLoc) |
| 7555 | return ExprError(); |
| 7556 | } |
| 7557 | |
| 7558 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 7559 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 7560 | if (!PD) |
| 7561 | return ExprError(); |
| 7562 | |
| 7563 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 7564 | if (Base.isInvalid()) |
| 7565 | return ExprError(); |
| 7566 | |
| 7567 | return new (SemaRef.getASTContext()) |
| 7568 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 7569 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 7570 | QualifierLoc, E->getMemberLoc()); |
| 7571 | } |
| 7572 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7573 | template <typename Derived> |
| Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 7574 | ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 7575 | MSPropertySubscriptExpr *E) { |
| 7576 | auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 7577 | if (BaseRes.isInvalid()) |
| 7578 | return ExprError(); |
| 7579 | auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 7580 | if (IdxRes.isInvalid()) |
| 7581 | return ExprError(); |
| 7582 | |
| 7583 | if (!getDerived().AlwaysRebuild() && |
| 7584 | BaseRes.get() == E->getBase() && |
| 7585 | IdxRes.get() == E->getIdx()) |
| 7586 | return E; |
| 7587 | |
| 7588 | return getDerived().RebuildArraySubscriptExpr( |
| 7589 | BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 7590 | } |
| 7591 | |
| 7592 | template <typename Derived> |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7593 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7594 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7595 | if (TryBlock.isInvalid()) |
| 7596 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7597 | |
| 7598 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7599 | if (Handler.isInvalid()) |
| 7600 | return StmtError(); |
| 7601 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7602 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 7603 | Handler.get() == S->getHandler()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7604 | return S; |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7605 | |
| Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 7606 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 7607 | TryBlock.get(), Handler.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7608 | } |
| 7609 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7610 | template <typename Derived> |
| 7611 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7612 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7613 | if (Block.isInvalid()) |
| 7614 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7615 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7616 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7617 | } |
| 7618 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7619 | template <typename Derived> |
| 7620 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7621 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7622 | if (FilterExpr.isInvalid()) |
| 7623 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7624 | |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7625 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7626 | if (Block.isInvalid()) |
| 7627 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7628 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7629 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 7630 | Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7631 | } |
| 7632 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7633 | template <typename Derived> |
| 7634 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 7635 | if (isa<SEHFinallyStmt>(Handler)) |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7636 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 7637 | else |
| 7638 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 7639 | } |
| 7640 | |
| Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 7641 | template<typename Derived> |
| 7642 | StmtResult |
| 7643 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 7644 | return S; |
| 7645 | } |
| 7646 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7647 | //===----------------------------------------------------------------------===// |
| 7648 | // OpenMP directive transformation |
| 7649 | //===----------------------------------------------------------------------===// |
| 7650 | template <typename Derived> |
| 7651 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 7652 | OMPExecutableDirective *D) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7653 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7654 | // Transform the clauses |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7655 | llvm::SmallVector<OMPClause *, 16> TClauses; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7656 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 7657 | TClauses.reserve(Clauses.size()); |
| 7658 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 7659 | I != E; ++I) { |
| 7660 | if (*I) { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7661 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7662 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7663 | getDerived().getSema().EndOpenMPClause(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7664 | if (Clause) |
| 7665 | TClauses.push_back(Clause); |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7666 | } else { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 7667 | TClauses.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7668 | } |
| 7669 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7670 | StmtResult AssociatedStmt; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 7671 | if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7672 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 7673 | /*CurScope=*/nullptr); |
| 7674 | StmtResult Body; |
| 7675 | { |
| 7676 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| Alexey Bataev | 475a744 | 2018-01-12 19:39:11 +0000 | [diff] [blame] | 7677 | Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt(); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 7678 | Body = getDerived().TransformStmt(CS); |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7679 | } |
| 7680 | AssociatedStmt = |
| 7681 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7682 | if (AssociatedStmt.isInvalid()) { |
| 7683 | return StmtError(); |
| 7684 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7685 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7686 | if (TClauses.size() != Clauses.size()) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7687 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7688 | } |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7689 | |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7690 | // Transform directive name for 'omp critical' directive. |
| 7691 | DeclarationNameInfo DirName; |
| 7692 | if (D->getDirectiveKind() == OMPD_critical) { |
| 7693 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 7694 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 7695 | } |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7696 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 7697 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 7698 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7699 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 7700 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7701 | } |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7702 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7703 | return getDerived().RebuildOMPExecutableDirective( |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7704 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7705 | AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7706 | } |
| 7707 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7708 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7709 | StmtResult |
| 7710 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 7711 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7712 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7713 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7714 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7715 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7716 | return Res; |
| 7717 | } |
| 7718 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7719 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7720 | StmtResult |
| 7721 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 7722 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7723 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7724 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7725 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7726 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7727 | return Res; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7728 | } |
| 7729 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7730 | template <typename Derived> |
| 7731 | StmtResult |
| 7732 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 7733 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7734 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7735 | D->getBeginLoc()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7736 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7737 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7738 | return Res; |
| 7739 | } |
| 7740 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7741 | template <typename Derived> |
| 7742 | StmtResult |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7743 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 7744 | DeclarationNameInfo DirName; |
| 7745 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7746 | D->getBeginLoc()); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7747 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7748 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7749 | return Res; |
| 7750 | } |
| 7751 | |
| 7752 | template <typename Derived> |
| 7753 | StmtResult |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7754 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 7755 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7756 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7757 | D->getBeginLoc()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7758 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7759 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7760 | return Res; |
| 7761 | } |
| 7762 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7763 | template <typename Derived> |
| 7764 | StmtResult |
| 7765 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 7766 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7767 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7768 | D->getBeginLoc()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7769 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7770 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7771 | return Res; |
| 7772 | } |
| 7773 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7774 | template <typename Derived> |
| 7775 | StmtResult |
| 7776 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 7777 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7778 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7779 | D->getBeginLoc()); |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7780 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7781 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7782 | return Res; |
| 7783 | } |
| 7784 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7785 | template <typename Derived> |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7786 | StmtResult |
| 7787 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 7788 | DeclarationNameInfo DirName; |
| 7789 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7790 | D->getBeginLoc()); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7791 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7792 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7793 | return Res; |
| 7794 | } |
| 7795 | |
| 7796 | template <typename Derived> |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7797 | StmtResult |
| 7798 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 7799 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7800 | OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7801 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7802 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7803 | return Res; |
| 7804 | } |
| 7805 | |
| 7806 | template <typename Derived> |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7807 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7808 | OMPParallelForDirective *D) { |
| 7809 | DeclarationNameInfo DirName; |
| 7810 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7811 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7812 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7813 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7814 | return Res; |
| 7815 | } |
| 7816 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7817 | template <typename Derived> |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7818 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 7819 | OMPParallelForSimdDirective *D) { |
| 7820 | DeclarationNameInfo DirName; |
| 7821 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7822 | nullptr, D->getBeginLoc()); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7823 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7824 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7825 | return Res; |
| 7826 | } |
| 7827 | |
| 7828 | template <typename Derived> |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7829 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 7830 | OMPParallelSectionsDirective *D) { |
| 7831 | DeclarationNameInfo DirName; |
| 7832 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7833 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7834 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7835 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7836 | return Res; |
| 7837 | } |
| 7838 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7839 | template <typename Derived> |
| 7840 | StmtResult |
| 7841 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 7842 | DeclarationNameInfo DirName; |
| 7843 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7844 | D->getBeginLoc()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7845 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7846 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7847 | return Res; |
| 7848 | } |
| 7849 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7850 | template <typename Derived> |
| 7851 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 7852 | OMPTaskyieldDirective *D) { |
| 7853 | DeclarationNameInfo DirName; |
| 7854 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7855 | D->getBeginLoc()); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7856 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7857 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7858 | return Res; |
| 7859 | } |
| 7860 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 7861 | template <typename Derived> |
| 7862 | StmtResult |
| 7863 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 7864 | DeclarationNameInfo DirName; |
| 7865 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7866 | D->getBeginLoc()); |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 7867 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7868 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7869 | return Res; |
| 7870 | } |
| 7871 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 7872 | template <typename Derived> |
| 7873 | StmtResult |
| 7874 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 7875 | DeclarationNameInfo DirName; |
| 7876 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7877 | D->getBeginLoc()); |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 7878 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7879 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7880 | return Res; |
| 7881 | } |
| 7882 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7883 | template <typename Derived> |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 7884 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 7885 | OMPTaskgroupDirective *D) { |
| 7886 | DeclarationNameInfo DirName; |
| 7887 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7888 | D->getBeginLoc()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 7889 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7890 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7891 | return Res; |
| 7892 | } |
| 7893 | |
| 7894 | template <typename Derived> |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7895 | StmtResult |
| 7896 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 7897 | DeclarationNameInfo DirName; |
| 7898 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7899 | D->getBeginLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7900 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7901 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7902 | return Res; |
| 7903 | } |
| 7904 | |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 7905 | template <typename Derived> |
| 7906 | StmtResult |
| 7907 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 7908 | DeclarationNameInfo DirName; |
| 7909 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7910 | D->getBeginLoc()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 7911 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7912 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7913 | return Res; |
| 7914 | } |
| 7915 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7916 | template <typename Derived> |
| 7917 | StmtResult |
| 7918 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 7919 | DeclarationNameInfo DirName; |
| 7920 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7921 | D->getBeginLoc()); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7922 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7923 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7924 | return Res; |
| 7925 | } |
| 7926 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7927 | template <typename Derived> |
| 7928 | StmtResult |
| 7929 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 7930 | DeclarationNameInfo DirName; |
| 7931 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7932 | D->getBeginLoc()); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7933 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7934 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7935 | return Res; |
| 7936 | } |
| 7937 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7938 | template <typename Derived> |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7939 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 7940 | OMPTargetDataDirective *D) { |
| 7941 | DeclarationNameInfo DirName; |
| 7942 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7943 | D->getBeginLoc()); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7944 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7945 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7946 | return Res; |
| 7947 | } |
| 7948 | |
| 7949 | template <typename Derived> |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7950 | StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 7951 | OMPTargetEnterDataDirective *D) { |
| 7952 | DeclarationNameInfo DirName; |
| 7953 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7954 | nullptr, D->getBeginLoc()); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7955 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7956 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7957 | return Res; |
| 7958 | } |
| 7959 | |
| 7960 | template <typename Derived> |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7961 | StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 7962 | OMPTargetExitDataDirective *D) { |
| 7963 | DeclarationNameInfo DirName; |
| 7964 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7965 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7966 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7967 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7968 | return Res; |
| 7969 | } |
| 7970 | |
| 7971 | template <typename Derived> |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7972 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 7973 | OMPTargetParallelDirective *D) { |
| 7974 | DeclarationNameInfo DirName; |
| 7975 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7976 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7977 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7978 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7979 | return Res; |
| 7980 | } |
| 7981 | |
| 7982 | template <typename Derived> |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7983 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 7984 | OMPTargetParallelForDirective *D) { |
| 7985 | DeclarationNameInfo DirName; |
| 7986 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7987 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7988 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7989 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7990 | return Res; |
| 7991 | } |
| 7992 | |
| 7993 | template <typename Derived> |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7994 | StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 7995 | OMPTargetUpdateDirective *D) { |
| 7996 | DeclarationNameInfo DirName; |
| 7997 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7998 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7999 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8000 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8001 | return Res; |
| 8002 | } |
| 8003 | |
| 8004 | template <typename Derived> |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8005 | StmtResult |
| 8006 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 8007 | DeclarationNameInfo DirName; |
| 8008 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8009 | D->getBeginLoc()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8010 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8011 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8012 | return Res; |
| 8013 | } |
| 8014 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8015 | template <typename Derived> |
| 8016 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 8017 | OMPCancellationPointDirective *D) { |
| 8018 | DeclarationNameInfo DirName; |
| 8019 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8020 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8021 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8022 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8023 | return Res; |
| 8024 | } |
| 8025 | |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8026 | template <typename Derived> |
| 8027 | StmtResult |
| 8028 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 8029 | DeclarationNameInfo DirName; |
| 8030 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8031 | D->getBeginLoc()); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8032 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8033 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8034 | return Res; |
| 8035 | } |
| 8036 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8037 | template <typename Derived> |
| 8038 | StmtResult |
| 8039 | TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 8040 | DeclarationNameInfo DirName; |
| 8041 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8042 | D->getBeginLoc()); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8043 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8044 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8045 | return Res; |
| 8046 | } |
| 8047 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8048 | template <typename Derived> |
| 8049 | StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 8050 | OMPTaskLoopSimdDirective *D) { |
| 8051 | DeclarationNameInfo DirName; |
| 8052 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8053 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8054 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8055 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8056 | return Res; |
| 8057 | } |
| 8058 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8059 | template <typename Derived> |
| 8060 | StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 8061 | OMPDistributeDirective *D) { |
| 8062 | DeclarationNameInfo DirName; |
| 8063 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8064 | D->getBeginLoc()); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8065 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8066 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8067 | return Res; |
| 8068 | } |
| 8069 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8070 | template <typename Derived> |
| 8071 | StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 8072 | OMPDistributeParallelForDirective *D) { |
| 8073 | DeclarationNameInfo DirName; |
| 8074 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8075 | OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8076 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8077 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8078 | return Res; |
| 8079 | } |
| 8080 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8081 | template <typename Derived> |
| 8082 | StmtResult |
| 8083 | TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 8084 | OMPDistributeParallelForSimdDirective *D) { |
| 8085 | DeclarationNameInfo DirName; |
| 8086 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8087 | OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8088 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8089 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8090 | return Res; |
| 8091 | } |
| 8092 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8093 | template <typename Derived> |
| 8094 | StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( |
| 8095 | OMPDistributeSimdDirective *D) { |
| 8096 | DeclarationNameInfo DirName; |
| 8097 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8098 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8099 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8100 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8101 | return Res; |
| 8102 | } |
| 8103 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8104 | template <typename Derived> |
| 8105 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( |
| 8106 | OMPTargetParallelForSimdDirective *D) { |
| 8107 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8108 | getDerived().getSema().StartOpenMPDSABlock( |
| 8109 | OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8110 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8111 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8112 | return Res; |
| 8113 | } |
| 8114 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8115 | template <typename Derived> |
| 8116 | StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( |
| 8117 | OMPTargetSimdDirective *D) { |
| 8118 | DeclarationNameInfo DirName; |
| 8119 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8120 | D->getBeginLoc()); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8121 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8122 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8123 | return Res; |
| 8124 | } |
| 8125 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8126 | template <typename Derived> |
| 8127 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( |
| 8128 | OMPTeamsDistributeDirective *D) { |
| 8129 | DeclarationNameInfo DirName; |
| 8130 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8131 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8132 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8133 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8134 | return Res; |
| 8135 | } |
| 8136 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8137 | template <typename Derived> |
| 8138 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( |
| 8139 | OMPTeamsDistributeSimdDirective *D) { |
| 8140 | DeclarationNameInfo DirName; |
| 8141 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8142 | OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8143 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8144 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8145 | return Res; |
| 8146 | } |
| 8147 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8148 | template <typename Derived> |
| 8149 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( |
| 8150 | OMPTeamsDistributeParallelForSimdDirective *D) { |
| 8151 | DeclarationNameInfo DirName; |
| 8152 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8153 | OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 8154 | D->getBeginLoc()); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8155 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8156 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8157 | return Res; |
| 8158 | } |
| 8159 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8160 | template <typename Derived> |
| 8161 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( |
| 8162 | OMPTeamsDistributeParallelForDirective *D) { |
| 8163 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8164 | getDerived().getSema().StartOpenMPDSABlock( |
| 8165 | OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8166 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8167 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8168 | return Res; |
| 8169 | } |
| 8170 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8171 | template <typename Derived> |
| 8172 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( |
| 8173 | OMPTargetTeamsDirective *D) { |
| 8174 | DeclarationNameInfo DirName; |
| 8175 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8176 | nullptr, D->getBeginLoc()); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8177 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8178 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8179 | return Res; |
| 8180 | } |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8181 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8182 | template <typename Derived> |
| 8183 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( |
| 8184 | OMPTargetTeamsDistributeDirective *D) { |
| 8185 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8186 | getDerived().getSema().StartOpenMPDSABlock( |
| 8187 | OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8188 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8189 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8190 | return Res; |
| 8191 | } |
| 8192 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8193 | template <typename Derived> |
| 8194 | StmtResult |
| 8195 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( |
| 8196 | OMPTargetTeamsDistributeParallelForDirective *D) { |
| 8197 | DeclarationNameInfo DirName; |
| 8198 | getDerived().getSema().StartOpenMPDSABlock( |
| 8199 | OMPD_target_teams_distribute_parallel_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8200 | D->getBeginLoc()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8201 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8202 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8203 | return Res; |
| 8204 | } |
| 8205 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8206 | template <typename Derived> |
| 8207 | StmtResult TreeTransform<Derived>:: |
| 8208 | TransformOMPTargetTeamsDistributeParallelForSimdDirective( |
| 8209 | OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 8210 | DeclarationNameInfo DirName; |
| 8211 | getDerived().getSema().StartOpenMPDSABlock( |
| 8212 | OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8213 | D->getBeginLoc()); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8214 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8215 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8216 | return Res; |
| 8217 | } |
| 8218 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8219 | template <typename Derived> |
| 8220 | StmtResult |
| 8221 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( |
| 8222 | OMPTargetTeamsDistributeSimdDirective *D) { |
| 8223 | DeclarationNameInfo DirName; |
| 8224 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8225 | OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8226 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8227 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8228 | return Res; |
| 8229 | } |
| 8230 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8231 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8232 | //===----------------------------------------------------------------------===// |
| 8233 | // OpenMP clause transformation |
| 8234 | //===----------------------------------------------------------------------===// |
| 8235 | template <typename Derived> |
| 8236 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 8237 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8238 | if (Cond.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8239 | return nullptr; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8240 | return getDerived().RebuildOMPIfClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8241 | C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8242 | C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8243 | } |
| 8244 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8245 | template <typename Derived> |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8246 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 8247 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8248 | if (Cond.isInvalid()) |
| 8249 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8250 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8251 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8252 | } |
| 8253 | |
| 8254 | template <typename Derived> |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8255 | OMPClause * |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8256 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 8257 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 8258 | if (NumThreads.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8259 | return nullptr; |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8260 | return getDerived().RebuildOMPNumThreadsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8261 | NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8262 | } |
| 8263 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8264 | template <typename Derived> |
| 8265 | OMPClause * |
| 8266 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 8267 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 8268 | if (E.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8269 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8270 | return getDerived().RebuildOMPSafelenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8271 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8272 | } |
| 8273 | |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8274 | template <typename Derived> |
| 8275 | OMPClause * |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8276 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 8277 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 8278 | if (E.isInvalid()) |
| 8279 | return nullptr; |
| 8280 | return getDerived().RebuildOMPSimdlenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8281 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | template <typename Derived> |
| 8285 | OMPClause * |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8286 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 8287 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 8288 | if (E.isInvalid()) |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 8289 | return nullptr; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8290 | return getDerived().RebuildOMPCollapseClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8291 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8292 | } |
| 8293 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8294 | template <typename Derived> |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8295 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8296 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8297 | return getDerived().RebuildOMPDefaultClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8298 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8299 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8300 | } |
| 8301 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8302 | template <typename Derived> |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8303 | OMPClause * |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8304 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8305 | return getDerived().RebuildOMPProcBindClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8306 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8307 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8308 | } |
| 8309 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8310 | template <typename Derived> |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8311 | OMPClause * |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8312 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 8313 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 8314 | if (E.isInvalid()) |
| 8315 | return nullptr; |
| 8316 | return getDerived().RebuildOMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8317 | C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8318 | C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8319 | C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8320 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8321 | } |
| 8322 | |
| 8323 | template <typename Derived> |
| 8324 | OMPClause * |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8325 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8326 | ExprResult E; |
| 8327 | if (auto *Num = C->getNumForLoops()) { |
| 8328 | E = getDerived().TransformExpr(Num); |
| 8329 | if (E.isInvalid()) |
| 8330 | return nullptr; |
| 8331 | } |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8332 | return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8333 | C->getLParenLoc(), E.get()); |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8334 | } |
| 8335 | |
| 8336 | template <typename Derived> |
| 8337 | OMPClause * |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8338 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 8339 | // No need to rebuild this clause, no template-dependent parameters. |
| 8340 | return C; |
| 8341 | } |
| 8342 | |
| 8343 | template <typename Derived> |
| 8344 | OMPClause * |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8345 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 8346 | // No need to rebuild this clause, no template-dependent parameters. |
| 8347 | return C; |
| 8348 | } |
| 8349 | |
| 8350 | template <typename Derived> |
| 8351 | OMPClause * |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8352 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 8353 | // No need to rebuild this clause, no template-dependent parameters. |
| 8354 | return C; |
| 8355 | } |
| 8356 | |
| 8357 | template <typename Derived> |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8358 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 8359 | // No need to rebuild this clause, no template-dependent parameters. |
| 8360 | return C; |
| 8361 | } |
| 8362 | |
| 8363 | template <typename Derived> |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8364 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 8365 | // No need to rebuild this clause, no template-dependent parameters. |
| 8366 | return C; |
| 8367 | } |
| 8368 | |
| 8369 | template <typename Derived> |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8370 | OMPClause * |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8371 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 8372 | // No need to rebuild this clause, no template-dependent parameters. |
| 8373 | return C; |
| 8374 | } |
| 8375 | |
| 8376 | template <typename Derived> |
| 8377 | OMPClause * |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8378 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 8379 | // No need to rebuild this clause, no template-dependent parameters. |
| 8380 | return C; |
| 8381 | } |
| 8382 | |
| 8383 | template <typename Derived> |
| 8384 | OMPClause * |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8385 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 8386 | // No need to rebuild this clause, no template-dependent parameters. |
| 8387 | return C; |
| 8388 | } |
| 8389 | |
| 8390 | template <typename Derived> |
| 8391 | OMPClause * |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8392 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 8393 | // No need to rebuild this clause, no template-dependent parameters. |
| 8394 | return C; |
| 8395 | } |
| 8396 | |
| 8397 | template <typename Derived> |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8398 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 8399 | // No need to rebuild this clause, no template-dependent parameters. |
| 8400 | return C; |
| 8401 | } |
| 8402 | |
| 8403 | template <typename Derived> |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8404 | OMPClause * |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8405 | TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 8406 | // No need to rebuild this clause, no template-dependent parameters. |
| 8407 | return C; |
| 8408 | } |
| 8409 | |
| 8410 | template <typename Derived> |
| 8411 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8412 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8413 | llvm::SmallVector<Expr *, 16> Vars; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8414 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8415 | for (auto *VE : C->varlists()) { |
| 8416 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8417 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8418 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8419 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8420 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8421 | return getDerived().RebuildOMPPrivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8422 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8423 | } |
| 8424 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8425 | template <typename Derived> |
| 8426 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 8427 | OMPFirstprivateClause *C) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8428 | llvm::SmallVector<Expr *, 16> Vars; |
| 8429 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8430 | for (auto *VE : C->varlists()) { |
| 8431 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8432 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8433 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8434 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8435 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8436 | return getDerived().RebuildOMPFirstprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8437 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8438 | } |
| 8439 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8440 | template <typename Derived> |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8441 | OMPClause * |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8442 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 8443 | llvm::SmallVector<Expr *, 16> Vars; |
| 8444 | Vars.reserve(C->varlist_size()); |
| 8445 | for (auto *VE : C->varlists()) { |
| 8446 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8447 | if (EVar.isInvalid()) |
| 8448 | return nullptr; |
| 8449 | Vars.push_back(EVar.get()); |
| 8450 | } |
| 8451 | return getDerived().RebuildOMPLastprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8452 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | template <typename Derived> |
| 8456 | OMPClause * |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8457 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 8458 | llvm::SmallVector<Expr *, 16> Vars; |
| 8459 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8460 | for (auto *VE : C->varlists()) { |
| 8461 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8462 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8463 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8464 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8465 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8466 | return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8467 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8468 | } |
| 8469 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8470 | template <typename Derived> |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8471 | OMPClause * |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8472 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 8473 | llvm::SmallVector<Expr *, 16> Vars; |
| 8474 | Vars.reserve(C->varlist_size()); |
| 8475 | for (auto *VE : C->varlists()) { |
| 8476 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8477 | if (EVar.isInvalid()) |
| 8478 | return nullptr; |
| 8479 | Vars.push_back(EVar.get()); |
| 8480 | } |
| 8481 | CXXScopeSpec ReductionIdScopeSpec; |
| 8482 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8483 | |
| 8484 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8485 | if (NameInfo.getName()) { |
| 8486 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8487 | if (!NameInfo.getName()) |
| 8488 | return nullptr; |
| 8489 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8490 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8491 | // The Scope boundary is a duplication of the previous decl. |
| 8492 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8493 | for (auto *E : C->reduction_ops()) { |
| 8494 | // Transform all the decls. |
| 8495 | if (E) { |
| 8496 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8497 | UnresolvedSet<8> Decls; |
| 8498 | for (auto *D : ULE->decls()) { |
| 8499 | NamedDecl *InstD = |
| 8500 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8501 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8502 | } |
| 8503 | UnresolvedReductions.push_back( |
| 8504 | UnresolvedLookupExpr::Create( |
| 8505 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8506 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), |
| 8507 | NameInfo, /*ADL=*/true, ULE->isOverloaded(), |
| 8508 | Decls.begin(), Decls.end())); |
| 8509 | } else |
| 8510 | UnresolvedReductions.push_back(nullptr); |
| 8511 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8512 | return getDerived().RebuildOMPReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8513 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8514 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8515 | } |
| 8516 | |
| 8517 | template <typename Derived> |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8518 | OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( |
| 8519 | OMPTaskReductionClause *C) { |
| 8520 | llvm::SmallVector<Expr *, 16> Vars; |
| 8521 | Vars.reserve(C->varlist_size()); |
| 8522 | for (auto *VE : C->varlists()) { |
| 8523 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8524 | if (EVar.isInvalid()) |
| 8525 | return nullptr; |
| 8526 | Vars.push_back(EVar.get()); |
| 8527 | } |
| 8528 | CXXScopeSpec ReductionIdScopeSpec; |
| 8529 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8530 | |
| 8531 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8532 | if (NameInfo.getName()) { |
| 8533 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8534 | if (!NameInfo.getName()) |
| 8535 | return nullptr; |
| 8536 | } |
| 8537 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8538 | // The Scope boundary is a duplication of the previous decl. |
| 8539 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8540 | for (auto *E : C->reduction_ops()) { |
| 8541 | // Transform all the decls. |
| 8542 | if (E) { |
| 8543 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8544 | UnresolvedSet<8> Decls; |
| 8545 | for (auto *D : ULE->decls()) { |
| 8546 | NamedDecl *InstD = |
| 8547 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8548 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8549 | } |
| 8550 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8551 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8552 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8553 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8554 | } else |
| 8555 | UnresolvedReductions.push_back(nullptr); |
| 8556 | } |
| 8557 | return getDerived().RebuildOMPTaskReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8558 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8559 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8560 | } |
| 8561 | |
| 8562 | template <typename Derived> |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8563 | OMPClause * |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8564 | TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { |
| 8565 | llvm::SmallVector<Expr *, 16> Vars; |
| 8566 | Vars.reserve(C->varlist_size()); |
| 8567 | for (auto *VE : C->varlists()) { |
| 8568 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8569 | if (EVar.isInvalid()) |
| 8570 | return nullptr; |
| 8571 | Vars.push_back(EVar.get()); |
| 8572 | } |
| 8573 | CXXScopeSpec ReductionIdScopeSpec; |
| 8574 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8575 | |
| 8576 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8577 | if (NameInfo.getName()) { |
| 8578 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8579 | if (!NameInfo.getName()) |
| 8580 | return nullptr; |
| 8581 | } |
| 8582 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8583 | // The Scope boundary is a duplication of the previous decl. |
| 8584 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8585 | for (auto *E : C->reduction_ops()) { |
| 8586 | // Transform all the decls. |
| 8587 | if (E) { |
| 8588 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8589 | UnresolvedSet<8> Decls; |
| 8590 | for (auto *D : ULE->decls()) { |
| 8591 | NamedDecl *InstD = |
| 8592 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8593 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8594 | } |
| 8595 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8596 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8597 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8598 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8599 | } else |
| 8600 | UnresolvedReductions.push_back(nullptr); |
| 8601 | } |
| 8602 | return getDerived().RebuildOMPInReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8603 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8604 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8605 | } |
| 8606 | |
| 8607 | template <typename Derived> |
| 8608 | OMPClause * |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8609 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 8610 | llvm::SmallVector<Expr *, 16> Vars; |
| 8611 | Vars.reserve(C->varlist_size()); |
| 8612 | for (auto *VE : C->varlists()) { |
| 8613 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8614 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8615 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8616 | Vars.push_back(EVar.get()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8617 | } |
| 8618 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 8619 | if (Step.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8620 | return nullptr; |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8621 | return getDerived().RebuildOMPLinearClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8622 | Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8623 | C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8624 | } |
| 8625 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8626 | template <typename Derived> |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8627 | OMPClause * |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8628 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 8629 | llvm::SmallVector<Expr *, 16> Vars; |
| 8630 | Vars.reserve(C->varlist_size()); |
| 8631 | for (auto *VE : C->varlists()) { |
| 8632 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8633 | if (EVar.isInvalid()) |
| 8634 | return nullptr; |
| 8635 | Vars.push_back(EVar.get()); |
| 8636 | } |
| 8637 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 8638 | if (Alignment.isInvalid()) |
| 8639 | return nullptr; |
| 8640 | return getDerived().RebuildOMPAlignedClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8641 | Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8642 | C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8643 | } |
| 8644 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8645 | template <typename Derived> |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8646 | OMPClause * |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8647 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 8648 | llvm::SmallVector<Expr *, 16> Vars; |
| 8649 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8650 | for (auto *VE : C->varlists()) { |
| 8651 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8652 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8653 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8654 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8655 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8656 | return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8657 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8658 | } |
| 8659 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8660 | template <typename Derived> |
| 8661 | OMPClause * |
| 8662 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 8663 | llvm::SmallVector<Expr *, 16> Vars; |
| 8664 | Vars.reserve(C->varlist_size()); |
| 8665 | for (auto *VE : C->varlists()) { |
| 8666 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8667 | if (EVar.isInvalid()) |
| 8668 | return nullptr; |
| 8669 | Vars.push_back(EVar.get()); |
| 8670 | } |
| 8671 | return getDerived().RebuildOMPCopyprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8672 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8673 | } |
| 8674 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8675 | template <typename Derived> |
| 8676 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 8677 | llvm::SmallVector<Expr *, 16> Vars; |
| 8678 | Vars.reserve(C->varlist_size()); |
| 8679 | for (auto *VE : C->varlists()) { |
| 8680 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8681 | if (EVar.isInvalid()) |
| 8682 | return nullptr; |
| 8683 | Vars.push_back(EVar.get()); |
| 8684 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8685 | return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8686 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8687 | } |
| 8688 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8689 | template <typename Derived> |
| 8690 | OMPClause * |
| 8691 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 8692 | llvm::SmallVector<Expr *, 16> Vars; |
| 8693 | Vars.reserve(C->varlist_size()); |
| 8694 | for (auto *VE : C->varlists()) { |
| 8695 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8696 | if (EVar.isInvalid()) |
| 8697 | return nullptr; |
| 8698 | Vars.push_back(EVar.get()); |
| 8699 | } |
| 8700 | return getDerived().RebuildOMPDependClause( |
| 8701 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8702 | C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8703 | } |
| 8704 | |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8705 | template <typename Derived> |
| 8706 | OMPClause * |
| 8707 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 8708 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 8709 | if (E.isInvalid()) |
| 8710 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8711 | return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8712 | C->getLParenLoc(), C->getEndLoc()); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8713 | } |
| 8714 | |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8715 | template <typename Derived> |
| 8716 | OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| 8717 | llvm::SmallVector<Expr *, 16> Vars; |
| 8718 | Vars.reserve(C->varlist_size()); |
| 8719 | for (auto *VE : C->varlists()) { |
| 8720 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8721 | if (EVar.isInvalid()) |
| 8722 | return nullptr; |
| 8723 | Vars.push_back(EVar.get()); |
| 8724 | } |
| 8725 | return getDerived().RebuildOMPMapClause( |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8726 | C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8727 | C->getMapLoc(), C->getColonLoc(), Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8728 | C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8729 | } |
| 8730 | |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8731 | template <typename Derived> |
| 8732 | OMPClause * |
| 8733 | TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 8734 | ExprResult E = getDerived().TransformExpr(C->getNumTeams()); |
| 8735 | if (E.isInvalid()) |
| 8736 | return nullptr; |
| 8737 | return getDerived().RebuildOMPNumTeamsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8738 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8739 | } |
| 8740 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8741 | template <typename Derived> |
| 8742 | OMPClause * |
| 8743 | TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 8744 | ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); |
| 8745 | if (E.isInvalid()) |
| 8746 | return nullptr; |
| 8747 | return getDerived().RebuildOMPThreadLimitClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8748 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8749 | } |
| 8750 | |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8751 | template <typename Derived> |
| 8752 | OMPClause * |
| 8753 | TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 8754 | ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 8755 | if (E.isInvalid()) |
| 8756 | return nullptr; |
| 8757 | return getDerived().RebuildOMPPriorityClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8758 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8759 | } |
| 8760 | |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8761 | template <typename Derived> |
| 8762 | OMPClause * |
| 8763 | TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 8764 | ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 8765 | if (E.isInvalid()) |
| 8766 | return nullptr; |
| 8767 | return getDerived().RebuildOMPGrainsizeClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8768 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8769 | } |
| 8770 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8771 | template <typename Derived> |
| 8772 | OMPClause * |
| 8773 | TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 8774 | ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 8775 | if (E.isInvalid()) |
| 8776 | return nullptr; |
| 8777 | return getDerived().RebuildOMPNumTasksClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8778 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8779 | } |
| 8780 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8781 | template <typename Derived> |
| 8782 | OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 8783 | ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 8784 | if (E.isInvalid()) |
| 8785 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8786 | return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8787 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8788 | } |
| 8789 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8790 | template <typename Derived> |
| 8791 | OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 8792 | OMPDistScheduleClause *C) { |
| 8793 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 8794 | if (E.isInvalid()) |
| 8795 | return nullptr; |
| 8796 | return getDerived().RebuildOMPDistScheduleClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8797 | C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8798 | C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8799 | } |
| 8800 | |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8801 | template <typename Derived> |
| 8802 | OMPClause * |
| 8803 | TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 8804 | return C; |
| 8805 | } |
| 8806 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8807 | template <typename Derived> |
| 8808 | OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| 8809 | llvm::SmallVector<Expr *, 16> Vars; |
| 8810 | Vars.reserve(C->varlist_size()); |
| 8811 | for (auto *VE : C->varlists()) { |
| 8812 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8813 | if (EVar.isInvalid()) |
| 8814 | return 0; |
| 8815 | Vars.push_back(EVar.get()); |
| 8816 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8817 | return getDerived().RebuildOMPToClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8818 | C->getLParenLoc(), C->getEndLoc()); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8819 | } |
| 8820 | |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8821 | template <typename Derived> |
| 8822 | OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| 8823 | llvm::SmallVector<Expr *, 16> Vars; |
| 8824 | Vars.reserve(C->varlist_size()); |
| 8825 | for (auto *VE : C->varlists()) { |
| 8826 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8827 | if (EVar.isInvalid()) |
| 8828 | return 0; |
| 8829 | Vars.push_back(EVar.get()); |
| 8830 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8831 | return getDerived().RebuildOMPFromClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8832 | C->getLParenLoc(), C->getEndLoc()); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8833 | } |
| 8834 | |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8835 | template <typename Derived> |
| 8836 | OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( |
| 8837 | OMPUseDevicePtrClause *C) { |
| 8838 | llvm::SmallVector<Expr *, 16> Vars; |
| 8839 | Vars.reserve(C->varlist_size()); |
| 8840 | for (auto *VE : C->varlists()) { |
| 8841 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8842 | if (EVar.isInvalid()) |
| 8843 | return nullptr; |
| 8844 | Vars.push_back(EVar.get()); |
| 8845 | } |
| 8846 | return getDerived().RebuildOMPUseDevicePtrClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8847 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8848 | } |
| 8849 | |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8850 | template <typename Derived> |
| 8851 | OMPClause * |
| 8852 | TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 8853 | llvm::SmallVector<Expr *, 16> Vars; |
| 8854 | Vars.reserve(C->varlist_size()); |
| 8855 | for (auto *VE : C->varlists()) { |
| 8856 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8857 | if (EVar.isInvalid()) |
| 8858 | return nullptr; |
| 8859 | Vars.push_back(EVar.get()); |
| 8860 | } |
| 8861 | return getDerived().RebuildOMPIsDevicePtrClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8862 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8863 | } |
| 8864 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 8865 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8866 | // Expression transformation |
| 8867 | //===----------------------------------------------------------------------===// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8868 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8869 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8870 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 8871 | if (!E->isTypeDependent()) |
| 8872 | return E; |
| 8873 | |
| 8874 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 8875 | E->getIdentType()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8876 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8877 | |
| 8878 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8879 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8880 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8881 | NestedNameSpecifierLoc QualifierLoc; |
| 8882 | if (E->getQualifierLoc()) { |
| 8883 | QualifierLoc |
| 8884 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8885 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8886 | return ExprError(); |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8887 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8888 | |
| 8889 | ValueDecl *ND |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 8890 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 8891 | E->getDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8892 | if (!ND) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8893 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8894 | |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 8895 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 8896 | if (NameInfo.getName()) { |
| 8897 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8898 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 8899 | return ExprError(); |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 8900 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8901 | |
| 8902 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8903 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8904 | ND == E->getDecl() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 8905 | NameInfo.getName() == E->getDecl()->getDeclName() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8906 | !E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8907 | |
| 8908 | // Mark it referenced in the new context regardless. |
| 8909 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 8910 | SemaRef.MarkDeclRefReferenced(E); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8911 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8912 | return E; |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 8913 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8914 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8915 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 8916 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8917 | TemplateArgs = &TransArgs; |
| 8918 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 8919 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 8920 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 8921 | E->getNumTemplateArgs(), |
| 8922 | TransArgs)) |
| 8923 | return ExprError(); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 8924 | } |
| 8925 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 8926 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 8927 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8928 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8929 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8930 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8931 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8932 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8933 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8934 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8935 | |
| Leonard Chan | db01c3a | 2018-06-20 17:19:40 +0000 | [diff] [blame] | 8936 | template <typename Derived> |
| 8937 | ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( |
| 8938 | FixedPointLiteral *E) { |
| 8939 | return E; |
| 8940 | } |
| 8941 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8942 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8943 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8944 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8945 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8946 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8947 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8948 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8949 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8950 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8951 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8952 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8953 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8954 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8955 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8956 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8957 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8958 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8959 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 8960 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8961 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 8962 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 8963 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8964 | } |
| 8965 | |
| 8966 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 8967 | ExprResult |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 8968 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 8969 | if (FunctionDecl *FD = E->getDirectCallee()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8970 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD); |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 8971 | return SemaRef.MaybeBindToTemporary(E); |
| 8972 | } |
| 8973 | |
| 8974 | template<typename Derived> |
| 8975 | ExprResult |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8976 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 8977 | ExprResult ControllingExpr = |
| 8978 | getDerived().TransformExpr(E->getControllingExpr()); |
| 8979 | if (ControllingExpr.isInvalid()) |
| 8980 | return ExprError(); |
| 8981 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 8982 | SmallVector<Expr *, 4> AssocExprs; |
| 8983 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8984 | for (unsigned i = 0; i != E->getNumAssocs(); ++i) { |
| 8985 | TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); |
| 8986 | if (TS) { |
| 8987 | TypeSourceInfo *AssocType = getDerived().TransformType(TS); |
| 8988 | if (!AssocType) |
| 8989 | return ExprError(); |
| 8990 | AssocTypes.push_back(AssocType); |
| 8991 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8992 | AssocTypes.push_back(nullptr); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8993 | } |
| 8994 | |
| 8995 | ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); |
| 8996 | if (AssocExpr.isInvalid()) |
| 8997 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8998 | AssocExprs.push_back(AssocExpr.get()); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 8999 | } |
| 9000 | |
| 9001 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 9002 | E->getDefaultLoc(), |
| 9003 | E->getRParenLoc(), |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9004 | ControllingExpr.get(), |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 9005 | AssocTypes, |
| 9006 | AssocExprs); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9007 | } |
| 9008 | |
| 9009 | template<typename Derived> |
| 9010 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9011 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9012 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9013 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9014 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9015 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9016 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9017 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9018 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9019 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9020 | E->getRParen()); |
| 9021 | } |
| 9022 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9023 | /// The operand of a unary address-of operator has special rules: it's |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9024 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 9025 | /// object available. |
| 9026 | template<typename Derived> |
| 9027 | ExprResult |
| 9028 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 9029 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9030 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9031 | else |
| 9032 | return getDerived().TransformExpr(E); |
| 9033 | } |
| 9034 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9035 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9036 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9037 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 9038 | ExprResult SubExpr; |
| 9039 | if (E->getOpcode() == UO_AddrOf) |
| 9040 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 9041 | else |
| 9042 | SubExpr = TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9043 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9044 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9045 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9046 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9047 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9048 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9049 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 9050 | E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9051 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9052 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9053 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9054 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9055 | ExprResult |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9056 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 9057 | // Transform the type. |
| 9058 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9059 | if (!Type) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9060 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9061 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9062 | // Transform all of the components into components similar to what the |
| 9063 | // parser uses. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9064 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 9065 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 9066 | // the fields again. However, __builtin_offsetof is rare enough in |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9067 | // template code that we don't care. |
| 9068 | bool ExprChanged = false; |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9069 | typedef Sema::OffsetOfComponent Component; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9070 | SmallVector<Component, 4> Components; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9071 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9072 | const OffsetOfNode &ON = E->getComponent(I); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9073 | Component Comp; |
| Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 9074 | Comp.isBrackets = true; |
| Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 9075 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 9076 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9077 | switch (ON.getKind()) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9078 | case OffsetOfNode::Array: { |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9079 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9080 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9081 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9082 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9083 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9084 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 9085 | Comp.isBrackets = true; |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9086 | Comp.U.E = Index.get(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9087 | break; |
| 9088 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9089 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9090 | case OffsetOfNode::Field: |
| 9091 | case OffsetOfNode::Identifier: |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9092 | Comp.isBrackets = false; |
| 9093 | Comp.U.IdentInfo = ON.getFieldName(); |
| Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 9094 | if (!Comp.U.IdentInfo) |
| 9095 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9096 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9097 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9098 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9099 | case OffsetOfNode::Base: |
| Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 9100 | // Will be recomputed during the rebuild. |
| 9101 | continue; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9102 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9103 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9104 | Components.push_back(Comp); |
| 9105 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9106 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9107 | // If nothing changed, retain the existing expression. |
| 9108 | if (!getDerived().AlwaysRebuild() && |
| 9109 | Type == E->getTypeSourceInfo() && |
| 9110 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9111 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9112 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9113 | // Build a new offsetof expression. |
| 9114 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 9115 | Components, E->getRParenLoc()); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9116 | } |
| 9117 | |
| 9118 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9119 | ExprResult |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9120 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| Hubert Tong | 2cded44 | 2015-09-01 22:50:31 +0000 | [diff] [blame] | 9121 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9122 | "opaque value expression requires transformation"); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9123 | return E; |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9124 | } |
| 9125 | |
| 9126 | template<typename Derived> |
| 9127 | ExprResult |
| Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 9128 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 9129 | return E; |
| 9130 | } |
| 9131 | |
| 9132 | template<typename Derived> |
| 9133 | ExprResult |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9134 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
| John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 9135 | // Rebuild the syntactic form. The original syntactic form has |
| 9136 | // opaque-value expressions in it, so strip those away and rebuild |
| 9137 | // the result. This is a really awful way of doing this, but the |
| 9138 | // better solution (rebuilding the semantic expressions and |
| 9139 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 9140 | // TreeTransform to not strip away implicit conversions. |
| 9141 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 9142 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9143 | if (result.isInvalid()) return ExprError(); |
| 9144 | |
| 9145 | // If that gives us a pseudo-object result back, the pseudo-object |
| 9146 | // expression must have been an lvalue-to-rvalue conversion which we |
| 9147 | // should reapply. |
| 9148 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9149 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9150 | |
| 9151 | return result; |
| 9152 | } |
| 9153 | |
| 9154 | template<typename Derived> |
| 9155 | ExprResult |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9156 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 9157 | UnaryExprOrTypeTraitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9158 | if (E->isArgumentType()) { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9159 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9160 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9161 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9162 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9163 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9164 | |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9165 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9166 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9167 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9168 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 9169 | E->getKind(), |
| 9170 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9171 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9172 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9173 | // C++0x [expr.sizeof]p1: |
| 9174 | // The operand is either an expression, which is an unevaluated operand |
| 9175 | // [...] |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 9176 | EnterExpressionEvaluationContext Unevaluated( |
| 9177 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 9178 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9179 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9180 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 9181 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 9182 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 9183 | ExprResult SubExpr; |
| 9184 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 9185 | if (auto *DRE = |
| 9186 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 9187 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 9188 | PE, DRE, false, &RecoveryTSI); |
| 9189 | else |
| 9190 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 9191 | |
| 9192 | if (RecoveryTSI) { |
| 9193 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 9194 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 9195 | } else if (SubExpr.isInvalid()) |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9196 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9197 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9198 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9199 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9200 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9201 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 9202 | E->getOperatorLoc(), |
| 9203 | E->getKind(), |
| 9204 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9205 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9206 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9207 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9208 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9209 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9210 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9211 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9212 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9213 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9214 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9215 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9216 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9217 | |
| 9218 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9219 | if (!getDerived().AlwaysRebuild() && |
| 9220 | LHS.get() == E->getLHS() && |
| 9221 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9222 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9223 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9224 | return getDerived().RebuildArraySubscriptExpr( |
| 9225 | LHS.get(), |
| 9226 | /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9227 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9228 | |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9229 | template <typename Derived> |
| 9230 | ExprResult |
| 9231 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 9232 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 9233 | if (Base.isInvalid()) |
| 9234 | return ExprError(); |
| 9235 | |
| 9236 | ExprResult LowerBound; |
| 9237 | if (E->getLowerBound()) { |
| 9238 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 9239 | if (LowerBound.isInvalid()) |
| 9240 | return ExprError(); |
| 9241 | } |
| 9242 | |
| 9243 | ExprResult Length; |
| 9244 | if (E->getLength()) { |
| 9245 | Length = getDerived().TransformExpr(E->getLength()); |
| 9246 | if (Length.isInvalid()) |
| 9247 | return ExprError(); |
| 9248 | } |
| 9249 | |
| 9250 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 9251 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 9252 | return E; |
| 9253 | |
| 9254 | return getDerived().RebuildOMPArraySectionExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9255 | Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(), |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9256 | Length.get(), E->getRBracketLoc()); |
| 9257 | } |
| 9258 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9259 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9260 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9261 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9262 | // Transform the callee. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9263 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9264 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9265 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9266 | |
| 9267 | // Transform arguments. |
| 9268 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9269 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9270 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9271 | &ArgChanged)) |
| 9272 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9273 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9274 | if (!getDerived().AlwaysRebuild() && |
| 9275 | Callee.get() == E->getCallee() && |
| 9276 | !ArgChanged) |
| Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 9277 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9278 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9279 | // FIXME: Wrong source location information for the '('. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9280 | SourceLocation FakeLParenLoc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9281 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9282 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9283 | Args, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9284 | E->getRParenLoc()); |
| 9285 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9286 | |
| 9287 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9288 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9289 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9290 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9291 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9292 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9293 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9294 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9295 | if (E->hasQualifier()) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9296 | QualifierLoc |
| 9297 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9298 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9299 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9300 | return ExprError(); |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9301 | } |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9302 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9303 | |
| Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 9304 | ValueDecl *Member |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9305 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 9306 | E->getMemberDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9307 | if (!Member) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9308 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9309 | |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9310 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 9311 | if (FoundDecl == E->getMemberDecl()) { |
| 9312 | FoundDecl = Member; |
| 9313 | } else { |
| 9314 | FoundDecl = cast_or_null<NamedDecl>( |
| 9315 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 9316 | if (!FoundDecl) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9317 | return ExprError(); |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9318 | } |
| 9319 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9320 | if (!getDerived().AlwaysRebuild() && |
| 9321 | Base.get() == E->getBase() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9322 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9323 | Member == E->getMemberDecl() && |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9324 | FoundDecl == E->getFoundDecl() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9325 | !E->hasExplicitTemplateArgs()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9326 | |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9327 | // Mark it referenced in the new context regardless. |
| 9328 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9329 | SemaRef.MarkMemberReferenced(E); |
| 9330 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9331 | return E; |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9332 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9333 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9334 | TemplateArgumentListInfo TransArgs; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9335 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9336 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9337 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9338 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9339 | E->getNumTemplateArgs(), |
| 9340 | TransArgs)) |
| 9341 | return ExprError(); |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9342 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9343 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9344 | // FIXME: Bogus source location for the operator |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9345 | SourceLocation FakeOperatorLoc = |
| 9346 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9347 | |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9348 | // FIXME: to do this check properly, we will need to preserve the |
| 9349 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9350 | // base (and therefore couldn't do the check) and a |
| 9351 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9352 | NamedDecl *FirstQualifierInScope = nullptr; |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9353 | DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); |
| 9354 | if (MemberNameInfo.getName()) { |
| 9355 | MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); |
| 9356 | if (!MemberNameInfo.getName()) |
| 9357 | return ExprError(); |
| 9358 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9359 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9360 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9361 | E->isArrow(), |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9362 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9363 | TemplateKWLoc, |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9364 | MemberNameInfo, |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9365 | Member, |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9366 | FoundDecl, |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9367 | (E->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9368 | ? &TransArgs : nullptr), |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9369 | FirstQualifierInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9370 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9371 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9372 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9373 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9374 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9375 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9376 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9377 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9378 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9379 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9380 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9381 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9382 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9383 | if (!getDerived().AlwaysRebuild() && |
| 9384 | LHS.get() == E->getLHS() && |
| 9385 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9386 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9387 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9388 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 9389 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9390 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9391 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9392 | LHS.get(), RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9393 | } |
| 9394 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9395 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9396 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9397 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9398 | CompoundAssignOperator *E) { |
| 9399 | return getDerived().TransformBinaryOperator(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9400 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9401 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9402 | template<typename Derived> |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9403 | ExprResult TreeTransform<Derived>:: |
| 9404 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 9405 | // Just rebuild the common and RHS expressions and see whether we |
| 9406 | // get any changes. |
| 9407 | |
| 9408 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 9409 | if (commonExpr.isInvalid()) |
| 9410 | return ExprError(); |
| 9411 | |
| 9412 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 9413 | if (rhs.isInvalid()) |
| 9414 | return ExprError(); |
| 9415 | |
| 9416 | if (!getDerived().AlwaysRebuild() && |
| 9417 | commonExpr.get() == e->getCommon() && |
| 9418 | rhs.get() == e->getFalseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9419 | return e; |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9420 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9421 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9422 | e->getQuestionLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9423 | nullptr, |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9424 | e->getColonLoc(), |
| 9425 | rhs.get()); |
| 9426 | } |
| 9427 | |
| 9428 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9429 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9430 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9431 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9432 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9433 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9434 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9435 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9436 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9437 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9438 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9439 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9440 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9441 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9442 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9443 | if (!getDerived().AlwaysRebuild() && |
| 9444 | Cond.get() == E->getCond() && |
| 9445 | LHS.get() == E->getLHS() && |
| 9446 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9447 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9448 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9449 | return getDerived().RebuildConditionalOperator(Cond.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9450 | E->getQuestionLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9451 | LHS.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9452 | E->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9453 | RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9454 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9455 | |
| 9456 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9457 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9458 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
| Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 9459 | // Implicit casts are eliminated during transformation, since they |
| 9460 | // will be recomputed by semantic analysis after transformation. |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9461 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9462 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9463 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9464 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9465 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9466 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9467 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9468 | if (!Type) |
| 9469 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9470 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9471 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9472 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9473 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9474 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9475 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9476 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9477 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9478 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9479 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9480 | |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 9481 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9482 | Type, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9483 | E->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9484 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9485 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9486 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9487 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9488 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9489 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9490 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 9491 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 9492 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9493 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9494 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9495 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9496 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9497 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9498 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9499 | if (!getDerived().AlwaysRebuild() && |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9500 | OldT == NewT && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9501 | Init.get() == E->getInitializer()) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9502 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9503 | |
| John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 9504 | // Note: the expression type doesn't necessarily match the |
| 9505 | // type-as-written, but that's okay, because it should always be |
| 9506 | // derivable from the initializer. |
| 9507 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9508 | return getDerived().RebuildCompoundLiteralExpr( |
| 9509 | E->getLParenLoc(), NewT, |
| 9510 | /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9511 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9512 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9513 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9514 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9515 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9516 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9517 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9518 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9519 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9520 | if (!getDerived().AlwaysRebuild() && |
| 9521 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9522 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9523 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9524 | // FIXME: Bad source location |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9525 | SourceLocation FakeOperatorLoc = |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9526 | SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9527 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9528 | E->getAccessorLoc(), |
| 9529 | E->getAccessor()); |
| 9530 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9531 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9532 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9533 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9534 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9535 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 9536 | E = Syntactic; |
| 9537 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9538 | bool InitChanged = false; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9539 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9540 | SmallVector<Expr*, 4> Inits; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9541 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9542 | Inits, &InitChanged)) |
| 9543 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9544 | |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9545 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 9546 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 9547 | // in some cases. We can't reuse it in general, because the syntactic and |
| 9548 | // semantic forms are linked, and we can't know that semantic form will |
| 9549 | // match even if the syntactic form does. |
| 9550 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9551 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9552 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 9553 | E->getRBraceLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9554 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9555 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9556 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9557 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9558 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9559 | Designation Desig; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9560 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9561 | // transform the initializer value |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9562 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9563 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9564 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9565 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9566 | // transform the designators. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9567 | SmallVector<Expr*, 4> ArrayExprs; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9568 | bool ExprChanged = false; |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9569 | for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 9570 | if (D.isFieldDesignator()) { |
| 9571 | Desig.AddDesignator(Designator::getField(D.getFieldName(), |
| 9572 | D.getDotLoc(), |
| 9573 | D.getFieldLoc())); |
| Alex Lorenz | cb642b9 | 2016-10-24 09:33:32 +0000 | [diff] [blame] | 9574 | if (D.getField()) { |
| 9575 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 9576 | getDerived().TransformDecl(D.getFieldLoc(), D.getField())); |
| 9577 | if (Field != D.getField()) |
| 9578 | // Rebuild the expression when the transformed FieldDecl is |
| 9579 | // different to the already assigned FieldDecl. |
| 9580 | ExprChanged = true; |
| 9581 | } else { |
| 9582 | // Ensure that the designator expression is rebuilt when there isn't |
| 9583 | // a resolved FieldDecl in the designator as we don't want to assign |
| 9584 | // a FieldDecl to a pattern designator that will be instantiated again. |
| 9585 | ExprChanged = true; |
| 9586 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9587 | continue; |
| 9588 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9589 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9590 | if (D.isArrayDesignator()) { |
| 9591 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9592 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9593 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9594 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9595 | Desig.AddDesignator( |
| 9596 | Designator::getArray(Index.get(), D.getLBracketLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9597 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9598 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9599 | ArrayExprs.push_back(Index.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9600 | continue; |
| 9601 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9602 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9603 | assert(D.isArrayRangeDesignator() && "New kind of designator?"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9604 | ExprResult Start |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9605 | = getDerived().TransformExpr(E->getArrayRangeStart(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9606 | if (Start.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9607 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9608 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9609 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9610 | if (End.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9611 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9612 | |
| 9613 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9614 | End.get(), |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9615 | D.getLBracketLoc(), |
| 9616 | D.getEllipsisLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9617 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9618 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 9619 | End.get() != E->getArrayRangeEnd(D); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9620 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9621 | ArrayExprs.push_back(Start.get()); |
| 9622 | ArrayExprs.push_back(End.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9623 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9624 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9625 | if (!getDerived().AlwaysRebuild() && |
| 9626 | Init.get() == E->getInit() && |
| 9627 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9628 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9629 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9630 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9631 | E->getEqualOrColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9632 | E->usesGNUSyntax(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9633 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9634 | |
| Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 9635 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 9636 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 9637 | template<typename Derived> |
| 9638 | ExprResult |
| 9639 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 9640 | DesignatedInitUpdateExpr *E) { |
| 9641 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 9642 | "initializer"); |
| 9643 | return ExprError(); |
| 9644 | } |
| 9645 | |
| 9646 | template<typename Derived> |
| 9647 | ExprResult |
| 9648 | TreeTransform<Derived>::TransformNoInitExpr( |
| 9649 | NoInitExpr *E) { |
| 9650 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 9651 | return ExprError(); |
| 9652 | } |
| 9653 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9654 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9655 | ExprResult |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 9656 | TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 9657 | llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); |
| 9658 | return ExprError(); |
| 9659 | } |
| 9660 | |
| 9661 | template<typename Derived> |
| 9662 | ExprResult |
| 9663 | TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 9664 | llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); |
| 9665 | return ExprError(); |
| 9666 | } |
| 9667 | |
| 9668 | template<typename Derived> |
| 9669 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9670 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9671 | ImplicitValueInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9672 | TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9673 | |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9674 | // FIXME: Will we ever have proper type location here? Will we actually |
| 9675 | // need to transform the type? |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9676 | QualType T = getDerived().TransformType(E->getType()); |
| 9677 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9678 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9679 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9680 | if (!getDerived().AlwaysRebuild() && |
| 9681 | T == E->getType()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9682 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9683 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9684 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 9685 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9686 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9687 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9688 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9689 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 9690 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 9691 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9692 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9693 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9694 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9695 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9696 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9697 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9698 | if (!getDerived().AlwaysRebuild() && |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 9699 | TInfo == E->getWrittenTypeInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9700 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9701 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9702 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9703 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 9704 | TInfo, E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9705 | } |
| 9706 | |
| 9707 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9708 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9709 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9710 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9711 | SmallVector<Expr*, 4> Inits; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9712 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 9713 | &ArgumentChanged)) |
| 9714 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9715 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9716 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9717 | Inits, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9718 | E->getRParenLoc()); |
| 9719 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9720 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9721 | /// Transform an address-of-label expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9722 | /// |
| 9723 | /// By default, the transformation of an address-of-label expression always |
| 9724 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 9725 | /// the corresponding label statement by semantic analysis. |
| 9726 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9727 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9728 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 9729 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 9730 | E->getLabel()); |
| 9731 | if (!LD) |
| 9732 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9733 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9734 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 9735 | cast<LabelDecl>(LD)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9736 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9737 | |
| 9738 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9739 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9740 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 9741 | SemaRef.ActOnStartStmtExpr(); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9742 | StmtResult SubStmt |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9743 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 9744 | if (SubStmt.isInvalid()) { |
| 9745 | SemaRef.ActOnStmtExprError(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9746 | return ExprError(); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 9747 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9748 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9749 | if (!getDerived().AlwaysRebuild() && |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 9750 | SubStmt.get() == E->getSubStmt()) { |
| 9751 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 9752 | SemaRef.ActOnStmtExprError(); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9753 | return SemaRef.MaybeBindToTemporary(E); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 9754 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9755 | |
| 9756 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9757 | SubStmt.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9758 | E->getRParenLoc()); |
| 9759 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9760 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9761 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9762 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9763 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9764 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9765 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9766 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9767 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9768 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9769 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9770 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9771 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9772 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9773 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9774 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9775 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9776 | if (!getDerived().AlwaysRebuild() && |
| 9777 | Cond.get() == E->getCond() && |
| 9778 | LHS.get() == E->getLHS() && |
| 9779 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9780 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9781 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9782 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9783 | Cond.get(), LHS.get(), RHS.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9784 | E->getRParenLoc()); |
| 9785 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9786 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9787 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9788 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9789 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9790 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9791 | } |
| 9792 | |
| 9793 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9794 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9795 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9796 | switch (E->getOperator()) { |
| 9797 | case OO_New: |
| 9798 | case OO_Delete: |
| 9799 | case OO_Array_New: |
| 9800 | case OO_Array_Delete: |
| 9801 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9802 | |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9803 | case OO_Call: { |
| 9804 | // This is a call to an object's operator(). |
| 9805 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 9806 | |
| 9807 | // Transform the object itself. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9808 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9809 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9810 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9811 | |
| 9812 | // FIXME: Poor location information |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9813 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9814 | static_cast<Expr *>(Object.get())->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9815 | |
| 9816 | // Transform the call arguments. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9817 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9818 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9819 | Args)) |
| 9820 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9821 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9822 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, |
| 9823 | E->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9824 | } |
| 9825 | |
| 9826 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 9827 | case OO_##Name: |
| 9828 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 9829 | #include "clang/Basic/OperatorKinds.def" |
| 9830 | case OO_Subscript: |
| 9831 | // Handled below. |
| 9832 | break; |
| 9833 | |
| 9834 | case OO_Conditional: |
| 9835 | llvm_unreachable("conditional operator is not actually overloadable"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9836 | |
| 9837 | case OO_None: |
| 9838 | case NUM_OVERLOADED_OPERATORS: |
| 9839 | llvm_unreachable("not an overloaded operator?"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 9840 | } |
| 9841 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9842 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9843 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9844 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9845 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9846 | ExprResult First; |
| 9847 | if (E->getOperator() == OO_Amp) |
| 9848 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 9849 | else |
| 9850 | First = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9851 | if (First.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9852 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9853 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9854 | ExprResult Second; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9855 | if (E->getNumArgs() == 2) { |
| 9856 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 9857 | if (Second.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9858 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9859 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9860 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9861 | if (!getDerived().AlwaysRebuild() && |
| 9862 | Callee.get() == E->getCallee() && |
| 9863 | First.get() == E->getArg(0) && |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9864 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9865 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9866 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9867 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 9868 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9869 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9870 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 9871 | E->getOperatorLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9872 | Callee.get(), |
| 9873 | First.get(), |
| 9874 | Second.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9875 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9876 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9877 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9878 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9879 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 9880 | return getDerived().TransformCallExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9881 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9882 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9883 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9884 | ExprResult |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9885 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 9886 | // Transform the callee. |
| 9887 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 9888 | if (Callee.isInvalid()) |
| 9889 | return ExprError(); |
| 9890 | |
| 9891 | // Transform exec config. |
| 9892 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 9893 | if (EC.isInvalid()) |
| 9894 | return ExprError(); |
| 9895 | |
| 9896 | // Transform arguments. |
| 9897 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9898 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9899 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9900 | &ArgChanged)) |
| 9901 | return ExprError(); |
| 9902 | |
| 9903 | if (!getDerived().AlwaysRebuild() && |
| 9904 | Callee.get() == E->getCallee() && |
| 9905 | !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9906 | return SemaRef.MaybeBindToTemporary(E); |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9907 | |
| 9908 | // FIXME: Wrong source location information for the '('. |
| 9909 | SourceLocation FakeLParenLoc |
| 9910 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 9911 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9912 | Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 9913 | E->getRParenLoc(), EC.get()); |
| 9914 | } |
| 9915 | |
| 9916 | template<typename Derived> |
| 9917 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9918 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9919 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9920 | if (!Type) |
| 9921 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9922 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9923 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9924 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9925 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9926 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9927 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9928 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9929 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9930 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9931 | return E; |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 9932 | return getDerived().RebuildCXXNamedCastExpr( |
| 9933 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 9934 | Type, E->getAngleBrackets().getEnd(), |
| 9935 | // FIXME. this should be '(' location |
| 9936 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9937 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9938 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9939 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9940 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9941 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 9942 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9943 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9944 | |
| 9945 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9946 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9947 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 9948 | return getDerived().TransformCXXNamedCastExpr(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9949 | } |
| 9950 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9951 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9952 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9953 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9954 | CXXReinterpretCastExpr *E) { |
| 9955 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9956 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9957 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9958 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9959 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9960 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 9961 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9962 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9963 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9964 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9965 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9966 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9967 | CXXFunctionalCastExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 9968 | TypeSourceInfo *Type = |
| 9969 | getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9970 | if (!Type) |
| 9971 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9972 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9973 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9974 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9975 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9976 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9977 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9978 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9979 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9980 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9981 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9982 | |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9983 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
| Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 9984 | E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9985 | SubExpr.get(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 9986 | E->getRParenLoc(), |
| 9987 | E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9988 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9989 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9990 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9991 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9992 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9993 | if (E->isTypeOperand()) { |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 9994 | TypeSourceInfo *TInfo |
| 9995 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 9996 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9997 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9998 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9999 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 10000 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10001 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10002 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10003 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10004 | TInfo, E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10005 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10006 | |
| Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 10007 | // We don't know whether the subexpression is potentially evaluated until |
| 10008 | // after we perform semantic analysis. We speculatively assume it is |
| 10009 | // unevaluated; it will get fixed later if the subexpression is in fact |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10010 | // potentially evaluated. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10011 | EnterExpressionEvaluationContext Unevaluated( |
| 10012 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 10013 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10014 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10015 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10016 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10017 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10018 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10019 | if (!getDerived().AlwaysRebuild() && |
| 10020 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10021 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10022 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10023 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10024 | SubExpr.get(), E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10025 | } |
| 10026 | |
| 10027 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10028 | ExprResult |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10029 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 10030 | if (E->isTypeOperand()) { |
| 10031 | TypeSourceInfo *TInfo |
| 10032 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 10033 | if (!TInfo) |
| 10034 | return ExprError(); |
| 10035 | |
| 10036 | if (!getDerived().AlwaysRebuild() && |
| 10037 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10038 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10039 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10040 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10041 | TInfo, E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10042 | } |
| 10043 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10044 | EnterExpressionEvaluationContext Unevaluated( |
| 10045 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10046 | |
| 10047 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 10048 | if (SubExpr.isInvalid()) |
| 10049 | return ExprError(); |
| 10050 | |
| 10051 | if (!getDerived().AlwaysRebuild() && |
| 10052 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10053 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10054 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10055 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10056 | SubExpr.get(), E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10057 | } |
| 10058 | |
| 10059 | template<typename Derived> |
| 10060 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10061 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10062 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10063 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10064 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10065 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10066 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10067 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10068 | CXXNullPtrLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10069 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10070 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10071 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10072 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10073 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10074 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 10075 | QualType T = getSema().getCurrentThisType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10076 | |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10077 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 10078 | // Make sure that we capture 'this'. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10079 | getSema().CheckCXXThisCapture(E->getBeginLoc()); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10080 | return E; |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10081 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10082 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10083 | return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10084 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10085 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10086 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10087 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10088 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10089 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10090 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10091 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10092 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10093 | if (!getDerived().AlwaysRebuild() && |
| 10094 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10095 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10096 | |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 10097 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 10098 | E->isThrownVariableInScope()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10099 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10100 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10101 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10102 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10103 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10104 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 10105 | getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10106 | if (!Param) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10107 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10108 | |
| Chandler Carruth | 794da4c | 2010-02-08 06:42:49 +0000 | [diff] [blame] | 10109 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10110 | Param == E->getParam()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10111 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10112 | |
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 10113 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10114 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10115 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10116 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10117 | ExprResult |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10118 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10119 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 10120 | getDerived().TransformDecl(E->getBeginLoc(), E->getField())); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10121 | if (!Field) |
| 10122 | return ExprError(); |
| 10123 | |
| 10124 | if (!getDerived().AlwaysRebuild() && Field == E->getField()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10125 | return E; |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10126 | |
| 10127 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 10128 | } |
| 10129 | |
| 10130 | template<typename Derived> |
| 10131 | ExprResult |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10132 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 10133 | CXXScalarValueInitExpr *E) { |
| 10134 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10135 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10136 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10137 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10138 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10139 | T == E->getTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10140 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10141 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10142 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10143 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
| Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 10144 | E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10145 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10146 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10147 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10148 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10149 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10150 | // Transform the type that we're allocating |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10151 | TypeSourceInfo *AllocTypeInfo = |
| 10152 | getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10153 | if (!AllocTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10154 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10155 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10156 | // Transform the size of the array we're allocating (if any). |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10157 | ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10158 | if (ArraySize.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10159 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10160 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10161 | // Transform the placement arguments (if any). |
| 10162 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10163 | SmallVector<Expr*, 8> PlacementArgs; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10164 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10165 | E->getNumPlacementArgs(), true, |
| 10166 | PlacementArgs, &ArgumentChanged)) |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10167 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10168 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10169 | // Transform the initializer (if any). |
| 10170 | Expr *OldInit = E->getInitializer(); |
| 10171 | ExprResult NewInit; |
| 10172 | if (OldInit) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 10173 | NewInit = getDerived().TransformInitializer(OldInit, true); |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10174 | if (NewInit.isInvalid()) |
| 10175 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10176 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10177 | // Transform new operator and delete operator. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10178 | FunctionDecl *OperatorNew = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10179 | if (E->getOperatorNew()) { |
| 10180 | OperatorNew = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10181 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10182 | if (!OperatorNew) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10183 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10184 | } |
| 10185 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10186 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10187 | if (E->getOperatorDelete()) { |
| 10188 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10189 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10190 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10191 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10192 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10193 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10194 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10195 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10196 | ArraySize.get() == E->getArraySize() && |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10197 | NewInit.get() == OldInit && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10198 | OperatorNew == E->getOperatorNew() && |
| 10199 | OperatorDelete == E->getOperatorDelete() && |
| 10200 | !ArgumentChanged) { |
| 10201 | // Mark any declarations we need as referenced. |
| 10202 | // FIXME: instantiation-specific. |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10203 | if (OperatorNew) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10204 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10205 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10206 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10207 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10208 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10209 | QualType ElementType |
| 10210 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 10211 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 10212 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 10213 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10214 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10215 | } |
| 10216 | } |
| 10217 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10218 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10219 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10220 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10221 | |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10222 | QualType AllocType = AllocTypeInfo->getType(); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10223 | if (!ArraySize.get()) { |
| 10224 | // If no array size was specified, but the new expression was |
| 10225 | // instantiated with an array type (e.g., "new T" where T is |
| 10226 | // instantiated with "int[4]"), extract the outer bound from the |
| 10227 | // array type as our array size. We do this with constant and |
| 10228 | // dependently-sized array types. |
| 10229 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 10230 | if (!ArrayT) { |
| 10231 | // Do nothing |
| 10232 | } else if (const ConstantArrayType *ConsArrayT |
| 10233 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10234 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 10235 | SemaRef.Context.getSizeType(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10236 | /*FIXME:*/ E->getBeginLoc()); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10237 | AllocType = ConsArrayT->getElementType(); |
| 10238 | } else if (const DependentSizedArrayType *DepArrayT |
| 10239 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 10240 | if (DepArrayT->getSizeExpr()) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10241 | ArraySize = DepArrayT->getSizeExpr(); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10242 | AllocType = DepArrayT->getElementType(); |
| 10243 | } |
| 10244 | } |
| 10245 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10246 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10247 | return getDerived().RebuildCXXNewExpr( |
| 10248 | E->getBeginLoc(), E->isGlobalNew(), |
| 10249 | /*FIXME:*/ E->getBeginLoc(), PlacementArgs, |
| 10250 | /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, |
| 10251 | AllocTypeInfo, ArraySize.get(), E->getDirectInitRange(), NewInit.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10252 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10253 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10254 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10255 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10256 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10257 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10258 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10259 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10260 | |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10261 | // Transform the delete operator, if known. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10262 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10263 | if (E->getOperatorDelete()) { |
| 10264 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10265 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10266 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10267 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10268 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10269 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10270 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10271 | Operand.get() == E->getArgument() && |
| 10272 | OperatorDelete == E->getOperatorDelete()) { |
| 10273 | // Mark any declarations we need as referenced. |
| 10274 | // FIXME: instantiation-specific. |
| 10275 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10276 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10277 | |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10278 | if (!E->getArgument()->isTypeDependent()) { |
| 10279 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 10280 | E->getDestroyedType()); |
| 10281 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 10282 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10283 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 10284 | SemaRef.LookupDestructor(Record)); |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10285 | } |
| 10286 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10287 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10288 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10289 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10290 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10291 | return getDerived().RebuildCXXDeleteExpr( |
| 10292 | E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10293 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10294 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10295 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10296 | ExprResult |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10297 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10298 | CXXPseudoDestructorExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10299 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10300 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10301 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10302 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10303 | ParsedType ObjectTypePtr; |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10304 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10305 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10306 | E->getOperatorLoc(), |
| 10307 | E->isArrow()? tok::arrow : tok::period, |
| 10308 | ObjectTypePtr, |
| 10309 | MayBePseudoDestructor); |
| 10310 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10311 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10312 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10313 | QualType ObjectType = ObjectTypePtr.get(); |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10314 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 10315 | if (QualifierLoc) { |
| 10316 | QualifierLoc |
| 10317 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 10318 | if (!QualifierLoc) |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10319 | return ExprError(); |
| 10320 | } |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10321 | CXXScopeSpec SS; |
| 10322 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10323 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10324 | PseudoDestructorTypeStorage Destroyed; |
| 10325 | if (E->getDestroyedTypeInfo()) { |
| 10326 | TypeSourceInfo *DestroyedTypeInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10327 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10328 | ObjectType, nullptr, SS); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10329 | if (!DestroyedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10330 | return ExprError(); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10331 | Destroyed = DestroyedTypeInfo; |
| Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 10332 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10333 | // We aren't likely to be able to resolve the identifier down to a type |
| 10334 | // now anyway, so just retain the identifier. |
| 10335 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 10336 | E->getDestroyedTypeLoc()); |
| 10337 | } else { |
| 10338 | // Look for a destructor known with the given name. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10339 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10340 | *E->getDestroyedTypeIdentifier(), |
| 10341 | E->getDestroyedTypeLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10342 | /*Scope=*/nullptr, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10343 | SS, ObjectTypePtr, |
| 10344 | false); |
| 10345 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10346 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10347 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10348 | Destroyed |
| 10349 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 10350 | E->getDestroyedTypeLoc()); |
| 10351 | } |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10352 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10353 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10354 | if (E->getScopeTypeInfo()) { |
| Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 10355 | CXXScopeSpec EmptySS; |
| 10356 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10357 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10358 | if (!ScopeTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10359 | return ExprError(); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10360 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10361 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10362 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10363 | E->getOperatorLoc(), |
| 10364 | E->isArrow(), |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10365 | SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10366 | ScopeTypeInfo, |
| 10367 | E->getColonColonLoc(), |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10368 | E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10369 | Destroyed); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10370 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10371 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10372 | template <typename Derived> |
| 10373 | bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, |
| 10374 | bool RequiresADL, |
| 10375 | LookupResult &R) { |
| 10376 | // Transform all the decls. |
| 10377 | bool AllEmptyPacks = true; |
| 10378 | for (auto *OldD : Old->decls()) { |
| 10379 | Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); |
| 10380 | if (!InstD) { |
| 10381 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 10382 | // This can happen because of dependent hiding. |
| 10383 | if (isa<UsingShadowDecl>(OldD)) |
| 10384 | continue; |
| 10385 | else { |
| 10386 | R.clear(); |
| 10387 | return true; |
| 10388 | } |
| 10389 | } |
| 10390 | |
| 10391 | // Expand using pack declarations. |
| 10392 | NamedDecl *SingleDecl = cast<NamedDecl>(InstD); |
| 10393 | ArrayRef<NamedDecl*> Decls = SingleDecl; |
| 10394 | if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) |
| 10395 | Decls = UPD->expansions(); |
| 10396 | |
| 10397 | // Expand using declarations. |
| 10398 | for (auto *D : Decls) { |
| 10399 | if (auto *UD = dyn_cast<UsingDecl>(D)) { |
| 10400 | for (auto *SD : UD->shadows()) |
| 10401 | R.addDecl(SD); |
| 10402 | } else { |
| 10403 | R.addDecl(D); |
| 10404 | } |
| 10405 | } |
| 10406 | |
| 10407 | AllEmptyPacks &= Decls.empty(); |
| 10408 | }; |
| 10409 | |
| 10410 | // C++ [temp.res]/8.4.2: |
| 10411 | // The program is ill-formed, no diagnostic required, if [...] lookup for |
| 10412 | // a name in the template definition found a using-declaration, but the |
| 10413 | // lookup in the corresponding scope in the instantiation odoes not find |
| 10414 | // any declarations because the using-declaration was a pack expansion and |
| 10415 | // the corresponding pack is empty |
| 10416 | if (AllEmptyPacks && !RequiresADL) { |
| 10417 | getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) |
| Richard Trieu | b402580 | 2018-03-28 04:16:13 +0000 | [diff] [blame] | 10418 | << isa<UnresolvedMemberExpr>(Old) << Old->getName(); |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10419 | return true; |
| 10420 | } |
| 10421 | |
| 10422 | // Resolve a kind, but don't do any further analysis. If it's |
| 10423 | // ambiguous, the callee needs to deal with it. |
| 10424 | R.resolveKind(); |
| 10425 | return false; |
| 10426 | } |
| 10427 | |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10428 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10429 | ExprResult |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10430 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10431 | UnresolvedLookupExpr *Old) { |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10432 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 10433 | Sema::LookupOrdinaryName); |
| 10434 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10435 | // Transform the declaration set. |
| 10436 | if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) |
| 10437 | return ExprError(); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10438 | |
| 10439 | // Rebuild the nested-name qualifier, if present. |
| 10440 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10441 | if (Old->getQualifierLoc()) { |
| 10442 | NestedNameSpecifierLoc QualifierLoc |
| 10443 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 10444 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10445 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10446 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10447 | SS.Adopt(QualifierLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10448 | } |
| 10449 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10450 | if (Old->getNamingClass()) { |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10451 | CXXRecordDecl *NamingClass |
| 10452 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 10453 | Old->getNameLoc(), |
| 10454 | Old->getNamingClass())); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10455 | if (!NamingClass) { |
| 10456 | R.clear(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10457 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10458 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10459 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10460 | R.setNamingClass(NamingClass); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10461 | } |
| 10462 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10463 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 10464 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10465 | // If we have neither explicit template arguments, nor the template keyword, |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10466 | // it's a normal declaration name or member reference. |
| 10467 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 10468 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 10469 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 10470 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 10471 | // give a good diagnostic. |
| 10472 | if (D && D->isCXXInstanceMember()) { |
| 10473 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 10474 | /*TemplateArgs=*/nullptr, |
| 10475 | /*Scope=*/nullptr); |
| 10476 | } |
| 10477 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10478 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10479 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10480 | |
| 10481 | // If we have template arguments, rebuild them, then rebuild the |
| 10482 | // templateid expression. |
| 10483 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 10484 | if (Old->hasExplicitTemplateArgs() && |
| 10485 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10486 | Old->getNumTemplateArgs(), |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10487 | TransArgs)) { |
| 10488 | R.clear(); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10489 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10490 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10491 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10492 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10493 | Old->requiresADL(), &TransArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10494 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10495 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10496 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10497 | ExprResult |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10498 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 10499 | bool ArgChanged = false; |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10500 | SmallVector<TypeSourceInfo *, 4> Args; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10501 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 10502 | TypeSourceInfo *From = E->getArg(I); |
| 10503 | TypeLoc FromTL = From->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10504 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10505 | TypeLocBuilder TLB; |
| 10506 | TLB.reserve(FromTL.getFullDataSize()); |
| 10507 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 10508 | if (To.isNull()) |
| 10509 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10510 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10511 | if (To == From->getType()) |
| 10512 | Args.push_back(From); |
| 10513 | else { |
| 10514 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10515 | ArgChanged = true; |
| 10516 | } |
| 10517 | continue; |
| 10518 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10519 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10520 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10521 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10522 | // We have a pack expansion. Instantiate it. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10523 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10524 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 10525 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10526 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10527 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10528 | // Determine whether the set of unexpanded parameter packs can and should |
| 10529 | // be expanded. |
| 10530 | bool Expand = true; |
| 10531 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10532 | Optional<unsigned> OrigNumExpansions = |
| 10533 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 10534 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10535 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 10536 | PatternTL.getSourceRange(), |
| 10537 | Unexpanded, |
| 10538 | Expand, RetainExpansion, |
| 10539 | NumExpansions)) |
| 10540 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10541 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10542 | if (!Expand) { |
| 10543 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10544 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10545 | // expansion. |
| 10546 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10547 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10548 | TypeLocBuilder TLB; |
| 10549 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 10550 | |
| 10551 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10552 | if (To.isNull()) |
| 10553 | return ExprError(); |
| 10554 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10555 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10556 | PatternTL.getSourceRange(), |
| 10557 | ExpansionTL.getEllipsisLoc(), |
| 10558 | NumExpansions); |
| 10559 | if (To.isNull()) |
| 10560 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10561 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10562 | PackExpansionTypeLoc ToExpansionTL |
| 10563 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10564 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10565 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10566 | continue; |
| 10567 | } |
| 10568 | |
| 10569 | // Expand the pack expansion by substituting for each argument in the |
| 10570 | // pack(s). |
| 10571 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10572 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 10573 | TypeLocBuilder TLB; |
| 10574 | TLB.reserve(PatternTL.getFullDataSize()); |
| 10575 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10576 | if (To.isNull()) |
| 10577 | return ExprError(); |
| 10578 | |
| Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 10579 | if (To->containsUnexpandedParameterPack()) { |
| 10580 | To = getDerived().RebuildPackExpansionType(To, |
| 10581 | PatternTL.getSourceRange(), |
| 10582 | ExpansionTL.getEllipsisLoc(), |
| 10583 | NumExpansions); |
| 10584 | if (To.isNull()) |
| 10585 | return ExprError(); |
| 10586 | |
| 10587 | PackExpansionTypeLoc ToExpansionTL |
| 10588 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10589 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10590 | } |
| 10591 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10592 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10593 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10594 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10595 | if (!RetainExpansion) |
| 10596 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10597 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10598 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 10599 | // forgetting the partially-substituted parameter pack. |
| 10600 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10601 | |
| 10602 | TypeLocBuilder TLB; |
| 10603 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10604 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10605 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10606 | if (To.isNull()) |
| 10607 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10608 | |
| 10609 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10610 | PatternTL.getSourceRange(), |
| 10611 | ExpansionTL.getEllipsisLoc(), |
| 10612 | NumExpansions); |
| 10613 | if (To.isNull()) |
| 10614 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10615 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10616 | PackExpansionTypeLoc ToExpansionTL |
| 10617 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10618 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10619 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10620 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10621 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10622 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10623 | return E; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10624 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10625 | return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10626 | E->getEndLoc()); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10627 | } |
| 10628 | |
| 10629 | template<typename Derived> |
| 10630 | ExprResult |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10631 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 10632 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 10633 | if (!T) |
| 10634 | return ExprError(); |
| 10635 | |
| 10636 | if (!getDerived().AlwaysRebuild() && |
| 10637 | T == E->getQueriedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10638 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10639 | |
| 10640 | ExprResult SubExpr; |
| 10641 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10642 | EnterExpressionEvaluationContext Unevaluated( |
| 10643 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10644 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 10645 | if (SubExpr.isInvalid()) |
| 10646 | return ExprError(); |
| 10647 | |
| 10648 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10649 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10650 | } |
| 10651 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10652 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10653 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10654 | } |
| 10655 | |
| 10656 | template<typename Derived> |
| 10657 | ExprResult |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10658 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 10659 | ExprResult SubExpr; |
| 10660 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10661 | EnterExpressionEvaluationContext Unevaluated( |
| 10662 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10663 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 10664 | if (SubExpr.isInvalid()) |
| 10665 | return ExprError(); |
| 10666 | |
| 10667 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10668 | return E; |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10669 | } |
| 10670 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10671 | return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10672 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10673 | } |
| 10674 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 10675 | template <typename Derived> |
| 10676 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 10677 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 10678 | TypeSourceInfo **RecoveryTSI) { |
| 10679 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 10680 | DRE, AddrTaken, RecoveryTSI); |
| 10681 | |
| 10682 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 10683 | if (!NewDRE.isUsable()) |
| 10684 | return NewDRE; |
| 10685 | |
| 10686 | // We got an expr, wrap it up in parens. |
| 10687 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 10688 | return PE; |
| 10689 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 10690 | PE->getRParen()); |
| 10691 | } |
| 10692 | |
| 10693 | template <typename Derived> |
| 10694 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 10695 | DependentScopeDeclRefExpr *E) { |
| 10696 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 10697 | nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 10698 | } |
| 10699 | |
| 10700 | template<typename Derived> |
| 10701 | ExprResult |
| 10702 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 10703 | DependentScopeDeclRefExpr *E, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 10704 | bool IsAddressOfOperand, |
| 10705 | TypeSourceInfo **RecoveryTSI) { |
| Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 10706 | assert(E->getQualifierLoc()); |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 10707 | NestedNameSpecifierLoc QualifierLoc |
| 10708 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 10709 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10710 | return ExprError(); |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10711 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10712 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10713 | // TODO: If this is a conversion-function-id, verify that the |
| 10714 | // destination type name (if present) resolves the same way after |
| 10715 | // instantiation as it did in the local scope. |
| 10716 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10717 | DeclarationNameInfo NameInfo |
| 10718 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 10719 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10720 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10721 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10722 | if (!E->hasExplicitTemplateArgs()) { |
| 10723 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 10724 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 10725 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 10726 | // if name has not changed, DNLoc has not changed either. |
| 10727 | NameInfo.getName() == E->getDeclName()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10728 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10729 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 10730 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 10731 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 10732 | IsAddressOfOperand, RecoveryTSI); |
| Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 10733 | } |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 10734 | |
| 10735 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10736 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 10737 | E->getNumTemplateArgs(), |
| 10738 | TransArgs)) |
| 10739 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10740 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 10741 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 10742 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 10743 | RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10744 | } |
| 10745 | |
| 10746 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10747 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10748 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 10749 | // CXXConstructExprs other than for list-initialization and |
| 10750 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 10751 | // a 1-argument construction we just transform that argument. |
| Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 10752 | if ((E->getNumArgs() == 1 || |
| 10753 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 10754 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 10755 | !E->isListInitialization()) |
| Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 10756 | return getDerived().TransformExpr(E->getArg(0)); |
| 10757 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10758 | TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10759 | |
| 10760 | QualType T = getDerived().TransformType(E->getType()); |
| 10761 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10762 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10763 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10764 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 10765 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10766 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10767 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10768 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10769 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10770 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10771 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10772 | &ArgumentChanged)) |
| 10773 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10774 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10775 | if (!getDerived().AlwaysRebuild() && |
| 10776 | T == E->getType() && |
| 10777 | Constructor == E->getConstructor() && |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 10778 | !ArgumentChanged) { |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10779 | // Mark the constructor as referenced. |
| 10780 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10781 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10782 | return E; |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 10783 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10784 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10785 | return getDerived().RebuildCXXConstructExpr( |
| 10786 | T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, |
| 10787 | E->hadMultipleCandidates(), E->isListInitialization(), |
| 10788 | E->isStdInitListInitialization(), E->requiresZeroInitialization(), |
| 10789 | E->getConstructionKind(), E->getParenOrBraceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10790 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10791 | |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 10792 | template<typename Derived> |
| 10793 | ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 10794 | CXXInheritedCtorInitExpr *E) { |
| 10795 | QualType T = getDerived().TransformType(E->getType()); |
| 10796 | if (T.isNull()) |
| 10797 | return ExprError(); |
| 10798 | |
| 10799 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10800 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 10801 | if (!Constructor) |
| 10802 | return ExprError(); |
| 10803 | |
| 10804 | if (!getDerived().AlwaysRebuild() && |
| 10805 | T == E->getType() && |
| 10806 | Constructor == E->getConstructor()) { |
| 10807 | // Mark the constructor as referenced. |
| 10808 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10809 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 10810 | return E; |
| 10811 | } |
| 10812 | |
| 10813 | return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 10814 | T, E->getLocation(), Constructor, |
| 10815 | E->constructsVBase(), E->inheritedFromVBase()); |
| 10816 | } |
| 10817 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10818 | /// Transform a C++ temporary-binding expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10819 | /// |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10820 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 10821 | /// transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10822 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10823 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10824 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10825 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10826 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10827 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10828 | /// Transform a C++ expression that contains cleanups that should |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 10829 | /// be run after the expression is evaluated. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10830 | /// |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 10831 | /// Since ExprWithCleanups nodes are implicitly generated, we |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10832 | /// just transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10833 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10834 | ExprResult |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 10835 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 10836 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10837 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10838 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10839 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10840 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10841 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10842 | CXXTemporaryObjectExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10843 | TypeSourceInfo *T = |
| 10844 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10845 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10846 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10847 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10848 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 10849 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10850 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10851 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10852 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10853 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10854 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10855 | Args.reserve(E->getNumArgs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10856 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10857 | &ArgumentChanged)) |
| 10858 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10859 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10860 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10861 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10862 | Constructor == E->getConstructor() && |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 10863 | !ArgumentChanged) { |
| 10864 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10865 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 10866 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 10867 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10868 | |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 10869 | // FIXME: We should just pass E->isListInitialization(), but we're not |
| 10870 | // prepared to handle list-initialization without a child InitListExpr. |
| 10871 | SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); |
| 10872 | return getDerived().RebuildCXXTemporaryObjectExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10873 | T, LParenLoc, Args, E->getEndLoc(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 10874 | /*ListInitialization=*/LParenLoc.isInvalid()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10875 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10876 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10877 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10878 | ExprResult |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 10879 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10880 | // Transform any init-capture expressions before entering the scope of the |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10881 | // lambda body, because they are not semantically within that scope. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10882 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10883 | SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes; |
| 10884 | InitCaptureExprsAndTypes.resize(E->explicit_capture_end() - |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10885 | E->explicit_capture_begin()); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10886 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10887 | CEnd = E->capture_end(); |
| 10888 | C != CEnd; ++C) { |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 10889 | if (!E->isInitCapture(C)) |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10890 | continue; |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10891 | EnterExpressionEvaluationContext EEEC( |
| 10892 | getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10893 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 10894 | C->getCapturedVar()->getInit(), |
| 10895 | C->getCapturedVar()->getInitStyle() == VarDecl::CallInit); |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10896 | |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10897 | if (NewExprInitResult.isInvalid()) |
| 10898 | return ExprError(); |
| 10899 | Expr *NewExprInit = NewExprInitResult.get(); |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10900 | |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10901 | VarDecl *OldVD = C->getCapturedVar(); |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10902 | QualType NewInitCaptureType = |
| Richard Smith | 42b1057 | 2015-11-11 01:36:17 +0000 | [diff] [blame] | 10903 | getSema().buildLambdaInitCaptureInitialization( |
| 10904 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 10905 | OldVD->getIdentifier(), |
| 10906 | C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10907 | NewExprInitResult = NewExprInit; |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10908 | InitCaptureExprsAndTypes[C - E->capture_begin()] = |
| 10909 | std::make_pair(NewExprInitResult, NewInitCaptureType); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 10910 | } |
| 10911 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10912 | // Transform the template parameters, and add them to the current |
| 10913 | // instantiation scope. The null case is handled correctly. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10914 | auto TPL = getDerived().TransformTemplateParameterList( |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10915 | E->getTemplateParameterList()); |
| 10916 | |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10917 | // Transform the type of the original lambda's call operator. |
| 10918 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 10919 | // it introduces a mapping of the original to the newly created |
| 10920 | // transformed parameters. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10921 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10922 | { |
| 10923 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 10924 | FunctionProtoTypeLoc OldCallOpFPTL = |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10925 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10926 | |
| 10927 | TypeLocBuilder NewCallOpTLBuilder; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10928 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 10929 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10930 | QualType NewCallOpType = TransformFunctionProtoType( |
| 10931 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0, |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 10932 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 10933 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 10934 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 10935 | }); |
| Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 10936 | if (NewCallOpType.isNull()) |
| 10937 | return ExprError(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10938 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 10939 | NewCallOpType); |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 10940 | } |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10941 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10942 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 10943 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 10944 | LSI->GLTemplateParameterList = TPL; |
| 10945 | |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 10946 | // Create the local class that will describe the lambda. |
| 10947 | CXXRecordDecl *Class |
| 10948 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10949 | NewCallOpTSI, |
| Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 10950 | /*KnownDependent=*/false, |
| 10951 | E->getCaptureDefault()); |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 10952 | getDerived().transformedLocalDecl(E->getLambdaClass(), Class); |
| 10953 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10954 | // Build the call operator. |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 10955 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 10956 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10957 | E->getCallOperator()->getEndLoc(), |
| Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 10958 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), |
| 10959 | E->getCallOperator()->isConstexpr()); |
| 10960 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10961 | LSI->CallOperator = NewCallOperator; |
| Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 10962 | |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 10963 | for (unsigned I = 0, NumParams = NewCallOperator->getNumParams(); |
| 10964 | I != NumParams; ++I) { |
| 10965 | auto *P = NewCallOperator->getParamDecl(I); |
| 10966 | if (P->hasUninstantiatedDefaultArg()) { |
| 10967 | EnterExpressionEvaluationContext Eval( |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10968 | getSema(), |
| 10969 | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P); |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 10970 | ExprResult R = getDerived().TransformExpr( |
| 10971 | E->getCallOperator()->getParamDecl(I)->getDefaultArg()); |
| 10972 | P->setDefaultArg(R.get()); |
| 10973 | } |
| 10974 | } |
| 10975 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 10976 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10977 | getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 10978 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10979 | // Introduce the context of the call operator. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10980 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
| Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 10981 | /*NewThisContext*/false); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 10982 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10983 | // Enter the scope of the lambda. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 10984 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 10985 | E->getIntroducerRange(), |
| 10986 | E->getCaptureDefault(), |
| 10987 | E->getCaptureDefaultLoc(), |
| 10988 | E->hasExplicitParameters(), |
| 10989 | E->hasExplicitResultType(), |
| 10990 | E->isMutable()); |
| 10991 | |
| 10992 | bool Invalid = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10993 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10994 | // Transform captures. |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10995 | bool FinishedExplicitCaptures = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10996 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 10997 | CEnd = E->capture_end(); |
| 10998 | C != CEnd; ++C) { |
| 10999 | // When we hit the first implicit capture, tell Sema that we've finished |
| 11000 | // the list of explicit captures. |
| 11001 | if (!FinishedExplicitCaptures && C->isImplicit()) { |
| 11002 | getSema().finishLambdaExplicitCaptures(LSI); |
| 11003 | FinishedExplicitCaptures = true; |
| 11004 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11005 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11006 | // Capturing 'this' is trivial. |
| 11007 | if (C->capturesThis()) { |
| Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 11008 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 11009 | /*BuildAndDiagnose*/ true, nullptr, |
| 11010 | C->getCaptureKind() == LCK_StarThis); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11011 | continue; |
| 11012 | } |
| Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 11013 | // Captured expression will be recaptured during captured variables |
| 11014 | // rebuilding. |
| 11015 | if (C->capturesVLAType()) |
| 11016 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11017 | |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11018 | // Rebuild init-captures, including the implied field declaration. |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 11019 | if (E->isInitCapture(C)) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 11020 | InitCaptureInfoTy InitExprTypePair = |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11021 | InitCaptureExprsAndTypes[C - E->capture_begin()]; |
| 11022 | ExprResult Init = InitExprTypePair.first; |
| 11023 | QualType InitQualType = InitExprTypePair.second; |
| 11024 | if (Init.isInvalid() || InitQualType.isNull()) { |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11025 | Invalid = true; |
| 11026 | continue; |
| 11027 | } |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11028 | VarDecl *OldVD = C->getCapturedVar(); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11029 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| Richard Smith | 42b1057 | 2015-11-11 01:36:17 +0000 | [diff] [blame] | 11030 | OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(), |
| 11031 | OldVD->getInitStyle(), Init.get()); |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11032 | if (!NewVD) |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11033 | Invalid = true; |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11034 | else { |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11035 | getDerived().transformedLocalDecl(OldVD, NewVD); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11036 | } |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11037 | getSema().buildInitCaptureField(LSI, NewVD); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11038 | continue; |
| 11039 | } |
| 11040 | |
| 11041 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 11042 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11043 | // Determine the capture kind for Sema. |
| 11044 | Sema::TryCaptureKind Kind |
| 11045 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 11046 | : C->getCaptureKind() == LCK_ByCopy |
| 11047 | ? Sema::TryCapture_ExplicitByVal |
| 11048 | : Sema::TryCapture_ExplicitByRef; |
| 11049 | SourceLocation EllipsisLoc; |
| 11050 | if (C->isPackExpansion()) { |
| 11051 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 11052 | bool ShouldExpand = false; |
| 11053 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 11054 | Optional<unsigned> NumExpansions; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11055 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 11056 | C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11057 | Unexpanded, |
| 11058 | ShouldExpand, RetainExpansion, |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11059 | NumExpansions)) { |
| 11060 | Invalid = true; |
| 11061 | continue; |
| 11062 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11063 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11064 | if (ShouldExpand) { |
| 11065 | // The transform has determined that we should perform an expansion; |
| 11066 | // transform and capture each of the arguments. |
| 11067 | // expansion of the pattern. Do so. |
| 11068 | VarDecl *Pack = C->getCapturedVar(); |
| 11069 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11070 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11071 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11072 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11073 | Pack)); |
| 11074 | if (!CapturedVar) { |
| 11075 | Invalid = true; |
| 11076 | continue; |
| 11077 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11078 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11079 | // Capture the transformed variable. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11080 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 11081 | } |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 11082 | |
| 11083 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 11084 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11085 | continue; |
| 11086 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11087 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11088 | EllipsisLoc = C->getEllipsisLoc(); |
| 11089 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11090 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11091 | // Transform the captured variable. |
| 11092 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11093 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11094 | C->getCapturedVar())); |
| Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 11095 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11096 | Invalid = true; |
| 11097 | continue; |
| 11098 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11099 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11100 | // Capture the transformed variable. |
| Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 11101 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 11102 | EllipsisLoc); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11103 | } |
| 11104 | if (!FinishedExplicitCaptures) |
| 11105 | getSema().finishLambdaExplicitCaptures(LSI); |
| 11106 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11107 | // Enter a new evaluation context to insulate the lambda from any |
| 11108 | // cleanups from the enclosing full-expression. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11109 | getSema().PushExpressionEvaluationContext( |
| 11110 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11111 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11112 | // Instantiate the body of the lambda expression. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11113 | StmtResult Body = |
| 11114 | Invalid ? StmtError() : getDerived().TransformStmt(E->getBody()); |
| 11115 | |
| 11116 | // ActOnLambda* will pop the function scope for us. |
| 11117 | FuncScopeCleanup.disable(); |
| 11118 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11119 | if (Body.isInvalid()) { |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11120 | SavedContext.pop(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11121 | getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11122 | /*IsInstantiation=*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11123 | return ExprError(); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11124 | } |
| Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 11125 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11126 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 11127 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 11128 | // the call operator. |
| 11129 | auto LSICopy = *LSI; |
| 11130 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 11131 | /*IsInstantiation*/ true); |
| 11132 | SavedContext.pop(); |
| 11133 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11134 | return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11135 | &LSICopy); |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11136 | } |
| 11137 | |
| 11138 | template<typename Derived> |
| 11139 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11140 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11141 | CXXUnresolvedConstructExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 11142 | TypeSourceInfo *T = |
| 11143 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11144 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11145 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11146 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11147 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11148 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11149 | Args.reserve(E->arg_size()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11150 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11151 | &ArgumentChanged)) |
| 11152 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11153 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11154 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11155 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11156 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11157 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11158 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11159 | // FIXME: we're faking the locations of the commas |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11160 | return getDerived().RebuildCXXUnresolvedConstructExpr( |
| 11161 | T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11162 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11163 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11164 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11165 | ExprResult |
| John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 11166 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11167 | CXXDependentScopeMemberExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11168 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11169 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11170 | Expr *OldBase; |
| 11171 | QualType BaseType; |
| 11172 | QualType ObjectType; |
| 11173 | if (!E->isImplicitAccess()) { |
| 11174 | OldBase = E->getBase(); |
| 11175 | Base = getDerived().TransformExpr(OldBase); |
| 11176 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11177 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11178 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11179 | // Start the member reference and compute the object's type. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11180 | ParsedType ObjectTy; |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11181 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11182 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11183 | E->getOperatorLoc(), |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11184 | E->isArrow()? tok::arrow : tok::period, |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11185 | ObjectTy, |
| 11186 | MayBePseudoDestructor); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11187 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11188 | return ExprError(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11189 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11190 | ObjectType = ObjectTy.get(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11191 | BaseType = ((Expr*) Base.get())->getType(); |
| 11192 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11193 | OldBase = nullptr; |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11194 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 11195 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 11196 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11197 | |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11198 | // Transform the first part of the nested-name-specifier that qualifies |
| 11199 | // the member name. |
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 11200 | NamedDecl *FirstQualifierInScope |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11201 | = getDerived().TransformFirstQualifierInScope( |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11202 | E->getFirstQualifierFoundInScope(), |
| 11203 | E->getQualifierLoc().getBeginLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11204 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11205 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11206 | if (E->getQualifier()) { |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11207 | QualifierLoc |
| 11208 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 11209 | ObjectType, |
| 11210 | FirstQualifierInScope); |
| 11211 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11212 | return ExprError(); |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11213 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11214 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11215 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 11216 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11217 | // TODO: If this is a conversion-function-id, verify that the |
| 11218 | // destination type name (if present) resolves the same way after |
| 11219 | // instantiation as it did in the local scope. |
| 11220 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11221 | DeclarationNameInfo NameInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11222 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11223 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11224 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11225 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11226 | if (!E->hasExplicitTemplateArgs()) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11227 | // This is a reference to a member without an explicitly-specified |
| 11228 | // template argument list. Optimize for this common case. |
| 11229 | if (!getDerived().AlwaysRebuild() && |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11230 | Base.get() == OldBase && |
| 11231 | BaseType == E->getBaseType() && |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11232 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11233 | NameInfo.getName() == E->getMember() && |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11234 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11235 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11236 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11237 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11238 | BaseType, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11239 | E->isArrow(), |
| 11240 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11241 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11242 | TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11243 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11244 | NameInfo, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11245 | /*TemplateArgs*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11246 | } |
| 11247 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11248 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11249 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 11250 | E->getNumTemplateArgs(), |
| 11251 | TransArgs)) |
| 11252 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11253 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11254 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11255 | BaseType, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11256 | E->isArrow(), |
| 11257 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11258 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11259 | TemplateKWLoc, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11260 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11261 | NameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11262 | &TransArgs); |
| 11263 | } |
| 11264 | |
| 11265 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11266 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11267 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11268 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11269 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11270 | QualType BaseType; |
| 11271 | if (!Old->isImplicitAccess()) { |
| 11272 | Base = getDerived().TransformExpr(Old->getBase()); |
| 11273 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11274 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11275 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 11276 | Old->isArrow()); |
| 11277 | if (Base.isInvalid()) |
| 11278 | return ExprError(); |
| 11279 | BaseType = Base.get()->getType(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11280 | } else { |
| 11281 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 11282 | } |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11283 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11284 | NestedNameSpecifierLoc QualifierLoc; |
| 11285 | if (Old->getQualifierLoc()) { |
| 11286 | QualifierLoc |
| 11287 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 11288 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11289 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11290 | } |
| 11291 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11292 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 11293 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11294 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11295 | Sema::LookupOrdinaryName); |
| 11296 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 11297 | // Transform the declaration set. |
| 11298 | if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R)) |
| 11299 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11300 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11301 | // Determine the naming class. |
| Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 11302 | if (Old->getNamingClass()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11303 | CXXRecordDecl *NamingClass |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11304 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11305 | Old->getMemberLoc(), |
| 11306 | Old->getNamingClass())); |
| 11307 | if (!NamingClass) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11308 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11309 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11310 | R.setNamingClass(NamingClass); |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11311 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11312 | |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11313 | TemplateArgumentListInfo TransArgs; |
| 11314 | if (Old->hasExplicitTemplateArgs()) { |
| 11315 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 11316 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11317 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 11318 | Old->getNumTemplateArgs(), |
| 11319 | TransArgs)) |
| 11320 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11321 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11322 | |
| 11323 | // FIXME: to do this check properly, we will need to preserve the |
| 11324 | // first-qualifier-in-scope here, just in case we had a dependent |
| 11325 | // base (and therefore couldn't do the check) and a |
| 11326 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11327 | NamedDecl *FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11328 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11329 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11330 | BaseType, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11331 | Old->getOperatorLoc(), |
| 11332 | Old->isArrow(), |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11333 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11334 | TemplateKWLoc, |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11335 | FirstQualifierInScope, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11336 | R, |
| 11337 | (Old->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11338 | ? &TransArgs : nullptr)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11339 | } |
| 11340 | |
| 11341 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11342 | ExprResult |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11343 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11344 | EnterExpressionEvaluationContext Unevaluated( |
| 11345 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11346 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 11347 | if (SubExpr.isInvalid()) |
| 11348 | return ExprError(); |
| 11349 | |
| 11350 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11351 | return E; |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11352 | |
| 11353 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 11354 | } |
| 11355 | |
| 11356 | template<typename Derived> |
| 11357 | ExprResult |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11358 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11359 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 11360 | if (Pattern.isInvalid()) |
| 11361 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11362 | |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11363 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11364 | return E; |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11365 | |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 11366 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 11367 | E->getNumExpansions()); |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11368 | } |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11369 | |
| 11370 | template<typename Derived> |
| 11371 | ExprResult |
| 11372 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 11373 | // If E is not value-dependent, then nothing will change when we transform it. |
| 11374 | // Note: This is an instantiation-centric view. |
| 11375 | if (!E->isValueDependent()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11376 | return E; |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11377 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11378 | EnterExpressionEvaluationContext Unevaluated( |
| 11379 | getSema(), Sema::ExpressionEvaluationContext::Unevaluated); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11380 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11381 | ArrayRef<TemplateArgument> PackArgs; |
| 11382 | TemplateArgument ArgStorage; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11383 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11384 | // Find the argument list to transform. |
| 11385 | if (E->isPartiallySubstituted()) { |
| 11386 | PackArgs = E->getPartialArguments(); |
| 11387 | } else if (E->isValueDependent()) { |
| 11388 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 11389 | bool ShouldExpand = false; |
| 11390 | bool RetainExpansion = false; |
| 11391 | Optional<unsigned> NumExpansions; |
| 11392 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 11393 | Unexpanded, |
| 11394 | ShouldExpand, RetainExpansion, |
| 11395 | NumExpansions)) |
| 11396 | return ExprError(); |
| 11397 | |
| 11398 | // If we need to expand the pack, build a template argument from it and |
| 11399 | // expand that. |
| 11400 | if (ShouldExpand) { |
| 11401 | auto *Pack = E->getPack(); |
| 11402 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 11403 | ArgStorage = getSema().Context.getPackExpansionType( |
| 11404 | getSema().Context.getTypeDeclType(TTPD), None); |
| 11405 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 11406 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 11407 | } else { |
| 11408 | auto *VD = cast<ValueDecl>(Pack); |
| Richard Smith | f1f20e6 | 2018-02-14 02:07:53 +0000 | [diff] [blame] | 11409 | ExprResult DRE = getSema().BuildDeclRefExpr( |
| 11410 | VD, VD->getType().getNonLValueExprType(getSema().Context), |
| 11411 | VD->getType()->isReferenceType() ? VK_LValue : VK_RValue, |
| 11412 | E->getPackLoc()); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11413 | if (DRE.isInvalid()) |
| 11414 | return ExprError(); |
| 11415 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 11416 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 11417 | } |
| 11418 | PackArgs = ArgStorage; |
| 11419 | } |
| 11420 | } |
| 11421 | |
| 11422 | // If we're not expanding the pack, just transform the decl. |
| 11423 | if (!PackArgs.size()) { |
| 11424 | auto *Pack = cast_or_null<NamedDecl>( |
| 11425 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11426 | if (!Pack) |
| 11427 | return ExprError(); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11428 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 11429 | E->getPackLoc(), |
| 11430 | E->getRParenLoc(), None, None); |
| 11431 | } |
| 11432 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11433 | // Try to compute the result without performing a partial substitution. |
| 11434 | Optional<unsigned> Result = 0; |
| 11435 | for (const TemplateArgument &Arg : PackArgs) { |
| 11436 | if (!Arg.isPackExpansion()) { |
| 11437 | Result = *Result + 1; |
| 11438 | continue; |
| 11439 | } |
| 11440 | |
| 11441 | TemplateArgumentLoc ArgLoc; |
| 11442 | InventTemplateArgumentLoc(Arg, ArgLoc); |
| 11443 | |
| 11444 | // Find the pattern of the pack expansion. |
| 11445 | SourceLocation Ellipsis; |
| 11446 | Optional<unsigned> OrigNumExpansions; |
| 11447 | TemplateArgumentLoc Pattern = |
| 11448 | getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, |
| 11449 | OrigNumExpansions); |
| 11450 | |
| 11451 | // Substitute under the pack expansion. Do not expand the pack (yet). |
| 11452 | TemplateArgumentLoc OutPattern; |
| 11453 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11454 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, |
| 11455 | /*Uneval*/ true)) |
| 11456 | return true; |
| 11457 | |
| 11458 | // See if we can determine the number of arguments from the result. |
| 11459 | Optional<unsigned> NumExpansions = |
| 11460 | getSema().getFullyPackExpandedSize(OutPattern.getArgument()); |
| 11461 | if (!NumExpansions) { |
| 11462 | // No: we must be in an alias template expansion, and we're going to need |
| 11463 | // to actually expand the packs. |
| 11464 | Result = None; |
| 11465 | break; |
| 11466 | } |
| 11467 | |
| 11468 | Result = *Result + *NumExpansions; |
| 11469 | } |
| 11470 | |
| 11471 | // Common case: we could determine the number of expansions without |
| 11472 | // substituting. |
| 11473 | if (Result) |
| 11474 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11475 | E->getPackLoc(), |
| 11476 | E->getRParenLoc(), *Result, None); |
| 11477 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11478 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 11479 | E->getPackLoc()); |
| 11480 | { |
| 11481 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 11482 | typedef TemplateArgumentLocInventIterator< |
| 11483 | Derived, const TemplateArgument*> PackLocIterator; |
| 11484 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 11485 | PackLocIterator(*this, PackArgs.end()), |
| 11486 | TransformedPackArgs, /*Uneval*/true)) |
| 11487 | return ExprError(); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11488 | } |
| 11489 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11490 | // Check whether we managed to fully-expand the pack. |
| 11491 | // FIXME: Is it possible for us to do so and not hit the early exit path? |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11492 | SmallVector<TemplateArgument, 8> Args; |
| 11493 | bool PartialSubstitution = false; |
| 11494 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 11495 | Args.push_back(Loc.getArgument()); |
| 11496 | if (Loc.getArgument().isPackExpansion()) |
| 11497 | PartialSubstitution = true; |
| 11498 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11499 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11500 | if (PartialSubstitution) |
| 11501 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11502 | E->getPackLoc(), |
| 11503 | E->getRParenLoc(), None, Args); |
| 11504 | |
| 11505 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11506 | E->getPackLoc(), E->getRParenLoc(), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11507 | Args.size(), None); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11508 | } |
| 11509 | |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11510 | template<typename Derived> |
| 11511 | ExprResult |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11512 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 11513 | SubstNonTypeTemplateParmPackExpr *E) { |
| 11514 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11515 | return E; |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11516 | } |
| 11517 | |
| 11518 | template<typename Derived> |
| 11519 | ExprResult |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11520 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 11521 | SubstNonTypeTemplateParmExpr *E) { |
| 11522 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11523 | return E; |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11524 | } |
| 11525 | |
| 11526 | template<typename Derived> |
| 11527 | ExprResult |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 11528 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 11529 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11530 | return E; |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 11531 | } |
| 11532 | |
| 11533 | template<typename Derived> |
| 11534 | ExprResult |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 11535 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 11536 | MaterializeTemporaryExpr *E) { |
| 11537 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 11538 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11539 | |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 11540 | template<typename Derived> |
| 11541 | ExprResult |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11542 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 11543 | Expr *Pattern = E->getPattern(); |
| 11544 | |
| 11545 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11546 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 11547 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 11548 | |
| 11549 | // Determine whether the set of unexpanded parameter packs can and should |
| 11550 | // be expanded. |
| 11551 | bool Expand = true; |
| 11552 | bool RetainExpansion = false; |
| 11553 | Optional<unsigned> NumExpansions; |
| 11554 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 11555 | Pattern->getSourceRange(), |
| 11556 | Unexpanded, |
| 11557 | Expand, RetainExpansion, |
| 11558 | NumExpansions)) |
| 11559 | return true; |
| 11560 | |
| 11561 | if (!Expand) { |
| 11562 | // Do not expand any packs here, just transform and rebuild a fold |
| 11563 | // expression. |
| 11564 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11565 | |
| 11566 | ExprResult LHS = |
| 11567 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 11568 | if (LHS.isInvalid()) |
| 11569 | return true; |
| 11570 | |
| 11571 | ExprResult RHS = |
| 11572 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 11573 | if (RHS.isInvalid()) |
| 11574 | return true; |
| 11575 | |
| 11576 | if (!getDerived().AlwaysRebuild() && |
| 11577 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 11578 | return E; |
| 11579 | |
| 11580 | return getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11581 | E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11582 | RHS.get(), E->getEndLoc()); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11583 | } |
| 11584 | |
| 11585 | // The transform has determined that we should perform an elementwise |
| 11586 | // expansion of the pattern. Do so. |
| 11587 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 11588 | if (Result.isInvalid()) |
| 11589 | return true; |
| 11590 | bool LeftFold = E->isLeftFold(); |
| 11591 | |
| 11592 | // If we're retaining an expansion for a right fold, it is the innermost |
| 11593 | // component and takes the init (if any). |
| 11594 | if (!LeftFold && RetainExpansion) { |
| 11595 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 11596 | |
| 11597 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 11598 | if (Out.isInvalid()) |
| 11599 | return true; |
| 11600 | |
| 11601 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11602 | E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11603 | Result.get(), E->getEndLoc()); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11604 | if (Result.isInvalid()) |
| 11605 | return true; |
| 11606 | } |
| 11607 | |
| 11608 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11609 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 11610 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 11611 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 11612 | if (Out.isInvalid()) |
| 11613 | return true; |
| 11614 | |
| 11615 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 11616 | // We still have a pack; retain a pack expansion for this slice. |
| 11617 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11618 | E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11619 | E->getOperator(), E->getEllipsisLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11620 | LeftFold ? Out.get() : Result.get(), E->getEndLoc()); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11621 | } else if (Result.isUsable()) { |
| 11622 | // We've got down to a single element; build a binary operator. |
| 11623 | Result = getDerived().RebuildBinaryOperator( |
| 11624 | E->getEllipsisLoc(), E->getOperator(), |
| 11625 | LeftFold ? Result.get() : Out.get(), |
| 11626 | LeftFold ? Out.get() : Result.get()); |
| 11627 | } else |
| 11628 | Result = Out; |
| 11629 | |
| 11630 | if (Result.isInvalid()) |
| 11631 | return true; |
| 11632 | } |
| 11633 | |
| 11634 | // If we're retaining an expansion for a left fold, it is the outermost |
| 11635 | // component and takes the complete expansion so far as its init (if any). |
| 11636 | if (LeftFold && RetainExpansion) { |
| 11637 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 11638 | |
| 11639 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 11640 | if (Out.isInvalid()) |
| 11641 | return true; |
| 11642 | |
| 11643 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11644 | E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11645 | Out.get(), E->getEndLoc()); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11646 | if (Result.isInvalid()) |
| 11647 | return true; |
| 11648 | } |
| 11649 | |
| 11650 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 11651 | // then produce a fallback value or error. |
| 11652 | if (Result.isUnset()) |
| 11653 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 11654 | E->getOperator()); |
| 11655 | |
| 11656 | return Result; |
| 11657 | } |
| 11658 | |
| 11659 | template<typename Derived> |
| 11660 | ExprResult |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 11661 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 11662 | CXXStdInitializerListExpr *E) { |
| 11663 | return getDerived().TransformExpr(E->getSubExpr()); |
| 11664 | } |
| 11665 | |
| 11666 | template<typename Derived> |
| 11667 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11668 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11669 | return SemaRef.MaybeBindToTemporary(E); |
| 11670 | } |
| 11671 | |
| 11672 | template<typename Derived> |
| 11673 | ExprResult |
| 11674 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11675 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11676 | } |
| 11677 | |
| 11678 | template<typename Derived> |
| 11679 | ExprResult |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 11680 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 11681 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 11682 | if (SubExpr.isInvalid()) |
| 11683 | return ExprError(); |
| 11684 | |
| 11685 | if (!getDerived().AlwaysRebuild() && |
| 11686 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11687 | return E; |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 11688 | |
| 11689 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11690 | } |
| 11691 | |
| 11692 | template<typename Derived> |
| 11693 | ExprResult |
| 11694 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 11695 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 11696 | SmallVector<Expr *, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11697 | bool ArgChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11698 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11699 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 11700 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11701 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11702 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 11703 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11704 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11705 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 11706 | Elements.data(), |
| 11707 | Elements.size()); |
| 11708 | } |
| 11709 | |
| 11710 | template<typename Derived> |
| 11711 | ExprResult |
| 11712 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11713 | ObjCDictionaryLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11714 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 11715 | SmallVector<ObjCDictionaryElement, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11716 | bool ArgChanged = false; |
| 11717 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 11718 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11719 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11720 | if (OrigElement.isPackExpansion()) { |
| 11721 | // This key/value element is a pack expansion. |
| 11722 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11723 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 11724 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 11725 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 11726 | |
| 11727 | // Determine whether the set of unexpanded parameter packs can |
| 11728 | // and should be expanded. |
| 11729 | bool Expand = true; |
| 11730 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 11731 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 11732 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11733 | SourceRange PatternRange(OrigElement.Key->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11734 | OrigElement.Value->getEndLoc()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11735 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 11736 | PatternRange, Unexpanded, Expand, |
| 11737 | RetainExpansion, NumExpansions)) |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11738 | return ExprError(); |
| 11739 | |
| 11740 | if (!Expand) { |
| 11741 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11742 | // transformation on the pack expansion, producing another pack |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11743 | // expansion. |
| 11744 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11745 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 11746 | if (Key.isInvalid()) |
| 11747 | return ExprError(); |
| 11748 | |
| 11749 | if (Key.get() != OrigElement.Key) |
| 11750 | ArgChanged = true; |
| 11751 | |
| 11752 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 11753 | if (Value.isInvalid()) |
| 11754 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11755 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11756 | if (Value.get() != OrigElement.Value) |
| 11757 | ArgChanged = true; |
| 11758 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11759 | ObjCDictionaryElement Expansion = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11760 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 11761 | }; |
| 11762 | Elements.push_back(Expansion); |
| 11763 | continue; |
| 11764 | } |
| 11765 | |
| 11766 | // Record right away that the argument was changed. This needs |
| 11767 | // to happen even if the array expands to nothing. |
| 11768 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11769 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11770 | // The transform has determined that we should perform an elementwise |
| 11771 | // expansion of the pattern. Do so. |
| 11772 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11773 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11774 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 11775 | if (Key.isInvalid()) |
| 11776 | return ExprError(); |
| 11777 | |
| 11778 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 11779 | if (Value.isInvalid()) |
| 11780 | return ExprError(); |
| 11781 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11782 | ObjCDictionaryElement Element = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11783 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 11784 | }; |
| 11785 | |
| 11786 | // If any unexpanded parameter packs remain, we still have a |
| 11787 | // pack expansion. |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 11788 | // FIXME: Can this really happen? |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11789 | if (Key.get()->containsUnexpandedParameterPack() || |
| 11790 | Value.get()->containsUnexpandedParameterPack()) |
| 11791 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11792 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11793 | Elements.push_back(Element); |
| 11794 | } |
| 11795 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 11796 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 11797 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11798 | // We've finished with this pack expansion. |
| 11799 | continue; |
| 11800 | } |
| 11801 | |
| 11802 | // Transform and check key. |
| 11803 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 11804 | if (Key.isInvalid()) |
| 11805 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11806 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11807 | if (Key.get() != OrigElement.Key) |
| 11808 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11809 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11810 | // Transform and check value. |
| 11811 | ExprResult Value |
| 11812 | = getDerived().TransformExpr(OrigElement.Value); |
| 11813 | if (Value.isInvalid()) |
| 11814 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11815 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11816 | if (Value.get() != OrigElement.Value) |
| 11817 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11818 | |
| 11819 | ObjCDictionaryElement Element = { |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 11820 | Key.get(), Value.get(), SourceLocation(), None |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11821 | }; |
| 11822 | Elements.push_back(Element); |
| 11823 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11824 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 11825 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 11826 | return SemaRef.MaybeBindToTemporary(E); |
| 11827 | |
| 11828 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 11829 | Elements); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11830 | } |
| 11831 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11832 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11833 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11834 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 11835 | TypeSourceInfo *EncodedTypeInfo |
| 11836 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 11837 | if (!EncodedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11838 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11839 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11840 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 11841 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11842 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11843 | |
| 11844 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 11845 | EncodedTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11846 | E->getRParenLoc()); |
| 11847 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11848 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11849 | template<typename Derived> |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11850 | ExprResult TreeTransform<Derived>:: |
| 11851 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 11852 | // This is a kind of implicit conversion, and it needs to get dropped |
| 11853 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 11854 | // do, as well a more specific one: this expression is only valid when |
| 11855 | // it appears *immediately* as an argument expression. |
| 11856 | return getDerived().TransformExpr(E->getSubExpr()); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11857 | } |
| 11858 | |
| 11859 | template<typename Derived> |
| 11860 | ExprResult TreeTransform<Derived>:: |
| 11861 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11862 | TypeSourceInfo *TSInfo |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11863 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 11864 | if (!TSInfo) |
| 11865 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11866 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11867 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11868 | if (Result.isInvalid()) |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11869 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11870 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11871 | if (!getDerived().AlwaysRebuild() && |
| 11872 | TSInfo == E->getTypeInfoAsWritten() && |
| 11873 | Result.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11874 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11875 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11876 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11877 | E->getBridgeKeywordLoc(), TSInfo, |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11878 | Result.get()); |
| 11879 | } |
| 11880 | |
| Erik Pilkington | 29099de | 2016-07-16 00:35:23 +0000 | [diff] [blame] | 11881 | template <typename Derived> |
| 11882 | ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( |
| 11883 | ObjCAvailabilityCheckExpr *E) { |
| 11884 | return E; |
| 11885 | } |
| 11886 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11887 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11888 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11889 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11890 | // Transform arguments. |
| 11891 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11892 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11893 | Args.reserve(E->getNumArgs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11894 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11895 | &ArgChanged)) |
| 11896 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11897 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11898 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 11899 | // Class message: transform the receiver type. |
| 11900 | TypeSourceInfo *ReceiverTypeInfo |
| 11901 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 11902 | if (!ReceiverTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11903 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11904 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11905 | // If nothing changed, just retain the existing message send. |
| 11906 | if (!getDerived().AlwaysRebuild() && |
| 11907 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 11908 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11909 | |
| 11910 | // Build a new class message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11911 | SmallVector<SourceLocation, 16> SelLocs; |
| 11912 | E->getSelectorLocs(SelLocs); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11913 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 11914 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11915 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11916 | E->getMethodDecl(), |
| 11917 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11918 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11919 | E->getRightLoc()); |
| 11920 | } |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 11921 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 11922 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| Bruno Cardoso Lopes | 25f02cf | 2016-08-22 21:50:22 +0000 | [diff] [blame] | 11923 | if (!E->getMethodDecl()) |
| 11924 | return ExprError(); |
| 11925 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 11926 | // Build a new class message send to 'super'. |
| 11927 | SmallVector<SourceLocation, 16> SelLocs; |
| 11928 | E->getSelectorLocs(SelLocs); |
| 11929 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 11930 | E->getSelector(), |
| 11931 | SelLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 11932 | E->getReceiverType(), |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 11933 | E->getMethodDecl(), |
| 11934 | E->getLeftLoc(), |
| 11935 | Args, |
| 11936 | E->getRightLoc()); |
| 11937 | } |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11938 | |
| 11939 | // Instance message: transform the receiver |
| 11940 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 11941 | "Only class and instance messages may be instantiated"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11942 | ExprResult Receiver |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11943 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 11944 | if (Receiver.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11945 | return ExprError(); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11946 | |
| 11947 | // If nothing changed, just retain the existing message send. |
| 11948 | if (!getDerived().AlwaysRebuild() && |
| 11949 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 11950 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11951 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11952 | // Build a new instance message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11953 | SmallVector<SourceLocation, 16> SelLocs; |
| 11954 | E->getSelectorLocs(SelLocs); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11955 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11956 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 11957 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11958 | E->getMethodDecl(), |
| 11959 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 11960 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 11961 | E->getRightLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11962 | } |
| 11963 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11964 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11965 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11966 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11967 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11968 | } |
| 11969 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11970 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11971 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11972 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11973 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11974 | } |
| 11975 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11976 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11977 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11978 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11979 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11980 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11981 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11982 | return ExprError(); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11983 | |
| 11984 | // We don't need to transform the ivar; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11985 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11986 | // If nothing changed, just retain the existing expression. |
| 11987 | if (!getDerived().AlwaysRebuild() && |
| 11988 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11989 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11990 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11991 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 11992 | E->getLocation(), |
| 11993 | E->isArrow(), E->isFreeIvar()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11994 | } |
| 11995 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11996 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11997 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11998 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 11999 | // 'super' and types never change. Property never changes. Just |
| 12000 | // retain the existing expression. |
| 12001 | if (!E->isObjectReceiver()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12002 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12003 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12004 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12005 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12006 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12007 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12008 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12009 | // We don't need to transform the property; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12010 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12011 | // If nothing changed, just retain the existing expression. |
| 12012 | if (!getDerived().AlwaysRebuild() && |
| 12013 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12014 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12015 | |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12016 | if (E->isExplicitProperty()) |
| 12017 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 12018 | E->getExplicitProperty(), |
| 12019 | E->getLocation()); |
| 12020 | |
| 12021 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 12022 | SemaRef.Context.PseudoObjectTy, |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12023 | E->getImplicitPropertyGetter(), |
| 12024 | E->getImplicitPropertySetter(), |
| 12025 | E->getLocation()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12026 | } |
| 12027 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12028 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12029 | ExprResult |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12030 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 12031 | // Transform the base expression. |
| 12032 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 12033 | if (Base.isInvalid()) |
| 12034 | return ExprError(); |
| 12035 | |
| 12036 | // Transform the key expression. |
| 12037 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 12038 | if (Key.isInvalid()) |
| 12039 | return ExprError(); |
| 12040 | |
| 12041 | // If nothing changed, just retain the existing expression. |
| 12042 | if (!getDerived().AlwaysRebuild() && |
| 12043 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12044 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12045 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12046 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12047 | Base.get(), Key.get(), |
| 12048 | E->getAtIndexMethodDecl(), |
| 12049 | E->setAtIndexMethodDecl()); |
| 12050 | } |
| 12051 | |
| 12052 | template<typename Derived> |
| 12053 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12054 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12055 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12056 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12057 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12058 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12059 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12060 | // If nothing changed, just retain the existing expression. |
| 12061 | if (!getDerived().AlwaysRebuild() && |
| 12062 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12063 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12064 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12065 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 12066 | E->getOpLoc(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12067 | E->isArrow()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12068 | } |
| 12069 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12070 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12071 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12072 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12073 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12074 | SmallVector<Expr*, 8> SubExprs; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12075 | SubExprs.reserve(E->getNumSubExprs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12076 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12077 | SubExprs, &ArgumentChanged)) |
| 12078 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12079 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12080 | if (!getDerived().AlwaysRebuild() && |
| 12081 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12082 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12083 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12084 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12085 | SubExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12086 | E->getRParenLoc()); |
| 12087 | } |
| 12088 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12089 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12090 | ExprResult |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12091 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 12092 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 12093 | if (SrcExpr.isInvalid()) |
| 12094 | return ExprError(); |
| 12095 | |
| 12096 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 12097 | if (!Type) |
| 12098 | return ExprError(); |
| 12099 | |
| 12100 | if (!getDerived().AlwaysRebuild() && |
| 12101 | Type == E->getTypeSourceInfo() && |
| 12102 | SrcExpr.get() == E->getSrcExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12103 | return E; |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12104 | |
| 12105 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 12106 | SrcExpr.get(), Type, |
| 12107 | E->getRParenLoc()); |
| 12108 | } |
| 12109 | |
| 12110 | template<typename Derived> |
| 12111 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12112 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12113 | BlockDecl *oldBlock = E->getBlockDecl(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12114 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12115 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12116 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 12117 | |
| 12118 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 12119 | blockScope->TheDecl->setBlockMissingReturnType( |
| 12120 | oldBlock->blockMissingReturnType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12121 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 12122 | SmallVector<ParmVarDecl*, 4> params; |
| 12123 | SmallVector<QualType, 4> paramTypes; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12124 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12125 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 12126 | |
| Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 12127 | // Parameter substitution. |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12128 | Sema::ExtParameterInfoBuilder extParamInfos; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 12129 | if (getDerived().TransformFunctionTypeParams( |
| 12130 | E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 12131 | exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 12132 | extParamInfos)) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12133 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12134 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12135 | } |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12136 | |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12137 | QualType exprResultType = |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 12138 | getDerived().TransformType(exprFunctionType->getReturnType()); |
| Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 12139 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12140 | auto epi = exprFunctionType->getExtProtoInfo(); |
| 12141 | epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 12142 | |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12143 | QualType functionType = |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12144 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12145 | blockScope->FunctionType = functionType; |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12146 | |
| 12147 | // Set the parameters on the block decl. |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12148 | if (!params.empty()) |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 12149 | blockScope->TheDecl->setParams(params); |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12150 | |
| 12151 | if (!oldBlock->blockMissingReturnType()) { |
| 12152 | blockScope->HasImplicitReturnType = false; |
| 12153 | blockScope->ReturnType = exprResultType; |
| 12154 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12155 | |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12156 | // Transform the body |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12157 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12158 | if (body.isInvalid()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12159 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12160 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12161 | } |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12162 | |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12163 | #ifndef NDEBUG |
| 12164 | // In builds with assertions, make sure that we captured everything we |
| 12165 | // captured before. |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12166 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 12167 | for (const auto &I : oldBlock->captures()) { |
| 12168 | VarDecl *oldCapture = I.getVariable(); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12169 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12170 | // Ignore parameter packs. |
| 12171 | if (isa<ParmVarDecl>(oldCapture) && |
| 12172 | cast<ParmVarDecl>(oldCapture)->isParameterPack()) |
| 12173 | continue; |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12174 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12175 | VarDecl *newCapture = |
| 12176 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 12177 | oldCapture)); |
| 12178 | assert(blockScope->CaptureMap.count(newCapture)); |
| 12179 | } |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 12180 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12181 | } |
| 12182 | #endif |
| 12183 | |
| 12184 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12185 | /*Scope=*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12186 | } |
| 12187 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12188 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12189 | ExprResult |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12190 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 12191 | llvm_unreachable("Cannot transform asType expressions yet"); |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12192 | } |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12193 | |
| 12194 | template<typename Derived> |
| 12195 | ExprResult |
| 12196 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12197 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 12198 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12199 | SmallVector<Expr*, 8> SubExprs; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12200 | SubExprs.reserve(E->getNumSubExprs()); |
| 12201 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 12202 | SubExprs, &ArgumentChanged)) |
| 12203 | return ExprError(); |
| 12204 | |
| 12205 | if (!getDerived().AlwaysRebuild() && |
| 12206 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12207 | return E; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12208 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12209 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12210 | RetTy, E->getOp(), E->getRParenLoc()); |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12211 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12212 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12213 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12214 | // Type reconstruction |
| 12215 | //===----------------------------------------------------------------------===// |
| 12216 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12217 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12218 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 12219 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12220 | return SemaRef.BuildPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12221 | getDerived().getBaseEntity()); |
| 12222 | } |
| 12223 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12224 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12225 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 12226 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12227 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12228 | getDerived().getBaseEntity()); |
| 12229 | } |
| 12230 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12231 | template<typename Derived> |
| 12232 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12233 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 12234 | bool WrittenAsLValue, |
| 12235 | SourceLocation Sigil) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12236 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12237 | Sigil, getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12238 | } |
| 12239 | |
| 12240 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12241 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12242 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 12243 | QualType ClassType, |
| 12244 | SourceLocation Sigil) { |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 12245 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 12246 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12247 | } |
| 12248 | |
| 12249 | template<typename Derived> |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 12250 | QualType TreeTransform<Derived>::RebuildObjCTypeParamType( |
| 12251 | const ObjCTypeParamDecl *Decl, |
| 12252 | SourceLocation ProtocolLAngleLoc, |
| 12253 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12254 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12255 | SourceLocation ProtocolRAngleLoc) { |
| 12256 | return SemaRef.BuildObjCTypeParamType(Decl, |
| 12257 | ProtocolLAngleLoc, Protocols, |
| 12258 | ProtocolLocs, ProtocolRAngleLoc, |
| 12259 | /*FailOnError=*/true); |
| 12260 | } |
| 12261 | |
| 12262 | template<typename Derived> |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 12263 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 12264 | QualType BaseType, |
| 12265 | SourceLocation Loc, |
| 12266 | SourceLocation TypeArgsLAngleLoc, |
| 12267 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 12268 | SourceLocation TypeArgsRAngleLoc, |
| 12269 | SourceLocation ProtocolLAngleLoc, |
| 12270 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12271 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12272 | SourceLocation ProtocolRAngleLoc) { |
| 12273 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 12274 | TypeArgs, TypeArgsRAngleLoc, |
| 12275 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 12276 | ProtocolRAngleLoc, |
| 12277 | /*FailOnError=*/true); |
| 12278 | } |
| 12279 | |
| 12280 | template<typename Derived> |
| 12281 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 12282 | QualType PointeeType, |
| 12283 | SourceLocation Star) { |
| 12284 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 12285 | } |
| 12286 | |
| 12287 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12288 | QualType |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12289 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 12290 | ArrayType::ArraySizeModifier SizeMod, |
| 12291 | const llvm::APInt *Size, |
| 12292 | Expr *SizeExpr, |
| 12293 | unsigned IndexTypeQuals, |
| 12294 | SourceRange BracketsRange) { |
| 12295 | if (SizeExpr || !Size) |
| 12296 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 12297 | IndexTypeQuals, BracketsRange, |
| 12298 | getDerived().getBaseEntity()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12299 | |
| 12300 | QualType Types[] = { |
| 12301 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 12302 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 12303 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12304 | }; |
| Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 12305 | const unsigned NumTypes = llvm::array_lengthof(Types); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12306 | QualType SizeType; |
| 12307 | for (unsigned I = 0; I != NumTypes; ++I) |
| 12308 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 12309 | SizeType = Types[I]; |
| 12310 | break; |
| 12311 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12312 | |
| Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 12313 | // Note that we can return a VariableArrayType here in the case where |
| 12314 | // the element type was a dependent VariableArrayType. |
| 12315 | IntegerLiteral *ArraySize |
| 12316 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 12317 | /*FIXME*/BracketsRange.getBegin()); |
| 12318 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12319 | IndexTypeQuals, BracketsRange, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12320 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12321 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12322 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12323 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12324 | QualType |
| 12325 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12326 | ArrayType::ArraySizeModifier SizeMod, |
| 12327 | const llvm::APInt &Size, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12328 | unsigned IndexTypeQuals, |
| 12329 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12330 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12331 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12332 | } |
| 12333 | |
| 12334 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12335 | QualType |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12336 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12337 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12338 | unsigned IndexTypeQuals, |
| 12339 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12340 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12341 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12342 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12343 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12344 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12345 | QualType |
| 12346 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12347 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12348 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12349 | unsigned IndexTypeQuals, |
| 12350 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12351 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12352 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12353 | IndexTypeQuals, BracketsRange); |
| 12354 | } |
| 12355 | |
| 12356 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12357 | QualType |
| 12358 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12359 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12360 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12361 | unsigned IndexTypeQuals, |
| 12362 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12363 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12364 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12365 | IndexTypeQuals, BracketsRange); |
| 12366 | } |
| 12367 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 12368 | template <typename Derived> |
| 12369 | QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( |
| 12370 | QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { |
| 12371 | return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, |
| 12372 | AttributeLoc); |
| 12373 | } |
| 12374 | |
| 12375 | template <typename Derived> |
| 12376 | QualType |
| 12377 | TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 12378 | unsigned NumElements, |
| 12379 | VectorType::VectorKind VecKind) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12380 | // FIXME: semantic checking! |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 12381 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12382 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12383 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 12384 | template <typename Derived> |
| 12385 | QualType TreeTransform<Derived>::RebuildDependentVectorType( |
| 12386 | QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, |
| 12387 | VectorType::VectorKind VecKind) { |
| 12388 | return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); |
| 12389 | } |
| 12390 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12391 | template<typename Derived> |
| 12392 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 12393 | unsigned NumElements, |
| 12394 | SourceLocation AttributeLoc) { |
| 12395 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 12396 | NumElements, true); |
| 12397 | IntegerLiteral *VectorSize |
| Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 12398 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 12399 | AttributeLoc); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12400 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12401 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12402 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12403 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12404 | QualType |
| 12405 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12406 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12407 | SourceLocation AttributeLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12408 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12409 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12410 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12411 | template<typename Derived> |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12412 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 12413 | QualType T, |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 12414 | MutableArrayRef<QualType> ParamTypes, |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12415 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 12416 | return SemaRef.BuildFunctionType(T, ParamTypes, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12417 | getDerived().getBaseLocation(), |
| Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 12418 | getDerived().getBaseEntity(), |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12419 | EPI); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12420 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12421 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12422 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 12423 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 12424 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 12425 | } |
| 12426 | |
| 12427 | template<typename Derived> |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12428 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, |
| 12429 | Decl *D) { |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12430 | assert(D && "no decl found"); |
| 12431 | if (D->isInvalidDecl()) return QualType(); |
| 12432 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12433 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12434 | TypeDecl *Ty; |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12435 | if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { |
| 12436 | // A valid resolved using typename pack expansion decl can have multiple |
| 12437 | // UsingDecls, but they must each have exactly one type, and it must be |
| 12438 | // the same type in every case. But we must have at least one expansion! |
| 12439 | if (UPD->expansions().empty()) { |
| 12440 | getSema().Diag(Loc, diag::err_using_pack_expansion_empty) |
| 12441 | << UPD->isCXXClassMember() << UPD; |
| 12442 | return QualType(); |
| 12443 | } |
| 12444 | |
| 12445 | // We might still have some unresolved types. Try to pick a resolved type |
| 12446 | // if we can. The final instantiation will check that the remaining |
| 12447 | // unresolved types instantiate to the type we pick. |
| 12448 | QualType FallbackT; |
| 12449 | QualType T; |
| 12450 | for (auto *E : UPD->expansions()) { |
| 12451 | QualType ThisT = RebuildUnresolvedUsingType(Loc, E); |
| 12452 | if (ThisT.isNull()) |
| 12453 | continue; |
| 12454 | else if (ThisT->getAs<UnresolvedUsingType>()) |
| 12455 | FallbackT = ThisT; |
| 12456 | else if (T.isNull()) |
| 12457 | T = ThisT; |
| 12458 | else |
| 12459 | assert(getSema().Context.hasSameType(ThisT, T) && |
| 12460 | "mismatched resolved types in using pack expansion"); |
| 12461 | } |
| 12462 | return T.isNull() ? FallbackT : T; |
| 12463 | } else if (auto *Using = dyn_cast<UsingDecl>(D)) { |
| Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 12464 | assert(Using->hasTypename() && |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12465 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 12466 | |
| 12467 | // A valid resolved using typename decl points to exactly one type decl. |
| 12468 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 12469 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12470 | } else { |
| 12471 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 12472 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 12473 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 12474 | } |
| 12475 | |
| 12476 | return SemaRef.Context.getTypeDeclType(Ty); |
| 12477 | } |
| 12478 | |
| 12479 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12480 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 12481 | SourceLocation Loc) { |
| 12482 | return SemaRef.BuildTypeofExprType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12483 | } |
| 12484 | |
| 12485 | template<typename Derived> |
| 12486 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 12487 | return SemaRef.Context.getTypeOfType(Underlying); |
| 12488 | } |
| 12489 | |
| 12490 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12491 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 12492 | SourceLocation Loc) { |
| 12493 | return SemaRef.BuildDecltypeType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12494 | } |
| 12495 | |
| 12496 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 12497 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 12498 | UnaryTransformType::UTTKind UKind, |
| 12499 | SourceLocation Loc) { |
| 12500 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 12501 | } |
| 12502 | |
| 12503 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12504 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 12505 | TemplateName Template, |
| 12506 | SourceLocation TemplateNameLoc, |
| Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 12507 | TemplateArgumentListInfo &TemplateArgs) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 12508 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12509 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12510 | |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 12511 | template<typename Derived> |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 12512 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 12513 | SourceLocation KWLoc) { |
| 12514 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 12515 | } |
| 12516 | |
| 12517 | template<typename Derived> |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12518 | QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 12519 | SourceLocation KWLoc, |
| 12520 | bool isReadPipe) { |
| 12521 | return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) |
| 12522 | : SemaRef.BuildWritePipeType(ValueType, KWLoc); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12523 | } |
| 12524 | |
| 12525 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12526 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12527 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12528 | bool TemplateKW, |
| 12529 | TemplateDecl *Template) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12530 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12531 | Template); |
| 12532 | } |
| 12533 | |
| 12534 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12535 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12536 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 12537 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12538 | const IdentifierInfo &Name, |
| 12539 | SourceLocation NameLoc, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 12540 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12541 | NamedDecl *FirstQualifierInScope, |
| 12542 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12543 | UnqualifiedId TemplateName; |
| 12544 | TemplateName.setIdentifier(&Name, NameLoc); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12545 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12546 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12547 | SS, TemplateKWLoc, TemplateName, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 12548 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12549 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12550 | Template, AllowInjectedClassName); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 12551 | return Template.get(); |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12552 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12553 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12554 | template<typename Derived> |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12555 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12556 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 12557 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12558 | OverloadedOperatorKind Operator, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12559 | SourceLocation NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12560 | QualType ObjectType, |
| 12561 | bool AllowInjectedClassName) { |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12562 | UnqualifiedId Name; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12563 | // FIXME: Bogus location information. |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12564 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12565 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12566 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12567 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12568 | SS, TemplateKWLoc, Name, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 12569 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12570 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12571 | Template, AllowInjectedClassName); |
| Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 12572 | return Template.get(); |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12573 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12574 | |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12575 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12576 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12577 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 12578 | SourceLocation OpLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12579 | Expr *OrigCallee, |
| 12580 | Expr *First, |
| 12581 | Expr *Second) { |
| 12582 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 12583 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12584 | |
| Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 12585 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 12586 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 12587 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 12588 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 12589 | First, Second); |
| 12590 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 12591 | if (Result.isInvalid()) |
| 12592 | return ExprError(); |
| 12593 | First = Result.get(); |
| 12594 | } |
| 12595 | |
| 12596 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 12597 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 12598 | if (Result.isInvalid()) |
| 12599 | return ExprError(); |
| 12600 | Second = Result.get(); |
| 12601 | } |
| 12602 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12603 | // Determine whether this should be a builtin operation. |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 12604 | if (Op == OO_Subscript) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12605 | if (!First->getType()->isOverloadableType() && |
| 12606 | !Second->getType()->isOverloadableType()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12607 | return getSema().CreateBuiltinArraySubscriptExpr( |
| 12608 | First, Callee->getBeginLoc(), Second, OpLoc); |
| Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 12609 | } else if (Op == OO_Arrow) { |
| 12610 | // -> is never a builtin operation. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12611 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 12612 | } else if (Second == nullptr || isPostIncDec) { |
| Richard Smith | cc4ad95 | 2018-07-22 05:21:47 +0000 | [diff] [blame] | 12613 | if (!First->getType()->isOverloadableType() || |
| 12614 | (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { |
| 12615 | // The argument is not of overloadable type, or this is an expression |
| 12616 | // of the form &Class::member, so try to create a built-in unary |
| 12617 | // operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 12618 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12619 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12620 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12621 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12622 | } |
| 12623 | } else { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12624 | if (!First->getType()->isOverloadableType() && |
| 12625 | !Second->getType()->isOverloadableType()) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12626 | // Neither of the arguments is an overloadable type, so try to |
| 12627 | // create a built-in binary operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 12628 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12629 | ExprResult Result |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12630 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12631 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12632 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12633 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12634 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12635 | } |
| 12636 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12637 | |
| 12638 | // Compute the transformed set of functions (and function templates) to be |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12639 | // used during overload resolution. |
| John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 12640 | UnresolvedSet<16> Functions; |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 12641 | bool RequiresADL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12642 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12643 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
| Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 12644 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 12645 | // If the overload could not be resolved in the template definition |
| 12646 | // (because we had a dependent argument), ADL is performed as part of |
| 12647 | // template instantiation. |
| 12648 | RequiresADL = ULE->requiresADL(); |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 12649 | } else { |
| Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 12650 | // If we've resolved this to a particular non-member function, just call |
| 12651 | // that function. If we resolved it to a member function, |
| 12652 | // CreateOverloaded* will find that function for us. |
| 12653 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 12654 | if (!isa<CXXMethodDecl>(ND)) |
| 12655 | Functions.addDecl(ND); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 12656 | RequiresADL = false; |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 12657 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12658 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12659 | // Add any functions found via argument-dependent lookup. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12660 | Expr *Args[2] = { First, Second }; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12661 | unsigned NumArgs = 1 + (Second != nullptr); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12662 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12663 | // Create the overloaded operator invocation for unary operators. |
| 12664 | if (NumArgs == 1 || isPostIncDec) { |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 12665 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12666 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 12667 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, |
| 12668 | RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12669 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12670 | |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 12671 | if (Op == OO_Subscript) { |
| 12672 | SourceLocation LBrace; |
| 12673 | SourceLocation RBrace; |
| 12674 | |
| 12675 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 12676 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 12677 | LBrace = SourceLocation::getFromRawEncoding( |
| 12678 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 12679 | RBrace = SourceLocation::getFromRawEncoding( |
| 12680 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 12681 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12682 | LBrace = Callee->getBeginLoc(); |
| 12683 | RBrace = OpLoc; |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 12684 | } |
| 12685 | |
| 12686 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 12687 | First, Second); |
| 12688 | } |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 12689 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12690 | // Create the overloaded operator invocation for binary operators. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 12691 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 12692 | ExprResult Result = SemaRef.CreateOverloadedBinOp( |
| 12693 | OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12694 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12695 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12696 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12697 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12698 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12699 | |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12700 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12701 | ExprResult |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12702 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12703 | SourceLocation OperatorLoc, |
| 12704 | bool isArrow, |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 12705 | CXXScopeSpec &SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12706 | TypeSourceInfo *ScopeType, |
| 12707 | SourceLocation CCLoc, |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 12708 | SourceLocation TildeLoc, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 12709 | PseudoDestructorTypeStorage Destroyed) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12710 | QualType BaseType = Base->getType(); |
| 12711 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12712 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12713 | (isArrow && BaseType->getAs<PointerType>() && |
| Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 12714 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 12715 | ->template getAs<RecordType>())){ |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12716 | // This pseudo-destructor expression is still a pseudo-destructor. |
| David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 12717 | return SemaRef.BuildPseudoDestructorExpr( |
| 12718 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 12719 | CCLoc, TildeLoc, Destroyed); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12720 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 12721 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 12722 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 12723 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 12724 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 12725 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 12726 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 12727 | |
| Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 12728 | // The scope type is now known to be a valid nested name specifier |
| 12729 | // component. Tack it on to the end of the nested name specifier. |
| Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 12730 | if (ScopeType) { |
| 12731 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 12732 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 12733 | diag::err_expected_class_or_namespace) |
| 12734 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 12735 | return ExprError(); |
| 12736 | } |
| 12737 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 12738 | CCLoc); |
| 12739 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 12740 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12741 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12742 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12743 | OperatorLoc, isArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12744 | SS, TemplateKWLoc, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12745 | /*FIXME: FirstQualifier*/ nullptr, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 12746 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 12747 | /*TemplateArgs*/ nullptr, |
| 12748 | /*S*/nullptr); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 12749 | } |
| 12750 | |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 12751 | template<typename Derived> |
| 12752 | StmtResult |
| 12753 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12754 | SourceLocation Loc = S->getBeginLoc(); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 12755 | CapturedDecl *CD = S->getCapturedDecl(); |
| 12756 | unsigned NumParams = CD->getNumParams(); |
| 12757 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 12758 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 12759 | for (unsigned I = 0; I < NumParams; ++I) { |
| 12760 | if (I != ContextParamPos) { |
| 12761 | Params.push_back( |
| 12762 | std::make_pair( |
| 12763 | CD->getParam(I)->getName(), |
| 12764 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 12765 | } else { |
| 12766 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 12767 | } |
| 12768 | } |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12769 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 12770 | S->getCapturedRegionKind(), Params); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 12771 | StmtResult Body; |
| 12772 | { |
| 12773 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 12774 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 12775 | } |
| Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 12776 | |
| 12777 | if (Body.isInvalid()) { |
| 12778 | getSema().ActOnCapturedRegionError(); |
| 12779 | return StmtError(); |
| 12780 | } |
| 12781 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 12782 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 12783 | } |
| 12784 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12785 | } // end namespace clang |
| 12786 | |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 12787 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |