| 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 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 7 | // |
| 8 | // This file implements a semantic tree transformation that takes a given |
| 9 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 10 | // |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 13 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 15 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 16 | #include "CoroutineStmtBuilder.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "TypeLocBuilder.h" |
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
| John McCall | de6836a | 2010-08-24 07:21:54 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclTemplate.h" |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 21 | #include "clang/AST/Expr.h" |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 22 | #include "clang/AST/ExprCXX.h" |
| 23 | #include "clang/AST/ExprObjC.h" |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 24 | #include "clang/AST/ExprOpenMP.h" |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 25 | #include "clang/AST/Stmt.h" |
| 26 | #include "clang/AST/StmtCXX.h" |
| 27 | #include "clang/AST/StmtObjC.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/AST/StmtOpenMP.h" |
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Designator.h" |
| 30 | #include "clang/Sema/Lookup.h" |
| 31 | #include "clang/Sema/Ownership.h" |
| 32 | #include "clang/Sema/ParsedTemplate.h" |
| 33 | #include "clang/Sema/ScopeInfo.h" |
| 34 | #include "clang/Sema/SemaDiagnostic.h" |
| 35 | #include "clang/Sema/SemaInternal.h" |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ErrorHandling.h" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 38 | #include <algorithm> |
| 39 | |
| 40 | namespace clang { |
| John McCall | aab3e41 | 2010-08-25 08:40:02 +0000 | [diff] [blame] | 41 | using namespace sema; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 43 | /// A semantic tree transformation that allows one to transform one |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 44 | /// abstract syntax tree into another. |
| 45 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 47 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 48 | /// behavior specific to that transformation. For example, template |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 49 | /// instantiation is implemented as a tree transformation where the |
| 50 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 51 | /// template arguments for their corresponding template parameters; a similar |
| 52 | /// transformation is performed for non-type template parameters and |
| 53 | /// template template parameters. |
| 54 | /// |
| 55 | /// This tree-transformation template uses static polymorphism to allow |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | /// subclasses to customize any of its operations. Thus, a subclass can |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 57 | /// override any of the transformation or rebuild operators by providing an |
| 58 | /// operation with the same signature as the default implementation. The |
| Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 59 | /// overriding function should not be virtual. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 60 | /// |
| 61 | /// Semantic tree transformations are split into two stages, either of which |
| 62 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 63 | /// or the parts of an AST node using the various transformation functions, |
| 64 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 65 | /// node of the appropriate kind from the pieces. The default transformation |
| 66 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 67 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 68 | /// were changed by the transformation, invokes the rebuild operation to create |
| 69 | /// a new AST node. |
| 70 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// Subclasses can customize the transformation at various levels. The |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 72 | /// most coarse-grained transformations involve replacing TransformType(), |
| Douglas Gregor | fd35cde | 2011-03-02 18:50:38 +0000 | [diff] [blame] | 73 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 74 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 75 | /// new implementations. |
| 76 | /// |
| 77 | /// For more fine-grained transformations, subclasses can replace any of the |
| 78 | /// \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] | 79 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 80 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// to substitute template arguments for their corresponding template |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 82 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 83 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 84 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 85 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 86 | /// be able to use more efficient rebuild steps. |
| 87 | /// |
| 88 | /// 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] | 89 | /// to avoid traversing nodes that don't need any transformation |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 90 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 91 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 92 | /// default locations and entity names used for type-checking |
| 93 | /// (\c getBaseLocation(), \c getBaseEntity()). |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 94 | template<typename Derived> |
| 95 | class TreeTransform { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 96 | /// Private RAII object that helps us forget and then re-remember |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 97 | /// the template argument corresponding to a partially-substituted parameter |
| 98 | /// pack. |
| 99 | class ForgetPartiallySubstitutedPackRAII { |
| 100 | Derived &Self; |
| 101 | TemplateArgument Old; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 102 | |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 103 | public: |
| 104 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 105 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 106 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 107 | |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 108 | ~ForgetPartiallySubstitutedPackRAII() { |
| 109 | Self.RememberPartiallySubstitutedPack(Old); |
| 110 | } |
| 111 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 112 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 113 | protected: |
| 114 | Sema &SemaRef; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 115 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 116 | /// The set of local declarations that have been transformed, for |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 117 | /// cases where we are forced to build new declarations within the transformer |
| 118 | /// rather than in the subclass (e.g., lambda closure types). |
| 119 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 120 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | public: |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 122 | /// Initializes a new tree transformer. |
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 123 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 125 | /// Retrieves a reference to the derived class. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 126 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 127 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 128 | /// Retrieves a reference to the derived class. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | const Derived &getDerived() const { |
| 130 | return static_cast<const Derived&>(*this); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 133 | static inline ExprResult Owned(Expr *E) { return E; } |
| 134 | static inline StmtResult Owned(Stmt *S) { return S; } |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 135 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 136 | /// Retrieves a reference to the semantic analysis object used for |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 137 | /// this tree transform. |
| 138 | Sema &getSema() const { return SemaRef; } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 140 | /// Whether the transformation should always rebuild AST nodes, even |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 141 | /// if none of the children have changed. |
| 142 | /// |
| 143 | /// Subclasses may override this function to specify when the transformation |
| 144 | /// should rebuild all AST nodes. |
| Richard Smith | 2aa81a7 | 2013-11-07 20:07:17 +0000 | [diff] [blame] | 145 | /// |
| 146 | /// We must always rebuild all AST nodes when performing variadic template |
| 147 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 148 | /// statement node appears at most once in its containing declaration. |
| 149 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 151 | /// Whether the transformation is forming an expression or statement that |
| 152 | /// replaces the original. In this case, we'll reuse mangling numbers from |
| 153 | /// existing lambdas. |
| 154 | bool ReplacingOriginal() { return false; } |
| 155 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 156 | /// Returns the location of the entity being transformed, if that |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 157 | /// information was not available elsewhere in the AST. |
| 158 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 159 | /// By default, returns no source-location information. Subclasses can |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 160 | /// provide an alternative implementation that provides better location |
| 161 | /// information. |
| 162 | SourceLocation getBaseLocation() { return SourceLocation(); } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 164 | /// Returns the name of the entity being transformed, if that |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 165 | /// information was not available elsewhere in the AST. |
| 166 | /// |
| 167 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 168 | /// implementation with a more precise name. |
| 169 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 170 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 171 | /// Sets the "base" location and entity when that |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 172 | /// information is known based on another transformation. |
| 173 | /// |
| 174 | /// By default, the source location and entity are ignored. Subclasses can |
| 175 | /// override this function to provide a customized implementation. |
| 176 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 178 | /// RAII object that temporarily sets the base location and entity |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 179 | /// used for reporting diagnostics in types. |
| 180 | class TemporaryBase { |
| 181 | TreeTransform &Self; |
| 182 | SourceLocation OldLocation; |
| 183 | DeclarationName OldEntity; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 185 | public: |
| 186 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | DeclarationName Entity) : Self(Self) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 188 | OldLocation = Self.getDerived().getBaseLocation(); |
| 189 | OldEntity = Self.getDerived().getBaseEntity(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 190 | |
| Douglas Gregor | a518d5b | 2011-01-25 17:51:48 +0000 | [diff] [blame] | 191 | if (Location.isValid()) |
| 192 | Self.getDerived().setBase(Location, Entity); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 193 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 195 | ~TemporaryBase() { |
| 196 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 197 | } |
| 198 | }; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 200 | /// Determine whether the given type \p T has already been |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 201 | /// transformed. |
| 202 | /// |
| 203 | /// Subclasses can provide an alternative implementation of this routine |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | /// 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] | 205 | /// not change. For example, template instantiation need not traverse |
| 206 | /// non-dependent types. |
| 207 | bool AlreadyTransformed(QualType T) { |
| 208 | return T.isNull(); |
| 209 | } |
| 210 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 211 | /// Determine whether the given call argument should be dropped, e.g., |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 212 | /// because it is a default argument. |
| 213 | /// |
| 214 | /// Subclasses can provide an alternative implementation of this routine to |
| 215 | /// determine which kinds of call arguments get dropped. By default, |
| 216 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 217 | bool DropCallArgument(Expr *E) { |
| 218 | return E->isDefaultArgument(); |
| 219 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 220 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 221 | /// Determine whether we should expand a pack expansion with the |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 222 | /// given set of parameter packs into separate arguments by repeatedly |
| 223 | /// transforming the pattern. |
| 224 | /// |
| Douglas Gregor | 76aca7b | 2010-12-21 00:52:54 +0000 | [diff] [blame] | 225 | /// By default, the transformer never tries to expand pack expansions. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 226 | /// Subclasses can override this routine to provide different behavior. |
| 227 | /// |
| 228 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 229 | /// pack expansion. |
| 230 | /// |
| 231 | /// \param PatternRange The source range that covers the entire pattern of |
| 232 | /// the pack expansion. |
| 233 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 234 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 235 | /// pattern. |
| 236 | /// |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 237 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 238 | /// expand the corresponding pack expansions into separate arguments. When |
| 239 | /// set, \c NumExpansions must also be set. |
| 240 | /// |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 241 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 242 | /// pack expansion after all of the expanded arguments. This is used |
| 243 | /// when extending explicitly-specified template argument packs per |
| 244 | /// C++0x [temp.arg.explicit]p9. |
| 245 | /// |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 246 | /// \param NumExpansions The number of separate arguments that will be in |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 247 | /// the expanded form of the corresponding pack expansion. This is both an |
| 248 | /// input and an output parameter, which can be set by the caller if the |
| 249 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 250 | /// and will be set by the callee when the number of expansions is known. |
| 251 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 252 | /// set this value in other cases. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 253 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 254 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 255 | /// are to be instantiated with arguments of different lengths), false |
| 256 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 257 | /// must be set. |
| 258 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 259 | SourceRange PatternRange, |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 260 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 261 | bool &ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 262 | bool &RetainExpansion, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 263 | Optional<unsigned> &NumExpansions) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 264 | ShouldExpand = false; |
| 265 | return false; |
| 266 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 267 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 268 | /// "Forget" about the partially-substituted pack template argument, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 269 | /// when performing an instantiation that must preserve the parameter pack |
| 270 | /// use. |
| 271 | /// |
| 272 | /// This routine is meant to be overridden by the template instantiator. |
| 273 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 274 | return TemplateArgument(); |
| 275 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 276 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 277 | /// "Remember" the partially-substituted pack template argument |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 278 | /// after performing an instantiation that must preserve the parameter pack |
| 279 | /// use. |
| 280 | /// |
| 281 | /// This routine is meant to be overridden by the template instantiator. |
| 282 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 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 | /// Note to the derived class when a function parameter pack is |
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 285 | /// being expanded. |
| 286 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 287 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 288 | /// Transforms the given type into another type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 289 | /// |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 290 | /// By default, this routine transforms a type by creating a |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 291 | /// TypeSourceInfo for it and delegating to the appropriate |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 292 | /// function. This is expensive, but we don't mind, because |
| 293 | /// this method is deprecated anyway; all users should be |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 294 | /// switched to storing TypeSourceInfos. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 295 | /// |
| 296 | /// \returns the transformed type. |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 297 | QualType TransformType(QualType T); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 298 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 299 | /// Transforms the given type-with-location into a new |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 300 | /// type-with-location. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 301 | /// |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 302 | /// By default, this routine transforms a type by delegating to the |
| 303 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 304 | /// may override this function (to take over all type |
| 305 | /// transformations) or some set of the TransformXXXType functions |
| 306 | /// to alter the transformation. |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 307 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 308 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 309 | /// Transform the given type-with-location into a new |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 310 | /// type, collecting location information in the given builder |
| 311 | /// as necessary. |
| 312 | /// |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 313 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 314 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 315 | /// Transform a type that is permitted to produce a |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 316 | /// DeducedTemplateSpecializationType. |
| 317 | /// |
| 318 | /// This is used in the (relatively rare) contexts where it is acceptable |
| 319 | /// for transformation to produce a class template type with deduced |
| 320 | /// template arguments. |
| 321 | /// @{ |
| 322 | QualType TransformTypeWithDeducedTST(QualType T); |
| 323 | TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); |
| 324 | /// @} |
| 325 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 326 | /// The reason why the value of a statement is not discarded, if any. |
| 327 | enum StmtDiscardKind { |
| 328 | SDK_Discarded, |
| 329 | SDK_NotDiscarded, |
| 330 | SDK_StmtExprResult, |
| 331 | }; |
| 332 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 333 | /// Transform the given statement. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 334 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 335 | /// By default, this routine transforms a statement by delegating to the |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 336 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 337 | /// statement or the TransformExpr() function to transform an expression. |
| 338 | /// Subclasses may override this function to transform statements using some |
| 339 | /// other mechanism. |
| 340 | /// |
| 341 | /// \returns the transformed statement. |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 342 | StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 344 | /// Transform the given statement. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 345 | /// |
| 346 | /// By default, this routine transforms a statement by delegating to the |
| 347 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 348 | /// of clause. Subclasses may override this function to transform statements |
| 349 | /// using some other mechanism. |
| 350 | /// |
| 351 | /// \returns the transformed OpenMP clause. |
| 352 | OMPClause *TransformOMPClause(OMPClause *S); |
| 353 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 354 | /// Transform the given attribute. |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 355 | /// |
| 356 | /// By default, this routine transforms a statement by delegating to the |
| 357 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 358 | /// of attribute. Subclasses may override this function to transform |
| 359 | /// attributed statements using some other mechanism. |
| 360 | /// |
| 361 | /// \returns the transformed attribute |
| 362 | const Attr *TransformAttr(const Attr *S); |
| 363 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 364 | /// Transform the specified attribute. |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 365 | /// |
| 366 | /// Subclasses should override the transformation of attributes with a pragma |
| 367 | /// spelling to transform expressions stored within the attribute. |
| 368 | /// |
| 369 | /// \returns the transformed attribute. |
| 370 | #define ATTR(X) |
| 371 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 372 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 373 | #include "clang/Basic/AttrList.inc" |
| 374 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 375 | /// Transform the given expression. |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 376 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 377 | /// By default, this routine transforms an expression by delegating to the |
| 378 | /// appropriate TransformXXXExpr function to build a new expression. |
| 379 | /// Subclasses may override this function to transform expressions using some |
| 380 | /// other mechanism. |
| 381 | /// |
| 382 | /// \returns the transformed expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 383 | ExprResult TransformExpr(Expr *E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 385 | /// Transform the given initializer. |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 386 | /// |
| 387 | /// By default, this routine transforms an initializer by stripping off the |
| 388 | /// semantic nodes added by initialization, then passing the result to |
| 389 | /// TransformExpr or TransformExprs. |
| 390 | /// |
| 391 | /// \returns the transformed initializer. |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 392 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 393 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 394 | /// Transform the given list of expressions. |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 395 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 396 | /// This routine transforms a list of expressions by invoking |
| 397 | /// \c TransformExpr() for each subexpression. However, it also provides |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 398 | /// support for variadic templates by expanding any pack expansions (if the |
| 399 | /// derived class permits such expansion) along the way. When pack expansions |
| 400 | /// are present, the number of outputs may not equal the number of inputs. |
| 401 | /// |
| 402 | /// \param Inputs The set of expressions to be transformed. |
| 403 | /// |
| 404 | /// \param NumInputs The number of expressions in \c Inputs. |
| 405 | /// |
| 406 | /// \param IsCall If \c true, then this transform is being performed on |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 407 | /// function-call arguments, and any arguments that should be dropped, will |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 408 | /// be. |
| 409 | /// |
| 410 | /// \param Outputs The transformed input expressions will be added to this |
| 411 | /// vector. |
| 412 | /// |
| 413 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 414 | /// due to transformation. |
| 415 | /// |
| 416 | /// \returns true if an error occurred, false otherwise. |
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 417 | bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 418 | SmallVectorImpl<Expr *> &Outputs, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 419 | bool *ArgChanged = nullptr); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 420 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 421 | /// Transform the given declaration, which is referenced from a type |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 422 | /// or expression. |
| 423 | /// |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 424 | /// By default, acts as the identity function on declarations, unless the |
| 425 | /// transformer has had to transform the declaration itself. Subclasses |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 426 | /// may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 427 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 428 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 429 | = TransformedLocalDecls.find(D); |
| 430 | if (Known != TransformedLocalDecls.end()) |
| 431 | return Known->second; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 432 | |
| 433 | return D; |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 434 | } |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 435 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 436 | /// Transform the specified condition. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 437 | /// |
| 438 | /// By default, this transforms the variable and expression and rebuilds |
| 439 | /// the condition. |
| 440 | Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
| 441 | Expr *Expr, |
| 442 | Sema::ConditionKind Kind); |
| 443 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 444 | /// Transform the attributes associated with the given declaration and |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 445 | /// place them on the new declaration. |
| 446 | /// |
| 447 | /// By default, this operation does nothing. Subclasses may override this |
| 448 | /// behavior to transform attributes. |
| 449 | void transformAttrs(Decl *Old, Decl *New) { } |
| 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 | /// Note that a local declaration has been transformed by this |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 452 | /// transformer. |
| 453 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 454 | /// Local declarations are typically transformed via a call to |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 455 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 456 | /// the transformer itself has to transform the declarations. This routine |
| 457 | /// can be overridden by a subclass that keeps track of such mappings. |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 458 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { |
| 459 | assert(New.size() == 1 && |
| 460 | "must override transformedLocalDecl if performing pack expansion"); |
| 461 | TransformedLocalDecls[Old] = New.front(); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 462 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 463 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 464 | /// Transform the definition of the given declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 465 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | /// By default, invokes TransformDecl() to transform the declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 467 | /// Subclasses may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 468 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 469 | return getDerived().TransformDecl(Loc, D); |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 470 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 471 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 472 | /// Transform the given declaration, which was the first part of a |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 473 | /// nested-name-specifier in a member access expression. |
| 474 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 475 | /// This specific declaration transformation only applies to the first |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 476 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 477 | /// the \c T in \c x->T::member |
| 478 | /// |
| 479 | /// By default, invokes TransformDecl() to transform the declaration. |
| 480 | /// Subclasses may override this function to provide alternate behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 481 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 482 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 483 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 484 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 485 | /// Transform the set of declarations in an OverloadExpr. |
| 486 | bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, |
| 487 | LookupResult &R); |
| 488 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 489 | /// Transform the given nested-name-specifier with source-location |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 490 | /// information. |
| 491 | /// |
| 492 | /// By default, transforms all of the types and declarations within the |
| 493 | /// nested-name-specifier. Subclasses may override this function to provide |
| 494 | /// alternate behavior. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 495 | NestedNameSpecifierLoc |
| 496 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 497 | QualType ObjectType = QualType(), |
| 498 | NamedDecl *FirstQualifierInScope = nullptr); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 499 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 500 | /// Transform the given declaration name. |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 501 | /// |
| 502 | /// By default, transforms the types of conversion function, constructor, |
| 503 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 504 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 505 | /// override this function to provide alternate behavior. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 506 | DeclarationNameInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 507 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 509 | /// Transform the given template name. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 510 | /// |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 511 | /// \param SS The nested-name-specifier that qualifies the template |
| 512 | /// name. This nested-name-specifier must already have been transformed. |
| 513 | /// |
| 514 | /// \param Name The template name to transform. |
| 515 | /// |
| 516 | /// \param NameLoc The source location of the template name. |
| 517 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 518 | /// \param ObjectType If we're translating a template name within a member |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 519 | /// access expression, this is the type of the object whose member template |
| 520 | /// is being referenced. |
| 521 | /// |
| 522 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 523 | /// also refers to a name within the current (lexical) scope, this is the |
| 524 | /// declaration it refers to. |
| 525 | /// |
| 526 | /// By default, transforms the template name by transforming the declarations |
| 527 | /// and nested-name-specifiers that occur within the template name. |
| 528 | /// Subclasses may override this function to provide alternate behavior. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 529 | TemplateName |
| 530 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 531 | SourceLocation NameLoc, |
| 532 | QualType ObjectType = QualType(), |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 533 | NamedDecl *FirstQualifierInScope = nullptr, |
| 534 | bool AllowInjectedClassName = false); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 535 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 536 | /// Transform the given template argument. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 537 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | /// By default, this operation transforms the type, expression, or |
| 539 | /// declaration stored within the template argument and constructs a |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 540 | /// new template argument from the transformed result. Subclasses may |
| 541 | /// override this function to provide alternate behavior. |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 542 | /// |
| 543 | /// Returns true if there was an error. |
| 544 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 545 | TemplateArgumentLoc &Output, |
| 546 | bool Uneval = false); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 547 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 548 | /// Transform the given set of template arguments. |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 549 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 550 | /// By default, this operation transforms all of the template arguments |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 551 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 552 | /// the transformed arguments to the output list. |
| 553 | /// |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 554 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 555 | /// a convenience function. Subclasses that wish to override this behavior |
| 556 | /// should override the iterator-based member template version. |
| 557 | /// |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 558 | /// \param Inputs The set of template arguments to be transformed. |
| 559 | /// |
| 560 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 561 | /// |
| 562 | /// \param Outputs The set of transformed template arguments output by this |
| 563 | /// routine. |
| 564 | /// |
| 565 | /// Returns true if an error occurred. |
| 566 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 567 | unsigned NumInputs, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 568 | TemplateArgumentListInfo &Outputs, |
| 569 | bool Uneval = false) { |
| 570 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 571 | Uneval); |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 572 | } |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 573 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 574 | /// Transform the given set of template arguments. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 575 | /// |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 576 | /// By default, this operation transforms all of the template arguments |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 577 | /// in the input set using \c TransformTemplateArgument(), and appends |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 578 | /// the transformed arguments to the output list. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 579 | /// |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 580 | /// \param First An iterator to the first template argument. |
| 581 | /// |
| 582 | /// \param Last An iterator one step past the last template argument. |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 583 | /// |
| 584 | /// \param Outputs The set of transformed template arguments output by this |
| 585 | /// routine. |
| 586 | /// |
| 587 | /// Returns true if an error occurred. |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 588 | template<typename InputIterator> |
| 589 | bool TransformTemplateArguments(InputIterator First, |
| 590 | InputIterator Last, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 591 | TemplateArgumentListInfo &Outputs, |
| 592 | bool Uneval = false); |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 593 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 594 | /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 595 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 596 | TemplateArgumentLoc &ArgLoc); |
| 597 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 598 | /// Fakes up a TypeSourceInfo for a type. |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 599 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 600 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 601 | getDerived().getBaseLocation()); |
| 602 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 604 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 605 | #define TYPELOC(CLASS, PARENT) \ |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 606 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 607 | #include "clang/AST/TypeLocNodes.def" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 608 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 609 | template<typename Fn> |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 610 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 611 | FunctionProtoTypeLoc TL, |
| 612 | CXXRecordDecl *ThisContext, |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 613 | Qualifiers ThisTypeQuals, |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 614 | Fn TransformExceptionSpec); |
| 615 | |
| 616 | bool TransformExceptionSpec(SourceLocation Loc, |
| 617 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 618 | SmallVectorImpl<QualType> &Exceptions, |
| 619 | bool &Changed); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 620 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 621 | StmtResult TransformSEHHandler(Stmt *Handler); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 622 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 623 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 624 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 625 | TemplateSpecializationTypeLoc TL, |
| 626 | TemplateName Template); |
| 627 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 628 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 629 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 630 | DependentTemplateSpecializationTypeLoc TL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 631 | TemplateName Template, |
| 632 | CXXScopeSpec &SS); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 633 | |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 634 | QualType TransformDependentTemplateSpecializationType( |
| 635 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 636 | NestedNameSpecifierLoc QualifierLoc); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 637 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 638 | /// Transforms the parameters of a function type into the |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 639 | /// given vectors. |
| 640 | /// |
| 641 | /// The result vectors should be kept in sync; null entries in the |
| 642 | /// variables vector are acceptable. |
| 643 | /// |
| 644 | /// Return true on error. |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 645 | bool TransformFunctionTypeParams( |
| 646 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 647 | const QualType *ParamTypes, |
| 648 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 649 | SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 650 | Sema::ExtParameterInfoBuilder &PInfos); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 651 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 652 | /// Transforms a single function-type parameter. Return null |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 653 | /// on error. |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 654 | /// |
| 655 | /// \param indexAdjustment - A number to add to the parameter's |
| 656 | /// scope index; can be negative |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 657 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 658 | int indexAdjustment, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 659 | Optional<unsigned> NumExpansions, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 660 | bool ExpectParameterPack); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 661 | |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 662 | /// Transform the body of a lambda-expression. |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 663 | StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); |
| 664 | /// Alternative implementation of TransformLambdaBody that skips transforming |
| 665 | /// the body. |
| 666 | StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 667 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 668 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 669 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 670 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 671 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
| Richard Smith | 2589b980 | 2012-07-25 03:56:55 +0000 | [diff] [blame] | 672 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 673 | TemplateParameterList *TransformTemplateParameterList( |
| 674 | TemplateParameterList *TPL) { |
| 675 | return TPL; |
| 676 | } |
| 677 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 678 | ExprResult TransformAddressOfOperand(Expr *E); |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 679 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 680 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 681 | bool IsAddressOfOperand, |
| 682 | TypeSourceInfo **RecoveryTSI); |
| 683 | |
| 684 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 685 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 686 | TypeSourceInfo **RecoveryTSI); |
| 687 | |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 688 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 689 | |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 690 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 691 | // amount of stack usage with clang. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 692 | #define STMT(Node, Parent) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 693 | LLVM_ATTRIBUTE_NOINLINE \ |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 694 | StmtResult Transform##Node(Node *S); |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 695 | #define VALUESTMT(Node, Parent) \ |
| 696 | LLVM_ATTRIBUTE_NOINLINE \ |
| 697 | StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 698 | #define EXPR(Node, Parent) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 699 | LLVM_ATTRIBUTE_NOINLINE \ |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 700 | ExprResult Transform##Node(Node *E); |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 701 | #define ABSTRACT_STMT(Stmt) |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 702 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 704 | #define OPENMP_CLAUSE(Name, Class) \ |
| Eli Friedman | bc8c734 | 2013-09-06 01:13:30 +0000 | [diff] [blame] | 705 | LLVM_ATTRIBUTE_NOINLINE \ |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 706 | OMPClause *Transform ## Class(Class *S); |
| 707 | #include "clang/Basic/OpenMPKinds.def" |
| 708 | |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 709 | /// Build a new qualified type given its unqualified type and type location. |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 710 | /// |
| 711 | /// By default, this routine adds type qualifiers only to types that can |
| 712 | /// have qualifiers, and silently suppresses those qualifiers that are not |
| 713 | /// permitted. Subclasses may override this routine to provide different |
| 714 | /// behavior. |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 715 | QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 716 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 717 | /// Build a new pointer type given its pointee type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 718 | /// |
| 719 | /// By default, performs semantic analysis when building the pointer type. |
| 720 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 721 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 722 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 723 | /// Build a new block pointer type given its pointee type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 724 | /// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 725 | /// By default, performs semantic analysis when building the block pointer |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 726 | /// type. Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 727 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 728 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 729 | /// Build a new reference type given the type it references. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 730 | /// |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 731 | /// By default, performs semantic analysis when building the |
| 732 | /// reference type. Subclasses may override this routine to provide |
| 733 | /// different behavior. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 734 | /// |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 735 | /// \param LValue whether the type was written with an lvalue sigil |
| 736 | /// or an rvalue sigil. |
| 737 | QualType RebuildReferenceType(QualType ReferentType, |
| 738 | bool LValue, |
| 739 | SourceLocation Sigil); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 741 | /// Build a new member pointer type given the pointee type and the |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 742 | /// class type it refers into. |
| 743 | /// |
| 744 | /// By default, performs semantic analysis when building the member pointer |
| 745 | /// type. Subclasses may override this routine to provide different behavior. |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 746 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 747 | SourceLocation Sigil); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 748 | |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 749 | QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 750 | SourceLocation ProtocolLAngleLoc, |
| 751 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 752 | ArrayRef<SourceLocation> ProtocolLocs, |
| 753 | SourceLocation ProtocolRAngleLoc); |
| 754 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 755 | /// Build an Objective-C object type. |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 756 | /// |
| 757 | /// By default, performs semantic analysis when building the object type. |
| 758 | /// Subclasses may override this routine to provide different behavior. |
| 759 | QualType RebuildObjCObjectType(QualType BaseType, |
| 760 | SourceLocation Loc, |
| 761 | SourceLocation TypeArgsLAngleLoc, |
| 762 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 763 | SourceLocation TypeArgsRAngleLoc, |
| 764 | SourceLocation ProtocolLAngleLoc, |
| 765 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 766 | ArrayRef<SourceLocation> ProtocolLocs, |
| 767 | SourceLocation ProtocolRAngleLoc); |
| 768 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 769 | /// Build a new Objective-C object pointer type given the pointee type. |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 770 | /// |
| 771 | /// By default, directly builds the pointer type, with no additional semantic |
| 772 | /// analysis. |
| 773 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 774 | SourceLocation Star); |
| 775 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 776 | /// Build a new array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 777 | /// modifier, size of the array (if known), size expression, and index type |
| 778 | /// qualifiers. |
| 779 | /// |
| 780 | /// By default, performs semantic analysis when building the array type. |
| 781 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | /// Also by default, all of the other Rebuild*Array |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 783 | QualType RebuildArrayType(QualType ElementType, |
| 784 | ArrayType::ArraySizeModifier SizeMod, |
| 785 | const llvm::APInt *Size, |
| 786 | Expr *SizeExpr, |
| 787 | unsigned IndexTypeQuals, |
| 788 | SourceRange BracketsRange); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 789 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 790 | /// Build a new constant array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 791 | /// modifier, (known) size of the array, and index type qualifiers. |
| 792 | /// |
| 793 | /// By default, performs semantic analysis when building the array type. |
| 794 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 795 | QualType RebuildConstantArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 796 | ArrayType::ArraySizeModifier SizeMod, |
| 797 | const llvm::APInt &Size, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 798 | unsigned IndexTypeQuals, |
| 799 | SourceRange BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 800 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 801 | /// Build a new incomplete array type given the element type, size |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 802 | /// modifier, and index type qualifiers. |
| 803 | /// |
| 804 | /// By default, performs semantic analysis when building the array type. |
| 805 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | QualType RebuildIncompleteArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 807 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 808 | unsigned IndexTypeQuals, |
| 809 | SourceRange BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 810 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 811 | /// Build a new variable-length array type given the element type, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 812 | /// size modifier, size expression, and index type qualifiers. |
| 813 | /// |
| 814 | /// By default, performs semantic analysis when building the array type. |
| 815 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | QualType RebuildVariableArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 817 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 818 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 819 | unsigned IndexTypeQuals, |
| 820 | SourceRange BracketsRange); |
| 821 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 822 | /// Build a new dependent-sized array type given the element type, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 823 | /// size modifier, size expression, and index type qualifiers. |
| 824 | /// |
| 825 | /// By default, performs semantic analysis when building the array type. |
| 826 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 828 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 829 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 830 | unsigned IndexTypeQuals, |
| 831 | SourceRange BracketsRange); |
| 832 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 833 | /// Build a new vector type given the element type and |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 834 | /// number of elements. |
| 835 | /// |
| 836 | /// By default, performs semantic analysis when building the vector type. |
| 837 | /// Subclasses may override this routine to provide different behavior. |
| John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 838 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 839 | VectorType::VectorKind VecKind); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 841 | /// Build a new potentially dependently-sized extended vector type |
| 842 | /// given the element type and number of elements. |
| 843 | /// |
| 844 | /// By default, performs semantic analysis when building the vector type. |
| 845 | /// Subclasses may override this routine to provide different behavior. |
| 846 | QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, |
| 847 | SourceLocation AttributeLoc, |
| 848 | VectorType::VectorKind); |
| 849 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 850 | /// Build a new extended vector type given the element type and |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 851 | /// number of elements. |
| 852 | /// |
| 853 | /// By default, performs semantic analysis when building the vector type. |
| 854 | /// Subclasses may override this routine to provide different behavior. |
| 855 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 856 | SourceLocation AttributeLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 857 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 858 | /// Build a new potentially dependently-sized extended vector type |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 859 | /// given the element type and number of elements. |
| 860 | /// |
| 861 | /// By default, performs semantic analysis when building the vector type. |
| 862 | /// Subclasses may override this routine to provide different behavior. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 864 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 865 | SourceLocation AttributeLoc); |
| 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 DependentAddressSpaceType or return the pointee |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 868 | /// type variable with the correct address space (retrieved from |
| 869 | /// AddrSpaceExpr) applied to it. The former will be returned in cases |
| 870 | /// where the address space remains dependent. |
| 871 | /// |
| 872 | /// By default, performs semantic analysis when building the type with address |
| 873 | /// space applied. Subclasses may override this routine to provide different |
| 874 | /// behavior. |
| 875 | QualType RebuildDependentAddressSpaceType(QualType PointeeType, |
| 876 | Expr *AddrSpaceExpr, |
| 877 | SourceLocation AttributeLoc); |
| 878 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 879 | /// Build a new function type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 880 | /// |
| 881 | /// By default, performs semantic analysis when building the function type. |
| 882 | /// Subclasses may override this routine to provide different behavior. |
| 883 | QualType RebuildFunctionProtoType(QualType T, |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 884 | MutableArrayRef<QualType> ParamTypes, |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 885 | const FunctionProtoType::ExtProtoInfo &EPI); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 887 | /// Build a new unprototyped function type. |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 888 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 889 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 890 | /// Rebuild an unresolved typename type, given the decl that |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 891 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 892 | QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 893 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 894 | /// Build a new typedef type. |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 895 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 896 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 897 | } |
| 898 | |
| Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 899 | /// Build a new MacroDefined type. |
| 900 | QualType RebuildMacroQualifiedType(QualType T, |
| 901 | const IdentifierInfo *MacroII) { |
| 902 | return SemaRef.Context.getMacroQualifiedType(T, MacroII); |
| 903 | } |
| 904 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 905 | /// Build a new class/struct/union type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 906 | QualType RebuildRecordType(RecordDecl *Record) { |
| 907 | return SemaRef.Context.getTypeDeclType(Record); |
| 908 | } |
| 909 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 910 | /// Build a new Enum type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 911 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 912 | return SemaRef.Context.getTypeDeclType(Enum); |
| 913 | } |
| John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 914 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 915 | /// Build a new typeof(expr) type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 916 | /// |
| 917 | /// By default, performs semantic analysis when building the typeof type. |
| 918 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 919 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 920 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 921 | /// Build a new typeof(type) type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 922 | /// |
| 923 | /// By default, builds a new TypeOfType with the given underlying type. |
| 924 | QualType RebuildTypeOfType(QualType Underlying); |
| 925 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 926 | /// Build a new unary transform type. |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 927 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 928 | UnaryTransformType::UTTKind UKind, |
| 929 | SourceLocation Loc); |
| 930 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 931 | /// Build a new C++11 decltype type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 932 | /// |
| 933 | /// By default, performs semantic analysis when building the decltype type. |
| 934 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 935 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 937 | /// Build a new C++11 auto type. |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 938 | /// |
| 939 | /// By default, builds a new AutoType with the given deduced type. |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 940 | QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) { |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 941 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 942 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 943 | // that we'll retry deduction after the transformation. |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 944 | return SemaRef.Context.getAutoType(Deduced, Keyword, |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 945 | /*IsDependent*/ false); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 948 | /// By default, builds a new DeducedTemplateSpecializationType with the given |
| 949 | /// deduced type. |
| 950 | QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, |
| 951 | QualType Deduced) { |
| 952 | return SemaRef.Context.getDeducedTemplateSpecializationType( |
| 953 | Template, Deduced, /*IsDependent*/ false); |
| 954 | } |
| 955 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 956 | /// Build a new template specialization type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 957 | /// |
| 958 | /// By default, performs semantic analysis when building the template |
| 959 | /// specialization type. Subclasses may override this routine to provide |
| 960 | /// different behavior. |
| 961 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 962 | SourceLocation TemplateLoc, |
| Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 963 | TemplateArgumentListInfo &Args); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 965 | /// Build a new parenthesized type. |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 966 | /// |
| 967 | /// By default, builds a new ParenType type from the inner type. |
| 968 | /// Subclasses may override this routine to provide different behavior. |
| 969 | QualType RebuildParenType(QualType InnerType) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 970 | return SemaRef.BuildParenType(InnerType); |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 973 | /// Build a new qualified name type. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 974 | /// |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 975 | /// By default, builds a new ElaboratedType type from the keyword, |
| 976 | /// the nested-name-specifier and the named type. |
| 977 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | 954b5de | 2010-11-04 19:04:38 +0000 | [diff] [blame] | 978 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 979 | ElaboratedTypeKeyword Keyword, |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 980 | NestedNameSpecifierLoc QualifierLoc, |
| 981 | QualType Named) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 982 | return SemaRef.Context.getElaboratedType(Keyword, |
| 983 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 984 | Named); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 986 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 987 | /// Build a new typename type that refers to a template-id. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 988 | /// |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 989 | /// By default, builds a new DependentNameType type from the |
| 990 | /// nested-name-specifier and the given type. Subclasses may override |
| 991 | /// this routine to provide different behavior. |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 992 | QualType RebuildDependentTemplateSpecializationType( |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 993 | ElaboratedTypeKeyword Keyword, |
| 994 | NestedNameSpecifierLoc QualifierLoc, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 995 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 996 | const IdentifierInfo *Name, |
| 997 | SourceLocation NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 998 | TemplateArgumentListInfo &Args, |
| 999 | bool AllowInjectedClassName) { |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1000 | // Rebuild the template name. |
| 1001 | // TODO: avoid TemplateName abstraction |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1002 | CXXScopeSpec SS; |
| 1003 | SS.Adopt(QualifierLoc); |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1004 | TemplateName InstName = getDerived().RebuildTemplateName( |
| 1005 | SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, |
| 1006 | AllowInjectedClassName); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1007 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1008 | if (InstName.isNull()) |
| 1009 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1010 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1011 | // If it's still dependent, make a dependent specialization. |
| 1012 | if (InstName.getAsDependentTemplateName()) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1013 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 1014 | QualifierLoc.getNestedNameSpecifier(), |
| 1015 | Name, |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1016 | Args); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1017 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1018 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 1019 | // specialization. |
| 1020 | QualType T = |
| 1021 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 1022 | if (T.isNull()) return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1023 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1024 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1025 | return T; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1026 | |
| 1027 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1028 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 1029 | T); |
| 1030 | } |
| 1031 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1032 | /// Build a new typename type that refers to an identifier. |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1033 | /// |
| 1034 | /// By default, performs semantic analysis when building the typename type |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1035 | /// (or elaborated type). Subclasses may override this routine to provide |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 1036 | /// different behavior. |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1037 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1038 | SourceLocation KeywordLoc, |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1039 | NestedNameSpecifierLoc QualifierLoc, |
| 1040 | const IdentifierInfo *Id, |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1041 | SourceLocation IdLoc, |
| 1042 | bool DeducedTSTContext) { |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1043 | CXXScopeSpec SS; |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1044 | SS.Adopt(QualifierLoc); |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1045 | |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1046 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1047 | // If the name is still dependent, just build a new dependent name type. |
| 1048 | if (!SemaRef.computeDeclContext(SS)) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1049 | return SemaRef.Context.getDependentNameType(Keyword, |
| 1050 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1051 | Id); |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 1054 | if (Keyword == ETK_None || Keyword == ETK_Typename) { |
| 1055 | QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
| 1056 | *Id, IdLoc); |
| 1057 | // If a dependent name resolves to a deduced template specialization type, |
| 1058 | // check that we're in one of the syntactic contexts permitting it. |
| 1059 | if (!DeducedTSTContext) { |
| 1060 | if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>( |
| 1061 | T.isNull() ? nullptr : T->getContainedDeducedType())) { |
| 1062 | SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst) |
| 1063 | << (int)SemaRef.getTemplateNameKindForDiagnostics( |
| 1064 | Deduced->getTemplateName()) |
| 1065 | << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0); |
| 1066 | if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl()) |
| 1067 | SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here); |
| 1068 | return QualType(); |
| 1069 | } |
| 1070 | } |
| 1071 | return T; |
| 1072 | } |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1073 | |
| 1074 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 1075 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1076 | // We had a dependent elaborated-type-specifier that has been transformed |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1077 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 1078 | // referring to. |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1079 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1080 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 1081 | if (!DC) |
| 1082 | return QualType(); |
| 1083 | |
| John McCall | bf8c519 | 2010-05-27 06:40:31 +0000 | [diff] [blame] | 1084 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 1085 | return QualType(); |
| 1086 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1087 | TagDecl *Tag = nullptr; |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1088 | SemaRef.LookupQualifiedName(Result, DC); |
| 1089 | switch (Result.getResultKind()) { |
| 1090 | case LookupResult::NotFound: |
| 1091 | case LookupResult::NotFoundInCurrentInstantiation: |
| 1092 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1093 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1094 | case LookupResult::Found: |
| 1095 | Tag = Result.getAsSingle<TagDecl>(); |
| 1096 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1097 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1098 | case LookupResult::FoundOverloaded: |
| 1099 | case LookupResult::FoundUnresolvedValue: |
| 1100 | llvm_unreachable("Tag lookup cannot find non-tags"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1101 | |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1102 | case LookupResult::Ambiguous: |
| 1103 | // Let the LookupResult structure handle ambiguities. |
| 1104 | return QualType(); |
| 1105 | } |
| 1106 | |
| 1107 | if (!Tag) { |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1108 | // Check where the name exists but isn't a tag type and use that to emit |
| 1109 | // better diagnostics. |
| 1110 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1111 | SemaRef.LookupQualifiedName(Result, DC); |
| 1112 | switch (Result.getResultKind()) { |
| 1113 | case LookupResult::Found: |
| 1114 | case LookupResult::FoundOverloaded: |
| 1115 | case LookupResult::FoundUnresolvedValue: { |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1116 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| Reid Kleckner | 1a4ab7e | 2016-12-09 19:47:58 +0000 | [diff] [blame] | 1117 | Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); |
| 1118 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl |
| 1119 | << NTK << Kind; |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1120 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1121 | break; |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1122 | } |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1123 | default: |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1124 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| Stephan Tolksdorf | eb7708d | 2014-03-13 20:34:03 +0000 | [diff] [blame] | 1125 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
| Nick Lewycky | 0c43808 | 2011-01-24 19:01:04 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1128 | return QualType(); |
| 1129 | } |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1130 | |
| Richard Trieu | caa33d3 | 2011-06-10 03:11:26 +0000 | [diff] [blame] | 1131 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| Justin Bogner | c6ecb7c | 2015-07-10 23:05:47 +0000 | [diff] [blame] | 1132 | IdLoc, Id)) { |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 1133 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
| Douglas Gregor | e677daf | 2010-03-31 22:19:08 +0000 | [diff] [blame] | 1134 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1135 | return QualType(); |
| 1136 | } |
| 1137 | |
| 1138 | // Build the elaborated-type-specifier type. |
| 1139 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1140 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1141 | QualifierLoc.getNestedNameSpecifier(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 1142 | T); |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 1143 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1145 | /// Build a new pack expansion type. |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1146 | /// |
| 1147 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1148 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1149 | QualType RebuildPackExpansionType(QualType Pattern, |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1150 | SourceRange PatternRange, |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1151 | SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 1152 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 1153 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1154 | NumExpansions); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1157 | /// Build a new atomic type given its value type. |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1158 | /// |
| 1159 | /// By default, performs semantic analysis when building the atomic type. |
| 1160 | /// Subclasses may override this routine to provide different behavior. |
| 1161 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1162 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1163 | /// Build a new pipe type given its value type. |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 1164 | QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, |
| 1165 | bool isReadPipe); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 1166 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1167 | /// Build a new template name given a nested name specifier, a flag |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1168 | /// indicating whether the "template" keyword was provided, and the template |
| 1169 | /// that the template name refers to. |
| 1170 | /// |
| 1171 | /// By default, builds the new template name directly. Subclasses may override |
| 1172 | /// this routine to provide different behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1173 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1174 | bool TemplateKW, |
| 1175 | TemplateDecl *Template); |
| 1176 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1177 | /// Build a new template name given a nested name specifier and the |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 1178 | /// name that is referred to as a template. |
| 1179 | /// |
| 1180 | /// By default, performs semantic analysis to determine whether the name can |
| 1181 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1182 | /// template name. Subclasses may override this routine to provide different |
| 1183 | /// behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1184 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1185 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1186 | const IdentifierInfo &Name, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1187 | SourceLocation NameLoc, QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1188 | NamedDecl *FirstQualifierInScope, |
| 1189 | bool AllowInjectedClassName); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1191 | /// Build a new template name given a nested name specifier and the |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1192 | /// overloaded operator name that is referred to as a template. |
| 1193 | /// |
| 1194 | /// By default, performs semantic analysis to determine whether the name can |
| 1195 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1196 | /// template name. Subclasses may override this routine to provide different |
| 1197 | /// behavior. |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 1198 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1199 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1200 | OverloadedOperatorKind Operator, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 1201 | SourceLocation NameLoc, QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 1202 | bool AllowInjectedClassName); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1203 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1204 | /// Build a new template name given a template template parameter pack |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1205 | /// and the |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1206 | /// |
| 1207 | /// By default, performs semantic analysis to determine whether the name can |
| 1208 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1209 | /// template name. Subclasses may override this routine to provide different |
| 1210 | /// behavior. |
| 1211 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1212 | const TemplateArgument &ArgPack) { |
| 1213 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1214 | } |
| 1215 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1216 | /// Build a new compound statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1217 | /// |
| 1218 | /// By default, performs semantic analysis to build the new statement. |
| 1219 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1220 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1221 | MultiStmtArg Statements, |
| 1222 | SourceLocation RBraceLoc, |
| 1223 | bool IsStmtExpr) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1224 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1225 | IsStmtExpr); |
| 1226 | } |
| 1227 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1228 | /// Build a new case statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1229 | /// |
| 1230 | /// By default, performs semantic analysis to build the new statement. |
| 1231 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1232 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1233 | Expr *LHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1234 | SourceLocation EllipsisLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1235 | Expr *RHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1236 | SourceLocation ColonLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1237 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1238 | ColonLoc); |
| 1239 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1241 | /// Attach the body to a new case statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1242 | /// |
| 1243 | /// By default, performs semantic analysis to build the new statement. |
| 1244 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1245 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1246 | getSema().ActOnCaseStmtBody(S, Body); |
| 1247 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1248 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1249 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1250 | /// Build a new default statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1251 | /// |
| 1252 | /// By default, performs semantic analysis to build the new statement. |
| 1253 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1254 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1255 | SourceLocation ColonLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1256 | Stmt *SubStmt) { |
| 1257 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1258 | /*CurScope=*/nullptr); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1259 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1261 | /// Build a new label statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1262 | /// |
| 1263 | /// By default, performs semantic analysis to build the new statement. |
| 1264 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1265 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1266 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1267 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1268 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1269 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1270 | /// Build a new label statement. |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1271 | /// |
| 1272 | /// By default, performs semantic analysis to build the new statement. |
| 1273 | /// Subclasses may override this routine to provide different behavior. |
| Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 1274 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1275 | ArrayRef<const Attr*> Attrs, |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1276 | Stmt *SubStmt) { |
| 1277 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1278 | } |
| 1279 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1280 | /// Build a new "if" statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1281 | /// |
| 1282 | /// By default, performs semantic analysis to build the new statement. |
| 1283 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 1284 | StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1285 | Sema::ConditionResult Cond, Stmt *Init, Stmt *Then, |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 1286 | SourceLocation ElseLoc, Stmt *Else) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1287 | return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then, |
| Richard Smith | c7a05a9 | 2016-06-29 21:17:59 +0000 | [diff] [blame] | 1288 | ElseLoc, Else); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1289 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1290 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1291 | /// Start building a new switch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1292 | /// |
| 1293 | /// By default, performs semantic analysis to build the new statement. |
| 1294 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1295 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1296 | Sema::ConditionResult Cond) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 1297 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1298 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1300 | /// Attach the body to the switch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1301 | /// |
| 1302 | /// By default, performs semantic analysis to build the new statement. |
| 1303 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1304 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1305 | Stmt *Switch, Stmt *Body) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1306 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1309 | /// Build a new while statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new statement. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1313 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, |
| 1314 | Sema::ConditionResult Cond, Stmt *Body) { |
| 1315 | return getSema().ActOnWhileStmt(WhileLoc, Cond, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1316 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1318 | /// Build a new do-while statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1319 | /// |
| 1320 | /// By default, performs semantic analysis to build the new statement. |
| 1321 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1322 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1323 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1324 | Expr *Cond, SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1325 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1326 | Cond, RParenLoc); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1329 | /// Build a new for statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1330 | /// |
| 1331 | /// By default, performs semantic analysis to build the new statement. |
| 1332 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1333 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1334 | Stmt *Init, Sema::ConditionResult Cond, |
| 1335 | Sema::FullExprArg Inc, SourceLocation RParenLoc, |
| 1336 | Stmt *Body) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1337 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 1338 | Inc, RParenLoc, Body); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1339 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1341 | /// Build a new goto statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1342 | /// |
| 1343 | /// By default, performs semantic analysis to build the new statement. |
| 1344 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1345 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1346 | LabelDecl *Label) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 1347 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1350 | /// Build a new indirect goto statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1351 | /// |
| 1352 | /// By default, performs semantic analysis to build the new statement. |
| 1353 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1354 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1355 | SourceLocation StarLoc, |
| 1356 | Expr *Target) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1357 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1358 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1360 | /// Build a new return statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1361 | /// |
| 1362 | /// By default, performs semantic analysis to build the new statement. |
| 1363 | /// Subclasses may override this routine to provide different behavior. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1364 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
| Nick Lewycky | d78f92f | 2014-05-03 00:41:18 +0000 | [diff] [blame] | 1365 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1366 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1368 | /// Build a new declaration statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1369 | /// |
| 1370 | /// By default, performs semantic analysis to build the new statement. |
| 1371 | /// Subclasses may override this routine to provide different behavior. |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 1372 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
| Rafael Espindola | ab41769 | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 1373 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1374 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
| Richard Smith | 2abf676 | 2011-02-23 00:37:57 +0000 | [diff] [blame] | 1375 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 1376 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1377 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1378 | /// Build a new inline asm statement. |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1379 | /// |
| 1380 | /// By default, performs semantic analysis to build the new statement. |
| 1381 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1382 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1383 | bool IsVolatile, unsigned NumOutputs, |
| 1384 | unsigned NumInputs, IdentifierInfo **Names, |
| 1385 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1386 | Expr *AsmString, MultiExprArg Clobbers, |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 1387 | unsigned NumLabels, |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1388 | SourceLocation RParenLoc) { |
| 1389 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1390 | NumInputs, Names, Constraints, Exprs, |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 1391 | AsmString, Clobbers, NumLabels, RParenLoc); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 1392 | } |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1393 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1394 | /// Build a new MS style inline asm statement. |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1395 | /// |
| 1396 | /// By default, performs semantic analysis to build the new statement. |
| 1397 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 1398 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1399 | ArrayRef<Token> AsmToks, |
| 1400 | StringRef AsmString, |
| 1401 | unsigned NumOutputs, unsigned NumInputs, |
| 1402 | ArrayRef<StringRef> Constraints, |
| 1403 | ArrayRef<StringRef> Clobbers, |
| 1404 | ArrayRef<Expr*> Exprs, |
| 1405 | SourceLocation EndLoc) { |
| 1406 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1407 | NumOutputs, NumInputs, |
| 1408 | Constraints, Clobbers, Exprs, EndLoc); |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1411 | /// Build a new co_return statement. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1412 | /// |
| 1413 | /// By default, performs semantic analysis to build the new statement. |
| 1414 | /// Subclasses may override this routine to provide different behavior. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1415 | StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, |
| 1416 | bool IsImplicit) { |
| 1417 | return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1420 | /// Build a new co_await expression. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1421 | /// |
| 1422 | /// By default, performs semantic analysis to build the new expression. |
| 1423 | /// Subclasses may override this routine to provide different behavior. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1424 | ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, |
| 1425 | bool IsImplicit) { |
| 1426 | return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit); |
| 1427 | } |
| 1428 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1429 | /// Build a new co_await expression. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1430 | /// |
| 1431 | /// By default, performs semantic analysis to build the new expression. |
| 1432 | /// Subclasses may override this routine to provide different behavior. |
| 1433 | ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, |
| 1434 | Expr *Result, |
| 1435 | UnresolvedLookupExpr *Lookup) { |
| 1436 | return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1439 | /// Build a new co_yield expression. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 1440 | /// |
| 1441 | /// By default, performs semantic analysis to build the new expression. |
| 1442 | /// Subclasses may override this routine to provide different behavior. |
| 1443 | ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
| 1444 | return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
| 1445 | } |
| 1446 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 1447 | StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { |
| 1448 | return getSema().BuildCoroutineBodyStmt(Args); |
| 1449 | } |
| 1450 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1451 | /// Build a new Objective-C \@try statement. |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1452 | /// |
| 1453 | /// By default, performs semantic analysis to build the new statement. |
| 1454 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1455 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1456 | Stmt *TryBody, |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1457 | MultiStmtArg CatchStmts, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1458 | Stmt *Finally) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1459 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1460 | Finally); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1463 | /// Rebuild an Objective-C exception declaration. |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1464 | /// |
| 1465 | /// By default, performs semantic analysis to build the new declaration. |
| 1466 | /// Subclasses may override this routine to provide different behavior. |
| 1467 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1468 | TypeSourceInfo *TInfo, QualType T) { |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1469 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1470 | ExceptionDecl->getInnerLocStart(), |
| 1471 | ExceptionDecl->getLocation(), |
| 1472 | ExceptionDecl->getIdentifier()); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1473 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1474 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1475 | /// Build a new Objective-C \@catch statement. |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1476 | /// |
| 1477 | /// By default, performs semantic analysis to build the new statement. |
| 1478 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1479 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1480 | SourceLocation RParenLoc, |
| 1481 | VarDecl *Var, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1482 | Stmt *Body) { |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1483 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1484 | Var, Body); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 1485 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1486 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1487 | /// Build a new Objective-C \@finally statement. |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1488 | /// |
| 1489 | /// By default, performs semantic analysis to build the new statement. |
| 1490 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1491 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1492 | Stmt *Body) { |
| 1493 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 1494 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1495 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1496 | /// Build a new Objective-C \@throw statement. |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1497 | /// |
| 1498 | /// By default, performs semantic analysis to build the new statement. |
| 1499 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1500 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1501 | Expr *Operand) { |
| 1502 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 1503 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 1504 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1505 | /// Build a new OpenMP executable directive. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1506 | /// |
| 1507 | /// By default, performs semantic analysis to build the new statement. |
| 1508 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1509 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1510 | DeclarationNameInfo DirName, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1511 | OpenMPDirectiveKind CancelRegion, |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1512 | ArrayRef<OMPClause *> Clauses, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1513 | Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1514 | SourceLocation EndLoc) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1515 | return getSema().ActOnOpenMPExecutableDirective( |
| 1516 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1519 | /// Build a new OpenMP 'if' clause. |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1520 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1521 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1522 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1523 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1524 | Expr *Condition, SourceLocation StartLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1525 | SourceLocation LParenLoc, |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1526 | SourceLocation NameModifierLoc, |
| 1527 | SourceLocation ColonLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1528 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1529 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
| 1530 | LParenLoc, NameModifierLoc, ColonLoc, |
| 1531 | EndLoc); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1534 | /// Build a new OpenMP 'final' clause. |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1535 | /// |
| 1536 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1537 | /// Subclasses may override this routine to provide different behavior. |
| 1538 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1539 | SourceLocation LParenLoc, |
| 1540 | SourceLocation EndLoc) { |
| 1541 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1542 | EndLoc); |
| 1543 | } |
| 1544 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1545 | /// Build a new OpenMP 'num_threads' clause. |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1546 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1547 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1548 | /// Subclasses may override this routine to provide different behavior. |
| 1549 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1550 | SourceLocation StartLoc, |
| 1551 | SourceLocation LParenLoc, |
| 1552 | SourceLocation EndLoc) { |
| 1553 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1554 | LParenLoc, EndLoc); |
| 1555 | } |
| 1556 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1557 | /// Build a new OpenMP 'safelen' clause. |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1558 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1559 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1560 | /// Subclasses may override this routine to provide different behavior. |
| 1561 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1562 | SourceLocation LParenLoc, |
| 1563 | SourceLocation EndLoc) { |
| 1564 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1565 | } |
| 1566 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1567 | /// Build a new OpenMP 'simdlen' clause. |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1568 | /// |
| 1569 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1570 | /// Subclasses may override this routine to provide different behavior. |
| 1571 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1572 | SourceLocation LParenLoc, |
| 1573 | SourceLocation EndLoc) { |
| 1574 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1575 | } |
| 1576 | |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1577 | /// Build a new OpenMP 'allocator' clause. |
| 1578 | /// |
| 1579 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1580 | /// Subclasses may override this routine to provide different behavior. |
| 1581 | OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, |
| 1582 | SourceLocation LParenLoc, |
| 1583 | SourceLocation EndLoc) { |
| 1584 | return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc); |
| 1585 | } |
| 1586 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1587 | /// Build a new OpenMP 'collapse' clause. |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1588 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1589 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1590 | /// Subclasses may override this routine to provide different behavior. |
| 1591 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1592 | SourceLocation LParenLoc, |
| 1593 | SourceLocation EndLoc) { |
| 1594 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1595 | EndLoc); |
| 1596 | } |
| 1597 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1598 | /// Build a new OpenMP 'default' clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1599 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1600 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1601 | /// Subclasses may override this routine to provide different behavior. |
| 1602 | OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 1603 | SourceLocation KindKwLoc, |
| 1604 | SourceLocation StartLoc, |
| 1605 | SourceLocation LParenLoc, |
| 1606 | SourceLocation EndLoc) { |
| 1607 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1608 | StartLoc, LParenLoc, EndLoc); |
| 1609 | } |
| 1610 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1611 | /// Build a new OpenMP 'proc_bind' clause. |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +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 | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 1616 | SourceLocation KindKwLoc, |
| 1617 | SourceLocation StartLoc, |
| 1618 | SourceLocation LParenLoc, |
| 1619 | SourceLocation EndLoc) { |
| 1620 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1621 | StartLoc, LParenLoc, EndLoc); |
| 1622 | } |
| 1623 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1624 | /// Build a new OpenMP 'schedule' clause. |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1625 | /// |
| 1626 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1627 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1628 | OMPClause *RebuildOMPScheduleClause( |
| 1629 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 1630 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 1631 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 1632 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1633 | return getSema().ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1634 | M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
| 1635 | CommaLoc, EndLoc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1638 | /// Build a new OpenMP 'ordered' clause. |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1639 | /// |
| 1640 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1641 | /// Subclasses may override this routine to provide different behavior. |
| 1642 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1643 | SourceLocation EndLoc, |
| 1644 | SourceLocation LParenLoc, Expr *Num) { |
| 1645 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1646 | } |
| 1647 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1648 | /// Build a new OpenMP 'private' clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1649 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1650 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1651 | /// Subclasses may override this routine to provide different behavior. |
| 1652 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1653 | SourceLocation StartLoc, |
| 1654 | SourceLocation LParenLoc, |
| 1655 | SourceLocation EndLoc) { |
| 1656 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1657 | EndLoc); |
| 1658 | } |
| 1659 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1660 | /// Build a new OpenMP 'firstprivate' clause. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1661 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1662 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1663 | /// Subclasses may override this routine to provide different behavior. |
| 1664 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1665 | SourceLocation StartLoc, |
| 1666 | SourceLocation LParenLoc, |
| 1667 | SourceLocation EndLoc) { |
| 1668 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1669 | EndLoc); |
| 1670 | } |
| 1671 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1672 | /// Build a new OpenMP 'lastprivate' clause. |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1673 | /// |
| 1674 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1675 | /// Subclasses may override this routine to provide different behavior. |
| 1676 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1677 | SourceLocation StartLoc, |
| 1678 | SourceLocation LParenLoc, |
| 1679 | SourceLocation EndLoc) { |
| 1680 | return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, |
| 1681 | EndLoc); |
| 1682 | } |
| 1683 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1684 | /// Build a new OpenMP 'shared' clause. |
| Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1685 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1686 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 1687 | /// Subclasses may override this routine to provide different behavior. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1688 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1689 | SourceLocation StartLoc, |
| 1690 | SourceLocation LParenLoc, |
| 1691 | SourceLocation EndLoc) { |
| 1692 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1693 | EndLoc); |
| 1694 | } |
| 1695 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1696 | /// Build a new OpenMP 'reduction' clause. |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1697 | /// |
| 1698 | /// By default, performs semantic analysis to build the new statement. |
| 1699 | /// Subclasses may override this routine to provide different behavior. |
| 1700 | OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList, |
| 1701 | SourceLocation StartLoc, |
| 1702 | SourceLocation LParenLoc, |
| 1703 | SourceLocation ColonLoc, |
| 1704 | SourceLocation EndLoc, |
| 1705 | CXXScopeSpec &ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1706 | const DeclarationNameInfo &ReductionId, |
| 1707 | ArrayRef<Expr *> UnresolvedReductions) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1708 | return getSema().ActOnOpenMPReductionClause( |
| 1709 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 1710 | ReductionId, UnresolvedReductions); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 1713 | /// Build a new OpenMP 'task_reduction' clause. |
| 1714 | /// |
| 1715 | /// By default, performs semantic analysis to build the new statement. |
| 1716 | /// Subclasses may override this routine to provide different behavior. |
| 1717 | OMPClause *RebuildOMPTaskReductionClause( |
| 1718 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1719 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 1720 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1721 | const DeclarationNameInfo &ReductionId, |
| 1722 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1723 | return getSema().ActOnOpenMPTaskReductionClause( |
| 1724 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1725 | ReductionId, UnresolvedReductions); |
| 1726 | } |
| 1727 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1728 | /// Build a new OpenMP 'in_reduction' clause. |
| 1729 | /// |
| 1730 | /// By default, performs semantic analysis to build the new statement. |
| 1731 | /// Subclasses may override this routine to provide different behavior. |
| 1732 | OMPClause * |
| 1733 | RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1734 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1735 | SourceLocation EndLoc, |
| 1736 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1737 | const DeclarationNameInfo &ReductionId, |
| 1738 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1739 | return getSema().ActOnOpenMPInReductionClause( |
| 1740 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1741 | ReductionId, UnresolvedReductions); |
| 1742 | } |
| 1743 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1744 | /// Build a new OpenMP 'linear' clause. |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1745 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1746 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1747 | /// Subclasses may override this routine to provide different behavior. |
| 1748 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1749 | SourceLocation StartLoc, |
| 1750 | SourceLocation LParenLoc, |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1751 | OpenMPLinearClauseKind Modifier, |
| 1752 | SourceLocation ModifierLoc, |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1753 | SourceLocation ColonLoc, |
| 1754 | SourceLocation EndLoc) { |
| 1755 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1756 | Modifier, ModifierLoc, ColonLoc, |
| 1757 | EndLoc); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1760 | /// Build a new OpenMP 'aligned' clause. |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1761 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1762 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1763 | /// Subclasses may override this routine to provide different behavior. |
| 1764 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1765 | SourceLocation StartLoc, |
| 1766 | SourceLocation LParenLoc, |
| 1767 | SourceLocation ColonLoc, |
| 1768 | SourceLocation EndLoc) { |
| 1769 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1770 | LParenLoc, ColonLoc, EndLoc); |
| 1771 | } |
| 1772 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1773 | /// Build a new OpenMP 'copyin' clause. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1774 | /// |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 1775 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1776 | /// Subclasses may override this routine to provide different behavior. |
| 1777 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1778 | SourceLocation StartLoc, |
| 1779 | SourceLocation LParenLoc, |
| 1780 | SourceLocation EndLoc) { |
| 1781 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1782 | EndLoc); |
| 1783 | } |
| 1784 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1785 | /// Build a new OpenMP 'copyprivate' clause. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1786 | /// |
| 1787 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1788 | /// Subclasses may override this routine to provide different behavior. |
| 1789 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1790 | SourceLocation StartLoc, |
| 1791 | SourceLocation LParenLoc, |
| 1792 | SourceLocation EndLoc) { |
| 1793 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1794 | EndLoc); |
| 1795 | } |
| 1796 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1797 | /// Build a new OpenMP 'flush' pseudo clause. |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1798 | /// |
| 1799 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1800 | /// Subclasses may override this routine to provide different behavior. |
| 1801 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1802 | SourceLocation StartLoc, |
| 1803 | SourceLocation LParenLoc, |
| 1804 | SourceLocation EndLoc) { |
| 1805 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1806 | EndLoc); |
| 1807 | } |
| 1808 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1809 | /// Build a new OpenMP 'depend' pseudo clause. |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1810 | /// |
| 1811 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1812 | /// Subclasses may override this routine to provide different behavior. |
| 1813 | OMPClause * |
| 1814 | RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1815 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1816 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1817 | SourceLocation EndLoc) { |
| 1818 | return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, |
| 1819 | StartLoc, LParenLoc, EndLoc); |
| 1820 | } |
| 1821 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1822 | /// Build a new OpenMP 'device' clause. |
| Michael Wong | e710d54 | 2015-08-07 16:16: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 *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 1827 | SourceLocation LParenLoc, |
| 1828 | SourceLocation EndLoc) { |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1829 | return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc, |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1830 | EndLoc); |
| 1831 | } |
| 1832 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1833 | /// Build a new OpenMP 'map' clause. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1834 | /// |
| 1835 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1836 | /// Subclasses may override this routine to provide different behavior. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1837 | OMPClause *RebuildOMPMapClause( |
| 1838 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 1839 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 1840 | CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, |
| 1841 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 1842 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1843 | const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 1844 | return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1845 | MapperIdScopeSpec, MapperId, MapType, |
| 1846 | IsMapTypeImplicit, MapLoc, ColonLoc, |
| 1847 | VarList, Locs, UnresolvedMappers); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 1850 | /// Build a new OpenMP 'allocate' clause. |
| 1851 | /// |
| 1852 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1853 | /// Subclasses may override this routine to provide different behavior. |
| 1854 | OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList, |
| 1855 | SourceLocation StartLoc, |
| 1856 | SourceLocation LParenLoc, |
| 1857 | SourceLocation ColonLoc, |
| 1858 | SourceLocation EndLoc) { |
| 1859 | return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc, |
| 1860 | LParenLoc, ColonLoc, EndLoc); |
| 1861 | } |
| 1862 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1863 | /// Build a new OpenMP 'num_teams' clause. |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1864 | /// |
| 1865 | /// By default, performs semantic analysis to build the new statement. |
| 1866 | /// Subclasses may override this routine to provide different behavior. |
| 1867 | OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
| 1868 | SourceLocation LParenLoc, |
| 1869 | SourceLocation EndLoc) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1870 | return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1871 | EndLoc); |
| 1872 | } |
| 1873 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1874 | /// Build a new OpenMP 'thread_limit' clause. |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1875 | /// |
| 1876 | /// By default, performs semantic analysis to build the new statement. |
| 1877 | /// Subclasses may override this routine to provide different behavior. |
| 1878 | OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, |
| 1879 | SourceLocation StartLoc, |
| 1880 | SourceLocation LParenLoc, |
| 1881 | SourceLocation EndLoc) { |
| 1882 | return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, |
| 1883 | LParenLoc, EndLoc); |
| 1884 | } |
| 1885 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1886 | /// Build a new OpenMP 'priority' clause. |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1887 | /// |
| 1888 | /// By default, performs semantic analysis to build the new statement. |
| 1889 | /// Subclasses may override this routine to provide different behavior. |
| 1890 | OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 1891 | SourceLocation LParenLoc, |
| 1892 | SourceLocation EndLoc) { |
| 1893 | return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, |
| 1894 | EndLoc); |
| 1895 | } |
| 1896 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1897 | /// Build a new OpenMP 'grainsize' clause. |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1898 | /// |
| 1899 | /// By default, performs semantic analysis to build the new statement. |
| 1900 | /// Subclasses may override this routine to provide different behavior. |
| 1901 | OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, |
| 1902 | SourceLocation LParenLoc, |
| 1903 | SourceLocation EndLoc) { |
| 1904 | return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, |
| 1905 | EndLoc); |
| 1906 | } |
| 1907 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1908 | /// Build a new OpenMP 'num_tasks' clause. |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1909 | /// |
| 1910 | /// By default, performs semantic analysis to build the new statement. |
| 1911 | /// Subclasses may override this routine to provide different behavior. |
| 1912 | OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
| 1913 | SourceLocation LParenLoc, |
| 1914 | SourceLocation EndLoc) { |
| 1915 | return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, |
| 1916 | EndLoc); |
| 1917 | } |
| 1918 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1919 | /// Build a new OpenMP 'hint' clause. |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1920 | /// |
| 1921 | /// By default, performs semantic analysis to build the new statement. |
| 1922 | /// Subclasses may override this routine to provide different behavior. |
| 1923 | OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 1924 | SourceLocation LParenLoc, |
| 1925 | SourceLocation EndLoc) { |
| 1926 | return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); |
| 1927 | } |
| 1928 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1929 | /// Build a new OpenMP 'dist_schedule' clause. |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1930 | /// |
| 1931 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1932 | /// Subclasses may override this routine to provide different behavior. |
| 1933 | OMPClause * |
| 1934 | RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
| 1935 | Expr *ChunkSize, SourceLocation StartLoc, |
| 1936 | SourceLocation LParenLoc, SourceLocation KindLoc, |
| 1937 | SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 1938 | return getSema().ActOnOpenMPDistScheduleClause( |
| 1939 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 1940 | } |
| 1941 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1942 | /// Build a new OpenMP 'to' clause. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1943 | /// |
| 1944 | /// By default, performs semantic analysis to build the new statement. |
| 1945 | /// Subclasses may override this routine to provide different behavior. |
| 1946 | OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 1947 | CXXScopeSpec &MapperIdScopeSpec, |
| 1948 | DeclarationNameInfo &MapperId, |
| 1949 | const OMPVarListLocTy &Locs, |
| 1950 | ArrayRef<Expr *> UnresolvedMappers) { |
| 1951 | return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId, |
| 1952 | Locs, UnresolvedMappers); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1955 | /// Build a new OpenMP 'from' clause. |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +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 | OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1960 | CXXScopeSpec &MapperIdScopeSpec, |
| 1961 | DeclarationNameInfo &MapperId, |
| 1962 | const OMPVarListLocTy &Locs, |
| 1963 | ArrayRef<Expr *> UnresolvedMappers) { |
| 1964 | return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId, |
| 1965 | Locs, UnresolvedMappers); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1968 | /// Build a new OpenMP 'use_device_ptr' clause. |
| 1969 | /// |
| 1970 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1971 | /// Subclasses may override this routine to provide different behavior. |
| 1972 | OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1973 | const OMPVarListLocTy &Locs) { |
| 1974 | return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1977 | /// Build a new OpenMP 'is_device_ptr' clause. |
| 1978 | /// |
| 1979 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1980 | /// Subclasses may override this routine to provide different behavior. |
| 1981 | OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1982 | const OMPVarListLocTy &Locs) { |
| 1983 | return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1986 | /// Rebuild the operand to an Objective-C \@synchronized statement. |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1987 | /// |
| 1988 | /// By default, performs semantic analysis to build the new statement. |
| 1989 | /// Subclasses may override this routine to provide different behavior. |
| 1990 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 1991 | Expr *object) { |
| 1992 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 1993 | } |
| 1994 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1995 | /// Build a new Objective-C \@synchronized statement. |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1996 | /// |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 1997 | /// By default, performs semantic analysis to build the new statement. |
| 1998 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1999 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 2000 | Expr *Object, Stmt *Body) { |
| 2001 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 2002 | } |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 2003 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2004 | /// Build a new Objective-C \@autoreleasepool statement. |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2005 | /// |
| 2006 | /// By default, performs semantic analysis to build the new statement. |
| 2007 | /// Subclasses may override this routine to provide different behavior. |
| 2008 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 2009 | Stmt *Body) { |
| 2010 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 2011 | } |
| John McCall | 5384823 | 2011-07-27 01:07:15 +0000 | [diff] [blame] | 2012 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2013 | /// Build a new Objective-C fast enumeration statement. |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 2014 | /// |
| 2015 | /// By default, performs semantic analysis to build the new statement. |
| 2016 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2017 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2018 | Stmt *Element, |
| 2019 | Expr *Collection, |
| 2020 | SourceLocation RParenLoc, |
| 2021 | Stmt *Body) { |
| Sam Panzer | 2c4ca0f | 2012-08-16 21:47:25 +0000 | [diff] [blame] | 2022 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
| Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 2023 | Element, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2024 | Collection, |
| Fariborz Jahanian | 450bb6e | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 2025 | RParenLoc); |
| 2026 | if (ForEachStmt.isInvalid()) |
| 2027 | return StmtError(); |
| 2028 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2029 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 2030 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2031 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2032 | /// Build a new C++ exception declaration. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2033 | /// |
| 2034 | /// By default, performs semantic analysis to build the new decaration. |
| 2035 | /// Subclasses may override this routine to provide different behavior. |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2036 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2037 | TypeSourceInfo *Declarator, |
| Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2038 | SourceLocation StartLoc, |
| 2039 | SourceLocation IdLoc, |
| 2040 | IdentifierInfo *Id) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2041 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
| Douglas Gregor | 40965fa | 2011-04-14 22:32:28 +0000 | [diff] [blame] | 2042 | StartLoc, IdLoc, Id); |
| 2043 | if (Var) |
| 2044 | getSema().CurContext->addDecl(Var); |
| 2045 | return Var; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2048 | /// Build a new C++ catch statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2049 | /// |
| 2050 | /// By default, performs semantic analysis to build the new statement. |
| 2051 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2052 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2053 | VarDecl *ExceptionDecl, |
| 2054 | Stmt *Handler) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2055 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 2056 | Handler)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2057 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2059 | /// Build a new C++ try statement. |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2060 | /// |
| 2061 | /// By default, performs semantic analysis to build the new statement. |
| 2062 | /// Subclasses may override this routine to provide different behavior. |
| Robert Wilhelm | cafda82 | 2013-08-22 09:20:03 +0000 | [diff] [blame] | 2063 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 2064 | ArrayRef<Stmt *> Handlers) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2065 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 2066 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2068 | /// Build a new C++0x range-based for statement. |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2069 | /// |
| 2070 | /// By default, performs semantic analysis to build the new statement. |
| 2071 | /// Subclasses may override this routine to provide different behavior. |
| 2072 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 2073 | SourceLocation CoawaitLoc, Stmt *Init, |
| 2074 | SourceLocation ColonLoc, Stmt *Range, |
| 2075 | Stmt *Begin, Stmt *End, Expr *Cond, |
| 2076 | Expr *Inc, Stmt *LoopVar, |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2077 | SourceLocation RParenLoc) { |
| Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 2078 | // If we've just learned that the range is actually an Objective-C |
| 2079 | // collection, treat this as an Objective-C fast enumeration loop. |
| 2080 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 2081 | if (RangeStmt->isSingleDecl()) { |
| 2082 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 2083 | if (RangeVar->isInvalidDecl()) |
| 2084 | return StmtError(); |
| 2085 | |
| Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 2086 | Expr *RangeExpr = RangeVar->getInit(); |
| 2087 | if (!RangeExpr->isTypeDependent() && |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 2088 | RangeExpr->getType()->isObjCObjectPointerType()) { |
| 2089 | // FIXME: Support init-statements in Objective-C++20 ranged for |
| 2090 | // statement. |
| 2091 | if (Init) { |
| 2092 | return SemaRef.Diag(Init->getBeginLoc(), |
| 2093 | diag::err_objc_for_range_init_stmt) |
| 2094 | << Init->getSourceRange(); |
| 2095 | } |
| 2096 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, |
| 2097 | RangeExpr, RParenLoc); |
| 2098 | } |
| Douglas Gregor | f7106af | 2013-04-08 18:40:13 +0000 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 2103 | return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc, |
| 2104 | Range, Begin, End, Cond, Inc, LoopVar, |
| 2105 | RParenLoc, Sema::BFRK_Rebuild); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2106 | } |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2107 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2108 | /// Build a new C++0x range-based for statement. |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2109 | /// |
| 2110 | /// By default, performs semantic analysis to build the new statement. |
| 2111 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2112 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 2113 | bool IsIfExists, |
| 2114 | NestedNameSpecifierLoc QualifierLoc, |
| 2115 | DeclarationNameInfo NameInfo, |
| 2116 | Stmt *Nested) { |
| 2117 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 2118 | QualifierLoc, NameInfo, Nested); |
| 2119 | } |
| 2120 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2121 | /// Attach body to a C++0x range-based for statement. |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2122 | /// |
| 2123 | /// By default, performs semantic analysis to finish the new statement. |
| 2124 | /// Subclasses may override this routine to provide different behavior. |
| 2125 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 2126 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 2127 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2128 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2129 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 2130 | Stmt *TryBlock, Stmt *Handler) { |
| 2131 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2134 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2135 | Stmt *Block) { |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2136 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 2139 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| Nico Weber | d64657f | 2015-03-09 02:47:59 +0000 | [diff] [blame] | 2140 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2143 | /// Build a new predefined expression. |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 2144 | /// |
| 2145 | /// By default, performs semantic analysis to build the new expression. |
| 2146 | /// Subclasses may override this routine to provide different behavior. |
| 2147 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 2148 | PredefinedExpr::IdentKind IK) { |
| 2149 | return getSema().BuildPredefinedExpr(Loc, IK); |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2152 | /// Build a new expression that references a declaration. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2153 | /// |
| 2154 | /// By default, performs semantic analysis to build the new expression. |
| 2155 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2156 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2157 | LookupResult &R, |
| 2158 | bool RequiresADL) { |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2159 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 2160 | } |
| 2161 | |
| 2162 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2163 | /// Build a new expression that references a declaration. |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2164 | /// |
| 2165 | /// By default, performs semantic analysis to build the new expression. |
| 2166 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2167 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2168 | ValueDecl *VD, |
| 2169 | const DeclarationNameInfo &NameInfo, |
| 2170 | TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 2171 | CXXScopeSpec SS; |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2172 | SS.Adopt(QualifierLoc); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 2173 | |
| 2174 | // FIXME: loses template args. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2175 | |
| 2176 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2177 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2178 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2179 | /// Build a new expression in parentheses. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2180 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2181 | /// By default, performs semantic analysis to build the new expression. |
| 2182 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2183 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2184 | SourceLocation RParen) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2185 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2188 | /// Build a new pseudo-destructor expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2189 | /// |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 2190 | /// By default, performs semantic analysis to build the new expression. |
| 2191 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2192 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 2193 | SourceLocation OperatorLoc, |
| 2194 | bool isArrow, |
| 2195 | CXXScopeSpec &SS, |
| 2196 | TypeSourceInfo *ScopeType, |
| 2197 | SourceLocation CCLoc, |
| 2198 | SourceLocation TildeLoc, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 2199 | PseudoDestructorTypeStorage Destroyed); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2200 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2201 | /// Build a new unary operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2202 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2203 | /// By default, performs semantic analysis to build the new expression. |
| 2204 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2205 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2206 | UnaryOperatorKind Opc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2207 | Expr *SubExpr) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2208 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2209 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2211 | /// Build a new builtin offsetof expression. |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2212 | /// |
| 2213 | /// By default, performs semantic analysis to build the new expression. |
| 2214 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2215 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2216 | TypeSourceInfo *Type, |
| 2217 | ArrayRef<Sema::OffsetOfComponent> Components, |
| 2218 | SourceLocation RParenLoc) { |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2219 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 2220 | RParenLoc); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 2221 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2222 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2223 | /// Build a new sizeof, alignof or vec_step expression with a |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2224 | /// type argument. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2225 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2226 | /// By default, performs semantic analysis to build the new expression. |
| 2227 | /// Subclasses may override this routine to provide different behavior. |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2228 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 2229 | SourceLocation OpLoc, |
| 2230 | UnaryExprOrTypeTrait ExprKind, |
| 2231 | SourceRange R) { |
| 2232 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2235 | /// Build a new sizeof, alignof or vec step expression with an |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2236 | /// expression argument. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2238 | /// By default, performs semantic analysis to build the new expression. |
| 2239 | /// Subclasses may override this routine to provide different behavior. |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2240 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 2241 | UnaryExprOrTypeTrait ExprKind, |
| 2242 | SourceRange R) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2243 | ExprResult Result |
| Chandler Carruth | a923fb2 | 2011-05-29 07:32:14 +0000 | [diff] [blame] | 2244 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2245 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2246 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2247 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2248 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2249 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2250 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2251 | /// Build a new array subscript expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2252 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2253 | /// By default, performs semantic analysis to build the new expression. |
| 2254 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2255 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2256 | SourceLocation LBracketLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2257 | Expr *RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2258 | SourceLocation RBracketLoc) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2259 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2260 | LBracketLoc, RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2261 | RBracketLoc); |
| 2262 | } |
| 2263 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2264 | /// Build a new array section expression. |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 2265 | /// |
| 2266 | /// By default, performs semantic analysis to build the new expression. |
| 2267 | /// Subclasses may override this routine to provide different behavior. |
| 2268 | ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, |
| 2269 | Expr *LowerBound, |
| 2270 | SourceLocation ColonLoc, Expr *Length, |
| 2271 | SourceLocation RBracketLoc) { |
| 2272 | return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, |
| 2273 | ColonLoc, Length, RBracketLoc); |
| 2274 | } |
| 2275 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2276 | /// Build a new call expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2277 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2278 | /// By default, performs semantic analysis to build the new expression. |
| 2279 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2280 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2281 | MultiExprArg Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 2282 | SourceLocation RParenLoc, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2283 | Expr *ExecConfig = nullptr) { |
| Richard Smith | 255b85f | 2019-05-08 01:36:36 +0000 | [diff] [blame] | 2284 | return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args, |
| 2285 | RParenLoc, ExecConfig); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2286 | } |
| 2287 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2288 | /// Build a new member access expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2289 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2290 | /// By default, performs semantic analysis to build the new expression. |
| 2291 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2292 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2293 | bool isArrow, |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2294 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2295 | SourceLocation TemplateKWLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2296 | const DeclarationNameInfo &MemberNameInfo, |
| 2297 | ValueDecl *Member, |
| 2298 | NamedDecl *FoundDecl, |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 2299 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2300 | NamedDecl *FirstQualifierInScope) { |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2301 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 2302 | isArrow); |
| Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2303 | if (!Member->getDeclName()) { |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2304 | // We have a reference to an unnamed field. This is always the |
| 2305 | // base of an anonymous struct/union member access, i.e. the |
| 2306 | // field is always of record type. |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 2307 | assert(Member->getType()->isRecordType() && |
| 2308 | "unnamed member not of record type?"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2309 | |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2310 | BaseResult = |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2311 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
| John Wiegley | 0129629 | 2011-04-08 18:41:53 +0000 | [diff] [blame] | 2312 | QualifierLoc.getNestedNameSpecifier(), |
| 2313 | FoundDecl, Member); |
| 2314 | if (BaseResult.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2315 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2316 | Base = BaseResult.get(); |
| Eric Fiselier | 8439361 | 2018-04-08 05:11:59 +0000 | [diff] [blame] | 2317 | |
| 2318 | CXXScopeSpec EmptySS; |
| 2319 | return getSema().BuildFieldReferenceExpr( |
| 2320 | Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), |
| 2321 | DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo); |
| Anders Carlsson | 5da8484 | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 2322 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2323 | |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2324 | CXXScopeSpec SS; |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 2325 | SS.Adopt(QualifierLoc); |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 2326 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2327 | Base = BaseResult.get(); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2328 | QualType BaseType = Base->getType(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2329 | |
| Saleem Abdulrasool | 1f5f5c2 | 2017-04-20 22:23:10 +0000 | [diff] [blame] | 2330 | if (isArrow && !BaseType->isPointerType()) |
| 2331 | return ExprError(); |
| 2332 | |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2333 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 2334 | // cases; we should avoid this when possible. |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2335 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 2336 | R.addDecl(FoundDecl); |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 2337 | R.resolveKind(); |
| 2338 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2339 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2340 | SS, TemplateKWLoc, |
| 2341 | FirstQualifierInScope, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2342 | R, ExplicitTemplateArgs, |
| 2343 | /*S*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2344 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2345 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2346 | /// Build a new binary operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2347 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2348 | /// By default, performs semantic analysis to build the new expression. |
| 2349 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2350 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 2351 | BinaryOperatorKind Opc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2352 | Expr *LHS, Expr *RHS) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2353 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2356 | /// Build a new conditional operator expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2357 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2358 | /// By default, performs semantic analysis to build the new expression. |
| 2359 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2360 | ExprResult RebuildConditionalOperator(Expr *Cond, |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2361 | SourceLocation QuestionLoc, |
| 2362 | Expr *LHS, |
| 2363 | SourceLocation ColonLoc, |
| 2364 | Expr *RHS) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2365 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 2366 | LHS, RHS); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2369 | /// Build a new C-style cast expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2370 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2371 | /// By default, performs semantic analysis to build the new expression. |
| 2372 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2373 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2374 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2375 | SourceLocation RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2376 | Expr *SubExpr) { |
| John McCall | ebe5474 | 2010-01-15 18:56:44 +0000 | [diff] [blame] | 2377 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2378 | SubExpr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2379 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2380 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2381 | /// Build a new compound literal expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2382 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2383 | /// By default, performs semantic analysis to build the new expression. |
| 2384 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2385 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2386 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2387 | SourceLocation RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2388 | Expr *Init) { |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 2389 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2390 | Init); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2391 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2392 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2393 | /// Build a new extended vector element access expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2394 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2395 | /// By default, performs semantic analysis to build the new expression. |
| 2396 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2397 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2398 | SourceLocation OpLoc, |
| 2399 | SourceLocation AccessorLoc, |
| 2400 | IdentifierInfo &Accessor) { |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2401 | |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2402 | CXXScopeSpec SS; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2403 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2404 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2405 | OpLoc, /*IsArrow*/ false, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2406 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 2407 | /*FirstQualifierInScope*/ nullptr, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2408 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2409 | /* TemplateArgs */ nullptr, |
| 2410 | /*S*/ nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2411 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2412 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2413 | /// Build a new initializer list expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2414 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2415 | /// By default, performs semantic analysis to build the new expression. |
| 2416 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2417 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
| John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 2418 | MultiExprArg Inits, |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 2419 | SourceLocation RBraceLoc) { |
| 2420 | return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2421 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2422 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2423 | /// Build a new designated initializer expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2424 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2425 | /// By default, performs semantic analysis to build the new expression. |
| 2426 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2427 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2428 | MultiExprArg ArrayExprs, |
| 2429 | SourceLocation EqualOrColonLoc, |
| 2430 | bool GNUSyntax, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2431 | Expr *Init) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2432 | ExprResult Result |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2433 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2434 | Init); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2435 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2436 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2437 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2438 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2439 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2440 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2441 | /// Build a new value-initialized expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2442 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2443 | /// By default, builds the implicit value initialization without performing |
| 2444 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2445 | /// different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2446 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2447 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2448 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2449 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2450 | /// Build a new \c va_arg expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2451 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2452 | /// By default, performs semantic analysis to build the new expression. |
| 2453 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2454 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2455 | Expr *SubExpr, TypeSourceInfo *TInfo, |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2456 | SourceLocation RParenLoc) { |
| 2457 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2458 | SubExpr, TInfo, |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 2459 | RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2462 | /// Build a new expression list in parentheses. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2463 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2464 | /// By default, performs semantic analysis to build the new expression. |
| 2465 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2466 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 2467 | MultiExprArg SubExprs, |
| 2468 | SourceLocation RParenLoc) { |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2469 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2470 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2471 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2472 | /// Build a new address-of-label expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2473 | /// |
| 2474 | /// By default, performs semantic analysis, using the name of the label |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2475 | /// rather than attempting to map the label statement itself. |
| 2476 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2477 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 2478 | SourceLocation LabelLoc, LabelDecl *Label) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 2479 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2480 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2481 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2482 | /// Build a new GNU statement expression. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2483 | /// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2484 | /// By default, performs semantic analysis to build the new expression. |
| 2485 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2486 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2487 | Stmt *SubStmt, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2488 | SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2489 | return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2490 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2491 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2492 | /// Build a new __builtin_choose_expr expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2493 | /// |
| 2494 | /// By default, performs semantic analysis to build the new expression. |
| 2495 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2496 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2497 | Expr *Cond, Expr *LHS, Expr *RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2498 | SourceLocation RParenLoc) { |
| 2499 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2500 | Cond, LHS, RHS, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2501 | RParenLoc); |
| 2502 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2503 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2504 | /// Build a new generic selection expression. |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2505 | /// |
| 2506 | /// By default, performs semantic analysis to build the new expression. |
| 2507 | /// Subclasses may override this routine to provide different behavior. |
| 2508 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2509 | SourceLocation DefaultLoc, |
| 2510 | SourceLocation RParenLoc, |
| 2511 | Expr *ControllingExpr, |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2512 | ArrayRef<TypeSourceInfo *> Types, |
| 2513 | ArrayRef<Expr *> Exprs) { |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2514 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 2515 | ControllingExpr, Types, Exprs); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2518 | /// Build a new overloaded operator call 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 | /// The semantic analysis provides the behavior of template instantiation, |
| 2522 | /// copying with transformations that turn what looks like an overloaded |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2523 | /// operator call into a use of a builtin operator, performing |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2524 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2525 | /// provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2526 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2527 | SourceLocation OpLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2528 | Expr *Callee, |
| 2529 | Expr *First, |
| 2530 | Expr *Second); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2531 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2532 | /// Build a new C++ "named" cast expression, such as static_cast or |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2533 | /// reinterpret_cast. |
| 2534 | /// |
| 2535 | /// By default, this routine dispatches to one of the more-specific routines |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2536 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2537 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2538 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2539 | Stmt::StmtClass Class, |
| 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) { |
| 2546 | switch (Class) { |
| 2547 | case Stmt::CXXStaticCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2548 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2549 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2550 | SubExpr, RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2551 | |
| 2552 | case Stmt::CXXDynamicCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2553 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2554 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2555 | SubExpr, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2556 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2557 | case Stmt::CXXReinterpretCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2558 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2559 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2560 | SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2561 | RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2562 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2563 | case Stmt::CXXConstCastExprClass: |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2564 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2565 | RAngleLoc, LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2566 | SubExpr, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2567 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2568 | default: |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2569 | llvm_unreachable("Invalid C++ named cast"); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2570 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2571 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2572 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2573 | /// Build a new C++ static_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2574 | /// |
| 2575 | /// By default, performs semantic analysis to build the new expression. |
| 2576 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2577 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2578 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2579 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2580 | SourceLocation RAngleLoc, |
| 2581 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2582 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2583 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2584 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2585 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2586 | SourceRange(LAngleLoc, RAngleLoc), |
| 2587 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2590 | /// Build a new C++ dynamic_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2591 | /// |
| 2592 | /// By default, performs semantic analysis to build the new expression. |
| 2593 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2594 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2595 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2596 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2597 | SourceLocation RAngleLoc, |
| 2598 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2599 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2600 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2601 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2602 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2603 | SourceRange(LAngleLoc, RAngleLoc), |
| 2604 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2607 | /// Build a new C++ reinterpret_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2608 | /// |
| 2609 | /// By default, performs semantic analysis to build the new expression. |
| 2610 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2611 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2612 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2613 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2614 | SourceLocation RAngleLoc, |
| 2615 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2616 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2617 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2618 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2619 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2620 | SourceRange(LAngleLoc, RAngleLoc), |
| 2621 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2624 | /// Build a new C++ const_cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2625 | /// |
| 2626 | /// By default, performs semantic analysis to build the new expression. |
| 2627 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2628 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2629 | SourceLocation LAngleLoc, |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 2630 | TypeSourceInfo *TInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2631 | SourceLocation RAngleLoc, |
| 2632 | SourceLocation LParenLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2633 | Expr *SubExpr, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2634 | SourceLocation RParenLoc) { |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2635 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2636 | TInfo, SubExpr, |
| John McCall | d377e04 | 2010-01-15 19:13:16 +0000 | [diff] [blame] | 2637 | SourceRange(LAngleLoc, RAngleLoc), |
| 2638 | SourceRange(LParenLoc, RParenLoc)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2639 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2640 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2641 | /// Build a new C++ functional-style cast expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2642 | /// |
| 2643 | /// By default, performs semantic analysis to build the new expression. |
| 2644 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2645 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2646 | SourceLocation LParenLoc, |
| 2647 | Expr *Sub, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2648 | SourceLocation RParenLoc, |
| 2649 | bool ListInitialization) { |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2650 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2651 | MultiExprArg(&Sub, 1), RParenLoc, |
| 2652 | ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2653 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2654 | |
| Erik Pilkington | eee944e | 2019-07-02 18:28:13 +0000 | [diff] [blame] | 2655 | /// Build a new C++ __builtin_bit_cast expression. |
| 2656 | /// |
| 2657 | /// By default, performs semantic analysis to build the new expression. |
| 2658 | /// Subclasses may override this routine to provide different behavior. |
| 2659 | ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, |
| 2660 | TypeSourceInfo *TSI, Expr *Sub, |
| 2661 | SourceLocation RParenLoc) { |
| 2662 | return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc); |
| 2663 | } |
| 2664 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2665 | /// Build a new C++ typeid(type) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2666 | /// |
| 2667 | /// By default, performs semantic analysis to build the new expression. |
| 2668 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2669 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2670 | SourceLocation TypeidLoc, |
| 2671 | TypeSourceInfo *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2672 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2673 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2674 | RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2675 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2676 | |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2677 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2678 | /// Build a new C++ typeid(expr) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2679 | /// |
| 2680 | /// By default, performs semantic analysis to build the new expression. |
| 2681 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2682 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2683 | SourceLocation TypeidLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2684 | Expr *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2685 | SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2686 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2687 | RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2690 | /// Build a new C++ __uuidof(type) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +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. |
| 2694 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2695 | SourceLocation TypeidLoc, |
| 2696 | TypeSourceInfo *Operand, |
| 2697 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2698 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2699 | RParenLoc); |
| 2700 | } |
| 2701 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2702 | /// Build a new C++ __uuidof(expr) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2703 | /// |
| 2704 | /// By default, performs semantic analysis to build the new expression. |
| 2705 | /// Subclasses may override this routine to provide different behavior. |
| 2706 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2707 | SourceLocation TypeidLoc, |
| 2708 | Expr *Operand, |
| 2709 | SourceLocation RParenLoc) { |
| 2710 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2711 | RParenLoc); |
| 2712 | } |
| 2713 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2714 | /// Build a new C++ "this" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2715 | /// |
| 2716 | /// By default, builds a new "this" expression without performing any |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2717 | /// semantic analysis. Subclasses may override this routine to provide |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2718 | /// different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2719 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2720 | QualType ThisType, |
| 2721 | bool isImplicit) { |
| Richard Smith | 8458c9e | 2019-05-24 01:35:07 +0000 | [diff] [blame] | 2722 | return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2725 | /// Build a new C++ throw expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2726 | /// |
| 2727 | /// By default, performs semantic analysis to build the new expression. |
| 2728 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2729 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2730 | bool IsThrownVariableInScope) { |
| 2731 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2734 | /// Build a new C++ default-argument expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2735 | /// |
| 2736 | /// By default, builds a new default-argument expression, which does not |
| 2737 | /// require any semantic analysis. Subclasses may override this routine to |
| 2738 | /// provide different behavior. |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 2739 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) { |
| 2740 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, |
| 2741 | getSema().CurContext); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2744 | /// Build a new C++11 default-initialization expression. |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2745 | /// |
| 2746 | /// By default, builds a new default field initialization expression, which |
| 2747 | /// does not require any semantic analysis. Subclasses may override this |
| 2748 | /// routine to provide different behavior. |
| 2749 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2750 | FieldDecl *Field) { |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 2751 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field, |
| 2752 | getSema().CurContext); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2755 | /// Build a new C++ zero-initialization expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2756 | /// |
| 2757 | /// By default, performs semantic analysis to build the new expression. |
| 2758 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2759 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2760 | SourceLocation LParenLoc, |
| 2761 | SourceLocation RParenLoc) { |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2762 | return getSema().BuildCXXTypeConstructExpr( |
| 2763 | TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2764 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2765 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2766 | /// Build a new C++ "new" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2767 | /// |
| 2768 | /// By default, performs semantic analysis to build the new expression. |
| 2769 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2770 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2771 | bool UseGlobal, |
| 2772 | SourceLocation PlacementLParen, |
| 2773 | MultiExprArg PlacementArgs, |
| 2774 | SourceLocation PlacementRParen, |
| 2775 | SourceRange TypeIdParens, |
| 2776 | QualType AllocatedType, |
| 2777 | TypeSourceInfo *AllocatedTypeInfo, |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 2778 | Optional<Expr *> ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2779 | SourceRange DirectInitRange, |
| 2780 | Expr *Initializer) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2781 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2782 | PlacementLParen, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2783 | PlacementArgs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2784 | PlacementRParen, |
| Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2785 | TypeIdParens, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2786 | AllocatedType, |
| 2787 | AllocatedTypeInfo, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2788 | ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2789 | DirectInitRange, |
| 2790 | Initializer); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2791 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2792 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2793 | /// Build a new C++ "delete" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2794 | /// |
| 2795 | /// By default, performs semantic analysis to build the new expression. |
| 2796 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2797 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2798 | bool IsGlobalDelete, |
| 2799 | bool IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2800 | Expr *Operand) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2801 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2802 | Operand); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2803 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2804 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2805 | /// Build a new type trait expression. |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2806 | /// |
| 2807 | /// By default, performs semantic analysis to build the new expression. |
| 2808 | /// Subclasses may override this routine to provide different behavior. |
| 2809 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2810 | SourceLocation StartLoc, |
| 2811 | ArrayRef<TypeSourceInfo *> Args, |
| 2812 | SourceLocation RParenLoc) { |
| 2813 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2814 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2815 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2816 | /// Build a new array type trait expression. |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2817 | /// |
| 2818 | /// By default, performs semantic analysis to build the new expression. |
| 2819 | /// Subclasses may override this routine to provide different behavior. |
| 2820 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2821 | SourceLocation StartLoc, |
| 2822 | TypeSourceInfo *TSInfo, |
| 2823 | Expr *DimExpr, |
| 2824 | SourceLocation RParenLoc) { |
| 2825 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2826 | } |
| 2827 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2828 | /// Build a new expression trait expression. |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2829 | /// |
| 2830 | /// By default, performs semantic analysis to build the new expression. |
| 2831 | /// Subclasses may override this routine to provide different behavior. |
| 2832 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2833 | SourceLocation StartLoc, |
| 2834 | Expr *Queried, |
| 2835 | SourceLocation RParenLoc) { |
| 2836 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2837 | } |
| 2838 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2839 | /// Build a new (previously unresolved) declaration reference |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2840 | /// expression. |
| 2841 | /// |
| 2842 | /// By default, performs semantic analysis to build the new expression. |
| 2843 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2844 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2845 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2846 | SourceLocation TemplateKWLoc, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2847 | const DeclarationNameInfo &NameInfo, |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2848 | const TemplateArgumentListInfo *TemplateArgs, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2849 | bool IsAddressOfOperand, |
| 2850 | TypeSourceInfo **RecoveryTSI) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2851 | CXXScopeSpec SS; |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2852 | SS.Adopt(QualifierLoc); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2853 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2854 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2855 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2856 | TemplateArgs); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2857 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2858 | return getSema().BuildQualifiedDeclarationNameExpr( |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2859 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2862 | /// Build a new template-id expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2863 | /// |
| 2864 | /// By default, performs semantic analysis to build the new expression. |
| 2865 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2866 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2867 | SourceLocation TemplateKWLoc, |
| 2868 | LookupResult &R, |
| 2869 | bool RequiresADL, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2870 | const TemplateArgumentListInfo *TemplateArgs) { |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2871 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2872 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2875 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2876 | /// |
| 2877 | /// By default, performs semantic analysis to build the new expression. |
| 2878 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2879 | ExprResult RebuildCXXConstructExpr(QualType T, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2880 | SourceLocation Loc, |
| 2881 | CXXConstructorDecl *Constructor, |
| 2882 | bool IsElidable, |
| 2883 | MultiExprArg Args, |
| 2884 | bool HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2885 | bool ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2886 | bool StdInitListInitialization, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2887 | bool RequiresZeroInit, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2888 | CXXConstructExpr::ConstructionKind ConstructKind, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2889 | SourceRange ParenRange) { |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2890 | SmallVector<Expr*, 8> ConvertedArgs; |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2891 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
| Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2892 | ConvertedArgs)) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2893 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2894 | |
| Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 2895 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
| Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 2896 | IsElidable, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2897 | ConvertedArgs, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2898 | HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2899 | ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2900 | StdInitListInitialization, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2901 | RequiresZeroInit, ConstructKind, |
| 2902 | ParenRange); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2905 | /// Build a new implicit construction via inherited constructor |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2906 | /// expression. |
| 2907 | ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 2908 | CXXConstructorDecl *Constructor, |
| 2909 | bool ConstructsVBase, |
| 2910 | bool InheritedFromVBase) { |
| 2911 | return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 2912 | Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 2913 | } |
| 2914 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2915 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2916 | /// |
| 2917 | /// By default, performs semantic analysis to build the new expression. |
| 2918 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2919 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2920 | SourceLocation LParenOrBraceLoc, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2921 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2922 | SourceLocation RParenOrBraceLoc, |
| 2923 | bool ListInitialization) { |
| 2924 | return getSema().BuildCXXTypeConstructExpr( |
| 2925 | TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2928 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2929 | /// |
| 2930 | /// By default, performs semantic analysis to build the new expression. |
| 2931 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2932 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2933 | SourceLocation LParenLoc, |
| 2934 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2935 | SourceLocation RParenLoc, |
| 2936 | bool ListInitialization) { |
| 2937 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, |
| 2938 | RParenLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2939 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2940 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2941 | /// Build a new member reference expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +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. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2945 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2946 | QualType BaseType, |
| 2947 | bool IsArrow, |
| 2948 | SourceLocation OperatorLoc, |
| 2949 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2950 | SourceLocation TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2951 | NamedDecl *FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2952 | const DeclarationNameInfo &MemberNameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2953 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2954 | CXXScopeSpec SS; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2955 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2956 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2957 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2958 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2959 | SS, TemplateKWLoc, |
| 2960 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2961 | MemberNameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2962 | TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2965 | /// Build a new member reference expression. |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2966 | /// |
| 2967 | /// By default, performs semantic analysis to build the new expression. |
| 2968 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2969 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2970 | SourceLocation OperatorLoc, |
| 2971 | bool IsArrow, |
| 2972 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2973 | SourceLocation TemplateKWLoc, |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2974 | NamedDecl *FirstQualifierInScope, |
| 2975 | LookupResult &R, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2976 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2977 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2978 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2980 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2981 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2982 | SS, TemplateKWLoc, |
| 2983 | FirstQualifierInScope, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2984 | R, TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2985 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2986 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2987 | /// Build a new noexcept expression. |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2988 | /// |
| 2989 | /// By default, performs semantic analysis to build the new expression. |
| 2990 | /// Subclasses may override this routine to provide different behavior. |
| 2991 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2992 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2993 | } |
| 2994 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2995 | /// Build a new expression to compute the length of a parameter pack. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2996 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 2997 | NamedDecl *Pack, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2998 | SourceLocation PackLoc, |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2999 | SourceLocation RParenLoc, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3000 | Optional<unsigned> Length, |
| 3001 | ArrayRef<TemplateArgument> PartialArgs) { |
| 3002 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 3003 | RParenLoc, Length, PartialArgs); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 3004 | } |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3005 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 3006 | /// Build a new expression representing a call to a source location |
| 3007 | /// builtin. |
| 3008 | /// |
| 3009 | /// By default, performs semantic analysis to build the new expression. |
| 3010 | /// Subclasses may override this routine to provide different behavior. |
| 3011 | ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
| 3012 | SourceLocation BuiltinLoc, |
| 3013 | SourceLocation RPLoc, |
| 3014 | DeclContext *ParentContext) { |
| 3015 | return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext); |
| 3016 | } |
| 3017 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3018 | /// Build a new Objective-C boxed expression. |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 3019 | /// |
| 3020 | /// By default, performs semantic analysis to build the new expression. |
| 3021 | /// Subclasses may override this routine to provide different behavior. |
| 3022 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 3023 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 3024 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3025 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3026 | /// Build a new Objective-C array literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3027 | /// |
| 3028 | /// By default, performs semantic analysis to build the new expression. |
| 3029 | /// Subclasses may override this routine to provide different behavior. |
| 3030 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 3031 | Expr **Elements, unsigned NumElements) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3032 | return getSema().BuildObjCArrayLiteral(Range, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3033 | MultiExprArg(Elements, NumElements)); |
| 3034 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3035 | |
| 3036 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3037 | Expr *Base, Expr *Key, |
| 3038 | ObjCMethodDecl *getterMethod, |
| 3039 | ObjCMethodDecl *setterMethod) { |
| 3040 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 3041 | getterMethod, setterMethod); |
| 3042 | } |
| 3043 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3044 | /// Build a new Objective-C dictionary literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3045 | /// |
| 3046 | /// By default, performs semantic analysis to build the new expression. |
| 3047 | /// Subclasses may override this routine to provide different behavior. |
| 3048 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 3049 | MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 3050 | return getSema().BuildObjCDictionaryLiteral(Range, Elements); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3051 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3052 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3053 | /// Build a new Objective-C \@encode expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3054 | /// |
| 3055 | /// By default, performs semantic analysis to build the new expression. |
| 3056 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3057 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 3058 | TypeSourceInfo *EncodeTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3059 | SourceLocation RParenLoc) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3060 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3061 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3062 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3063 | /// Build a new Objective-C class message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3064 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3065 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3066 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3067 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3068 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3069 | MultiExprArg Args, |
| 3070 | SourceLocation RBracLoc) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3071 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 3072 | ReceiverTypeInfo->getType(), |
| 3073 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3074 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3075 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3078 | /// Build a new Objective-C instance message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3079 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3080 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3081 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3082 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3083 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3084 | MultiExprArg Args, |
| 3085 | SourceLocation RBracLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3086 | return SemaRef.BuildInstanceMessage(Receiver, |
| 3087 | Receiver->getType(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3088 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3089 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3090 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3093 | /// Build a new Objective-C instance/class message to 'super'. |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3094 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 3095 | Selector Sel, |
| 3096 | ArrayRef<SourceLocation> SelectorLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3097 | QualType SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3098 | ObjCMethodDecl *Method, |
| 3099 | SourceLocation LBracLoc, |
| 3100 | MultiExprArg Args, |
| 3101 | SourceLocation RBracLoc) { |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3102 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3103 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3104 | SuperLoc, |
| 3105 | Sel, Method, LBracLoc, SelectorLocs, |
| 3106 | RBracLoc, Args) |
| 3107 | : SemaRef.BuildClassMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3108 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3109 | SuperLoc, |
| 3110 | Sel, Method, LBracLoc, SelectorLocs, |
| 3111 | RBracLoc, Args); |
| 3112 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3113 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3116 | /// Build a new Objective-C ivar reference expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3117 | /// |
| 3118 | /// By default, performs semantic analysis to build the new expression. |
| 3119 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3120 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3121 | SourceLocation IvarLoc, |
| 3122 | bool IsArrow, bool IsFreeIvar) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3123 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3124 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| Alex Lorenz | 776b417 | 2017-02-03 14:22:33 +0000 | [diff] [blame] | 3125 | ExprResult Result = getSema().BuildMemberReferenceExpr( |
| 3126 | BaseArg, BaseArg->getType(), |
| 3127 | /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), |
| 3128 | /*FirstQualifierInScope=*/nullptr, NameInfo, |
| 3129 | /*TemplateArgs=*/nullptr, |
| 3130 | /*S=*/nullptr); |
| 3131 | if (IsFreeIvar && Result.isUsable()) |
| 3132 | cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); |
| 3133 | return Result; |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3134 | } |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3135 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3136 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3137 | /// |
| 3138 | /// By default, performs semantic analysis to build the new expression. |
| 3139 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3140 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 3141 | ObjCPropertyDecl *Property, |
| 3142 | SourceLocation PropertyLoc) { |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3143 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3144 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 3145 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3146 | /*FIXME:*/PropertyLoc, |
| 3147 | /*IsArrow=*/false, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3148 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3149 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3150 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3151 | /*TemplateArgs=*/nullptr, |
| 3152 | /*S=*/nullptr); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3153 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3154 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3155 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3156 | /// |
| 3157 | /// By default, performs semantic analysis to build the new expression. |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 3158 | /// Subclasses may override this routine to provide different behavior. |
| 3159 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 3160 | ObjCMethodDecl *Getter, |
| 3161 | ObjCMethodDecl *Setter, |
| 3162 | SourceLocation PropertyLoc) { |
| 3163 | // Since these expressions can only be value-dependent, we do not |
| 3164 | // need to perform semantic analysis again. |
| 3165 | return Owned( |
| 3166 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 3167 | VK_LValue, OK_ObjCProperty, |
| 3168 | PropertyLoc, Base)); |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3169 | } |
| 3170 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3171 | /// Build a new Objective-C "isa" expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3172 | /// |
| 3173 | /// By default, performs semantic analysis to build the new expression. |
| 3174 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3175 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3176 | SourceLocation OpLoc, bool IsArrow) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3177 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3178 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 3179 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 3180 | OpLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3181 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3182 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3183 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3184 | /*TemplateArgs=*/nullptr, |
| 3185 | /*S=*/nullptr); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3186 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3187 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3188 | /// Build a new shuffle vector expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3189 | /// |
| 3190 | /// By default, performs semantic analysis to build the new expression. |
| 3191 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3192 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 3193 | MultiExprArg SubExprs, |
| 3194 | SourceLocation RParenLoc) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3195 | // Find the declaration for __builtin_shufflevector |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3196 | const IdentifierInfo &Name |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3197 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 3198 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 3199 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3200 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3201 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3202 | // Build a reference to the __builtin_shufflevector builtin |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3203 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
| Bruno Ricci | 5fc4db7 | 2018-12-21 14:10:18 +0000 | [diff] [blame] | 3204 | Expr *Callee = new (SemaRef.Context) |
| 3205 | DeclRefExpr(SemaRef.Context, Builtin, false, |
| 3206 | SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc); |
| Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 3207 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 3208 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3209 | CK_BuiltinFnToFnPtr).get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3210 | |
| 3211 | // Build the CallExpr |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 3212 | ExprResult TheCall = CallExpr::Create( |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3213 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3214 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3215 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3216 | // Type-check the __builtin_shufflevector expression. |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3217 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3218 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3219 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3220 | /// Build a new convert vector expression. |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 3221 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 3222 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 3223 | SourceLocation RParenLoc) { |
| 3224 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 3225 | BuiltinLoc, RParenLoc); |
| 3226 | } |
| 3227 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3228 | /// Build a new template argument pack expansion. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3229 | /// |
| 3230 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3231 | /// for a template argument. Subclasses may override this routine to provide |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3232 | /// different behavior. |
| 3233 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3234 | SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3235 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3236 | switch (Pattern.getArgument().getKind()) { |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3237 | case TemplateArgument::Expression: { |
| 3238 | ExprResult Result |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3239 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 3240 | EllipsisLoc, NumExpansions); |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3241 | if (Result.isInvalid()) |
| 3242 | return TemplateArgumentLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3243 | |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3244 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 3245 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3246 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3247 | case TemplateArgument::Template: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3248 | return TemplateArgumentLoc(TemplateArgument( |
| 3249 | Pattern.getArgument().getAsTemplate(), |
| Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3250 | NumExpansions), |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3251 | Pattern.getTemplateQualifierLoc(), |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3252 | Pattern.getTemplateNameLoc(), |
| 3253 | EllipsisLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3255 | case TemplateArgument::Null: |
| 3256 | case TemplateArgument::Integral: |
| 3257 | case TemplateArgument::Declaration: |
| 3258 | case TemplateArgument::Pack: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3259 | case TemplateArgument::TemplateExpansion: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3260 | case TemplateArgument::NullPtr: |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3261 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3262 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3263 | case TemplateArgument::Type: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3264 | if (TypeSourceInfo *Expansion |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3265 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3266 | EllipsisLoc, |
| 3267 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3268 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 3269 | Expansion); |
| 3270 | break; |
| 3271 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3272 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3273 | return TemplateArgumentLoc(); |
| 3274 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3275 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3276 | /// Build a new expression pack expansion. |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3277 | /// |
| 3278 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3279 | /// for an expression. Subclasses may override this routine to provide |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3280 | /// different behavior. |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3281 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3282 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3283 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3284 | } |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3285 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3286 | /// Build a new C++1z fold-expression. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3287 | /// |
| 3288 | /// By default, performs semantic analysis in order to build a new fold |
| 3289 | /// expression. |
| 3290 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 3291 | BinaryOperatorKind Operator, |
| 3292 | SourceLocation EllipsisLoc, Expr *RHS, |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 3293 | SourceLocation RParenLoc, |
| 3294 | Optional<unsigned> NumExpansions) { |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3295 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 3296 | RHS, RParenLoc, NumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3299 | /// Build an empty C++1z fold-expression with the given operator. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3300 | /// |
| 3301 | /// By default, produces the fallback value for the fold-expression, or |
| 3302 | /// produce an error if there is no fallback value. |
| 3303 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 3304 | BinaryOperatorKind Operator) { |
| 3305 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 3306 | } |
| 3307 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3308 | /// Build a new atomic operation expression. |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3309 | /// |
| 3310 | /// By default, performs semantic analysis to build the new expression. |
| 3311 | /// Subclasses may override this routine to provide different behavior. |
| 3312 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 3313 | MultiExprArg SubExprs, |
| 3314 | QualType RetTy, |
| 3315 | AtomicExpr::AtomicOp Op, |
| 3316 | SourceLocation RParenLoc) { |
| 3317 | // Just create the expression; there is not any interesting semantic |
| 3318 | // analysis here because we can't actually build an AtomicExpr until |
| 3319 | // we are sure it is semantically sound. |
| Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 3320 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3321 | RParenLoc); |
| 3322 | } |
| 3323 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3324 | private: |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3325 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 3326 | QualType ObjectType, |
| 3327 | NamedDecl *FirstQualifierInScope, |
| 3328 | CXXScopeSpec &SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3329 | |
| 3330 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3331 | QualType ObjectType, |
| 3332 | NamedDecl *FirstQualifierInScope, |
| 3333 | CXXScopeSpec &SS); |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3334 | |
| 3335 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 3336 | NamedDecl *FirstQualifierInScope, |
| 3337 | CXXScopeSpec &SS); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 3338 | |
| 3339 | QualType TransformDependentNameType(TypeLocBuilder &TLB, |
| 3340 | DependentNameTypeLoc TL, |
| 3341 | bool DeducibleTSTContext); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3342 | }; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3343 | |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 3344 | template <typename Derived> |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3345 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3346 | if (!S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3347 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3348 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3349 | switch (S->getStmtClass()) { |
| 3350 | case Stmt::NoStmtClass: break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3351 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3352 | // Transform individual statement nodes |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3353 | // Pass SDK into statements that can produce a value |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3354 | #define STMT(Node, Parent) \ |
| 3355 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3356 | #define VALUESTMT(Node, Parent) \ |
| 3357 | case Stmt::Node##Class: \ |
| 3358 | return getDerived().Transform##Node(cast<Node>(S), SDK); |
| John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3359 | #define ABSTRACT_STMT(Node) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3360 | #define EXPR(Node, Parent) |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3361 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3362 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3363 | // Transform expressions by calling TransformExpr. |
| 3364 | #define STMT(Node, Parent) |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3365 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3366 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3367 | #include "clang/AST/StmtNodes.inc" |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3369 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3370 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3371 | if (SDK == SDK_StmtExprResult) |
| 3372 | E = getSema().ActOnStmtExprResult(E); |
| 3373 | return getSema().ActOnExprStmt(E, SDK == SDK_Discarded); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3374 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3377 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3378 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3379 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3380 | template<typename Derived> |
| 3381 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 3382 | if (!S) |
| 3383 | return S; |
| 3384 | |
| 3385 | switch (S->getClauseKind()) { |
| 3386 | default: break; |
| 3387 | // Transform individual clause nodes |
| 3388 | #define OPENMP_CLAUSE(Name, Class) \ |
| 3389 | case OMPC_ ## Name : \ |
| 3390 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 3391 | #include "clang/Basic/OpenMPKinds.def" |
| 3392 | } |
| 3393 | |
| 3394 | return S; |
| 3395 | } |
| 3396 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3397 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3398 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3399 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3400 | if (!E) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3401 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3402 | |
| 3403 | switch (E->getStmtClass()) { |
| 3404 | case Stmt::NoStmtClass: break; |
| 3405 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3406 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3407 | #define EXPR(Node, Parent) \ |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3408 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3409 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3412 | return E; |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | template<typename Derived> |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3416 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3417 | bool NotCopyInit) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3418 | // Initializers are instantiated like expressions, except that various outer |
| 3419 | // layers are stripped. |
| 3420 | if (!Init) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3421 | return Init; |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3422 | |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 3423 | if (auto *FE = dyn_cast<FullExpr>(Init)) |
| 3424 | Init = FE->getSubExpr(); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3425 | |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 3426 | if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) |
| 3427 | Init = AIL->getCommonExpr(); |
| 3428 | |
| Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 3429 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3430 | Init = MTE->GetTemporaryExpr(); |
| 3431 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3432 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3433 | Init = Binder->getSubExpr(); |
| 3434 | |
| 3435 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3436 | Init = ICE->getSubExprAsWritten(); |
| 3437 | |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3438 | if (CXXStdInitializerListExpr *ILE = |
| 3439 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3440 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3441 | |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3442 | // If this is copy-initialization, we only need to reconstruct |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3443 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3444 | // the initializer is already the right type. |
| 3445 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3446 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3447 | return getDerived().TransformExpr(Init); |
| 3448 | |
| 3449 | // Revert value-initialization back to empty parens. |
| 3450 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3451 | SourceRange Parens = VIE->getSourceRange(); |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3452 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3453 | Parens.getEnd()); |
| 3454 | } |
| 3455 | |
| 3456 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3457 | if (isa<ImplicitValueInitExpr>(Init)) |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3458 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3459 | SourceLocation()); |
| 3460 | |
| 3461 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3462 | // of expressions. Any other form of initializer can just be reused directly. |
| 3463 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3464 | return getDerived().TransformExpr(Init); |
| 3465 | |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3466 | // If the initialization implicitly converted an initializer list to a |
| 3467 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3468 | if (Construct && Construct->isStdInitListInitialization()) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3469 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3470 | |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 3471 | // Enter a list-init context if this was list initialization. |
| 3472 | EnterExpressionEvaluationContext Context( |
| 3473 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 3474 | Construct->isListInitialization()); |
| 3475 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3476 | SmallVector<Expr*, 8> NewArgs; |
| 3477 | bool ArgChanged = false; |
| 3478 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3479 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3480 | return ExprError(); |
| 3481 | |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 3482 | // If this was list initialization, revert to syntactic list form. |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3483 | if (Construct->isListInitialization()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3484 | return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3485 | Construct->getEndLoc()); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3486 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3487 | // Build a ParenListExpr to represent anything else. |
| Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3488 | SourceRange Parens = Construct->getParenOrBraceRange(); |
| Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3489 | if (Parens.isInvalid()) { |
| 3490 | // This was a variable declaration's initialization for which no initializer |
| 3491 | // was specified. |
| 3492 | assert(NewArgs.empty() && |
| 3493 | "no parens or braces but have direct init with arguments?"); |
| 3494 | return ExprEmpty(); |
| 3495 | } |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3496 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3497 | Parens.getEnd()); |
| 3498 | } |
| 3499 | |
| 3500 | template<typename Derived> |
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 3501 | bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3502 | unsigned NumInputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3503 | bool IsCall, |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3504 | SmallVectorImpl<Expr *> &Outputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3505 | bool *ArgChanged) { |
| 3506 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3507 | // If requested, drop call arguments that need to be dropped. |
| 3508 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3509 | if (ArgChanged) |
| 3510 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3511 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3512 | break; |
| 3513 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3514 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3515 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3516 | Expr *Pattern = Expansion->getPattern(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3517 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3518 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3519 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3520 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3521 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3522 | // Determine whether the set of unexpanded parameter packs can and should |
| 3523 | // be expanded. |
| 3524 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3525 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3526 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3527 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3528 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3529 | Pattern->getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3530 | Unexpanded, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3531 | Expand, RetainExpansion, |
| 3532 | NumExpansions)) |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3533 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3534 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3535 | if (!Expand) { |
| 3536 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3537 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3538 | // expansion. |
| 3539 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3540 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3541 | if (OutPattern.isInvalid()) |
| 3542 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3543 | |
| 3544 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3545 | Expansion->getEllipsisLoc(), |
| 3546 | NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3547 | if (Out.isInvalid()) |
| 3548 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3549 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3550 | if (ArgChanged) |
| 3551 | *ArgChanged = true; |
| 3552 | Outputs.push_back(Out.get()); |
| 3553 | continue; |
| 3554 | } |
| John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3555 | |
| 3556 | // Record right away that the argument was changed. This needs |
| 3557 | // to happen even if the array expands to nothing. |
| 3558 | if (ArgChanged) *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3559 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3560 | // The transform has determined that we should perform an elementwise |
| 3561 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3562 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3563 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3564 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3565 | if (Out.isInvalid()) |
| 3566 | return true; |
| 3567 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3568 | if (Out.get()->containsUnexpandedParameterPack()) { |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3569 | Out = getDerived().RebuildPackExpansion( |
| 3570 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3571 | if (Out.isInvalid()) |
| 3572 | return true; |
| 3573 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3574 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3575 | Outputs.push_back(Out.get()); |
| 3576 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3577 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3578 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3579 | // forgetting the partially-substituted parameter pack. |
| 3580 | if (RetainExpansion) { |
| 3581 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3582 | |
| 3583 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3584 | if (Out.isInvalid()) |
| 3585 | return true; |
| 3586 | |
| 3587 | Out = getDerived().RebuildPackExpansion( |
| 3588 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3589 | if (Out.isInvalid()) |
| 3590 | return true; |
| 3591 | |
| 3592 | Outputs.push_back(Out.get()); |
| 3593 | } |
| 3594 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3595 | continue; |
| 3596 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3597 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3598 | ExprResult Result = |
| 3599 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3600 | : getDerived().TransformExpr(Inputs[I]); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3601 | if (Result.isInvalid()) |
| 3602 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3603 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3604 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3605 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3606 | |
| 3607 | Outputs.push_back(Result.get()); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3608 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3609 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3610 | return false; |
| 3611 | } |
| 3612 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 3613 | template <typename Derived> |
| 3614 | Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 3615 | SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 3616 | if (Var) { |
| 3617 | VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 3618 | getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 3619 | |
| 3620 | if (!ConditionVar) |
| 3621 | return Sema::ConditionError(); |
| 3622 | |
| 3623 | return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 3624 | } |
| 3625 | |
| 3626 | if (Expr) { |
| 3627 | ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 3628 | |
| 3629 | if (CondExpr.isInvalid()) |
| 3630 | return Sema::ConditionError(); |
| 3631 | |
| 3632 | return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); |
| 3633 | } |
| 3634 | |
| 3635 | return Sema::ConditionResult(); |
| 3636 | } |
| 3637 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3638 | template<typename Derived> |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3639 | NestedNameSpecifierLoc |
| 3640 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3641 | NestedNameSpecifierLoc NNS, |
| 3642 | QualType ObjectType, |
| 3643 | NamedDecl *FirstQualifierInScope) { |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3644 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3645 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3646 | Qualifier = Qualifier.getPrefix()) |
| 3647 | Qualifiers.push_back(Qualifier); |
| 3648 | |
| 3649 | CXXScopeSpec SS; |
| 3650 | while (!Qualifiers.empty()) { |
| 3651 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3652 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3653 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3654 | switch (QNNS->getKind()) { |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3655 | case NestedNameSpecifier::Identifier: { |
| 3656 | Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), |
| 3657 | Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType); |
| 3658 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, |
| 3659 | SS, FirstQualifierInScope, false)) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3660 | return NestedNameSpecifierLoc(); |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3661 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3662 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3663 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3664 | case NestedNameSpecifier::Namespace: { |
| 3665 | NamespaceDecl *NS |
| 3666 | = cast_or_null<NamespaceDecl>( |
| 3667 | getDerived().TransformDecl( |
| 3668 | Q.getLocalBeginLoc(), |
| 3669 | QNNS->getAsNamespace())); |
| 3670 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3671 | break; |
| 3672 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3673 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3674 | case NestedNameSpecifier::NamespaceAlias: { |
| 3675 | NamespaceAliasDecl *Alias |
| 3676 | = cast_or_null<NamespaceAliasDecl>( |
| 3677 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3678 | QNNS->getAsNamespaceAlias())); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3679 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3680 | Q.getLocalEndLoc()); |
| 3681 | break; |
| 3682 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3683 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3684 | case NestedNameSpecifier::Global: |
| 3685 | // There is no meaningful transformation that one could perform on the |
| 3686 | // global scope. |
| 3687 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3688 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3689 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3690 | case NestedNameSpecifier::Super: { |
| 3691 | CXXRecordDecl *RD = |
| 3692 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3693 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3694 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3695 | break; |
| 3696 | } |
| 3697 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3698 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3699 | case NestedNameSpecifier::TypeSpec: { |
| 3700 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3701 | FirstQualifierInScope, SS); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3702 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3703 | if (!TL) |
| 3704 | return NestedNameSpecifierLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3705 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3706 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3707 | (SemaRef.getLangOpts().CPlusPlus11 && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3708 | TL.getType()->isEnumeralType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3709 | assert(!TL.getType().hasLocalQualifiers() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3710 | "Can't get cv-qualifiers here"); |
| Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3711 | if (TL.getType()->isEnumeralType()) |
| 3712 | SemaRef.Diag(TL.getBeginLoc(), |
| 3713 | diag::warn_cxx98_compat_enum_nested_name_spec); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3714 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3715 | Q.getLocalEndLoc()); |
| 3716 | break; |
| 3717 | } |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3718 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3719 | // error because a previous error should have already been emitted. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3720 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3721 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3722 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3723 | << TL.getType() << SS.getRange(); |
| 3724 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3725 | return NestedNameSpecifierLoc(); |
| 3726 | } |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3727 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3728 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3729 | // 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] | 3730 | FirstQualifierInScope = nullptr; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3731 | ObjectType = QualType(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3732 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3733 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3734 | // 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] | 3735 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3736 | !getDerived().AlwaysRebuild()) |
| 3737 | return NNS; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3738 | |
| 3739 | // If we can re-use the source-location data from the original |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3740 | // nested-name-specifier, do so. |
| 3741 | if (SS.location_size() == NNS.getDataLength() && |
| 3742 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3743 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3744 | |
| 3745 | // Allocate new nested-name-specifier location information. |
| 3746 | return SS.getWithLocInContext(SemaRef.Context); |
| 3747 | } |
| 3748 | |
| 3749 | template<typename Derived> |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3750 | DeclarationNameInfo |
| 3751 | TreeTransform<Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3752 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3753 | DeclarationName Name = NameInfo.getName(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3754 | if (!Name) |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3755 | return DeclarationNameInfo(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3756 | |
| 3757 | switch (Name.getNameKind()) { |
| 3758 | case DeclarationName::Identifier: |
| 3759 | case DeclarationName::ObjCZeroArgSelector: |
| 3760 | case DeclarationName::ObjCOneArgSelector: |
| 3761 | case DeclarationName::ObjCMultiArgSelector: |
| 3762 | case DeclarationName::CXXOperatorName: |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3763 | case DeclarationName::CXXLiteralOperatorName: |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3764 | case DeclarationName::CXXUsingDirective: |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3765 | return NameInfo; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3766 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3767 | case DeclarationName::CXXDeductionGuideName: { |
| 3768 | TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); |
| 3769 | TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( |
| 3770 | getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); |
| 3771 | if (!NewTemplate) |
| 3772 | return DeclarationNameInfo(); |
| 3773 | |
| 3774 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3775 | NewNameInfo.setName( |
| 3776 | SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); |
| 3777 | return NewNameInfo; |
| 3778 | } |
| 3779 | |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3780 | case DeclarationName::CXXConstructorName: |
| 3781 | case DeclarationName::CXXDestructorName: |
| 3782 | case DeclarationName::CXXConversionFunctionName: { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3783 | TypeSourceInfo *NewTInfo; |
| 3784 | CanQualType NewCanTy; |
| 3785 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3786 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3787 | if (!NewTInfo) |
| 3788 | return DeclarationNameInfo(); |
| 3789 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3790 | } |
| 3791 | else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3792 | NewTInfo = nullptr; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3793 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3794 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3795 | if (NewT.isNull()) |
| 3796 | return DeclarationNameInfo(); |
| 3797 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3798 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3799 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3800 | DeclarationName NewName |
| 3801 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3802 | NewCanTy); |
| 3803 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3804 | NewNameInfo.setName(NewName); |
| 3805 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3806 | return NewNameInfo; |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3807 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3810 | llvm_unreachable("Unknown name kind."); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3814 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3815 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3816 | TemplateName Name, |
| 3817 | SourceLocation NameLoc, |
| 3818 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3819 | NamedDecl *FirstQualifierInScope, |
| 3820 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3821 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3822 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3823 | assert(Template && "qualified template name must refer to a template"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3824 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3825 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3826 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3827 | Template)); |
| 3828 | if (!TransTemplate) |
| 3829 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3830 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3831 | if (!getDerived().AlwaysRebuild() && |
| 3832 | SS.getScopeRep() == QTN->getQualifier() && |
| 3833 | TransTemplate == Template) |
| 3834 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3835 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3836 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3837 | TransTemplate); |
| 3838 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3839 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3840 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3841 | if (SS.getScopeRep()) { |
| 3842 | // These apply to the scope specifier, not the template. |
| 3843 | ObjectType = QualType(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3844 | FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3845 | } |
| 3846 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3847 | if (!getDerived().AlwaysRebuild() && |
| 3848 | SS.getScopeRep() == DTN->getQualifier() && |
| 3849 | ObjectType.isNull()) |
| 3850 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3851 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3852 | // FIXME: Preserve the location of the "template" keyword. |
| 3853 | SourceLocation TemplateKWLoc = NameLoc; |
| 3854 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3855 | if (DTN->isIdentifier()) { |
| 3856 | return getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3857 | TemplateKWLoc, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3858 | *DTN->getIdentifier(), |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3859 | NameLoc, |
| 3860 | ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3861 | FirstQualifierInScope, |
| 3862 | AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3863 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3864 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3865 | return getDerived().RebuildTemplateName(SS, TemplateKWLoc, |
| 3866 | DTN->getOperator(), NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3867 | ObjectType, AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3868 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3869 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3870 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3871 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3872 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3873 | Template)); |
| 3874 | if (!TransTemplate) |
| 3875 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3876 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3877 | if (!getDerived().AlwaysRebuild() && |
| 3878 | TransTemplate == Template) |
| 3879 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3880 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3881 | return TemplateName(TransTemplate); |
| 3882 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3883 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3884 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3885 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3886 | TemplateTemplateParmDecl *TransParam |
| 3887 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3888 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3889 | if (!TransParam) |
| 3890 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3891 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3892 | if (!getDerived().AlwaysRebuild() && |
| 3893 | TransParam == SubstPack->getParameterPack()) |
| 3894 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3895 | |
| 3896 | return getDerived().RebuildTemplateName(TransParam, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3897 | SubstPack->getArgumentPack()); |
| 3898 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3899 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3900 | // These should be getting filtered out before they reach the AST. |
| 3901 | llvm_unreachable("overloaded function decl survived to here"); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3905 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3906 | const TemplateArgument &Arg, |
| 3907 | TemplateArgumentLoc &Output) { |
| 3908 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3909 | switch (Arg.getKind()) { |
| 3910 | case TemplateArgument::Null: |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3911 | llvm_unreachable("null template argument in TreeTransform"); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3912 | break; |
| 3913 | |
| 3914 | case TemplateArgument::Type: |
| 3915 | Output = TemplateArgumentLoc(Arg, |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3916 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3917 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3918 | break; |
| 3919 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3920 | case TemplateArgument::Template: |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3921 | case TemplateArgument::TemplateExpansion: { |
| 3922 | NestedNameSpecifierLocBuilder Builder; |
| Manuel Klimek | 4c67fa7 | 2016-01-11 11:39:00 +0000 | [diff] [blame] | 3923 | TemplateName Template = Arg.getAsTemplateOrTemplatePattern(); |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3924 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3925 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3926 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3927 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3928 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3929 | if (Arg.getKind() == TemplateArgument::Template) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3930 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3931 | Builder.getWithLocInContext(SemaRef.Context), |
| 3932 | Loc); |
| 3933 | else |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3934 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3935 | Builder.getWithLocInContext(SemaRef.Context), |
| 3936 | Loc, Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3937 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3938 | break; |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3939 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3940 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3941 | case TemplateArgument::Expression: |
| 3942 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3943 | break; |
| 3944 | |
| 3945 | case TemplateArgument::Declaration: |
| 3946 | case TemplateArgument::Integral: |
| 3947 | case TemplateArgument::Pack: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3948 | case TemplateArgument::NullPtr: |
| John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3949 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3950 | break; |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | template<typename Derived> |
| 3955 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3956 | const TemplateArgumentLoc &Input, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3957 | TemplateArgumentLoc &Output, bool Uneval) { |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3958 | const TemplateArgument &Arg = Input.getArgument(); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3959 | switch (Arg.getKind()) { |
| 3960 | case TemplateArgument::Null: |
| 3961 | case TemplateArgument::Integral: |
| Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3962 | case TemplateArgument::Pack: |
| 3963 | case TemplateArgument::Declaration: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3964 | case TemplateArgument::NullPtr: |
| 3965 | llvm_unreachable("Unexpected TemplateArgument"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3966 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3967 | case TemplateArgument::Type: { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3968 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3969 | if (!DI) |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3970 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3971 | |
| 3972 | DI = getDerived().TransformType(DI); |
| 3973 | if (!DI) return true; |
| 3974 | |
| 3975 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3976 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3977 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3979 | case TemplateArgument::Template: { |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3980 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3981 | if (QualifierLoc) { |
| 3982 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3983 | if (!QualifierLoc) |
| 3984 | return true; |
| 3985 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3986 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3987 | CXXScopeSpec SS; |
| 3988 | SS.Adopt(QualifierLoc); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3989 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3990 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3991 | Input.getTemplateNameLoc()); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3992 | if (Template.isNull()) |
| 3993 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3994 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3995 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3996 | Input.getTemplateNameLoc()); |
| 3997 | return false; |
| 3998 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3999 | |
| 4000 | case TemplateArgument::TemplateExpansion: |
| 4001 | llvm_unreachable("Caller should expand pack expansions"); |
| 4002 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4003 | case TemplateArgument::Expression: { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4004 | // Template argument expressions are constant expressions. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4005 | EnterExpressionEvaluationContext Unevaluated( |
| Richard Smith | dcd7eb7 | 2019-06-25 20:40:27 +0000 | [diff] [blame] | 4006 | getSema(), |
| 4007 | Uneval ? Sema::ExpressionEvaluationContext::Unevaluated |
| 4008 | : Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 4009 | /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ |
| 4010 | Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4011 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4012 | Expr *InputExpr = Input.getSourceExpression(); |
| 4013 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 4014 | |
| Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 4015 | ExprResult E = getDerived().TransformExpr(InputExpr); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4016 | E = SemaRef.ActOnConstantExpression(E); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4017 | if (E.isInvalid()) return true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4018 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4019 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4020 | } |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4021 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4022 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4023 | // Work around bogus GCC warning |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4024 | return true; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4025 | } |
| 4026 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4027 | /// Iterator adaptor that invents template argument location information |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4028 | /// for each of the template arguments in its underlying iterator. |
| 4029 | template<typename Derived, typename InputIterator> |
| 4030 | class TemplateArgumentLocInventIterator { |
| 4031 | TreeTransform<Derived> &Self; |
| 4032 | InputIterator Iter; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4033 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4034 | public: |
| 4035 | typedef TemplateArgumentLoc value_type; |
| 4036 | typedef TemplateArgumentLoc reference; |
| 4037 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 4038 | difference_type; |
| 4039 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4040 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4041 | class pointer { |
| 4042 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4043 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4044 | public: |
| 4045 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4046 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4047 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 4048 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4049 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4050 | TemplateArgumentLocInventIterator() { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4051 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4052 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 4053 | InputIterator Iter) |
| 4054 | : Self(Self), Iter(Iter) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4055 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4056 | TemplateArgumentLocInventIterator &operator++() { |
| 4057 | ++Iter; |
| 4058 | return *this; |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 4059 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4060 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4061 | TemplateArgumentLocInventIterator operator++(int) { |
| 4062 | TemplateArgumentLocInventIterator Old(*this); |
| 4063 | ++(*this); |
| 4064 | return Old; |
| 4065 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4066 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4067 | reference operator*() const { |
| 4068 | TemplateArgumentLoc Result; |
| 4069 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 4070 | return Result; |
| 4071 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4072 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4073 | pointer operator->() const { return pointer(**this); } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4074 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4075 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 4076 | const TemplateArgumentLocInventIterator &Y) { |
| 4077 | return X.Iter == Y.Iter; |
| 4078 | } |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 4079 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4080 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 4081 | const TemplateArgumentLocInventIterator &Y) { |
| 4082 | return X.Iter != Y.Iter; |
| 4083 | } |
| 4084 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4085 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4086 | template<typename Derived> |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4087 | template<typename InputIterator> |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4088 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 4089 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 4090 | bool Uneval) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4091 | for (; First != Last; ++First) { |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4092 | TemplateArgumentLoc Out; |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4093 | TemplateArgumentLoc In = *First; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4094 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4095 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 4096 | // Unpack argument packs, which we translate them into separate |
| 4097 | // arguments. |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4098 | // FIXME: We could do much better if we could guarantee that the |
| 4099 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 4100 | // all of the template arguments in the argument pack. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4101 | typedef TemplateArgumentLocInventIterator<Derived, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4102 | TemplateArgument::pack_iterator> |
| 4103 | PackLocIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4104 | if (TransformTemplateArguments(PackLocIterator(*this, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4105 | In.getArgument().pack_begin()), |
| 4106 | PackLocIterator(*this, |
| 4107 | In.getArgument().pack_end()), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4108 | Outputs, Uneval)) |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4109 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4110 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4111 | continue; |
| 4112 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4113 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4114 | if (In.getArgument().isPackExpansion()) { |
| 4115 | // We have a pack expansion, for which we will be substituting into |
| 4116 | // the pattern. |
| 4117 | SourceLocation Ellipsis; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4118 | Optional<unsigned> OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4119 | TemplateArgumentLoc Pattern |
| Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 4120 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 4121 | In, Ellipsis, OrigNumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4122 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4123 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4124 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4125 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4126 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4127 | // Determine whether the set of unexpanded parameter packs can and should |
| 4128 | // be expanded. |
| 4129 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4130 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4131 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4132 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 4133 | Pattern.getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4134 | Unexpanded, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4135 | Expand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4136 | RetainExpansion, |
| 4137 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4138 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4139 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4140 | if (!Expand) { |
| 4141 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4142 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4143 | // expansion. |
| 4144 | TemplateArgumentLoc OutPattern; |
| 4145 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4146 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4147 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4148 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4149 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 4150 | NumExpansions); |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4151 | if (Out.getArgument().isNull()) |
| 4152 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4153 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4154 | Outputs.addArgument(Out); |
| 4155 | continue; |
| 4156 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4157 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4158 | // The transform has determined that we should perform an elementwise |
| 4159 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4160 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4161 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4162 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4163 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4164 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4165 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4166 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4167 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4168 | OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4169 | if (Out.getArgument().isNull()) |
| 4170 | return true; |
| 4171 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4172 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4173 | Outputs.addArgument(Out); |
| 4174 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4175 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4176 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4177 | // forgetting the partially-substituted parameter pack. |
| 4178 | if (RetainExpansion) { |
| 4179 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4180 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4181 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4182 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4183 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4184 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4185 | OrigNumExpansions); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4186 | if (Out.getArgument().isNull()) |
| 4187 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4188 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4189 | Outputs.addArgument(Out); |
| 4190 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4191 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4192 | continue; |
| 4193 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4194 | |
| 4195 | // The simple case: |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4196 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4197 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4198 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4199 | Outputs.addArgument(Out); |
| 4200 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4201 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4202 | return false; |
| 4203 | |
| 4204 | } |
| 4205 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4206 | //===----------------------------------------------------------------------===// |
| 4207 | // Type transformation |
| 4208 | //===----------------------------------------------------------------------===// |
| 4209 | |
| 4210 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4211 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4212 | if (getDerived().AlreadyTransformed(T)) |
| 4213 | return T; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4214 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4215 | // Temporary workaround. All of these transformations should |
| 4216 | // eventually turn into transformations on TypeLocs. |
| Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 4217 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4218 | getDerived().getBaseLocation()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4219 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4220 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4221 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4222 | if (!NewDI) |
| 4223 | return QualType(); |
| 4224 | |
| 4225 | return NewDI->getType(); |
| 4226 | } |
| 4227 | |
| 4228 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4229 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4230 | // Refine the base location to the type's location. |
| 4231 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4232 | getDerived().getBaseEntity()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4233 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4234 | return DI; |
| 4235 | |
| 4236 | TypeLocBuilder TLB; |
| 4237 | |
| 4238 | TypeLoc TL = DI->getTypeLoc(); |
| 4239 | TLB.reserve(TL.getFullDataSize()); |
| 4240 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4241 | QualType Result = getDerived().TransformType(TLB, TL); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4242 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4243 | return nullptr; |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4244 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4245 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | template<typename Derived> |
| 4249 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4250 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4251 | switch (T.getTypeLocClass()) { |
| 4252 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4253 | #define TYPELOC(CLASS, PARENT) \ |
| 4254 | case TypeLoc::CLASS: \ |
| 4255 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 4256 | T.castAs<CLASS##TypeLoc>()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4257 | #include "clang/AST/TypeLocNodes.def" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4258 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4259 | |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4260 | llvm_unreachable("unhandled type loc!"); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4261 | } |
| 4262 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4263 | template<typename Derived> |
| 4264 | QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { |
| 4265 | if (!isa<DependentNameType>(T)) |
| 4266 | return TransformType(T); |
| 4267 | |
| 4268 | if (getDerived().AlreadyTransformed(T)) |
| 4269 | return T; |
| 4270 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4271 | getDerived().getBaseLocation()); |
| 4272 | TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); |
| 4273 | return NewDI ? NewDI->getType() : QualType(); |
| 4274 | } |
| 4275 | |
| 4276 | template<typename Derived> |
| 4277 | TypeSourceInfo * |
| 4278 | TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { |
| 4279 | if (!isa<DependentNameType>(DI->getType())) |
| 4280 | return TransformType(DI); |
| 4281 | |
| 4282 | // Refine the base location to the type's location. |
| 4283 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4284 | getDerived().getBaseEntity()); |
| 4285 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4286 | return DI; |
| 4287 | |
| 4288 | TypeLocBuilder TLB; |
| 4289 | |
| 4290 | TypeLoc TL = DI->getTypeLoc(); |
| 4291 | TLB.reserve(TL.getFullDataSize()); |
| 4292 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4293 | auto QTL = TL.getAs<QualifiedTypeLoc>(); |
| 4294 | if (QTL) |
| 4295 | TL = QTL.getUnqualifiedLoc(); |
| 4296 | |
| 4297 | auto DNTL = TL.castAs<DependentNameTypeLoc>(); |
| 4298 | |
| 4299 | QualType Result = getDerived().TransformDependentNameType( |
| 4300 | TLB, DNTL, /*DeducedTSTContext*/true); |
| 4301 | if (Result.isNull()) |
| 4302 | return nullptr; |
| 4303 | |
| 4304 | if (QTL) { |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4305 | Result = getDerived().RebuildQualifiedType(Result, QTL); |
| 4306 | if (Result.isNull()) |
| 4307 | return nullptr; |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4308 | TLB.TypeWasModifiedSafely(Result); |
| 4309 | } |
| 4310 | |
| 4311 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4312 | } |
| 4313 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4314 | template<typename Derived> |
| 4315 | QualType |
| 4316 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4317 | QualifiedTypeLoc T) { |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4318 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4319 | if (Result.isNull()) |
| 4320 | return QualType(); |
| 4321 | |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4322 | Result = getDerived().RebuildQualifiedType(Result, T); |
| 4323 | |
| 4324 | if (Result.isNull()) |
| 4325 | return QualType(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4326 | |
| 4327 | // RebuildQualifiedType might have updated the type, but not in a way |
| 4328 | // that invalidates the TypeLoc. (There's no location information for |
| 4329 | // qualifiers.) |
| 4330 | TLB.TypeWasModifiedSafely(Result); |
| 4331 | |
| 4332 | return Result; |
| 4333 | } |
| 4334 | |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4335 | template <typename Derived> |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4336 | QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4337 | QualifiedTypeLoc TL) { |
| 4338 | |
| 4339 | SourceLocation Loc = TL.getBeginLoc(); |
| 4340 | Qualifiers Quals = TL.getType().getLocalQualifiers(); |
| 4341 | |
| 4342 | if (((T.getAddressSpace() != LangAS::Default && |
| 4343 | Quals.getAddressSpace() != LangAS::Default)) && |
| 4344 | T.getAddressSpace() != Quals.getAddressSpace()) { |
| 4345 | SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) |
| 4346 | << TL.getType() << T; |
| 4347 | return QualType(); |
| 4348 | } |
| 4349 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4350 | // C++ [dcl.fct]p7: |
| 4351 | // [When] adding cv-qualifications on top of the function type [...] the |
| 4352 | // cv-qualifiers are ignored. |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 4353 | if (T->isFunctionType()) { |
| 4354 | T = SemaRef.getASTContext().getAddrSpaceQualType(T, |
| 4355 | Quals.getAddressSpace()); |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4356 | return T; |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 4357 | } |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4358 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4359 | // C++ [dcl.ref]p1: |
| 4360 | // when the cv-qualifiers are introduced through the use of a typedef-name |
| 4361 | // or decltype-specifier [...] the cv-qualifiers are ignored. |
| 4362 | // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be |
| 4363 | // applied to a reference type. |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4364 | if (T->isReferenceType()) { |
| 4365 | // The only qualifier that applies to a reference type is restrict. |
| 4366 | if (!Quals.hasRestrict()) |
| 4367 | return T; |
| 4368 | Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); |
| 4369 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4370 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4371 | // 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] | 4372 | // resulting type. |
| 4373 | if (Quals.hasObjCLifetime()) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4374 | if (!T->isObjCLifetimeType() && !T->isDependentType()) |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4375 | Quals.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4376 | else if (T.getObjCLifetime()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4377 | // Objective-C ARC: |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4378 | // A lifetime qualifier applied to a substituted template parameter |
| 4379 | // overrides the lifetime qualifier from the template argument. |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4380 | const AutoType *AutoTy; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4381 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4382 | = dyn_cast<SubstTemplateTypeParmType>(T)) { |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4383 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 4384 | Qualifiers Qs = Replacement.getQualifiers(); |
| 4385 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4386 | Replacement = SemaRef.Context.getQualifiedType( |
| 4387 | Replacement.getUnqualifiedType(), Qs); |
| 4388 | T = SemaRef.Context.getSubstTemplateTypeParmType( |
| 4389 | SubstTypeParam->getReplacedParameter(), Replacement); |
| 4390 | } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4391 | // 'auto' types behave the same way as template parameters. |
| 4392 | QualType Deduced = AutoTy->getDeducedType(); |
| 4393 | Qualifiers Qs = Deduced.getQualifiers(); |
| 4394 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4395 | Deduced = |
| 4396 | SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); |
| 4397 | T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
| 4398 | AutoTy->isDependentType()); |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4399 | } else { |
| Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4400 | // Otherwise, complain about the addition of a qualifier to an |
| 4401 | // already-qualified type. |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4402 | // FIXME: Why is this check not in Sema::BuildQualifiedType? |
| 4403 | SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4404 | Quals.removeObjCLifetime(); |
| 4405 | } |
| 4406 | } |
| 4407 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4408 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4409 | return SemaRef.BuildQualifiedType(T, Loc, Quals); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4412 | template<typename Derived> |
| 4413 | TypeLoc |
| 4414 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 4415 | QualType ObjectType, |
| 4416 | NamedDecl *UnqualLookup, |
| 4417 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4418 | if (getDerived().AlreadyTransformed(TL.getType())) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4419 | return TL; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4420 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4421 | TypeSourceInfo *TSI = |
| 4422 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 4423 | if (TSI) |
| 4424 | return TSI->getTypeLoc(); |
| 4425 | return TypeLoc(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4428 | template<typename Derived> |
| 4429 | TypeSourceInfo * |
| 4430 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4431 | QualType ObjectType, |
| 4432 | NamedDecl *UnqualLookup, |
| 4433 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4434 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4435 | return TSInfo; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4436 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4437 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 4438 | UnqualLookup, SS); |
| 4439 | } |
| 4440 | |
| 4441 | template <typename Derived> |
| 4442 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 4443 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 4444 | CXXScopeSpec &SS) { |
| 4445 | QualType T = TL.getType(); |
| 4446 | assert(!getDerived().AlreadyTransformed(T)); |
| 4447 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4448 | TypeLocBuilder TLB; |
| 4449 | QualType Result; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4450 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4451 | if (isa<TemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4452 | TemplateSpecializationTypeLoc SpecTL = |
| 4453 | TL.castAs<TemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4454 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4455 | TemplateName Template = getDerived().TransformTemplateName( |
| 4456 | SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), |
| 4457 | ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4458 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4459 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4460 | |
| 4461 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4462 | Template); |
| 4463 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4464 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 4465 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4466 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4467 | TemplateName Template |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4468 | = getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 4469 | SpecTL.getTemplateKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4470 | *SpecTL.getTypePtr()->getIdentifier(), |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4471 | SpecTL.getTemplateNameLoc(), |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4472 | ObjectType, UnqualLookup, |
| 4473 | /*AllowInjectedClassName*/true); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4474 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4475 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4476 | |
| 4477 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4478 | SpecTL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4479 | Template, |
| 4480 | SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4481 | } else { |
| 4482 | // Nothing special needs to be done for these. |
| 4483 | Result = getDerived().TransformType(TLB, TL); |
| 4484 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4485 | |
| 4486 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4487 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4488 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4489 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4490 | } |
| 4491 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4492 | template <class TyLoc> static inline |
| 4493 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 4494 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 4495 | NewT.setNameLoc(T.getNameLoc()); |
| 4496 | return T.getType(); |
| 4497 | } |
| 4498 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4499 | template<typename Derived> |
| 4500 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4501 | BuiltinTypeLoc T) { |
| Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4502 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 4503 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 4504 | if (T.needsExtraLocalData()) |
| 4505 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 4506 | return T.getType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4507 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4508 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4509 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4510 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4511 | ComplexTypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4512 | // FIXME: recurse? |
| 4513 | return TransformTypeSpecType(TLB, T); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4514 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4515 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4516 | template <typename Derived> |
| 4517 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 4518 | AdjustedTypeLoc TL) { |
| 4519 | // Adjustments applied during transformation are handled elsewhere. |
| 4520 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4521 | } |
| 4522 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4523 | template<typename Derived> |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4524 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4525 | DecayedTypeLoc TL) { |
| 4526 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4527 | if (OriginalType.isNull()) |
| 4528 | return QualType(); |
| 4529 | |
| 4530 | QualType Result = TL.getType(); |
| 4531 | if (getDerived().AlwaysRebuild() || |
| 4532 | OriginalType != TL.getOriginalLoc().getType()) |
| 4533 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4534 | TLB.push<DecayedTypeLoc>(Result); |
| 4535 | // Nothing to set for DecayedTypeLoc. |
| 4536 | return Result; |
| 4537 | } |
| 4538 | |
| Anastasia Stulova | d6f34bf | 2019-07-15 13:02:21 +0000 | [diff] [blame] | 4539 | /// Helper to deduce addr space of a pointee type in OpenCL mode. |
| 4540 | /// If the type is updated it will be overwritten in PointeeType param. |
| 4541 | static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) { |
| 4542 | if (PointeeType.getAddressSpace() == LangAS::Default) |
| 4543 | PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType, |
| 4544 | LangAS::opencl_generic); |
| 4545 | } |
| 4546 | |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4547 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4548 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4549 | PointerTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4550 | QualType PointeeType |
| 4551 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4552 | if (PointeeType.isNull()) |
| 4553 | return QualType(); |
| 4554 | |
| Anastasia Stulova | d6f34bf | 2019-07-15 13:02:21 +0000 | [diff] [blame] | 4555 | if (SemaRef.getLangOpts().OpenCL) |
| 4556 | deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType); |
| 4557 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4558 | QualType Result = TL.getType(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4559 | if (PointeeType->getAs<ObjCObjectType>()) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4560 | // A dependent pointer type 'T *' has is being transformed such |
| 4561 | // that an Objective-C class type is being replaced for 'T'. The |
| 4562 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4563 | // PointerType. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4564 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4565 | |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4566 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4567 | NewT.setStarLoc(TL.getStarLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4568 | return Result; |
| 4569 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4570 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4571 | if (getDerived().AlwaysRebuild() || |
| 4572 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4573 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4574 | if (Result.isNull()) |
| 4575 | return QualType(); |
| 4576 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4577 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4578 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4579 | // pointing to. |
| 4580 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4581 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4582 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4583 | NewT.setSigilLoc(TL.getSigilLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4584 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4585 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4586 | |
| 4587 | template<typename Derived> |
| 4588 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4589 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4590 | BlockPointerTypeLoc TL) { |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4591 | QualType PointeeType |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4592 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4593 | if (PointeeType.isNull()) |
| 4594 | return QualType(); |
| 4595 | |
| Anastasia Stulova | d6f34bf | 2019-07-15 13:02:21 +0000 | [diff] [blame] | 4596 | if (SemaRef.getLangOpts().OpenCL) |
| 4597 | deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType); |
| 4598 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4599 | QualType Result = TL.getType(); |
| 4600 | if (getDerived().AlwaysRebuild() || |
| 4601 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4602 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4603 | TL.getSigilLoc()); |
| 4604 | if (Result.isNull()) |
| 4605 | return QualType(); |
| 4606 | } |
| 4607 | |
| Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4608 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4609 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4610 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4613 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4614 | /// don't care whether the type itself is an l-value type or an r-value |
| 4615 | /// type; we only care if the type was *written* as an l-value type |
| 4616 | /// or an r-value type. |
| 4617 | template<typename Derived> |
| 4618 | QualType |
| 4619 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4620 | ReferenceTypeLoc TL) { |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4621 | const ReferenceType *T = TL.getTypePtr(); |
| 4622 | |
| 4623 | // Note that this works with the pointee-as-written. |
| 4624 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4625 | if (PointeeType.isNull()) |
| 4626 | return QualType(); |
| 4627 | |
| Anastasia Stulova | d6f34bf | 2019-07-15 13:02:21 +0000 | [diff] [blame] | 4628 | if (SemaRef.getLangOpts().OpenCL) |
| 4629 | deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType); |
| 4630 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4631 | QualType Result = TL.getType(); |
| 4632 | if (getDerived().AlwaysRebuild() || |
| 4633 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4634 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4635 | T->isSpelledAsLValue(), |
| 4636 | TL.getSigilLoc()); |
| 4637 | if (Result.isNull()) |
| 4638 | return QualType(); |
| 4639 | } |
| 4640 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4641 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4642 | // referring to. |
| 4643 | TLB.TypeWasModifiedSafely( |
| 4644 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4645 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4646 | // r-value references can be rebuilt as l-value references. |
| 4647 | ReferenceTypeLoc NewTL; |
| 4648 | if (isa<LValueReferenceType>(Result)) |
| 4649 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4650 | else |
| 4651 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4652 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4653 | |
| 4654 | return Result; |
| 4655 | } |
| 4656 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4657 | template<typename Derived> |
| 4658 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4659 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4660 | LValueReferenceTypeLoc TL) { |
| 4661 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4664 | template<typename Derived> |
| 4665 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4666 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4667 | RValueReferenceTypeLoc TL) { |
| 4668 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4669 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4670 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4671 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4673 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4674 | MemberPointerTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4675 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4676 | if (PointeeType.isNull()) |
| 4677 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4678 | |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4679 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4680 | TypeSourceInfo *NewClsTInfo = nullptr; |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4681 | if (OldClsTInfo) { |
| 4682 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4683 | if (!NewClsTInfo) |
| 4684 | return QualType(); |
| 4685 | } |
| 4686 | |
| 4687 | const MemberPointerType *T = TL.getTypePtr(); |
| 4688 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4689 | QualType NewClsType; |
| 4690 | if (NewClsTInfo) |
| 4691 | NewClsType = NewClsTInfo->getType(); |
| 4692 | else { |
| 4693 | NewClsType = getDerived().TransformType(OldClsType); |
| 4694 | if (NewClsType.isNull()) |
| 4695 | return QualType(); |
| 4696 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4697 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4698 | QualType Result = TL.getType(); |
| 4699 | if (getDerived().AlwaysRebuild() || |
| 4700 | PointeeType != T->getPointeeType() || |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4701 | NewClsType != OldClsType) { |
| 4702 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4703 | TL.getStarLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4704 | if (Result.isNull()) |
| 4705 | return QualType(); |
| 4706 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4707 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4708 | // If we had to adjust the pointee type when building a member pointer, make |
| 4709 | // sure to push TypeLoc info for it. |
| 4710 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4711 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4712 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4713 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4714 | } |
| 4715 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4716 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4717 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4718 | NewTL.setClassTInfo(NewClsTInfo); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4719 | |
| 4720 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4723 | template<typename Derived> |
| 4724 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4725 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4726 | ConstantArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4727 | const ConstantArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4728 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4729 | if (ElementType.isNull()) |
| 4730 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4731 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4732 | QualType Result = TL.getType(); |
| 4733 | if (getDerived().AlwaysRebuild() || |
| 4734 | ElementType != T->getElementType()) { |
| 4735 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4736 | T->getSizeModifier(), |
| 4737 | T->getSize(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4738 | T->getIndexTypeCVRQualifiers(), |
| 4739 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4740 | if (Result.isNull()) |
| 4741 | return QualType(); |
| 4742 | } |
| Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4743 | |
| 4744 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4745 | // a ConstantArrayType is allowed to have an element type which is a |
| 4746 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4747 | // types have the same location layout. |
| 4748 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4749 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4750 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4751 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4752 | Expr *Size = TL.getSizeExpr(); |
| 4753 | if (Size) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4754 | EnterExpressionEvaluationContext Unevaluated( |
| 4755 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4756 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4757 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4758 | } |
| 4759 | NewTL.setSizeExpr(Size); |
| 4760 | |
| 4761 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4762 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4763 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4764 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4765 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4766 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4767 | IncompleteArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4768 | const IncompleteArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4769 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4770 | if (ElementType.isNull()) |
| 4771 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4772 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4773 | QualType Result = TL.getType(); |
| 4774 | if (getDerived().AlwaysRebuild() || |
| 4775 | ElementType != T->getElementType()) { |
| 4776 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4777 | T->getSizeModifier(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4778 | T->getIndexTypeCVRQualifiers(), |
| 4779 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4780 | if (Result.isNull()) |
| 4781 | return QualType(); |
| 4782 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4783 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4784 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4785 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4786 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4787 | NewTL.setSizeExpr(nullptr); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4788 | |
| 4789 | return Result; |
| 4790 | } |
| 4791 | |
| 4792 | template<typename Derived> |
| 4793 | QualType |
| 4794 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4795 | VariableArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4796 | const VariableArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4797 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4798 | if (ElementType.isNull()) |
| 4799 | return QualType(); |
| 4800 | |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4801 | ExprResult SizeResult; |
| 4802 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4803 | EnterExpressionEvaluationContext Context( |
| 4804 | SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4805 | SizeResult = getDerived().TransformExpr(T->getSizeExpr()); |
| 4806 | } |
| 4807 | if (SizeResult.isInvalid()) |
| 4808 | return QualType(); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 4809 | SizeResult = |
| 4810 | SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4811 | if (SizeResult.isInvalid()) |
| 4812 | return QualType(); |
| 4813 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4814 | Expr *Size = SizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4815 | |
| 4816 | QualType Result = TL.getType(); |
| 4817 | if (getDerived().AlwaysRebuild() || |
| 4818 | ElementType != T->getElementType() || |
| 4819 | Size != T->getSizeExpr()) { |
| 4820 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4821 | T->getSizeModifier(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4822 | Size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4823 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4824 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4825 | if (Result.isNull()) |
| 4826 | return QualType(); |
| 4827 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4828 | |
| Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4829 | // We might have constant size array now, but fortunately it has the same |
| 4830 | // location layout. |
| 4831 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4832 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4833 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4834 | NewTL.setSizeExpr(Size); |
| 4835 | |
| 4836 | return Result; |
| 4837 | } |
| 4838 | |
| 4839 | template<typename Derived> |
| 4840 | QualType |
| 4841 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4842 | DependentSizedArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4843 | const DependentSizedArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4844 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4845 | if (ElementType.isNull()) |
| 4846 | return QualType(); |
| 4847 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4848 | // Array bounds are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4849 | EnterExpressionEvaluationContext Unevaluated( |
| 4850 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4851 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4852 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4853 | Expr *origSize = TL.getSizeExpr(); |
| 4854 | if (!origSize) origSize = T->getSizeExpr(); |
| 4855 | |
| 4856 | ExprResult sizeResult |
| 4857 | = getDerived().TransformExpr(origSize); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4858 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4859 | if (sizeResult.isInvalid()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4860 | return QualType(); |
| 4861 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4862 | Expr *size = sizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4863 | |
| 4864 | QualType Result = TL.getType(); |
| 4865 | if (getDerived().AlwaysRebuild() || |
| 4866 | ElementType != T->getElementType() || |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4867 | size != origSize) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4868 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4869 | T->getSizeModifier(), |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4870 | size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4871 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4872 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4873 | if (Result.isNull()) |
| 4874 | return QualType(); |
| 4875 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4876 | |
| 4877 | // We might have any sort of array type now, but fortunately they |
| 4878 | // all have the same location layout. |
| 4879 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4880 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4881 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4882 | NewTL.setSizeExpr(size); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4883 | |
| 4884 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4885 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4886 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 4887 | template <typename Derived> |
| 4888 | QualType TreeTransform<Derived>::TransformDependentVectorType( |
| 4889 | TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { |
| 4890 | const DependentVectorType *T = TL.getTypePtr(); |
| 4891 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4892 | if (ElementType.isNull()) |
| 4893 | return QualType(); |
| 4894 | |
| 4895 | EnterExpressionEvaluationContext Unevaluated( |
| 4896 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4897 | |
| 4898 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 4899 | Size = SemaRef.ActOnConstantExpression(Size); |
| 4900 | if (Size.isInvalid()) |
| 4901 | return QualType(); |
| 4902 | |
| 4903 | QualType Result = TL.getType(); |
| 4904 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 4905 | Size.get() != T->getSizeExpr()) { |
| 4906 | Result = getDerived().RebuildDependentVectorType( |
| 4907 | ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); |
| 4908 | if (Result.isNull()) |
| 4909 | return QualType(); |
| 4910 | } |
| 4911 | |
| 4912 | // Result might be dependent or not. |
| 4913 | if (isa<DependentVectorType>(Result)) { |
| 4914 | DependentVectorTypeLoc NewTL = |
| 4915 | TLB.push<DependentVectorTypeLoc>(Result); |
| 4916 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4917 | } else { |
| 4918 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4919 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4920 | } |
| 4921 | |
| 4922 | return Result; |
| 4923 | } |
| 4924 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4926 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4927 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4928 | DependentSizedExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4929 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4930 | |
| 4931 | // FIXME: ext vector locs should be nested |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4932 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4933 | if (ElementType.isNull()) |
| 4934 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4935 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4936 | // Vector sizes are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4937 | EnterExpressionEvaluationContext Unevaluated( |
| 4938 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4939 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4940 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4941 | Size = SemaRef.ActOnConstantExpression(Size); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4942 | if (Size.isInvalid()) |
| 4943 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4944 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4945 | QualType Result = TL.getType(); |
| 4946 | if (getDerived().AlwaysRebuild() || |
| John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4947 | ElementType != T->getElementType() || |
| 4948 | Size.get() != T->getSizeExpr()) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4949 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4950 | Size.get(), |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4951 | T->getAttributeLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4952 | if (Result.isNull()) |
| 4953 | return QualType(); |
| 4954 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4955 | |
| 4956 | // Result might be dependent or not. |
| 4957 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4958 | DependentSizedExtVectorTypeLoc NewTL |
| 4959 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4960 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4961 | } else { |
| 4962 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4963 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4964 | } |
| 4965 | |
| 4966 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4967 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4968 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 4969 | template <typename Derived> |
| 4970 | QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( |
| 4971 | TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { |
| 4972 | const DependentAddressSpaceType *T = TL.getTypePtr(); |
| 4973 | |
| 4974 | QualType pointeeType = getDerived().TransformType(T->getPointeeType()); |
| 4975 | |
| 4976 | if (pointeeType.isNull()) |
| 4977 | return QualType(); |
| 4978 | |
| 4979 | // Address spaces are constant expressions. |
| 4980 | EnterExpressionEvaluationContext Unevaluated( |
| 4981 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4982 | |
| 4983 | ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); |
| 4984 | AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); |
| 4985 | if (AddrSpace.isInvalid()) |
| 4986 | return QualType(); |
| 4987 | |
| 4988 | QualType Result = TL.getType(); |
| 4989 | if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || |
| 4990 | AddrSpace.get() != T->getAddrSpaceExpr()) { |
| 4991 | Result = getDerived().RebuildDependentAddressSpaceType( |
| 4992 | pointeeType, AddrSpace.get(), T->getAttributeLoc()); |
| 4993 | if (Result.isNull()) |
| 4994 | return QualType(); |
| 4995 | } |
| 4996 | |
| 4997 | // Result might be dependent or not. |
| 4998 | if (isa<DependentAddressSpaceType>(Result)) { |
| 4999 | DependentAddressSpaceTypeLoc NewTL = |
| 5000 | TLB.push<DependentAddressSpaceTypeLoc>(Result); |
| 5001 | |
| 5002 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5003 | NewTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5004 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5005 | |
| 5006 | } else { |
| 5007 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( |
| 5008 | Result, getDerived().getBaseLocation()); |
| 5009 | TransformType(TLB, DI->getTypeLoc()); |
| 5010 | } |
| 5011 | |
| 5012 | return Result; |
| 5013 | } |
| 5014 | |
| 5015 | template <typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5016 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5017 | VectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5018 | const VectorType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5019 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 5020 | if (ElementType.isNull()) |
| 5021 | return QualType(); |
| 5022 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5023 | QualType Result = TL.getType(); |
| 5024 | if (getDerived().AlwaysRebuild() || |
| 5025 | ElementType != T->getElementType()) { |
| John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5026 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 5027 | T->getVectorKind()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5028 | if (Result.isNull()) |
| 5029 | return QualType(); |
| 5030 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5031 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5032 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 5033 | NewTL.setNameLoc(TL.getNameLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5034 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5035 | return Result; |
| 5036 | } |
| 5037 | |
| 5038 | template<typename Derived> |
| 5039 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5040 | ExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5041 | const VectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5042 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 5043 | if (ElementType.isNull()) |
| 5044 | return QualType(); |
| 5045 | |
| 5046 | QualType Result = TL.getType(); |
| 5047 | if (getDerived().AlwaysRebuild() || |
| 5048 | ElementType != T->getElementType()) { |
| 5049 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 5050 | T->getNumElements(), |
| 5051 | /*FIXME*/ SourceLocation()); |
| 5052 | if (Result.isNull()) |
| 5053 | return QualType(); |
| 5054 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5055 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5056 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 5057 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5058 | |
| 5059 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5060 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5061 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5062 | template <typename Derived> |
| 5063 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 5064 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 5065 | bool ExpectParameterPack) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5066 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5067 | TypeSourceInfo *NewDI = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5068 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5069 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5070 | // 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] | 5071 | // length we want to expand to, just substitute for the pattern. |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5072 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 5073 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5074 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5075 | TypeLocBuilder TLB; |
| 5076 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 5077 | TLB.reserve(NewTL.getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5078 | |
| 5079 | QualType Result = getDerived().TransformType(TLB, |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5080 | OldExpansionTL.getPatternLoc()); |
| 5081 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5082 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5083 | |
| 5084 | Result = RebuildPackExpansionType(Result, |
| 5085 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5086 | OldExpansionTL.getEllipsisLoc(), |
| 5087 | NumExpansions); |
| 5088 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5089 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5090 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5091 | PackExpansionTypeLoc NewExpansionTL |
| 5092 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 5093 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 5094 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 5095 | } else |
| 5096 | NewDI = getDerived().TransformType(OldDI); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5097 | if (!NewDI) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5098 | return nullptr; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5099 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5100 | if (NewDI == OldDI && indexAdjustment == 0) |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5101 | return OldParm; |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5102 | |
| 5103 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 5104 | OldParm->getDeclContext(), |
| 5105 | OldParm->getInnerLocStart(), |
| 5106 | OldParm->getLocation(), |
| 5107 | OldParm->getIdentifier(), |
| 5108 | NewDI->getType(), |
| 5109 | NewDI, |
| 5110 | OldParm->getStorageClass(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5111 | /* DefArg */ nullptr); |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5112 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 5113 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 5114 | return newParm; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5117 | template <typename Derived> |
| 5118 | bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 5119 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 5120 | const QualType *ParamTypes, |
| 5121 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 5122 | SmallVectorImpl<QualType> &OutParamTypes, |
| 5123 | SmallVectorImpl<ParmVarDecl *> *PVars, |
| 5124 | Sema::ExtParameterInfoBuilder &PInfos) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5125 | int indexAdjustment = 0; |
| 5126 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5127 | unsigned NumParams = Params.size(); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5128 | for (unsigned i = 0; i != NumParams; ++i) { |
| 5129 | if (ParmVarDecl *OldParm = Params[i]) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5130 | assert(OldParm->getFunctionScopeIndex() == i); |
| 5131 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5132 | Optional<unsigned> NumExpansions; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5133 | ParmVarDecl *NewParm = nullptr; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5134 | if (OldParm->isParameterPack()) { |
| 5135 | // We have a function parameter pack that may need to be expanded. |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5136 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5137 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5138 | // Find the parameter packs that could be expanded. |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5139 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 5140 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5141 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 5142 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5143 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 5144 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5145 | // Determine whether we should expand the parameter packs. |
| 5146 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5147 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5148 | Optional<unsigned> OrigNumExpansions = |
| 5149 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5150 | NumExpansions = OrigNumExpansions; |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5151 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 5152 | Pattern.getSourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5153 | Unexpanded, |
| 5154 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5155 | RetainExpansion, |
| 5156 | NumExpansions)) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5157 | return true; |
| 5158 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5159 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5160 | if (ShouldExpand) { |
| 5161 | // Expand the function parameter pack into multiple, separate |
| 5162 | // parameters. |
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 5163 | getDerived().ExpandingFunctionParameterPack(OldParm); |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5164 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5165 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5166 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5167 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5168 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5169 | OrigNumExpansions, |
| 5170 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5171 | if (!NewParm) |
| 5172 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5173 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5174 | if (ParamInfos) |
| 5175 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5176 | OutParamTypes.push_back(NewParm->getType()); |
| 5177 | if (PVars) |
| 5178 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5179 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5180 | |
| 5181 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5182 | // forgetting the partially-substituted parameter pack. |
| 5183 | if (RetainExpansion) { |
| 5184 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5185 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5186 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5187 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5188 | OrigNumExpansions, |
| 5189 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5190 | if (!NewParm) |
| 5191 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5192 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5193 | if (ParamInfos) |
| 5194 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5195 | OutParamTypes.push_back(NewParm->getType()); |
| 5196 | if (PVars) |
| 5197 | PVars->push_back(NewParm); |
| 5198 | } |
| 5199 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5200 | // The next parameter should have the same adjustment as the |
| 5201 | // last thing we pushed, but we post-incremented indexAdjustment |
| 5202 | // on every push. Also, if we push nothing, the adjustment should |
| 5203 | // go down by one. |
| 5204 | indexAdjustment--; |
| 5205 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5206 | // We're done with the pack expansion. |
| 5207 | continue; |
| 5208 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5209 | |
| 5210 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5211 | // expansion. |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5212 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5213 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5214 | indexAdjustment, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5215 | NumExpansions, |
| 5216 | /*ExpectParameterPack=*/true); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5217 | } else { |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5218 | NewParm = getDerived().TransformFunctionTypeParam( |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 5219 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5220 | } |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5221 | |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5222 | if (!NewParm) |
| 5223 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5224 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5225 | if (ParamInfos) |
| 5226 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5227 | OutParamTypes.push_back(NewParm->getType()); |
| 5228 | if (PVars) |
| 5229 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5230 | continue; |
| 5231 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5232 | |
| 5233 | // Deal with the possibility that we don't have a parameter |
| 5234 | // declaration for this parameter. |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5235 | QualType OldType = ParamTypes[i]; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5236 | bool IsPackExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5237 | Optional<unsigned> NumExpansions; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5238 | QualType NewType; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5239 | if (const PackExpansionType *Expansion |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5240 | = dyn_cast<PackExpansionType>(OldType)) { |
| 5241 | // We have a function parameter pack that may need to be expanded. |
| 5242 | QualType Pattern = Expansion->getPattern(); |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5243 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5244 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5245 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5246 | // Determine whether we should expand the parameter packs. |
| 5247 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5248 | bool RetainExpansion = false; |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5249 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5250 | Unexpanded, |
| 5251 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5252 | RetainExpansion, |
| 5253 | NumExpansions)) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5254 | return true; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5255 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5256 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5257 | if (ShouldExpand) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5258 | // Expand the function parameter pack into multiple, separate |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5259 | // parameters. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5260 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5261 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 5262 | QualType NewType = getDerived().TransformType(Pattern); |
| 5263 | if (NewType.isNull()) |
| 5264 | return true; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5265 | |
| Erik Pilkington | f1bd000 | 2016-07-05 17:57:24 +0000 | [diff] [blame] | 5266 | if (NewType->containsUnexpandedParameterPack()) { |
| 5267 | NewType = |
| 5268 | getSema().getASTContext().getPackExpansionType(NewType, None); |
| 5269 | |
| 5270 | if (NewType.isNull()) |
| 5271 | return true; |
| 5272 | } |
| 5273 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5274 | if (ParamInfos) |
| 5275 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5276 | OutParamTypes.push_back(NewType); |
| 5277 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5278 | PVars->push_back(nullptr); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5279 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5280 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5281 | // We're done with the pack expansion. |
| 5282 | continue; |
| 5283 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5284 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5285 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5286 | // forgetting the partially-substituted parameter pack. |
| 5287 | if (RetainExpansion) { |
| 5288 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5289 | QualType NewType = getDerived().TransformType(Pattern); |
| 5290 | if (NewType.isNull()) |
| 5291 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5292 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5293 | if (ParamInfos) |
| 5294 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5295 | OutParamTypes.push_back(NewType); |
| 5296 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5297 | PVars->push_back(nullptr); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5298 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5299 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5300 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5301 | // expansion. |
| 5302 | OldType = Expansion->getPattern(); |
| 5303 | IsPackExpansion = true; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5304 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5305 | NewType = getDerived().TransformType(OldType); |
| 5306 | } else { |
| 5307 | NewType = getDerived().TransformType(OldType); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5308 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5309 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5310 | if (NewType.isNull()) |
| 5311 | return true; |
| 5312 | |
| 5313 | if (IsPackExpansion) |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5314 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 5315 | NumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5316 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5317 | if (ParamInfos) |
| 5318 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5319 | OutParamTypes.push_back(NewType); |
| 5320 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5321 | PVars->push_back(nullptr); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5324 | #ifndef NDEBUG |
| 5325 | if (PVars) { |
| 5326 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 5327 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 5328 | assert(parm->getFunctionScopeIndex() == i); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5329 | } |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5330 | #endif |
| 5331 | |
| 5332 | return false; |
| 5333 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5334 | |
| 5335 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5336 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5337 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5338 | FunctionProtoTypeLoc TL) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5339 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5340 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5341 | return getDerived().TransformFunctionProtoType( |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 5342 | TLB, TL, nullptr, Qualifiers(), |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5343 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 5344 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 5345 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5346 | }); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5347 | } |
| 5348 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5349 | template<typename Derived> template<typename Fn> |
| 5350 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 5351 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 5352 | Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5353 | |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5354 | // Transform the parameters and return type. |
| 5355 | // |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5356 | // 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] | 5357 | // When the function has a trailing return type, we instantiate the |
| 5358 | // parameters before the return type, since the return type can then refer |
| 5359 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 5360 | // |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5361 | SmallVector<QualType, 4> ParamTypes; |
| 5362 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5363 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5364 | const FunctionProtoType *T = TL.getTypePtr(); |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5365 | |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5366 | QualType ResultType; |
| 5367 | |
| Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 5368 | if (T->hasTrailingReturn()) { |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5369 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5370 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5371 | TL.getTypePtr()->param_type_begin(), |
| 5372 | T->getExtParameterInfosOrNull(), |
| 5373 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5374 | return QualType(); |
| 5375 | |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5376 | { |
| 5377 | // C++11 [expr.prim.general]p3: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5378 | // If a declaration declares a member function or member function |
| 5379 | // 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] | 5380 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5381 | // and the end of the function-definition, member-declarator, or |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5382 | // declarator. |
| 5383 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5384 | |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5385 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5386 | if (ResultType.isNull()) |
| 5387 | return QualType(); |
| 5388 | } |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5389 | } |
| 5390 | else { |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5391 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5392 | if (ResultType.isNull()) |
| 5393 | return QualType(); |
| 5394 | |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5395 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5396 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5397 | TL.getTypePtr()->param_type_begin(), |
| 5398 | T->getExtParameterInfosOrNull(), |
| 5399 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5400 | return QualType(); |
| 5401 | } |
| 5402 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5403 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 5404 | |
| 5405 | bool EPIChanged = false; |
| 5406 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 5407 | return QualType(); |
| 5408 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5409 | // Handle extended parameter information. |
| 5410 | if (auto NewExtParamInfos = |
| 5411 | ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 5412 | if (!EPI.ExtParameterInfos || |
| 5413 | llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) |
| 5414 | != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 5415 | EPIChanged = true; |
| 5416 | } |
| 5417 | EPI.ExtParameterInfos = NewExtParamInfos; |
| 5418 | } else if (EPI.ExtParameterInfos) { |
| 5419 | EPIChanged = true; |
| 5420 | EPI.ExtParameterInfos = nullptr; |
| 5421 | } |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5422 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5423 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5424 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
| Benjamin Kramer | e1c08b0 | 2015-08-18 08:10:39 +0000 | [diff] [blame] | 5425 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5426 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5427 | if (Result.isNull()) |
| 5428 | return QualType(); |
| 5429 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5430 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5431 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5432 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5433 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5434 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 5435 | NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5436 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 5437 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 5438 | NewTL.setParam(i, ParamDecls[i]); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5439 | |
| 5440 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5441 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5442 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5443 | template<typename Derived> |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5444 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 5445 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 5446 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 5447 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 5448 | |
| 5449 | // Instantiate a dynamic noexcept expression, if any. |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5450 | if (isComputedNoexcept(ESI.Type)) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5451 | EnterExpressionEvaluationContext Unevaluated( |
| 5452 | getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5453 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 5454 | if (NoexceptExpr.isInvalid()) |
| 5455 | return true; |
| 5456 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5457 | ExceptionSpecificationType EST = ESI.Type; |
| 5458 | NoexceptExpr = |
| 5459 | getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5460 | if (NoexceptExpr.isInvalid()) |
| 5461 | return true; |
| 5462 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5463 | if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5464 | Changed = true; |
| 5465 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5466 | ESI.Type = EST; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | if (ESI.Type != EST_Dynamic) |
| 5470 | return false; |
| 5471 | |
| 5472 | // Instantiate a dynamic exception specification's type. |
| 5473 | for (QualType T : ESI.Exceptions) { |
| 5474 | if (const PackExpansionType *PackExpansion = |
| 5475 | T->getAs<PackExpansionType>()) { |
| 5476 | Changed = true; |
| 5477 | |
| 5478 | // We have a pack expansion. Instantiate it. |
| 5479 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5480 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5481 | Unexpanded); |
| 5482 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5483 | |
| 5484 | // Determine whether the set of unexpanded parameter packs can and |
| 5485 | // should |
| 5486 | // be expanded. |
| 5487 | bool Expand = false; |
| 5488 | bool RetainExpansion = false; |
| 5489 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5490 | // FIXME: Track the location of the ellipsis (and track source location |
| 5491 | // information for the types in the exception specification in general). |
| 5492 | if (getDerived().TryExpandParameterPacks( |
| 5493 | Loc, SourceRange(), Unexpanded, Expand, |
| 5494 | RetainExpansion, NumExpansions)) |
| 5495 | return true; |
| 5496 | |
| 5497 | if (!Expand) { |
| 5498 | // We can't expand this pack expansion into separate arguments yet; |
| 5499 | // just substitute into the pattern and create a new pack expansion |
| 5500 | // type. |
| 5501 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5502 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5503 | if (U.isNull()) |
| 5504 | return true; |
| 5505 | |
| 5506 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 5507 | Exceptions.push_back(U); |
| 5508 | continue; |
| 5509 | } |
| 5510 | |
| 5511 | // Substitute into the pack expansion pattern for each slice of the |
| 5512 | // pack. |
| 5513 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5514 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5515 | |
| 5516 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5517 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5518 | return true; |
| 5519 | |
| 5520 | Exceptions.push_back(U); |
| 5521 | } |
| 5522 | } else { |
| 5523 | QualType U = getDerived().TransformType(T); |
| 5524 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5525 | return true; |
| 5526 | if (T != U) |
| 5527 | Changed = true; |
| 5528 | |
| 5529 | Exceptions.push_back(U); |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | ESI.Exceptions = Exceptions; |
| Richard Smith | fda59e5 | 2016-10-26 01:05:54 +0000 | [diff] [blame] | 5534 | if (ESI.Exceptions.empty()) |
| 5535 | ESI.Type = EST_DynamicNone; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5536 | return false; |
| 5537 | } |
| 5538 | |
| 5539 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5540 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5541 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5542 | FunctionNoProtoTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5543 | const FunctionNoProtoType *T = TL.getTypePtr(); |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5544 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5545 | if (ResultType.isNull()) |
| 5546 | return QualType(); |
| 5547 | |
| 5548 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5549 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5550 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 5551 | |
| 5552 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5553 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5554 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5555 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5556 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5557 | |
| 5558 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5559 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5560 | |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5561 | template<typename Derived> QualType |
| 5562 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5563 | UnresolvedUsingTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5564 | const UnresolvedUsingType *T = TL.getTypePtr(); |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5565 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5566 | if (!D) |
| 5567 | return QualType(); |
| 5568 | |
| 5569 | QualType Result = TL.getType(); |
| 5570 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 5571 | Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5572 | if (Result.isNull()) |
| 5573 | return QualType(); |
| 5574 | } |
| 5575 | |
| 5576 | // We might get an arbitrary type spec type back. We should at |
| 5577 | // least always get a type spec type, though. |
| 5578 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 5579 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5580 | |
| 5581 | return Result; |
| 5582 | } |
| 5583 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5584 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5585 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5586 | TypedefTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5587 | const TypedefType *T = TL.getTypePtr(); |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5588 | TypedefNameDecl *Typedef |
| 5589 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5590 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5591 | if (!Typedef) |
| 5592 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5593 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5594 | QualType Result = TL.getType(); |
| 5595 | if (getDerived().AlwaysRebuild() || |
| 5596 | Typedef != T->getDecl()) { |
| 5597 | Result = getDerived().RebuildTypedefType(Typedef); |
| 5598 | if (Result.isNull()) |
| 5599 | return QualType(); |
| 5600 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5601 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5602 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 5603 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5604 | |
| 5605 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5606 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5607 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5608 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5609 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5610 | TypeOfExprTypeLoc TL) { |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5611 | // typeof expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5612 | EnterExpressionEvaluationContext Unevaluated( |
| 5613 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 5614 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5616 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5617 | if (E.isInvalid()) |
| 5618 | return QualType(); |
| 5619 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 5620 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 5621 | if (E.isInvalid()) |
| 5622 | return QualType(); |
| 5623 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5624 | QualType Result = TL.getType(); |
| 5625 | if (getDerived().AlwaysRebuild() || |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5626 | E.get() != TL.getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5627 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5628 | if (Result.isNull()) |
| 5629 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5630 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5631 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5632 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5633 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5634 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5635 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5636 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5637 | |
| 5638 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5639 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5640 | |
| 5641 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5642 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5643 | TypeOfTypeLoc TL) { |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5644 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 5645 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 5646 | if (!New_Under_TI) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5647 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5648 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5649 | QualType Result = TL.getType(); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5650 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 5651 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5652 | if (Result.isNull()) |
| 5653 | return QualType(); |
| 5654 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5655 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5656 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5657 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5658 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5659 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5660 | NewTL.setUnderlyingTInfo(New_Under_TI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5661 | |
| 5662 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5663 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
| 5665 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5666 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5667 | DecltypeTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5668 | const DecltypeType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5669 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5670 | // decltype expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5671 | EnterExpressionEvaluationContext Unevaluated( |
| 5672 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| Nicolas Lesser | b6d5c58 | 2018-07-12 18:45:41 +0000 | [diff] [blame] | 5673 | Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5674 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5675 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5676 | if (E.isInvalid()) |
| 5677 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5678 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5679 | E = getSema().ActOnDecltypeExpression(E.get()); |
| Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 5680 | if (E.isInvalid()) |
| 5681 | return QualType(); |
| 5682 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5683 | QualType Result = TL.getType(); |
| 5684 | if (getDerived().AlwaysRebuild() || |
| 5685 | E.get() != T->getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5686 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5687 | if (Result.isNull()) |
| 5688 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5689 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5690 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5691 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5692 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 5693 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5694 | |
| 5695 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5699 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5700 | TypeLocBuilder &TLB, |
| 5701 | UnaryTransformTypeLoc TL) { |
| 5702 | QualType Result = TL.getType(); |
| 5703 | if (Result->isDependentType()) { |
| 5704 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5705 | QualType NewBase = |
| 5706 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5707 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5708 | T->getUTTKind(), |
| 5709 | TL.getKWLoc()); |
| 5710 | if (Result.isNull()) |
| 5711 | return QualType(); |
| 5712 | } |
| 5713 | |
| 5714 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5715 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5716 | NewTL.setParensRange(TL.getParensRange()); |
| 5717 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5718 | return Result; |
| 5719 | } |
| 5720 | |
| 5721 | template<typename Derived> |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5722 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5723 | AutoTypeLoc TL) { |
| 5724 | const AutoType *T = TL.getTypePtr(); |
| 5725 | QualType OldDeduced = T->getDeducedType(); |
| 5726 | QualType NewDeduced; |
| 5727 | if (!OldDeduced.isNull()) { |
| 5728 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5729 | if (NewDeduced.isNull()) |
| 5730 | return QualType(); |
| 5731 | } |
| 5732 | |
| 5733 | QualType Result = TL.getType(); |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5734 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5735 | T->isDependentType()) { |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5736 | Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword()); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5737 | if (Result.isNull()) |
| 5738 | return QualType(); |
| 5739 | } |
| 5740 | |
| 5741 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5742 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5743 | |
| 5744 | return Result; |
| 5745 | } |
| 5746 | |
| 5747 | template<typename Derived> |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 5748 | QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( |
| 5749 | TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { |
| 5750 | const DeducedTemplateSpecializationType *T = TL.getTypePtr(); |
| 5751 | |
| 5752 | CXXScopeSpec SS; |
| 5753 | TemplateName TemplateName = getDerived().TransformTemplateName( |
| 5754 | SS, T->getTemplateName(), TL.getTemplateNameLoc()); |
| 5755 | if (TemplateName.isNull()) |
| 5756 | return QualType(); |
| 5757 | |
| 5758 | QualType OldDeduced = T->getDeducedType(); |
| 5759 | QualType NewDeduced; |
| 5760 | if (!OldDeduced.isNull()) { |
| 5761 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5762 | if (NewDeduced.isNull()) |
| 5763 | return QualType(); |
| 5764 | } |
| 5765 | |
| 5766 | QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( |
| 5767 | TemplateName, NewDeduced); |
| 5768 | if (Result.isNull()) |
| 5769 | return QualType(); |
| 5770 | |
| 5771 | DeducedTemplateSpecializationTypeLoc NewTL = |
| 5772 | TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 5773 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5774 | |
| 5775 | return Result; |
| 5776 | } |
| 5777 | |
| 5778 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5779 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5780 | RecordTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5781 | const RecordType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5782 | RecordDecl *Record |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5783 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5784 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5785 | if (!Record) |
| 5786 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5787 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5788 | QualType Result = TL.getType(); |
| 5789 | if (getDerived().AlwaysRebuild() || |
| 5790 | Record != T->getDecl()) { |
| 5791 | Result = getDerived().RebuildRecordType(Record); |
| 5792 | if (Result.isNull()) |
| 5793 | return QualType(); |
| 5794 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5795 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5796 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5797 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5798 | |
| 5799 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5800 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5801 | |
| 5802 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5803 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5804 | EnumTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5805 | const EnumType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5806 | EnumDecl *Enum |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5807 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5808 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5809 | if (!Enum) |
| 5810 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5811 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5812 | QualType Result = TL.getType(); |
| 5813 | if (getDerived().AlwaysRebuild() || |
| 5814 | Enum != T->getDecl()) { |
| 5815 | Result = getDerived().RebuildEnumType(Enum); |
| 5816 | if (Result.isNull()) |
| 5817 | return QualType(); |
| 5818 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5819 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5820 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5821 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5822 | |
| 5823 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5824 | } |
| John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5825 | |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5826 | template<typename Derived> |
| 5827 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5828 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5829 | InjectedClassNameTypeLoc TL) { |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5830 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5831 | TL.getTypePtr()->getDecl()); |
| 5832 | if (!D) return QualType(); |
| 5833 | |
| 5834 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5835 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5836 | return T; |
| 5837 | } |
| 5838 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5839 | template<typename Derived> |
| 5840 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5841 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5842 | TemplateTypeParmTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5843 | return TransformTypeSpecType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5844 | } |
| 5845 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5846 | template<typename Derived> |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5847 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5848 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5849 | SubstTemplateTypeParmTypeLoc TL) { |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5850 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5851 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5852 | // Substitute into the replacement type, which itself might involve something |
| 5853 | // that needs to be transformed. This only tends to occur with default |
| 5854 | // template arguments of template template parameters. |
| 5855 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5856 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5857 | if (Replacement.isNull()) |
| 5858 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5859 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5860 | // Always canonicalize the replacement type. |
| 5861 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5862 | QualType Result |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5863 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5864 | Replacement); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5865 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5866 | // Propagate type-source information. |
| 5867 | SubstTemplateTypeParmTypeLoc NewTL |
| 5868 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5869 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5870 | return Result; |
| 5871 | |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | template<typename Derived> |
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5875 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5876 | TypeLocBuilder &TLB, |
| 5877 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5878 | return TransformTypeSpecType(TLB, TL); |
| 5879 | } |
| 5880 | |
| 5881 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5882 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5883 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5884 | TemplateSpecializationTypeLoc TL) { |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5885 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5886 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5887 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5888 | // because we can't have a dependent nested-name-specifier anyway. |
| 5889 | CXXScopeSpec SS; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5890 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5891 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5892 | TL.getTemplateNameLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5893 | if (Template.isNull()) |
| 5894 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5895 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5896 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5897 | } |
| 5898 | |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5899 | template<typename Derived> |
| 5900 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5901 | AtomicTypeLoc TL) { |
| 5902 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5903 | if (ValueType.isNull()) |
| 5904 | return QualType(); |
| 5905 | |
| 5906 | QualType Result = TL.getType(); |
| 5907 | if (getDerived().AlwaysRebuild() || |
| 5908 | ValueType != TL.getValueLoc().getType()) { |
| 5909 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5910 | if (Result.isNull()) |
| 5911 | return QualType(); |
| 5912 | } |
| 5913 | |
| 5914 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5915 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5916 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5917 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5918 | |
| 5919 | return Result; |
| 5920 | } |
| 5921 | |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5922 | template <typename Derived> |
| 5923 | QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 5924 | PipeTypeLoc TL) { |
| 5925 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5926 | if (ValueType.isNull()) |
| 5927 | return QualType(); |
| 5928 | |
| 5929 | QualType Result = TL.getType(); |
| 5930 | if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 5931 | const PipeType *PT = Result->getAs<PipeType>(); |
| 5932 | bool isReadPipe = PT->isReadOnly(); |
| 5933 | Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5934 | if (Result.isNull()) |
| 5935 | return QualType(); |
| 5936 | } |
| 5937 | |
| 5938 | PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 5939 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5940 | |
| 5941 | return Result; |
| 5942 | } |
| 5943 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5944 | /// Simple iterator that traverses the template arguments in a |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5945 | /// container that provides a \c getArgLoc() member function. |
| 5946 | /// |
| 5947 | /// This iterator is intended to be used with the iterator form of |
| 5948 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5949 | template<typename ArgLocContainer> |
| 5950 | class TemplateArgumentLocContainerIterator { |
| 5951 | ArgLocContainer *Container; |
| 5952 | unsigned Index; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5953 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5954 | public: |
| 5955 | typedef TemplateArgumentLoc value_type; |
| 5956 | typedef TemplateArgumentLoc reference; |
| 5957 | typedef int difference_type; |
| 5958 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5959 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5960 | class pointer { |
| 5961 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5962 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5963 | public: |
| 5964 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5965 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5966 | const TemplateArgumentLoc *operator->() const { |
| 5967 | return &Arg; |
| 5968 | } |
| 5969 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5970 | |
| 5971 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5972 | TemplateArgumentLocContainerIterator() {} |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5973 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5974 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5975 | unsigned Index) |
| 5976 | : Container(&Container), Index(Index) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5977 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5978 | TemplateArgumentLocContainerIterator &operator++() { |
| 5979 | ++Index; |
| 5980 | return *this; |
| 5981 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5982 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5983 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5984 | TemplateArgumentLocContainerIterator Old(*this); |
| 5985 | ++(*this); |
| 5986 | return Old; |
| 5987 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5988 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5989 | TemplateArgumentLoc operator*() const { |
| 5990 | return Container->getArgLoc(Index); |
| 5991 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5992 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5993 | pointer operator->() const { |
| 5994 | return pointer(Container->getArgLoc(Index)); |
| 5995 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5996 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5997 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5998 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5999 | return X.Container == Y.Container && X.Index == Y.Index; |
| 6000 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6001 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 6002 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 6003 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 6004 | return !(X == Y); |
| 6005 | } |
| 6006 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6007 | |
| 6008 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6009 | template <typename Derived> |
| 6010 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 6011 | TypeLocBuilder &TLB, |
| 6012 | TemplateSpecializationTypeLoc TL, |
| 6013 | TemplateName Template) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6014 | TemplateArgumentListInfo NewTemplateArgs; |
| 6015 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6016 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 6017 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 6018 | ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6019 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 6020 | ArgIterator(TL, TL.getNumArgs()), |
| 6021 | NewTemplateArgs)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 6022 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6023 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6024 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 6025 | |
| 6026 | QualType Result = |
| 6027 | getDerived().RebuildTemplateSpecializationType(Template, |
| 6028 | TL.getTemplateNameLoc(), |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6029 | NewTemplateArgs); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6030 | |
| 6031 | if (!Result.isNull()) { |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6032 | // Specializations of template template parameters are represented as |
| 6033 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 6034 | // within a dependent context can transform them into |
| 6035 | // DependentTemplateSpecializationTypes. |
| 6036 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6037 | DependentTemplateSpecializationTypeLoc NewTL |
| 6038 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6039 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6040 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6041 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6042 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6043 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6044 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6045 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6046 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6047 | return Result; |
| 6048 | } |
| 6049 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6050 | TemplateSpecializationTypeLoc NewTL |
| 6051 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6052 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6053 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6054 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6055 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6056 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6057 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6058 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6059 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6060 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6061 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6062 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6063 | template <typename Derived> |
| 6064 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 6065 | TypeLocBuilder &TLB, |
| 6066 | DependentTemplateSpecializationTypeLoc TL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 6067 | TemplateName Template, |
| 6068 | CXXScopeSpec &SS) { |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6069 | TemplateArgumentListInfo NewTemplateArgs; |
| 6070 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6071 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6072 | typedef TemplateArgumentLocContainerIterator< |
| 6073 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6074 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6075 | ArgIterator(TL, TL.getNumArgs()), |
| 6076 | NewTemplateArgs)) |
| 6077 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6078 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6079 | // 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] | 6080 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6081 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 6082 | QualType Result |
| 6083 | = getSema().Context.getDependentTemplateSpecializationType( |
| 6084 | TL.getTypePtr()->getKeyword(), |
| 6085 | DTN->getQualifier(), |
| 6086 | DTN->getIdentifier(), |
| 6087 | NewTemplateArgs); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6088 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6089 | DependentTemplateSpecializationTypeLoc NewTL |
| 6090 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6091 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6092 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6093 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6094 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6095 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6096 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6097 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6098 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6099 | return Result; |
| 6100 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6101 | |
| 6102 | QualType Result |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6103 | = getDerived().RebuildTemplateSpecializationType(Template, |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6104 | TL.getTemplateNameLoc(), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6105 | NewTemplateArgs); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6106 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6107 | if (!Result.isNull()) { |
| 6108 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 6109 | TemplateSpecializationTypeLoc NewTL |
| 6110 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6111 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6112 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6113 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6114 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6115 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6116 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6117 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6118 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6119 | return Result; |
| 6120 | } |
| 6121 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6122 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6123 | QualType |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6124 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6125 | ElaboratedTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6126 | const ElaboratedType *T = TL.getTypePtr(); |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6127 | |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6128 | NestedNameSpecifierLoc QualifierLoc; |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6129 | // NOTE: the qualifier in an ElaboratedType is optional. |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6130 | if (TL.getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6131 | QualifierLoc |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6132 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6133 | if (!QualifierLoc) |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6134 | return QualType(); |
| 6135 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6136 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6137 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 6138 | if (NamedT.isNull()) |
| 6139 | return QualType(); |
| Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 6140 | |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6141 | // C++0x [dcl.type.elab]p2: |
| 6142 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 6143 | // resolves to an alias template specialization, the |
| 6144 | // elaborated-type-specifier is ill-formed. |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6145 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 6146 | if (const TemplateSpecializationType *TST = |
| 6147 | NamedT->getAs<TemplateSpecializationType>()) { |
| 6148 | TemplateName Template = TST->getTemplateName(); |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 6149 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 6150 | Template.getAsTemplateDecl())) { |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6151 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| Reid Kleckner | f33bfcb0 | 2016-10-03 18:34:23 +0000 | [diff] [blame] | 6152 | diag::err_tag_reference_non_tag) |
| Reid Kleckner | 1a4ab7e | 2016-12-09 19:47:58 +0000 | [diff] [blame] | 6153 | << TAT << Sema::NTK_TypeAliasTemplate |
| 6154 | << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6155 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 6156 | } |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6157 | } |
| 6158 | } |
| 6159 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6160 | QualType Result = TL.getType(); |
| 6161 | if (getDerived().AlwaysRebuild() || |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6162 | QualifierLoc != TL.getQualifierLoc() || |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6163 | NamedT != T->getNamedType()) { |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6164 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6165 | T->getKeyword(), |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6166 | QualifierLoc, NamedT); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6167 | if (Result.isNull()) |
| 6168 | return QualType(); |
| 6169 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6170 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6171 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6172 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6173 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6174 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6175 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6176 | |
| 6177 | template<typename Derived> |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6178 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 6179 | TypeLocBuilder &TLB, |
| 6180 | AttributedTypeLoc TL) { |
| 6181 | const AttributedType *oldType = TL.getTypePtr(); |
| 6182 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 6183 | if (modifiedType.isNull()) |
| 6184 | return QualType(); |
| 6185 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6186 | // oldAttr can be null if we started with a QualType rather than a TypeLoc. |
| 6187 | const Attr *oldAttr = TL.getAttr(); |
| 6188 | const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; |
| 6189 | if (oldAttr && !newAttr) |
| 6190 | return QualType(); |
| 6191 | |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6192 | QualType result = TL.getType(); |
| 6193 | |
| 6194 | // FIXME: dependent operand expressions? |
| 6195 | if (getDerived().AlwaysRebuild() || |
| 6196 | modifiedType != oldType->getModifiedType()) { |
| 6197 | // TODO: this is really lame; we should really be rebuilding the |
| 6198 | // equivalent type from first principles. |
| 6199 | QualType equivalentType |
| 6200 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 6201 | if (equivalentType.isNull()) |
| 6202 | return QualType(); |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6203 | |
| 6204 | // Check whether we can add nullability; it is only represented as |
| 6205 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 6206 | if (auto nullability = oldType->getImmediateNullability()) { |
| 6207 | if (!modifiedType->canHaveNullability()) { |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6208 | SemaRef.Diag(TL.getAttr()->getLocation(), |
| 6209 | diag::err_nullability_nonpointer) |
| 6210 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6211 | return QualType(); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6215 | result = SemaRef.Context.getAttributedType(TL.getAttrKind(), |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6216 | modifiedType, |
| 6217 | equivalentType); |
| 6218 | } |
| 6219 | |
| 6220 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6221 | newTL.setAttr(newAttr); |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6222 | return result; |
| 6223 | } |
| 6224 | |
| 6225 | template<typename Derived> |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 6226 | QualType |
| 6227 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 6228 | ParenTypeLoc TL) { |
| 6229 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6230 | if (Inner.isNull()) |
| 6231 | return QualType(); |
| 6232 | |
| 6233 | QualType Result = TL.getType(); |
| 6234 | if (getDerived().AlwaysRebuild() || |
| 6235 | Inner != TL.getInnerLoc().getType()) { |
| 6236 | Result = getDerived().RebuildParenType(Inner); |
| 6237 | if (Result.isNull()) |
| 6238 | return QualType(); |
| 6239 | } |
| 6240 | |
| 6241 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 6242 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6243 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6244 | return Result; |
| 6245 | } |
| 6246 | |
| Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 6247 | template <typename Derived> |
| 6248 | QualType |
| 6249 | TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, |
| 6250 | MacroQualifiedTypeLoc TL) { |
| 6251 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6252 | if (Inner.isNull()) |
| 6253 | return QualType(); |
| 6254 | |
| 6255 | QualType Result = TL.getType(); |
| 6256 | if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { |
| 6257 | Result = |
| 6258 | getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); |
| 6259 | if (Result.isNull()) |
| 6260 | return QualType(); |
| 6261 | } |
| 6262 | |
| 6263 | MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); |
| 6264 | NewTL.setExpansionLoc(TL.getExpansionLoc()); |
| 6265 | return Result; |
| 6266 | } |
| 6267 | |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 6268 | template<typename Derived> |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6269 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6270 | TypeLocBuilder &TLB, DependentNameTypeLoc TL) { |
| 6271 | return TransformDependentNameType(TLB, TL, false); |
| 6272 | } |
| 6273 | |
| 6274 | template<typename Derived> |
| 6275 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6276 | TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6277 | const DependentNameType *T = TL.getTypePtr(); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6278 | |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6279 | NestedNameSpecifierLoc QualifierLoc |
| 6280 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6281 | if (!QualifierLoc) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6282 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6283 | |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6284 | QualType Result |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6285 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6286 | TL.getElaboratedKeywordLoc(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6287 | QualifierLoc, |
| 6288 | T->getIdentifier(), |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6289 | TL.getNameLoc(), |
| 6290 | DeducedTSTContext); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6291 | if (Result.isNull()) |
| 6292 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6293 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6294 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 6295 | QualType NamedT = ElabT->getNamedType(); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6296 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 6297 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6298 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6299 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6300 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6301 | } else { |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6302 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6303 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6304 | NewTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6305 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6306 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6307 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6308 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6309 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6310 | template<typename Derived> |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6311 | QualType TreeTransform<Derived>:: |
| 6312 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6313 | DependentTemplateSpecializationTypeLoc TL) { |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6314 | NestedNameSpecifierLoc QualifierLoc; |
| 6315 | if (TL.getQualifierLoc()) { |
| 6316 | QualifierLoc |
| 6317 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6318 | if (!QualifierLoc) |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6319 | return QualType(); |
| 6320 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6321 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6322 | return getDerived() |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6323 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | template<typename Derived> |
| 6327 | QualType TreeTransform<Derived>:: |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6328 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 6329 | DependentTemplateSpecializationTypeLoc TL, |
| 6330 | NestedNameSpecifierLoc QualifierLoc) { |
| 6331 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6332 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6333 | TemplateArgumentListInfo NewTemplateArgs; |
| 6334 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6335 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6336 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6337 | typedef TemplateArgumentLocContainerIterator< |
| 6338 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 6339 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6340 | ArgIterator(TL, TL.getNumArgs()), |
| 6341 | NewTemplateArgs)) |
| 6342 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6343 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6344 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 6345 | T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), |
| 6346 | T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6347 | /*AllowInjectedClassName*/ false); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6348 | if (Result.isNull()) |
| 6349 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6350 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6351 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 6352 | QualType NamedT = ElabT->getNamedType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6353 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6354 | // Copy information relevant to the template specialization. |
| 6355 | TemplateSpecializationTypeLoc NamedTL |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6356 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6357 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6358 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6359 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6360 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6361 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6362 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6363 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6364 | // Copy information relevant to the elaborated type. |
| 6365 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6366 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6367 | NewTL.setQualifierLoc(QualifierLoc); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6368 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6369 | DependentTemplateSpecializationTypeLoc SpecTL |
| 6370 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6371 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6372 | SpecTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6373 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6374 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6375 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6376 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6377 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6378 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6379 | } else { |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6380 | TemplateSpecializationTypeLoc SpecTL |
| 6381 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6382 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6383 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6384 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6385 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6386 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6387 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6388 | } |
| 6389 | return Result; |
| 6390 | } |
| 6391 | |
| 6392 | template<typename Derived> |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6393 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 6394 | PackExpansionTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6395 | QualType Pattern |
| 6396 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6397 | if (Pattern.isNull()) |
| 6398 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6399 | |
| 6400 | QualType Result = TL.getType(); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6401 | if (getDerived().AlwaysRebuild() || |
| 6402 | Pattern != TL.getPatternLoc().getType()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6403 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6404 | TL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6405 | TL.getEllipsisLoc(), |
| 6406 | TL.getTypePtr()->getNumExpansions()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6407 | if (Result.isNull()) |
| 6408 | return QualType(); |
| 6409 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6410 | |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6411 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 6412 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 6413 | return Result; |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6417 | QualType |
| 6418 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6419 | ObjCInterfaceTypeLoc TL) { |
| Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6420 | // ObjCInterfaceType is never dependent. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6421 | TLB.pushFullCopy(TL); |
| 6422 | return TL.getType(); |
| 6423 | } |
| 6424 | |
| 6425 | template<typename Derived> |
| 6426 | QualType |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6427 | TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, |
| 6428 | ObjCTypeParamTypeLoc TL) { |
| 6429 | const ObjCTypeParamType *T = TL.getTypePtr(); |
| 6430 | ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( |
| 6431 | getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); |
| 6432 | if (!OTP) |
| 6433 | return QualType(); |
| 6434 | |
| 6435 | QualType Result = TL.getType(); |
| 6436 | if (getDerived().AlwaysRebuild() || |
| 6437 | OTP != T->getDecl()) { |
| 6438 | Result = getDerived().RebuildObjCTypeParamType(OTP, |
| 6439 | TL.getProtocolLAngleLoc(), |
| 6440 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 6441 | TL.getNumProtocols()), |
| 6442 | TL.getProtocolLocs(), |
| 6443 | TL.getProtocolRAngleLoc()); |
| 6444 | if (Result.isNull()) |
| 6445 | return QualType(); |
| 6446 | } |
| 6447 | |
| 6448 | ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); |
| 6449 | if (TL.getNumProtocols()) { |
| 6450 | NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6451 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6452 | NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6453 | NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6454 | } |
| 6455 | return Result; |
| 6456 | } |
| 6457 | |
| 6458 | template<typename Derived> |
| 6459 | QualType |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6460 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6461 | ObjCObjectTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6462 | // Transform base type. |
| 6463 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 6464 | if (BaseType.isNull()) |
| 6465 | return QualType(); |
| 6466 | |
| 6467 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 6468 | |
| 6469 | // Transform type arguments. |
| 6470 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 6471 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 6472 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 6473 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 6474 | QualType TypeArg = TypeArgInfo->getType(); |
| 6475 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 6476 | AnyChanged = true; |
| 6477 | |
| 6478 | // We have a pack expansion. Instantiate it. |
| 6479 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 6480 | ->castAs<PackExpansionType>(); |
| 6481 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6482 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 6483 | Unexpanded); |
| 6484 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 6485 | |
| 6486 | // Determine whether the set of unexpanded parameter packs can |
| 6487 | // and should be expanded. |
| 6488 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 6489 | bool Expand = false; |
| 6490 | bool RetainExpansion = false; |
| 6491 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 6492 | if (getDerived().TryExpandParameterPacks( |
| 6493 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 6494 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 6495 | return QualType(); |
| 6496 | |
| 6497 | if (!Expand) { |
| 6498 | // We can't expand this pack expansion into separate arguments yet; |
| 6499 | // just substitute into the pattern and create a new pack expansion |
| 6500 | // type. |
| 6501 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 6502 | |
| 6503 | TypeLocBuilder TypeArgBuilder; |
| 6504 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6505 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6506 | PatternLoc); |
| 6507 | if (NewPatternType.isNull()) |
| 6508 | return QualType(); |
| 6509 | |
| 6510 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 6511 | NewPatternType, NumExpansions); |
| 6512 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 6513 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 6514 | NewTypeArgInfos.push_back( |
| 6515 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 6516 | continue; |
| 6517 | } |
| 6518 | |
| 6519 | // Substitute into the pack expansion pattern for each slice of the |
| 6520 | // pack. |
| 6521 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 6522 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 6523 | |
| 6524 | TypeLocBuilder TypeArgBuilder; |
| 6525 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 6526 | |
| 6527 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 6528 | PatternLoc); |
| 6529 | if (NewTypeArg.isNull()) |
| 6530 | return QualType(); |
| 6531 | |
| 6532 | NewTypeArgInfos.push_back( |
| 6533 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6534 | } |
| 6535 | |
| 6536 | continue; |
| 6537 | } |
| 6538 | |
| 6539 | TypeLocBuilder TypeArgBuilder; |
| 6540 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 6541 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 6542 | if (NewTypeArg.isNull()) |
| 6543 | return QualType(); |
| 6544 | |
| 6545 | // If nothing changed, just keep the old TypeSourceInfo. |
| 6546 | if (NewTypeArg == TypeArg) { |
| 6547 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 6548 | continue; |
| 6549 | } |
| 6550 | |
| 6551 | NewTypeArgInfos.push_back( |
| 6552 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6553 | AnyChanged = true; |
| 6554 | } |
| 6555 | |
| 6556 | QualType Result = TL.getType(); |
| 6557 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 6558 | // Rebuild the type. |
| 6559 | Result = getDerived().RebuildObjCObjectType( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6560 | BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, |
| 6561 | TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), |
| 6562 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 6563 | TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6564 | |
| 6565 | if (Result.isNull()) |
| 6566 | return QualType(); |
| 6567 | } |
| 6568 | |
| 6569 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6570 | NewT.setHasBaseTypeAsWritten(true); |
| 6571 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 6572 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 6573 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 6574 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 6575 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6576 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6577 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6578 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6579 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6580 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6581 | |
| 6582 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6583 | QualType |
| 6584 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6585 | ObjCObjectPointerTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6586 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 6587 | if (PointeeType.isNull()) |
| 6588 | return QualType(); |
| 6589 | |
| 6590 | QualType Result = TL.getType(); |
| 6591 | if (getDerived().AlwaysRebuild() || |
| 6592 | PointeeType != TL.getPointeeLoc().getType()) { |
| 6593 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 6594 | TL.getStarLoc()); |
| 6595 | if (Result.isNull()) |
| 6596 | return QualType(); |
| 6597 | } |
| 6598 | |
| 6599 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 6600 | NewT.setStarLoc(TL.getStarLoc()); |
| 6601 | return Result; |
| Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6604 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6605 | // Statement transformation |
| 6606 | //===----------------------------------------------------------------------===// |
| 6607 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6608 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6609 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6610 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
| 6613 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6614 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6615 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 6616 | return getDerived().TransformCompoundStmt(S, false); |
| 6617 | } |
| 6618 | |
| 6619 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6620 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6621 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6622 | bool IsStmtExpr) { |
| Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 6623 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6624 | |
| Aaron Ballman | b1e511b | 2019-07-09 15:02:07 +0000 | [diff] [blame] | 6625 | const Stmt *ExprResult = S->getStmtExprResult(); |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6626 | bool SubStmtInvalid = false; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6627 | bool SubStmtChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6628 | SmallVector<Stmt*, 8> Statements; |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6629 | for (auto *B : S->body()) { |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6630 | StmtResult Result = getDerived().TransformStmt( |
| Aaron Ballman | b1e511b | 2019-07-09 15:02:07 +0000 | [diff] [blame] | 6631 | B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 6632 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6633 | if (Result.isInvalid()) { |
| 6634 | // Immediately fail if this was a DeclStmt, since it's very |
| 6635 | // likely that this will cause problems for future statements. |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6636 | if (isa<DeclStmt>(B)) |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6637 | return StmtError(); |
| 6638 | |
| 6639 | // Otherwise, just keep processing substatements and fail later. |
| 6640 | SubStmtInvalid = true; |
| 6641 | continue; |
| 6642 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6643 | |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6644 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6645 | Statements.push_back(Result.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6646 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6647 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6648 | if (SubStmtInvalid) |
| 6649 | return StmtError(); |
| 6650 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6651 | if (!getDerived().AlwaysRebuild() && |
| 6652 | !SubStmtChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6653 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6654 | |
| 6655 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6656 | Statements, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6657 | S->getRBracLoc(), |
| 6658 | IsStmtExpr); |
| 6659 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6660 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6661 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6662 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6663 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6664 | ExprResult LHS, RHS; |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6665 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 6666 | EnterExpressionEvaluationContext Unevaluated( |
| 6667 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6668 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6669 | // Transform the left-hand case value. |
| 6670 | LHS = getDerived().TransformExpr(S->getLHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6671 | LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6672 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6673 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6674 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6675 | // Transform the right-hand case value (for the GNU case-range extension). |
| 6676 | RHS = getDerived().TransformExpr(S->getRHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6677 | RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6678 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6679 | return StmtError(); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6680 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6681 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6682 | // Build the case statement. |
| 6683 | // Case statements are always rebuilt so that they will attached to their |
| 6684 | // transformed switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6685 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6686 | LHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6687 | S->getEllipsisLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6688 | RHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6689 | S->getColonLoc()); |
| 6690 | if (Case.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6691 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6692 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6693 | // Transform the statement following the case |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6694 | StmtResult SubStmt = |
| 6695 | getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6696 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6697 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6698 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6699 | // Attach the body to the case statement |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6700 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6703 | template <typename Derived> |
| 6704 | StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6705 | // Transform the statement following the default case |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6706 | StmtResult SubStmt = |
| 6707 | getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6708 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6709 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6710 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6711 | // Default statements are always rebuilt |
| 6712 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6713 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6714 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6715 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6716 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6717 | StmtResult |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6718 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { |
| 6719 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6720 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6721 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6722 | |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6723 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 6724 | S->getDecl()); |
| 6725 | if (!LD) |
| 6726 | return StmtError(); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6727 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6728 | // If we're transforming "in-place" (we're not creating new local |
| 6729 | // declarations), assume we're replacing the old label statement |
| 6730 | // and clear out the reference to it. |
| 6731 | if (LD == S->getDecl()) |
| 6732 | S->getDecl()->setStmt(nullptr); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6733 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6734 | // FIXME: Pass the real colon location in. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 6735 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6736 | cast<LabelDecl>(LD), SourceLocation(), |
| 6737 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6738 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6739 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6740 | template <typename Derived> |
| 6741 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 6742 | if (!R) |
| 6743 | return R; |
| 6744 | |
| 6745 | switch (R->getKind()) { |
| 6746 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 6747 | #define ATTR(X) |
| 6748 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 6749 | case attr::X: \ |
| 6750 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 6751 | #include "clang/Basic/AttrList.inc" |
| 6752 | default: |
| 6753 | return R; |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | template <typename Derived> |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6758 | StmtResult |
| 6759 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, |
| 6760 | StmtDiscardKind SDK) { |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6761 | bool AttrsChanged = false; |
| 6762 | SmallVector<const Attr *, 1> Attrs; |
| 6763 | |
| 6764 | // Visit attributes and keep track if any are transformed. |
| 6765 | for (const auto *I : S->getAttrs()) { |
| 6766 | const Attr *R = getDerived().TransformAttr(I); |
| 6767 | AttrsChanged |= (I != R); |
| 6768 | Attrs.push_back(R); |
| 6769 | } |
| 6770 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6771 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6772 | if (SubStmt.isInvalid()) |
| 6773 | return StmtError(); |
| 6774 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6775 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6776 | return S; |
| 6777 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6778 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6779 | SubStmt.get()); |
| 6780 | } |
| 6781 | |
| 6782 | template<typename Derived> |
| 6783 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6784 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6785 | // Transform the initialization statement |
| 6786 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6787 | if (Init.isInvalid()) |
| 6788 | return StmtError(); |
| 6789 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6790 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6791 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6792 | S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6793 | S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 6794 | : Sema::ConditionKind::Boolean); |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6795 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6796 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6797 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6798 | // If this is a constexpr if, determine which arm we should instantiate. |
| 6799 | llvm::Optional<bool> ConstexprConditionValue; |
| 6800 | if (S->isConstexpr()) |
| 6801 | ConstexprConditionValue = Cond.getKnownValue(); |
| 6802 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6803 | // Transform the "then" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6804 | StmtResult Then; |
| 6805 | if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 6806 | Then = getDerived().TransformStmt(S->getThen()); |
| 6807 | if (Then.isInvalid()) |
| 6808 | return StmtError(); |
| 6809 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6810 | Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6811 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6812 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6813 | // Transform the "else" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6814 | StmtResult Else; |
| 6815 | if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 6816 | Else = getDerived().TransformStmt(S->getElse()); |
| 6817 | if (Else.isInvalid()) |
| 6818 | return StmtError(); |
| 6819 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6820 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6821 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6822 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6823 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6824 | Then.get() == S->getThen() && |
| 6825 | Else.get() == S->getElse()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6826 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6827 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6828 | return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond, |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6829 | Init.get(), Then.get(), S->getElseLoc(), |
| 6830 | Else.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6834 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6835 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6836 | // Transform the initialization statement |
| 6837 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6838 | if (Init.isInvalid()) |
| 6839 | return StmtError(); |
| 6840 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6841 | // Transform the condition. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6842 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6843 | S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 6844 | Sema::ConditionKind::Switch); |
| 6845 | if (Cond.isInvalid()) |
| 6846 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6847 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6848 | // Rebuild the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6849 | StmtResult Switch |
| Volodymyr Sapsai | ddf524c | 2017-09-21 17:58:27 +0000 | [diff] [blame] | 6850 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6851 | if (Switch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6852 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6853 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6854 | // Transform the body of the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6855 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6856 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6857 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6858 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6859 | // Complete the switch statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6860 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6861 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6862 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6863 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6864 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6865 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6866 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6867 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6868 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6869 | S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 6870 | Sema::ConditionKind::Boolean); |
| 6871 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6872 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6873 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6874 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6875 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6876 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6877 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6878 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6879 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6880 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6881 | Body.get() == S->getBody()) |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6882 | return Owned(S); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6883 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6884 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6885 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6886 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6887 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6888 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6889 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6890 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6891 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6892 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6893 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6894 | |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6895 | // Transform the condition |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6896 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6897 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6898 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6899 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6900 | if (!getDerived().AlwaysRebuild() && |
| 6901 | Cond.get() == S->getCond() && |
| 6902 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6903 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6904 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6905 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6906 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6907 | S->getRParenLoc()); |
| 6908 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6909 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6910 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6911 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6912 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 6913 | if (getSema().getLangOpts().OpenMP) |
| 6914 | getSema().startOpenMPLoop(); |
| 6915 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6916 | // Transform the initialization statement |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6917 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6918 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6919 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6920 | |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6921 | // In OpenMP loop region loop control variable must be captured and be |
| 6922 | // private. Perform analysis of first part (if any). |
| 6923 | if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 6924 | getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); |
| 6925 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6926 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6927 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6928 | S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 6929 | Sema::ConditionKind::Boolean); |
| 6930 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6931 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6932 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6933 | // Transform the increment |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6934 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6935 | if (Inc.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6936 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6937 | |
| Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6938 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6939 | if (S->getInc() && !FullInc.get()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6940 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6941 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6942 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6943 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6944 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6945 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6946 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6947 | if (!getDerived().AlwaysRebuild() && |
| 6948 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6949 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6950 | Inc.get() == S->getInc() && |
| 6951 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6952 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6953 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6954 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6955 | Init.get(), Cond, FullInc, |
| 6956 | S->getRParenLoc(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6957 | } |
| 6958 | |
| 6959 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6960 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6961 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6962 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6963 | S->getLabel()); |
| 6964 | if (!LD) |
| 6965 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6966 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6967 | // Goto statements must always be rebuilt, to resolve the label. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6968 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6969 | cast<LabelDecl>(LD)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6973 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6974 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6975 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6976 | if (Target.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6977 | return StmtError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6978 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6979 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6980 | if (!getDerived().AlwaysRebuild() && |
| 6981 | Target.get() == S->getTarget()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6982 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6983 | |
| 6984 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6985 | Target.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6986 | } |
| 6987 | |
| 6988 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6989 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6990 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6991 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6992 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6993 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6994 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6995 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6996 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6997 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6998 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6999 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7000 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7001 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7002 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
| Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 7003 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 7004 | /*NotCopyInit*/false); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7005 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7006 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7007 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7008 | // FIXME: We always rebuild the return statement because there is no way |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7009 | // to tell whether the return type of the function has changed. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7010 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7011 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7012 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7013 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7014 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7015 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7016 | bool DeclChanged = false; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7017 | SmallVector<Decl *, 4> Decls; |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 7018 | for (auto *D : S->decls()) { |
| 7019 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7020 | if (!Transformed) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7021 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7022 | |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 7023 | if (Transformed != D) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7024 | DeclChanged = true; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7025 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7026 | Decls.push_back(Transformed); |
| 7027 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7028 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7029 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7030 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7031 | |
| Stephen Kelly | a6e4358 | 2018-08-09 21:05:56 +0000 | [diff] [blame] | 7032 | return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7033 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7034 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7035 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7036 | StmtResult |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 7037 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7038 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7039 | SmallVector<Expr*, 8> Constraints; |
| 7040 | SmallVector<Expr*, 8> Exprs; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7041 | SmallVector<IdentifierInfo *, 4> Names; |
| Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 7042 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7043 | ExprResult AsmString; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7044 | SmallVector<Expr*, 8> Clobbers; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7045 | |
| 7046 | bool ExprsChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7047 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7048 | // Go through the outputs. |
| 7049 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 7050 | Names.push_back(S->getOutputIdentifier(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7051 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7052 | // No need to transform the constraint literal. |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7053 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7054 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7055 | // Transform the output expr. |
| 7056 | Expr *OutputExpr = S->getOutputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7057 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7058 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7059 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7060 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7061 | ExprsChanged |= Result.get() != OutputExpr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7062 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7063 | Exprs.push_back(Result.get()); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7064 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7065 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7066 | // Go through the inputs. |
| 7067 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 7068 | Names.push_back(S->getInputIdentifier(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7069 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7070 | // No need to transform the constraint literal. |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7071 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7072 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7073 | // Transform the input expr. |
| 7074 | Expr *InputExpr = S->getInputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7075 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7076 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7077 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7078 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7079 | ExprsChanged |= Result.get() != InputExpr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7080 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7081 | Exprs.push_back(Result.get()); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7082 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7083 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 7084 | // Go through the Labels. |
| 7085 | for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { |
| 7086 | Names.push_back(S->getLabelIdentifier(I)); |
| 7087 | |
| 7088 | ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); |
| 7089 | if (Result.isInvalid()) |
| 7090 | return StmtError(); |
| 7091 | ExprsChanged |= Result.get() != S->getLabelExpr(I); |
| 7092 | Exprs.push_back(Result.get()); |
| 7093 | } |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7094 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7095 | return S; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7096 | |
| 7097 | // Go through the clobbers. |
| 7098 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 7099 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7100 | |
| 7101 | // No need to transform the asm string literal. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7102 | AsmString = S->getAsmString(); |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 7103 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 7104 | S->isVolatile(), S->getNumOutputs(), |
| 7105 | S->getNumInputs(), Names.data(), |
| 7106 | Constraints, Exprs, AsmString.get(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 7107 | Clobbers, S->getNumLabels(), |
| 7108 | S->getRParenLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7109 | } |
| 7110 | |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 7111 | template<typename Derived> |
| 7112 | StmtResult |
| 7113 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 7114 | ArrayRef<Token> AsmToks = |
| 7115 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
| Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 7116 | |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7117 | bool HadError = false, HadChange = false; |
| 7118 | |
| 7119 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 7120 | SmallVector<Expr*, 8> TransformedExprs; |
| 7121 | TransformedExprs.reserve(SrcExprs.size()); |
| 7122 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 7123 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 7124 | if (!Result.isUsable()) { |
| 7125 | HadError = true; |
| 7126 | } else { |
| 7127 | HadChange |= (Result.get() != SrcExprs[i]); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7128 | TransformedExprs.push_back(Result.get()); |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7129 | } |
| 7130 | } |
| 7131 | |
| 7132 | if (HadError) return StmtError(); |
| 7133 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 7134 | return Owned(S); |
| 7135 | |
| Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 7136 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7137 | AsmToks, S->getAsmString(), |
| 7138 | S->getNumOutputs(), S->getNumInputs(), |
| 7139 | S->getAllConstraints(), S->getClobbers(), |
| 7140 | TransformedExprs, S->getEndLoc()); |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 7141 | } |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7142 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7143 | // C++ Coroutines TS |
| 7144 | |
| 7145 | template<typename Derived> |
| 7146 | StmtResult |
| 7147 | TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7148 | auto *ScopeInfo = SemaRef.getCurFunction(); |
| 7149 | auto *FD = cast<FunctionDecl>(SemaRef.CurContext); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7150 | assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7151 | ScopeInfo->NeedsCoroutineSuspends && |
| 7152 | ScopeInfo->CoroutineSuspends.first == nullptr && |
| 7153 | ScopeInfo->CoroutineSuspends.second == nullptr && |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 7154 | "expected clean scope info"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7155 | |
| 7156 | // Set that we have (possibly-invalid) suspend points before we do anything |
| 7157 | // that may fail. |
| 7158 | ScopeInfo->setNeedsCoroutineSuspends(false); |
| 7159 | |
| 7160 | // The new CoroutinePromise object needs to be built and put into the current |
| 7161 | // FunctionScopeInfo before any transformations or rebuilding occurs. |
| Brian Gesiak | 61f4ac9 | 2018-01-24 22:15:42 +0000 | [diff] [blame] | 7162 | if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) |
| 7163 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7164 | auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); |
| 7165 | if (!Promise) |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7166 | return StmtError(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 7167 | getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7168 | ScopeInfo->CoroutinePromise = Promise; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7169 | |
| 7170 | // Transform the implicit coroutine statements we built during the initial |
| 7171 | // parse. |
| 7172 | StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); |
| 7173 | if (InitSuspend.isInvalid()) |
| 7174 | return StmtError(); |
| 7175 | StmtResult FinalSuspend = |
| 7176 | getDerived().TransformStmt(S->getFinalSuspendStmt()); |
| 7177 | if (FinalSuspend.isInvalid()) |
| 7178 | return StmtError(); |
| 7179 | ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); |
| 7180 | assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7181 | |
| 7182 | StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); |
| 7183 | if (BodyRes.isInvalid()) |
| 7184 | return StmtError(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7185 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7186 | CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); |
| 7187 | if (Builder.isInvalid()) |
| 7188 | return StmtError(); |
| 7189 | |
| 7190 | Expr *ReturnObject = S->getReturnValueInit(); |
| 7191 | assert(ReturnObject && "the return object is expected to be valid"); |
| 7192 | ExprResult Res = getDerived().TransformInitializer(ReturnObject, |
| 7193 | /*NoCopyInit*/ false); |
| 7194 | if (Res.isInvalid()) |
| 7195 | return StmtError(); |
| 7196 | Builder.ReturnValue = Res.get(); |
| 7197 | |
| 7198 | if (S->hasDependentPromiseType()) { |
| Brian Gesiak | 38f1182 | 2019-06-03 00:47:32 +0000 | [diff] [blame] | 7199 | // PR41909: We may find a generic coroutine lambda definition within a |
| 7200 | // template function that is being instantiated. In this case, the lambda |
| 7201 | // will have a dependent promise type, until it is used in an expression |
| 7202 | // that creates an instantiation with a non-dependent promise type. We |
| 7203 | // should not assert or build coroutine dependent statements for such a |
| 7204 | // generic lambda. |
| 7205 | auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD); |
| 7206 | if (!MD || !MD->getParent()->isGenericLambda()) { |
| 7207 | assert(!Promise->getType()->isDependentType() && |
| 7208 | "the promise type must no longer be dependent"); |
| 7209 | assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && |
| 7210 | !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && |
| 7211 | "these nodes should not have been built yet"); |
| 7212 | if (!Builder.buildDependentStatements()) |
| 7213 | return StmtError(); |
| 7214 | } |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7215 | } else { |
| 7216 | if (auto *OnFallthrough = S->getFallthroughHandler()) { |
| 7217 | StmtResult Res = getDerived().TransformStmt(OnFallthrough); |
| 7218 | if (Res.isInvalid()) |
| 7219 | return StmtError(); |
| 7220 | Builder.OnFallthrough = Res.get(); |
| 7221 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7222 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7223 | if (auto *OnException = S->getExceptionHandler()) { |
| 7224 | StmtResult Res = getDerived().TransformStmt(OnException); |
| 7225 | if (Res.isInvalid()) |
| 7226 | return StmtError(); |
| 7227 | Builder.OnException = Res.get(); |
| 7228 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7229 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7230 | if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { |
| 7231 | StmtResult Res = getDerived().TransformStmt(OnAllocFailure); |
| 7232 | if (Res.isInvalid()) |
| 7233 | return StmtError(); |
| 7234 | Builder.ReturnStmtOnAllocFailure = Res.get(); |
| 7235 | } |
| 7236 | |
| 7237 | // Transform any additional statements we may have already built |
| 7238 | assert(S->getAllocate() && S->getDeallocate() && |
| 7239 | "allocation and deallocation calls must already be built"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7240 | ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); |
| 7241 | if (AllocRes.isInvalid()) |
| 7242 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7243 | Builder.Allocate = AllocRes.get(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7244 | |
| 7245 | ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); |
| 7246 | if (DeallocRes.isInvalid()) |
| 7247 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7248 | Builder.Deallocate = DeallocRes.get(); |
| Gor Nishanov | afff89e | 2017-05-24 15:44:57 +0000 | [diff] [blame] | 7249 | |
| 7250 | assert(S->getResultDecl() && "ResultDecl must already be built"); |
| 7251 | StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl()); |
| 7252 | if (ResultDecl.isInvalid()) |
| 7253 | return StmtError(); |
| 7254 | Builder.ResultDecl = ResultDecl.get(); |
| 7255 | |
| 7256 | if (auto *ReturnStmt = S->getReturnStmt()) { |
| 7257 | StmtResult Res = getDerived().TransformStmt(ReturnStmt); |
| 7258 | if (Res.isInvalid()) |
| 7259 | return StmtError(); |
| 7260 | Builder.ReturnStmt = Res.get(); |
| 7261 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7262 | } |
| 7263 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7264 | return getDerived().RebuildCoroutineBodyStmt(Builder); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7265 | } |
| 7266 | |
| 7267 | template<typename Derived> |
| 7268 | StmtResult |
| 7269 | TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 7270 | ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 7271 | /*NotCopyInit*/false); |
| 7272 | if (Result.isInvalid()) |
| 7273 | return StmtError(); |
| 7274 | |
| 7275 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7276 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7277 | return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), |
| 7278 | S->isImplicit()); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7279 | } |
| 7280 | |
| 7281 | template<typename Derived> |
| 7282 | ExprResult |
| 7283 | TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 7284 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7285 | /*NotCopyInit*/false); |
| 7286 | if (Result.isInvalid()) |
| 7287 | return ExprError(); |
| 7288 | |
| 7289 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7290 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7291 | return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(), |
| 7292 | E->isImplicit()); |
| 7293 | } |
| 7294 | |
| 7295 | template <typename Derived> |
| 7296 | ExprResult |
| 7297 | TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { |
| 7298 | ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), |
| 7299 | /*NotCopyInit*/ false); |
| 7300 | if (OperandResult.isInvalid()) |
| 7301 | return ExprError(); |
| 7302 | |
| 7303 | ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( |
| 7304 | E->getOperatorCoawaitLookup()); |
| 7305 | |
| 7306 | if (LookupResult.isInvalid()) |
| 7307 | return ExprError(); |
| 7308 | |
| 7309 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7310 | // context or if the promise type has changed. |
| 7311 | return getDerived().RebuildDependentCoawaitExpr( |
| 7312 | E->getKeywordLoc(), OperandResult.get(), |
| 7313 | cast<UnresolvedLookupExpr>(LookupResult.get())); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7314 | } |
| 7315 | |
| 7316 | template<typename Derived> |
| 7317 | ExprResult |
| 7318 | TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 7319 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7320 | /*NotCopyInit*/false); |
| 7321 | if (Result.isInvalid()) |
| 7322 | return ExprError(); |
| 7323 | |
| 7324 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7325 | // context or if the promise type has changed. |
| 7326 | return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 7327 | } |
| 7328 | |
| 7329 | // Objective-C Statements. |
| 7330 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7331 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7332 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7333 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7334 | // Transform the body of the @try. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7335 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7336 | if (TryBody.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7337 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7338 | |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7339 | // Transform the @catch statements (if present). |
| 7340 | bool AnyCatchChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7341 | SmallVector<Stmt*, 8> CatchStmts; |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7342 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7343 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7344 | if (Catch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7345 | return StmtError(); |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7346 | if (Catch.get() != S->getCatchStmt(I)) |
| 7347 | AnyCatchChanged = true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7348 | CatchStmts.push_back(Catch.get()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7349 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7350 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7351 | // Transform the @finally statement (if present). |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7352 | StmtResult Finally; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7353 | if (S->getFinallyStmt()) { |
| 7354 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 7355 | if (Finally.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7356 | return StmtError(); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7357 | } |
| 7358 | |
| 7359 | // If nothing changed, just retain this statement. |
| 7360 | if (!getDerived().AlwaysRebuild() && |
| 7361 | TryBody.get() == S->getTryBody() && |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7362 | !AnyCatchChanged && |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7363 | Finally.get() == S->getFinallyStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7364 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7365 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7366 | // Build a new statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7367 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7368 | CatchStmts, Finally.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7369 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7370 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7371 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7372 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7373 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7374 | // Transform the @catch parameter, if there is one. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7375 | VarDecl *Var = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7376 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7377 | TypeSourceInfo *TSInfo = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7378 | if (FromVar->getTypeSourceInfo()) { |
| 7379 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 7380 | if (!TSInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7381 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7382 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7383 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7384 | QualType T; |
| 7385 | if (TSInfo) |
| 7386 | T = TSInfo->getType(); |
| 7387 | else { |
| 7388 | T = getDerived().TransformType(FromVar->getType()); |
| 7389 | if (T.isNull()) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7390 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7391 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7392 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7393 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 7394 | if (!Var) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7395 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7396 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7397 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7398 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7399 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7400 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7401 | |
| 7402 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7403 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7404 | Var, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7405 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7406 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7407 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7408 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7409 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7410 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7411 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7412 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7413 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7414 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7415 | // If nothing changed, just retain this statement. |
| 7416 | if (!getDerived().AlwaysRebuild() && |
| 7417 | Body.get() == S->getFinallyBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7418 | return S; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7419 | |
| 7420 | // Build a new statement. |
| 7421 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7422 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7423 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7424 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7425 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7426 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7427 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7428 | ExprResult Operand; |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7429 | if (S->getThrowExpr()) { |
| 7430 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 7431 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7432 | return StmtError(); |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7433 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7434 | |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7435 | if (!getDerived().AlwaysRebuild() && |
| 7436 | Operand.get() == S->getThrowExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7437 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7438 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7439 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7440 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7441 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7442 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7443 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7444 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7445 | ObjCAtSynchronizedStmt *S) { |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7446 | // Transform the object we are locking. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7447 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7448 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7449 | return StmtError(); |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 7450 | Object = |
| 7451 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 7452 | Object.get()); |
| 7453 | if (Object.isInvalid()) |
| 7454 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7455 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7456 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7457 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7458 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7459 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7460 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7461 | // If nothing change, just retain the current statement. |
| 7462 | if (!getDerived().AlwaysRebuild() && |
| 7463 | Object.get() == S->getSynchExpr() && |
| 7464 | Body.get() == S->getSynchBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7465 | return S; |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7466 | |
| 7467 | // Build a new statement. |
| 7468 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7469 | Object.get(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7470 | } |
| 7471 | |
| 7472 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7473 | StmtResult |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7474 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 7475 | ObjCAutoreleasePoolStmt *S) { |
| 7476 | // Transform the body. |
| 7477 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 7478 | if (Body.isInvalid()) |
| 7479 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7480 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7481 | // If nothing changed, just retain this statement. |
| 7482 | if (!getDerived().AlwaysRebuild() && |
| 7483 | Body.get() == S->getSubStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7484 | return S; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7485 | |
| 7486 | // Build a new statement. |
| 7487 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 7488 | S->getAtLoc(), Body.get()); |
| 7489 | } |
| 7490 | |
| 7491 | template<typename Derived> |
| 7492 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7493 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7494 | ObjCForCollectionStmt *S) { |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7495 | // Transform the element statement. |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 7496 | StmtResult Element = |
| 7497 | getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7498 | if (Element.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7499 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7500 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7501 | // Transform the collection expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7502 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7503 | if (Collection.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7504 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7505 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7506 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7507 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7508 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7509 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7510 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7511 | // If nothing changed, just retain this statement. |
| 7512 | if (!getDerived().AlwaysRebuild() && |
| 7513 | Element.get() == S->getElement() && |
| 7514 | Collection.get() == S->getCollection() && |
| 7515 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7516 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7517 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7518 | // Build a new statement. |
| 7519 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7520 | Element.get(), |
| 7521 | Collection.get(), |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7522 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7523 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7524 | } |
| 7525 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7526 | template <typename Derived> |
| 7527 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7528 | // Transform the exception declaration, if any. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7529 | VarDecl *Var = nullptr; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7530 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 7531 | TypeSourceInfo *T = |
| 7532 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
| Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 7533 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7534 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7535 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7536 | Var = getDerived().RebuildExceptionDecl( |
| 7537 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 7538 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7539 | if (!Var || Var->isInvalidDecl()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7540 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7541 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7542 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7543 | // Transform the actual exception handler. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7544 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7545 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7546 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7547 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7548 | if (!getDerived().AlwaysRebuild() && !Var && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7549 | Handler.get() == S->getHandlerBlock()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7550 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7551 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7552 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7553 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7554 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7555 | template <typename Derived> |
| 7556 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7557 | // Transform the try block itself. |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7558 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7559 | if (TryBlock.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7560 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7561 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7562 | // Transform the handlers. |
| 7563 | bool HandlerChanged = false; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7564 | SmallVector<Stmt *, 8> Handlers; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7565 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7566 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7567 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7568 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7569 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7570 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7571 | Handlers.push_back(Handler.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7572 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7573 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7574 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7575 | !HandlerChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7576 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7577 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7578 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7579 | Handlers); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7580 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7581 | |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7582 | template<typename Derived> |
| 7583 | StmtResult |
| 7584 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7585 | StmtResult Init = |
| 7586 | S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); |
| 7587 | if (Init.isInvalid()) |
| 7588 | return StmtError(); |
| 7589 | |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7590 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 7591 | if (Range.isInvalid()) |
| 7592 | return StmtError(); |
| 7593 | |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7594 | StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 7595 | if (Begin.isInvalid()) |
| 7596 | return StmtError(); |
| 7597 | StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 7598 | if (End.isInvalid()) |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7599 | return StmtError(); |
| 7600 | |
| 7601 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 7602 | if (Cond.isInvalid()) |
| 7603 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7604 | if (Cond.get()) |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7605 | Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7606 | if (Cond.isInvalid()) |
| 7607 | return StmtError(); |
| 7608 | if (Cond.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7609 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7610 | |
| 7611 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 7612 | if (Inc.isInvalid()) |
| 7613 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7614 | if (Inc.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7615 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7616 | |
| 7617 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 7618 | if (LoopVar.isInvalid()) |
| 7619 | return StmtError(); |
| 7620 | |
| 7621 | StmtResult NewStmt = S; |
| 7622 | if (getDerived().AlwaysRebuild() || |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7623 | Init.get() != S->getInit() || |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7624 | Range.get() != S->getRangeStmt() || |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7625 | Begin.get() != S->getBeginStmt() || |
| 7626 | End.get() != S->getEndStmt() || |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7627 | Cond.get() != S->getCond() || |
| 7628 | Inc.get() != S->getInc() || |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7629 | LoopVar.get() != S->getLoopVarStmt()) { |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7630 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7631 | S->getCoawaitLoc(), Init.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7632 | S->getColonLoc(), Range.get(), |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7633 | Begin.get(), End.get(), |
| 7634 | Cond.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7635 | Inc.get(), LoopVar.get(), |
| 7636 | S->getRParenLoc()); |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7637 | if (NewStmt.isInvalid()) |
| 7638 | return StmtError(); |
| 7639 | } |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7640 | |
| 7641 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7642 | if (Body.isInvalid()) |
| 7643 | return StmtError(); |
| 7644 | |
| 7645 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 7646 | // 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] | 7647 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7648 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7649 | S->getCoawaitLoc(), Init.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7650 | S->getColonLoc(), Range.get(), |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7651 | Begin.get(), End.get(), |
| 7652 | Cond.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7653 | Inc.get(), LoopVar.get(), |
| 7654 | S->getRParenLoc()); |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7655 | if (NewStmt.isInvalid()) |
| 7656 | return StmtError(); |
| 7657 | } |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7658 | |
| 7659 | if (NewStmt.get() == S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7660 | return S; |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7661 | |
| 7662 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 7663 | } |
| 7664 | |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7665 | template<typename Derived> |
| 7666 | StmtResult |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7667 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 7668 | MSDependentExistsStmt *S) { |
| 7669 | // Transform the nested-name-specifier, if any. |
| 7670 | NestedNameSpecifierLoc QualifierLoc; |
| 7671 | if (S->getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7672 | QualifierLoc |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7673 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 7674 | if (!QualifierLoc) |
| 7675 | return StmtError(); |
| 7676 | } |
| 7677 | |
| 7678 | // Transform the declaration name. |
| 7679 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 7680 | if (NameInfo.getName()) { |
| 7681 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7682 | if (!NameInfo.getName()) |
| 7683 | return StmtError(); |
| 7684 | } |
| 7685 | |
| 7686 | // Check whether anything changed. |
| 7687 | if (!getDerived().AlwaysRebuild() && |
| 7688 | QualifierLoc == S->getQualifierLoc() && |
| 7689 | NameInfo.getName() == S->getNameInfo().getName()) |
| 7690 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7691 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7692 | // Determine whether this name exists, if we can. |
| 7693 | CXXScopeSpec SS; |
| 7694 | SS.Adopt(QualifierLoc); |
| 7695 | bool Dependent = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7696 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7697 | case Sema::IER_Exists: |
| 7698 | if (S->isIfExists()) |
| 7699 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7700 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7701 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 7702 | |
| 7703 | case Sema::IER_DoesNotExist: |
| 7704 | if (S->isIfNotExists()) |
| 7705 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7706 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7707 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7708 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7709 | case Sema::IER_Dependent: |
| 7710 | Dependent = true; |
| 7711 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7712 | |
| Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 7713 | case Sema::IER_Error: |
| 7714 | return StmtError(); |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7715 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7716 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7717 | // We need to continue with the instantiation, so do so now. |
| 7718 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 7719 | if (SubStmt.isInvalid()) |
| 7720 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7721 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7722 | // If we have resolved the name, just transform to the substatement. |
| 7723 | if (!Dependent) |
| 7724 | return SubStmt; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7725 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7726 | // The name is still dependent, so build a dependent expression again. |
| 7727 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 7728 | S->isIfExists(), |
| 7729 | QualifierLoc, |
| 7730 | NameInfo, |
| 7731 | SubStmt.get()); |
| 7732 | } |
| 7733 | |
| 7734 | template<typename Derived> |
| John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 7735 | ExprResult |
| 7736 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 7737 | NestedNameSpecifierLoc QualifierLoc; |
| 7738 | if (E->getQualifierLoc()) { |
| 7739 | QualifierLoc |
| 7740 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7741 | if (!QualifierLoc) |
| 7742 | return ExprError(); |
| 7743 | } |
| 7744 | |
| 7745 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 7746 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 7747 | if (!PD) |
| 7748 | return ExprError(); |
| 7749 | |
| 7750 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 7751 | if (Base.isInvalid()) |
| 7752 | return ExprError(); |
| 7753 | |
| 7754 | return new (SemaRef.getASTContext()) |
| 7755 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 7756 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 7757 | QualifierLoc, E->getMemberLoc()); |
| 7758 | } |
| 7759 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7760 | template <typename Derived> |
| Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 7761 | ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 7762 | MSPropertySubscriptExpr *E) { |
| 7763 | auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 7764 | if (BaseRes.isInvalid()) |
| 7765 | return ExprError(); |
| 7766 | auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 7767 | if (IdxRes.isInvalid()) |
| 7768 | return ExprError(); |
| 7769 | |
| 7770 | if (!getDerived().AlwaysRebuild() && |
| 7771 | BaseRes.get() == E->getBase() && |
| 7772 | IdxRes.get() == E->getIdx()) |
| 7773 | return E; |
| 7774 | |
| 7775 | return getDerived().RebuildArraySubscriptExpr( |
| 7776 | BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 7777 | } |
| 7778 | |
| 7779 | template <typename Derived> |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7780 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7781 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7782 | if (TryBlock.isInvalid()) |
| 7783 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7784 | |
| 7785 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7786 | if (Handler.isInvalid()) |
| 7787 | return StmtError(); |
| 7788 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7789 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 7790 | Handler.get() == S->getHandler()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7791 | return S; |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7792 | |
| Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 7793 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 7794 | TryBlock.get(), Handler.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7795 | } |
| 7796 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7797 | template <typename Derived> |
| 7798 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7799 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7800 | if (Block.isInvalid()) |
| 7801 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7802 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7803 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7804 | } |
| 7805 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7806 | template <typename Derived> |
| 7807 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7808 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7809 | if (FilterExpr.isInvalid()) |
| 7810 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7811 | |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7812 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7813 | if (Block.isInvalid()) |
| 7814 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7815 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7816 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 7817 | Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7818 | } |
| 7819 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7820 | template <typename Derived> |
| 7821 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 7822 | if (isa<SEHFinallyStmt>(Handler)) |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7823 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 7824 | else |
| 7825 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 7826 | } |
| 7827 | |
| Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 7828 | template<typename Derived> |
| 7829 | StmtResult |
| 7830 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 7831 | return S; |
| 7832 | } |
| 7833 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7834 | //===----------------------------------------------------------------------===// |
| 7835 | // OpenMP directive transformation |
| 7836 | //===----------------------------------------------------------------------===// |
| 7837 | template <typename Derived> |
| 7838 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 7839 | OMPExecutableDirective *D) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7840 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7841 | // Transform the clauses |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7842 | llvm::SmallVector<OMPClause *, 16> TClauses; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7843 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 7844 | TClauses.reserve(Clauses.size()); |
| 7845 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 7846 | I != E; ++I) { |
| 7847 | if (*I) { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7848 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7849 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7850 | getDerived().getSema().EndOpenMPClause(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7851 | if (Clause) |
| 7852 | TClauses.push_back(Clause); |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7853 | } else { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 7854 | TClauses.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7855 | } |
| 7856 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7857 | StmtResult AssociatedStmt; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 7858 | if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7859 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 7860 | /*CurScope=*/nullptr); |
| 7861 | StmtResult Body; |
| 7862 | { |
| 7863 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| Alexey Bataev | 475a744 | 2018-01-12 19:39:11 +0000 | [diff] [blame] | 7864 | Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt(); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 7865 | Body = getDerived().TransformStmt(CS); |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7866 | } |
| 7867 | AssociatedStmt = |
| 7868 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7869 | if (AssociatedStmt.isInvalid()) { |
| 7870 | return StmtError(); |
| 7871 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7872 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7873 | if (TClauses.size() != Clauses.size()) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7874 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7875 | } |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7876 | |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7877 | // Transform directive name for 'omp critical' directive. |
| 7878 | DeclarationNameInfo DirName; |
| 7879 | if (D->getDirectiveKind() == OMPD_critical) { |
| 7880 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 7881 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 7882 | } |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7883 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 7884 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 7885 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7886 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 7887 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7888 | } |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7889 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7890 | return getDerived().RebuildOMPExecutableDirective( |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7891 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7892 | AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7893 | } |
| 7894 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7895 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7896 | StmtResult |
| 7897 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 7898 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7899 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7900 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7901 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7902 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7903 | return Res; |
| 7904 | } |
| 7905 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7906 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7907 | StmtResult |
| 7908 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 7909 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7910 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7911 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7912 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7913 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7914 | return Res; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7915 | } |
| 7916 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7917 | template <typename Derived> |
| 7918 | StmtResult |
| 7919 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 7920 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7921 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7922 | D->getBeginLoc()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7923 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7924 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7925 | return Res; |
| 7926 | } |
| 7927 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7928 | template <typename Derived> |
| 7929 | StmtResult |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7930 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 7931 | DeclarationNameInfo DirName; |
| 7932 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7933 | D->getBeginLoc()); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7934 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7935 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7936 | return Res; |
| 7937 | } |
| 7938 | |
| 7939 | template <typename Derived> |
| 7940 | StmtResult |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7941 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 7942 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7943 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7944 | D->getBeginLoc()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7945 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7946 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7947 | return Res; |
| 7948 | } |
| 7949 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7950 | template <typename Derived> |
| 7951 | StmtResult |
| 7952 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 7953 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7954 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7955 | D->getBeginLoc()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7956 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7957 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7958 | return Res; |
| 7959 | } |
| 7960 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7961 | template <typename Derived> |
| 7962 | StmtResult |
| 7963 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 7964 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7965 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7966 | D->getBeginLoc()); |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7967 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7968 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7969 | return Res; |
| 7970 | } |
| 7971 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7972 | template <typename Derived> |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7973 | StmtResult |
| 7974 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 7975 | DeclarationNameInfo DirName; |
| 7976 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7977 | D->getBeginLoc()); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7978 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7979 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7980 | return Res; |
| 7981 | } |
| 7982 | |
| 7983 | template <typename Derived> |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7984 | StmtResult |
| 7985 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 7986 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7987 | OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7988 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7989 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7990 | return Res; |
| 7991 | } |
| 7992 | |
| 7993 | template <typename Derived> |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7994 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7995 | OMPParallelForDirective *D) { |
| 7996 | DeclarationNameInfo DirName; |
| 7997 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7998 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7999 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8000 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8001 | return Res; |
| 8002 | } |
| 8003 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8004 | template <typename Derived> |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8005 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 8006 | OMPParallelForSimdDirective *D) { |
| 8007 | DeclarationNameInfo DirName; |
| 8008 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8009 | nullptr, D->getBeginLoc()); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 8010 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8011 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8012 | return Res; |
| 8013 | } |
| 8014 | |
| 8015 | template <typename Derived> |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8016 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 8017 | OMPParallelSectionsDirective *D) { |
| 8018 | DeclarationNameInfo DirName; |
| 8019 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8020 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8021 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8022 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8023 | return Res; |
| 8024 | } |
| 8025 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8026 | template <typename Derived> |
| 8027 | StmtResult |
| 8028 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 8029 | DeclarationNameInfo DirName; |
| 8030 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8031 | D->getBeginLoc()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8032 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8033 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8034 | return Res; |
| 8035 | } |
| 8036 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 8037 | template <typename Derived> |
| 8038 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 8039 | OMPTaskyieldDirective *D) { |
| 8040 | DeclarationNameInfo DirName; |
| 8041 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8042 | D->getBeginLoc()); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 8043 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8044 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8045 | return Res; |
| 8046 | } |
| 8047 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 8048 | template <typename Derived> |
| 8049 | StmtResult |
| 8050 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 8051 | DeclarationNameInfo DirName; |
| 8052 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8053 | D->getBeginLoc()); |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 8054 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8055 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8056 | return Res; |
| 8057 | } |
| 8058 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 8059 | template <typename Derived> |
| 8060 | StmtResult |
| 8061 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 8062 | DeclarationNameInfo DirName; |
| 8063 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8064 | D->getBeginLoc()); |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 8065 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8066 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8067 | return Res; |
| 8068 | } |
| 8069 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8070 | template <typename Derived> |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8071 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 8072 | OMPTaskgroupDirective *D) { |
| 8073 | DeclarationNameInfo DirName; |
| 8074 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8075 | D->getBeginLoc()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8076 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8077 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8078 | return Res; |
| 8079 | } |
| 8080 | |
| 8081 | template <typename Derived> |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8082 | StmtResult |
| 8083 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 8084 | DeclarationNameInfo DirName; |
| 8085 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8086 | D->getBeginLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8087 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8088 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8089 | return Res; |
| 8090 | } |
| 8091 | |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8092 | template <typename Derived> |
| 8093 | StmtResult |
| 8094 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 8095 | DeclarationNameInfo DirName; |
| 8096 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8097 | D->getBeginLoc()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8098 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8099 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8100 | return Res; |
| 8101 | } |
| 8102 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8103 | template <typename Derived> |
| 8104 | StmtResult |
| 8105 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 8106 | DeclarationNameInfo DirName; |
| 8107 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8108 | D->getBeginLoc()); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8109 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8110 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8111 | return Res; |
| 8112 | } |
| 8113 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 8114 | template <typename Derived> |
| 8115 | StmtResult |
| 8116 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 8117 | DeclarationNameInfo DirName; |
| 8118 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8119 | D->getBeginLoc()); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 8120 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8121 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8122 | return Res; |
| 8123 | } |
| 8124 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8125 | template <typename Derived> |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 8126 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 8127 | OMPTargetDataDirective *D) { |
| 8128 | DeclarationNameInfo DirName; |
| 8129 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8130 | D->getBeginLoc()); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 8131 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8132 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8133 | return Res; |
| 8134 | } |
| 8135 | |
| 8136 | template <typename Derived> |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8137 | StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 8138 | OMPTargetEnterDataDirective *D) { |
| 8139 | DeclarationNameInfo DirName; |
| 8140 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8141 | nullptr, D->getBeginLoc()); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8142 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8143 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8144 | return Res; |
| 8145 | } |
| 8146 | |
| 8147 | template <typename Derived> |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8148 | StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 8149 | OMPTargetExitDataDirective *D) { |
| 8150 | DeclarationNameInfo DirName; |
| 8151 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8152 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8153 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8154 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8155 | return Res; |
| 8156 | } |
| 8157 | |
| 8158 | template <typename Derived> |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 8159 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 8160 | OMPTargetParallelDirective *D) { |
| 8161 | DeclarationNameInfo DirName; |
| 8162 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8163 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 8164 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8165 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8166 | return Res; |
| 8167 | } |
| 8168 | |
| 8169 | template <typename Derived> |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 8170 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 8171 | OMPTargetParallelForDirective *D) { |
| 8172 | DeclarationNameInfo DirName; |
| 8173 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8174 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 8175 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8176 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8177 | return Res; |
| 8178 | } |
| 8179 | |
| 8180 | template <typename Derived> |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 8181 | StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 8182 | OMPTargetUpdateDirective *D) { |
| 8183 | DeclarationNameInfo DirName; |
| 8184 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8185 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 8186 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8187 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8188 | return Res; |
| 8189 | } |
| 8190 | |
| 8191 | template <typename Derived> |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8192 | StmtResult |
| 8193 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 8194 | DeclarationNameInfo DirName; |
| 8195 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8196 | D->getBeginLoc()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8197 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8198 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8199 | return Res; |
| 8200 | } |
| 8201 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8202 | template <typename Derived> |
| 8203 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 8204 | OMPCancellationPointDirective *D) { |
| 8205 | DeclarationNameInfo DirName; |
| 8206 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8207 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8208 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8209 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8210 | return Res; |
| 8211 | } |
| 8212 | |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8213 | template <typename Derived> |
| 8214 | StmtResult |
| 8215 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 8216 | DeclarationNameInfo DirName; |
| 8217 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8218 | D->getBeginLoc()); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8219 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8220 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8221 | return Res; |
| 8222 | } |
| 8223 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8224 | template <typename Derived> |
| 8225 | StmtResult |
| 8226 | TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 8227 | DeclarationNameInfo DirName; |
| 8228 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8229 | D->getBeginLoc()); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8230 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8231 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8232 | return Res; |
| 8233 | } |
| 8234 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8235 | template <typename Derived> |
| 8236 | StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 8237 | OMPTaskLoopSimdDirective *D) { |
| 8238 | DeclarationNameInfo DirName; |
| 8239 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8240 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8241 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8242 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8243 | return Res; |
| 8244 | } |
| 8245 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8246 | template <typename Derived> |
| 8247 | StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 8248 | OMPDistributeDirective *D) { |
| 8249 | DeclarationNameInfo DirName; |
| 8250 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8251 | D->getBeginLoc()); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8252 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8253 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8254 | return Res; |
| 8255 | } |
| 8256 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8257 | template <typename Derived> |
| 8258 | StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 8259 | OMPDistributeParallelForDirective *D) { |
| 8260 | DeclarationNameInfo DirName; |
| 8261 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8262 | OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8263 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8264 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8265 | return Res; |
| 8266 | } |
| 8267 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8268 | template <typename Derived> |
| 8269 | StmtResult |
| 8270 | TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 8271 | OMPDistributeParallelForSimdDirective *D) { |
| 8272 | DeclarationNameInfo DirName; |
| 8273 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8274 | OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8275 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8276 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8277 | return Res; |
| 8278 | } |
| 8279 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8280 | template <typename Derived> |
| 8281 | StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( |
| 8282 | OMPDistributeSimdDirective *D) { |
| 8283 | DeclarationNameInfo DirName; |
| 8284 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8285 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8286 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8287 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8288 | return Res; |
| 8289 | } |
| 8290 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8291 | template <typename Derived> |
| 8292 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( |
| 8293 | OMPTargetParallelForSimdDirective *D) { |
| 8294 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8295 | getDerived().getSema().StartOpenMPDSABlock( |
| 8296 | OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8297 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8298 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8299 | return Res; |
| 8300 | } |
| 8301 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8302 | template <typename Derived> |
| 8303 | StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( |
| 8304 | OMPTargetSimdDirective *D) { |
| 8305 | DeclarationNameInfo DirName; |
| 8306 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8307 | D->getBeginLoc()); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8308 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8309 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8310 | return Res; |
| 8311 | } |
| 8312 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8313 | template <typename Derived> |
| 8314 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( |
| 8315 | OMPTeamsDistributeDirective *D) { |
| 8316 | DeclarationNameInfo DirName; |
| 8317 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8318 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8319 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8320 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8321 | return Res; |
| 8322 | } |
| 8323 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8324 | template <typename Derived> |
| 8325 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( |
| 8326 | OMPTeamsDistributeSimdDirective *D) { |
| 8327 | DeclarationNameInfo DirName; |
| 8328 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8329 | OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8330 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8331 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8332 | return Res; |
| 8333 | } |
| 8334 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8335 | template <typename Derived> |
| 8336 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( |
| 8337 | OMPTeamsDistributeParallelForSimdDirective *D) { |
| 8338 | DeclarationNameInfo DirName; |
| 8339 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8340 | OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 8341 | D->getBeginLoc()); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8342 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8343 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8344 | return Res; |
| 8345 | } |
| 8346 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8347 | template <typename Derived> |
| 8348 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( |
| 8349 | OMPTeamsDistributeParallelForDirective *D) { |
| 8350 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8351 | getDerived().getSema().StartOpenMPDSABlock( |
| 8352 | OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8353 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8354 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8355 | return Res; |
| 8356 | } |
| 8357 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8358 | template <typename Derived> |
| 8359 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( |
| 8360 | OMPTargetTeamsDirective *D) { |
| 8361 | DeclarationNameInfo DirName; |
| 8362 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8363 | nullptr, D->getBeginLoc()); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8364 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8365 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8366 | return Res; |
| 8367 | } |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8368 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8369 | template <typename Derived> |
| 8370 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( |
| 8371 | OMPTargetTeamsDistributeDirective *D) { |
| 8372 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8373 | getDerived().getSema().StartOpenMPDSABlock( |
| 8374 | OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8375 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8376 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8377 | return Res; |
| 8378 | } |
| 8379 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8380 | template <typename Derived> |
| 8381 | StmtResult |
| 8382 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( |
| 8383 | OMPTargetTeamsDistributeParallelForDirective *D) { |
| 8384 | DeclarationNameInfo DirName; |
| 8385 | getDerived().getSema().StartOpenMPDSABlock( |
| 8386 | OMPD_target_teams_distribute_parallel_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8387 | D->getBeginLoc()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8388 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8389 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8390 | return Res; |
| 8391 | } |
| 8392 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8393 | template <typename Derived> |
| 8394 | StmtResult TreeTransform<Derived>:: |
| 8395 | TransformOMPTargetTeamsDistributeParallelForSimdDirective( |
| 8396 | OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 8397 | DeclarationNameInfo DirName; |
| 8398 | getDerived().getSema().StartOpenMPDSABlock( |
| 8399 | OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8400 | D->getBeginLoc()); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8401 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8402 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8403 | return Res; |
| 8404 | } |
| 8405 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8406 | template <typename Derived> |
| 8407 | StmtResult |
| 8408 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( |
| 8409 | OMPTargetTeamsDistributeSimdDirective *D) { |
| 8410 | DeclarationNameInfo DirName; |
| 8411 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8412 | OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8413 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8414 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8415 | return Res; |
| 8416 | } |
| 8417 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8418 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8419 | //===----------------------------------------------------------------------===// |
| 8420 | // OpenMP clause transformation |
| 8421 | //===----------------------------------------------------------------------===// |
| 8422 | template <typename Derived> |
| 8423 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 8424 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8425 | if (Cond.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8426 | return nullptr; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8427 | return getDerived().RebuildOMPIfClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8428 | C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8429 | C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8430 | } |
| 8431 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8432 | template <typename Derived> |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8433 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 8434 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8435 | if (Cond.isInvalid()) |
| 8436 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8437 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8438 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8439 | } |
| 8440 | |
| 8441 | template <typename Derived> |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8442 | OMPClause * |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8443 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 8444 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 8445 | if (NumThreads.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8446 | return nullptr; |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8447 | return getDerived().RebuildOMPNumThreadsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8448 | NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8449 | } |
| 8450 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8451 | template <typename Derived> |
| 8452 | OMPClause * |
| 8453 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 8454 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 8455 | if (E.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8456 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8457 | return getDerived().RebuildOMPSafelenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8458 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8459 | } |
| 8460 | |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8461 | template <typename Derived> |
| 8462 | OMPClause * |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 8463 | TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { |
| 8464 | ExprResult E = getDerived().TransformExpr(C->getAllocator()); |
| 8465 | if (E.isInvalid()) |
| 8466 | return nullptr; |
| 8467 | return getDerived().RebuildOMPAllocatorClause( |
| 8468 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 8469 | } |
| 8470 | |
| 8471 | template <typename Derived> |
| 8472 | OMPClause * |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8473 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 8474 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 8475 | if (E.isInvalid()) |
| 8476 | return nullptr; |
| 8477 | return getDerived().RebuildOMPSimdlenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8478 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8479 | } |
| 8480 | |
| 8481 | template <typename Derived> |
| 8482 | OMPClause * |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8483 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 8484 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 8485 | if (E.isInvalid()) |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 8486 | return nullptr; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8487 | return getDerived().RebuildOMPCollapseClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8488 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8489 | } |
| 8490 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8491 | template <typename Derived> |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8492 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8493 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8494 | return getDerived().RebuildOMPDefaultClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8495 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8496 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8497 | } |
| 8498 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8499 | template <typename Derived> |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8500 | OMPClause * |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8501 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8502 | return getDerived().RebuildOMPProcBindClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8503 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8504 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8505 | } |
| 8506 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8507 | template <typename Derived> |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8508 | OMPClause * |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8509 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 8510 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 8511 | if (E.isInvalid()) |
| 8512 | return nullptr; |
| 8513 | return getDerived().RebuildOMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8514 | C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8515 | C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8516 | C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8517 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | template <typename Derived> |
| 8521 | OMPClause * |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8522 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8523 | ExprResult E; |
| 8524 | if (auto *Num = C->getNumForLoops()) { |
| 8525 | E = getDerived().TransformExpr(Num); |
| 8526 | if (E.isInvalid()) |
| 8527 | return nullptr; |
| 8528 | } |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8529 | return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8530 | C->getLParenLoc(), E.get()); |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | template <typename Derived> |
| 8534 | OMPClause * |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8535 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 8536 | // No need to rebuild this clause, no template-dependent parameters. |
| 8537 | return C; |
| 8538 | } |
| 8539 | |
| 8540 | template <typename Derived> |
| 8541 | OMPClause * |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8542 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 8543 | // No need to rebuild this clause, no template-dependent parameters. |
| 8544 | return C; |
| 8545 | } |
| 8546 | |
| 8547 | template <typename Derived> |
| 8548 | OMPClause * |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8549 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 8550 | // No need to rebuild this clause, no template-dependent parameters. |
| 8551 | return C; |
| 8552 | } |
| 8553 | |
| 8554 | template <typename Derived> |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8555 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 8556 | // No need to rebuild this clause, no template-dependent parameters. |
| 8557 | return C; |
| 8558 | } |
| 8559 | |
| 8560 | template <typename Derived> |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8561 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 8562 | // No need to rebuild this clause, no template-dependent parameters. |
| 8563 | return C; |
| 8564 | } |
| 8565 | |
| 8566 | template <typename Derived> |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8567 | OMPClause * |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8568 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 8569 | // No need to rebuild this clause, no template-dependent parameters. |
| 8570 | return C; |
| 8571 | } |
| 8572 | |
| 8573 | template <typename Derived> |
| 8574 | OMPClause * |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8575 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 8576 | // No need to rebuild this clause, no template-dependent parameters. |
| 8577 | return C; |
| 8578 | } |
| 8579 | |
| 8580 | template <typename Derived> |
| 8581 | OMPClause * |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8582 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 8583 | // No need to rebuild this clause, no template-dependent parameters. |
| 8584 | return C; |
| 8585 | } |
| 8586 | |
| 8587 | template <typename Derived> |
| 8588 | OMPClause * |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8589 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 8590 | // No need to rebuild this clause, no template-dependent parameters. |
| 8591 | return C; |
| 8592 | } |
| 8593 | |
| 8594 | template <typename Derived> |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8595 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 8596 | // No need to rebuild this clause, no template-dependent parameters. |
| 8597 | return C; |
| 8598 | } |
| 8599 | |
| 8600 | template <typename Derived> |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8601 | OMPClause * |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8602 | TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 8603 | // No need to rebuild this clause, no template-dependent parameters. |
| 8604 | return C; |
| 8605 | } |
| 8606 | |
| 8607 | template <typename Derived> |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8608 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( |
| 8609 | OMPUnifiedAddressClause *C) { |
| Patrick Lyster | e653b63 | 2018-09-27 19:30:32 +0000 | [diff] [blame] | 8610 | llvm_unreachable("unified_address clause cannot appear in dependent context"); |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8611 | } |
| 8612 | |
| 8613 | template <typename Derived> |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 8614 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( |
| 8615 | OMPUnifiedSharedMemoryClause *C) { |
| 8616 | llvm_unreachable( |
| 8617 | "unified_shared_memory clause cannot appear in dependent context"); |
| 8618 | } |
| 8619 | |
| 8620 | template <typename Derived> |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 8621 | OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( |
| 8622 | OMPReverseOffloadClause *C) { |
| 8623 | llvm_unreachable("reverse_offload clause cannot appear in dependent context"); |
| 8624 | } |
| 8625 | |
| 8626 | template <typename Derived> |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 8627 | OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( |
| 8628 | OMPDynamicAllocatorsClause *C) { |
| 8629 | llvm_unreachable( |
| 8630 | "dynamic_allocators clause cannot appear in dependent context"); |
| 8631 | } |
| 8632 | |
| 8633 | template <typename Derived> |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 8634 | OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( |
| 8635 | OMPAtomicDefaultMemOrderClause *C) { |
| 8636 | llvm_unreachable( |
| 8637 | "atomic_default_mem_order clause cannot appear in dependent context"); |
| 8638 | } |
| 8639 | |
| 8640 | template <typename Derived> |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8641 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8642 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8643 | llvm::SmallVector<Expr *, 16> Vars; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8644 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8645 | for (auto *VE : C->varlists()) { |
| 8646 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8647 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8648 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8649 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8650 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8651 | return getDerived().RebuildOMPPrivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8652 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8653 | } |
| 8654 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8655 | template <typename Derived> |
| 8656 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 8657 | OMPFirstprivateClause *C) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8658 | llvm::SmallVector<Expr *, 16> Vars; |
| 8659 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8660 | for (auto *VE : C->varlists()) { |
| 8661 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8662 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8663 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8664 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8665 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8666 | return getDerived().RebuildOMPFirstprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8667 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8668 | } |
| 8669 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8670 | template <typename Derived> |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8671 | OMPClause * |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8672 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 8673 | llvm::SmallVector<Expr *, 16> Vars; |
| 8674 | Vars.reserve(C->varlist_size()); |
| 8675 | for (auto *VE : C->varlists()) { |
| 8676 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8677 | if (EVar.isInvalid()) |
| 8678 | return nullptr; |
| 8679 | Vars.push_back(EVar.get()); |
| 8680 | } |
| 8681 | return getDerived().RebuildOMPLastprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8682 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8683 | } |
| 8684 | |
| 8685 | template <typename Derived> |
| 8686 | OMPClause * |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8687 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 8688 | llvm::SmallVector<Expr *, 16> Vars; |
| 8689 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8690 | for (auto *VE : C->varlists()) { |
| 8691 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8692 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8693 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8694 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8695 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8696 | return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8697 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8698 | } |
| 8699 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8700 | template <typename Derived> |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8701 | OMPClause * |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8702 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 8703 | llvm::SmallVector<Expr *, 16> Vars; |
| 8704 | Vars.reserve(C->varlist_size()); |
| 8705 | for (auto *VE : C->varlists()) { |
| 8706 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8707 | if (EVar.isInvalid()) |
| 8708 | return nullptr; |
| 8709 | Vars.push_back(EVar.get()); |
| 8710 | } |
| 8711 | CXXScopeSpec ReductionIdScopeSpec; |
| 8712 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8713 | |
| 8714 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8715 | if (NameInfo.getName()) { |
| 8716 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8717 | if (!NameInfo.getName()) |
| 8718 | return nullptr; |
| 8719 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8720 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8721 | // The Scope boundary is a duplication of the previous decl. |
| 8722 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8723 | for (auto *E : C->reduction_ops()) { |
| 8724 | // Transform all the decls. |
| 8725 | if (E) { |
| 8726 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8727 | UnresolvedSet<8> Decls; |
| 8728 | for (auto *D : ULE->decls()) { |
| 8729 | NamedDecl *InstD = |
| 8730 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8731 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8732 | } |
| 8733 | UnresolvedReductions.push_back( |
| 8734 | UnresolvedLookupExpr::Create( |
| 8735 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8736 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), |
| 8737 | NameInfo, /*ADL=*/true, ULE->isOverloaded(), |
| 8738 | Decls.begin(), Decls.end())); |
| 8739 | } else |
| 8740 | UnresolvedReductions.push_back(nullptr); |
| 8741 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8742 | return getDerived().RebuildOMPReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8743 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8744 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8745 | } |
| 8746 | |
| 8747 | template <typename Derived> |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8748 | OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( |
| 8749 | OMPTaskReductionClause *C) { |
| 8750 | llvm::SmallVector<Expr *, 16> Vars; |
| 8751 | Vars.reserve(C->varlist_size()); |
| 8752 | for (auto *VE : C->varlists()) { |
| 8753 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8754 | if (EVar.isInvalid()) |
| 8755 | return nullptr; |
| 8756 | Vars.push_back(EVar.get()); |
| 8757 | } |
| 8758 | CXXScopeSpec ReductionIdScopeSpec; |
| 8759 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8760 | |
| 8761 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8762 | if (NameInfo.getName()) { |
| 8763 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8764 | if (!NameInfo.getName()) |
| 8765 | return nullptr; |
| 8766 | } |
| 8767 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8768 | // The Scope boundary is a duplication of the previous decl. |
| 8769 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8770 | for (auto *E : C->reduction_ops()) { |
| 8771 | // Transform all the decls. |
| 8772 | if (E) { |
| 8773 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8774 | UnresolvedSet<8> Decls; |
| 8775 | for (auto *D : ULE->decls()) { |
| 8776 | NamedDecl *InstD = |
| 8777 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8778 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8779 | } |
| 8780 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8781 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8782 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8783 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8784 | } else |
| 8785 | UnresolvedReductions.push_back(nullptr); |
| 8786 | } |
| 8787 | return getDerived().RebuildOMPTaskReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8788 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8789 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
| 8792 | template <typename Derived> |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8793 | OMPClause * |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8794 | TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { |
| 8795 | llvm::SmallVector<Expr *, 16> Vars; |
| 8796 | Vars.reserve(C->varlist_size()); |
| 8797 | for (auto *VE : C->varlists()) { |
| 8798 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8799 | if (EVar.isInvalid()) |
| 8800 | return nullptr; |
| 8801 | Vars.push_back(EVar.get()); |
| 8802 | } |
| 8803 | CXXScopeSpec ReductionIdScopeSpec; |
| 8804 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8805 | |
| 8806 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8807 | if (NameInfo.getName()) { |
| 8808 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8809 | if (!NameInfo.getName()) |
| 8810 | return nullptr; |
| 8811 | } |
| 8812 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8813 | // The Scope boundary is a duplication of the previous decl. |
| 8814 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8815 | for (auto *E : C->reduction_ops()) { |
| 8816 | // Transform all the decls. |
| 8817 | if (E) { |
| 8818 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8819 | UnresolvedSet<8> Decls; |
| 8820 | for (auto *D : ULE->decls()) { |
| 8821 | NamedDecl *InstD = |
| 8822 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8823 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8824 | } |
| 8825 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8826 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8827 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8828 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8829 | } else |
| 8830 | UnresolvedReductions.push_back(nullptr); |
| 8831 | } |
| 8832 | return getDerived().RebuildOMPInReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8833 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8834 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8835 | } |
| 8836 | |
| 8837 | template <typename Derived> |
| 8838 | OMPClause * |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8839 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 8840 | llvm::SmallVector<Expr *, 16> Vars; |
| 8841 | Vars.reserve(C->varlist_size()); |
| 8842 | for (auto *VE : C->varlists()) { |
| 8843 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8844 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8845 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8846 | Vars.push_back(EVar.get()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8847 | } |
| 8848 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 8849 | if (Step.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8850 | return nullptr; |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8851 | return getDerived().RebuildOMPLinearClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8852 | Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8853 | C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8854 | } |
| 8855 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8856 | template <typename Derived> |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8857 | OMPClause * |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8858 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 8859 | llvm::SmallVector<Expr *, 16> Vars; |
| 8860 | Vars.reserve(C->varlist_size()); |
| 8861 | for (auto *VE : C->varlists()) { |
| 8862 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8863 | if (EVar.isInvalid()) |
| 8864 | return nullptr; |
| 8865 | Vars.push_back(EVar.get()); |
| 8866 | } |
| 8867 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 8868 | if (Alignment.isInvalid()) |
| 8869 | return nullptr; |
| 8870 | return getDerived().RebuildOMPAlignedClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8871 | Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8872 | C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8873 | } |
| 8874 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8875 | template <typename Derived> |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8876 | OMPClause * |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8877 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 8878 | llvm::SmallVector<Expr *, 16> Vars; |
| 8879 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8880 | for (auto *VE : C->varlists()) { |
| 8881 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8882 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8883 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8884 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8885 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8886 | return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8887 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8888 | } |
| 8889 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8890 | template <typename Derived> |
| 8891 | OMPClause * |
| 8892 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 8893 | llvm::SmallVector<Expr *, 16> Vars; |
| 8894 | Vars.reserve(C->varlist_size()); |
| 8895 | for (auto *VE : C->varlists()) { |
| 8896 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8897 | if (EVar.isInvalid()) |
| 8898 | return nullptr; |
| 8899 | Vars.push_back(EVar.get()); |
| 8900 | } |
| 8901 | return getDerived().RebuildOMPCopyprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8902 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8903 | } |
| 8904 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8905 | template <typename Derived> |
| 8906 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 8907 | llvm::SmallVector<Expr *, 16> Vars; |
| 8908 | Vars.reserve(C->varlist_size()); |
| 8909 | for (auto *VE : C->varlists()) { |
| 8910 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8911 | if (EVar.isInvalid()) |
| 8912 | return nullptr; |
| 8913 | Vars.push_back(EVar.get()); |
| 8914 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8915 | return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8916 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8917 | } |
| 8918 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8919 | template <typename Derived> |
| 8920 | OMPClause * |
| 8921 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 8922 | llvm::SmallVector<Expr *, 16> Vars; |
| 8923 | Vars.reserve(C->varlist_size()); |
| 8924 | for (auto *VE : C->varlists()) { |
| 8925 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8926 | if (EVar.isInvalid()) |
| 8927 | return nullptr; |
| 8928 | Vars.push_back(EVar.get()); |
| 8929 | } |
| 8930 | return getDerived().RebuildOMPDependClause( |
| 8931 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8932 | C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8933 | } |
| 8934 | |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8935 | template <typename Derived> |
| 8936 | OMPClause * |
| 8937 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 8938 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 8939 | if (E.isInvalid()) |
| 8940 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8941 | return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8942 | C->getLParenLoc(), C->getEndLoc()); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8943 | } |
| 8944 | |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8945 | template <typename Derived, class T> |
| 8946 | bool transformOMPMappableExprListClause( |
| 8947 | TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, |
| 8948 | llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, |
| 8949 | DeclarationNameInfo &MapperIdInfo, |
| 8950 | llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { |
| 8951 | // Transform expressions in the list. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8952 | Vars.reserve(C->varlist_size()); |
| 8953 | for (auto *VE : C->varlists()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8954 | ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8955 | if (EVar.isInvalid()) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8956 | return true; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8957 | Vars.push_back(EVar.get()); |
| 8958 | } |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8959 | // Transform mapper scope specifier and identifier. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8960 | NestedNameSpecifierLoc QualifierLoc; |
| 8961 | if (C->getMapperQualifierLoc()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8962 | QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8963 | C->getMapperQualifierLoc()); |
| 8964 | if (!QualifierLoc) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8965 | return true; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8966 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8967 | MapperIdScopeSpec.Adopt(QualifierLoc); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8968 | MapperIdInfo = C->getMapperIdInfo(); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8969 | if (MapperIdInfo.getName()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8970 | MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8971 | if (!MapperIdInfo.getName()) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8972 | return true; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8973 | } |
| 8974 | // Build a list of all candidate OMPDeclareMapperDecls, which is provided by |
| 8975 | // the previous user-defined mapper lookup in dependent environment. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8976 | for (auto *E : C->mapperlists()) { |
| 8977 | // Transform all the decls. |
| 8978 | if (E) { |
| 8979 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8980 | UnresolvedSet<8> Decls; |
| 8981 | for (auto *D : ULE->decls()) { |
| 8982 | NamedDecl *InstD = |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8983 | cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8984 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8985 | } |
| 8986 | UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8987 | TT.getSema().Context, /*NamingClass=*/nullptr, |
| 8988 | MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), |
| 8989 | MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), |
| 8990 | Decls.end())); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8991 | } else { |
| 8992 | UnresolvedMappers.push_back(nullptr); |
| 8993 | } |
| 8994 | } |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8995 | return false; |
| 8996 | } |
| 8997 | |
| 8998 | template <typename Derived> |
| 8999 | OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9000 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 9001 | llvm::SmallVector<Expr *, 16> Vars; |
| 9002 | CXXScopeSpec MapperIdScopeSpec; |
| 9003 | DeclarationNameInfo MapperIdInfo; |
| 9004 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9005 | if (transformOMPMappableExprListClause<Derived, OMPMapClause>( |
| 9006 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9007 | return nullptr; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9008 | return getDerived().RebuildOMPMapClause( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9009 | C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec, |
| 9010 | MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(), |
| 9011 | C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9012 | } |
| 9013 | |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9014 | template <typename Derived> |
| 9015 | OMPClause * |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 9016 | TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { |
| 9017 | Expr *Allocator = C->getAllocator(); |
| 9018 | if (Allocator) { |
| 9019 | ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); |
| 9020 | if (AllocatorRes.isInvalid()) |
| 9021 | return nullptr; |
| 9022 | Allocator = AllocatorRes.get(); |
| 9023 | } |
| 9024 | llvm::SmallVector<Expr *, 16> Vars; |
| 9025 | Vars.reserve(C->varlist_size()); |
| 9026 | for (auto *VE : C->varlists()) { |
| 9027 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9028 | if (EVar.isInvalid()) |
| 9029 | return nullptr; |
| 9030 | Vars.push_back(EVar.get()); |
| 9031 | } |
| 9032 | return getDerived().RebuildOMPAllocateClause( |
| 9033 | Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 9034 | C->getEndLoc()); |
| 9035 | } |
| 9036 | |
| 9037 | template <typename Derived> |
| 9038 | OMPClause * |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9039 | TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 9040 | ExprResult E = getDerived().TransformExpr(C->getNumTeams()); |
| 9041 | if (E.isInvalid()) |
| 9042 | return nullptr; |
| 9043 | return getDerived().RebuildOMPNumTeamsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9044 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9045 | } |
| 9046 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9047 | template <typename Derived> |
| 9048 | OMPClause * |
| 9049 | TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 9050 | ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); |
| 9051 | if (E.isInvalid()) |
| 9052 | return nullptr; |
| 9053 | return getDerived().RebuildOMPThreadLimitClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9054 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9055 | } |
| 9056 | |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9057 | template <typename Derived> |
| 9058 | OMPClause * |
| 9059 | TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 9060 | ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 9061 | if (E.isInvalid()) |
| 9062 | return nullptr; |
| 9063 | return getDerived().RebuildOMPPriorityClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9064 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9065 | } |
| 9066 | |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9067 | template <typename Derived> |
| 9068 | OMPClause * |
| 9069 | TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 9070 | ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 9071 | if (E.isInvalid()) |
| 9072 | return nullptr; |
| 9073 | return getDerived().RebuildOMPGrainsizeClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9074 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9075 | } |
| 9076 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9077 | template <typename Derived> |
| 9078 | OMPClause * |
| 9079 | TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 9080 | ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 9081 | if (E.isInvalid()) |
| 9082 | return nullptr; |
| 9083 | return getDerived().RebuildOMPNumTasksClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9084 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9085 | } |
| 9086 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9087 | template <typename Derived> |
| 9088 | OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 9089 | ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 9090 | if (E.isInvalid()) |
| 9091 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9092 | return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9093 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9094 | } |
| 9095 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9096 | template <typename Derived> |
| 9097 | OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 9098 | OMPDistScheduleClause *C) { |
| 9099 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 9100 | if (E.isInvalid()) |
| 9101 | return nullptr; |
| 9102 | return getDerived().RebuildOMPDistScheduleClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9103 | C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9104 | C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9105 | } |
| 9106 | |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9107 | template <typename Derived> |
| 9108 | OMPClause * |
| 9109 | TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 9110 | return C; |
| 9111 | } |
| 9112 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9113 | template <typename Derived> |
| 9114 | OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9115 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 9116 | llvm::SmallVector<Expr *, 16> Vars; |
| 9117 | CXXScopeSpec MapperIdScopeSpec; |
| 9118 | DeclarationNameInfo MapperIdInfo; |
| 9119 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9120 | if (transformOMPMappableExprListClause<Derived, OMPToClause>( |
| 9121 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9122 | return nullptr; |
| 9123 | return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo, |
| 9124 | Locs, UnresolvedMappers); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9125 | } |
| 9126 | |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9127 | template <typename Derived> |
| 9128 | OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9129 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 9130 | llvm::SmallVector<Expr *, 16> Vars; |
| 9131 | CXXScopeSpec MapperIdScopeSpec; |
| 9132 | DeclarationNameInfo MapperIdInfo; |
| 9133 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9134 | if (transformOMPMappableExprListClause<Derived, OMPFromClause>( |
| 9135 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9136 | return nullptr; |
| 9137 | return getDerived().RebuildOMPFromClause( |
| 9138 | Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9139 | } |
| 9140 | |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9141 | template <typename Derived> |
| 9142 | OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( |
| 9143 | OMPUseDevicePtrClause *C) { |
| 9144 | llvm::SmallVector<Expr *, 16> Vars; |
| 9145 | Vars.reserve(C->varlist_size()); |
| 9146 | for (auto *VE : C->varlists()) { |
| 9147 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9148 | if (EVar.isInvalid()) |
| 9149 | return nullptr; |
| 9150 | Vars.push_back(EVar.get()); |
| 9151 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9152 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9153 | return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9154 | } |
| 9155 | |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9156 | template <typename Derived> |
| 9157 | OMPClause * |
| 9158 | TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 9159 | llvm::SmallVector<Expr *, 16> Vars; |
| 9160 | Vars.reserve(C->varlist_size()); |
| 9161 | for (auto *VE : C->varlists()) { |
| 9162 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9163 | if (EVar.isInvalid()) |
| 9164 | return nullptr; |
| 9165 | Vars.push_back(EVar.get()); |
| 9166 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9167 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9168 | return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9169 | } |
| 9170 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9171 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9172 | // Expression transformation |
| 9173 | //===----------------------------------------------------------------------===// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9174 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9175 | ExprResult |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 9176 | TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { |
| 9177 | return TransformExpr(E->getSubExpr()); |
| 9178 | } |
| 9179 | |
| 9180 | template<typename Derived> |
| 9181 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9182 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 9183 | if (!E->isTypeDependent()) |
| 9184 | return E; |
| 9185 | |
| 9186 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 9187 | E->getIdentKind()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9188 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9189 | |
| 9190 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9191 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9192 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9193 | NestedNameSpecifierLoc QualifierLoc; |
| 9194 | if (E->getQualifierLoc()) { |
| 9195 | QualifierLoc |
| 9196 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9197 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9198 | return ExprError(); |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9199 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9200 | |
| 9201 | ValueDecl *ND |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9202 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 9203 | E->getDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9204 | if (!ND) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9205 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9206 | |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 9207 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 9208 | if (NameInfo.getName()) { |
| 9209 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9210 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9211 | return ExprError(); |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 9212 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9213 | |
| 9214 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9215 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9216 | ND == E->getDecl() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9217 | NameInfo.getName() == E->getDecl()->getDeclName() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9218 | !E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9219 | |
| 9220 | // Mark it referenced in the new context regardless. |
| 9221 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9222 | SemaRef.MarkDeclRefReferenced(E); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9223 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9224 | return E; |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9225 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9226 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9227 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9228 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9229 | TemplateArgs = &TransArgs; |
| 9230 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9231 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9232 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9233 | E->getNumTemplateArgs(), |
| 9234 | TransArgs)) |
| 9235 | return ExprError(); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9236 | } |
| 9237 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9238 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9239 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9240 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9241 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9242 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9243 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9244 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9245 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9246 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9247 | |
| Leonard Chan | db01c3a | 2018-06-20 17:19:40 +0000 | [diff] [blame] | 9248 | template <typename Derived> |
| 9249 | ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( |
| 9250 | FixedPointLiteral *E) { |
| 9251 | return E; |
| 9252 | } |
| 9253 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9254 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9255 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9256 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9257 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9258 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9259 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9260 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9261 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9262 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9263 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9264 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9265 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9266 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9267 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9268 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9269 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9270 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9271 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9272 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9273 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9274 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9275 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9276 | } |
| 9277 | |
| 9278 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9279 | ExprResult |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 9280 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 9281 | if (FunctionDecl *FD = E->getDirectCallee()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9282 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD); |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 9283 | return SemaRef.MaybeBindToTemporary(E); |
| 9284 | } |
| 9285 | |
| 9286 | template<typename Derived> |
| 9287 | ExprResult |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9288 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 9289 | ExprResult ControllingExpr = |
| 9290 | getDerived().TransformExpr(E->getControllingExpr()); |
| 9291 | if (ControllingExpr.isInvalid()) |
| 9292 | return ExprError(); |
| 9293 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9294 | SmallVector<Expr *, 4> AssocExprs; |
| 9295 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| Bruno Ricci | 1ec7fd3 | 2019-01-29 12:57:11 +0000 | [diff] [blame] | 9296 | for (const GenericSelectionExpr::Association &Assoc : E->associations()) { |
| 9297 | TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); |
| 9298 | if (TSI) { |
| 9299 | TypeSourceInfo *AssocType = getDerived().TransformType(TSI); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9300 | if (!AssocType) |
| 9301 | return ExprError(); |
| 9302 | AssocTypes.push_back(AssocType); |
| 9303 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9304 | AssocTypes.push_back(nullptr); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9305 | } |
| 9306 | |
| Bruno Ricci | 1ec7fd3 | 2019-01-29 12:57:11 +0000 | [diff] [blame] | 9307 | ExprResult AssocExpr = |
| 9308 | getDerived().TransformExpr(Assoc.getAssociationExpr()); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9309 | if (AssocExpr.isInvalid()) |
| 9310 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9311 | AssocExprs.push_back(AssocExpr.get()); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9312 | } |
| 9313 | |
| 9314 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 9315 | E->getDefaultLoc(), |
| 9316 | E->getRParenLoc(), |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9317 | ControllingExpr.get(), |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 9318 | AssocTypes, |
| 9319 | AssocExprs); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9320 | } |
| 9321 | |
| 9322 | template<typename Derived> |
| 9323 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9324 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9325 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9326 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9327 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9328 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9329 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9330 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9331 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9332 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9333 | E->getRParen()); |
| 9334 | } |
| 9335 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9336 | /// 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] | 9337 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 9338 | /// object available. |
| 9339 | template<typename Derived> |
| 9340 | ExprResult |
| 9341 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 9342 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9343 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9344 | else |
| 9345 | return getDerived().TransformExpr(E); |
| 9346 | } |
| 9347 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9348 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9349 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9350 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 9351 | ExprResult SubExpr; |
| 9352 | if (E->getOpcode() == UO_AddrOf) |
| 9353 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 9354 | else |
| 9355 | SubExpr = TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9356 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9357 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9358 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9359 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9360 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9361 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9362 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 9363 | E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9364 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9365 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9366 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9367 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9368 | ExprResult |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9369 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 9370 | // Transform the type. |
| 9371 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9372 | if (!Type) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9373 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9374 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9375 | // Transform all of the components into components similar to what the |
| 9376 | // parser uses. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9377 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 9378 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 9379 | // the fields again. However, __builtin_offsetof is rare enough in |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9380 | // template code that we don't care. |
| 9381 | bool ExprChanged = false; |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9382 | typedef Sema::OffsetOfComponent Component; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9383 | SmallVector<Component, 4> Components; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9384 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9385 | const OffsetOfNode &ON = E->getComponent(I); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9386 | Component Comp; |
| Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 9387 | Comp.isBrackets = true; |
| Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 9388 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 9389 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9390 | switch (ON.getKind()) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9391 | case OffsetOfNode::Array: { |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9392 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9393 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9394 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9395 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9396 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9397 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 9398 | Comp.isBrackets = true; |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9399 | Comp.U.E = Index.get(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9400 | break; |
| 9401 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9402 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9403 | case OffsetOfNode::Field: |
| 9404 | case OffsetOfNode::Identifier: |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9405 | Comp.isBrackets = false; |
| 9406 | Comp.U.IdentInfo = ON.getFieldName(); |
| Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 9407 | if (!Comp.U.IdentInfo) |
| 9408 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9409 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9410 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9411 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9412 | case OffsetOfNode::Base: |
| Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 9413 | // Will be recomputed during the rebuild. |
| 9414 | continue; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9415 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9416 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9417 | Components.push_back(Comp); |
| 9418 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9419 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9420 | // If nothing changed, retain the existing expression. |
| 9421 | if (!getDerived().AlwaysRebuild() && |
| 9422 | Type == E->getTypeSourceInfo() && |
| 9423 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9424 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9425 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9426 | // Build a new offsetof expression. |
| 9427 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 9428 | Components, E->getRParenLoc()); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9429 | } |
| 9430 | |
| 9431 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9432 | ExprResult |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9433 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| Hubert Tong | 2cded44 | 2015-09-01 22:50:31 +0000 | [diff] [blame] | 9434 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9435 | "opaque value expression requires transformation"); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9436 | return E; |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9437 | } |
| 9438 | |
| 9439 | template<typename Derived> |
| 9440 | ExprResult |
| Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 9441 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 9442 | return E; |
| 9443 | } |
| 9444 | |
| 9445 | template<typename Derived> |
| 9446 | ExprResult |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9447 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
| John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 9448 | // Rebuild the syntactic form. The original syntactic form has |
| 9449 | // opaque-value expressions in it, so strip those away and rebuild |
| 9450 | // the result. This is a really awful way of doing this, but the |
| 9451 | // better solution (rebuilding the semantic expressions and |
| 9452 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 9453 | // TreeTransform to not strip away implicit conversions. |
| 9454 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 9455 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9456 | if (result.isInvalid()) return ExprError(); |
| 9457 | |
| 9458 | // If that gives us a pseudo-object result back, the pseudo-object |
| 9459 | // expression must have been an lvalue-to-rvalue conversion which we |
| 9460 | // should reapply. |
| 9461 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9462 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9463 | |
| 9464 | return result; |
| 9465 | } |
| 9466 | |
| 9467 | template<typename Derived> |
| 9468 | ExprResult |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9469 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 9470 | UnaryExprOrTypeTraitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9471 | if (E->isArgumentType()) { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9472 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9473 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9474 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9475 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9476 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9477 | |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9478 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
| 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 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9481 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 9482 | E->getKind(), |
| 9483 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9484 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9485 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9486 | // C++0x [expr.sizeof]p1: |
| 9487 | // The operand is either an expression, which is an unevaluated operand |
| 9488 | // [...] |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 9489 | EnterExpressionEvaluationContext Unevaluated( |
| 9490 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 9491 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9492 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9493 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 9494 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 9495 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 9496 | ExprResult SubExpr; |
| 9497 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 9498 | if (auto *DRE = |
| 9499 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 9500 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 9501 | PE, DRE, false, &RecoveryTSI); |
| 9502 | else |
| 9503 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 9504 | |
| 9505 | if (RecoveryTSI) { |
| 9506 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 9507 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 9508 | } else if (SubExpr.isInvalid()) |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9509 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9510 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9511 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9512 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9513 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9514 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 9515 | E->getOperatorLoc(), |
| 9516 | E->getKind(), |
| 9517 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9518 | } |
| 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 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9521 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9522 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9523 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9524 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9525 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9526 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9527 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9528 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9529 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9530 | |
| 9531 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9532 | if (!getDerived().AlwaysRebuild() && |
| 9533 | LHS.get() == E->getLHS() && |
| 9534 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9535 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9536 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9537 | return getDerived().RebuildArraySubscriptExpr( |
| 9538 | LHS.get(), |
| 9539 | /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9540 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9541 | |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9542 | template <typename Derived> |
| 9543 | ExprResult |
| 9544 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 9545 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 9546 | if (Base.isInvalid()) |
| 9547 | return ExprError(); |
| 9548 | |
| 9549 | ExprResult LowerBound; |
| 9550 | if (E->getLowerBound()) { |
| 9551 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 9552 | if (LowerBound.isInvalid()) |
| 9553 | return ExprError(); |
| 9554 | } |
| 9555 | |
| 9556 | ExprResult Length; |
| 9557 | if (E->getLength()) { |
| 9558 | Length = getDerived().TransformExpr(E->getLength()); |
| 9559 | if (Length.isInvalid()) |
| 9560 | return ExprError(); |
| 9561 | } |
| 9562 | |
| 9563 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 9564 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 9565 | return E; |
| 9566 | |
| 9567 | return getDerived().RebuildOMPArraySectionExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9568 | Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(), |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9569 | Length.get(), E->getRBracketLoc()); |
| 9570 | } |
| 9571 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9572 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9573 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9574 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9575 | // Transform the callee. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9576 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9577 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9578 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9579 | |
| 9580 | // Transform arguments. |
| 9581 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9582 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9583 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9584 | &ArgChanged)) |
| 9585 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9586 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9587 | if (!getDerived().AlwaysRebuild() && |
| 9588 | Callee.get() == E->getCallee() && |
| 9589 | !ArgChanged) |
| Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 9590 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9591 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9592 | // FIXME: Wrong source location information for the '('. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9593 | SourceLocation FakeLParenLoc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9594 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9595 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9596 | Args, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9597 | E->getRParenLoc()); |
| 9598 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9599 | |
| 9600 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9601 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9602 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9603 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9604 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9605 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9606 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9607 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9608 | if (E->hasQualifier()) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9609 | QualifierLoc |
| 9610 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9611 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9612 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9613 | return ExprError(); |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9614 | } |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9615 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9616 | |
| Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 9617 | ValueDecl *Member |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9618 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 9619 | E->getMemberDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9620 | if (!Member) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9621 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9622 | |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9623 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 9624 | if (FoundDecl == E->getMemberDecl()) { |
| 9625 | FoundDecl = Member; |
| 9626 | } else { |
| 9627 | FoundDecl = cast_or_null<NamedDecl>( |
| 9628 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 9629 | if (!FoundDecl) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9630 | return ExprError(); |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9631 | } |
| 9632 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9633 | if (!getDerived().AlwaysRebuild() && |
| 9634 | Base.get() == E->getBase() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9635 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9636 | Member == E->getMemberDecl() && |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9637 | FoundDecl == E->getFoundDecl() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9638 | !E->hasExplicitTemplateArgs()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9639 | |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9640 | // Mark it referenced in the new context regardless. |
| 9641 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9642 | SemaRef.MarkMemberReferenced(E); |
| 9643 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9644 | return E; |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9645 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9646 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9647 | TemplateArgumentListInfo TransArgs; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9648 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9649 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9650 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9651 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9652 | E->getNumTemplateArgs(), |
| 9653 | TransArgs)) |
| 9654 | return ExprError(); |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9655 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9656 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9657 | // FIXME: Bogus source location for the operator |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9658 | SourceLocation FakeOperatorLoc = |
| 9659 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9660 | |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9661 | // FIXME: to do this check properly, we will need to preserve the |
| 9662 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9663 | // base (and therefore couldn't do the check) and a |
| 9664 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9665 | NamedDecl *FirstQualifierInScope = nullptr; |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9666 | DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); |
| 9667 | if (MemberNameInfo.getName()) { |
| 9668 | MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); |
| 9669 | if (!MemberNameInfo.getName()) |
| 9670 | return ExprError(); |
| 9671 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9672 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9673 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9674 | E->isArrow(), |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9675 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9676 | TemplateKWLoc, |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9677 | MemberNameInfo, |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9678 | Member, |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9679 | FoundDecl, |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9680 | (E->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9681 | ? &TransArgs : nullptr), |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9682 | FirstQualifierInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9683 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9684 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9685 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9686 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9687 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9688 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9689 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9690 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9691 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9692 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9693 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9694 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9695 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9696 | if (!getDerived().AlwaysRebuild() && |
| 9697 | LHS.get() == E->getLHS() && |
| 9698 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9699 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9700 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9701 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 9702 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9703 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9704 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9705 | LHS.get(), RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9706 | } |
| 9707 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9708 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9709 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9710 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9711 | CompoundAssignOperator *E) { |
| 9712 | return getDerived().TransformBinaryOperator(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9713 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9714 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9715 | template<typename Derived> |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9716 | ExprResult TreeTransform<Derived>:: |
| 9717 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 9718 | // Just rebuild the common and RHS expressions and see whether we |
| 9719 | // get any changes. |
| 9720 | |
| 9721 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 9722 | if (commonExpr.isInvalid()) |
| 9723 | return ExprError(); |
| 9724 | |
| 9725 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 9726 | if (rhs.isInvalid()) |
| 9727 | return ExprError(); |
| 9728 | |
| 9729 | if (!getDerived().AlwaysRebuild() && |
| 9730 | commonExpr.get() == e->getCommon() && |
| 9731 | rhs.get() == e->getFalseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9732 | return e; |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9733 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9734 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9735 | e->getQuestionLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9736 | nullptr, |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9737 | e->getColonLoc(), |
| 9738 | rhs.get()); |
| 9739 | } |
| 9740 | |
| 9741 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9742 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9743 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9744 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9745 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9746 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9747 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9748 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9749 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9750 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9751 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9752 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9753 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9754 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9755 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9756 | if (!getDerived().AlwaysRebuild() && |
| 9757 | Cond.get() == E->getCond() && |
| 9758 | LHS.get() == E->getLHS() && |
| 9759 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9760 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9761 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9762 | return getDerived().RebuildConditionalOperator(Cond.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9763 | E->getQuestionLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9764 | LHS.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9765 | E->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9766 | RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9767 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9768 | |
| 9769 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9770 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9771 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
| Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 9772 | // Implicit casts are eliminated during transformation, since they |
| 9773 | // will be recomputed by semantic analysis after transformation. |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9774 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9775 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9776 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9777 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9778 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9779 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9780 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9781 | if (!Type) |
| 9782 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9783 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9784 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9785 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9786 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9787 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9788 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9789 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9790 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9791 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9792 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9793 | |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 9794 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9795 | Type, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9796 | E->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9797 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9798 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9799 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9800 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9801 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9802 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9803 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 9804 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 9805 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9806 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9807 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9808 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9809 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9810 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9811 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9812 | if (!getDerived().AlwaysRebuild() && |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9813 | OldT == NewT && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9814 | Init.get() == E->getInitializer()) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9815 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9816 | |
| John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 9817 | // Note: the expression type doesn't necessarily match the |
| 9818 | // type-as-written, but that's okay, because it should always be |
| 9819 | // derivable from the initializer. |
| 9820 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9821 | return getDerived().RebuildCompoundLiteralExpr( |
| 9822 | E->getLParenLoc(), NewT, |
| 9823 | /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9824 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9825 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9826 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9827 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9828 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9829 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9830 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9831 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9832 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9833 | if (!getDerived().AlwaysRebuild() && |
| 9834 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9835 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9836 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9837 | // FIXME: Bad source location |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9838 | SourceLocation FakeOperatorLoc = |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9839 | SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9840 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9841 | E->getAccessorLoc(), |
| 9842 | E->getAccessor()); |
| 9843 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9844 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9845 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9846 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9847 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9848 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 9849 | E = Syntactic; |
| 9850 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9851 | bool InitChanged = false; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9852 | |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 9853 | EnterExpressionEvaluationContext Context( |
| 9854 | getSema(), EnterExpressionEvaluationContext::InitList); |
| 9855 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9856 | SmallVector<Expr*, 4> Inits; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9857 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9858 | Inits, &InitChanged)) |
| 9859 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9860 | |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9861 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 9862 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 9863 | // in some cases. We can't reuse it in general, because the syntactic and |
| 9864 | // semantic forms are linked, and we can't know that semantic form will |
| 9865 | // match even if the syntactic form does. |
| 9866 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9867 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9868 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 9869 | E->getRBraceLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9870 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9871 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9872 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9873 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9874 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9875 | Designation Desig; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9876 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9877 | // transform the initializer value |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9878 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9879 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9880 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9881 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9882 | // transform the designators. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9883 | SmallVector<Expr*, 4> ArrayExprs; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9884 | bool ExprChanged = false; |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9885 | for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 9886 | if (D.isFieldDesignator()) { |
| 9887 | Desig.AddDesignator(Designator::getField(D.getFieldName(), |
| 9888 | D.getDotLoc(), |
| 9889 | D.getFieldLoc())); |
| Alex Lorenz | cb642b9 | 2016-10-24 09:33:32 +0000 | [diff] [blame] | 9890 | if (D.getField()) { |
| 9891 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 9892 | getDerived().TransformDecl(D.getFieldLoc(), D.getField())); |
| 9893 | if (Field != D.getField()) |
| 9894 | // Rebuild the expression when the transformed FieldDecl is |
| 9895 | // different to the already assigned FieldDecl. |
| 9896 | ExprChanged = true; |
| 9897 | } else { |
| 9898 | // Ensure that the designator expression is rebuilt when there isn't |
| 9899 | // a resolved FieldDecl in the designator as we don't want to assign |
| 9900 | // a FieldDecl to a pattern designator that will be instantiated again. |
| 9901 | ExprChanged = true; |
| 9902 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9903 | continue; |
| 9904 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9905 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9906 | if (D.isArrayDesignator()) { |
| 9907 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9908 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9909 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9910 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9911 | Desig.AddDesignator( |
| 9912 | Designator::getArray(Index.get(), D.getLBracketLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9913 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9914 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9915 | ArrayExprs.push_back(Index.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9916 | continue; |
| 9917 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9918 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9919 | assert(D.isArrayRangeDesignator() && "New kind of designator?"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9920 | ExprResult Start |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9921 | = getDerived().TransformExpr(E->getArrayRangeStart(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9922 | if (Start.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9923 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9924 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9925 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9926 | if (End.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9927 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9928 | |
| 9929 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9930 | End.get(), |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9931 | D.getLBracketLoc(), |
| 9932 | D.getEllipsisLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9933 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9934 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 9935 | End.get() != E->getArrayRangeEnd(D); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9936 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9937 | ArrayExprs.push_back(Start.get()); |
| 9938 | ArrayExprs.push_back(End.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9939 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9940 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9941 | if (!getDerived().AlwaysRebuild() && |
| 9942 | Init.get() == E->getInit() && |
| 9943 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9944 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9945 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9946 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9947 | E->getEqualOrColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9948 | E->usesGNUSyntax(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9949 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9950 | |
| Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 9951 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 9952 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 9953 | template<typename Derived> |
| 9954 | ExprResult |
| 9955 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 9956 | DesignatedInitUpdateExpr *E) { |
| 9957 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 9958 | "initializer"); |
| 9959 | return ExprError(); |
| 9960 | } |
| 9961 | |
| 9962 | template<typename Derived> |
| 9963 | ExprResult |
| 9964 | TreeTransform<Derived>::TransformNoInitExpr( |
| 9965 | NoInitExpr *E) { |
| 9966 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 9967 | return ExprError(); |
| 9968 | } |
| 9969 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9970 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9971 | ExprResult |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 9972 | TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 9973 | llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); |
| 9974 | return ExprError(); |
| 9975 | } |
| 9976 | |
| 9977 | template<typename Derived> |
| 9978 | ExprResult |
| 9979 | TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 9980 | llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); |
| 9981 | return ExprError(); |
| 9982 | } |
| 9983 | |
| 9984 | template<typename Derived> |
| 9985 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9986 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9987 | ImplicitValueInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9988 | TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9989 | |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9990 | // FIXME: Will we ever have proper type location here? Will we actually |
| 9991 | // need to transform the type? |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9992 | QualType T = getDerived().TransformType(E->getType()); |
| 9993 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9994 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9995 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9996 | if (!getDerived().AlwaysRebuild() && |
| 9997 | T == E->getType()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9998 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9999 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10000 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 10001 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10002 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10003 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10004 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10005 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 10006 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 10007 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10008 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10009 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10010 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10011 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10012 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10013 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10014 | if (!getDerived().AlwaysRebuild() && |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 10015 | TInfo == E->getWrittenTypeInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10016 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10017 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10018 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10019 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 10020 | TInfo, E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10021 | } |
| 10022 | |
| 10023 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10024 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10025 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10026 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10027 | SmallVector<Expr*, 4> Inits; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10028 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 10029 | &ArgumentChanged)) |
| 10030 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10031 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10032 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10033 | Inits, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10034 | E->getRParenLoc()); |
| 10035 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10036 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10037 | /// Transform an address-of-label expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10038 | /// |
| 10039 | /// By default, the transformation of an address-of-label expression always |
| 10040 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 10041 | /// the corresponding label statement by semantic analysis. |
| 10042 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10043 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10044 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 10045 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 10046 | E->getLabel()); |
| 10047 | if (!LD) |
| 10048 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10049 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10050 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 10051 | cast<LabelDecl>(LD)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10052 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10053 | |
| 10054 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10055 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10056 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10057 | SemaRef.ActOnStartStmtExpr(); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10058 | StmtResult SubStmt |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10059 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10060 | if (SubStmt.isInvalid()) { |
| 10061 | SemaRef.ActOnStmtExprError(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10062 | return ExprError(); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +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 | if (!getDerived().AlwaysRebuild() && |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10066 | SubStmt.get() == E->getSubStmt()) { |
| 10067 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 10068 | SemaRef.ActOnStmtExprError(); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10069 | return SemaRef.MaybeBindToTemporary(E); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10070 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10071 | |
| 10072 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10073 | SubStmt.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10074 | E->getRParenLoc()); |
| 10075 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10076 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10077 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10078 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10079 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10080 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10081 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10082 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10083 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10084 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10085 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10086 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10087 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10088 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10089 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10090 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10091 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10092 | if (!getDerived().AlwaysRebuild() && |
| 10093 | Cond.get() == E->getCond() && |
| 10094 | LHS.get() == E->getLHS() && |
| 10095 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10096 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10097 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10098 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10099 | Cond.get(), LHS.get(), RHS.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10100 | E->getRParenLoc()); |
| 10101 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10102 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10103 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10104 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10105 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10106 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10107 | } |
| 10108 | |
| 10109 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10110 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10111 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10112 | switch (E->getOperator()) { |
| 10113 | case OO_New: |
| 10114 | case OO_Delete: |
| 10115 | case OO_Array_New: |
| 10116 | case OO_Array_Delete: |
| 10117 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10118 | |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10119 | case OO_Call: { |
| 10120 | // This is a call to an object's operator(). |
| 10121 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 10122 | |
| 10123 | // Transform the object itself. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10124 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10125 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10126 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10127 | |
| 10128 | // FIXME: Poor location information |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 10129 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10130 | static_cast<Expr *>(Object.get())->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10131 | |
| 10132 | // Transform the call arguments. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10133 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10134 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10135 | Args)) |
| 10136 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10137 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10138 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, |
| 10139 | E->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10140 | } |
| 10141 | |
| 10142 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 10143 | case OO_##Name: |
| 10144 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 10145 | #include "clang/Basic/OperatorKinds.def" |
| 10146 | case OO_Subscript: |
| 10147 | // Handled below. |
| 10148 | break; |
| 10149 | |
| 10150 | case OO_Conditional: |
| 10151 | llvm_unreachable("conditional operator is not actually overloadable"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10152 | |
| 10153 | case OO_None: |
| 10154 | case NUM_OVERLOADED_OPERATORS: |
| 10155 | llvm_unreachable("not an overloaded operator?"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10156 | } |
| 10157 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10158 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10159 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10160 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10161 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 10162 | ExprResult First; |
| 10163 | if (E->getOperator() == OO_Amp) |
| 10164 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 10165 | else |
| 10166 | First = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10167 | if (First.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10168 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10169 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10170 | ExprResult Second; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10171 | if (E->getNumArgs() == 2) { |
| 10172 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 10173 | if (Second.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10174 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10175 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10176 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10177 | if (!getDerived().AlwaysRebuild() && |
| 10178 | Callee.get() == E->getCallee() && |
| 10179 | First.get() == E->getArg(0) && |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10180 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10181 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10182 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 10183 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 10184 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 10185 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10186 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 10187 | E->getOperatorLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10188 | Callee.get(), |
| 10189 | First.get(), |
| 10190 | Second.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10191 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10192 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10193 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10194 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10195 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 10196 | return getDerived().TransformCallExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10197 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10198 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10199 | template <typename Derived> |
| 10200 | ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { |
| 10201 | bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function && |
| 10202 | getSema().CurContext != E->getParentContext(); |
| 10203 | |
| 10204 | if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) |
| 10205 | return E; |
| 10206 | |
| 10207 | return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(), |
| 10208 | E->getEndLoc(), |
| 10209 | getSema().CurContext); |
| 10210 | } |
| 10211 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10212 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10213 | ExprResult |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10214 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 10215 | // Transform the callee. |
| 10216 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 10217 | if (Callee.isInvalid()) |
| 10218 | return ExprError(); |
| 10219 | |
| 10220 | // Transform exec config. |
| 10221 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 10222 | if (EC.isInvalid()) |
| 10223 | return ExprError(); |
| 10224 | |
| 10225 | // Transform arguments. |
| 10226 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10227 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10228 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10229 | &ArgChanged)) |
| 10230 | return ExprError(); |
| 10231 | |
| 10232 | if (!getDerived().AlwaysRebuild() && |
| 10233 | Callee.get() == E->getCallee() && |
| 10234 | !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10235 | return SemaRef.MaybeBindToTemporary(E); |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10236 | |
| 10237 | // FIXME: Wrong source location information for the '('. |
| 10238 | SourceLocation FakeLParenLoc |
| 10239 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 10240 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10241 | Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10242 | E->getRParenLoc(), EC.get()); |
| 10243 | } |
| 10244 | |
| 10245 | template<typename Derived> |
| 10246 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10247 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10248 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 10249 | if (!Type) |
| 10250 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10251 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10252 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 10253 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10254 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10255 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10256 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10257 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10258 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10259 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10260 | return E; |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 10261 | return getDerived().RebuildCXXNamedCastExpr( |
| 10262 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 10263 | Type, E->getAngleBrackets().getEnd(), |
| 10264 | // FIXME. this should be '(' location |
| 10265 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10266 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10267 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10268 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10269 | ExprResult |
| Erik Pilkington | eee944e | 2019-07-02 18:28:13 +0000 | [diff] [blame] | 10270 | TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) { |
| 10271 | TypeSourceInfo *TSI = |
| 10272 | getDerived().TransformType(BCE->getTypeInfoAsWritten()); |
| 10273 | if (!TSI) |
| 10274 | return ExprError(); |
| 10275 | |
| 10276 | ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr()); |
| 10277 | if (Sub.isInvalid()) |
| 10278 | return ExprError(); |
| 10279 | |
| 10280 | return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI, |
| 10281 | Sub.get(), BCE->getEndLoc()); |
| 10282 | } |
| 10283 | |
| 10284 | template<typename Derived> |
| 10285 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10286 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 10287 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10288 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10289 | |
| 10290 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10291 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10292 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 10293 | return getDerived().TransformCXXNamedCastExpr(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10294 | } |
| 10295 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10296 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10297 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10298 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10299 | CXXReinterpretCastExpr *E) { |
| 10300 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10301 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10302 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10303 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10304 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10305 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 10306 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10307 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10308 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10309 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10310 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10311 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10312 | CXXFunctionalCastExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10313 | TypeSourceInfo *Type = |
| 10314 | getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10315 | if (!Type) |
| 10316 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10317 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10318 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 10319 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10320 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10321 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10322 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10323 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10324 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10325 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10326 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10327 | |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10328 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
| Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 10329 | E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10330 | SubExpr.get(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 10331 | E->getRParenLoc(), |
| 10332 | E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10333 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10334 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10335 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10336 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10337 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10338 | if (E->isTypeOperand()) { |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 10339 | TypeSourceInfo *TInfo |
| 10340 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 10341 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10342 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10343 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10344 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 10345 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10346 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10347 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10348 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10349 | TInfo, E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10350 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10351 | |
| Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 10352 | // We don't know whether the subexpression is potentially evaluated until |
| 10353 | // after we perform semantic analysis. We speculatively assume it is |
| 10354 | // unevaluated; it will get fixed later if the subexpression is in fact |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10355 | // potentially evaluated. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10356 | EnterExpressionEvaluationContext Unevaluated( |
| 10357 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 10358 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10359 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10360 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10361 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10362 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10363 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10364 | if (!getDerived().AlwaysRebuild() && |
| 10365 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10366 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10367 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10368 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10369 | SubExpr.get(), E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10370 | } |
| 10371 | |
| 10372 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10373 | ExprResult |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10374 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 10375 | if (E->isTypeOperand()) { |
| 10376 | TypeSourceInfo *TInfo |
| 10377 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 10378 | if (!TInfo) |
| 10379 | return ExprError(); |
| 10380 | |
| 10381 | if (!getDerived().AlwaysRebuild() && |
| 10382 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10383 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10384 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10385 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10386 | TInfo, E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10387 | } |
| 10388 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10389 | EnterExpressionEvaluationContext Unevaluated( |
| 10390 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10391 | |
| 10392 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 10393 | if (SubExpr.isInvalid()) |
| 10394 | return ExprError(); |
| 10395 | |
| 10396 | if (!getDerived().AlwaysRebuild() && |
| 10397 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10398 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10399 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10400 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10401 | SubExpr.get(), E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10402 | } |
| 10403 | |
| 10404 | template<typename Derived> |
| 10405 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10406 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10407 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10408 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10409 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10410 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10411 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10412 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10413 | CXXNullPtrLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10414 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10415 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10416 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10417 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10418 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10419 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 10420 | QualType T = getSema().getCurrentThisType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10421 | |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10422 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| Richard Smith | 8458c9e | 2019-05-24 01:35:07 +0000 | [diff] [blame] | 10423 | // Mark it referenced in the new context regardless. |
| 10424 | // FIXME: this is a bit instantiation-specific. |
| 10425 | getSema().MarkThisReferenced(E); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10426 | return E; |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10427 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10428 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10429 | return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10430 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10431 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10432 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10433 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10434 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10435 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10436 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10437 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10438 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10439 | if (!getDerived().AlwaysRebuild() && |
| 10440 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10441 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10442 | |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 10443 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 10444 | E->isThrownVariableInScope()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10445 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10446 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10447 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10448 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10449 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10450 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 10451 | getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10452 | if (!Param) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10453 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10454 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10455 | if (!getDerived().AlwaysRebuild() && Param == E->getParam() && |
| 10456 | E->getUsedContext() == SemaRef.CurContext) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10457 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10458 | |
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 10459 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10460 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10461 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10462 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10463 | ExprResult |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10464 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10465 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 10466 | getDerived().TransformDecl(E->getBeginLoc(), E->getField())); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10467 | if (!Field) |
| 10468 | return ExprError(); |
| 10469 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10470 | if (!getDerived().AlwaysRebuild() && Field == E->getField() && |
| 10471 | E->getUsedContext() == SemaRef.CurContext) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10472 | return E; |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10473 | |
| 10474 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 10475 | } |
| 10476 | |
| 10477 | template<typename Derived> |
| 10478 | ExprResult |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10479 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 10480 | CXXScalarValueInitExpr *E) { |
| 10481 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10482 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10483 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10484 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10485 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10486 | T == E->getTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10487 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10488 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10489 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10490 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
| Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 10491 | E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10492 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10493 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10494 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10495 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10496 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10497 | // Transform the type that we're allocating |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10498 | TypeSourceInfo *AllocTypeInfo = |
| 10499 | getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10500 | if (!AllocTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10501 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10502 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10503 | // Transform the size of the array we're allocating (if any). |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10504 | Optional<Expr *> ArraySize; |
| 10505 | if (Optional<Expr *> OldArraySize = E->getArraySize()) { |
| 10506 | ExprResult NewArraySize; |
| 10507 | if (*OldArraySize) { |
| 10508 | NewArraySize = getDerived().TransformExpr(*OldArraySize); |
| 10509 | if (NewArraySize.isInvalid()) |
| 10510 | return ExprError(); |
| 10511 | } |
| 10512 | ArraySize = NewArraySize.get(); |
| 10513 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10514 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10515 | // Transform the placement arguments (if any). |
| 10516 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10517 | SmallVector<Expr*, 8> PlacementArgs; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10518 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10519 | E->getNumPlacementArgs(), true, |
| 10520 | PlacementArgs, &ArgumentChanged)) |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10521 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10522 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10523 | // Transform the initializer (if any). |
| 10524 | Expr *OldInit = E->getInitializer(); |
| 10525 | ExprResult NewInit; |
| 10526 | if (OldInit) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 10527 | NewInit = getDerived().TransformInitializer(OldInit, true); |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10528 | if (NewInit.isInvalid()) |
| 10529 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10530 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10531 | // Transform new operator and delete operator. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10532 | FunctionDecl *OperatorNew = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10533 | if (E->getOperatorNew()) { |
| 10534 | OperatorNew = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10535 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10536 | if (!OperatorNew) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10537 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10538 | } |
| 10539 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10540 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10541 | if (E->getOperatorDelete()) { |
| 10542 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10543 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10544 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10545 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10546 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10547 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10548 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10549 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10550 | ArraySize == E->getArraySize() && |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10551 | NewInit.get() == OldInit && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10552 | OperatorNew == E->getOperatorNew() && |
| 10553 | OperatorDelete == E->getOperatorDelete() && |
| 10554 | !ArgumentChanged) { |
| 10555 | // Mark any declarations we need as referenced. |
| 10556 | // FIXME: instantiation-specific. |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10557 | if (OperatorNew) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10558 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10559 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10560 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10561 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10562 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10563 | QualType ElementType |
| 10564 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 10565 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 10566 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 10567 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10568 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10569 | } |
| 10570 | } |
| 10571 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10572 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10573 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10574 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10575 | |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10576 | QualType AllocType = AllocTypeInfo->getType(); |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10577 | if (!ArraySize) { |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10578 | // If no array size was specified, but the new expression was |
| 10579 | // instantiated with an array type (e.g., "new T" where T is |
| 10580 | // instantiated with "int[4]"), extract the outer bound from the |
| 10581 | // array type as our array size. We do this with constant and |
| 10582 | // dependently-sized array types. |
| 10583 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 10584 | if (!ArrayT) { |
| 10585 | // Do nothing |
| 10586 | } else if (const ConstantArrayType *ConsArrayT |
| 10587 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10588 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 10589 | SemaRef.Context.getSizeType(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10590 | /*FIXME:*/ E->getBeginLoc()); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10591 | AllocType = ConsArrayT->getElementType(); |
| 10592 | } else if (const DependentSizedArrayType *DepArrayT |
| 10593 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 10594 | if (DepArrayT->getSizeExpr()) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10595 | ArraySize = DepArrayT->getSizeExpr(); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10596 | AllocType = DepArrayT->getElementType(); |
| 10597 | } |
| 10598 | } |
| 10599 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10600 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10601 | return getDerived().RebuildCXXNewExpr( |
| 10602 | E->getBeginLoc(), E->isGlobalNew(), |
| 10603 | /*FIXME:*/ E->getBeginLoc(), PlacementArgs, |
| 10604 | /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10605 | AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10606 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10607 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10608 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10609 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10610 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10611 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10612 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10613 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10614 | |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10615 | // Transform the delete operator, if known. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10616 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10617 | if (E->getOperatorDelete()) { |
| 10618 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10619 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10620 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10621 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10622 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10623 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10624 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10625 | Operand.get() == E->getArgument() && |
| 10626 | OperatorDelete == E->getOperatorDelete()) { |
| 10627 | // Mark any declarations we need as referenced. |
| 10628 | // FIXME: instantiation-specific. |
| 10629 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10630 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10631 | |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10632 | if (!E->getArgument()->isTypeDependent()) { |
| 10633 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 10634 | E->getDestroyedType()); |
| 10635 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 10636 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10637 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 10638 | SemaRef.LookupDestructor(Record)); |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10639 | } |
| 10640 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10641 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10642 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10643 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10644 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10645 | return getDerived().RebuildCXXDeleteExpr( |
| 10646 | E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10647 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10648 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10649 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10650 | ExprResult |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10651 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10652 | CXXPseudoDestructorExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10653 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10654 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10655 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10656 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10657 | ParsedType ObjectTypePtr; |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10658 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10659 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10660 | E->getOperatorLoc(), |
| 10661 | E->isArrow()? tok::arrow : tok::period, |
| 10662 | ObjectTypePtr, |
| 10663 | MayBePseudoDestructor); |
| 10664 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10665 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10666 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10667 | QualType ObjectType = ObjectTypePtr.get(); |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10668 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 10669 | if (QualifierLoc) { |
| 10670 | QualifierLoc |
| 10671 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 10672 | if (!QualifierLoc) |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10673 | return ExprError(); |
| 10674 | } |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10675 | CXXScopeSpec SS; |
| 10676 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10677 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10678 | PseudoDestructorTypeStorage Destroyed; |
| 10679 | if (E->getDestroyedTypeInfo()) { |
| 10680 | TypeSourceInfo *DestroyedTypeInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10681 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10682 | ObjectType, nullptr, SS); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10683 | if (!DestroyedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10684 | return ExprError(); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10685 | Destroyed = DestroyedTypeInfo; |
| Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 10686 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10687 | // We aren't likely to be able to resolve the identifier down to a type |
| 10688 | // now anyway, so just retain the identifier. |
| 10689 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 10690 | E->getDestroyedTypeLoc()); |
| 10691 | } else { |
| 10692 | // Look for a destructor known with the given name. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10693 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10694 | *E->getDestroyedTypeIdentifier(), |
| 10695 | E->getDestroyedTypeLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10696 | /*Scope=*/nullptr, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10697 | SS, ObjectTypePtr, |
| 10698 | false); |
| 10699 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10700 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10701 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10702 | Destroyed |
| 10703 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 10704 | E->getDestroyedTypeLoc()); |
| 10705 | } |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10706 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10707 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10708 | if (E->getScopeTypeInfo()) { |
| Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 10709 | CXXScopeSpec EmptySS; |
| 10710 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10711 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10712 | if (!ScopeTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10713 | return ExprError(); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10714 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10715 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10716 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10717 | E->getOperatorLoc(), |
| 10718 | E->isArrow(), |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10719 | SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10720 | ScopeTypeInfo, |
| 10721 | E->getColonColonLoc(), |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10722 | E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10723 | Destroyed); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10724 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10725 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10726 | template <typename Derived> |
| 10727 | bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, |
| 10728 | bool RequiresADL, |
| 10729 | LookupResult &R) { |
| 10730 | // Transform all the decls. |
| 10731 | bool AllEmptyPacks = true; |
| 10732 | for (auto *OldD : Old->decls()) { |
| 10733 | Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); |
| 10734 | if (!InstD) { |
| 10735 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 10736 | // This can happen because of dependent hiding. |
| 10737 | if (isa<UsingShadowDecl>(OldD)) |
| 10738 | continue; |
| 10739 | else { |
| 10740 | R.clear(); |
| 10741 | return true; |
| 10742 | } |
| 10743 | } |
| 10744 | |
| 10745 | // Expand using pack declarations. |
| 10746 | NamedDecl *SingleDecl = cast<NamedDecl>(InstD); |
| 10747 | ArrayRef<NamedDecl*> Decls = SingleDecl; |
| 10748 | if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) |
| 10749 | Decls = UPD->expansions(); |
| 10750 | |
| 10751 | // Expand using declarations. |
| 10752 | for (auto *D : Decls) { |
| 10753 | if (auto *UD = dyn_cast<UsingDecl>(D)) { |
| 10754 | for (auto *SD : UD->shadows()) |
| 10755 | R.addDecl(SD); |
| 10756 | } else { |
| 10757 | R.addDecl(D); |
| 10758 | } |
| 10759 | } |
| 10760 | |
| 10761 | AllEmptyPacks &= Decls.empty(); |
| 10762 | }; |
| 10763 | |
| 10764 | // C++ [temp.res]/8.4.2: |
| 10765 | // The program is ill-formed, no diagnostic required, if [...] lookup for |
| 10766 | // a name in the template definition found a using-declaration, but the |
| 10767 | // lookup in the corresponding scope in the instantiation odoes not find |
| 10768 | // any declarations because the using-declaration was a pack expansion and |
| 10769 | // the corresponding pack is empty |
| 10770 | if (AllEmptyPacks && !RequiresADL) { |
| 10771 | getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) |
| Richard Trieu | b402580 | 2018-03-28 04:16:13 +0000 | [diff] [blame] | 10772 | << isa<UnresolvedMemberExpr>(Old) << Old->getName(); |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10773 | return true; |
| 10774 | } |
| 10775 | |
| 10776 | // Resolve a kind, but don't do any further analysis. If it's |
| 10777 | // ambiguous, the callee needs to deal with it. |
| 10778 | R.resolveKind(); |
| 10779 | return false; |
| 10780 | } |
| 10781 | |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10782 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10783 | ExprResult |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10784 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10785 | UnresolvedLookupExpr *Old) { |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10786 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 10787 | Sema::LookupOrdinaryName); |
| 10788 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10789 | // Transform the declaration set. |
| 10790 | if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) |
| 10791 | return ExprError(); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10792 | |
| 10793 | // Rebuild the nested-name qualifier, if present. |
| 10794 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10795 | if (Old->getQualifierLoc()) { |
| 10796 | NestedNameSpecifierLoc QualifierLoc |
| 10797 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 10798 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10799 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10800 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10801 | SS.Adopt(QualifierLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10802 | } |
| 10803 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10804 | if (Old->getNamingClass()) { |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10805 | CXXRecordDecl *NamingClass |
| 10806 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 10807 | Old->getNameLoc(), |
| 10808 | Old->getNamingClass())); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10809 | if (!NamingClass) { |
| 10810 | R.clear(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10811 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10812 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10813 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10814 | R.setNamingClass(NamingClass); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10815 | } |
| 10816 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10817 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 10818 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10819 | // If we have neither explicit template arguments, nor the template keyword, |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10820 | // it's a normal declaration name or member reference. |
| 10821 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 10822 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 10823 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 10824 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 10825 | // give a good diagnostic. |
| 10826 | if (D && D->isCXXInstanceMember()) { |
| 10827 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 10828 | /*TemplateArgs=*/nullptr, |
| 10829 | /*Scope=*/nullptr); |
| 10830 | } |
| 10831 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10832 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10833 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10834 | |
| 10835 | // If we have template arguments, rebuild them, then rebuild the |
| 10836 | // templateid expression. |
| 10837 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 10838 | if (Old->hasExplicitTemplateArgs() && |
| 10839 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10840 | Old->getNumTemplateArgs(), |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10841 | TransArgs)) { |
| 10842 | R.clear(); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10843 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10844 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10845 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10846 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10847 | Old->requiresADL(), &TransArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10848 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10849 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10850 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10851 | ExprResult |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10852 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 10853 | bool ArgChanged = false; |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10854 | SmallVector<TypeSourceInfo *, 4> Args; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10855 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 10856 | TypeSourceInfo *From = E->getArg(I); |
| 10857 | TypeLoc FromTL = From->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10858 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10859 | TypeLocBuilder TLB; |
| 10860 | TLB.reserve(FromTL.getFullDataSize()); |
| 10861 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 10862 | if (To.isNull()) |
| 10863 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10864 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10865 | if (To == From->getType()) |
| 10866 | Args.push_back(From); |
| 10867 | else { |
| 10868 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10869 | ArgChanged = true; |
| 10870 | } |
| 10871 | continue; |
| 10872 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10873 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10874 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10875 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10876 | // We have a pack expansion. Instantiate it. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10877 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10878 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 10879 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10880 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10881 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10882 | // Determine whether the set of unexpanded parameter packs can and should |
| 10883 | // be expanded. |
| 10884 | bool Expand = true; |
| 10885 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10886 | Optional<unsigned> OrigNumExpansions = |
| 10887 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 10888 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10889 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 10890 | PatternTL.getSourceRange(), |
| 10891 | Unexpanded, |
| 10892 | Expand, RetainExpansion, |
| 10893 | NumExpansions)) |
| 10894 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10895 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10896 | if (!Expand) { |
| 10897 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10898 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10899 | // expansion. |
| 10900 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10901 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10902 | TypeLocBuilder TLB; |
| 10903 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 10904 | |
| 10905 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10906 | if (To.isNull()) |
| 10907 | return ExprError(); |
| 10908 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10909 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10910 | PatternTL.getSourceRange(), |
| 10911 | ExpansionTL.getEllipsisLoc(), |
| 10912 | NumExpansions); |
| 10913 | if (To.isNull()) |
| 10914 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10915 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10916 | PackExpansionTypeLoc ToExpansionTL |
| 10917 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10918 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10919 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10920 | continue; |
| 10921 | } |
| 10922 | |
| 10923 | // Expand the pack expansion by substituting for each argument in the |
| 10924 | // pack(s). |
| 10925 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10926 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 10927 | TypeLocBuilder TLB; |
| 10928 | TLB.reserve(PatternTL.getFullDataSize()); |
| 10929 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10930 | if (To.isNull()) |
| 10931 | return ExprError(); |
| 10932 | |
| Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 10933 | if (To->containsUnexpandedParameterPack()) { |
| 10934 | To = getDerived().RebuildPackExpansionType(To, |
| 10935 | PatternTL.getSourceRange(), |
| 10936 | ExpansionTL.getEllipsisLoc(), |
| 10937 | NumExpansions); |
| 10938 | if (To.isNull()) |
| 10939 | return ExprError(); |
| 10940 | |
| 10941 | PackExpansionTypeLoc ToExpansionTL |
| 10942 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10943 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10944 | } |
| 10945 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10946 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10947 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10948 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10949 | if (!RetainExpansion) |
| 10950 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10951 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10952 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 10953 | // forgetting the partially-substituted parameter pack. |
| 10954 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10955 | |
| 10956 | TypeLocBuilder TLB; |
| 10957 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10958 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10959 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10960 | if (To.isNull()) |
| 10961 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10962 | |
| 10963 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10964 | PatternTL.getSourceRange(), |
| 10965 | ExpansionTL.getEllipsisLoc(), |
| 10966 | NumExpansions); |
| 10967 | if (To.isNull()) |
| 10968 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10969 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10970 | PackExpansionTypeLoc ToExpansionTL |
| 10971 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10972 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10973 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10974 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10975 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10976 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10977 | return E; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10978 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10979 | return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10980 | E->getEndLoc()); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10981 | } |
| 10982 | |
| 10983 | template<typename Derived> |
| 10984 | ExprResult |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10985 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 10986 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 10987 | if (!T) |
| 10988 | return ExprError(); |
| 10989 | |
| 10990 | if (!getDerived().AlwaysRebuild() && |
| 10991 | T == E->getQueriedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10992 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10993 | |
| 10994 | ExprResult SubExpr; |
| 10995 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10996 | EnterExpressionEvaluationContext Unevaluated( |
| 10997 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10998 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 10999 | if (SubExpr.isInvalid()) |
| 11000 | return ExprError(); |
| 11001 | |
| 11002 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11003 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 11004 | } |
| 11005 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11006 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11007 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 11008 | } |
| 11009 | |
| 11010 | template<typename Derived> |
| 11011 | ExprResult |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 11012 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 11013 | ExprResult SubExpr; |
| 11014 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11015 | EnterExpressionEvaluationContext Unevaluated( |
| 11016 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 11017 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 11018 | if (SubExpr.isInvalid()) |
| 11019 | return ExprError(); |
| 11020 | |
| 11021 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11022 | return E; |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 11023 | } |
| 11024 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11025 | return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11026 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 11027 | } |
| 11028 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11029 | template <typename Derived> |
| 11030 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 11031 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 11032 | TypeSourceInfo **RecoveryTSI) { |
| 11033 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 11034 | DRE, AddrTaken, RecoveryTSI); |
| 11035 | |
| 11036 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 11037 | if (!NewDRE.isUsable()) |
| 11038 | return NewDRE; |
| 11039 | |
| 11040 | // We got an expr, wrap it up in parens. |
| 11041 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 11042 | return PE; |
| 11043 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 11044 | PE->getRParen()); |
| 11045 | } |
| 11046 | |
| 11047 | template <typename Derived> |
| 11048 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 11049 | DependentScopeDeclRefExpr *E) { |
| 11050 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 11051 | nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 11052 | } |
| 11053 | |
| 11054 | template<typename Derived> |
| 11055 | ExprResult |
| 11056 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 11057 | DependentScopeDeclRefExpr *E, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11058 | bool IsAddressOfOperand, |
| 11059 | TypeSourceInfo **RecoveryTSI) { |
| Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 11060 | assert(E->getQualifierLoc()); |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 11061 | NestedNameSpecifierLoc QualifierLoc |
| 11062 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 11063 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11064 | return ExprError(); |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11065 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11066 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11067 | // TODO: If this is a conversion-function-id, verify that the |
| 11068 | // destination type name (if present) resolves the same way after |
| 11069 | // instantiation as it did in the local scope. |
| 11070 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11071 | DeclarationNameInfo NameInfo |
| 11072 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 11073 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11074 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11075 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 11076 | if (!E->hasExplicitTemplateArgs()) { |
| 11077 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 11078 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11079 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 11080 | // if name has not changed, DNLoc has not changed either. |
| 11081 | NameInfo.getName() == E->getDeclName()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11082 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11083 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11084 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 11085 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 11086 | IsAddressOfOperand, RecoveryTSI); |
| Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 11087 | } |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11088 | |
| 11089 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11090 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 11091 | E->getNumTemplateArgs(), |
| 11092 | TransArgs)) |
| 11093 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11094 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11095 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 11096 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 11097 | RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11098 | } |
| 11099 | |
| 11100 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11101 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11102 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 11103 | // CXXConstructExprs other than for list-initialization and |
| 11104 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 11105 | // a 1-argument construction we just transform that argument. |
| Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 11106 | if ((E->getNumArgs() == 1 || |
| 11107 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 11108 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 11109 | !E->isListInitialization()) |
| Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 11110 | return getDerived().TransformExpr(E->getArg(0)); |
| 11111 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11112 | TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11113 | |
| 11114 | QualType T = getDerived().TransformType(E->getType()); |
| 11115 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11116 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11117 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11118 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 11119 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11120 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11121 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11122 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11123 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11124 | SmallVector<Expr*, 8> Args; |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11125 | { |
| 11126 | EnterExpressionEvaluationContext Context( |
| 11127 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11128 | E->isListInitialization()); |
| 11129 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 11130 | &ArgumentChanged)) |
| 11131 | return ExprError(); |
| 11132 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11133 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11134 | if (!getDerived().AlwaysRebuild() && |
| 11135 | T == E->getType() && |
| 11136 | Constructor == E->getConstructor() && |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 11137 | !ArgumentChanged) { |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 11138 | // Mark the constructor as referenced. |
| 11139 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11140 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11141 | return E; |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 11142 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11143 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11144 | return getDerived().RebuildCXXConstructExpr( |
| 11145 | T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, |
| 11146 | E->hadMultipleCandidates(), E->isListInitialization(), |
| 11147 | E->isStdInitListInitialization(), E->requiresZeroInitialization(), |
| 11148 | E->getConstructionKind(), E->getParenOrBraceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11149 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11150 | |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11151 | template<typename Derived> |
| 11152 | ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 11153 | CXXInheritedCtorInitExpr *E) { |
| 11154 | QualType T = getDerived().TransformType(E->getType()); |
| 11155 | if (T.isNull()) |
| 11156 | return ExprError(); |
| 11157 | |
| 11158 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11159 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11160 | if (!Constructor) |
| 11161 | return ExprError(); |
| 11162 | |
| 11163 | if (!getDerived().AlwaysRebuild() && |
| 11164 | T == E->getType() && |
| 11165 | Constructor == E->getConstructor()) { |
| 11166 | // Mark the constructor as referenced. |
| 11167 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11168 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11169 | return E; |
| 11170 | } |
| 11171 | |
| 11172 | return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 11173 | T, E->getLocation(), Constructor, |
| 11174 | E->constructsVBase(), E->inheritedFromVBase()); |
| 11175 | } |
| 11176 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11177 | /// Transform a C++ temporary-binding expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11178 | /// |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11179 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 11180 | /// transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11181 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11182 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11183 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11184 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11185 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11186 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11187 | /// Transform a C++ expression that contains cleanups that should |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11188 | /// be run after the expression is evaluated. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11189 | /// |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11190 | /// Since ExprWithCleanups nodes are implicitly generated, we |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11191 | /// just transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11192 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11193 | ExprResult |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11194 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11195 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11196 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11197 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11198 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11199 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11200 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11201 | CXXTemporaryObjectExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 11202 | TypeSourceInfo *T = |
| 11203 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11204 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11205 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11206 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11207 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 11208 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11209 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11210 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11211 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11212 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11213 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11214 | Args.reserve(E->getNumArgs()); |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11215 | { |
| 11216 | EnterExpressionEvaluationContext Context( |
| 11217 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11218 | E->isListInitialization()); |
| 11219 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 11220 | &ArgumentChanged)) |
| 11221 | return ExprError(); |
| 11222 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11223 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11224 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11225 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11226 | Constructor == E->getConstructor() && |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 11227 | !ArgumentChanged) { |
| 11228 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11229 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 11230 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 11231 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11232 | |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11233 | // FIXME: We should just pass E->isListInitialization(), but we're not |
| 11234 | // prepared to handle list-initialization without a child InitListExpr. |
| 11235 | SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); |
| 11236 | return getDerived().RebuildCXXTemporaryObjectExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11237 | T, LParenLoc, Args, E->getEndLoc(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11238 | /*ListInitialization=*/LParenLoc.isInvalid()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11239 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11240 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11241 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11242 | ExprResult |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11243 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11244 | // Transform any init-capture expressions before entering the scope of the |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11245 | // lambda body, because they are not semantically within that scope. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11246 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11247 | struct TransformedInitCapture { |
| 11248 | // The location of the ... if the result is retaining a pack expansion. |
| 11249 | SourceLocation EllipsisLoc; |
| 11250 | // Zero or more expansions of the init-capture. |
| 11251 | SmallVector<InitCaptureInfoTy, 4> Expansions; |
| 11252 | }; |
| 11253 | SmallVector<TransformedInitCapture, 4> InitCaptures; |
| 11254 | InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11255 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11256 | CEnd = E->capture_end(); |
| 11257 | C != CEnd; ++C) { |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 11258 | if (!E->isInitCapture(C)) |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11259 | continue; |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11260 | |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11261 | TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11262 | VarDecl *OldVD = C->getCapturedVar(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11263 | |
| 11264 | auto SubstInitCapture = [&](SourceLocation EllipsisLoc, |
| 11265 | Optional<unsigned> NumExpansions) { |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11266 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 11267 | OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); |
| 11268 | |
| 11269 | if (NewExprInitResult.isInvalid()) { |
| 11270 | Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); |
| 11271 | return; |
| 11272 | } |
| 11273 | Expr *NewExprInit = NewExprInitResult.get(); |
| 11274 | |
| 11275 | QualType NewInitCaptureType = |
| 11276 | getSema().buildLambdaInitCaptureInitialization( |
| 11277 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 11278 | EllipsisLoc, NumExpansions, OldVD->getIdentifier(), |
| 11279 | C->getCapturedVar()->getInitStyle() != VarDecl::CInit, |
| 11280 | NewExprInit); |
| 11281 | Result.Expansions.push_back( |
| 11282 | InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); |
| 11283 | }; |
| 11284 | |
| 11285 | // If this is an init-capture pack, consider expanding the pack now. |
| 11286 | if (OldVD->isParameterPack()) { |
| 11287 | PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() |
| 11288 | ->getTypeLoc() |
| 11289 | .castAs<PackExpansionTypeLoc>(); |
| 11290 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11291 | SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); |
| 11292 | |
| 11293 | // Determine whether the set of unexpanded parameter packs can and should |
| 11294 | // be expanded. |
| 11295 | bool Expand = true; |
| 11296 | bool RetainExpansion = false; |
| 11297 | Optional<unsigned> OrigNumExpansions = |
| 11298 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 11299 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 11300 | if (getDerived().TryExpandParameterPacks( |
| 11301 | ExpansionTL.getEllipsisLoc(), |
| 11302 | OldVD->getInit()->getSourceRange(), Unexpanded, Expand, |
| 11303 | RetainExpansion, NumExpansions)) |
| 11304 | return ExprError(); |
| 11305 | if (Expand) { |
| 11306 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11307 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11308 | SubstInitCapture(SourceLocation(), None); |
| 11309 | } |
| 11310 | } |
| 11311 | if (!Expand || RetainExpansion) { |
| 11312 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 11313 | SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); |
| 11314 | Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); |
| 11315 | } |
| 11316 | } else { |
| 11317 | SubstInitCapture(SourceLocation(), None); |
| 11318 | } |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11319 | } |
| 11320 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11321 | // Transform the template parameters, and add them to the current |
| 11322 | // instantiation scope. The null case is handled correctly. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11323 | auto TPL = getDerived().TransformTemplateParameterList( |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11324 | E->getTemplateParameterList()); |
| 11325 | |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11326 | // Transform the type of the original lambda's call operator. |
| 11327 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 11328 | // it introduces a mapping of the original to the newly created |
| 11329 | // transformed parameters. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11330 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11331 | { |
| 11332 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 11333 | FunctionProtoTypeLoc OldCallOpFPTL = |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11334 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11335 | |
| 11336 | TypeLocBuilder NewCallOpTLBuilder; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11337 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 11338 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11339 | QualType NewCallOpType = TransformFunctionProtoType( |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 11340 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(), |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 11341 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 11342 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 11343 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11344 | }); |
| Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 11345 | if (NewCallOpType.isNull()) |
| 11346 | return ExprError(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11347 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 11348 | NewCallOpType); |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 11349 | } |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11350 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11351 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 11352 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 11353 | LSI->GLTemplateParameterList = TPL; |
| 11354 | |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11355 | // Create the local class that will describe the lambda. |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11356 | CXXRecordDecl *OldClass = E->getLambdaClass(); |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11357 | CXXRecordDecl *Class |
| 11358 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11359 | NewCallOpTSI, |
| Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 11360 | /*KnownDependent=*/false, |
| 11361 | E->getCaptureDefault()); |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11362 | getDerived().transformedLocalDecl(OldClass, {Class}); |
| 11363 | |
| 11364 | Optional<std::pair<unsigned, Decl*>> Mangling; |
| 11365 | if (getDerived().ReplacingOriginal()) |
| 11366 | Mangling = std::make_pair(OldClass->getLambdaManglingNumber(), |
| 11367 | OldClass->getLambdaContextDecl()); |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11368 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11369 | // Build the call operator. |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11370 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 11371 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11372 | E->getCallOperator()->getEndLoc(), |
| Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 11373 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 11374 | E->getCallOperator()->getConstexprKind(), Mangling); |
| Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 11375 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11376 | LSI->CallOperator = NewCallOperator; |
| Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 11377 | |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 11378 | for (unsigned I = 0, NumParams = NewCallOperator->getNumParams(); |
| 11379 | I != NumParams; ++I) { |
| 11380 | auto *P = NewCallOperator->getParamDecl(I); |
| 11381 | if (P->hasUninstantiatedDefaultArg()) { |
| 11382 | EnterExpressionEvaluationContext Eval( |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11383 | getSema(), |
| 11384 | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P); |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 11385 | ExprResult R = getDerived().TransformExpr( |
| 11386 | E->getCallOperator()->getParamDecl(I)->getDefaultArg()); |
| 11387 | P->setDefaultArg(R.get()); |
| 11388 | } |
| 11389 | } |
| 11390 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11391 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11392 | getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11393 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11394 | // Introduce the context of the call operator. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11395 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
| Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 11396 | /*NewThisContext*/false); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11397 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11398 | // Enter the scope of the lambda. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11399 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 11400 | E->getIntroducerRange(), |
| 11401 | E->getCaptureDefault(), |
| 11402 | E->getCaptureDefaultLoc(), |
| 11403 | E->hasExplicitParameters(), |
| 11404 | E->hasExplicitResultType(), |
| 11405 | E->isMutable()); |
| 11406 | |
| 11407 | bool Invalid = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11408 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11409 | // Transform captures. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11410 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11411 | CEnd = E->capture_end(); |
| 11412 | C != CEnd; ++C) { |
| 11413 | // When we hit the first implicit capture, tell Sema that we've finished |
| 11414 | // the list of explicit captures. |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11415 | if (C->isImplicit()) |
| 11416 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11417 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11418 | // Capturing 'this' is trivial. |
| 11419 | if (C->capturesThis()) { |
| Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 11420 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 11421 | /*BuildAndDiagnose*/ true, nullptr, |
| 11422 | C->getCaptureKind() == LCK_StarThis); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11423 | continue; |
| 11424 | } |
| Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 11425 | // Captured expression will be recaptured during captured variables |
| 11426 | // rebuilding. |
| 11427 | if (C->capturesVLAType()) |
| 11428 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11429 | |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11430 | // Rebuild init-captures, including the implied field declaration. |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 11431 | if (E->isInitCapture(C)) { |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11432 | TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; |
| 11433 | |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11434 | VarDecl *OldVD = C->getCapturedVar(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11435 | llvm::SmallVector<Decl*, 4> NewVDs; |
| 11436 | |
| 11437 | for (InitCaptureInfoTy &Info : NewC.Expansions) { |
| 11438 | ExprResult Init = Info.first; |
| 11439 | QualType InitQualType = Info.second; |
| 11440 | if (Init.isInvalid() || InitQualType.isNull()) { |
| 11441 | Invalid = true; |
| 11442 | break; |
| 11443 | } |
| 11444 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 11445 | OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, |
| 11446 | OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get()); |
| 11447 | if (!NewVD) { |
| 11448 | Invalid = true; |
| 11449 | break; |
| 11450 | } |
| 11451 | NewVDs.push_back(NewVD); |
| Richard Smith | 3011653 | 2019-05-28 23:09:46 +0000 | [diff] [blame] | 11452 | getSema().addInitCapture(LSI, NewVD); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11453 | } |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11454 | |
| 11455 | if (Invalid) |
| 11456 | break; |
| 11457 | |
| 11458 | getDerived().transformedLocalDecl(OldVD, NewVDs); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11459 | continue; |
| 11460 | } |
| 11461 | |
| 11462 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 11463 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11464 | // Determine the capture kind for Sema. |
| 11465 | Sema::TryCaptureKind Kind |
| 11466 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 11467 | : C->getCaptureKind() == LCK_ByCopy |
| 11468 | ? Sema::TryCapture_ExplicitByVal |
| 11469 | : Sema::TryCapture_ExplicitByRef; |
| 11470 | SourceLocation EllipsisLoc; |
| 11471 | if (C->isPackExpansion()) { |
| 11472 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 11473 | bool ShouldExpand = false; |
| 11474 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 11475 | Optional<unsigned> NumExpansions; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11476 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 11477 | C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11478 | Unexpanded, |
| 11479 | ShouldExpand, RetainExpansion, |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11480 | NumExpansions)) { |
| 11481 | Invalid = true; |
| 11482 | continue; |
| 11483 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11484 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11485 | if (ShouldExpand) { |
| 11486 | // The transform has determined that we should perform an expansion; |
| 11487 | // transform and capture each of the arguments. |
| 11488 | // expansion of the pattern. Do so. |
| 11489 | VarDecl *Pack = C->getCapturedVar(); |
| 11490 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11491 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11492 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11493 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11494 | Pack)); |
| 11495 | if (!CapturedVar) { |
| 11496 | Invalid = true; |
| 11497 | continue; |
| 11498 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11499 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11500 | // Capture the transformed variable. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11501 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 11502 | } |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 11503 | |
| 11504 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 11505 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11506 | continue; |
| 11507 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11508 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11509 | EllipsisLoc = C->getEllipsisLoc(); |
| 11510 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11511 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11512 | // Transform the captured variable. |
| 11513 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11514 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11515 | C->getCapturedVar())); |
| Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 11516 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11517 | Invalid = true; |
| 11518 | continue; |
| 11519 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11520 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11521 | // Capture the transformed variable. |
| Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 11522 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 11523 | EllipsisLoc); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11524 | } |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11525 | getSema().finishLambdaExplicitCaptures(LSI); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11526 | |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11527 | // FIXME: Sema's lambda-building mechanism expects us to push an expression |
| 11528 | // evaluation context even if we're not transforming the function body. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11529 | getSema().PushExpressionEvaluationContext( |
| 11530 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11531 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11532 | // Instantiate the body of the lambda expression. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11533 | StmtResult Body = |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11534 | Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody()); |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11535 | |
| 11536 | // ActOnLambda* will pop the function scope for us. |
| 11537 | FuncScopeCleanup.disable(); |
| 11538 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11539 | if (Body.isInvalid()) { |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11540 | SavedContext.pop(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11541 | getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11542 | /*IsInstantiation=*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11543 | return ExprError(); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11544 | } |
| Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 11545 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11546 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 11547 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 11548 | // the call operator. |
| 11549 | auto LSICopy = *LSI; |
| 11550 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 11551 | /*IsInstantiation*/ true); |
| 11552 | SavedContext.pop(); |
| 11553 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11554 | return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11555 | &LSICopy); |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11556 | } |
| 11557 | |
| 11558 | template<typename Derived> |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11559 | StmtResult |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11560 | TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11561 | return TransformStmt(S); |
| 11562 | } |
| 11563 | |
| 11564 | template<typename Derived> |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11565 | StmtResult |
| 11566 | TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { |
| 11567 | // Transform captures. |
| 11568 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 11569 | CEnd = E->capture_end(); |
| 11570 | C != CEnd; ++C) { |
| 11571 | // When we hit the first implicit capture, tell Sema that we've finished |
| 11572 | // the list of explicit captures. |
| 11573 | if (!C->isImplicit()) |
| 11574 | continue; |
| 11575 | |
| 11576 | // Capturing 'this' is trivial. |
| 11577 | if (C->capturesThis()) { |
| 11578 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 11579 | /*BuildAndDiagnose*/ true, nullptr, |
| 11580 | C->getCaptureKind() == LCK_StarThis); |
| 11581 | continue; |
| 11582 | } |
| 11583 | // Captured expression will be recaptured during captured variables |
| 11584 | // rebuilding. |
| 11585 | if (C->capturesVLAType()) |
| 11586 | continue; |
| 11587 | |
| 11588 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 11589 | assert(!E->isInitCapture(C) && "implicit init-capture?"); |
| 11590 | |
| 11591 | // Transform the captured variable. |
| 11592 | VarDecl *CapturedVar = cast_or_null<VarDecl>( |
| 11593 | getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); |
| 11594 | if (!CapturedVar || CapturedVar->isInvalidDecl()) |
| 11595 | return StmtError(); |
| 11596 | |
| 11597 | // Capture the transformed variable. |
| 11598 | getSema().tryCaptureVariable(CapturedVar, C->getLocation()); |
| 11599 | } |
| 11600 | |
| 11601 | return S; |
| 11602 | } |
| 11603 | |
| 11604 | template<typename Derived> |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11605 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11606 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11607 | CXXUnresolvedConstructExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 11608 | TypeSourceInfo *T = |
| 11609 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11610 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11611 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11612 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11613 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11614 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11615 | Args.reserve(E->arg_size()); |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11616 | { |
| 11617 | EnterExpressionEvaluationContext Context( |
| 11618 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11619 | E->isListInitialization()); |
| 11620 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 11621 | &ArgumentChanged)) |
| 11622 | return ExprError(); |
| 11623 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11624 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11625 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11626 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11627 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11628 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11629 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11630 | // FIXME: we're faking the locations of the commas |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11631 | return getDerived().RebuildCXXUnresolvedConstructExpr( |
| 11632 | T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11633 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11634 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11635 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11636 | ExprResult |
| John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 11637 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11638 | CXXDependentScopeMemberExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11639 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11640 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11641 | Expr *OldBase; |
| 11642 | QualType BaseType; |
| 11643 | QualType ObjectType; |
| 11644 | if (!E->isImplicitAccess()) { |
| 11645 | OldBase = E->getBase(); |
| 11646 | Base = getDerived().TransformExpr(OldBase); |
| 11647 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11648 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11649 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11650 | // Start the member reference and compute the object's type. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11651 | ParsedType ObjectTy; |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11652 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11653 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11654 | E->getOperatorLoc(), |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11655 | E->isArrow()? tok::arrow : tok::period, |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11656 | ObjectTy, |
| 11657 | MayBePseudoDestructor); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11658 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11659 | return ExprError(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11660 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11661 | ObjectType = ObjectTy.get(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11662 | BaseType = ((Expr*) Base.get())->getType(); |
| 11663 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11664 | OldBase = nullptr; |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11665 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 11666 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 11667 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11668 | |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11669 | // Transform the first part of the nested-name-specifier that qualifies |
| 11670 | // the member name. |
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 11671 | NamedDecl *FirstQualifierInScope |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11672 | = getDerived().TransformFirstQualifierInScope( |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11673 | E->getFirstQualifierFoundInScope(), |
| 11674 | E->getQualifierLoc().getBeginLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11675 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11676 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11677 | if (E->getQualifier()) { |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11678 | QualifierLoc |
| 11679 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 11680 | ObjectType, |
| 11681 | FirstQualifierInScope); |
| 11682 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11683 | return ExprError(); |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11684 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11685 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11686 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 11687 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11688 | // TODO: If this is a conversion-function-id, verify that the |
| 11689 | // destination type name (if present) resolves the same way after |
| 11690 | // instantiation as it did in the local scope. |
| 11691 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11692 | DeclarationNameInfo NameInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11693 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11694 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11695 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11696 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11697 | if (!E->hasExplicitTemplateArgs()) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11698 | // This is a reference to a member without an explicitly-specified |
| 11699 | // template argument list. Optimize for this common case. |
| 11700 | if (!getDerived().AlwaysRebuild() && |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11701 | Base.get() == OldBase && |
| 11702 | BaseType == E->getBaseType() && |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11703 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11704 | NameInfo.getName() == E->getMember() && |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11705 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11706 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11707 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11708 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11709 | BaseType, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11710 | E->isArrow(), |
| 11711 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11712 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11713 | TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11714 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11715 | NameInfo, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11716 | /*TemplateArgs*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11717 | } |
| 11718 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11719 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11720 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 11721 | E->getNumTemplateArgs(), |
| 11722 | TransArgs)) |
| 11723 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11724 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11725 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11726 | BaseType, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11727 | E->isArrow(), |
| 11728 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11729 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11730 | TemplateKWLoc, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11731 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11732 | NameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11733 | &TransArgs); |
| 11734 | } |
| 11735 | |
| 11736 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11737 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11738 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11739 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11740 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11741 | QualType BaseType; |
| 11742 | if (!Old->isImplicitAccess()) { |
| 11743 | Base = getDerived().TransformExpr(Old->getBase()); |
| 11744 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11745 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11746 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 11747 | Old->isArrow()); |
| 11748 | if (Base.isInvalid()) |
| 11749 | return ExprError(); |
| 11750 | BaseType = Base.get()->getType(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11751 | } else { |
| 11752 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 11753 | } |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11754 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11755 | NestedNameSpecifierLoc QualifierLoc; |
| 11756 | if (Old->getQualifierLoc()) { |
| 11757 | QualifierLoc |
| 11758 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 11759 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11760 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11761 | } |
| 11762 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11763 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 11764 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11765 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11766 | Sema::LookupOrdinaryName); |
| 11767 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 11768 | // Transform the declaration set. |
| 11769 | if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R)) |
| 11770 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11771 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11772 | // Determine the naming class. |
| Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 11773 | if (Old->getNamingClass()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11774 | CXXRecordDecl *NamingClass |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11775 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11776 | Old->getMemberLoc(), |
| 11777 | Old->getNamingClass())); |
| 11778 | if (!NamingClass) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11779 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11780 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11781 | R.setNamingClass(NamingClass); |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11782 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11783 | |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11784 | TemplateArgumentListInfo TransArgs; |
| 11785 | if (Old->hasExplicitTemplateArgs()) { |
| 11786 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 11787 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11788 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 11789 | Old->getNumTemplateArgs(), |
| 11790 | TransArgs)) |
| 11791 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11792 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11793 | |
| 11794 | // FIXME: to do this check properly, we will need to preserve the |
| 11795 | // first-qualifier-in-scope here, just in case we had a dependent |
| 11796 | // base (and therefore couldn't do the check) and a |
| 11797 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11798 | NamedDecl *FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11799 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11800 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11801 | BaseType, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11802 | Old->getOperatorLoc(), |
| 11803 | Old->isArrow(), |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11804 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11805 | TemplateKWLoc, |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11806 | FirstQualifierInScope, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11807 | R, |
| 11808 | (Old->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11809 | ? &TransArgs : nullptr)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11810 | } |
| 11811 | |
| 11812 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11813 | ExprResult |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11814 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11815 | EnterExpressionEvaluationContext Unevaluated( |
| 11816 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11817 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 11818 | if (SubExpr.isInvalid()) |
| 11819 | return ExprError(); |
| 11820 | |
| 11821 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11822 | return E; |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11823 | |
| 11824 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 11825 | } |
| 11826 | |
| 11827 | template<typename Derived> |
| 11828 | ExprResult |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11829 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11830 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 11831 | if (Pattern.isInvalid()) |
| 11832 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11833 | |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11834 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11835 | return E; |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11836 | |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 11837 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 11838 | E->getNumExpansions()); |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11839 | } |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11840 | |
| 11841 | template<typename Derived> |
| 11842 | ExprResult |
| 11843 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 11844 | // If E is not value-dependent, then nothing will change when we transform it. |
| 11845 | // Note: This is an instantiation-centric view. |
| 11846 | if (!E->isValueDependent()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11847 | return E; |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11848 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11849 | EnterExpressionEvaluationContext Unevaluated( |
| 11850 | getSema(), Sema::ExpressionEvaluationContext::Unevaluated); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11851 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11852 | ArrayRef<TemplateArgument> PackArgs; |
| 11853 | TemplateArgument ArgStorage; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11854 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11855 | // Find the argument list to transform. |
| 11856 | if (E->isPartiallySubstituted()) { |
| 11857 | PackArgs = E->getPartialArguments(); |
| 11858 | } else if (E->isValueDependent()) { |
| 11859 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 11860 | bool ShouldExpand = false; |
| 11861 | bool RetainExpansion = false; |
| 11862 | Optional<unsigned> NumExpansions; |
| 11863 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 11864 | Unexpanded, |
| 11865 | ShouldExpand, RetainExpansion, |
| 11866 | NumExpansions)) |
| 11867 | return ExprError(); |
| 11868 | |
| 11869 | // If we need to expand the pack, build a template argument from it and |
| 11870 | // expand that. |
| 11871 | if (ShouldExpand) { |
| 11872 | auto *Pack = E->getPack(); |
| 11873 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 11874 | ArgStorage = getSema().Context.getPackExpansionType( |
| 11875 | getSema().Context.getTypeDeclType(TTPD), None); |
| 11876 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 11877 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 11878 | } else { |
| 11879 | auto *VD = cast<ValueDecl>(Pack); |
| Richard Smith | f1f20e6 | 2018-02-14 02:07:53 +0000 | [diff] [blame] | 11880 | ExprResult DRE = getSema().BuildDeclRefExpr( |
| 11881 | VD, VD->getType().getNonLValueExprType(getSema().Context), |
| 11882 | VD->getType()->isReferenceType() ? VK_LValue : VK_RValue, |
| 11883 | E->getPackLoc()); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11884 | if (DRE.isInvalid()) |
| 11885 | return ExprError(); |
| 11886 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 11887 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 11888 | } |
| 11889 | PackArgs = ArgStorage; |
| 11890 | } |
| 11891 | } |
| 11892 | |
| 11893 | // If we're not expanding the pack, just transform the decl. |
| 11894 | if (!PackArgs.size()) { |
| 11895 | auto *Pack = cast_or_null<NamedDecl>( |
| 11896 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11897 | if (!Pack) |
| 11898 | return ExprError(); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11899 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 11900 | E->getPackLoc(), |
| 11901 | E->getRParenLoc(), None, None); |
| 11902 | } |
| 11903 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11904 | // Try to compute the result without performing a partial substitution. |
| 11905 | Optional<unsigned> Result = 0; |
| 11906 | for (const TemplateArgument &Arg : PackArgs) { |
| 11907 | if (!Arg.isPackExpansion()) { |
| 11908 | Result = *Result + 1; |
| 11909 | continue; |
| 11910 | } |
| 11911 | |
| 11912 | TemplateArgumentLoc ArgLoc; |
| 11913 | InventTemplateArgumentLoc(Arg, ArgLoc); |
| 11914 | |
| 11915 | // Find the pattern of the pack expansion. |
| 11916 | SourceLocation Ellipsis; |
| 11917 | Optional<unsigned> OrigNumExpansions; |
| 11918 | TemplateArgumentLoc Pattern = |
| 11919 | getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, |
| 11920 | OrigNumExpansions); |
| 11921 | |
| 11922 | // Substitute under the pack expansion. Do not expand the pack (yet). |
| 11923 | TemplateArgumentLoc OutPattern; |
| 11924 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11925 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, |
| 11926 | /*Uneval*/ true)) |
| 11927 | return true; |
| 11928 | |
| 11929 | // See if we can determine the number of arguments from the result. |
| 11930 | Optional<unsigned> NumExpansions = |
| 11931 | getSema().getFullyPackExpandedSize(OutPattern.getArgument()); |
| 11932 | if (!NumExpansions) { |
| 11933 | // No: we must be in an alias template expansion, and we're going to need |
| 11934 | // to actually expand the packs. |
| 11935 | Result = None; |
| 11936 | break; |
| 11937 | } |
| 11938 | |
| 11939 | Result = *Result + *NumExpansions; |
| 11940 | } |
| 11941 | |
| 11942 | // Common case: we could determine the number of expansions without |
| 11943 | // substituting. |
| 11944 | if (Result) |
| 11945 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11946 | E->getPackLoc(), |
| 11947 | E->getRParenLoc(), *Result, None); |
| 11948 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11949 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 11950 | E->getPackLoc()); |
| 11951 | { |
| 11952 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 11953 | typedef TemplateArgumentLocInventIterator< |
| 11954 | Derived, const TemplateArgument*> PackLocIterator; |
| 11955 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 11956 | PackLocIterator(*this, PackArgs.end()), |
| 11957 | TransformedPackArgs, /*Uneval*/true)) |
| 11958 | return ExprError(); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11959 | } |
| 11960 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11961 | // Check whether we managed to fully-expand the pack. |
| 11962 | // 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] | 11963 | SmallVector<TemplateArgument, 8> Args; |
| 11964 | bool PartialSubstitution = false; |
| 11965 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 11966 | Args.push_back(Loc.getArgument()); |
| 11967 | if (Loc.getArgument().isPackExpansion()) |
| 11968 | PartialSubstitution = true; |
| 11969 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11970 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11971 | if (PartialSubstitution) |
| 11972 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11973 | E->getPackLoc(), |
| 11974 | E->getRParenLoc(), None, Args); |
| 11975 | |
| 11976 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11977 | E->getPackLoc(), E->getRParenLoc(), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11978 | Args.size(), None); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11979 | } |
| 11980 | |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11981 | template<typename Derived> |
| 11982 | ExprResult |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11983 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 11984 | SubstNonTypeTemplateParmPackExpr *E) { |
| 11985 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11986 | return E; |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11987 | } |
| 11988 | |
| 11989 | template<typename Derived> |
| 11990 | ExprResult |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11991 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 11992 | SubstNonTypeTemplateParmExpr *E) { |
| 11993 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11994 | return E; |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11995 | } |
| 11996 | |
| 11997 | template<typename Derived> |
| 11998 | ExprResult |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 11999 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 12000 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12001 | return E; |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 12002 | } |
| 12003 | |
| 12004 | template<typename Derived> |
| 12005 | ExprResult |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 12006 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 12007 | MaterializeTemporaryExpr *E) { |
| 12008 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 12009 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12010 | |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 12011 | template<typename Derived> |
| 12012 | ExprResult |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12013 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 12014 | Expr *Pattern = E->getPattern(); |
| 12015 | |
| 12016 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 12017 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 12018 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 12019 | |
| 12020 | // Determine whether the set of unexpanded parameter packs can and should |
| 12021 | // be expanded. |
| 12022 | bool Expand = true; |
| 12023 | bool RetainExpansion = false; |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12024 | Optional<unsigned> OrigNumExpansions = E->getNumExpansions(), |
| 12025 | NumExpansions = OrigNumExpansions; |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12026 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 12027 | Pattern->getSourceRange(), |
| 12028 | Unexpanded, |
| 12029 | Expand, RetainExpansion, |
| 12030 | NumExpansions)) |
| 12031 | return true; |
| 12032 | |
| 12033 | if (!Expand) { |
| 12034 | // Do not expand any packs here, just transform and rebuild a fold |
| 12035 | // expression. |
| 12036 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 12037 | |
| 12038 | ExprResult LHS = |
| 12039 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 12040 | if (LHS.isInvalid()) |
| 12041 | return true; |
| 12042 | |
| 12043 | ExprResult RHS = |
| 12044 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 12045 | if (RHS.isInvalid()) |
| 12046 | return true; |
| 12047 | |
| 12048 | if (!getDerived().AlwaysRebuild() && |
| 12049 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 12050 | return E; |
| 12051 | |
| 12052 | return getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12053 | E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12054 | RHS.get(), E->getEndLoc(), NumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12055 | } |
| 12056 | |
| 12057 | // The transform has determined that we should perform an elementwise |
| 12058 | // expansion of the pattern. Do so. |
| 12059 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 12060 | if (Result.isInvalid()) |
| 12061 | return true; |
| 12062 | bool LeftFold = E->isLeftFold(); |
| 12063 | |
| 12064 | // If we're retaining an expansion for a right fold, it is the innermost |
| 12065 | // component and takes the init (if any). |
| 12066 | if (!LeftFold && RetainExpansion) { |
| 12067 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 12068 | |
| 12069 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12070 | if (Out.isInvalid()) |
| 12071 | return true; |
| 12072 | |
| 12073 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12074 | E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12075 | Result.get(), E->getEndLoc(), OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12076 | if (Result.isInvalid()) |
| 12077 | return true; |
| 12078 | } |
| 12079 | |
| 12080 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12081 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 12082 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 12083 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12084 | if (Out.isInvalid()) |
| 12085 | return true; |
| 12086 | |
| 12087 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 12088 | // We still have a pack; retain a pack expansion for this slice. |
| 12089 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12090 | E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12091 | E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12092 | LeftFold ? Out.get() : Result.get(), E->getEndLoc(), |
| 12093 | OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12094 | } else if (Result.isUsable()) { |
| 12095 | // We've got down to a single element; build a binary operator. |
| 12096 | Result = getDerived().RebuildBinaryOperator( |
| 12097 | E->getEllipsisLoc(), E->getOperator(), |
| 12098 | LeftFold ? Result.get() : Out.get(), |
| 12099 | LeftFold ? Out.get() : Result.get()); |
| 12100 | } else |
| 12101 | Result = Out; |
| 12102 | |
| 12103 | if (Result.isInvalid()) |
| 12104 | return true; |
| 12105 | } |
| 12106 | |
| 12107 | // If we're retaining an expansion for a left fold, it is the outermost |
| 12108 | // component and takes the complete expansion so far as its init (if any). |
| 12109 | if (LeftFold && RetainExpansion) { |
| 12110 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 12111 | |
| 12112 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12113 | if (Out.isInvalid()) |
| 12114 | return true; |
| 12115 | |
| 12116 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12117 | E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12118 | Out.get(), E->getEndLoc(), OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12119 | if (Result.isInvalid()) |
| 12120 | return true; |
| 12121 | } |
| 12122 | |
| 12123 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 12124 | // then produce a fallback value or error. |
| 12125 | if (Result.isUnset()) |
| 12126 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 12127 | E->getOperator()); |
| 12128 | |
| 12129 | return Result; |
| 12130 | } |
| 12131 | |
| 12132 | template<typename Derived> |
| 12133 | ExprResult |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 12134 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 12135 | CXXStdInitializerListExpr *E) { |
| 12136 | return getDerived().TransformExpr(E->getSubExpr()); |
| 12137 | } |
| 12138 | |
| 12139 | template<typename Derived> |
| 12140 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12141 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12142 | return SemaRef.MaybeBindToTemporary(E); |
| 12143 | } |
| 12144 | |
| 12145 | template<typename Derived> |
| 12146 | ExprResult |
| 12147 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12148 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12149 | } |
| 12150 | |
| 12151 | template<typename Derived> |
| 12152 | ExprResult |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 12153 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 12154 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 12155 | if (SubExpr.isInvalid()) |
| 12156 | return ExprError(); |
| 12157 | |
| 12158 | if (!getDerived().AlwaysRebuild() && |
| 12159 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12160 | return E; |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 12161 | |
| 12162 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12163 | } |
| 12164 | |
| 12165 | template<typename Derived> |
| 12166 | ExprResult |
| 12167 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 12168 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 12169 | SmallVector<Expr *, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12170 | bool ArgChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12171 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12172 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 12173 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12174 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12175 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 12176 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12177 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12178 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 12179 | Elements.data(), |
| 12180 | Elements.size()); |
| 12181 | } |
| 12182 | |
| 12183 | template<typename Derived> |
| 12184 | ExprResult |
| 12185 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12186 | ObjCDictionaryLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12187 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 12188 | SmallVector<ObjCDictionaryElement, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12189 | bool ArgChanged = false; |
| 12190 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 12191 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12192 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12193 | if (OrigElement.isPackExpansion()) { |
| 12194 | // This key/value element is a pack expansion. |
| 12195 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 12196 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 12197 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 12198 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 12199 | |
| 12200 | // Determine whether the set of unexpanded parameter packs can |
| 12201 | // and should be expanded. |
| 12202 | bool Expand = true; |
| 12203 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 12204 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 12205 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12206 | SourceRange PatternRange(OrigElement.Key->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 12207 | OrigElement.Value->getEndLoc()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12208 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 12209 | PatternRange, Unexpanded, Expand, |
| 12210 | RetainExpansion, NumExpansions)) |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12211 | return ExprError(); |
| 12212 | |
| 12213 | if (!Expand) { |
| 12214 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12215 | // transformation on the pack expansion, producing another pack |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12216 | // expansion. |
| 12217 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 12218 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12219 | if (Key.isInvalid()) |
| 12220 | return ExprError(); |
| 12221 | |
| 12222 | if (Key.get() != OrigElement.Key) |
| 12223 | ArgChanged = true; |
| 12224 | |
| 12225 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 12226 | if (Value.isInvalid()) |
| 12227 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12228 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12229 | if (Value.get() != OrigElement.Value) |
| 12230 | ArgChanged = true; |
| 12231 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12232 | ObjCDictionaryElement Expansion = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12233 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 12234 | }; |
| 12235 | Elements.push_back(Expansion); |
| 12236 | continue; |
| 12237 | } |
| 12238 | |
| 12239 | // Record right away that the argument was changed. This needs |
| 12240 | // to happen even if the array expands to nothing. |
| 12241 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12242 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12243 | // The transform has determined that we should perform an elementwise |
| 12244 | // expansion of the pattern. Do so. |
| 12245 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12246 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 12247 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12248 | if (Key.isInvalid()) |
| 12249 | return ExprError(); |
| 12250 | |
| 12251 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 12252 | if (Value.isInvalid()) |
| 12253 | return ExprError(); |
| 12254 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12255 | ObjCDictionaryElement Element = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12256 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 12257 | }; |
| 12258 | |
| 12259 | // If any unexpanded parameter packs remain, we still have a |
| 12260 | // pack expansion. |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 12261 | // FIXME: Can this really happen? |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12262 | if (Key.get()->containsUnexpandedParameterPack() || |
| 12263 | Value.get()->containsUnexpandedParameterPack()) |
| 12264 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12265 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12266 | Elements.push_back(Element); |
| 12267 | } |
| 12268 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 12269 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 12270 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12271 | // We've finished with this pack expansion. |
| 12272 | continue; |
| 12273 | } |
| 12274 | |
| 12275 | // Transform and check key. |
| 12276 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12277 | if (Key.isInvalid()) |
| 12278 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12279 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12280 | if (Key.get() != OrigElement.Key) |
| 12281 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12282 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12283 | // Transform and check value. |
| 12284 | ExprResult Value |
| 12285 | = getDerived().TransformExpr(OrigElement.Value); |
| 12286 | if (Value.isInvalid()) |
| 12287 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12288 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12289 | if (Value.get() != OrigElement.Value) |
| 12290 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12291 | |
| 12292 | ObjCDictionaryElement Element = { |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 12293 | Key.get(), Value.get(), SourceLocation(), None |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12294 | }; |
| 12295 | Elements.push_back(Element); |
| 12296 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12297 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12298 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 12299 | return SemaRef.MaybeBindToTemporary(E); |
| 12300 | |
| 12301 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 12302 | Elements); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12303 | } |
| 12304 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12305 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12306 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12307 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12308 | TypeSourceInfo *EncodedTypeInfo |
| 12309 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 12310 | if (!EncodedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12311 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12312 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12313 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12314 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12315 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12316 | |
| 12317 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12318 | EncodedTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12319 | E->getRParenLoc()); |
| 12320 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12321 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12322 | template<typename Derived> |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12323 | ExprResult TreeTransform<Derived>:: |
| 12324 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 12325 | // This is a kind of implicit conversion, and it needs to get dropped |
| 12326 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 12327 | // do, as well a more specific one: this expression is only valid when |
| 12328 | // it appears *immediately* as an argument expression. |
| 12329 | return getDerived().TransformExpr(E->getSubExpr()); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12330 | } |
| 12331 | |
| 12332 | template<typename Derived> |
| 12333 | ExprResult TreeTransform<Derived>:: |
| 12334 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12335 | TypeSourceInfo *TSInfo |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12336 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 12337 | if (!TSInfo) |
| 12338 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12339 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12340 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12341 | if (Result.isInvalid()) |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12342 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12343 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12344 | if (!getDerived().AlwaysRebuild() && |
| 12345 | TSInfo == E->getTypeInfoAsWritten() && |
| 12346 | Result.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12347 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12348 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12349 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12350 | E->getBridgeKeywordLoc(), TSInfo, |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12351 | Result.get()); |
| 12352 | } |
| 12353 | |
| Erik Pilkington | 29099de | 2016-07-16 00:35:23 +0000 | [diff] [blame] | 12354 | template <typename Derived> |
| 12355 | ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( |
| 12356 | ObjCAvailabilityCheckExpr *E) { |
| 12357 | return E; |
| 12358 | } |
| 12359 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12360 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12361 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12362 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12363 | // Transform arguments. |
| 12364 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12365 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12366 | Args.reserve(E->getNumArgs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12367 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12368 | &ArgChanged)) |
| 12369 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12370 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12371 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 12372 | // Class message: transform the receiver type. |
| 12373 | TypeSourceInfo *ReceiverTypeInfo |
| 12374 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 12375 | if (!ReceiverTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12376 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12377 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12378 | // If nothing changed, just retain the existing message send. |
| 12379 | if (!getDerived().AlwaysRebuild() && |
| 12380 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12381 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12382 | |
| 12383 | // Build a new class message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12384 | SmallVector<SourceLocation, 16> SelLocs; |
| 12385 | E->getSelectorLocs(SelLocs); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12386 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 12387 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12388 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12389 | E->getMethodDecl(), |
| 12390 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12391 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12392 | E->getRightLoc()); |
| 12393 | } |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12394 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 12395 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| Bruno Cardoso Lopes | 25f02cf | 2016-08-22 21:50:22 +0000 | [diff] [blame] | 12396 | if (!E->getMethodDecl()) |
| 12397 | return ExprError(); |
| 12398 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12399 | // Build a new class message send to 'super'. |
| 12400 | SmallVector<SourceLocation, 16> SelLocs; |
| 12401 | E->getSelectorLocs(SelLocs); |
| 12402 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 12403 | E->getSelector(), |
| 12404 | SelLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 12405 | E->getReceiverType(), |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12406 | E->getMethodDecl(), |
| 12407 | E->getLeftLoc(), |
| 12408 | Args, |
| 12409 | E->getRightLoc()); |
| 12410 | } |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12411 | |
| 12412 | // Instance message: transform the receiver |
| 12413 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 12414 | "Only class and instance messages may be instantiated"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12415 | ExprResult Receiver |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12416 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 12417 | if (Receiver.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12418 | return ExprError(); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12419 | |
| 12420 | // If nothing changed, just retain the existing message send. |
| 12421 | if (!getDerived().AlwaysRebuild() && |
| 12422 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12423 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12424 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12425 | // Build a new instance message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12426 | SmallVector<SourceLocation, 16> SelLocs; |
| 12427 | E->getSelectorLocs(SelLocs); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12428 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12429 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12430 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12431 | E->getMethodDecl(), |
| 12432 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12433 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12434 | E->getRightLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12435 | } |
| 12436 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12437 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12438 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12439 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12440 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12441 | } |
| 12442 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12443 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12444 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12445 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12446 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12447 | } |
| 12448 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12449 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12450 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12451 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12452 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12453 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12454 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12455 | return ExprError(); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12456 | |
| 12457 | // We don't need to transform the ivar; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12458 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12459 | // If nothing changed, just retain the existing expression. |
| 12460 | if (!getDerived().AlwaysRebuild() && |
| 12461 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12462 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12463 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12464 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12465 | E->getLocation(), |
| 12466 | E->isArrow(), E->isFreeIvar()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12467 | } |
| 12468 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12469 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12470 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12471 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12472 | // 'super' and types never change. Property never changes. Just |
| 12473 | // retain the existing expression. |
| 12474 | if (!E->isObjectReceiver()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12475 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12476 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12477 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12478 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12479 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12480 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12481 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12482 | // We don't need to transform the property; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12483 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12484 | // If nothing changed, just retain the existing expression. |
| 12485 | if (!getDerived().AlwaysRebuild() && |
| 12486 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12487 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12488 | |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12489 | if (E->isExplicitProperty()) |
| 12490 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 12491 | E->getExplicitProperty(), |
| 12492 | E->getLocation()); |
| 12493 | |
| 12494 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 12495 | SemaRef.Context.PseudoObjectTy, |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12496 | E->getImplicitPropertyGetter(), |
| 12497 | E->getImplicitPropertySetter(), |
| 12498 | E->getLocation()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12499 | } |
| 12500 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12501 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12502 | ExprResult |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12503 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 12504 | // Transform the base expression. |
| 12505 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 12506 | if (Base.isInvalid()) |
| 12507 | return ExprError(); |
| 12508 | |
| 12509 | // Transform the key expression. |
| 12510 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 12511 | if (Key.isInvalid()) |
| 12512 | return ExprError(); |
| 12513 | |
| 12514 | // If nothing changed, just retain the existing expression. |
| 12515 | if (!getDerived().AlwaysRebuild() && |
| 12516 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12517 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12518 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12519 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12520 | Base.get(), Key.get(), |
| 12521 | E->getAtIndexMethodDecl(), |
| 12522 | E->setAtIndexMethodDecl()); |
| 12523 | } |
| 12524 | |
| 12525 | template<typename Derived> |
| 12526 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12527 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12528 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12529 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12530 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12531 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12532 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12533 | // If nothing changed, just retain the existing expression. |
| 12534 | if (!getDerived().AlwaysRebuild() && |
| 12535 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12536 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12537 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12538 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 12539 | E->getOpLoc(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12540 | E->isArrow()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12541 | } |
| 12542 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12543 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12544 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12545 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12546 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12547 | SmallVector<Expr*, 8> SubExprs; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12548 | SubExprs.reserve(E->getNumSubExprs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12549 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12550 | SubExprs, &ArgumentChanged)) |
| 12551 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12552 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12553 | if (!getDerived().AlwaysRebuild() && |
| 12554 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12555 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12556 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12557 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12558 | SubExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12559 | E->getRParenLoc()); |
| 12560 | } |
| 12561 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12562 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12563 | ExprResult |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12564 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 12565 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 12566 | if (SrcExpr.isInvalid()) |
| 12567 | return ExprError(); |
| 12568 | |
| 12569 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 12570 | if (!Type) |
| 12571 | return ExprError(); |
| 12572 | |
| 12573 | if (!getDerived().AlwaysRebuild() && |
| 12574 | Type == E->getTypeSourceInfo() && |
| 12575 | SrcExpr.get() == E->getSrcExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12576 | return E; |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12577 | |
| 12578 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 12579 | SrcExpr.get(), Type, |
| 12580 | E->getRParenLoc()); |
| 12581 | } |
| 12582 | |
| 12583 | template<typename Derived> |
| 12584 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12585 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12586 | BlockDecl *oldBlock = E->getBlockDecl(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12587 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12588 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12589 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 12590 | |
| 12591 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 12592 | blockScope->TheDecl->setBlockMissingReturnType( |
| 12593 | oldBlock->blockMissingReturnType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12594 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 12595 | SmallVector<ParmVarDecl*, 4> params; |
| 12596 | SmallVector<QualType, 4> paramTypes; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12597 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12598 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 12599 | |
| Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 12600 | // Parameter substitution. |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12601 | Sema::ExtParameterInfoBuilder extParamInfos; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 12602 | if (getDerived().TransformFunctionTypeParams( |
| 12603 | E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 12604 | exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 12605 | extParamInfos)) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12606 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12607 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12608 | } |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12609 | |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12610 | QualType exprResultType = |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 12611 | getDerived().TransformType(exprFunctionType->getReturnType()); |
| Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 12612 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12613 | auto epi = exprFunctionType->getExtProtoInfo(); |
| 12614 | epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 12615 | |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12616 | QualType functionType = |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12617 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12618 | blockScope->FunctionType = functionType; |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12619 | |
| 12620 | // Set the parameters on the block decl. |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12621 | if (!params.empty()) |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 12622 | blockScope->TheDecl->setParams(params); |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12623 | |
| 12624 | if (!oldBlock->blockMissingReturnType()) { |
| 12625 | blockScope->HasImplicitReturnType = false; |
| 12626 | blockScope->ReturnType = exprResultType; |
| 12627 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12628 | |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12629 | // Transform the body |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12630 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12631 | if (body.isInvalid()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12632 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12633 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12634 | } |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12635 | |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12636 | #ifndef NDEBUG |
| 12637 | // In builds with assertions, make sure that we captured everything we |
| 12638 | // captured before. |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12639 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 12640 | for (const auto &I : oldBlock->captures()) { |
| 12641 | VarDecl *oldCapture = I.getVariable(); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12642 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12643 | // Ignore parameter packs. |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 12644 | if (oldCapture->isParameterPack()) |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12645 | continue; |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12646 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12647 | VarDecl *newCapture = |
| 12648 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 12649 | oldCapture)); |
| 12650 | assert(blockScope->CaptureMap.count(newCapture)); |
| 12651 | } |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 12652 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12653 | } |
| 12654 | #endif |
| 12655 | |
| 12656 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12657 | /*Scope=*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12658 | } |
| 12659 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12660 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12661 | ExprResult |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12662 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 12663 | llvm_unreachable("Cannot transform asType expressions yet"); |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12664 | } |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12665 | |
| 12666 | template<typename Derived> |
| 12667 | ExprResult |
| 12668 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12669 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 12670 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12671 | SmallVector<Expr*, 8> SubExprs; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12672 | SubExprs.reserve(E->getNumSubExprs()); |
| 12673 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 12674 | SubExprs, &ArgumentChanged)) |
| 12675 | return ExprError(); |
| 12676 | |
| 12677 | if (!getDerived().AlwaysRebuild() && |
| 12678 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12679 | return E; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12680 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12681 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12682 | RetTy, E->getOp(), E->getRParenLoc()); |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12683 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12684 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12685 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12686 | // Type reconstruction |
| 12687 | //===----------------------------------------------------------------------===// |
| 12688 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12689 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12690 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 12691 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12692 | return SemaRef.BuildPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12693 | getDerived().getBaseEntity()); |
| 12694 | } |
| 12695 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12696 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12697 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 12698 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12699 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12700 | getDerived().getBaseEntity()); |
| 12701 | } |
| 12702 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12703 | template<typename Derived> |
| 12704 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12705 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 12706 | bool WrittenAsLValue, |
| 12707 | SourceLocation Sigil) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12708 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12709 | Sigil, getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12710 | } |
| 12711 | |
| 12712 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12713 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12714 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 12715 | QualType ClassType, |
| 12716 | SourceLocation Sigil) { |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 12717 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 12718 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12719 | } |
| 12720 | |
| 12721 | template<typename Derived> |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 12722 | QualType TreeTransform<Derived>::RebuildObjCTypeParamType( |
| 12723 | const ObjCTypeParamDecl *Decl, |
| 12724 | SourceLocation ProtocolLAngleLoc, |
| 12725 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12726 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12727 | SourceLocation ProtocolRAngleLoc) { |
| 12728 | return SemaRef.BuildObjCTypeParamType(Decl, |
| 12729 | ProtocolLAngleLoc, Protocols, |
| 12730 | ProtocolLocs, ProtocolRAngleLoc, |
| 12731 | /*FailOnError=*/true); |
| 12732 | } |
| 12733 | |
| 12734 | template<typename Derived> |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 12735 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 12736 | QualType BaseType, |
| 12737 | SourceLocation Loc, |
| 12738 | SourceLocation TypeArgsLAngleLoc, |
| 12739 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 12740 | SourceLocation TypeArgsRAngleLoc, |
| 12741 | SourceLocation ProtocolLAngleLoc, |
| 12742 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12743 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12744 | SourceLocation ProtocolRAngleLoc) { |
| 12745 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 12746 | TypeArgs, TypeArgsRAngleLoc, |
| 12747 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 12748 | ProtocolRAngleLoc, |
| 12749 | /*FailOnError=*/true); |
| 12750 | } |
| 12751 | |
| 12752 | template<typename Derived> |
| 12753 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 12754 | QualType PointeeType, |
| 12755 | SourceLocation Star) { |
| 12756 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 12757 | } |
| 12758 | |
| 12759 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12760 | QualType |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12761 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 12762 | ArrayType::ArraySizeModifier SizeMod, |
| 12763 | const llvm::APInt *Size, |
| 12764 | Expr *SizeExpr, |
| 12765 | unsigned IndexTypeQuals, |
| 12766 | SourceRange BracketsRange) { |
| 12767 | if (SizeExpr || !Size) |
| 12768 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 12769 | IndexTypeQuals, BracketsRange, |
| 12770 | getDerived().getBaseEntity()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12771 | |
| 12772 | QualType Types[] = { |
| 12773 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 12774 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 12775 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12776 | }; |
| Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 12777 | const unsigned NumTypes = llvm::array_lengthof(Types); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12778 | QualType SizeType; |
| 12779 | for (unsigned I = 0; I != NumTypes; ++I) |
| 12780 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 12781 | SizeType = Types[I]; |
| 12782 | break; |
| 12783 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12784 | |
| Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 12785 | // Note that we can return a VariableArrayType here in the case where |
| 12786 | // the element type was a dependent VariableArrayType. |
| 12787 | IntegerLiteral *ArraySize |
| 12788 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 12789 | /*FIXME*/BracketsRange.getBegin()); |
| 12790 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12791 | IndexTypeQuals, BracketsRange, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12792 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12793 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12794 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12795 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12796 | QualType |
| 12797 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12798 | ArrayType::ArraySizeModifier SizeMod, |
| 12799 | const llvm::APInt &Size, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12800 | unsigned IndexTypeQuals, |
| 12801 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12802 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12803 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12804 | } |
| 12805 | |
| 12806 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12807 | QualType |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12808 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12809 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12810 | unsigned IndexTypeQuals, |
| 12811 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12812 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12813 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12814 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12815 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12816 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12817 | QualType |
| 12818 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12819 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12820 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12821 | unsigned IndexTypeQuals, |
| 12822 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12823 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12824 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12825 | IndexTypeQuals, BracketsRange); |
| 12826 | } |
| 12827 | |
| 12828 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12829 | QualType |
| 12830 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12831 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12832 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12833 | unsigned IndexTypeQuals, |
| 12834 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12835 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12836 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12837 | IndexTypeQuals, BracketsRange); |
| 12838 | } |
| 12839 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 12840 | template <typename Derived> |
| 12841 | QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( |
| 12842 | QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { |
| 12843 | return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, |
| 12844 | AttributeLoc); |
| 12845 | } |
| 12846 | |
| 12847 | template <typename Derived> |
| 12848 | QualType |
| 12849 | TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 12850 | unsigned NumElements, |
| 12851 | VectorType::VectorKind VecKind) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12852 | // FIXME: semantic checking! |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 12853 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12854 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12855 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 12856 | template <typename Derived> |
| 12857 | QualType TreeTransform<Derived>::RebuildDependentVectorType( |
| 12858 | QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, |
| 12859 | VectorType::VectorKind VecKind) { |
| 12860 | return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); |
| 12861 | } |
| 12862 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12863 | template<typename Derived> |
| 12864 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 12865 | unsigned NumElements, |
| 12866 | SourceLocation AttributeLoc) { |
| 12867 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 12868 | NumElements, true); |
| 12869 | IntegerLiteral *VectorSize |
| Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 12870 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 12871 | AttributeLoc); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12872 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12873 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12874 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12875 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12876 | QualType |
| 12877 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12878 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12879 | SourceLocation AttributeLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12880 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12881 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12882 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12883 | template<typename Derived> |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12884 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 12885 | QualType T, |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 12886 | MutableArrayRef<QualType> ParamTypes, |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12887 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 12888 | return SemaRef.BuildFunctionType(T, ParamTypes, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12889 | getDerived().getBaseLocation(), |
| Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 12890 | getDerived().getBaseEntity(), |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12891 | EPI); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12892 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12893 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12894 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 12895 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 12896 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 12897 | } |
| 12898 | |
| 12899 | template<typename Derived> |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12900 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, |
| 12901 | Decl *D) { |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12902 | assert(D && "no decl found"); |
| 12903 | if (D->isInvalidDecl()) return QualType(); |
| 12904 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12905 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12906 | TypeDecl *Ty; |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12907 | if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { |
| 12908 | // A valid resolved using typename pack expansion decl can have multiple |
| 12909 | // UsingDecls, but they must each have exactly one type, and it must be |
| 12910 | // the same type in every case. But we must have at least one expansion! |
| 12911 | if (UPD->expansions().empty()) { |
| 12912 | getSema().Diag(Loc, diag::err_using_pack_expansion_empty) |
| 12913 | << UPD->isCXXClassMember() << UPD; |
| 12914 | return QualType(); |
| 12915 | } |
| 12916 | |
| 12917 | // We might still have some unresolved types. Try to pick a resolved type |
| 12918 | // if we can. The final instantiation will check that the remaining |
| 12919 | // unresolved types instantiate to the type we pick. |
| 12920 | QualType FallbackT; |
| 12921 | QualType T; |
| 12922 | for (auto *E : UPD->expansions()) { |
| 12923 | QualType ThisT = RebuildUnresolvedUsingType(Loc, E); |
| 12924 | if (ThisT.isNull()) |
| 12925 | continue; |
| 12926 | else if (ThisT->getAs<UnresolvedUsingType>()) |
| 12927 | FallbackT = ThisT; |
| 12928 | else if (T.isNull()) |
| 12929 | T = ThisT; |
| 12930 | else |
| 12931 | assert(getSema().Context.hasSameType(ThisT, T) && |
| 12932 | "mismatched resolved types in using pack expansion"); |
| 12933 | } |
| 12934 | return T.isNull() ? FallbackT : T; |
| 12935 | } else if (auto *Using = dyn_cast<UsingDecl>(D)) { |
| Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 12936 | assert(Using->hasTypename() && |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12937 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 12938 | |
| 12939 | // A valid resolved using typename decl points to exactly one type decl. |
| 12940 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 12941 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12942 | } else { |
| 12943 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 12944 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 12945 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 12946 | } |
| 12947 | |
| 12948 | return SemaRef.Context.getTypeDeclType(Ty); |
| 12949 | } |
| 12950 | |
| 12951 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12952 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 12953 | SourceLocation Loc) { |
| 12954 | return SemaRef.BuildTypeofExprType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12955 | } |
| 12956 | |
| 12957 | template<typename Derived> |
| 12958 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 12959 | return SemaRef.Context.getTypeOfType(Underlying); |
| 12960 | } |
| 12961 | |
| 12962 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12963 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 12964 | SourceLocation Loc) { |
| 12965 | return SemaRef.BuildDecltypeType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12966 | } |
| 12967 | |
| 12968 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 12969 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 12970 | UnaryTransformType::UTTKind UKind, |
| 12971 | SourceLocation Loc) { |
| 12972 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 12973 | } |
| 12974 | |
| 12975 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12976 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 12977 | TemplateName Template, |
| 12978 | SourceLocation TemplateNameLoc, |
| Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 12979 | TemplateArgumentListInfo &TemplateArgs) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 12980 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12981 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12982 | |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 12983 | template<typename Derived> |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 12984 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 12985 | SourceLocation KWLoc) { |
| 12986 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 12987 | } |
| 12988 | |
| 12989 | template<typename Derived> |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12990 | QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 12991 | SourceLocation KWLoc, |
| 12992 | bool isReadPipe) { |
| 12993 | return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) |
| 12994 | : SemaRef.BuildWritePipeType(ValueType, KWLoc); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12995 | } |
| 12996 | |
| 12997 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12998 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12999 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 13000 | bool TemplateKW, |
| 13001 | TemplateDecl *Template) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13002 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 13003 | Template); |
| 13004 | } |
| 13005 | |
| 13006 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13007 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13008 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 13009 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13010 | const IdentifierInfo &Name, |
| 13011 | SourceLocation NameLoc, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 13012 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 13013 | NamedDecl *FirstQualifierInScope, |
| 13014 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13015 | UnqualifiedId TemplateName; |
| 13016 | TemplateName.setIdentifier(&Name, NameLoc); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13017 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13018 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13019 | SS, TemplateKWLoc, TemplateName, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 13020 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13021 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 13022 | Template, AllowInjectedClassName); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 13023 | return Template.get(); |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 13024 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13025 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13026 | template<typename Derived> |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13027 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13028 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 13029 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13030 | OverloadedOperatorKind Operator, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13031 | SourceLocation NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 13032 | QualType ObjectType, |
| 13033 | bool AllowInjectedClassName) { |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13034 | UnqualifiedId Name; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13035 | // FIXME: Bogus location information. |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13036 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13037 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13038 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13039 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13040 | SS, TemplateKWLoc, Name, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 13041 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13042 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 13043 | Template, AllowInjectedClassName); |
| Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 13044 | return Template.get(); |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13045 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13046 | |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13047 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 13048 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13049 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 13050 | SourceLocation OpLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13051 | Expr *OrigCallee, |
| 13052 | Expr *First, |
| 13053 | Expr *Second) { |
| 13054 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 13055 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13056 | |
| Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 13057 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 13058 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 13059 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 13060 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 13061 | First, Second); |
| 13062 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 13063 | if (Result.isInvalid()) |
| 13064 | return ExprError(); |
| 13065 | First = Result.get(); |
| 13066 | } |
| 13067 | |
| 13068 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 13069 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 13070 | if (Result.isInvalid()) |
| 13071 | return ExprError(); |
| 13072 | Second = Result.get(); |
| 13073 | } |
| 13074 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13075 | // Determine whether this should be a builtin operation. |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 13076 | if (Op == OO_Subscript) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13077 | if (!First->getType()->isOverloadableType() && |
| 13078 | !Second->getType()->isOverloadableType()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13079 | return getSema().CreateBuiltinArraySubscriptExpr( |
| 13080 | First, Callee->getBeginLoc(), Second, OpLoc); |
| Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 13081 | } else if (Op == OO_Arrow) { |
| 13082 | // -> is never a builtin operation. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13083 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 13084 | } else if (Second == nullptr || isPostIncDec) { |
| Richard Smith | cc4ad95 | 2018-07-22 05:21:47 +0000 | [diff] [blame] | 13085 | if (!First->getType()->isOverloadableType() || |
| 13086 | (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { |
| 13087 | // The argument is not of overloadable type, or this is an expression |
| 13088 | // of the form &Class::member, so try to create a built-in unary |
| 13089 | // operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13090 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13091 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13092 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13093 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13094 | } |
| 13095 | } else { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13096 | if (!First->getType()->isOverloadableType() && |
| 13097 | !Second->getType()->isOverloadableType()) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13098 | // Neither of the arguments is an overloadable type, so try to |
| 13099 | // create a built-in binary operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13100 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 13101 | ExprResult Result |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13102 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13103 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 13104 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13105 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 13106 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13107 | } |
| 13108 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13109 | |
| 13110 | // Compute the transformed set of functions (and function templates) to be |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13111 | // used during overload resolution. |
| John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 13112 | UnresolvedSet<16> Functions; |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13113 | bool RequiresADL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13114 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13115 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
| Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 13116 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13117 | // If the overload could not be resolved in the template definition |
| 13118 | // (because we had a dependent argument), ADL is performed as part of |
| 13119 | // template instantiation. |
| 13120 | RequiresADL = ULE->requiresADL(); |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 13121 | } else { |
| Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 13122 | // If we've resolved this to a particular non-member function, just call |
| 13123 | // that function. If we resolved it to a member function, |
| 13124 | // CreateOverloaded* will find that function for us. |
| 13125 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 13126 | if (!isa<CXXMethodDecl>(ND)) |
| 13127 | Functions.addDecl(ND); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13128 | RequiresADL = false; |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 13129 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13130 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13131 | // Add any functions found via argument-dependent lookup. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13132 | Expr *Args[2] = { First, Second }; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13133 | unsigned NumArgs = 1 + (Second != nullptr); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13134 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13135 | // Create the overloaded operator invocation for unary operators. |
| 13136 | if (NumArgs == 1 || isPostIncDec) { |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13137 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13138 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13139 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, |
| 13140 | RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13141 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13142 | |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13143 | if (Op == OO_Subscript) { |
| 13144 | SourceLocation LBrace; |
| 13145 | SourceLocation RBrace; |
| 13146 | |
| 13147 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 13148 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13149 | LBrace = SourceLocation::getFromRawEncoding( |
| 13150 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 13151 | RBrace = SourceLocation::getFromRawEncoding( |
| 13152 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 13153 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13154 | LBrace = Callee->getBeginLoc(); |
| 13155 | RBrace = OpLoc; |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13156 | } |
| 13157 | |
| 13158 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 13159 | First, Second); |
| 13160 | } |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 13161 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13162 | // Create the overloaded operator invocation for binary operators. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13163 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13164 | ExprResult Result = SemaRef.CreateOverloadedBinOp( |
| 13165 | OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13166 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 13167 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13168 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 13169 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13170 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13171 | |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13172 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13173 | ExprResult |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13174 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13175 | SourceLocation OperatorLoc, |
| 13176 | bool isArrow, |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 13177 | CXXScopeSpec &SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13178 | TypeSourceInfo *ScopeType, |
| 13179 | SourceLocation CCLoc, |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 13180 | SourceLocation TildeLoc, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 13181 | PseudoDestructorTypeStorage Destroyed) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13182 | QualType BaseType = Base->getType(); |
| 13183 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13184 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13185 | (isArrow && BaseType->getAs<PointerType>() && |
| Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 13186 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 13187 | ->template getAs<RecordType>())){ |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13188 | // This pseudo-destructor expression is still a pseudo-destructor. |
| David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 13189 | return SemaRef.BuildPseudoDestructorExpr( |
| 13190 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 13191 | CCLoc, TildeLoc, Destroyed); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13192 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13193 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 13194 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13195 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 13196 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 13197 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 13198 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 13199 | |
| Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 13200 | // The scope type is now known to be a valid nested name specifier |
| 13201 | // component. Tack it on to the end of the nested name specifier. |
| Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 13202 | if (ScopeType) { |
| 13203 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 13204 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 13205 | diag::err_expected_class_or_namespace) |
| 13206 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 13207 | return ExprError(); |
| 13208 | } |
| 13209 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 13210 | CCLoc); |
| 13211 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13212 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13213 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13214 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13215 | OperatorLoc, isArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13216 | SS, TemplateKWLoc, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13217 | /*FIXME: FirstQualifier*/ nullptr, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13218 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 13219 | /*TemplateArgs*/ nullptr, |
| 13220 | /*S*/nullptr); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13221 | } |
| 13222 | |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 13223 | template<typename Derived> |
| 13224 | StmtResult |
| 13225 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13226 | SourceLocation Loc = S->getBeginLoc(); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 13227 | CapturedDecl *CD = S->getCapturedDecl(); |
| 13228 | unsigned NumParams = CD->getNumParams(); |
| 13229 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 13230 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 13231 | for (unsigned I = 0; I < NumParams; ++I) { |
| 13232 | if (I != ContextParamPos) { |
| 13233 | Params.push_back( |
| 13234 | std::make_pair( |
| 13235 | CD->getParam(I)->getName(), |
| 13236 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 13237 | } else { |
| 13238 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 13239 | } |
| 13240 | } |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13241 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 13242 | S->getCapturedRegionKind(), Params); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13243 | StmtResult Body; |
| 13244 | { |
| 13245 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 13246 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 13247 | } |
| Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 13248 | |
| 13249 | if (Body.isInvalid()) { |
| 13250 | getSema().ActOnCapturedRegionError(); |
| 13251 | return StmtError(); |
| 13252 | } |
| 13253 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 13254 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 13255 | } |
| 13256 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 13257 | } // end namespace clang |
| 13258 | |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 13259 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |