| 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 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2655 | /// Build a new C++ typeid(type) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2656 | /// |
| 2657 | /// By default, performs semantic analysis to build the new expression. |
| 2658 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2659 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2660 | SourceLocation TypeidLoc, |
| 2661 | TypeSourceInfo *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2662 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2663 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2664 | RParenLoc); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2665 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2666 | |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2667 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2668 | /// Build a new C++ typeid(expr) expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2669 | /// |
| 2670 | /// By default, performs semantic analysis to build the new expression. |
| 2671 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2672 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2673 | SourceLocation TypeidLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2674 | Expr *Operand, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2675 | SourceLocation RParenLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2676 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 2677 | RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2680 | /// Build a new C++ __uuidof(type) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2681 | /// |
| 2682 | /// By default, performs semantic analysis to build the new expression. |
| 2683 | /// Subclasses may override this routine to provide different behavior. |
| 2684 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2685 | SourceLocation TypeidLoc, |
| 2686 | TypeSourceInfo *Operand, |
| 2687 | SourceLocation RParenLoc) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2688 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2689 | RParenLoc); |
| 2690 | } |
| 2691 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2692 | /// Build a new C++ __uuidof(expr) expression. |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 2693 | /// |
| 2694 | /// By default, performs semantic analysis to build the new expression. |
| 2695 | /// Subclasses may override this routine to provide different behavior. |
| 2696 | ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, |
| 2697 | SourceLocation TypeidLoc, |
| 2698 | Expr *Operand, |
| 2699 | SourceLocation RParenLoc) { |
| 2700 | return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, |
| 2701 | RParenLoc); |
| 2702 | } |
| 2703 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2704 | /// Build a new C++ "this" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2705 | /// |
| 2706 | /// By default, builds a new "this" expression without performing any |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2707 | /// semantic analysis. Subclasses may override this routine to provide |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2708 | /// different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2709 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 2710 | QualType ThisType, |
| 2711 | bool isImplicit) { |
| Richard Smith | 8458c9e | 2019-05-24 01:35:07 +0000 | [diff] [blame] | 2712 | return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2715 | /// Build a new C++ throw expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2716 | /// |
| 2717 | /// By default, performs semantic analysis to build the new expression. |
| 2718 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 2719 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2720 | bool IsThrownVariableInScope) { |
| 2721 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2724 | /// Build a new C++ default-argument expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2725 | /// |
| 2726 | /// By default, builds a new default-argument expression, which does not |
| 2727 | /// require any semantic analysis. Subclasses may override this routine to |
| 2728 | /// provide different behavior. |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 2729 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) { |
| 2730 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, |
| 2731 | getSema().CurContext); |
| 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++11 default-initialization expression. |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2735 | /// |
| 2736 | /// By default, builds a new default field initialization expression, which |
| 2737 | /// does not require any semantic analysis. Subclasses may override this |
| 2738 | /// routine to provide different behavior. |
| 2739 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2740 | FieldDecl *Field) { |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 2741 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field, |
| 2742 | getSema().CurContext); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2745 | /// Build a new C++ zero-initialization expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2746 | /// |
| 2747 | /// By default, performs semantic analysis to build the new expression. |
| 2748 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2749 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2750 | SourceLocation LParenLoc, |
| 2751 | SourceLocation RParenLoc) { |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2752 | return getSema().BuildCXXTypeConstructExpr( |
| 2753 | TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2754 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2755 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2756 | /// Build a new C++ "new" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2757 | /// |
| 2758 | /// By default, performs semantic analysis to build the new expression. |
| 2759 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2760 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2761 | bool UseGlobal, |
| 2762 | SourceLocation PlacementLParen, |
| 2763 | MultiExprArg PlacementArgs, |
| 2764 | SourceLocation PlacementRParen, |
| 2765 | SourceRange TypeIdParens, |
| 2766 | QualType AllocatedType, |
| 2767 | TypeSourceInfo *AllocatedTypeInfo, |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 2768 | Optional<Expr *> ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2769 | SourceRange DirectInitRange, |
| 2770 | Expr *Initializer) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2771 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2772 | PlacementLParen, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2773 | PlacementArgs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2774 | PlacementRParen, |
| Douglas Gregor | f2753b3 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2775 | TypeIdParens, |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 2776 | AllocatedType, |
| 2777 | AllocatedTypeInfo, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2778 | ArraySize, |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2779 | DirectInitRange, |
| 2780 | Initializer); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2781 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2782 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2783 | /// Build a new C++ "delete" expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2784 | /// |
| 2785 | /// By default, performs semantic analysis to build the new expression. |
| 2786 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2787 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2788 | bool IsGlobalDelete, |
| 2789 | bool IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2790 | Expr *Operand) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2791 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2792 | Operand); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2793 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2795 | /// Build a new type trait expression. |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2796 | /// |
| 2797 | /// By default, performs semantic analysis to build the new expression. |
| 2798 | /// Subclasses may override this routine to provide different behavior. |
| 2799 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 2800 | SourceLocation StartLoc, |
| 2801 | ArrayRef<TypeSourceInfo *> Args, |
| 2802 | SourceLocation RParenLoc) { |
| 2803 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 2804 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2805 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2806 | /// Build a new array type trait expression. |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2807 | /// |
| 2808 | /// By default, performs semantic analysis to build the new expression. |
| 2809 | /// Subclasses may override this routine to provide different behavior. |
| 2810 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 2811 | SourceLocation StartLoc, |
| 2812 | TypeSourceInfo *TSInfo, |
| 2813 | Expr *DimExpr, |
| 2814 | SourceLocation RParenLoc) { |
| 2815 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 2816 | } |
| 2817 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2818 | /// Build a new expression trait expression. |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2819 | /// |
| 2820 | /// By default, performs semantic analysis to build the new expression. |
| 2821 | /// Subclasses may override this routine to provide different behavior. |
| 2822 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 2823 | SourceLocation StartLoc, |
| 2824 | Expr *Queried, |
| 2825 | SourceLocation RParenLoc) { |
| 2826 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 2827 | } |
| 2828 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2829 | /// Build a new (previously unresolved) declaration reference |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2830 | /// expression. |
| 2831 | /// |
| 2832 | /// By default, performs semantic analysis to build the new expression. |
| 2833 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2834 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 2835 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2836 | SourceLocation TemplateKWLoc, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2837 | const DeclarationNameInfo &NameInfo, |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 2838 | const TemplateArgumentListInfo *TemplateArgs, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2839 | bool IsAddressOfOperand, |
| 2840 | TypeSourceInfo **RecoveryTSI) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2841 | CXXScopeSpec SS; |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 2842 | SS.Adopt(QualifierLoc); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2843 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2844 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2845 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 2846 | TemplateArgs); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 2847 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 2848 | return getSema().BuildQualifiedDeclarationNameExpr( |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2849 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2852 | /// Build a new template-id expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2853 | /// |
| 2854 | /// By default, performs semantic analysis to build the new expression. |
| 2855 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2856 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2857 | SourceLocation TemplateKWLoc, |
| 2858 | LookupResult &R, |
| 2859 | bool RequiresADL, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 2860 | const TemplateArgumentListInfo *TemplateArgs) { |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2861 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 2862 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2865 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2866 | /// |
| 2867 | /// By default, performs semantic analysis to build the new expression. |
| 2868 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2869 | ExprResult RebuildCXXConstructExpr(QualType T, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2870 | SourceLocation Loc, |
| 2871 | CXXConstructorDecl *Constructor, |
| 2872 | bool IsElidable, |
| 2873 | MultiExprArg Args, |
| 2874 | bool HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2875 | bool ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2876 | bool StdInitListInitialization, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2877 | bool RequiresZeroInit, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2878 | CXXConstructExpr::ConstructionKind ConstructKind, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2879 | SourceRange ParenRange) { |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2880 | SmallVector<Expr*, 8> ConvertedArgs; |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2881 | if (getSema().CompleteConstructorCall(Constructor, Args, Loc, |
| Douglas Gregor | db121ba | 2009-12-14 16:27:04 +0000 | [diff] [blame] | 2882 | ConvertedArgs)) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2883 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2884 | |
| Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 2885 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
| Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 2886 | IsElidable, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2887 | ConvertedArgs, |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 2888 | HadMultipleCandidates, |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 2889 | ListInitialization, |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 2890 | StdInitListInitialization, |
| Chandler Carruth | 0171815 | 2010-10-25 08:47:36 +0000 | [diff] [blame] | 2891 | RequiresZeroInit, ConstructKind, |
| 2892 | ParenRange); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2895 | /// Build a new implicit construction via inherited constructor |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2896 | /// expression. |
| 2897 | ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 2898 | CXXConstructorDecl *Constructor, |
| 2899 | bool ConstructsVBase, |
| 2900 | bool InheritedFromVBase) { |
| 2901 | return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 2902 | Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 2903 | } |
| 2904 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2905 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2906 | /// |
| 2907 | /// By default, performs semantic analysis to build the new expression. |
| 2908 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2909 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2910 | SourceLocation LParenOrBraceLoc, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2911 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2912 | SourceLocation RParenOrBraceLoc, |
| 2913 | bool ListInitialization) { |
| 2914 | return getSema().BuildCXXTypeConstructExpr( |
| 2915 | TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2918 | /// Build a new object-construction expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2919 | /// |
| 2920 | /// By default, performs semantic analysis to build the new expression. |
| 2921 | /// Subclasses may override this routine to provide different behavior. |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 2922 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 2923 | SourceLocation LParenLoc, |
| 2924 | MultiExprArg Args, |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 2925 | SourceLocation RParenLoc, |
| 2926 | bool ListInitialization) { |
| 2927 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, |
| 2928 | RParenLoc, ListInitialization); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2929 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2930 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2931 | /// Build a new member reference expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2932 | /// |
| 2933 | /// By default, performs semantic analysis to build the new expression. |
| 2934 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2935 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2936 | QualType BaseType, |
| 2937 | bool IsArrow, |
| 2938 | SourceLocation OperatorLoc, |
| 2939 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2940 | SourceLocation TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2941 | NamedDecl *FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2942 | const DeclarationNameInfo &MemberNameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2943 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2944 | CXXScopeSpec SS; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 2945 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2947 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2948 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2949 | SS, TemplateKWLoc, |
| 2950 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2951 | MemberNameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2952 | TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2955 | /// Build a new member reference expression. |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2956 | /// |
| 2957 | /// By default, performs semantic analysis to build the new expression. |
| 2958 | /// Subclasses may override this routine to provide different behavior. |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2959 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 2960 | SourceLocation OperatorLoc, |
| 2961 | bool IsArrow, |
| 2962 | NestedNameSpecifierLoc QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2963 | SourceLocation TemplateKWLoc, |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 2964 | NamedDecl *FirstQualifierInScope, |
| 2965 | LookupResult &R, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 2966 | const TemplateArgumentListInfo *TemplateArgs) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2967 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 2968 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2969 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2970 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 2971 | OperatorLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2972 | SS, TemplateKWLoc, |
| 2973 | FirstQualifierInScope, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 2974 | R, TemplateArgs, /*S*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 2975 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2977 | /// Build a new noexcept expression. |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 2978 | /// |
| 2979 | /// By default, performs semantic analysis to build the new expression. |
| 2980 | /// Subclasses may override this routine to provide different behavior. |
| 2981 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 2982 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 2983 | } |
| 2984 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2985 | /// Build a new expression to compute the length of a parameter pack. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2986 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 2987 | NamedDecl *Pack, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 2988 | SourceLocation PackLoc, |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2989 | SourceLocation RParenLoc, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 2990 | Optional<unsigned> Length, |
| 2991 | ArrayRef<TemplateArgument> PartialArgs) { |
| 2992 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 2993 | RParenLoc, Length, PartialArgs); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 2994 | } |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2995 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 2996 | /// Build a new expression representing a call to a source location |
| 2997 | /// builtin. |
| 2998 | /// |
| 2999 | /// By default, performs semantic analysis to build the new expression. |
| 3000 | /// Subclasses may override this routine to provide different behavior. |
| 3001 | ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
| 3002 | SourceLocation BuiltinLoc, |
| 3003 | SourceLocation RPLoc, |
| 3004 | DeclContext *ParentContext) { |
| 3005 | return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext); |
| 3006 | } |
| 3007 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3008 | /// Build a new Objective-C boxed expression. |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 3009 | /// |
| 3010 | /// By default, performs semantic analysis to build the new expression. |
| 3011 | /// Subclasses may override this routine to provide different behavior. |
| 3012 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 3013 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 3014 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3015 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3016 | /// Build a new Objective-C array literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3017 | /// |
| 3018 | /// By default, performs semantic analysis to build the new expression. |
| 3019 | /// Subclasses may override this routine to provide different behavior. |
| 3020 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 3021 | Expr **Elements, unsigned NumElements) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3022 | return getSema().BuildObjCArrayLiteral(Range, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3023 | MultiExprArg(Elements, NumElements)); |
| 3024 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3025 | |
| 3026 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3027 | Expr *Base, Expr *Key, |
| 3028 | ObjCMethodDecl *getterMethod, |
| 3029 | ObjCMethodDecl *setterMethod) { |
| 3030 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 3031 | getterMethod, setterMethod); |
| 3032 | } |
| 3033 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3034 | /// Build a new Objective-C dictionary literal. |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3035 | /// |
| 3036 | /// By default, performs semantic analysis to build the new expression. |
| 3037 | /// Subclasses may override this routine to provide different behavior. |
| 3038 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 3039 | MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 3040 | return getSema().BuildObjCDictionaryLiteral(Range, Elements); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 3041 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3042 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3043 | /// Build a new Objective-C \@encode expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3044 | /// |
| 3045 | /// By default, performs semantic analysis to build the new expression. |
| 3046 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3047 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 3048 | TypeSourceInfo *EncodeTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3049 | SourceLocation RParenLoc) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3050 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3051 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3052 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3053 | /// Build a new Objective-C class message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3054 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3055 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3056 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3057 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3058 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3059 | MultiExprArg Args, |
| 3060 | SourceLocation RBracLoc) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3061 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 3062 | ReceiverTypeInfo->getType(), |
| 3063 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3064 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3065 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3068 | /// Build a new Objective-C instance message. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3069 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3070 | Selector Sel, |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3071 | ArrayRef<SourceLocation> SelectorLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3072 | ObjCMethodDecl *Method, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3073 | SourceLocation LBracLoc, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3074 | MultiExprArg Args, |
| 3075 | SourceLocation RBracLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 3076 | return SemaRef.BuildInstanceMessage(Receiver, |
| 3077 | Receiver->getType(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3078 | /*SuperLoc=*/SourceLocation(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 3079 | Sel, Method, LBracLoc, SelectorLocs, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3080 | RBracLoc, Args); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3083 | /// Build a new Objective-C instance/class message to 'super'. |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3084 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 3085 | Selector Sel, |
| 3086 | ArrayRef<SourceLocation> SelectorLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3087 | QualType SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3088 | ObjCMethodDecl *Method, |
| 3089 | SourceLocation LBracLoc, |
| 3090 | MultiExprArg Args, |
| 3091 | SourceLocation RBracLoc) { |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3092 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3093 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3094 | SuperLoc, |
| 3095 | Sel, Method, LBracLoc, SelectorLocs, |
| 3096 | RBracLoc, Args) |
| 3097 | : SemaRef.BuildClassMessage(nullptr, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 3098 | SuperType, |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3099 | SuperLoc, |
| 3100 | Sel, Method, LBracLoc, SelectorLocs, |
| 3101 | RBracLoc, Args); |
| 3102 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3103 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3106 | /// Build a new Objective-C ivar reference expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3107 | /// |
| 3108 | /// By default, performs semantic analysis to build the new expression. |
| 3109 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3110 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3111 | SourceLocation IvarLoc, |
| 3112 | bool IsArrow, bool IsFreeIvar) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3113 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3114 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| Alex Lorenz | 776b417 | 2017-02-03 14:22:33 +0000 | [diff] [blame] | 3115 | ExprResult Result = getSema().BuildMemberReferenceExpr( |
| 3116 | BaseArg, BaseArg->getType(), |
| 3117 | /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), |
| 3118 | /*FirstQualifierInScope=*/nullptr, NameInfo, |
| 3119 | /*TemplateArgs=*/nullptr, |
| 3120 | /*S=*/nullptr); |
| 3121 | if (IsFreeIvar && Result.isUsable()) |
| 3122 | cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); |
| 3123 | return Result; |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3124 | } |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3125 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3126 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3127 | /// |
| 3128 | /// By default, performs semantic analysis to build the new expression. |
| 3129 | /// Subclasses may override this routine to provide different behavior. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3130 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 3131 | ObjCPropertyDecl *Property, |
| 3132 | SourceLocation PropertyLoc) { |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3133 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3134 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 3135 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3136 | /*FIXME:*/PropertyLoc, |
| 3137 | /*IsArrow=*/false, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3138 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3139 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3140 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3141 | /*TemplateArgs=*/nullptr, |
| 3142 | /*S=*/nullptr); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 3143 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3144 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3145 | /// Build a new Objective-C property reference expression. |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3146 | /// |
| 3147 | /// By default, performs semantic analysis to build the new expression. |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 3148 | /// Subclasses may override this routine to provide different behavior. |
| 3149 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 3150 | ObjCMethodDecl *Getter, |
| 3151 | ObjCMethodDecl *Setter, |
| 3152 | SourceLocation PropertyLoc) { |
| 3153 | // Since these expressions can only be value-dependent, we do not |
| 3154 | // need to perform semantic analysis again. |
| 3155 | return Owned( |
| 3156 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 3157 | VK_LValue, OK_ObjCProperty, |
| 3158 | PropertyLoc, Base)); |
| Douglas Gregor | b7e20eb | 2010-04-26 21:04:54 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3161 | /// Build a new Objective-C "isa" expression. |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3162 | /// |
| 3163 | /// By default, performs semantic analysis to build the new expression. |
| 3164 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3165 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3166 | SourceLocation OpLoc, bool IsArrow) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3167 | CXXScopeSpec SS; |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3168 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 3169 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 3170 | OpLoc, IsArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 3171 | SS, SourceLocation(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3172 | /*FirstQualifierInScope=*/nullptr, |
| Richard Smith | a0edd30 | 2014-05-31 00:18:32 +0000 | [diff] [blame] | 3173 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 3174 | /*TemplateArgs=*/nullptr, |
| 3175 | /*S=*/nullptr); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 3176 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3177 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3178 | /// Build a new shuffle vector expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3179 | /// |
| 3180 | /// By default, performs semantic analysis to build the new expression. |
| 3181 | /// Subclasses may override this routine to provide different behavior. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3182 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 3183 | MultiExprArg SubExprs, |
| 3184 | SourceLocation RParenLoc) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3185 | // Find the declaration for __builtin_shufflevector |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 | const IdentifierInfo &Name |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3187 | = SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 3188 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 3189 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3190 | assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3191 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3192 | // Build a reference to the __builtin_shufflevector builtin |
| David Blaikie | ff7d47a | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 3193 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
| Bruno Ricci | 5fc4db7 | 2018-12-21 14:10:18 +0000 | [diff] [blame] | 3194 | Expr *Callee = new (SemaRef.Context) |
| 3195 | DeclRefExpr(SemaRef.Context, Builtin, false, |
| 3196 | SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc); |
| Eli Friedman | 34866c7 | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 3197 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 3198 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3199 | CK_BuiltinFnToFnPtr).get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3200 | |
| 3201 | // Build the CallExpr |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 3202 | ExprResult TheCall = CallExpr::Create( |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3203 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3204 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3205 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3206 | // Type-check the __builtin_shufflevector expression. |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3207 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3208 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3209 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3210 | /// Build a new convert vector expression. |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 3211 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 3212 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 3213 | SourceLocation RParenLoc) { |
| 3214 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 3215 | BuiltinLoc, RParenLoc); |
| 3216 | } |
| 3217 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3218 | /// Build a new template argument pack expansion. |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3219 | /// |
| 3220 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3221 | /// for a template argument. Subclasses may override this routine to provide |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3222 | /// different behavior. |
| 3223 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3224 | SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3225 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3226 | switch (Pattern.getArgument().getKind()) { |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3227 | case TemplateArgument::Expression: { |
| 3228 | ExprResult Result |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3229 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 3230 | EllipsisLoc, NumExpansions); |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3231 | if (Result.isInvalid()) |
| 3232 | return TemplateArgumentLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3233 | |
| Douglas Gregor | 98318c2 | 2011-01-03 21:37:45 +0000 | [diff] [blame] | 3234 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 3235 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3236 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3237 | case TemplateArgument::Template: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3238 | return TemplateArgumentLoc(TemplateArgument( |
| 3239 | Pattern.getArgument().getAsTemplate(), |
| Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 3240 | NumExpansions), |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3241 | Pattern.getTemplateQualifierLoc(), |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3242 | Pattern.getTemplateNameLoc(), |
| 3243 | EllipsisLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3244 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3245 | case TemplateArgument::Null: |
| 3246 | case TemplateArgument::Integral: |
| 3247 | case TemplateArgument::Declaration: |
| 3248 | case TemplateArgument::Pack: |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3249 | case TemplateArgument::TemplateExpansion: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3250 | case TemplateArgument::NullPtr: |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3251 | llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3252 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3253 | case TemplateArgument::Type: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3254 | if (TypeSourceInfo *Expansion |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3255 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3256 | EllipsisLoc, |
| 3257 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 3258 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 3259 | Expansion); |
| 3260 | break; |
| 3261 | } |
| 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 | return TemplateArgumentLoc(); |
| 3264 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3265 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3266 | /// Build a new expression pack expansion. |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3267 | /// |
| 3268 | /// By default, performs semantic analysis to build a new pack expansion |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3269 | /// for an expression. Subclasses may override this routine to provide |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3270 | /// different behavior. |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3271 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3272 | Optional<unsigned> NumExpansions) { |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3273 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3274 | } |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3275 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3276 | /// Build a new C++1z fold-expression. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3277 | /// |
| 3278 | /// By default, performs semantic analysis in order to build a new fold |
| 3279 | /// expression. |
| 3280 | ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
| 3281 | BinaryOperatorKind Operator, |
| 3282 | SourceLocation EllipsisLoc, Expr *RHS, |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 3283 | SourceLocation RParenLoc, |
| 3284 | Optional<unsigned> NumExpansions) { |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3285 | return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc, |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 3286 | RHS, RParenLoc, NumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3289 | /// Build an empty C++1z fold-expression with the given operator. |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 3290 | /// |
| 3291 | /// By default, produces the fallback value for the fold-expression, or |
| 3292 | /// produce an error if there is no fallback value. |
| 3293 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 3294 | BinaryOperatorKind Operator) { |
| 3295 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 3296 | } |
| 3297 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3298 | /// Build a new atomic operation expression. |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3299 | /// |
| 3300 | /// By default, performs semantic analysis to build the new expression. |
| 3301 | /// Subclasses may override this routine to provide different behavior. |
| 3302 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, |
| 3303 | MultiExprArg SubExprs, |
| 3304 | QualType RetTy, |
| 3305 | AtomicExpr::AtomicOp Op, |
| 3306 | SourceLocation RParenLoc) { |
| 3307 | // Just create the expression; there is not any interesting semantic |
| 3308 | // analysis here because we can't actually build an AtomicExpr until |
| 3309 | // we are sure it is semantically sound. |
| Benjamin Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 3310 | return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 3311 | RParenLoc); |
| 3312 | } |
| 3313 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3314 | private: |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3315 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 3316 | QualType ObjectType, |
| 3317 | NamedDecl *FirstQualifierInScope, |
| 3318 | CXXScopeSpec &SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 3319 | |
| 3320 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3321 | QualType ObjectType, |
| 3322 | NamedDecl *FirstQualifierInScope, |
| 3323 | CXXScopeSpec &SS); |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 3324 | |
| 3325 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 3326 | NamedDecl *FirstQualifierInScope, |
| 3327 | CXXScopeSpec &SS); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 3328 | |
| 3329 | QualType TransformDependentNameType(TypeLocBuilder &TLB, |
| 3330 | DependentNameTypeLoc TL, |
| 3331 | bool DeducibleTSTContext); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 3332 | }; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3333 | |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 3334 | template <typename Derived> |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3335 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3336 | if (!S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3337 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3339 | switch (S->getStmtClass()) { |
| 3340 | case Stmt::NoStmtClass: break; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3341 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3342 | // Transform individual statement nodes |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3343 | // Pass SDK into statements that can produce a value |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3344 | #define STMT(Node, Parent) \ |
| 3345 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3346 | #define VALUESTMT(Node, Parent) \ |
| 3347 | case Stmt::Node##Class: \ |
| 3348 | return getDerived().Transform##Node(cast<Node>(S), SDK); |
| John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 3349 | #define ABSTRACT_STMT(Node) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3350 | #define EXPR(Node, Parent) |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3351 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3353 | // Transform expressions by calling TransformExpr. |
| 3354 | #define STMT(Node, Parent) |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3355 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3356 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3357 | #include "clang/AST/StmtNodes.inc" |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3358 | { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3359 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 3361 | if (SDK == SDK_StmtExprResult) |
| 3362 | E = getSema().ActOnStmtExprResult(E); |
| 3363 | return getSema().ActOnExprStmt(E, SDK == SDK_Discarded); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3364 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3367 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 3368 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3369 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3370 | template<typename Derived> |
| 3371 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 3372 | if (!S) |
| 3373 | return S; |
| 3374 | |
| 3375 | switch (S->getClauseKind()) { |
| 3376 | default: break; |
| 3377 | // Transform individual clause nodes |
| 3378 | #define OPENMP_CLAUSE(Name, Class) \ |
| 3379 | case OMPC_ ## Name : \ |
| 3380 | return getDerived().Transform ## Class(cast<Class>(S)); |
| 3381 | #include "clang/Basic/OpenMPKinds.def" |
| 3382 | } |
| 3383 | |
| 3384 | return S; |
| 3385 | } |
| 3386 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3387 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3388 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3389 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3390 | if (!E) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3391 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3392 | |
| 3393 | switch (E->getStmtClass()) { |
| 3394 | case Stmt::NoStmtClass: break; |
| 3395 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 3396 | #define ABSTRACT_STMT(Stmt) |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 3397 | #define EXPR(Node, Parent) \ |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 3398 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 3399 | #include "clang/AST/StmtNodes.inc" |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3402 | return E; |
| Douglas Gregor | 766b0bb | 2009-08-06 22:17:10 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | template<typename Derived> |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3406 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3407 | bool NotCopyInit) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3408 | // Initializers are instantiated like expressions, except that various outer |
| 3409 | // layers are stripped. |
| 3410 | if (!Init) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3411 | return Init; |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3412 | |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 3413 | if (auto *FE = dyn_cast<FullExpr>(Init)) |
| 3414 | Init = FE->getSubExpr(); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3415 | |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 3416 | if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) |
| 3417 | Init = AIL->getCommonExpr(); |
| 3418 | |
| Richard Smith | e6ca475 | 2013-05-30 22:40:16 +0000 | [diff] [blame] | 3419 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3420 | Init = MTE->GetTemporaryExpr(); |
| 3421 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3422 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3423 | Init = Binder->getSubExpr(); |
| 3424 | |
| 3425 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3426 | Init = ICE->getSubExprAsWritten(); |
| 3427 | |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3428 | if (CXXStdInitializerListExpr *ILE = |
| 3429 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3430 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 3431 | |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3432 | // If this is copy-initialization, we only need to reconstruct |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3433 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3434 | // the initializer is already the right type. |
| 3435 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3436 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3437 | return getDerived().TransformExpr(Init); |
| 3438 | |
| 3439 | // Revert value-initialization back to empty parens. |
| 3440 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3441 | SourceRange Parens = VIE->getSourceRange(); |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3442 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3443 | Parens.getEnd()); |
| 3444 | } |
| 3445 | |
| 3446 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3447 | if (isa<ImplicitValueInitExpr>(Init)) |
| Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 3448 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
| Richard Smith | 38a549b | 2012-12-21 08:13:35 +0000 | [diff] [blame] | 3449 | SourceLocation()); |
| 3450 | |
| 3451 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3452 | // of expressions. Any other form of initializer can just be reused directly. |
| 3453 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3454 | return getDerived().TransformExpr(Init); |
| 3455 | |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3456 | // If the initialization implicitly converted an initializer list to a |
| 3457 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3458 | if (Construct && Construct->isStdInitListInitialization()) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3459 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
| Richard Smith | f8adcdc | 2014-07-17 05:12:35 +0000 | [diff] [blame] | 3460 | |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 3461 | // Enter a list-init context if this was list initialization. |
| 3462 | EnterExpressionEvaluationContext Context( |
| 3463 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 3464 | Construct->isListInitialization()); |
| 3465 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3466 | SmallVector<Expr*, 8> NewArgs; |
| 3467 | bool ArgChanged = false; |
| 3468 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 3469 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3470 | return ExprError(); |
| 3471 | |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 3472 | // If this was list initialization, revert to syntactic list form. |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3473 | if (Construct->isListInitialization()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3474 | return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3475 | Construct->getEndLoc()); |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3476 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3477 | // Build a ParenListExpr to represent anything else. |
| Enea Zaffanella | 76e98fe | 2013-09-07 05:49:53 +0000 | [diff] [blame] | 3478 | SourceRange Parens = Construct->getParenOrBraceRange(); |
| Richard Smith | 95b83e9 | 2014-07-10 20:53:43 +0000 | [diff] [blame] | 3479 | if (Parens.isInvalid()) { |
| 3480 | // This was a variable declaration's initialization for which no initializer |
| 3481 | // was specified. |
| 3482 | assert(NewArgs.empty() && |
| 3483 | "no parens or braces but have direct init with arguments?"); |
| 3484 | return ExprEmpty(); |
| 3485 | } |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3486 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3487 | Parens.getEnd()); |
| 3488 | } |
| 3489 | |
| 3490 | template<typename Derived> |
| Craig Topper | 99d2353 | 2015-12-24 23:58:29 +0000 | [diff] [blame] | 3491 | bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3492 | unsigned NumInputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3493 | bool IsCall, |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3494 | SmallVectorImpl<Expr *> &Outputs, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3495 | bool *ArgChanged) { |
| 3496 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3497 | // If requested, drop call arguments that need to be dropped. |
| 3498 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3499 | if (ArgChanged) |
| 3500 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3501 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3504 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3505 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3506 | Expr *Pattern = Expansion->getPattern(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3507 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3508 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3509 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3510 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3511 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3512 | // Determine whether the set of unexpanded parameter packs can and should |
| 3513 | // be expanded. |
| 3514 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3515 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 3516 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3517 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3518 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3519 | Pattern->getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 3520 | Unexpanded, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 3521 | Expand, RetainExpansion, |
| 3522 | NumExpansions)) |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3523 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3524 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3525 | if (!Expand) { |
| 3526 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3527 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3528 | // expansion. |
| 3529 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3530 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3531 | if (OutPattern.isInvalid()) |
| 3532 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3533 | |
| 3534 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 3535 | Expansion->getEllipsisLoc(), |
| 3536 | NumExpansions); |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3537 | if (Out.isInvalid()) |
| 3538 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3539 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3540 | if (ArgChanged) |
| 3541 | *ArgChanged = true; |
| 3542 | Outputs.push_back(Out.get()); |
| 3543 | continue; |
| 3544 | } |
| John McCall | 542e7c6 | 2011-07-06 07:30:07 +0000 | [diff] [blame] | 3545 | |
| 3546 | // Record right away that the argument was changed. This needs |
| 3547 | // to happen even if the array expands to nothing. |
| 3548 | if (ArgChanged) *ArgChanged = 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 | // The transform has determined that we should perform an elementwise |
| 3551 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3552 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3553 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3554 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3555 | if (Out.isInvalid()) |
| 3556 | return true; |
| 3557 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3558 | if (Out.get()->containsUnexpandedParameterPack()) { |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3559 | Out = getDerived().RebuildPackExpansion( |
| 3560 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 3561 | if (Out.isInvalid()) |
| 3562 | return true; |
| 3563 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3564 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3565 | Outputs.push_back(Out.get()); |
| 3566 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3567 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 3568 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3569 | // forgetting the partially-substituted parameter pack. |
| 3570 | if (RetainExpansion) { |
| 3571 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3572 | |
| 3573 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3574 | if (Out.isInvalid()) |
| 3575 | return true; |
| 3576 | |
| 3577 | Out = getDerived().RebuildPackExpansion( |
| 3578 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3579 | if (Out.isInvalid()) |
| 3580 | return true; |
| 3581 | |
| 3582 | Outputs.push_back(Out.get()); |
| 3583 | } |
| 3584 | |
| Douglas Gregor | 968f23a | 2011-01-03 19:31:53 +0000 | [diff] [blame] | 3585 | continue; |
| 3586 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3587 | |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 3588 | ExprResult Result = |
| 3589 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3590 | : getDerived().TransformExpr(Inputs[I]); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3591 | if (Result.isInvalid()) |
| 3592 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3593 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3594 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3595 | *ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3596 | |
| 3597 | Outputs.push_back(Result.get()); |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3598 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3599 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3600 | return false; |
| 3601 | } |
| 3602 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 3603 | template <typename Derived> |
| 3604 | Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 3605 | SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 3606 | if (Var) { |
| 3607 | VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 3608 | getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 3609 | |
| 3610 | if (!ConditionVar) |
| 3611 | return Sema::ConditionError(); |
| 3612 | |
| 3613 | return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 3614 | } |
| 3615 | |
| 3616 | if (Expr) { |
| 3617 | ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 3618 | |
| 3619 | if (CondExpr.isInvalid()) |
| 3620 | return Sema::ConditionError(); |
| 3621 | |
| 3622 | return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); |
| 3623 | } |
| 3624 | |
| 3625 | return Sema::ConditionResult(); |
| 3626 | } |
| 3627 | |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 3628 | template<typename Derived> |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3629 | NestedNameSpecifierLoc |
| 3630 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3631 | NestedNameSpecifierLoc NNS, |
| 3632 | QualType ObjectType, |
| 3633 | NamedDecl *FirstQualifierInScope) { |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 3634 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3635 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3636 | Qualifier = Qualifier.getPrefix()) |
| 3637 | Qualifiers.push_back(Qualifier); |
| 3638 | |
| 3639 | CXXScopeSpec SS; |
| 3640 | while (!Qualifiers.empty()) { |
| 3641 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3642 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3643 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3644 | switch (QNNS->getKind()) { |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3645 | case NestedNameSpecifier::Identifier: { |
| 3646 | Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), |
| 3647 | Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType); |
| 3648 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, |
| 3649 | SS, FirstQualifierInScope, false)) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3650 | return NestedNameSpecifierLoc(); |
| Serge Pavlov | d931b9f | 2016-08-08 04:02:15 +0000 | [diff] [blame] | 3651 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3652 | break; |
| 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 | case NestedNameSpecifier::Namespace: { |
| 3655 | NamespaceDecl *NS |
| 3656 | = cast_or_null<NamespaceDecl>( |
| 3657 | getDerived().TransformDecl( |
| 3658 | Q.getLocalBeginLoc(), |
| 3659 | QNNS->getAsNamespace())); |
| 3660 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3661 | break; |
| 3662 | } |
| 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::NamespaceAlias: { |
| 3665 | NamespaceAliasDecl *Alias |
| 3666 | = cast_or_null<NamespaceAliasDecl>( |
| 3667 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3668 | QNNS->getAsNamespaceAlias())); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3669 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3670 | 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::Global: |
| 3675 | // There is no meaningful transformation that one could perform on the |
| 3676 | // global scope. |
| 3677 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3678 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3679 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 3680 | case NestedNameSpecifier::Super: { |
| 3681 | CXXRecordDecl *RD = |
| 3682 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 3683 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 3684 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 3685 | break; |
| 3686 | } |
| 3687 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3688 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 3689 | case NestedNameSpecifier::TypeSpec: { |
| 3690 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 3691 | FirstQualifierInScope, SS); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3692 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3693 | if (!TL) |
| 3694 | return NestedNameSpecifierLoc(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3695 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3696 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 3697 | (SemaRef.getLangOpts().CPlusPlus11 && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3698 | TL.getType()->isEnumeralType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3699 | assert(!TL.getType().hasLocalQualifiers() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3700 | "Can't get cv-qualifiers here"); |
| Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 3701 | if (TL.getType()->isEnumeralType()) |
| 3702 | SemaRef.Diag(TL.getBeginLoc(), |
| 3703 | diag::warn_cxx98_compat_enum_nested_name_spec); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3704 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 3705 | Q.getLocalEndLoc()); |
| 3706 | break; |
| 3707 | } |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3708 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 3709 | // error because a previous error should have already been emitted. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 3710 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 3711 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3712 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| Richard Trieu | de756fb | 2011-05-07 01:36:37 +0000 | [diff] [blame] | 3713 | << TL.getType() << SS.getRange(); |
| 3714 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3715 | return NestedNameSpecifierLoc(); |
| 3716 | } |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3717 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3718 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3719 | // 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] | 3720 | FirstQualifierInScope = nullptr; |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 3721 | ObjectType = QualType(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3722 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3723 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3724 | // 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] | 3725 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3726 | !getDerived().AlwaysRebuild()) |
| 3727 | return NNS; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3728 | |
| 3729 | // If we can re-use the source-location data from the original |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3730 | // nested-name-specifier, do so. |
| 3731 | if (SS.location_size() == NNS.getDataLength() && |
| 3732 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 3733 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 3734 | |
| 3735 | // Allocate new nested-name-specifier location information. |
| 3736 | return SS.getWithLocInContext(SemaRef.Context); |
| 3737 | } |
| 3738 | |
| 3739 | template<typename Derived> |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3740 | DeclarationNameInfo |
| 3741 | TreeTransform<Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3742 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3743 | DeclarationName Name = NameInfo.getName(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3744 | if (!Name) |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3745 | return DeclarationNameInfo(); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3746 | |
| 3747 | switch (Name.getNameKind()) { |
| 3748 | case DeclarationName::Identifier: |
| 3749 | case DeclarationName::ObjCZeroArgSelector: |
| 3750 | case DeclarationName::ObjCOneArgSelector: |
| 3751 | case DeclarationName::ObjCMultiArgSelector: |
| 3752 | case DeclarationName::CXXOperatorName: |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3753 | case DeclarationName::CXXLiteralOperatorName: |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3754 | case DeclarationName::CXXUsingDirective: |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3755 | return NameInfo; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3756 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3757 | case DeclarationName::CXXDeductionGuideName: { |
| 3758 | TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); |
| 3759 | TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( |
| 3760 | getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); |
| 3761 | if (!NewTemplate) |
| 3762 | return DeclarationNameInfo(); |
| 3763 | |
| 3764 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3765 | NewNameInfo.setName( |
| 3766 | SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); |
| 3767 | return NewNameInfo; |
| 3768 | } |
| 3769 | |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3770 | case DeclarationName::CXXConstructorName: |
| 3771 | case DeclarationName::CXXDestructorName: |
| 3772 | case DeclarationName::CXXConversionFunctionName: { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3773 | TypeSourceInfo *NewTInfo; |
| 3774 | CanQualType NewCanTy; |
| 3775 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3776 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 3777 | if (!NewTInfo) |
| 3778 | return DeclarationNameInfo(); |
| 3779 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3780 | } |
| 3781 | else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3782 | NewTInfo = nullptr; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3783 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 3784 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3785 | if (NewT.isNull()) |
| 3786 | return DeclarationNameInfo(); |
| 3787 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 3788 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3789 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3790 | DeclarationName NewName |
| 3791 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 3792 | NewCanTy); |
| 3793 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 3794 | NewNameInfo.setName(NewName); |
| 3795 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 3796 | return NewNameInfo; |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3797 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3800 | llvm_unreachable("Unknown name kind."); |
| Douglas Gregor | f816bd7 | 2009-09-03 22:13:48 +0000 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3804 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3805 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 3806 | TemplateName Name, |
| 3807 | SourceLocation NameLoc, |
| 3808 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3809 | NamedDecl *FirstQualifierInScope, |
| 3810 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3811 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 3812 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 3813 | assert(Template && "qualified template name must refer to a template"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3814 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3815 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3816 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3817 | Template)); |
| 3818 | if (!TransTemplate) |
| 3819 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3820 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3821 | if (!getDerived().AlwaysRebuild() && |
| 3822 | SS.getScopeRep() == QTN->getQualifier() && |
| 3823 | TransTemplate == Template) |
| 3824 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3825 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3826 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 3827 | TransTemplate); |
| 3828 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3829 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3830 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 3831 | if (SS.getScopeRep()) { |
| 3832 | // These apply to the scope specifier, not the template. |
| 3833 | ObjectType = QualType(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3834 | FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3837 | if (!getDerived().AlwaysRebuild() && |
| 3838 | SS.getScopeRep() == DTN->getQualifier() && |
| 3839 | ObjectType.isNull()) |
| 3840 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3841 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3842 | // FIXME: Preserve the location of the "template" keyword. |
| 3843 | SourceLocation TemplateKWLoc = NameLoc; |
| 3844 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3845 | if (DTN->isIdentifier()) { |
| 3846 | return getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3847 | TemplateKWLoc, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3848 | *DTN->getIdentifier(), |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3849 | NameLoc, |
| 3850 | ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3851 | FirstQualifierInScope, |
| 3852 | AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3853 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3854 | |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 3855 | return getDerived().RebuildTemplateName(SS, TemplateKWLoc, |
| 3856 | DTN->getOperator(), NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 3857 | ObjectType, AllowInjectedClassName); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3858 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3859 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3860 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 3861 | TemplateDecl *TransTemplate |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3862 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3863 | Template)); |
| 3864 | if (!TransTemplate) |
| 3865 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3866 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3867 | if (!getDerived().AlwaysRebuild() && |
| 3868 | TransTemplate == Template) |
| 3869 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3870 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3871 | return TemplateName(TransTemplate); |
| 3872 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3873 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3874 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 3875 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 3876 | TemplateTemplateParmDecl *TransParam |
| 3877 | = cast_or_null<TemplateTemplateParmDecl>( |
| 3878 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 3879 | if (!TransParam) |
| 3880 | return TemplateName(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3881 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3882 | if (!getDerived().AlwaysRebuild() && |
| 3883 | TransParam == SubstPack->getParameterPack()) |
| 3884 | return Name; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3885 | |
| 3886 | return getDerived().RebuildTemplateName(TransParam, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3887 | SubstPack->getArgumentPack()); |
| 3888 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3889 | |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3890 | // These should be getting filtered out before they reach the AST. |
| 3891 | llvm_unreachable("overloaded function decl survived to here"); |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3895 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 3896 | const TemplateArgument &Arg, |
| 3897 | TemplateArgumentLoc &Output) { |
| 3898 | SourceLocation Loc = getDerived().getBaseLocation(); |
| 3899 | switch (Arg.getKind()) { |
| 3900 | case TemplateArgument::Null: |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3901 | llvm_unreachable("null template argument in TreeTransform"); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3902 | break; |
| 3903 | |
| 3904 | case TemplateArgument::Type: |
| 3905 | Output = TemplateArgumentLoc(Arg, |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3906 | SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3907 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3908 | break; |
| 3909 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3910 | case TemplateArgument::Template: |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3911 | case TemplateArgument::TemplateExpansion: { |
| 3912 | NestedNameSpecifierLocBuilder Builder; |
| Manuel Klimek | 4c67fa7 | 2016-01-11 11:39:00 +0000 | [diff] [blame] | 3913 | TemplateName Template = Arg.getAsTemplateOrTemplatePattern(); |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3914 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) |
| 3915 | Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); |
| 3916 | else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) |
| 3917 | Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3918 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3919 | if (Arg.getKind() == TemplateArgument::Template) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3920 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3921 | Builder.getWithLocInContext(SemaRef.Context), |
| 3922 | Loc); |
| 3923 | else |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3924 | Output = TemplateArgumentLoc(Arg, |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3925 | Builder.getWithLocInContext(SemaRef.Context), |
| 3926 | Loc, Loc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3927 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3928 | break; |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3929 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3930 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3931 | case TemplateArgument::Expression: |
| 3932 | Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); |
| 3933 | break; |
| 3934 | |
| 3935 | case TemplateArgument::Declaration: |
| 3936 | case TemplateArgument::Integral: |
| 3937 | case TemplateArgument::Pack: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3938 | case TemplateArgument::NullPtr: |
| John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 3939 | Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3940 | break; |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | template<typename Derived> |
| 3945 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 3946 | const TemplateArgumentLoc &Input, |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3947 | TemplateArgumentLoc &Output, bool Uneval) { |
| Nicolas Lesser | b6d5c58 | 2018-07-12 18:45:41 +0000 | [diff] [blame] | 3948 | EnterExpressionEvaluationContext EEEC( |
| 3949 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 3950 | /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ |
| 3951 | Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3952 | const TemplateArgument &Arg = Input.getArgument(); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3953 | switch (Arg.getKind()) { |
| 3954 | case TemplateArgument::Null: |
| 3955 | case TemplateArgument::Integral: |
| Eli Friedman | cda3db8 | 2012-09-25 01:02:42 +0000 | [diff] [blame] | 3956 | case TemplateArgument::Pack: |
| 3957 | case TemplateArgument::Declaration: |
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 3958 | case TemplateArgument::NullPtr: |
| 3959 | llvm_unreachable("Unexpected TemplateArgument"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3960 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3961 | case TemplateArgument::Type: { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3962 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 3963 | if (!DI) |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3964 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3965 | |
| 3966 | DI = getDerived().TransformType(DI); |
| 3967 | if (!DI) return true; |
| 3968 | |
| 3969 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 3970 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3971 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3972 | |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3973 | case TemplateArgument::Template: { |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3974 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 3975 | if (QualifierLoc) { |
| 3976 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 3977 | if (!QualifierLoc) |
| 3978 | return true; |
| 3979 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3980 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3981 | CXXScopeSpec SS; |
| 3982 | SS.Adopt(QualifierLoc); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3983 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 3984 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 3985 | Input.getTemplateNameLoc()); |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3986 | if (Template.isNull()) |
| 3987 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 3988 | |
| Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3989 | Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, |
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3990 | Input.getTemplateNameLoc()); |
| 3991 | return false; |
| 3992 | } |
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3993 | |
| 3994 | case TemplateArgument::TemplateExpansion: |
| 3995 | llvm_unreachable("Caller should expand pack expansions"); |
| 3996 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 3997 | case TemplateArgument::Expression: { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 3998 | // Template argument expressions are constant expressions. |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 3999 | EnterExpressionEvaluationContext Unevaluated( |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4000 | getSema(), Uneval |
| 4001 | ? Sema::ExpressionEvaluationContext::Unevaluated |
| 4002 | : Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4003 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4004 | Expr *InputExpr = Input.getSourceExpression(); |
| 4005 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 4006 | |
| Chris Lattner | cdb591a | 2011-04-25 20:37:58 +0000 | [diff] [blame] | 4007 | ExprResult E = getDerived().TransformExpr(InputExpr); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4008 | E = SemaRef.ActOnConstantExpression(E); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4009 | if (E.isInvalid()) return true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4010 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4011 | return false; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4012 | } |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4013 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4014 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4015 | // Work around bogus GCC warning |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4016 | return true; |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4019 | /// Iterator adaptor that invents template argument location information |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4020 | /// for each of the template arguments in its underlying iterator. |
| 4021 | template<typename Derived, typename InputIterator> |
| 4022 | class TemplateArgumentLocInventIterator { |
| 4023 | TreeTransform<Derived> &Self; |
| 4024 | InputIterator Iter; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4025 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4026 | public: |
| 4027 | typedef TemplateArgumentLoc value_type; |
| 4028 | typedef TemplateArgumentLoc reference; |
| 4029 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 4030 | difference_type; |
| 4031 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4032 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4033 | class pointer { |
| 4034 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4035 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4036 | public: |
| 4037 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4038 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4039 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 4040 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4041 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 4042 | TemplateArgumentLocInventIterator() { } |
| 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 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 4045 | InputIterator Iter) |
| 4046 | : Self(Self), Iter(Iter) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4047 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4048 | TemplateArgumentLocInventIterator &operator++() { |
| 4049 | ++Iter; |
| 4050 | return *this; |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 4051 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4052 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4053 | TemplateArgumentLocInventIterator operator++(int) { |
| 4054 | TemplateArgumentLocInventIterator Old(*this); |
| 4055 | ++(*this); |
| 4056 | return Old; |
| 4057 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4058 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4059 | reference operator*() const { |
| 4060 | TemplateArgumentLoc Result; |
| 4061 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 4062 | return Result; |
| 4063 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4064 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4065 | pointer operator->() const { return pointer(**this); } |
| 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 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 4068 | const TemplateArgumentLocInventIterator &Y) { |
| 4069 | return X.Iter == Y.Iter; |
| 4070 | } |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 4071 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4072 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 4073 | const TemplateArgumentLocInventIterator &Y) { |
| 4074 | return X.Iter != Y.Iter; |
| 4075 | } |
| 4076 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4077 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4078 | template<typename Derived> |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4079 | template<typename InputIterator> |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4080 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 4081 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 4082 | bool Uneval) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4083 | for (; First != Last; ++First) { |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4084 | TemplateArgumentLoc Out; |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4085 | TemplateArgumentLoc In = *First; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4086 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4087 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 4088 | // Unpack argument packs, which we translate them into separate |
| 4089 | // arguments. |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4090 | // FIXME: We could do much better if we could guarantee that the |
| 4091 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 4092 | // all of the template arguments in the argument pack. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4093 | typedef TemplateArgumentLocInventIterator<Derived, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4094 | TemplateArgument::pack_iterator> |
| 4095 | PackLocIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4096 | if (TransformTemplateArguments(PackLocIterator(*this, |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4097 | In.getArgument().pack_begin()), |
| 4098 | PackLocIterator(*this, |
| 4099 | In.getArgument().pack_end()), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4100 | Outputs, Uneval)) |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 4101 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4102 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4103 | continue; |
| 4104 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4105 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4106 | if (In.getArgument().isPackExpansion()) { |
| 4107 | // We have a pack expansion, for which we will be substituting into |
| 4108 | // the pattern. |
| 4109 | SourceLocation Ellipsis; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4110 | Optional<unsigned> OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4111 | TemplateArgumentLoc Pattern |
| Eli Friedman | 94e9eaa | 2013-06-20 04:11:21 +0000 | [diff] [blame] | 4112 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 4113 | In, Ellipsis, OrigNumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4114 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 4115 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4116 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4117 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4118 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4119 | // Determine whether the set of unexpanded parameter packs can and should |
| 4120 | // be expanded. |
| 4121 | bool Expand = true; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4122 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4123 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4124 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 4125 | Pattern.getSourceRange(), |
| David Blaikie | b9c168a | 2011-09-22 02:34:54 +0000 | [diff] [blame] | 4126 | Unexpanded, |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4127 | Expand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 4128 | RetainExpansion, |
| 4129 | NumExpansions)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4130 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4131 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4132 | if (!Expand) { |
| 4133 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4134 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4135 | // expansion. |
| 4136 | TemplateArgumentLoc OutPattern; |
| 4137 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4138 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4139 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4140 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4141 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 4142 | NumExpansions); |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4143 | if (Out.getArgument().isNull()) |
| 4144 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4145 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4146 | Outputs.addArgument(Out); |
| 4147 | continue; |
| 4148 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4149 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4150 | // The transform has determined that we should perform an elementwise |
| 4151 | // expansion of the pattern. Do so. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4152 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4153 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4154 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4155 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4156 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4157 | |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4158 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4159 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4160 | OrigNumExpansions); |
| Douglas Gregor | 2fcb863 | 2011-01-11 22:21:24 +0000 | [diff] [blame] | 4161 | if (Out.getArgument().isNull()) |
| 4162 | return true; |
| 4163 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4164 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4165 | Outputs.addArgument(Out); |
| 4166 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4167 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4168 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4169 | // forgetting the partially-substituted parameter pack. |
| 4170 | if (RetainExpansion) { |
| 4171 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4172 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4173 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4174 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4175 | |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4176 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4177 | OrigNumExpansions); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4178 | if (Out.getArgument().isNull()) |
| 4179 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4180 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 4181 | Outputs.addArgument(Out); |
| 4182 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4183 | |
| Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 4184 | continue; |
| 4185 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4186 | |
| 4187 | // The simple case: |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 4188 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4189 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4190 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4191 | Outputs.addArgument(Out); |
| 4192 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4193 | |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 4194 | return false; |
| 4195 | |
| 4196 | } |
| 4197 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4198 | //===----------------------------------------------------------------------===// |
| 4199 | // Type transformation |
| 4200 | //===----------------------------------------------------------------------===// |
| 4201 | |
| 4202 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4203 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4204 | if (getDerived().AlreadyTransformed(T)) |
| 4205 | return T; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4206 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4207 | // Temporary workaround. All of these transformations should |
| 4208 | // eventually turn into transformations on TypeLocs. |
| Douglas Gregor | 2d525f0 | 2011-01-25 19:13:18 +0000 | [diff] [blame] | 4209 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4210 | getDerived().getBaseLocation()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4211 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4212 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4213 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4214 | if (!NewDI) |
| 4215 | return QualType(); |
| 4216 | |
| 4217 | return NewDI->getType(); |
| 4218 | } |
| 4219 | |
| 4220 | template<typename Derived> |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4221 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4222 | // Refine the base location to the type's location. |
| 4223 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4224 | getDerived().getBaseEntity()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4225 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4226 | return DI; |
| 4227 | |
| 4228 | TypeLocBuilder TLB; |
| 4229 | |
| 4230 | TypeLoc TL = DI->getTypeLoc(); |
| 4231 | TLB.reserve(TL.getFullDataSize()); |
| 4232 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4233 | QualType Result = getDerived().TransformType(TLB, TL); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4234 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4235 | return nullptr; |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4236 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4237 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | template<typename Derived> |
| 4241 | QualType |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4242 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4243 | switch (T.getTypeLocClass()) { |
| 4244 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4245 | #define TYPELOC(CLASS, PARENT) \ |
| 4246 | case TypeLoc::CLASS: \ |
| 4247 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 4248 | T.castAs<CLASS##TypeLoc>()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4249 | #include "clang/AST/TypeLocNodes.def" |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4250 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4251 | |
| Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4252 | llvm_unreachable("unhandled type loc!"); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4255 | template<typename Derived> |
| 4256 | QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { |
| 4257 | if (!isa<DependentNameType>(T)) |
| 4258 | return TransformType(T); |
| 4259 | |
| 4260 | if (getDerived().AlreadyTransformed(T)) |
| 4261 | return T; |
| 4262 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4263 | getDerived().getBaseLocation()); |
| 4264 | TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); |
| 4265 | return NewDI ? NewDI->getType() : QualType(); |
| 4266 | } |
| 4267 | |
| 4268 | template<typename Derived> |
| 4269 | TypeSourceInfo * |
| 4270 | TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { |
| 4271 | if (!isa<DependentNameType>(DI->getType())) |
| 4272 | return TransformType(DI); |
| 4273 | |
| 4274 | // Refine the base location to the type's location. |
| 4275 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4276 | getDerived().getBaseEntity()); |
| 4277 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4278 | return DI; |
| 4279 | |
| 4280 | TypeLocBuilder TLB; |
| 4281 | |
| 4282 | TypeLoc TL = DI->getTypeLoc(); |
| 4283 | TLB.reserve(TL.getFullDataSize()); |
| 4284 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4285 | auto QTL = TL.getAs<QualifiedTypeLoc>(); |
| 4286 | if (QTL) |
| 4287 | TL = QTL.getUnqualifiedLoc(); |
| 4288 | |
| 4289 | auto DNTL = TL.castAs<DependentNameTypeLoc>(); |
| 4290 | |
| 4291 | QualType Result = getDerived().TransformDependentNameType( |
| 4292 | TLB, DNTL, /*DeducedTSTContext*/true); |
| 4293 | if (Result.isNull()) |
| 4294 | return nullptr; |
| 4295 | |
| 4296 | if (QTL) { |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4297 | Result = getDerived().RebuildQualifiedType(Result, QTL); |
| 4298 | if (Result.isNull()) |
| 4299 | return nullptr; |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4300 | TLB.TypeWasModifiedSafely(Result); |
| 4301 | } |
| 4302 | |
| 4303 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4304 | } |
| 4305 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4306 | template<typename Derived> |
| 4307 | QualType |
| 4308 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4309 | QualifiedTypeLoc T) { |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4310 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4311 | if (Result.isNull()) |
| 4312 | return QualType(); |
| 4313 | |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4314 | Result = getDerived().RebuildQualifiedType(Result, T); |
| 4315 | |
| 4316 | if (Result.isNull()) |
| 4317 | return QualType(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4318 | |
| 4319 | // RebuildQualifiedType might have updated the type, but not in a way |
| 4320 | // that invalidates the TypeLoc. (There's no location information for |
| 4321 | // qualifiers.) |
| 4322 | TLB.TypeWasModifiedSafely(Result); |
| 4323 | |
| 4324 | return Result; |
| 4325 | } |
| 4326 | |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4327 | template <typename Derived> |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4328 | QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, |
| Anastasia Stulova | 12e3a8a | 2018-12-05 17:02:22 +0000 | [diff] [blame] | 4329 | QualifiedTypeLoc TL) { |
| 4330 | |
| 4331 | SourceLocation Loc = TL.getBeginLoc(); |
| 4332 | Qualifiers Quals = TL.getType().getLocalQualifiers(); |
| 4333 | |
| 4334 | if (((T.getAddressSpace() != LangAS::Default && |
| 4335 | Quals.getAddressSpace() != LangAS::Default)) && |
| 4336 | T.getAddressSpace() != Quals.getAddressSpace()) { |
| 4337 | SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) |
| 4338 | << TL.getType() << T; |
| 4339 | return QualType(); |
| 4340 | } |
| 4341 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4342 | // C++ [dcl.fct]p7: |
| 4343 | // [When] adding cv-qualifications on top of the function type [...] the |
| 4344 | // cv-qualifiers are ignored. |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 4345 | if (T->isFunctionType()) { |
| 4346 | T = SemaRef.getASTContext().getAddrSpaceQualType(T, |
| 4347 | Quals.getAddressSpace()); |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4348 | return T; |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 4349 | } |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4350 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4351 | // C++ [dcl.ref]p1: |
| 4352 | // when the cv-qualifiers are introduced through the use of a typedef-name |
| 4353 | // or decltype-specifier [...] the cv-qualifiers are ignored. |
| 4354 | // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be |
| 4355 | // applied to a reference type. |
| Erik Pilkington | f452337 | 2018-09-20 18:12:24 +0000 | [diff] [blame] | 4356 | if (T->isReferenceType()) { |
| 4357 | // The only qualifier that applies to a reference type is restrict. |
| 4358 | if (!Quals.hasRestrict()) |
| 4359 | return T; |
| 4360 | Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); |
| 4361 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4362 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4363 | // 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] | 4364 | // resulting type. |
| 4365 | if (Quals.hasObjCLifetime()) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4366 | if (!T->isObjCLifetimeType() && !T->isDependentType()) |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4367 | Quals.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4368 | else if (T.getObjCLifetime()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4369 | // Objective-C ARC: |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4370 | // A lifetime qualifier applied to a substituted template parameter |
| 4371 | // overrides the lifetime qualifier from the template argument. |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4372 | const AutoType *AutoTy; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4373 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4374 | = dyn_cast<SubstTemplateTypeParmType>(T)) { |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4375 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 4376 | Qualifiers Qs = Replacement.getQualifiers(); |
| 4377 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4378 | Replacement = SemaRef.Context.getQualifiedType( |
| 4379 | Replacement.getUnqualifiedType(), Qs); |
| 4380 | T = SemaRef.Context.getSubstTemplateTypeParmType( |
| 4381 | SubstTypeParam->getReplacedParameter(), Replacement); |
| 4382 | } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { |
| Douglas Gregor | f4e4331 | 2013-01-17 23:59:28 +0000 | [diff] [blame] | 4383 | // 'auto' types behave the same way as template parameters. |
| 4384 | QualType Deduced = AutoTy->getDeducedType(); |
| 4385 | Qualifiers Qs = Deduced.getQualifiers(); |
| 4386 | Qs.removeObjCLifetime(); |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4387 | Deduced = |
| 4388 | SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); |
| 4389 | T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
| 4390 | AutoTy->isDependentType()); |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4391 | } else { |
| Douglas Gregor | d7357a9 | 2011-06-17 23:16:24 +0000 | [diff] [blame] | 4392 | // Otherwise, complain about the addition of a qualifier to an |
| 4393 | // already-qualified type. |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4394 | // FIXME: Why is this check not in Sema::BuildQualifiedType? |
| 4395 | SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; |
| Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 4396 | Quals.removeObjCLifetime(); |
| 4397 | } |
| 4398 | } |
| 4399 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4400 | |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 4401 | return SemaRef.BuildQualifiedType(T, Loc, Quals); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4402 | } |
| 4403 | |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4404 | template<typename Derived> |
| 4405 | TypeLoc |
| 4406 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 4407 | QualType ObjectType, |
| 4408 | NamedDecl *UnqualLookup, |
| 4409 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4410 | if (getDerived().AlreadyTransformed(TL.getType())) |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4411 | return TL; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4412 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4413 | TypeSourceInfo *TSI = |
| 4414 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 4415 | if (TSI) |
| 4416 | return TSI->getTypeLoc(); |
| 4417 | return TypeLoc(); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4418 | } |
| 4419 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4420 | template<typename Derived> |
| 4421 | TypeSourceInfo * |
| 4422 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4423 | QualType ObjectType, |
| 4424 | NamedDecl *UnqualLookup, |
| 4425 | CXXScopeSpec &SS) { |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4426 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4427 | return TSInfo; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4428 | |
| Reid Kleckner | feb8ac9 | 2013-12-04 22:51:51 +0000 | [diff] [blame] | 4429 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 4430 | UnqualLookup, SS); |
| 4431 | } |
| 4432 | |
| 4433 | template <typename Derived> |
| 4434 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 4435 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 4436 | CXXScopeSpec &SS) { |
| 4437 | QualType T = TL.getType(); |
| 4438 | assert(!getDerived().AlreadyTransformed(T)); |
| 4439 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4440 | TypeLocBuilder TLB; |
| 4441 | QualType Result; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4442 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4443 | if (isa<TemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4444 | TemplateSpecializationTypeLoc SpecTL = |
| 4445 | TL.castAs<TemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4446 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4447 | TemplateName Template = getDerived().TransformTemplateName( |
| 4448 | SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), |
| 4449 | ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4450 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4451 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4452 | |
| 4453 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4454 | Template); |
| 4455 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 4456 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 4457 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4458 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4459 | TemplateName Template |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4460 | = getDerived().RebuildTemplateName(SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 4461 | SpecTL.getTemplateKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4462 | *SpecTL.getTypePtr()->getIdentifier(), |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4463 | SpecTL.getTemplateNameLoc(), |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 4464 | ObjectType, UnqualLookup, |
| 4465 | /*AllowInjectedClassName*/true); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4466 | if (Template.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4467 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4468 | |
| 4469 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4470 | SpecTL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 4471 | Template, |
| 4472 | SS); |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4473 | } else { |
| 4474 | // Nothing special needs to be done for these. |
| 4475 | Result = getDerived().TransformType(TLB, TL); |
| 4476 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4477 | |
| 4478 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4479 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4480 | |
| Douglas Gregor | 579c15f | 2011-03-02 18:32:08 +0000 | [diff] [blame] | 4481 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4482 | } |
| 4483 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4484 | template <class TyLoc> static inline |
| 4485 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 4486 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 4487 | NewT.setNameLoc(T.getNameLoc()); |
| 4488 | return T.getType(); |
| 4489 | } |
| 4490 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4491 | template<typename Derived> |
| 4492 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4493 | BuiltinTypeLoc T) { |
| Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4494 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 4495 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 4496 | if (T.needsExtraLocalData()) |
| 4497 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 4498 | return T.getType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4499 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4500 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4501 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4502 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4503 | ComplexTypeLoc T) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4504 | // FIXME: recurse? |
| 4505 | return TransformTypeSpecType(TLB, T); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4506 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4507 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4508 | template <typename Derived> |
| 4509 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 4510 | AdjustedTypeLoc TL) { |
| 4511 | // Adjustments applied during transformation are handled elsewhere. |
| 4512 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4513 | } |
| 4514 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4515 | template<typename Derived> |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 4516 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4517 | DecayedTypeLoc TL) { |
| 4518 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4519 | if (OriginalType.isNull()) |
| 4520 | return QualType(); |
| 4521 | |
| 4522 | QualType Result = TL.getType(); |
| 4523 | if (getDerived().AlwaysRebuild() || |
| 4524 | OriginalType != TL.getOriginalLoc().getType()) |
| 4525 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4526 | TLB.push<DecayedTypeLoc>(Result); |
| 4527 | // Nothing to set for DecayedTypeLoc. |
| 4528 | return Result; |
| 4529 | } |
| 4530 | |
| 4531 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4532 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4533 | PointerTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4534 | QualType PointeeType |
| 4535 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4536 | if (PointeeType.isNull()) |
| 4537 | return QualType(); |
| 4538 | |
| 4539 | QualType Result = TL.getType(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4540 | if (PointeeType->getAs<ObjCObjectType>()) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4541 | // A dependent pointer type 'T *' has is being transformed such |
| 4542 | // that an Objective-C class type is being replaced for 'T'. The |
| 4543 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4544 | // PointerType. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4545 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4546 | |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4547 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4548 | NewT.setStarLoc(TL.getStarLoc()); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4549 | return Result; |
| 4550 | } |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4551 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4552 | if (getDerived().AlwaysRebuild() || |
| 4553 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4554 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4555 | if (Result.isNull()) |
| 4556 | return QualType(); |
| 4557 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4558 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4559 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4560 | // pointing to. |
| 4561 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4562 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 4563 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4564 | NewT.setSigilLoc(TL.getSigilLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4565 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4566 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4567 | |
| 4568 | template<typename Derived> |
| 4569 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4570 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4571 | BlockPointerTypeLoc TL) { |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4572 | QualType PointeeType |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4573 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4574 | if (PointeeType.isNull()) |
| 4575 | return QualType(); |
| 4576 | |
| 4577 | QualType Result = TL.getType(); |
| 4578 | if (getDerived().AlwaysRebuild() || |
| 4579 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4580 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4581 | TL.getSigilLoc()); |
| 4582 | if (Result.isNull()) |
| 4583 | return QualType(); |
| 4584 | } |
| 4585 | |
| Douglas Gregor | 049211a | 2010-04-22 16:50:51 +0000 | [diff] [blame] | 4586 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
| Douglas Gregor | e1f79e8 | 2010-04-22 16:46:21 +0000 | [diff] [blame] | 4587 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4588 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4591 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4592 | /// don't care whether the type itself is an l-value type or an r-value |
| 4593 | /// type; we only care if the type was *written* as an l-value type |
| 4594 | /// or an r-value type. |
| 4595 | template<typename Derived> |
| 4596 | QualType |
| 4597 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4598 | ReferenceTypeLoc TL) { |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4599 | const ReferenceType *T = TL.getTypePtr(); |
| 4600 | |
| 4601 | // Note that this works with the pointee-as-written. |
| 4602 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4603 | if (PointeeType.isNull()) |
| 4604 | return QualType(); |
| 4605 | |
| 4606 | QualType Result = TL.getType(); |
| 4607 | if (getDerived().AlwaysRebuild() || |
| 4608 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4609 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4610 | T->isSpelledAsLValue(), |
| 4611 | TL.getSigilLoc()); |
| 4612 | if (Result.isNull()) |
| 4613 | return QualType(); |
| 4614 | } |
| 4615 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4616 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4617 | // referring to. |
| 4618 | TLB.TypeWasModifiedSafely( |
| 4619 | Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4620 | |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4621 | // r-value references can be rebuilt as l-value references. |
| 4622 | ReferenceTypeLoc NewTL; |
| 4623 | if (isa<LValueReferenceType>(Result)) |
| 4624 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4625 | else |
| 4626 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4627 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4628 | |
| 4629 | return Result; |
| 4630 | } |
| 4631 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4632 | template<typename Derived> |
| 4633 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4634 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4635 | LValueReferenceTypeLoc TL) { |
| 4636 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4639 | template<typename Derived> |
| 4640 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4641 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4642 | RValueReferenceTypeLoc TL) { |
| 4643 | return TransformReferenceType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4644 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4645 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4646 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4647 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4648 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4649 | MemberPointerTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4650 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4651 | if (PointeeType.isNull()) |
| 4652 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4653 | |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4654 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4655 | TypeSourceInfo *NewClsTInfo = nullptr; |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4656 | if (OldClsTInfo) { |
| 4657 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4658 | if (!NewClsTInfo) |
| 4659 | return QualType(); |
| 4660 | } |
| 4661 | |
| 4662 | const MemberPointerType *T = TL.getTypePtr(); |
| 4663 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4664 | QualType NewClsType; |
| 4665 | if (NewClsTInfo) |
| 4666 | NewClsType = NewClsTInfo->getType(); |
| 4667 | else { |
| 4668 | NewClsType = getDerived().TransformType(OldClsType); |
| 4669 | if (NewClsType.isNull()) |
| 4670 | return QualType(); |
| 4671 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4672 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4673 | QualType Result = TL.getType(); |
| 4674 | if (getDerived().AlwaysRebuild() || |
| 4675 | PointeeType != T->getPointeeType() || |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4676 | NewClsType != OldClsType) { |
| 4677 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4678 | TL.getStarLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4679 | if (Result.isNull()) |
| 4680 | return QualType(); |
| 4681 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4682 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 4683 | // If we had to adjust the pointee type when building a member pointer, make |
| 4684 | // sure to push TypeLoc info for it. |
| 4685 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4686 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4687 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4688 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4689 | } |
| 4690 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4691 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 4692 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4693 | NewTL.setClassTInfo(NewClsTInfo); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4694 | |
| 4695 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4698 | template<typename Derived> |
| 4699 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4700 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4701 | ConstantArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4702 | const ConstantArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4703 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4704 | if (ElementType.isNull()) |
| 4705 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4706 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4707 | QualType Result = TL.getType(); |
| 4708 | if (getDerived().AlwaysRebuild() || |
| 4709 | ElementType != T->getElementType()) { |
| 4710 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 4711 | T->getSizeModifier(), |
| 4712 | T->getSize(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4713 | T->getIndexTypeCVRQualifiers(), |
| 4714 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4715 | if (Result.isNull()) |
| 4716 | return QualType(); |
| 4717 | } |
| Eli Friedman | f7f102f | 2012-01-25 22:19:07 +0000 | [diff] [blame] | 4718 | |
| 4719 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 4720 | // a ConstantArrayType is allowed to have an element type which is a |
| 4721 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 4722 | // types have the same location layout. |
| 4723 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4724 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4725 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4726 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4727 | Expr *Size = TL.getSizeExpr(); |
| 4728 | if (Size) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4729 | EnterExpressionEvaluationContext Unevaluated( |
| 4730 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4731 | Size = getDerived().TransformExpr(Size).template getAs<Expr>(); |
| 4732 | Size = SemaRef.ActOnConstantExpression(Size).get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4733 | } |
| 4734 | NewTL.setSizeExpr(Size); |
| 4735 | |
| 4736 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4737 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4738 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4739 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4740 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4741 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4742 | IncompleteArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4743 | const IncompleteArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4744 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4745 | if (ElementType.isNull()) |
| 4746 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4747 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4748 | QualType Result = TL.getType(); |
| 4749 | if (getDerived().AlwaysRebuild() || |
| 4750 | ElementType != T->getElementType()) { |
| 4751 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4752 | T->getSizeModifier(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4753 | T->getIndexTypeCVRQualifiers(), |
| 4754 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4755 | if (Result.isNull()) |
| 4756 | return QualType(); |
| 4757 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4758 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4759 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 4760 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4761 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 4762 | NewTL.setSizeExpr(nullptr); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4763 | |
| 4764 | return Result; |
| 4765 | } |
| 4766 | |
| 4767 | template<typename Derived> |
| 4768 | QualType |
| 4769 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4770 | VariableArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4771 | const VariableArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4772 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4773 | if (ElementType.isNull()) |
| 4774 | return QualType(); |
| 4775 | |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4776 | ExprResult SizeResult; |
| 4777 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4778 | EnterExpressionEvaluationContext Context( |
| 4779 | SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Tim Shen | b34d0ef | 2017-02-14 23:46:37 +0000 | [diff] [blame] | 4780 | SizeResult = getDerived().TransformExpr(T->getSizeExpr()); |
| 4781 | } |
| 4782 | if (SizeResult.isInvalid()) |
| 4783 | return QualType(); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 4784 | SizeResult = |
| 4785 | SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4786 | if (SizeResult.isInvalid()) |
| 4787 | return QualType(); |
| 4788 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4789 | Expr *Size = SizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4790 | |
| 4791 | QualType Result = TL.getType(); |
| 4792 | if (getDerived().AlwaysRebuild() || |
| 4793 | ElementType != T->getElementType() || |
| 4794 | Size != T->getSizeExpr()) { |
| 4795 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 4796 | T->getSizeModifier(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4797 | Size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4798 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4799 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4800 | if (Result.isNull()) |
| 4801 | return QualType(); |
| 4802 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 4803 | |
| Serge Pavlov | 774c6d0 | 2014-02-06 03:49:11 +0000 | [diff] [blame] | 4804 | // We might have constant size array now, but fortunately it has the same |
| 4805 | // location layout. |
| 4806 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4807 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4808 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 4809 | NewTL.setSizeExpr(Size); |
| 4810 | |
| 4811 | return Result; |
| 4812 | } |
| 4813 | |
| 4814 | template<typename Derived> |
| 4815 | QualType |
| 4816 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4817 | DependentSizedArrayTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4818 | const DependentSizedArrayType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4819 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 4820 | if (ElementType.isNull()) |
| 4821 | return QualType(); |
| 4822 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4823 | // Array bounds are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4824 | EnterExpressionEvaluationContext Unevaluated( |
| 4825 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4826 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4827 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 4828 | Expr *origSize = TL.getSizeExpr(); |
| 4829 | if (!origSize) origSize = T->getSizeExpr(); |
| 4830 | |
| 4831 | ExprResult sizeResult |
| 4832 | = getDerived().TransformExpr(origSize); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4833 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4834 | if (sizeResult.isInvalid()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4835 | return QualType(); |
| 4836 | |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4837 | Expr *size = sizeResult.get(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4838 | |
| 4839 | QualType Result = TL.getType(); |
| 4840 | if (getDerived().AlwaysRebuild() || |
| 4841 | ElementType != T->getElementType() || |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4842 | size != origSize) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4843 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 4844 | T->getSizeModifier(), |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4845 | size, |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4846 | T->getIndexTypeCVRQualifiers(), |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 4847 | TL.getBracketsRange()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4848 | if (Result.isNull()) |
| 4849 | return QualType(); |
| 4850 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4851 | |
| 4852 | // We might have any sort of array type now, but fortunately they |
| 4853 | // all have the same location layout. |
| 4854 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 4855 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 4856 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| John McCall | 33ddac0 | 2011-01-19 10:06:00 +0000 | [diff] [blame] | 4857 | NewTL.setSizeExpr(size); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4858 | |
| 4859 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4860 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4861 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 4862 | template <typename Derived> |
| 4863 | QualType TreeTransform<Derived>::TransformDependentVectorType( |
| 4864 | TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { |
| 4865 | const DependentVectorType *T = TL.getTypePtr(); |
| 4866 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4867 | if (ElementType.isNull()) |
| 4868 | return QualType(); |
| 4869 | |
| 4870 | EnterExpressionEvaluationContext Unevaluated( |
| 4871 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4872 | |
| 4873 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 4874 | Size = SemaRef.ActOnConstantExpression(Size); |
| 4875 | if (Size.isInvalid()) |
| 4876 | return QualType(); |
| 4877 | |
| 4878 | QualType Result = TL.getType(); |
| 4879 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 4880 | Size.get() != T->getSizeExpr()) { |
| 4881 | Result = getDerived().RebuildDependentVectorType( |
| 4882 | ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); |
| 4883 | if (Result.isNull()) |
| 4884 | return QualType(); |
| 4885 | } |
| 4886 | |
| 4887 | // Result might be dependent or not. |
| 4888 | if (isa<DependentVectorType>(Result)) { |
| 4889 | DependentVectorTypeLoc NewTL = |
| 4890 | TLB.push<DependentVectorTypeLoc>(Result); |
| 4891 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4892 | } else { |
| 4893 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 4894 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4895 | } |
| 4896 | |
| 4897 | return Result; |
| 4898 | } |
| 4899 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4900 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4901 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4902 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4903 | DependentSizedExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4904 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4905 | |
| 4906 | // FIXME: ext vector locs should be nested |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4907 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4908 | if (ElementType.isNull()) |
| 4909 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4910 | |
| Richard Smith | 764d2fe | 2011-12-20 02:08:33 +0000 | [diff] [blame] | 4911 | // Vector sizes are constant expressions. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 4912 | EnterExpressionEvaluationContext Unevaluated( |
| 4913 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 4914 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4915 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| Eli Friedman | c6237c6 | 2012-02-29 03:16:56 +0000 | [diff] [blame] | 4916 | Size = SemaRef.ActOnConstantExpression(Size); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4917 | if (Size.isInvalid()) |
| 4918 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4919 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4920 | QualType Result = TL.getType(); |
| 4921 | if (getDerived().AlwaysRebuild() || |
| John McCall | 24e7cb6 | 2009-10-23 17:55:45 +0000 | [diff] [blame] | 4922 | ElementType != T->getElementType() || |
| 4923 | Size.get() != T->getSizeExpr()) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4924 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4925 | Size.get(), |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4926 | T->getAttributeLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4927 | if (Result.isNull()) |
| 4928 | return QualType(); |
| 4929 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4930 | |
| 4931 | // Result might be dependent or not. |
| 4932 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 4933 | DependentSizedExtVectorTypeLoc NewTL |
| 4934 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 4935 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4936 | } else { |
| 4937 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 4938 | NewTL.setNameLoc(TL.getNameLoc()); |
| 4939 | } |
| 4940 | |
| 4941 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4942 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 4944 | template <typename Derived> |
| 4945 | QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( |
| 4946 | TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { |
| 4947 | const DependentAddressSpaceType *T = TL.getTypePtr(); |
| 4948 | |
| 4949 | QualType pointeeType = getDerived().TransformType(T->getPointeeType()); |
| 4950 | |
| 4951 | if (pointeeType.isNull()) |
| 4952 | return QualType(); |
| 4953 | |
| 4954 | // Address spaces are constant expressions. |
| 4955 | EnterExpressionEvaluationContext Unevaluated( |
| 4956 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4957 | |
| 4958 | ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); |
| 4959 | AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); |
| 4960 | if (AddrSpace.isInvalid()) |
| 4961 | return QualType(); |
| 4962 | |
| 4963 | QualType Result = TL.getType(); |
| 4964 | if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || |
| 4965 | AddrSpace.get() != T->getAddrSpaceExpr()) { |
| 4966 | Result = getDerived().RebuildDependentAddressSpaceType( |
| 4967 | pointeeType, AddrSpace.get(), T->getAttributeLoc()); |
| 4968 | if (Result.isNull()) |
| 4969 | return QualType(); |
| 4970 | } |
| 4971 | |
| 4972 | // Result might be dependent or not. |
| 4973 | if (isa<DependentAddressSpaceType>(Result)) { |
| 4974 | DependentAddressSpaceTypeLoc NewTL = |
| 4975 | TLB.push<DependentAddressSpaceTypeLoc>(Result); |
| 4976 | |
| 4977 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 4978 | NewTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 4979 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 4980 | |
| 4981 | } else { |
| 4982 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( |
| 4983 | Result, getDerived().getBaseLocation()); |
| 4984 | TransformType(TLB, DI->getTypeLoc()); |
| 4985 | } |
| 4986 | |
| 4987 | return Result; |
| 4988 | } |
| 4989 | |
| 4990 | template <typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4991 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 4992 | VectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4993 | const VectorType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 4994 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 4995 | if (ElementType.isNull()) |
| 4996 | return QualType(); |
| 4997 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 4998 | QualType Result = TL.getType(); |
| 4999 | if (getDerived().AlwaysRebuild() || |
| 5000 | ElementType != T->getElementType()) { |
| John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 5001 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 5002 | T->getVectorKind()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5003 | if (Result.isNull()) |
| 5004 | return QualType(); |
| 5005 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5006 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5007 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 5008 | NewTL.setNameLoc(TL.getNameLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5009 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5010 | return Result; |
| 5011 | } |
| 5012 | |
| 5013 | template<typename Derived> |
| 5014 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5015 | ExtVectorTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5016 | const VectorType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5017 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 5018 | if (ElementType.isNull()) |
| 5019 | return QualType(); |
| 5020 | |
| 5021 | QualType Result = TL.getType(); |
| 5022 | if (getDerived().AlwaysRebuild() || |
| 5023 | ElementType != T->getElementType()) { |
| 5024 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 5025 | T->getNumElements(), |
| 5026 | /*FIXME*/ SourceLocation()); |
| 5027 | if (Result.isNull()) |
| 5028 | return QualType(); |
| 5029 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5030 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5031 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 5032 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5033 | |
| 5034 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5035 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5037 | template <typename Derived> |
| 5038 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 5039 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 5040 | bool ExpectParameterPack) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5041 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5042 | TypeSourceInfo *NewDI = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5043 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5044 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5045 | // 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] | 5046 | // length we want to expand to, just substitute for the pattern. |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5047 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 5048 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5049 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5050 | TypeLocBuilder TLB; |
| 5051 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 5052 | TLB.reserve(NewTL.getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5053 | |
| 5054 | QualType Result = getDerived().TransformType(TLB, |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5055 | OldExpansionTL.getPatternLoc()); |
| 5056 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5057 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5058 | |
| 5059 | Result = RebuildPackExpansionType(Result, |
| 5060 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5061 | OldExpansionTL.getEllipsisLoc(), |
| 5062 | NumExpansions); |
| 5063 | if (Result.isNull()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5064 | return nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5065 | |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5066 | PackExpansionTypeLoc NewExpansionTL |
| 5067 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 5068 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 5069 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 5070 | } else |
| 5071 | NewDI = getDerived().TransformType(OldDI); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5072 | if (!NewDI) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5073 | return nullptr; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5074 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5075 | if (NewDI == OldDI && indexAdjustment == 0) |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5076 | return OldParm; |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5077 | |
| 5078 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 5079 | OldParm->getDeclContext(), |
| 5080 | OldParm->getInnerLocStart(), |
| 5081 | OldParm->getLocation(), |
| 5082 | OldParm->getIdentifier(), |
| 5083 | NewDI->getType(), |
| 5084 | NewDI, |
| 5085 | OldParm->getStorageClass(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5086 | /* DefArg */ nullptr); |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5087 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 5088 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 5089 | return newParm; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5092 | template <typename Derived> |
| 5093 | bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 5094 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 5095 | const QualType *ParamTypes, |
| 5096 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 5097 | SmallVectorImpl<QualType> &OutParamTypes, |
| 5098 | SmallVectorImpl<ParmVarDecl *> *PVars, |
| 5099 | Sema::ExtParameterInfoBuilder &PInfos) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5100 | int indexAdjustment = 0; |
| 5101 | |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5102 | unsigned NumParams = Params.size(); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5103 | for (unsigned i = 0; i != NumParams; ++i) { |
| 5104 | if (ParmVarDecl *OldParm = Params[i]) { |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5105 | assert(OldParm->getFunctionScopeIndex() == i); |
| 5106 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5107 | Optional<unsigned> NumExpansions; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5108 | ParmVarDecl *NewParm = nullptr; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5109 | if (OldParm->isParameterPack()) { |
| 5110 | // We have a function parameter pack that may need to be expanded. |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5111 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5112 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5113 | // Find the parameter packs that could be expanded. |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5114 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 5115 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5116 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 5117 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5118 | assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); |
| 5119 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5120 | // Determine whether we should expand the parameter packs. |
| 5121 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5122 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5123 | Optional<unsigned> OrigNumExpansions = |
| 5124 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5125 | NumExpansions = OrigNumExpansions; |
| Douglas Gregor | f6272cd | 2011-01-05 23:16:57 +0000 | [diff] [blame] | 5126 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 5127 | Pattern.getSourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5128 | Unexpanded, |
| 5129 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5130 | RetainExpansion, |
| 5131 | NumExpansions)) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5132 | return true; |
| 5133 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5134 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5135 | if (ShouldExpand) { |
| 5136 | // Expand the function parameter pack into multiple, separate |
| 5137 | // parameters. |
| Douglas Gregor | f301011 | 2011-01-07 16:43:16 +0000 | [diff] [blame] | 5138 | getDerived().ExpandingFunctionParameterPack(OldParm); |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5139 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5140 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5141 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5142 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5143 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5144 | OrigNumExpansions, |
| 5145 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5146 | if (!NewParm) |
| 5147 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5148 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5149 | if (ParamInfos) |
| 5150 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5151 | OutParamTypes.push_back(NewParm->getType()); |
| 5152 | if (PVars) |
| 5153 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5154 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5155 | |
| 5156 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5157 | // forgetting the partially-substituted parameter pack. |
| 5158 | if (RetainExpansion) { |
| 5159 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5160 | ParmVarDecl *NewParm |
| Douglas Gregor | 715e461 | 2011-01-14 22:40:04 +0000 | [diff] [blame] | 5161 | = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5162 | indexAdjustment++, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5163 | OrigNumExpansions, |
| 5164 | /*ExpectParameterPack=*/false); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5165 | if (!NewParm) |
| 5166 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5167 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5168 | if (ParamInfos) |
| 5169 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5170 | OutParamTypes.push_back(NewParm->getType()); |
| 5171 | if (PVars) |
| 5172 | PVars->push_back(NewParm); |
| 5173 | } |
| 5174 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5175 | // The next parameter should have the same adjustment as the |
| 5176 | // last thing we pushed, but we post-incremented indexAdjustment |
| 5177 | // on every push. Also, if we push nothing, the adjustment should |
| 5178 | // go down by one. |
| 5179 | indexAdjustment--; |
| 5180 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5181 | // We're done with the pack expansion. |
| 5182 | continue; |
| 5183 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5184 | |
| 5185 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5186 | // expansion. |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5187 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5188 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5189 | indexAdjustment, |
| Douglas Gregor | 0dd22bc | 2012-01-25 16:15:54 +0000 | [diff] [blame] | 5190 | NumExpansions, |
| 5191 | /*ExpectParameterPack=*/true); |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5192 | } else { |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5193 | NewParm = getDerived().TransformFunctionTypeParam( |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 5194 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5195 | } |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5196 | |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5197 | if (!NewParm) |
| 5198 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5199 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5200 | if (ParamInfos) |
| 5201 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5202 | OutParamTypes.push_back(NewParm->getType()); |
| 5203 | if (PVars) |
| 5204 | PVars->push_back(NewParm); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5205 | continue; |
| 5206 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5207 | |
| 5208 | // Deal with the possibility that we don't have a parameter |
| 5209 | // declaration for this parameter. |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5210 | QualType OldType = ParamTypes[i]; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5211 | bool IsPackExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5212 | Optional<unsigned> NumExpansions; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5213 | QualType NewType; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5214 | if (const PackExpansionType *Expansion |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5215 | = dyn_cast<PackExpansionType>(OldType)) { |
| 5216 | // We have a function parameter pack that may need to be expanded. |
| 5217 | QualType Pattern = Expansion->getPattern(); |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5218 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5219 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5220 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5221 | // Determine whether we should expand the parameter packs. |
| 5222 | bool ShouldExpand = false; |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5223 | bool RetainExpansion = false; |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5224 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5225 | Unexpanded, |
| 5226 | ShouldExpand, |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5227 | RetainExpansion, |
| 5228 | NumExpansions)) { |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5229 | return true; |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5230 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5231 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5232 | if (ShouldExpand) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5233 | // Expand the function parameter pack into multiple, separate |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5234 | // parameters. |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5235 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5236 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 5237 | QualType NewType = getDerived().TransformType(Pattern); |
| 5238 | if (NewType.isNull()) |
| 5239 | return true; |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5240 | |
| Erik Pilkington | f1bd000 | 2016-07-05 17:57:24 +0000 | [diff] [blame] | 5241 | if (NewType->containsUnexpandedParameterPack()) { |
| 5242 | NewType = |
| 5243 | getSema().getASTContext().getPackExpansionType(NewType, None); |
| 5244 | |
| 5245 | if (NewType.isNull()) |
| 5246 | return true; |
| 5247 | } |
| 5248 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5249 | if (ParamInfos) |
| 5250 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5251 | OutParamTypes.push_back(NewType); |
| 5252 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5253 | PVars->push_back(nullptr); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5254 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5255 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5256 | // We're done with the pack expansion. |
| 5257 | continue; |
| 5258 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5259 | |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5260 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5261 | // forgetting the partially-substituted parameter pack. |
| 5262 | if (RetainExpansion) { |
| 5263 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5264 | QualType NewType = getDerived().TransformType(Pattern); |
| 5265 | if (NewType.isNull()) |
| 5266 | return true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5267 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5268 | if (ParamInfos) |
| 5269 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5270 | OutParamTypes.push_back(NewType); |
| 5271 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5272 | PVars->push_back(nullptr); |
| Douglas Gregor | 48d2411 | 2011-01-10 20:53:55 +0000 | [diff] [blame] | 5273 | } |
| Douglas Gregor | a8bac7f | 2011-01-10 07:32:04 +0000 | [diff] [blame] | 5274 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5275 | // We'll substitute the parameter now without expanding the pack |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5276 | // expansion. |
| 5277 | OldType = Expansion->getPattern(); |
| 5278 | IsPackExpansion = true; |
| Douglas Gregor | c52264e | 2011-03-02 02:04:06 +0000 | [diff] [blame] | 5279 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5280 | NewType = getDerived().TransformType(OldType); |
| 5281 | } else { |
| 5282 | NewType = getDerived().TransformType(OldType); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5283 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5284 | |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5285 | if (NewType.isNull()) |
| 5286 | return true; |
| 5287 | |
| 5288 | if (IsPackExpansion) |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 5289 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 5290 | NumExpansions); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5291 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5292 | if (ParamInfos) |
| 5293 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| Douglas Gregor | dd47216 | 2011-01-07 00:20:55 +0000 | [diff] [blame] | 5294 | OutParamTypes.push_back(NewType); |
| 5295 | if (PVars) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 5296 | PVars->push_back(nullptr); |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5297 | } |
| 5298 | |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5299 | #ifndef NDEBUG |
| 5300 | if (PVars) { |
| 5301 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 5302 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 5303 | assert(parm->getFunctionScopeIndex() == i); |
| Douglas Gregor | 5499af4 | 2011-01-05 23:12:31 +0000 | [diff] [blame] | 5304 | } |
| John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 5305 | #endif |
| 5306 | |
| 5307 | return false; |
| 5308 | } |
| John McCall | 58f10c3 | 2010-03-11 09:03:00 +0000 | [diff] [blame] | 5309 | |
| 5310 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5311 | QualType |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5312 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5313 | FunctionProtoTypeLoc TL) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5314 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5315 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5316 | return getDerived().TransformFunctionProtoType( |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 5317 | TLB, TL, nullptr, Qualifiers(), |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 5318 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 5319 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 5320 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5321 | }); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5324 | template<typename Derived> template<typename Fn> |
| 5325 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 5326 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 5327 | Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5328 | |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5329 | // Transform the parameters and return type. |
| 5330 | // |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5331 | // 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] | 5332 | // When the function has a trailing return type, we instantiate the |
| 5333 | // parameters before the return type, since the return type can then refer |
| 5334 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 5335 | // |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 5336 | SmallVector<QualType, 4> ParamTypes; |
| 5337 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5338 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5339 | const FunctionProtoType *T = TL.getTypePtr(); |
| Douglas Gregor | 4afc236 | 2010-08-31 00:26:14 +0000 | [diff] [blame] | 5340 | |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5341 | QualType ResultType; |
| 5342 | |
| Richard Smith | 1226c60 | 2012-08-14 22:51:13 +0000 | [diff] [blame] | 5343 | if (T->hasTrailingReturn()) { |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5344 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5345 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5346 | TL.getTypePtr()->param_type_begin(), |
| 5347 | T->getExtParameterInfosOrNull(), |
| 5348 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5349 | return QualType(); |
| 5350 | |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5351 | { |
| 5352 | // C++11 [expr.prim.general]p3: |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5353 | // If a declaration declares a member function or member function |
| 5354 | // 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] | 5355 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5356 | // and the end of the function-definition, member-declarator, or |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5357 | // declarator. |
| 5358 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5359 | |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5360 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 5361 | if (ResultType.isNull()) |
| 5362 | return QualType(); |
| 5363 | } |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5364 | } |
| 5365 | else { |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5366 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5367 | if (ResultType.isNull()) |
| 5368 | return QualType(); |
| 5369 | |
| Anastasia Stulova | 6a4c346 | 2018-11-29 14:11:15 +0000 | [diff] [blame] | 5370 | // Return type can not be qualified with an address space. |
| 5371 | if (ResultType.getAddressSpace() != LangAS::Default) { |
| 5372 | SemaRef.Diag(TL.getReturnLoc().getBeginLoc(), |
| 5373 | diag::err_attribute_address_function_type); |
| 5374 | return QualType(); |
| 5375 | } |
| 5376 | |
| Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 5377 | if (getDerived().TransformFunctionTypeParams( |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 5378 | TL.getBeginLoc(), TL.getParams(), |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5379 | TL.getTypePtr()->param_type_begin(), |
| 5380 | T->getExtParameterInfosOrNull(), |
| 5381 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 5382 | return QualType(); |
| 5383 | } |
| 5384 | |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5385 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 5386 | |
| 5387 | bool EPIChanged = false; |
| 5388 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 5389 | return QualType(); |
| 5390 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 5391 | // Handle extended parameter information. |
| 5392 | if (auto NewExtParamInfos = |
| 5393 | ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 5394 | if (!EPI.ExtParameterInfos || |
| 5395 | llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) |
| 5396 | != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 5397 | EPIChanged = true; |
| 5398 | } |
| 5399 | EPI.ExtParameterInfos = NewExtParamInfos; |
| 5400 | } else if (EPI.ExtParameterInfos) { |
| 5401 | EPIChanged = true; |
| 5402 | EPI.ExtParameterInfos = nullptr; |
| 5403 | } |
| Richard Smith | f623c96 | 2012-04-17 00:58:00 +0000 | [diff] [blame] | 5404 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5405 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5406 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
| Benjamin Kramer | e1c08b0 | 2015-08-18 08:10:39 +0000 | [diff] [blame] | 5407 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5408 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5409 | if (Result.isNull()) |
| 5410 | return QualType(); |
| 5411 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5412 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5413 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5414 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5415 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5416 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 5417 | NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5418 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 5419 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 5420 | NewTL.setParam(i, ParamDecls[i]); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5421 | |
| 5422 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5423 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5424 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5425 | template<typename Derived> |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5426 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 5427 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 5428 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 5429 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 5430 | |
| 5431 | // Instantiate a dynamic noexcept expression, if any. |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5432 | if (isComputedNoexcept(ESI.Type)) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5433 | EnterExpressionEvaluationContext Unevaluated( |
| 5434 | getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5435 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 5436 | if (NoexceptExpr.isInvalid()) |
| 5437 | return true; |
| 5438 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5439 | ExceptionSpecificationType EST = ESI.Type; |
| 5440 | NoexceptExpr = |
| 5441 | getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5442 | if (NoexceptExpr.isInvalid()) |
| 5443 | return true; |
| 5444 | |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5445 | if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5446 | Changed = true; |
| 5447 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 5448 | ESI.Type = EST; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | if (ESI.Type != EST_Dynamic) |
| 5452 | return false; |
| 5453 | |
| 5454 | // Instantiate a dynamic exception specification's type. |
| 5455 | for (QualType T : ESI.Exceptions) { |
| 5456 | if (const PackExpansionType *PackExpansion = |
| 5457 | T->getAs<PackExpansionType>()) { |
| 5458 | Changed = true; |
| 5459 | |
| 5460 | // We have a pack expansion. Instantiate it. |
| 5461 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5462 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5463 | Unexpanded); |
| 5464 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5465 | |
| 5466 | // Determine whether the set of unexpanded parameter packs can and |
| 5467 | // should |
| 5468 | // be expanded. |
| 5469 | bool Expand = false; |
| 5470 | bool RetainExpansion = false; |
| 5471 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5472 | // FIXME: Track the location of the ellipsis (and track source location |
| 5473 | // information for the types in the exception specification in general). |
| 5474 | if (getDerived().TryExpandParameterPacks( |
| 5475 | Loc, SourceRange(), Unexpanded, Expand, |
| 5476 | RetainExpansion, NumExpansions)) |
| 5477 | return true; |
| 5478 | |
| 5479 | if (!Expand) { |
| 5480 | // We can't expand this pack expansion into separate arguments yet; |
| 5481 | // just substitute into the pattern and create a new pack expansion |
| 5482 | // type. |
| 5483 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5484 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5485 | if (U.isNull()) |
| 5486 | return true; |
| 5487 | |
| 5488 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 5489 | Exceptions.push_back(U); |
| 5490 | continue; |
| 5491 | } |
| 5492 | |
| 5493 | // Substitute into the pack expansion pattern for each slice of the |
| 5494 | // pack. |
| 5495 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5496 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5497 | |
| 5498 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5499 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5500 | return true; |
| 5501 | |
| 5502 | Exceptions.push_back(U); |
| 5503 | } |
| 5504 | } else { |
| 5505 | QualType U = getDerived().TransformType(T); |
| 5506 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5507 | return true; |
| 5508 | if (T != U) |
| 5509 | Changed = true; |
| 5510 | |
| 5511 | Exceptions.push_back(U); |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | ESI.Exceptions = Exceptions; |
| Richard Smith | fda59e5 | 2016-10-26 01:05:54 +0000 | [diff] [blame] | 5516 | if (ESI.Exceptions.empty()) |
| 5517 | ESI.Type = EST_DynamicNone; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 5518 | return false; |
| 5519 | } |
| 5520 | |
| 5521 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5522 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5523 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5524 | FunctionNoProtoTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5525 | const FunctionNoProtoType *T = TL.getTypePtr(); |
| Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 5526 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5527 | if (ResultType.isNull()) |
| 5528 | return QualType(); |
| 5529 | |
| 5530 | QualType Result = TL.getType(); |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 5531 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5532 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 5533 | |
| 5534 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5535 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| Abramo Bagnara | aeeb989 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 5536 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5537 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 5538 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5539 | |
| 5540 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5541 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5542 | |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5543 | template<typename Derived> QualType |
| 5544 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5545 | UnresolvedUsingTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5546 | const UnresolvedUsingType *T = TL.getTypePtr(); |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5547 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5548 | if (!D) |
| 5549 | return QualType(); |
| 5550 | |
| 5551 | QualType Result = TL.getType(); |
| 5552 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 5553 | Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 5554 | if (Result.isNull()) |
| 5555 | return QualType(); |
| 5556 | } |
| 5557 | |
| 5558 | // We might get an arbitrary type spec type back. We should at |
| 5559 | // least always get a type spec type, though. |
| 5560 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 5561 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5562 | |
| 5563 | return Result; |
| 5564 | } |
| 5565 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5566 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5567 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5568 | TypedefTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5569 | const TypedefType *T = TL.getTypePtr(); |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 5570 | TypedefNameDecl *Typedef |
| 5571 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5572 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5573 | if (!Typedef) |
| 5574 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5575 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5576 | QualType Result = TL.getType(); |
| 5577 | if (getDerived().AlwaysRebuild() || |
| 5578 | Typedef != T->getDecl()) { |
| 5579 | Result = getDerived().RebuildTypedefType(Typedef); |
| 5580 | if (Result.isNull()) |
| 5581 | return QualType(); |
| 5582 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5583 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5584 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 5585 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5586 | |
| 5587 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5588 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5589 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5590 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5591 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5592 | TypeOfExprTypeLoc TL) { |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5593 | // typeof expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5594 | EnterExpressionEvaluationContext Unevaluated( |
| 5595 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 5596 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5597 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5598 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5599 | if (E.isInvalid()) |
| 5600 | return QualType(); |
| 5601 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 5602 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 5603 | if (E.isInvalid()) |
| 5604 | return QualType(); |
| 5605 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5606 | QualType Result = TL.getType(); |
| 5607 | if (getDerived().AlwaysRebuild() || |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5608 | E.get() != TL.getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5609 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5610 | if (Result.isNull()) |
| 5611 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5612 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5613 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5614 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5615 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5616 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5617 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5618 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5619 | |
| 5620 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5621 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5622 | |
| 5623 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5624 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5625 | TypeOfTypeLoc TL) { |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5626 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 5627 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 5628 | if (!New_Under_TI) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5629 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5630 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5631 | QualType Result = TL.getType(); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5632 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 5633 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5634 | if (Result.isNull()) |
| 5635 | return QualType(); |
| 5636 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5638 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| John McCall | e859503 | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 5639 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 5640 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5641 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5642 | NewTL.setUnderlyingTInfo(New_Under_TI); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5643 | |
| 5644 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5645 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5646 | |
| 5647 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5648 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5649 | DecltypeTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5650 | const DecltypeType *T = TL.getTypePtr(); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5651 | |
| Douglas Gregor | e922c77 | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 5652 | // decltype expressions are not potentially evaluated contexts |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 5653 | EnterExpressionEvaluationContext Unevaluated( |
| 5654 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| Nicolas Lesser | b6d5c58 | 2018-07-12 18:45:41 +0000 | [diff] [blame] | 5655 | Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5656 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 5657 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5658 | if (E.isInvalid()) |
| 5659 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5660 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5661 | E = getSema().ActOnDecltypeExpression(E.get()); |
| Richard Smith | fd555f6 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 5662 | if (E.isInvalid()) |
| 5663 | return QualType(); |
| 5664 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5665 | QualType Result = TL.getType(); |
| 5666 | if (getDerived().AlwaysRebuild() || |
| 5667 | E.get() != T->getUnderlyingExpr()) { |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 5668 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5669 | if (Result.isNull()) |
| 5670 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5671 | } |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5672 | else E.get(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5673 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5674 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 5675 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5676 | |
| 5677 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 5681 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 5682 | TypeLocBuilder &TLB, |
| 5683 | UnaryTransformTypeLoc TL) { |
| 5684 | QualType Result = TL.getType(); |
| 5685 | if (Result->isDependentType()) { |
| 5686 | const UnaryTransformType *T = TL.getTypePtr(); |
| 5687 | QualType NewBase = |
| 5688 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 5689 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 5690 | T->getUTTKind(), |
| 5691 | TL.getKWLoc()); |
| 5692 | if (Result.isNull()) |
| 5693 | return QualType(); |
| 5694 | } |
| 5695 | |
| 5696 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 5697 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5698 | NewTL.setParensRange(TL.getParensRange()); |
| 5699 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 5700 | return Result; |
| 5701 | } |
| 5702 | |
| 5703 | template<typename Derived> |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5704 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 5705 | AutoTypeLoc TL) { |
| 5706 | const AutoType *T = TL.getTypePtr(); |
| 5707 | QualType OldDeduced = T->getDeducedType(); |
| 5708 | QualType NewDeduced; |
| 5709 | if (!OldDeduced.isNull()) { |
| 5710 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5711 | if (NewDeduced.isNull()) |
| 5712 | return QualType(); |
| 5713 | } |
| 5714 | |
| 5715 | QualType Result = TL.getType(); |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5716 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 5717 | T->isDependentType()) { |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5718 | Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword()); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 5719 | if (Result.isNull()) |
| 5720 | return QualType(); |
| 5721 | } |
| 5722 | |
| 5723 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 5724 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5725 | |
| 5726 | return Result; |
| 5727 | } |
| 5728 | |
| 5729 | template<typename Derived> |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 5730 | QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( |
| 5731 | TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { |
| 5732 | const DeducedTemplateSpecializationType *T = TL.getTypePtr(); |
| 5733 | |
| 5734 | CXXScopeSpec SS; |
| 5735 | TemplateName TemplateName = getDerived().TransformTemplateName( |
| 5736 | SS, T->getTemplateName(), TL.getTemplateNameLoc()); |
| 5737 | if (TemplateName.isNull()) |
| 5738 | return QualType(); |
| 5739 | |
| 5740 | QualType OldDeduced = T->getDeducedType(); |
| 5741 | QualType NewDeduced; |
| 5742 | if (!OldDeduced.isNull()) { |
| 5743 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 5744 | if (NewDeduced.isNull()) |
| 5745 | return QualType(); |
| 5746 | } |
| 5747 | |
| 5748 | QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( |
| 5749 | TemplateName, NewDeduced); |
| 5750 | if (Result.isNull()) |
| 5751 | return QualType(); |
| 5752 | |
| 5753 | DeducedTemplateSpecializationTypeLoc NewTL = |
| 5754 | TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 5755 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 5756 | |
| 5757 | return Result; |
| 5758 | } |
| 5759 | |
| 5760 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5761 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5762 | RecordTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5763 | const RecordType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5764 | RecordDecl *Record |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5765 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5766 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5767 | if (!Record) |
| 5768 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5769 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5770 | QualType Result = TL.getType(); |
| 5771 | if (getDerived().AlwaysRebuild() || |
| 5772 | Record != T->getDecl()) { |
| 5773 | Result = getDerived().RebuildRecordType(Record); |
| 5774 | if (Result.isNull()) |
| 5775 | return QualType(); |
| 5776 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5777 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5778 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 5779 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5780 | |
| 5781 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5782 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5783 | |
| 5784 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5785 | QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5786 | EnumTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 5787 | const EnumType *T = TL.getTypePtr(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5788 | EnumDecl *Enum |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 5789 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5790 | T->getDecl())); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5791 | if (!Enum) |
| 5792 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5793 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5794 | QualType Result = TL.getType(); |
| 5795 | if (getDerived().AlwaysRebuild() || |
| 5796 | Enum != T->getDecl()) { |
| 5797 | Result = getDerived().RebuildEnumType(Enum); |
| 5798 | if (Result.isNull()) |
| 5799 | return QualType(); |
| 5800 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5801 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5802 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 5803 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5804 | |
| 5805 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5806 | } |
| John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 5807 | |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5808 | template<typename Derived> |
| 5809 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 5810 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5811 | InjectedClassNameTypeLoc TL) { |
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 5812 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 5813 | TL.getTypePtr()->getDecl()); |
| 5814 | if (!D) return QualType(); |
| 5815 | |
| 5816 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 5817 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 5818 | return T; |
| 5819 | } |
| 5820 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5821 | template<typename Derived> |
| 5822 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5823 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5824 | TemplateTypeParmTypeLoc TL) { |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5825 | return TransformTypeSpecType(TLB, TL); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5826 | } |
| 5827 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5828 | template<typename Derived> |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5829 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 5830 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5831 | SubstTemplateTypeParmTypeLoc TL) { |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5832 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5833 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5834 | // Substitute into the replacement type, which itself might involve something |
| 5835 | // that needs to be transformed. This only tends to occur with default |
| 5836 | // template arguments of template template parameters. |
| 5837 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 5838 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 5839 | if (Replacement.isNull()) |
| 5840 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5841 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5842 | // Always canonicalize the replacement type. |
| 5843 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 5844 | QualType Result |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5845 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5846 | Replacement); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5847 | |
| Douglas Gregor | 20bf98b | 2011-03-05 17:19:27 +0000 | [diff] [blame] | 5848 | // Propagate type-source information. |
| 5849 | SubstTemplateTypeParmTypeLoc NewTL |
| 5850 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 5851 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5852 | return Result; |
| 5853 | |
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | template<typename Derived> |
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 5857 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 5858 | TypeLocBuilder &TLB, |
| 5859 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 5860 | return TransformTypeSpecType(TLB, TL); |
| 5861 | } |
| 5862 | |
| 5863 | template<typename Derived> |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5864 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5865 | TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5866 | TemplateSpecializationTypeLoc TL) { |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5867 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 5868 | |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5869 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 5870 | // because we can't have a dependent nested-name-specifier anyway. |
| 5871 | CXXScopeSpec SS; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5872 | TemplateName Template |
| Douglas Gregor | df846d1 | 2011-03-02 18:46:51 +0000 | [diff] [blame] | 5873 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 5874 | TL.getTemplateNameLoc()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 5875 | if (Template.isNull()) |
| 5876 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5877 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5878 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 5879 | } |
| 5880 | |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 5881 | template<typename Derived> |
| 5882 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 5883 | AtomicTypeLoc TL) { |
| 5884 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5885 | if (ValueType.isNull()) |
| 5886 | return QualType(); |
| 5887 | |
| 5888 | QualType Result = TL.getType(); |
| 5889 | if (getDerived().AlwaysRebuild() || |
| 5890 | ValueType != TL.getValueLoc().getType()) { |
| 5891 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 5892 | if (Result.isNull()) |
| 5893 | return QualType(); |
| 5894 | } |
| 5895 | |
| 5896 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 5897 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5898 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5899 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5900 | |
| 5901 | return Result; |
| 5902 | } |
| 5903 | |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5904 | template <typename Derived> |
| 5905 | QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 5906 | PipeTypeLoc TL) { |
| 5907 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 5908 | if (ValueType.isNull()) |
| 5909 | return QualType(); |
| 5910 | |
| 5911 | QualType Result = TL.getType(); |
| 5912 | if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 5913 | const PipeType *PT = Result->getAs<PipeType>(); |
| 5914 | bool isReadPipe = PT->isReadOnly(); |
| 5915 | Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 5916 | if (Result.isNull()) |
| 5917 | return QualType(); |
| 5918 | } |
| 5919 | |
| 5920 | PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 5921 | NewTL.setKWLoc(TL.getKWLoc()); |
| 5922 | |
| 5923 | return Result; |
| 5924 | } |
| 5925 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5926 | /// Simple iterator that traverses the template arguments in a |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5927 | /// container that provides a \c getArgLoc() member function. |
| 5928 | /// |
| 5929 | /// This iterator is intended to be used with the iterator form of |
| 5930 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 5931 | template<typename ArgLocContainer> |
| 5932 | class TemplateArgumentLocContainerIterator { |
| 5933 | ArgLocContainer *Container; |
| 5934 | unsigned Index; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5935 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5936 | public: |
| 5937 | typedef TemplateArgumentLoc value_type; |
| 5938 | typedef TemplateArgumentLoc reference; |
| 5939 | typedef int difference_type; |
| 5940 | typedef std::input_iterator_tag iterator_category; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5941 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5942 | class pointer { |
| 5943 | TemplateArgumentLoc Arg; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5944 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5945 | public: |
| 5946 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5947 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5948 | const TemplateArgumentLoc *operator->() const { |
| 5949 | return &Arg; |
| 5950 | } |
| 5951 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5952 | |
| 5953 | |
| Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 5954 | TemplateArgumentLocContainerIterator() {} |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5955 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5956 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 5957 | unsigned Index) |
| 5958 | : Container(&Container), Index(Index) { } |
| 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 | TemplateArgumentLocContainerIterator &operator++() { |
| 5961 | ++Index; |
| 5962 | return *this; |
| 5963 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5964 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5965 | TemplateArgumentLocContainerIterator operator++(int) { |
| 5966 | TemplateArgumentLocContainerIterator Old(*this); |
| 5967 | ++(*this); |
| 5968 | return Old; |
| 5969 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5970 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5971 | TemplateArgumentLoc operator*() const { |
| 5972 | return Container->getArgLoc(Index); |
| 5973 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5974 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5975 | pointer operator->() const { |
| 5976 | return pointer(Container->getArgLoc(Index)); |
| 5977 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5978 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5979 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5980 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5981 | return X.Container == Y.Container && X.Index == Y.Index; |
| 5982 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5983 | |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5984 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
| Douglas Gregor | 5c7aa98 | 2010-12-21 21:51:48 +0000 | [diff] [blame] | 5985 | const TemplateArgumentLocContainerIterator &Y) { |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5986 | return !(X == Y); |
| 5987 | } |
| 5988 | }; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 5989 | |
| 5990 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 5991 | template <typename Derived> |
| 5992 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 5993 | TypeLocBuilder &TLB, |
| 5994 | TemplateSpecializationTypeLoc TL, |
| 5995 | TemplateName Template) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 5996 | TemplateArgumentListInfo NewTemplateArgs; |
| 5997 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 5998 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 5999 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 6000 | ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6001 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | fe921a7 | 2010-12-20 23:36:19 +0000 | [diff] [blame] | 6002 | ArgIterator(TL, TL.getNumArgs()), |
| 6003 | NewTemplateArgs)) |
| Douglas Gregor | 42cafa8 | 2010-12-20 17:42:22 +0000 | [diff] [blame] | 6004 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6005 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6006 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 6007 | |
| 6008 | QualType Result = |
| 6009 | getDerived().RebuildTemplateSpecializationType(Template, |
| 6010 | TL.getTemplateNameLoc(), |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 6011 | NewTemplateArgs); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6012 | |
| 6013 | if (!Result.isNull()) { |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6014 | // Specializations of template template parameters are represented as |
| 6015 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 6016 | // within a dependent context can transform them into |
| 6017 | // DependentTemplateSpecializationTypes. |
| 6018 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6019 | DependentTemplateSpecializationTypeLoc NewTL |
| 6020 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6021 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6022 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6023 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6024 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6025 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6026 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6027 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6028 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6029 | return Result; |
| 6030 | } |
| 6031 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6032 | TemplateSpecializationTypeLoc NewTL |
| 6033 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6034 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6035 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6036 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6037 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6038 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6039 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6040 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6041 | |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6042 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6043 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6044 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6045 | template <typename Derived> |
| 6046 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 6047 | TypeLocBuilder &TLB, |
| 6048 | DependentTemplateSpecializationTypeLoc TL, |
| Douglas Gregor | 23648d7 | 2011-03-04 18:53:13 +0000 | [diff] [blame] | 6049 | TemplateName Template, |
| 6050 | CXXScopeSpec &SS) { |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6051 | TemplateArgumentListInfo NewTemplateArgs; |
| 6052 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6053 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6054 | typedef TemplateArgumentLocContainerIterator< |
| 6055 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6056 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6057 | ArgIterator(TL, TL.getNumArgs()), |
| 6058 | NewTemplateArgs)) |
| 6059 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6060 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6061 | // 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] | 6062 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6063 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 6064 | QualType Result |
| 6065 | = getSema().Context.getDependentTemplateSpecializationType( |
| 6066 | TL.getTypePtr()->getKeyword(), |
| 6067 | DTN->getQualifier(), |
| 6068 | DTN->getIdentifier(), |
| 6069 | NewTemplateArgs); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6070 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6071 | DependentTemplateSpecializationTypeLoc NewTL |
| 6072 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6073 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6074 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6075 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6076 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6077 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6078 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6079 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6080 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6081 | return Result; |
| 6082 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6083 | |
| 6084 | QualType Result |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6085 | = getDerived().RebuildTemplateSpecializationType(Template, |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6086 | TL.getTemplateNameLoc(), |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 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 | if (!Result.isNull()) { |
| 6090 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 6091 | TemplateSpecializationTypeLoc NewTL |
| 6092 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 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 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6100 | |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6101 | return Result; |
| 6102 | } |
| 6103 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6104 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6105 | QualType |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6106 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6107 | ElaboratedTypeLoc TL) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6108 | const ElaboratedType *T = TL.getTypePtr(); |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6109 | |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6110 | NestedNameSpecifierLoc QualifierLoc; |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6111 | // NOTE: the qualifier in an ElaboratedType is optional. |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6112 | if (TL.getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6113 | QualifierLoc |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6114 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6115 | if (!QualifierLoc) |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6116 | return QualType(); |
| 6117 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6118 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6119 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 6120 | if (NamedT.isNull()) |
| 6121 | return QualType(); |
| Daniel Dunbar | 4707cef | 2010-05-14 16:34:09 +0000 | [diff] [blame] | 6122 | |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6123 | // C++0x [dcl.type.elab]p2: |
| 6124 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 6125 | // resolves to an alias template specialization, the |
| 6126 | // elaborated-type-specifier is ill-formed. |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6127 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 6128 | if (const TemplateSpecializationType *TST = |
| 6129 | NamedT->getAs<TemplateSpecializationType>()) { |
| 6130 | TemplateName Template = TST->getTemplateName(); |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 6131 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 6132 | Template.getAsTemplateDecl())) { |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6133 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| Reid Kleckner | f33bfcb0 | 2016-10-03 18:34:23 +0000 | [diff] [blame] | 6134 | diag::err_tag_reference_non_tag) |
| Reid Kleckner | 1a4ab7e | 2016-12-09 19:47:58 +0000 | [diff] [blame] | 6135 | << TAT << Sema::NTK_TypeAliasTemplate |
| 6136 | << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); |
| Richard Smith | 0c4a34b | 2011-05-14 15:04:18 +0000 | [diff] [blame] | 6137 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 6138 | } |
| Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6142 | QualType Result = TL.getType(); |
| 6143 | if (getDerived().AlwaysRebuild() || |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6144 | QualifierLoc != TL.getQualifierLoc() || |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6145 | NamedT != T->getNamedType()) { |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6146 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6147 | T->getKeyword(), |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6148 | QualifierLoc, NamedT); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6149 | if (Result.isNull()) |
| 6150 | return QualType(); |
| 6151 | } |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6152 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 6153 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6154 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6155 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6156 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6157 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6158 | |
| 6159 | template<typename Derived> |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6160 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 6161 | TypeLocBuilder &TLB, |
| 6162 | AttributedTypeLoc TL) { |
| 6163 | const AttributedType *oldType = TL.getTypePtr(); |
| 6164 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 6165 | if (modifiedType.isNull()) |
| 6166 | return QualType(); |
| 6167 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6168 | // oldAttr can be null if we started with a QualType rather than a TypeLoc. |
| 6169 | const Attr *oldAttr = TL.getAttr(); |
| 6170 | const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; |
| 6171 | if (oldAttr && !newAttr) |
| 6172 | return QualType(); |
| 6173 | |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6174 | QualType result = TL.getType(); |
| 6175 | |
| 6176 | // FIXME: dependent operand expressions? |
| 6177 | if (getDerived().AlwaysRebuild() || |
| 6178 | modifiedType != oldType->getModifiedType()) { |
| 6179 | // TODO: this is really lame; we should really be rebuilding the |
| 6180 | // equivalent type from first principles. |
| 6181 | QualType equivalentType |
| 6182 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 6183 | if (equivalentType.isNull()) |
| 6184 | return QualType(); |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6185 | |
| 6186 | // Check whether we can add nullability; it is only represented as |
| 6187 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 6188 | if (auto nullability = oldType->getImmediateNullability()) { |
| 6189 | if (!modifiedType->canHaveNullability()) { |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6190 | SemaRef.Diag(TL.getAttr()->getLocation(), |
| 6191 | diag::err_nullability_nonpointer) |
| 6192 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
| Douglas Gregor | 261a89b | 2015-06-19 17:51:05 +0000 | [diff] [blame] | 6193 | return QualType(); |
| 6194 | } |
| 6195 | } |
| 6196 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6197 | result = SemaRef.Context.getAttributedType(TL.getAttrKind(), |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6198 | modifiedType, |
| 6199 | equivalentType); |
| 6200 | } |
| 6201 | |
| 6202 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6203 | newTL.setAttr(newAttr); |
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 6204 | return result; |
| 6205 | } |
| 6206 | |
| 6207 | template<typename Derived> |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 6208 | QualType |
| 6209 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 6210 | ParenTypeLoc TL) { |
| 6211 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6212 | if (Inner.isNull()) |
| 6213 | return QualType(); |
| 6214 | |
| 6215 | QualType Result = TL.getType(); |
| 6216 | if (getDerived().AlwaysRebuild() || |
| 6217 | Inner != TL.getInnerLoc().getType()) { |
| 6218 | Result = getDerived().RebuildParenType(Inner); |
| 6219 | if (Result.isNull()) |
| 6220 | return QualType(); |
| 6221 | } |
| 6222 | |
| 6223 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 6224 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6225 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6226 | return Result; |
| 6227 | } |
| 6228 | |
| Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 6229 | template <typename Derived> |
| 6230 | QualType |
| 6231 | TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, |
| 6232 | MacroQualifiedTypeLoc TL) { |
| 6233 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6234 | if (Inner.isNull()) |
| 6235 | return QualType(); |
| 6236 | |
| 6237 | QualType Result = TL.getType(); |
| 6238 | if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { |
| 6239 | Result = |
| 6240 | getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); |
| 6241 | if (Result.isNull()) |
| 6242 | return QualType(); |
| 6243 | } |
| 6244 | |
| 6245 | MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); |
| 6246 | NewTL.setExpansionLoc(TL.getExpansionLoc()); |
| 6247 | return Result; |
| 6248 | } |
| 6249 | |
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 6250 | template<typename Derived> |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6251 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6252 | TypeLocBuilder &TLB, DependentNameTypeLoc TL) { |
| 6253 | return TransformDependentNameType(TLB, TL, false); |
| 6254 | } |
| 6255 | |
| 6256 | template<typename Derived> |
| 6257 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6258 | TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6259 | const DependentNameType *T = TL.getTypePtr(); |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 6260 | |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6261 | NestedNameSpecifierLoc QualifierLoc |
| 6262 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6263 | if (!QualifierLoc) |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6264 | return QualType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6265 | |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6266 | QualType Result |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6267 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6268 | TL.getElaboratedKeywordLoc(), |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6269 | QualifierLoc, |
| 6270 | T->getIdentifier(), |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 6271 | TL.getNameLoc(), |
| 6272 | DeducedTSTContext); |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6273 | if (Result.isNull()) |
| 6274 | return QualType(); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6275 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6276 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 6277 | QualType NamedT = ElabT->getNamedType(); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6278 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 6279 | |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6280 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6281 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 6282 | NewTL.setQualifierLoc(QualifierLoc); |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6283 | } else { |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6284 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6285 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 6286 | NewTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | d754848 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 6287 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6288 | } |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6289 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6290 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6291 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6292 | template<typename Derived> |
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 6293 | QualType TreeTransform<Derived>:: |
| 6294 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6295 | DependentTemplateSpecializationTypeLoc TL) { |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6296 | NestedNameSpecifierLoc QualifierLoc; |
| 6297 | if (TL.getQualifierLoc()) { |
| 6298 | QualifierLoc |
| 6299 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6300 | if (!QualifierLoc) |
| Douglas Gregor | 5a06472 | 2011-02-28 17:23:35 +0000 | [diff] [blame] | 6301 | return QualType(); |
| 6302 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6303 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6304 | return getDerived() |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6305 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | template<typename Derived> |
| 6309 | QualType TreeTransform<Derived>:: |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6310 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 6311 | DependentTemplateSpecializationTypeLoc TL, |
| 6312 | NestedNameSpecifierLoc QualifierLoc) { |
| 6313 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6314 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6315 | TemplateArgumentListInfo NewTemplateArgs; |
| 6316 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6317 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6318 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6319 | typedef TemplateArgumentLocContainerIterator< |
| 6320 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 6321 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6322 | ArgIterator(TL, TL.getNumArgs()), |
| 6323 | NewTemplateArgs)) |
| 6324 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6325 | |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6326 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 6327 | T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), |
| 6328 | T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 6329 | /*AllowInjectedClassName*/ false); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6330 | if (Result.isNull()) |
| 6331 | return QualType(); |
| 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 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 6334 | QualType NamedT = ElabT->getNamedType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6335 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6336 | // Copy information relevant to the template specialization. |
| 6337 | TemplateSpecializationTypeLoc NamedTL |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6338 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6339 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6340 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6341 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6342 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6343 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6344 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6345 | |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6346 | // Copy information relevant to the elaborated type. |
| 6347 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| Abramo Bagnara | 9033e2b | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 6348 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6349 | NewTL.setQualifierLoc(QualifierLoc); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6350 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6351 | DependentTemplateSpecializationTypeLoc SpecTL |
| 6352 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6353 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6354 | SpecTL.setQualifierLoc(QualifierLoc); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6355 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6356 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6357 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6358 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6359 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6360 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6361 | } else { |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6362 | TemplateSpecializationTypeLoc SpecTL |
| 6363 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| Abramo Bagnara | e0a70b2 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 6364 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| Abramo Bagnara | 48c05be | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 6365 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6366 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6367 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| Douglas Gregor | 11ddf13 | 2011-03-07 15:13:34 +0000 | [diff] [blame] | 6368 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| Douglas Gregor | 43f788f | 2011-03-07 02:33:33 +0000 | [diff] [blame] | 6369 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 6370 | } |
| 6371 | return Result; |
| 6372 | } |
| 6373 | |
| 6374 | template<typename Derived> |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6375 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 6376 | PackExpansionTypeLoc TL) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6377 | QualType Pattern |
| 6378 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6379 | if (Pattern.isNull()) |
| 6380 | return QualType(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6381 | |
| 6382 | QualType Result = TL.getType(); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6383 | if (getDerived().AlwaysRebuild() || |
| 6384 | Pattern != TL.getPatternLoc().getType()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6385 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6386 | TL.getPatternLoc().getSourceRange(), |
| Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 6387 | TL.getEllipsisLoc(), |
| 6388 | TL.getTypePtr()->getNumExpansions()); |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6389 | if (Result.isNull()) |
| 6390 | return QualType(); |
| 6391 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6392 | |
| Douglas Gregor | 822d030 | 2011-01-12 17:07:58 +0000 | [diff] [blame] | 6393 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 6394 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 6395 | return Result; |
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6399 | QualType |
| 6400 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6401 | ObjCInterfaceTypeLoc TL) { |
| Douglas Gregor | 21515a9 | 2010-04-22 17:28:13 +0000 | [diff] [blame] | 6402 | // ObjCInterfaceType is never dependent. |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6403 | TLB.pushFullCopy(TL); |
| 6404 | return TL.getType(); |
| 6405 | } |
| 6406 | |
| 6407 | template<typename Derived> |
| 6408 | QualType |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6409 | TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, |
| 6410 | ObjCTypeParamTypeLoc TL) { |
| 6411 | const ObjCTypeParamType *T = TL.getTypePtr(); |
| 6412 | ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( |
| 6413 | getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); |
| 6414 | if (!OTP) |
| 6415 | return QualType(); |
| 6416 | |
| 6417 | QualType Result = TL.getType(); |
| 6418 | if (getDerived().AlwaysRebuild() || |
| 6419 | OTP != T->getDecl()) { |
| 6420 | Result = getDerived().RebuildObjCTypeParamType(OTP, |
| 6421 | TL.getProtocolLAngleLoc(), |
| 6422 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 6423 | TL.getNumProtocols()), |
| 6424 | TL.getProtocolLocs(), |
| 6425 | TL.getProtocolRAngleLoc()); |
| 6426 | if (Result.isNull()) |
| 6427 | return QualType(); |
| 6428 | } |
| 6429 | |
| 6430 | ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); |
| 6431 | if (TL.getNumProtocols()) { |
| 6432 | NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6433 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6434 | NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6435 | NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6436 | } |
| 6437 | return Result; |
| 6438 | } |
| 6439 | |
| 6440 | template<typename Derived> |
| 6441 | QualType |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 6442 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6443 | ObjCObjectTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6444 | // Transform base type. |
| 6445 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 6446 | if (BaseType.isNull()) |
| 6447 | return QualType(); |
| 6448 | |
| 6449 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 6450 | |
| 6451 | // Transform type arguments. |
| 6452 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 6453 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 6454 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 6455 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 6456 | QualType TypeArg = TypeArgInfo->getType(); |
| 6457 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 6458 | AnyChanged = true; |
| 6459 | |
| 6460 | // We have a pack expansion. Instantiate it. |
| 6461 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 6462 | ->castAs<PackExpansionType>(); |
| 6463 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6464 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 6465 | Unexpanded); |
| 6466 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 6467 | |
| 6468 | // Determine whether the set of unexpanded parameter packs can |
| 6469 | // and should be expanded. |
| 6470 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 6471 | bool Expand = false; |
| 6472 | bool RetainExpansion = false; |
| 6473 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 6474 | if (getDerived().TryExpandParameterPacks( |
| 6475 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 6476 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 6477 | return QualType(); |
| 6478 | |
| 6479 | if (!Expand) { |
| 6480 | // We can't expand this pack expansion into separate arguments yet; |
| 6481 | // just substitute into the pattern and create a new pack expansion |
| 6482 | // type. |
| 6483 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 6484 | |
| 6485 | TypeLocBuilder TypeArgBuilder; |
| 6486 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6487 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6488 | PatternLoc); |
| 6489 | if (NewPatternType.isNull()) |
| 6490 | return QualType(); |
| 6491 | |
| 6492 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 6493 | NewPatternType, NumExpansions); |
| 6494 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 6495 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 6496 | NewTypeArgInfos.push_back( |
| 6497 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 6498 | continue; |
| 6499 | } |
| 6500 | |
| 6501 | // Substitute into the pack expansion pattern for each slice of the |
| 6502 | // pack. |
| 6503 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 6504 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 6505 | |
| 6506 | TypeLocBuilder TypeArgBuilder; |
| 6507 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 6508 | |
| 6509 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 6510 | PatternLoc); |
| 6511 | if (NewTypeArg.isNull()) |
| 6512 | return QualType(); |
| 6513 | |
| 6514 | NewTypeArgInfos.push_back( |
| 6515 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6516 | } |
| 6517 | |
| 6518 | continue; |
| 6519 | } |
| 6520 | |
| 6521 | TypeLocBuilder TypeArgBuilder; |
| 6522 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 6523 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 6524 | if (NewTypeArg.isNull()) |
| 6525 | return QualType(); |
| 6526 | |
| 6527 | // If nothing changed, just keep the old TypeSourceInfo. |
| 6528 | if (NewTypeArg == TypeArg) { |
| 6529 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 6530 | continue; |
| 6531 | } |
| 6532 | |
| 6533 | NewTypeArgInfos.push_back( |
| 6534 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 6535 | AnyChanged = true; |
| 6536 | } |
| 6537 | |
| 6538 | QualType Result = TL.getType(); |
| 6539 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 6540 | // Rebuild the type. |
| 6541 | Result = getDerived().RebuildObjCObjectType( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6542 | BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, |
| 6543 | TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), |
| 6544 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 6545 | TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6546 | |
| 6547 | if (Result.isNull()) |
| 6548 | return QualType(); |
| 6549 | } |
| 6550 | |
| 6551 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6552 | NewT.setHasBaseTypeAsWritten(true); |
| 6553 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 6554 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 6555 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 6556 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 6557 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6558 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6559 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6560 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6561 | return Result; |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6562 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6563 | |
| 6564 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 6565 | QualType |
| 6566 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 6567 | ObjCObjectPointerTypeLoc TL) { |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 6568 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 6569 | if (PointeeType.isNull()) |
| 6570 | return QualType(); |
| 6571 | |
| 6572 | QualType Result = TL.getType(); |
| 6573 | if (getDerived().AlwaysRebuild() || |
| 6574 | PointeeType != TL.getPointeeLoc().getType()) { |
| 6575 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 6576 | TL.getStarLoc()); |
| 6577 | if (Result.isNull()) |
| 6578 | return QualType(); |
| 6579 | } |
| 6580 | |
| 6581 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 6582 | NewT.setStarLoc(TL.getStarLoc()); |
| 6583 | return Result; |
| Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 6586 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6587 | // Statement transformation |
| 6588 | //===----------------------------------------------------------------------===// |
| 6589 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6590 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6591 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6592 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6596 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6597 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 6598 | return getDerived().TransformCompoundStmt(S, false); |
| 6599 | } |
| 6600 | |
| 6601 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6602 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6603 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6604 | bool IsStmtExpr) { |
| Dmitri Gribenko | 800ddf3 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 6605 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 6606 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6607 | bool SubStmtInvalid = false; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6608 | bool SubStmtChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 6609 | SmallVector<Stmt*, 8> Statements; |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6610 | for (auto *B : S->body()) { |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6611 | StmtResult Result = getDerived().TransformStmt( |
| 6612 | B, |
| 6613 | IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 6614 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6615 | if (Result.isInvalid()) { |
| 6616 | // Immediately fail if this was a DeclStmt, since it's very |
| 6617 | // likely that this will cause problems for future statements. |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6618 | if (isa<DeclStmt>(B)) |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6619 | return StmtError(); |
| 6620 | |
| 6621 | // Otherwise, just keep processing substatements and fail later. |
| 6622 | SubStmtInvalid = true; |
| 6623 | continue; |
| 6624 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6625 | |
| Aaron Ballman | c7e4e21 | 2014-03-17 14:19:37 +0000 | [diff] [blame] | 6626 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6627 | Statements.push_back(Result.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6628 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6629 | |
| John McCall | 1ababa6 | 2010-08-27 19:56:05 +0000 | [diff] [blame] | 6630 | if (SubStmtInvalid) |
| 6631 | return StmtError(); |
| 6632 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6633 | if (!getDerived().AlwaysRebuild() && |
| 6634 | !SubStmtChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6635 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6636 | |
| 6637 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 6638 | Statements, |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6639 | S->getRBracLoc(), |
| 6640 | IsStmtExpr); |
| 6641 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6642 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6643 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6644 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6645 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6646 | ExprResult LHS, RHS; |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6647 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 6648 | EnterExpressionEvaluationContext Unevaluated( |
| 6649 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6650 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6651 | // Transform the left-hand case value. |
| 6652 | LHS = getDerived().TransformExpr(S->getLHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6653 | LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6654 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6655 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6656 | |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6657 | // Transform the right-hand case value (for the GNU case-range extension). |
| 6658 | RHS = getDerived().TransformExpr(S->getRHS()); |
| Richard Smith | ef6c43d | 2018-07-26 18:41:30 +0000 | [diff] [blame] | 6659 | RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6660 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6661 | return StmtError(); |
| Eli Friedman | 0657738 | 2009-11-19 03:14:00 +0000 | [diff] [blame] | 6662 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6663 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6664 | // Build the case statement. |
| 6665 | // Case statements are always rebuilt so that they will attached to their |
| 6666 | // transformed switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6667 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6668 | LHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6669 | S->getEllipsisLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6670 | RHS.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6671 | S->getColonLoc()); |
| 6672 | if (Case.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 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6675 | // Transform the statement following the case |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6676 | StmtResult SubStmt = |
| 6677 | getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6678 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6679 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6680 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6681 | // Attach the body to the case statement |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6682 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6685 | template <typename Derived> |
| 6686 | StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6687 | // Transform the statement following the default case |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6688 | StmtResult SubStmt = |
| 6689 | getDerived().TransformStmt(S->getSubStmt()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6690 | if (SubStmt.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 | // Default statements are always rebuilt |
| 6694 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6695 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6696 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6697 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6698 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6699 | StmtResult |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6700 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { |
| 6701 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6702 | if (SubStmt.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6703 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6704 | |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6705 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 6706 | S->getDecl()); |
| 6707 | if (!LD) |
| 6708 | return StmtError(); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6709 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6710 | // If we're transforming "in-place" (we're not creating new local |
| 6711 | // declarations), assume we're replacing the old label statement |
| 6712 | // and clear out the reference to it. |
| 6713 | if (LD == S->getDecl()) |
| 6714 | S->getDecl()->setStmt(nullptr); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6715 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6716 | // FIXME: Pass the real colon location in. |
| Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 6717 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6718 | cast<LabelDecl>(LD), SourceLocation(), |
| 6719 | SubStmt.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6720 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6721 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6722 | template <typename Derived> |
| 6723 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 6724 | if (!R) |
| 6725 | return R; |
| 6726 | |
| 6727 | switch (R->getKind()) { |
| 6728 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 6729 | #define ATTR(X) |
| 6730 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 6731 | case attr::X: \ |
| 6732 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 6733 | #include "clang/Basic/AttrList.inc" |
| 6734 | default: |
| 6735 | return R; |
| 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | template <typename Derived> |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6740 | StmtResult |
| 6741 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, |
| 6742 | StmtDiscardKind SDK) { |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6743 | bool AttrsChanged = false; |
| 6744 | SmallVector<const Attr *, 1> Attrs; |
| 6745 | |
| 6746 | // Visit attributes and keep track if any are transformed. |
| 6747 | for (const auto *I : S->getAttrs()) { |
| 6748 | const Attr *R = getDerived().TransformAttr(I); |
| 6749 | AttrsChanged |= (I != R); |
| 6750 | Attrs.push_back(R); |
| 6751 | } |
| 6752 | |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 6753 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6754 | if (SubStmt.isInvalid()) |
| 6755 | return StmtError(); |
| 6756 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6757 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6758 | return S; |
| 6759 | |
| Tyler Nowicki | c724a83e | 2014-10-12 20:46:07 +0000 | [diff] [blame] | 6760 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 6761 | SubStmt.get()); |
| 6762 | } |
| 6763 | |
| 6764 | template<typename Derived> |
| 6765 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6766 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6767 | // Transform the initialization statement |
| 6768 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6769 | if (Init.isInvalid()) |
| 6770 | return StmtError(); |
| 6771 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6772 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6773 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6774 | S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6775 | S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 6776 | : Sema::ConditionKind::Boolean); |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6777 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6778 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6779 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6780 | // If this is a constexpr if, determine which arm we should instantiate. |
| 6781 | llvm::Optional<bool> ConstexprConditionValue; |
| 6782 | if (S->isConstexpr()) |
| 6783 | ConstexprConditionValue = Cond.getKnownValue(); |
| 6784 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6785 | // Transform the "then" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6786 | StmtResult Then; |
| 6787 | if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 6788 | Then = getDerived().TransformStmt(S->getThen()); |
| 6789 | if (Then.isInvalid()) |
| 6790 | return StmtError(); |
| 6791 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6792 | Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6793 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6794 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6795 | // Transform the "else" branch. |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6796 | StmtResult Else; |
| 6797 | if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 6798 | Else = getDerived().TransformStmt(S->getElse()); |
| 6799 | if (Else.isInvalid()) |
| 6800 | return StmtError(); |
| 6801 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6802 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6803 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6804 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6805 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6806 | Then.get() == S->getThen() && |
| 6807 | Else.get() == S->getElse()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6808 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6809 | |
| Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 6810 | return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond, |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6811 | Init.get(), Then.get(), S->getElseLoc(), |
| 6812 | Else.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6816 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6817 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
| Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 6818 | // Transform the initialization statement |
| 6819 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 6820 | if (Init.isInvalid()) |
| 6821 | return StmtError(); |
| 6822 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6823 | // Transform the condition. |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6824 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6825 | S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 6826 | Sema::ConditionKind::Switch); |
| 6827 | if (Cond.isInvalid()) |
| 6828 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6829 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6830 | // Rebuild the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6831 | StmtResult Switch |
| Volodymyr Sapsai | ddf524c | 2017-09-21 17:58:27 +0000 | [diff] [blame] | 6832 | = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6833 | if (Switch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6834 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6835 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6836 | // Transform the body of the switch statement. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6837 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6838 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6839 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6840 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6841 | // Complete the switch statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6842 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 6843 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6844 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6845 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6846 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6847 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6848 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6849 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6850 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6851 | S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 6852 | Sema::ConditionKind::Boolean); |
| 6853 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6854 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6855 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6856 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6857 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6858 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6859 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6860 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6861 | if (!getDerived().AlwaysRebuild() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6862 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6863 | Body.get() == S->getBody()) |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6864 | return Owned(S); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6865 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6866 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6867 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6868 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6869 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6870 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6871 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6872 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6873 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6874 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6875 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6876 | |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6877 | // Transform the condition |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6878 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6879 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6880 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6881 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6882 | if (!getDerived().AlwaysRebuild() && |
| 6883 | Cond.get() == S->getCond() && |
| 6884 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6885 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6886 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6887 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 6888 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6889 | S->getRParenLoc()); |
| 6890 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6891 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6892 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6893 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6894 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 6895 | if (getSema().getLangOpts().OpenMP) |
| 6896 | getSema().startOpenMPLoop(); |
| 6897 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6898 | // Transform the initialization statement |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6899 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6900 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6901 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6902 | |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6903 | // In OpenMP loop region loop control variable must be captured and be |
| 6904 | // private. Perform analysis of first part (if any). |
| 6905 | if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 6906 | getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); |
| 6907 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6908 | // Transform the condition |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6909 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 6910 | S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 6911 | Sema::ConditionKind::Boolean); |
| 6912 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6913 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6914 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6915 | // Transform the increment |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6916 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6917 | if (Inc.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6918 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6919 | |
| Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 6920 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6921 | if (S->getInc() && !FullInc.get()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6922 | return StmtError(); |
| Douglas Gregor | ff73a9e | 2010-05-08 22:20:28 +0000 | [diff] [blame] | 6923 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6924 | // Transform the body |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6925 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6926 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6927 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6928 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6929 | if (!getDerived().AlwaysRebuild() && |
| 6930 | Init.get() == S->getInit() && |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6931 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6932 | Inc.get() == S->getInc() && |
| 6933 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6934 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6935 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6936 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6937 | Init.get(), Cond, FullInc, |
| 6938 | S->getRParenLoc(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6939 | } |
| 6940 | |
| 6941 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6942 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6943 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6944 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 6945 | S->getLabel()); |
| 6946 | if (!LD) |
| 6947 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 6948 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6949 | // Goto statements must always be rebuilt, to resolve the label. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6950 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 6951 | cast<LabelDecl>(LD)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6955 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6956 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6957 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6958 | if (Target.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6959 | return StmtError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6960 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6961 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6962 | if (!getDerived().AlwaysRebuild() && |
| 6963 | Target.get() == S->getTarget()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6964 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6965 | |
| 6966 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6967 | Target.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6971 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6972 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6973 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6974 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6975 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6976 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6977 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6978 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6979 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6980 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6981 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6982 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6983 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6984 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
| Richard Smith | 3b71752 | 2014-08-21 20:51:13 +0000 | [diff] [blame] | 6985 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 6986 | /*NotCopyInit*/false); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6987 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 6988 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6989 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6990 | // FIXME: We always rebuild the return statement because there is no way |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6991 | // to tell whether the return type of the function has changed. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 6992 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6993 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6994 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6995 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 6996 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6997 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 6998 | bool DeclChanged = false; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 6999 | SmallVector<Decl *, 4> Decls; |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 7000 | for (auto *D : S->decls()) { |
| 7001 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7002 | if (!Transformed) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7003 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7004 | |
| Aaron Ballman | 535bbcc | 2014-03-14 17:01:24 +0000 | [diff] [blame] | 7005 | if (Transformed != D) |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7006 | DeclChanged = true; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7007 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7008 | Decls.push_back(Transformed); |
| 7009 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7010 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7011 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7012 | return S; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7013 | |
| Stephen Kelly | a6e4358 | 2018-08-09 21:05:56 +0000 | [diff] [blame] | 7014 | return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7015 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7016 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7017 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7018 | StmtResult |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 7019 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7020 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7021 | SmallVector<Expr*, 8> Constraints; |
| 7022 | SmallVector<Expr*, 8> Exprs; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 7023 | SmallVector<IdentifierInfo *, 4> Names; |
| Anders Carlsson | 087bc13 | 2010-01-30 20:05:21 +0000 | [diff] [blame] | 7024 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7025 | ExprResult AsmString; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7026 | SmallVector<Expr*, 8> Clobbers; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7027 | |
| 7028 | bool ExprsChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7029 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7030 | // Go through the outputs. |
| 7031 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 7032 | Names.push_back(S->getOutputIdentifier(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7033 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7034 | // No need to transform the constraint literal. |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 7035 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7036 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7037 | // Transform the output expr. |
| 7038 | Expr *OutputExpr = S->getOutputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7039 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7040 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7041 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7042 | |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7043 | ExprsChanged |= Result.get() != OutputExpr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7044 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7045 | Exprs.push_back(Result.get()); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7046 | } |
| 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 inputs. |
| 7049 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| Anders Carlsson | 9a020f9 | 2010-01-30 22:25:16 +0000 | [diff] [blame] | 7050 | Names.push_back(S->getInputIdentifier(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->getInputConstraintLiteral(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 input expr. |
| 7056 | Expr *InputExpr = S->getInputExpr(I); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7057 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
| 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() != InputExpr; |
| 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 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 7066 | // Go through the Labels. |
| 7067 | for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { |
| 7068 | Names.push_back(S->getLabelIdentifier(I)); |
| 7069 | |
| 7070 | ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); |
| 7071 | if (Result.isInvalid()) |
| 7072 | return StmtError(); |
| 7073 | ExprsChanged |= Result.get() != S->getLabelExpr(I); |
| 7074 | Exprs.push_back(Result.get()); |
| 7075 | } |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7076 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7077 | return S; |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7078 | |
| 7079 | // Go through the clobbers. |
| 7080 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| Chad Rosier | d9fb09a | 2012-08-27 23:28:41 +0000 | [diff] [blame] | 7081 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
| Anders Carlsson | aaeef07 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 7082 | |
| 7083 | // No need to transform the asm string literal. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7084 | AsmString = S->getAsmString(); |
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 7085 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 7086 | S->isVolatile(), S->getNumOutputs(), |
| 7087 | S->getNumInputs(), Names.data(), |
| 7088 | Constraints, Exprs, AsmString.get(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 7089 | Clobbers, S->getNumLabels(), |
| 7090 | S->getRParenLoc()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 7093 | template<typename Derived> |
| 7094 | StmtResult |
| 7095 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 7096 | ArrayRef<Token> AsmToks = |
| 7097 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
| Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 7098 | |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7099 | bool HadError = false, HadChange = false; |
| 7100 | |
| 7101 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 7102 | SmallVector<Expr*, 8> TransformedExprs; |
| 7103 | TransformedExprs.reserve(SrcExprs.size()); |
| 7104 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 7105 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 7106 | if (!Result.isUsable()) { |
| 7107 | HadError = true; |
| 7108 | } else { |
| 7109 | HadChange |= (Result.get() != SrcExprs[i]); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7110 | TransformedExprs.push_back(Result.get()); |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7111 | } |
| 7112 | } |
| 7113 | |
| 7114 | if (HadError) return StmtError(); |
| 7115 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 7116 | return Owned(S); |
| 7117 | |
| Chad Rosier | b6f46c1 | 2012-08-15 16:53:30 +0000 | [diff] [blame] | 7118 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 7119 | AsmToks, S->getAsmString(), |
| 7120 | S->getNumOutputs(), S->getNumInputs(), |
| 7121 | S->getAllConstraints(), S->getClobbers(), |
| 7122 | TransformedExprs, S->getEndLoc()); |
| Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 7123 | } |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7124 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7125 | // C++ Coroutines TS |
| 7126 | |
| 7127 | template<typename Derived> |
| 7128 | StmtResult |
| 7129 | TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7130 | auto *ScopeInfo = SemaRef.getCurFunction(); |
| 7131 | auto *FD = cast<FunctionDecl>(SemaRef.CurContext); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7132 | assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7133 | ScopeInfo->NeedsCoroutineSuspends && |
| 7134 | ScopeInfo->CoroutineSuspends.first == nullptr && |
| 7135 | ScopeInfo->CoroutineSuspends.second == nullptr && |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 7136 | "expected clean scope info"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7137 | |
| 7138 | // Set that we have (possibly-invalid) suspend points before we do anything |
| 7139 | // that may fail. |
| 7140 | ScopeInfo->setNeedsCoroutineSuspends(false); |
| 7141 | |
| 7142 | // The new CoroutinePromise object needs to be built and put into the current |
| 7143 | // FunctionScopeInfo before any transformations or rebuilding occurs. |
| Brian Gesiak | 61f4ac9 | 2018-01-24 22:15:42 +0000 | [diff] [blame] | 7144 | if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) |
| 7145 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7146 | auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); |
| 7147 | if (!Promise) |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7148 | return StmtError(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 7149 | getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7150 | ScopeInfo->CoroutinePromise = Promise; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7151 | |
| 7152 | // Transform the implicit coroutine statements we built during the initial |
| 7153 | // parse. |
| 7154 | StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); |
| 7155 | if (InitSuspend.isInvalid()) |
| 7156 | return StmtError(); |
| 7157 | StmtResult FinalSuspend = |
| 7158 | getDerived().TransformStmt(S->getFinalSuspendStmt()); |
| 7159 | if (FinalSuspend.isInvalid()) |
| 7160 | return StmtError(); |
| 7161 | ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); |
| 7162 | assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7163 | |
| 7164 | StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); |
| 7165 | if (BodyRes.isInvalid()) |
| 7166 | return StmtError(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7167 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7168 | CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); |
| 7169 | if (Builder.isInvalid()) |
| 7170 | return StmtError(); |
| 7171 | |
| 7172 | Expr *ReturnObject = S->getReturnValueInit(); |
| 7173 | assert(ReturnObject && "the return object is expected to be valid"); |
| 7174 | ExprResult Res = getDerived().TransformInitializer(ReturnObject, |
| 7175 | /*NoCopyInit*/ false); |
| 7176 | if (Res.isInvalid()) |
| 7177 | return StmtError(); |
| 7178 | Builder.ReturnValue = Res.get(); |
| 7179 | |
| 7180 | if (S->hasDependentPromiseType()) { |
| Brian Gesiak | 38f1182 | 2019-06-03 00:47:32 +0000 | [diff] [blame] | 7181 | // PR41909: We may find a generic coroutine lambda definition within a |
| 7182 | // template function that is being instantiated. In this case, the lambda |
| 7183 | // will have a dependent promise type, until it is used in an expression |
| 7184 | // that creates an instantiation with a non-dependent promise type. We |
| 7185 | // should not assert or build coroutine dependent statements for such a |
| 7186 | // generic lambda. |
| 7187 | auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD); |
| 7188 | if (!MD || !MD->getParent()->isGenericLambda()) { |
| 7189 | assert(!Promise->getType()->isDependentType() && |
| 7190 | "the promise type must no longer be dependent"); |
| 7191 | assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && |
| 7192 | !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && |
| 7193 | "these nodes should not have been built yet"); |
| 7194 | if (!Builder.buildDependentStatements()) |
| 7195 | return StmtError(); |
| 7196 | } |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7197 | } else { |
| 7198 | if (auto *OnFallthrough = S->getFallthroughHandler()) { |
| 7199 | StmtResult Res = getDerived().TransformStmt(OnFallthrough); |
| 7200 | if (Res.isInvalid()) |
| 7201 | return StmtError(); |
| 7202 | Builder.OnFallthrough = Res.get(); |
| 7203 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7204 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7205 | if (auto *OnException = S->getExceptionHandler()) { |
| 7206 | StmtResult Res = getDerived().TransformStmt(OnException); |
| 7207 | if (Res.isInvalid()) |
| 7208 | return StmtError(); |
| 7209 | Builder.OnException = Res.get(); |
| 7210 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7211 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7212 | if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { |
| 7213 | StmtResult Res = getDerived().TransformStmt(OnAllocFailure); |
| 7214 | if (Res.isInvalid()) |
| 7215 | return StmtError(); |
| 7216 | Builder.ReturnStmtOnAllocFailure = Res.get(); |
| 7217 | } |
| 7218 | |
| 7219 | // Transform any additional statements we may have already built |
| 7220 | assert(S->getAllocate() && S->getDeallocate() && |
| 7221 | "allocation and deallocation calls must already be built"); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7222 | ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); |
| 7223 | if (AllocRes.isInvalid()) |
| 7224 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7225 | Builder.Allocate = AllocRes.get(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7226 | |
| 7227 | ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); |
| 7228 | if (DeallocRes.isInvalid()) |
| 7229 | return StmtError(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7230 | Builder.Deallocate = DeallocRes.get(); |
| Gor Nishanov | afff89e | 2017-05-24 15:44:57 +0000 | [diff] [blame] | 7231 | |
| 7232 | assert(S->getResultDecl() && "ResultDecl must already be built"); |
| 7233 | StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl()); |
| 7234 | if (ResultDecl.isInvalid()) |
| 7235 | return StmtError(); |
| 7236 | Builder.ResultDecl = ResultDecl.get(); |
| 7237 | |
| 7238 | if (auto *ReturnStmt = S->getReturnStmt()) { |
| 7239 | StmtResult Res = getDerived().TransformStmt(ReturnStmt); |
| 7240 | if (Res.isInvalid()) |
| 7241 | return StmtError(); |
| 7242 | Builder.ReturnStmt = Res.get(); |
| 7243 | } |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7244 | } |
| 7245 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 7246 | return getDerived().RebuildCoroutineBodyStmt(Builder); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7247 | } |
| 7248 | |
| 7249 | template<typename Derived> |
| 7250 | StmtResult |
| 7251 | TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 7252 | ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 7253 | /*NotCopyInit*/false); |
| 7254 | if (Result.isInvalid()) |
| 7255 | return StmtError(); |
| 7256 | |
| 7257 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7258 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7259 | return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), |
| 7260 | S->isImplicit()); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | template<typename Derived> |
| 7264 | ExprResult |
| 7265 | TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 7266 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7267 | /*NotCopyInit*/false); |
| 7268 | if (Result.isInvalid()) |
| 7269 | return ExprError(); |
| 7270 | |
| 7271 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7272 | // context or if the promise type has changed. |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 7273 | return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(), |
| 7274 | E->isImplicit()); |
| 7275 | } |
| 7276 | |
| 7277 | template <typename Derived> |
| 7278 | ExprResult |
| 7279 | TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { |
| 7280 | ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), |
| 7281 | /*NotCopyInit*/ false); |
| 7282 | if (OperandResult.isInvalid()) |
| 7283 | return ExprError(); |
| 7284 | |
| 7285 | ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( |
| 7286 | E->getOperatorCoawaitLookup()); |
| 7287 | |
| 7288 | if (LookupResult.isInvalid()) |
| 7289 | return ExprError(); |
| 7290 | |
| 7291 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7292 | // context or if the promise type has changed. |
| 7293 | return getDerived().RebuildDependentCoawaitExpr( |
| 7294 | E->getKeywordLoc(), OperandResult.get(), |
| 7295 | cast<UnresolvedLookupExpr>(LookupResult.get())); |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 7296 | } |
| 7297 | |
| 7298 | template<typename Derived> |
| 7299 | ExprResult |
| 7300 | TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 7301 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7302 | /*NotCopyInit*/false); |
| 7303 | if (Result.isInvalid()) |
| 7304 | return ExprError(); |
| 7305 | |
| 7306 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7307 | // context or if the promise type has changed. |
| 7308 | return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 7309 | } |
| 7310 | |
| 7311 | // Objective-C Statements. |
| 7312 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7313 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7314 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7315 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7316 | // Transform the body of the @try. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7317 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7318 | if (TryBody.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7319 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7320 | |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7321 | // Transform the @catch statements (if present). |
| 7322 | bool AnyCatchChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 7323 | SmallVector<Stmt*, 8> CatchStmts; |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7324 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7325 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7326 | if (Catch.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7327 | return StmtError(); |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7328 | if (Catch.get() != S->getCatchStmt(I)) |
| 7329 | AnyCatchChanged = true; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7330 | CatchStmts.push_back(Catch.get()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7331 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7332 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7333 | // Transform the @finally statement (if present). |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7334 | StmtResult Finally; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7335 | if (S->getFinallyStmt()) { |
| 7336 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 7337 | if (Finally.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7338 | return StmtError(); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | // If nothing changed, just retain this statement. |
| 7342 | if (!getDerived().AlwaysRebuild() && |
| 7343 | TryBody.get() == S->getTryBody() && |
| Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 7344 | !AnyCatchChanged && |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7345 | Finally.get() == S->getFinallyStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7346 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7347 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7348 | // Build a new statement. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7349 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7350 | CatchStmts, Finally.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7351 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7352 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7353 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7354 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7355 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7356 | // Transform the @catch parameter, if there is one. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7357 | VarDecl *Var = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7358 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7359 | TypeSourceInfo *TSInfo = nullptr; |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7360 | if (FromVar->getTypeSourceInfo()) { |
| 7361 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 7362 | if (!TSInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7363 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7364 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7365 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7366 | QualType T; |
| 7367 | if (TSInfo) |
| 7368 | T = TSInfo->getType(); |
| 7369 | else { |
| 7370 | T = getDerived().TransformType(FromVar->getType()); |
| 7371 | if (T.isNull()) |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7372 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7373 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7374 | |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7375 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 7376 | if (!Var) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7377 | return StmtError(); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7378 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7379 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7380 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7381 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7382 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7383 | |
| 7384 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| Douglas Gregor | f4e837f | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 7385 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7386 | Var, Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7387 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7388 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7389 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7390 | StmtResult |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7391 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7392 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7393 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7394 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7395 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7396 | |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7397 | // If nothing changed, just retain this statement. |
| 7398 | if (!getDerived().AlwaysRebuild() && |
| 7399 | Body.get() == S->getFinallyBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7400 | return S; |
| Douglas Gregor | 306de2f | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 7401 | |
| 7402 | // Build a new statement. |
| 7403 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7404 | 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>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7410 | ExprResult Operand; |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7411 | if (S->getThrowExpr()) { |
| 7412 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 7413 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7414 | return StmtError(); |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7415 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7416 | |
| Douglas Gregor | 2900c16 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 7417 | if (!getDerived().AlwaysRebuild() && |
| 7418 | Operand.get() == S->getThrowExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7419 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7420 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7421 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7422 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7423 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7424 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7425 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7426 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7427 | ObjCAtSynchronizedStmt *S) { |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7428 | // Transform the object we are locking. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7429 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7430 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7431 | return StmtError(); |
| John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 7432 | Object = |
| 7433 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 7434 | Object.get()); |
| 7435 | if (Object.isInvalid()) |
| 7436 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7437 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7438 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7439 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7440 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7441 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7442 | |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7443 | // If nothing change, just retain the current statement. |
| 7444 | if (!getDerived().AlwaysRebuild() && |
| 7445 | Object.get() == S->getSynchExpr() && |
| 7446 | Body.get() == S->getSynchBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7447 | return S; |
| Douglas Gregor | 6148de7 | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 7448 | |
| 7449 | // Build a new statement. |
| 7450 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7451 | Object.get(), Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
| 7454 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7455 | StmtResult |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7456 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 7457 | ObjCAutoreleasePoolStmt *S) { |
| 7458 | // Transform the body. |
| 7459 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 7460 | if (Body.isInvalid()) |
| 7461 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7462 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7463 | // If nothing changed, just retain this statement. |
| 7464 | if (!getDerived().AlwaysRebuild() && |
| 7465 | Body.get() == S->getSubStmt()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7466 | return S; |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7467 | |
| 7468 | // Build a new statement. |
| 7469 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 7470 | S->getAtLoc(), Body.get()); |
| 7471 | } |
| 7472 | |
| 7473 | template<typename Derived> |
| 7474 | StmtResult |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7475 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7476 | ObjCForCollectionStmt *S) { |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7477 | // Transform the element statement. |
| Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 7478 | StmtResult Element = |
| 7479 | getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7480 | if (Element.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7481 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7482 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7483 | // Transform the collection expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7484 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7485 | if (Collection.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7486 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7487 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7488 | // Transform the body. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7489 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7490 | if (Body.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7491 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7492 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7493 | // If nothing changed, just retain this statement. |
| 7494 | if (!getDerived().AlwaysRebuild() && |
| 7495 | Element.get() == S->getElement() && |
| 7496 | Collection.get() == S->getCollection() && |
| 7497 | Body.get() == S->getBody()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7498 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7499 | |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7500 | // Build a new statement. |
| 7501 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7502 | Element.get(), |
| 7503 | Collection.get(), |
| Douglas Gregor | f68a508 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 7504 | S->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7505 | Body.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7506 | } |
| 7507 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7508 | template <typename Derived> |
| 7509 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7510 | // Transform the exception declaration, if any. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7511 | VarDecl *Var = nullptr; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7512 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 7513 | TypeSourceInfo *T = |
| 7514 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
| Douglas Gregor | 9f0e1aa | 2010-09-09 17:09:21 +0000 | [diff] [blame] | 7515 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7516 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7517 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7518 | Var = getDerived().RebuildExceptionDecl( |
| 7519 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 7520 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7521 | if (!Var || Var->isInvalidDecl()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7522 | return StmtError(); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7523 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7524 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7525 | // Transform the actual exception handler. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 7526 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| Douglas Gregor | b412e17 | 2010-07-25 18:17:45 +0000 | [diff] [blame] | 7527 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7528 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7529 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7530 | if (!getDerived().AlwaysRebuild() && !Var && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7531 | Handler.get() == S->getHandlerBlock()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7532 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7533 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7534 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7535 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7536 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7537 | template <typename Derived> |
| 7538 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7539 | // Transform the try block itself. |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7540 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7541 | if (TryBlock.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7542 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7543 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7544 | // Transform the handlers. |
| 7545 | bool HandlerChanged = false; |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7546 | SmallVector<Stmt *, 8> Handlers; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7547 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7548 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7549 | if (Handler.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 7550 | return StmtError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7551 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7552 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7553 | Handlers.push_back(Handler.getAs<Stmt>()); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7554 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7555 | |
| David Majnemer | 5f7efef | 2013-10-15 09:50:08 +0000 | [diff] [blame] | 7556 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7557 | !HandlerChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7558 | return S; |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7559 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 7560 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 7561 | Handlers); |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 7562 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7563 | |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7564 | template<typename Derived> |
| 7565 | StmtResult |
| 7566 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7567 | StmtResult Init = |
| 7568 | S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); |
| 7569 | if (Init.isInvalid()) |
| 7570 | return StmtError(); |
| 7571 | |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7572 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 7573 | if (Range.isInvalid()) |
| 7574 | return StmtError(); |
| 7575 | |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7576 | StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 7577 | if (Begin.isInvalid()) |
| 7578 | return StmtError(); |
| 7579 | StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 7580 | if (End.isInvalid()) |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7581 | return StmtError(); |
| 7582 | |
| 7583 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 7584 | if (Cond.isInvalid()) |
| 7585 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7586 | if (Cond.get()) |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7587 | Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7588 | if (Cond.isInvalid()) |
| 7589 | return StmtError(); |
| 7590 | if (Cond.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7591 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7592 | |
| 7593 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 7594 | if (Inc.isInvalid()) |
| 7595 | return StmtError(); |
| Eli Friedman | 87d3280 | 2012-01-31 22:45:40 +0000 | [diff] [blame] | 7596 | if (Inc.get()) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7597 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7598 | |
| 7599 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 7600 | if (LoopVar.isInvalid()) |
| 7601 | return StmtError(); |
| 7602 | |
| 7603 | StmtResult NewStmt = S; |
| 7604 | if (getDerived().AlwaysRebuild() || |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7605 | Init.get() != S->getInit() || |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7606 | Range.get() != S->getRangeStmt() || |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7607 | Begin.get() != S->getBeginStmt() || |
| 7608 | End.get() != S->getEndStmt() || |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7609 | Cond.get() != S->getCond() || |
| 7610 | Inc.get() != S->getInc() || |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7611 | LoopVar.get() != S->getLoopVarStmt()) { |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7612 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| Richard Smith | 8baa500 | 2018-09-28 18:44:09 +0000 | [diff] [blame] | 7613 | S->getCoawaitLoc(), Init.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7614 | S->getColonLoc(), Range.get(), |
| Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 7615 | Begin.get(), End.get(), |
| 7616 | Cond.get(), |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7617 | Inc.get(), LoopVar.get(), |
| 7618 | S->getRParenLoc()); |
| Douglas Gregor | 39aaeef | 2013-05-02 18:35:56 +0000 | [diff] [blame] | 7619 | if (NewStmt.isInvalid()) |
| 7620 | return StmtError(); |
| 7621 | } |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7622 | |
| 7623 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7624 | if (Body.isInvalid()) |
| 7625 | return StmtError(); |
| 7626 | |
| 7627 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 7628 | // 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] | 7629 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
| 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 | if (NewStmt.get() == S) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7642 | return S; |
| Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 7643 | |
| 7644 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 7645 | } |
| 7646 | |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7647 | template<typename Derived> |
| 7648 | StmtResult |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7649 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 7650 | MSDependentExistsStmt *S) { |
| 7651 | // Transform the nested-name-specifier, if any. |
| 7652 | NestedNameSpecifierLoc QualifierLoc; |
| 7653 | if (S->getQualifierLoc()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7654 | QualifierLoc |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7655 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 7656 | if (!QualifierLoc) |
| 7657 | return StmtError(); |
| 7658 | } |
| 7659 | |
| 7660 | // Transform the declaration name. |
| 7661 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 7662 | if (NameInfo.getName()) { |
| 7663 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 7664 | if (!NameInfo.getName()) |
| 7665 | return StmtError(); |
| 7666 | } |
| 7667 | |
| 7668 | // Check whether anything changed. |
| 7669 | if (!getDerived().AlwaysRebuild() && |
| 7670 | QualifierLoc == S->getQualifierLoc() && |
| 7671 | NameInfo.getName() == S->getNameInfo().getName()) |
| 7672 | return S; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7673 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7674 | // Determine whether this name exists, if we can. |
| 7675 | CXXScopeSpec SS; |
| 7676 | SS.Adopt(QualifierLoc); |
| 7677 | bool Dependent = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 7678 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7679 | case Sema::IER_Exists: |
| 7680 | if (S->isIfExists()) |
| 7681 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7682 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7683 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 7684 | |
| 7685 | case Sema::IER_DoesNotExist: |
| 7686 | if (S->isIfNotExists()) |
| 7687 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7688 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7689 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7690 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7691 | case Sema::IER_Dependent: |
| 7692 | Dependent = true; |
| 7693 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7694 | |
| Douglas Gregor | 4a2a8f7 | 2011-10-25 03:44:56 +0000 | [diff] [blame] | 7695 | case Sema::IER_Error: |
| 7696 | return StmtError(); |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7697 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7698 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7699 | // We need to continue with the instantiation, so do so now. |
| 7700 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 7701 | if (SubStmt.isInvalid()) |
| 7702 | return StmtError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7703 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7704 | // If we have resolved the name, just transform to the substatement. |
| 7705 | if (!Dependent) |
| 7706 | return SubStmt; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 7707 | |
| Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 7708 | // The name is still dependent, so build a dependent expression again. |
| 7709 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 7710 | S->isIfExists(), |
| 7711 | QualifierLoc, |
| 7712 | NameInfo, |
| 7713 | SubStmt.get()); |
| 7714 | } |
| 7715 | |
| 7716 | template<typename Derived> |
| John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 7717 | ExprResult |
| 7718 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 7719 | NestedNameSpecifierLoc QualifierLoc; |
| 7720 | if (E->getQualifierLoc()) { |
| 7721 | QualifierLoc |
| 7722 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 7723 | if (!QualifierLoc) |
| 7724 | return ExprError(); |
| 7725 | } |
| 7726 | |
| 7727 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 7728 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 7729 | if (!PD) |
| 7730 | return ExprError(); |
| 7731 | |
| 7732 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 7733 | if (Base.isInvalid()) |
| 7734 | return ExprError(); |
| 7735 | |
| 7736 | return new (SemaRef.getASTContext()) |
| 7737 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 7738 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 7739 | QualifierLoc, E->getMemberLoc()); |
| 7740 | } |
| 7741 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7742 | template <typename Derived> |
| Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 7743 | ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 7744 | MSPropertySubscriptExpr *E) { |
| 7745 | auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 7746 | if (BaseRes.isInvalid()) |
| 7747 | return ExprError(); |
| 7748 | auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 7749 | if (IdxRes.isInvalid()) |
| 7750 | return ExprError(); |
| 7751 | |
| 7752 | if (!getDerived().AlwaysRebuild() && |
| 7753 | BaseRes.get() == E->getBase() && |
| 7754 | IdxRes.get() == E->getIdx()) |
| 7755 | return E; |
| 7756 | |
| 7757 | return getDerived().RebuildArraySubscriptExpr( |
| 7758 | BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 7759 | } |
| 7760 | |
| 7761 | template <typename Derived> |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7762 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7763 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7764 | if (TryBlock.isInvalid()) |
| 7765 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7766 | |
| 7767 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7768 | if (Handler.isInvalid()) |
| 7769 | return StmtError(); |
| 7770 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7771 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 7772 | Handler.get() == S->getHandler()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7773 | return S; |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7774 | |
| Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 7775 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 7776 | TryBlock.get(), Handler.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7777 | } |
| 7778 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7779 | template <typename Derived> |
| 7780 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7781 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7782 | if (Block.isInvalid()) |
| 7783 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7784 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7785 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7788 | template <typename Derived> |
| 7789 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7790 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7791 | if (FilterExpr.isInvalid()) |
| 7792 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7793 | |
| David Majnemer | 7e75550 | 2013-10-15 09:30:14 +0000 | [diff] [blame] | 7794 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7795 | if (Block.isInvalid()) |
| 7796 | return StmtError(); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7797 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7798 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 7799 | Block.get()); |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
| David Majnemer | fad8f48 | 2013-10-15 09:33:02 +0000 | [diff] [blame] | 7802 | template <typename Derived> |
| 7803 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 7804 | if (isa<SEHFinallyStmt>(Handler)) |
| John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 7805 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 7806 | else |
| 7807 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 7808 | } |
| 7809 | |
| Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 7810 | template<typename Derived> |
| 7811 | StmtResult |
| 7812 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 7813 | return S; |
| 7814 | } |
| 7815 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7816 | //===----------------------------------------------------------------------===// |
| 7817 | // OpenMP directive transformation |
| 7818 | //===----------------------------------------------------------------------===// |
| 7819 | template <typename Derived> |
| 7820 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 7821 | OMPExecutableDirective *D) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7822 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7823 | // Transform the clauses |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7824 | llvm::SmallVector<OMPClause *, 16> TClauses; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7825 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 7826 | TClauses.reserve(Clauses.size()); |
| 7827 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 7828 | I != E; ++I) { |
| 7829 | if (*I) { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7830 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7831 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 7832 | getDerived().getSema().EndOpenMPClause(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7833 | if (Clause) |
| 7834 | TClauses.push_back(Clause); |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7835 | } else { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 7836 | TClauses.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7837 | } |
| 7838 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7839 | StmtResult AssociatedStmt; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 7840 | if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7841 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 7842 | /*CurScope=*/nullptr); |
| 7843 | StmtResult Body; |
| 7844 | { |
| 7845 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| Alexey Bataev | 475a744 | 2018-01-12 19:39:11 +0000 | [diff] [blame] | 7846 | Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt(); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 7847 | Body = getDerived().TransformStmt(CS); |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 7848 | } |
| 7849 | AssociatedStmt = |
| 7850 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7851 | if (AssociatedStmt.isInvalid()) { |
| 7852 | return StmtError(); |
| 7853 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7854 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 7855 | if (TClauses.size() != Clauses.size()) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7856 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7857 | } |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7858 | |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7859 | // Transform directive name for 'omp critical' directive. |
| 7860 | DeclarationNameInfo DirName; |
| 7861 | if (D->getDirectiveKind() == OMPD_critical) { |
| 7862 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 7863 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 7864 | } |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7865 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 7866 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 7867 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7868 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 7869 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7870 | } |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7871 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7872 | return getDerived().RebuildOMPExecutableDirective( |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7873 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7874 | AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7875 | } |
| 7876 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7877 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7878 | StmtResult |
| 7879 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 7880 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7881 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7882 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7883 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7884 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7885 | return Res; |
| 7886 | } |
| 7887 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7888 | template <typename Derived> |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7889 | StmtResult |
| 7890 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 7891 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7892 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7893 | D->getBeginLoc()); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 7894 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7895 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7896 | return Res; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7897 | } |
| 7898 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7899 | template <typename Derived> |
| 7900 | StmtResult |
| 7901 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 7902 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7903 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7904 | D->getBeginLoc()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7905 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7906 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7907 | return Res; |
| 7908 | } |
| 7909 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7910 | template <typename Derived> |
| 7911 | StmtResult |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7912 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 7913 | DeclarationNameInfo DirName; |
| 7914 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7915 | D->getBeginLoc()); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 7916 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7917 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7918 | return Res; |
| 7919 | } |
| 7920 | |
| 7921 | template <typename Derived> |
| 7922 | StmtResult |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7923 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 7924 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7925 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7926 | D->getBeginLoc()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 7927 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7928 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7929 | return Res; |
| 7930 | } |
| 7931 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7932 | template <typename Derived> |
| 7933 | StmtResult |
| 7934 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 7935 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7936 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7937 | D->getBeginLoc()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 7938 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7939 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7940 | return Res; |
| 7941 | } |
| 7942 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7943 | template <typename Derived> |
| 7944 | StmtResult |
| 7945 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 7946 | DeclarationNameInfo DirName; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7947 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7948 | D->getBeginLoc()); |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 7949 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7950 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7951 | return Res; |
| 7952 | } |
| 7953 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7954 | template <typename Derived> |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7955 | StmtResult |
| 7956 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 7957 | DeclarationNameInfo DirName; |
| 7958 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7959 | D->getBeginLoc()); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 7960 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7961 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7962 | return Res; |
| 7963 | } |
| 7964 | |
| 7965 | template <typename Derived> |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7966 | StmtResult |
| 7967 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 7968 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7969 | OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 7970 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7971 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7972 | return Res; |
| 7973 | } |
| 7974 | |
| 7975 | template <typename Derived> |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7976 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 7977 | OMPParallelForDirective *D) { |
| 7978 | DeclarationNameInfo DirName; |
| 7979 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7980 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 7981 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7982 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7983 | return Res; |
| 7984 | } |
| 7985 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7986 | template <typename Derived> |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7987 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 7988 | OMPParallelForSimdDirective *D) { |
| 7989 | DeclarationNameInfo DirName; |
| 7990 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7991 | nullptr, D->getBeginLoc()); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 7992 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 7993 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 7994 | return Res; |
| 7995 | } |
| 7996 | |
| 7997 | template <typename Derived> |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 7998 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 7999 | OMPParallelSectionsDirective *D) { |
| 8000 | DeclarationNameInfo DirName; |
| 8001 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8002 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 8003 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8004 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8005 | return Res; |
| 8006 | } |
| 8007 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8008 | template <typename Derived> |
| 8009 | StmtResult |
| 8010 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 8011 | DeclarationNameInfo DirName; |
| 8012 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8013 | D->getBeginLoc()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8014 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8015 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8016 | return Res; |
| 8017 | } |
| 8018 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 8019 | template <typename Derived> |
| 8020 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 8021 | OMPTaskyieldDirective *D) { |
| 8022 | DeclarationNameInfo DirName; |
| 8023 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8024 | D->getBeginLoc()); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 8025 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8026 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8027 | return Res; |
| 8028 | } |
| 8029 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 8030 | template <typename Derived> |
| 8031 | StmtResult |
| 8032 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 8033 | DeclarationNameInfo DirName; |
| 8034 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8035 | D->getBeginLoc()); |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 8036 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8037 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8038 | return Res; |
| 8039 | } |
| 8040 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 8041 | template <typename Derived> |
| 8042 | StmtResult |
| 8043 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 8044 | DeclarationNameInfo DirName; |
| 8045 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8046 | D->getBeginLoc()); |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 8047 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8048 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8049 | return Res; |
| 8050 | } |
| 8051 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8052 | template <typename Derived> |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8053 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 8054 | OMPTaskgroupDirective *D) { |
| 8055 | DeclarationNameInfo DirName; |
| 8056 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8057 | D->getBeginLoc()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 8058 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8059 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8060 | return Res; |
| 8061 | } |
| 8062 | |
| 8063 | template <typename Derived> |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8064 | StmtResult |
| 8065 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 8066 | DeclarationNameInfo DirName; |
| 8067 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8068 | D->getBeginLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8069 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8070 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8071 | return Res; |
| 8072 | } |
| 8073 | |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8074 | template <typename Derived> |
| 8075 | StmtResult |
| 8076 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 8077 | DeclarationNameInfo DirName; |
| 8078 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8079 | D->getBeginLoc()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 8080 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8081 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8082 | return Res; |
| 8083 | } |
| 8084 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8085 | template <typename Derived> |
| 8086 | StmtResult |
| 8087 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 8088 | DeclarationNameInfo DirName; |
| 8089 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8090 | D->getBeginLoc()); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 8091 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8092 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8093 | return Res; |
| 8094 | } |
| 8095 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 8096 | template <typename Derived> |
| 8097 | StmtResult |
| 8098 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 8099 | DeclarationNameInfo DirName; |
| 8100 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8101 | D->getBeginLoc()); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 8102 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8103 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8104 | return Res; |
| 8105 | } |
| 8106 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8107 | template <typename Derived> |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 8108 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 8109 | OMPTargetDataDirective *D) { |
| 8110 | DeclarationNameInfo DirName; |
| 8111 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8112 | D->getBeginLoc()); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 8113 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8114 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8115 | return Res; |
| 8116 | } |
| 8117 | |
| 8118 | template <typename Derived> |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8119 | StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 8120 | OMPTargetEnterDataDirective *D) { |
| 8121 | DeclarationNameInfo DirName; |
| 8122 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8123 | nullptr, D->getBeginLoc()); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 8124 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8125 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8126 | return Res; |
| 8127 | } |
| 8128 | |
| 8129 | template <typename Derived> |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8130 | StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 8131 | OMPTargetExitDataDirective *D) { |
| 8132 | DeclarationNameInfo DirName; |
| 8133 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8134 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 8135 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8136 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8137 | return Res; |
| 8138 | } |
| 8139 | |
| 8140 | template <typename Derived> |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 8141 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 8142 | OMPTargetParallelDirective *D) { |
| 8143 | DeclarationNameInfo DirName; |
| 8144 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8145 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 8146 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8147 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8148 | return Res; |
| 8149 | } |
| 8150 | |
| 8151 | template <typename Derived> |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 8152 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 8153 | OMPTargetParallelForDirective *D) { |
| 8154 | DeclarationNameInfo DirName; |
| 8155 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8156 | nullptr, D->getBeginLoc()); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 8157 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8158 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8159 | return Res; |
| 8160 | } |
| 8161 | |
| 8162 | template <typename Derived> |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 8163 | StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 8164 | OMPTargetUpdateDirective *D) { |
| 8165 | DeclarationNameInfo DirName; |
| 8166 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8167 | nullptr, D->getBeginLoc()); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 8168 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8169 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8170 | return Res; |
| 8171 | } |
| 8172 | |
| 8173 | template <typename Derived> |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8174 | StmtResult |
| 8175 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 8176 | DeclarationNameInfo DirName; |
| 8177 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8178 | D->getBeginLoc()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 8179 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8180 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8181 | return Res; |
| 8182 | } |
| 8183 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8184 | template <typename Derived> |
| 8185 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 8186 | OMPCancellationPointDirective *D) { |
| 8187 | DeclarationNameInfo DirName; |
| 8188 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8189 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8190 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8191 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8192 | return Res; |
| 8193 | } |
| 8194 | |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8195 | template <typename Derived> |
| 8196 | StmtResult |
| 8197 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 8198 | DeclarationNameInfo DirName; |
| 8199 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8200 | D->getBeginLoc()); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 8201 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8202 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8203 | return Res; |
| 8204 | } |
| 8205 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8206 | template <typename Derived> |
| 8207 | StmtResult |
| 8208 | TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 8209 | DeclarationNameInfo DirName; |
| 8210 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8211 | D->getBeginLoc()); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 8212 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8213 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8214 | return Res; |
| 8215 | } |
| 8216 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8217 | template <typename Derived> |
| 8218 | StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 8219 | OMPTaskLoopSimdDirective *D) { |
| 8220 | DeclarationNameInfo DirName; |
| 8221 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8222 | nullptr, D->getBeginLoc()); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 8223 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8224 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8225 | return Res; |
| 8226 | } |
| 8227 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8228 | template <typename Derived> |
| 8229 | StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 8230 | OMPDistributeDirective *D) { |
| 8231 | DeclarationNameInfo DirName; |
| 8232 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8233 | D->getBeginLoc()); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8234 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8235 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8236 | return Res; |
| 8237 | } |
| 8238 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8239 | template <typename Derived> |
| 8240 | StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 8241 | OMPDistributeParallelForDirective *D) { |
| 8242 | DeclarationNameInfo DirName; |
| 8243 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8244 | OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 8245 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8246 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8247 | return Res; |
| 8248 | } |
| 8249 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8250 | template <typename Derived> |
| 8251 | StmtResult |
| 8252 | TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 8253 | OMPDistributeParallelForSimdDirective *D) { |
| 8254 | DeclarationNameInfo DirName; |
| 8255 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8256 | OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 8257 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8258 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8259 | return Res; |
| 8260 | } |
| 8261 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8262 | template <typename Derived> |
| 8263 | StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( |
| 8264 | OMPDistributeSimdDirective *D) { |
| 8265 | DeclarationNameInfo DirName; |
| 8266 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8267 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 8268 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8269 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8270 | return Res; |
| 8271 | } |
| 8272 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8273 | template <typename Derived> |
| 8274 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( |
| 8275 | OMPTargetParallelForSimdDirective *D) { |
| 8276 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8277 | getDerived().getSema().StartOpenMPDSABlock( |
| 8278 | OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 8279 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8280 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8281 | return Res; |
| 8282 | } |
| 8283 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8284 | template <typename Derived> |
| 8285 | StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( |
| 8286 | OMPTargetSimdDirective *D) { |
| 8287 | DeclarationNameInfo DirName; |
| 8288 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8289 | D->getBeginLoc()); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 8290 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8291 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8292 | return Res; |
| 8293 | } |
| 8294 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8295 | template <typename Derived> |
| 8296 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( |
| 8297 | OMPTeamsDistributeDirective *D) { |
| 8298 | DeclarationNameInfo DirName; |
| 8299 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8300 | nullptr, D->getBeginLoc()); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 8301 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8302 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8303 | return Res; |
| 8304 | } |
| 8305 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8306 | template <typename Derived> |
| 8307 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( |
| 8308 | OMPTeamsDistributeSimdDirective *D) { |
| 8309 | DeclarationNameInfo DirName; |
| 8310 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8311 | OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 8312 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8313 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8314 | return Res; |
| 8315 | } |
| 8316 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8317 | template <typename Derived> |
| 8318 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( |
| 8319 | OMPTeamsDistributeParallelForSimdDirective *D) { |
| 8320 | DeclarationNameInfo DirName; |
| 8321 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8322 | OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 8323 | D->getBeginLoc()); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8324 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8325 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8326 | return Res; |
| 8327 | } |
| 8328 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8329 | template <typename Derived> |
| 8330 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( |
| 8331 | OMPTeamsDistributeParallelForDirective *D) { |
| 8332 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8333 | getDerived().getSema().StartOpenMPDSABlock( |
| 8334 | OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8335 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8336 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8337 | return Res; |
| 8338 | } |
| 8339 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8340 | template <typename Derived> |
| 8341 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( |
| 8342 | OMPTargetTeamsDirective *D) { |
| 8343 | DeclarationNameInfo DirName; |
| 8344 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8345 | nullptr, D->getBeginLoc()); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8346 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8347 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8348 | return Res; |
| 8349 | } |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8350 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8351 | template <typename Derived> |
| 8352 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( |
| 8353 | OMPTargetTeamsDistributeDirective *D) { |
| 8354 | DeclarationNameInfo DirName; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8355 | getDerived().getSema().StartOpenMPDSABlock( |
| 8356 | OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8357 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8358 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8359 | return Res; |
| 8360 | } |
| 8361 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8362 | template <typename Derived> |
| 8363 | StmtResult |
| 8364 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( |
| 8365 | OMPTargetTeamsDistributeParallelForDirective *D) { |
| 8366 | DeclarationNameInfo DirName; |
| 8367 | getDerived().getSema().StartOpenMPDSABlock( |
| 8368 | OMPD_target_teams_distribute_parallel_for, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8369 | D->getBeginLoc()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8370 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8371 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8372 | return Res; |
| 8373 | } |
| 8374 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8375 | template <typename Derived> |
| 8376 | StmtResult TreeTransform<Derived>:: |
| 8377 | TransformOMPTargetTeamsDistributeParallelForSimdDirective( |
| 8378 | OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 8379 | DeclarationNameInfo DirName; |
| 8380 | getDerived().getSema().StartOpenMPDSABlock( |
| 8381 | OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8382 | D->getBeginLoc()); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8383 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8384 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8385 | return Res; |
| 8386 | } |
| 8387 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8388 | template <typename Derived> |
| 8389 | StmtResult |
| 8390 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( |
| 8391 | OMPTargetTeamsDistributeSimdDirective *D) { |
| 8392 | DeclarationNameInfo DirName; |
| 8393 | getDerived().getSema().StartOpenMPDSABlock( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8394 | OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8395 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8396 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8397 | return Res; |
| 8398 | } |
| 8399 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8400 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8401 | //===----------------------------------------------------------------------===// |
| 8402 | // OpenMP clause transformation |
| 8403 | //===----------------------------------------------------------------------===// |
| 8404 | template <typename Derived> |
| 8405 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| Alexey Bataev | af7849e | 2014-03-05 06:45:14 +0000 | [diff] [blame] | 8406 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8407 | if (Cond.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8408 | return nullptr; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8409 | return getDerived().RebuildOMPIfClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8410 | C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8411 | C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8412 | } |
| 8413 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8414 | template <typename Derived> |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8415 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 8416 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8417 | if (Cond.isInvalid()) |
| 8418 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8419 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8420 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8421 | } |
| 8422 | |
| 8423 | template <typename Derived> |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8424 | OMPClause * |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8425 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 8426 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 8427 | if (NumThreads.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8428 | return nullptr; |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8429 | return getDerived().RebuildOMPNumThreadsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8430 | NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8431 | } |
| 8432 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8433 | template <typename Derived> |
| 8434 | OMPClause * |
| 8435 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 8436 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 8437 | if (E.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8438 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8439 | return getDerived().RebuildOMPSafelenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8440 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8441 | } |
| 8442 | |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8443 | template <typename Derived> |
| 8444 | OMPClause * |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 8445 | TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { |
| 8446 | ExprResult E = getDerived().TransformExpr(C->getAllocator()); |
| 8447 | if (E.isInvalid()) |
| 8448 | return nullptr; |
| 8449 | return getDerived().RebuildOMPAllocatorClause( |
| 8450 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 8451 | } |
| 8452 | |
| 8453 | template <typename Derived> |
| 8454 | OMPClause * |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8455 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 8456 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 8457 | if (E.isInvalid()) |
| 8458 | return nullptr; |
| 8459 | return getDerived().RebuildOMPSimdlenClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8460 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8461 | } |
| 8462 | |
| 8463 | template <typename Derived> |
| 8464 | OMPClause * |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8465 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 8466 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 8467 | if (E.isInvalid()) |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 8468 | return nullptr; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8469 | return getDerived().RebuildOMPCollapseClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8470 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8471 | } |
| 8472 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8473 | template <typename Derived> |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8474 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8475 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8476 | return getDerived().RebuildOMPDefaultClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8477 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8478 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8479 | } |
| 8480 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8481 | template <typename Derived> |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8482 | OMPClause * |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8483 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8484 | return getDerived().RebuildOMPProcBindClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8485 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8486 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8487 | } |
| 8488 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8489 | template <typename Derived> |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8490 | OMPClause * |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8491 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 8492 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 8493 | if (E.isInvalid()) |
| 8494 | return nullptr; |
| 8495 | return getDerived().RebuildOMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8496 | C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8497 | C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8498 | C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8499 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8500 | } |
| 8501 | |
| 8502 | template <typename Derived> |
| 8503 | OMPClause * |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8504 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8505 | ExprResult E; |
| 8506 | if (auto *Num = C->getNumForLoops()) { |
| 8507 | E = getDerived().TransformExpr(Num); |
| 8508 | if (E.isInvalid()) |
| 8509 | return nullptr; |
| 8510 | } |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8511 | return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8512 | C->getLParenLoc(), E.get()); |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8513 | } |
| 8514 | |
| 8515 | template <typename Derived> |
| 8516 | OMPClause * |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8517 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 8518 | // No need to rebuild this clause, no template-dependent parameters. |
| 8519 | return C; |
| 8520 | } |
| 8521 | |
| 8522 | template <typename Derived> |
| 8523 | OMPClause * |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8524 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 8525 | // No need to rebuild this clause, no template-dependent parameters. |
| 8526 | return C; |
| 8527 | } |
| 8528 | |
| 8529 | template <typename Derived> |
| 8530 | OMPClause * |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8531 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 8532 | // No need to rebuild this clause, no template-dependent parameters. |
| 8533 | return C; |
| 8534 | } |
| 8535 | |
| 8536 | template <typename Derived> |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8537 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 8538 | // No need to rebuild this clause, no template-dependent parameters. |
| 8539 | return C; |
| 8540 | } |
| 8541 | |
| 8542 | template <typename Derived> |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8543 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 8544 | // No need to rebuild this clause, no template-dependent parameters. |
| 8545 | return C; |
| 8546 | } |
| 8547 | |
| 8548 | template <typename Derived> |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8549 | OMPClause * |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8550 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 8551 | // No need to rebuild this clause, no template-dependent parameters. |
| 8552 | return C; |
| 8553 | } |
| 8554 | |
| 8555 | template <typename Derived> |
| 8556 | OMPClause * |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8557 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 8558 | // No need to rebuild this clause, no template-dependent parameters. |
| 8559 | return C; |
| 8560 | } |
| 8561 | |
| 8562 | template <typename Derived> |
| 8563 | OMPClause * |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8564 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 8565 | // No need to rebuild this clause, no template-dependent parameters. |
| 8566 | return C; |
| 8567 | } |
| 8568 | |
| 8569 | template <typename Derived> |
| 8570 | OMPClause * |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8571 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 8572 | // No need to rebuild this clause, no template-dependent parameters. |
| 8573 | return C; |
| 8574 | } |
| 8575 | |
| 8576 | template <typename Derived> |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8577 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 8578 | // No need to rebuild this clause, no template-dependent parameters. |
| 8579 | return C; |
| 8580 | } |
| 8581 | |
| 8582 | template <typename Derived> |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8583 | OMPClause * |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8584 | TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 8585 | // No need to rebuild this clause, no template-dependent parameters. |
| 8586 | return C; |
| 8587 | } |
| 8588 | |
| 8589 | template <typename Derived> |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8590 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( |
| 8591 | OMPUnifiedAddressClause *C) { |
| Patrick Lyster | e653b63 | 2018-09-27 19:30:32 +0000 | [diff] [blame] | 8592 | llvm_unreachable("unified_address clause cannot appear in dependent context"); |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8593 | } |
| 8594 | |
| 8595 | template <typename Derived> |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 8596 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( |
| 8597 | OMPUnifiedSharedMemoryClause *C) { |
| 8598 | llvm_unreachable( |
| 8599 | "unified_shared_memory clause cannot appear in dependent context"); |
| 8600 | } |
| 8601 | |
| 8602 | template <typename Derived> |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 8603 | OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( |
| 8604 | OMPReverseOffloadClause *C) { |
| 8605 | llvm_unreachable("reverse_offload clause cannot appear in dependent context"); |
| 8606 | } |
| 8607 | |
| 8608 | template <typename Derived> |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 8609 | OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( |
| 8610 | OMPDynamicAllocatorsClause *C) { |
| 8611 | llvm_unreachable( |
| 8612 | "dynamic_allocators clause cannot appear in dependent context"); |
| 8613 | } |
| 8614 | |
| 8615 | template <typename Derived> |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 8616 | OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( |
| 8617 | OMPAtomicDefaultMemOrderClause *C) { |
| 8618 | llvm_unreachable( |
| 8619 | "atomic_default_mem_order clause cannot appear in dependent context"); |
| 8620 | } |
| 8621 | |
| 8622 | template <typename Derived> |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8623 | OMPClause * |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8624 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8625 | llvm::SmallVector<Expr *, 16> Vars; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8626 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8627 | for (auto *VE : C->varlists()) { |
| 8628 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8629 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8630 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8631 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8632 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8633 | return getDerived().RebuildOMPPrivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8634 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8635 | } |
| 8636 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8637 | template <typename Derived> |
| 8638 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 8639 | OMPFirstprivateClause *C) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8640 | llvm::SmallVector<Expr *, 16> Vars; |
| 8641 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8642 | for (auto *VE : C->varlists()) { |
| 8643 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8644 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8645 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8646 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8647 | } |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8648 | return getDerived().RebuildOMPFirstprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8649 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8650 | } |
| 8651 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8652 | template <typename Derived> |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8653 | OMPClause * |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8654 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 8655 | llvm::SmallVector<Expr *, 16> Vars; |
| 8656 | Vars.reserve(C->varlist_size()); |
| 8657 | for (auto *VE : C->varlists()) { |
| 8658 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8659 | if (EVar.isInvalid()) |
| 8660 | return nullptr; |
| 8661 | Vars.push_back(EVar.get()); |
| 8662 | } |
| 8663 | return getDerived().RebuildOMPLastprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8664 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8665 | } |
| 8666 | |
| 8667 | template <typename Derived> |
| 8668 | OMPClause * |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8669 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 8670 | llvm::SmallVector<Expr *, 16> Vars; |
| 8671 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8672 | for (auto *VE : C->varlists()) { |
| 8673 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8674 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8675 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8676 | Vars.push_back(EVar.get()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8677 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8678 | return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8679 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8680 | } |
| 8681 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8682 | template <typename Derived> |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8683 | OMPClause * |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8684 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 8685 | llvm::SmallVector<Expr *, 16> Vars; |
| 8686 | Vars.reserve(C->varlist_size()); |
| 8687 | for (auto *VE : C->varlists()) { |
| 8688 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8689 | if (EVar.isInvalid()) |
| 8690 | return nullptr; |
| 8691 | Vars.push_back(EVar.get()); |
| 8692 | } |
| 8693 | CXXScopeSpec ReductionIdScopeSpec; |
| 8694 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8695 | |
| 8696 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8697 | if (NameInfo.getName()) { |
| 8698 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8699 | if (!NameInfo.getName()) |
| 8700 | return nullptr; |
| 8701 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8702 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8703 | // The Scope boundary is a duplication of the previous decl. |
| 8704 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8705 | for (auto *E : C->reduction_ops()) { |
| 8706 | // Transform all the decls. |
| 8707 | if (E) { |
| 8708 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8709 | UnresolvedSet<8> Decls; |
| 8710 | for (auto *D : ULE->decls()) { |
| 8711 | NamedDecl *InstD = |
| 8712 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8713 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8714 | } |
| 8715 | UnresolvedReductions.push_back( |
| 8716 | UnresolvedLookupExpr::Create( |
| 8717 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8718 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), |
| 8719 | NameInfo, /*ADL=*/true, ULE->isOverloaded(), |
| 8720 | Decls.begin(), Decls.end())); |
| 8721 | } else |
| 8722 | UnresolvedReductions.push_back(nullptr); |
| 8723 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8724 | return getDerived().RebuildOMPReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8725 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8726 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8727 | } |
| 8728 | |
| 8729 | template <typename Derived> |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8730 | OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( |
| 8731 | OMPTaskReductionClause *C) { |
| 8732 | llvm::SmallVector<Expr *, 16> Vars; |
| 8733 | Vars.reserve(C->varlist_size()); |
| 8734 | for (auto *VE : C->varlists()) { |
| 8735 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8736 | if (EVar.isInvalid()) |
| 8737 | return nullptr; |
| 8738 | Vars.push_back(EVar.get()); |
| 8739 | } |
| 8740 | CXXScopeSpec ReductionIdScopeSpec; |
| 8741 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8742 | |
| 8743 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8744 | if (NameInfo.getName()) { |
| 8745 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8746 | if (!NameInfo.getName()) |
| 8747 | return nullptr; |
| 8748 | } |
| 8749 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8750 | // The Scope boundary is a duplication of the previous decl. |
| 8751 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8752 | for (auto *E : C->reduction_ops()) { |
| 8753 | // Transform all the decls. |
| 8754 | if (E) { |
| 8755 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8756 | UnresolvedSet<8> Decls; |
| 8757 | for (auto *D : ULE->decls()) { |
| 8758 | NamedDecl *InstD = |
| 8759 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8760 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8761 | } |
| 8762 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8763 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8764 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8765 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8766 | } else |
| 8767 | UnresolvedReductions.push_back(nullptr); |
| 8768 | } |
| 8769 | return getDerived().RebuildOMPTaskReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8770 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8771 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8772 | } |
| 8773 | |
| 8774 | template <typename Derived> |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8775 | OMPClause * |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8776 | TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { |
| 8777 | llvm::SmallVector<Expr *, 16> Vars; |
| 8778 | Vars.reserve(C->varlist_size()); |
| 8779 | for (auto *VE : C->varlists()) { |
| 8780 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8781 | if (EVar.isInvalid()) |
| 8782 | return nullptr; |
| 8783 | Vars.push_back(EVar.get()); |
| 8784 | } |
| 8785 | CXXScopeSpec ReductionIdScopeSpec; |
| 8786 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 8787 | |
| 8788 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 8789 | if (NameInfo.getName()) { |
| 8790 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8791 | if (!NameInfo.getName()) |
| 8792 | return nullptr; |
| 8793 | } |
| 8794 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 8795 | // The Scope boundary is a duplication of the previous decl. |
| 8796 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 8797 | for (auto *E : C->reduction_ops()) { |
| 8798 | // Transform all the decls. |
| 8799 | if (E) { |
| 8800 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8801 | UnresolvedSet<8> Decls; |
| 8802 | for (auto *D : ULE->decls()) { |
| 8803 | NamedDecl *InstD = |
| 8804 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 8805 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8806 | } |
| 8807 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 8808 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8809 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 8810 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 8811 | } else |
| 8812 | UnresolvedReductions.push_back(nullptr); |
| 8813 | } |
| 8814 | return getDerived().RebuildOMPInReductionClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8815 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8816 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8817 | } |
| 8818 | |
| 8819 | template <typename Derived> |
| 8820 | OMPClause * |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8821 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 8822 | llvm::SmallVector<Expr *, 16> Vars; |
| 8823 | Vars.reserve(C->varlist_size()); |
| 8824 | for (auto *VE : C->varlists()) { |
| 8825 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8826 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8827 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8828 | Vars.push_back(EVar.get()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8829 | } |
| 8830 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 8831 | if (Step.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8832 | return nullptr; |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8833 | return getDerived().RebuildOMPLinearClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8834 | Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8835 | C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8836 | } |
| 8837 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8838 | template <typename Derived> |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8839 | OMPClause * |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8840 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 8841 | llvm::SmallVector<Expr *, 16> Vars; |
| 8842 | Vars.reserve(C->varlist_size()); |
| 8843 | for (auto *VE : C->varlists()) { |
| 8844 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8845 | if (EVar.isInvalid()) |
| 8846 | return nullptr; |
| 8847 | Vars.push_back(EVar.get()); |
| 8848 | } |
| 8849 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 8850 | if (Alignment.isInvalid()) |
| 8851 | return nullptr; |
| 8852 | return getDerived().RebuildOMPAlignedClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8853 | Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8854 | C->getColonLoc(), C->getEndLoc()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8855 | } |
| 8856 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 8857 | template <typename Derived> |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8858 | OMPClause * |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8859 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 8860 | llvm::SmallVector<Expr *, 16> Vars; |
| 8861 | Vars.reserve(C->varlist_size()); |
| Alexey Bataev | 444120d | 2014-04-04 10:02:14 +0000 | [diff] [blame] | 8862 | for (auto *VE : C->varlists()) { |
| 8863 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8864 | if (EVar.isInvalid()) |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 8865 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 8866 | Vars.push_back(EVar.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8867 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8868 | return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8869 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8870 | } |
| 8871 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8872 | template <typename Derived> |
| 8873 | OMPClause * |
| 8874 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 8875 | llvm::SmallVector<Expr *, 16> Vars; |
| 8876 | Vars.reserve(C->varlist_size()); |
| 8877 | for (auto *VE : C->varlists()) { |
| 8878 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8879 | if (EVar.isInvalid()) |
| 8880 | return nullptr; |
| 8881 | Vars.push_back(EVar.get()); |
| 8882 | } |
| 8883 | return getDerived().RebuildOMPCopyprivateClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8884 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8885 | } |
| 8886 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8887 | template <typename Derived> |
| 8888 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 8889 | llvm::SmallVector<Expr *, 16> Vars; |
| 8890 | Vars.reserve(C->varlist_size()); |
| 8891 | for (auto *VE : C->varlists()) { |
| 8892 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8893 | if (EVar.isInvalid()) |
| 8894 | return nullptr; |
| 8895 | Vars.push_back(EVar.get()); |
| 8896 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8897 | return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8898 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8899 | } |
| 8900 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8901 | template <typename Derived> |
| 8902 | OMPClause * |
| 8903 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 8904 | llvm::SmallVector<Expr *, 16> Vars; |
| 8905 | Vars.reserve(C->varlist_size()); |
| 8906 | for (auto *VE : C->varlists()) { |
| 8907 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 8908 | if (EVar.isInvalid()) |
| 8909 | return nullptr; |
| 8910 | Vars.push_back(EVar.get()); |
| 8911 | } |
| 8912 | return getDerived().RebuildOMPDependClause( |
| 8913 | C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8914 | C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8915 | } |
| 8916 | |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8917 | template <typename Derived> |
| 8918 | OMPClause * |
| 8919 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 8920 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 8921 | if (E.isInvalid()) |
| 8922 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 8923 | return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 8924 | C->getLParenLoc(), C->getEndLoc()); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8925 | } |
| 8926 | |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8927 | template <typename Derived, class T> |
| 8928 | bool transformOMPMappableExprListClause( |
| 8929 | TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, |
| 8930 | llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, |
| 8931 | DeclarationNameInfo &MapperIdInfo, |
| 8932 | llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { |
| 8933 | // Transform expressions in the list. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8934 | Vars.reserve(C->varlist_size()); |
| 8935 | for (auto *VE : C->varlists()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8936 | ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8937 | if (EVar.isInvalid()) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8938 | return true; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8939 | Vars.push_back(EVar.get()); |
| 8940 | } |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8941 | // Transform mapper scope specifier and identifier. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8942 | NestedNameSpecifierLoc QualifierLoc; |
| 8943 | if (C->getMapperQualifierLoc()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8944 | QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8945 | C->getMapperQualifierLoc()); |
| 8946 | if (!QualifierLoc) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8947 | return true; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8948 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8949 | MapperIdScopeSpec.Adopt(QualifierLoc); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8950 | MapperIdInfo = C->getMapperIdInfo(); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8951 | if (MapperIdInfo.getName()) { |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8952 | MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8953 | if (!MapperIdInfo.getName()) |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8954 | return true; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8955 | } |
| 8956 | // Build a list of all candidate OMPDeclareMapperDecls, which is provided by |
| 8957 | // the previous user-defined mapper lookup in dependent environment. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8958 | for (auto *E : C->mapperlists()) { |
| 8959 | // Transform all the decls. |
| 8960 | if (E) { |
| 8961 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 8962 | UnresolvedSet<8> Decls; |
| 8963 | for (auto *D : ULE->decls()) { |
| 8964 | NamedDecl *InstD = |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8965 | cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8966 | Decls.addDecl(InstD, InstD->getAccess()); |
| 8967 | } |
| 8968 | UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8969 | TT.getSema().Context, /*NamingClass=*/nullptr, |
| 8970 | MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), |
| 8971 | MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), |
| 8972 | Decls.end())); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8973 | } else { |
| 8974 | UnresolvedMappers.push_back(nullptr); |
| 8975 | } |
| 8976 | } |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8977 | return false; |
| 8978 | } |
| 8979 | |
| 8980 | template <typename Derived> |
| 8981 | OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8982 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 8983 | llvm::SmallVector<Expr *, 16> Vars; |
| 8984 | CXXScopeSpec MapperIdScopeSpec; |
| 8985 | DeclarationNameInfo MapperIdInfo; |
| 8986 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 8987 | if (transformOMPMappableExprListClause<Derived, OMPMapClause>( |
| 8988 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 8989 | return nullptr; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8990 | return getDerived().RebuildOMPMapClause( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 8991 | C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec, |
| 8992 | MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(), |
| 8993 | C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8994 | } |
| 8995 | |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8996 | template <typename Derived> |
| 8997 | OMPClause * |
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 8998 | TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { |
| 8999 | Expr *Allocator = C->getAllocator(); |
| 9000 | if (Allocator) { |
| 9001 | ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); |
| 9002 | if (AllocatorRes.isInvalid()) |
| 9003 | return nullptr; |
| 9004 | Allocator = AllocatorRes.get(); |
| 9005 | } |
| 9006 | llvm::SmallVector<Expr *, 16> Vars; |
| 9007 | Vars.reserve(C->varlist_size()); |
| 9008 | for (auto *VE : C->varlists()) { |
| 9009 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9010 | if (EVar.isInvalid()) |
| 9011 | return nullptr; |
| 9012 | Vars.push_back(EVar.get()); |
| 9013 | } |
| 9014 | return getDerived().RebuildOMPAllocateClause( |
| 9015 | Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 9016 | C->getEndLoc()); |
| 9017 | } |
| 9018 | |
| 9019 | template <typename Derived> |
| 9020 | OMPClause * |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9021 | TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 9022 | ExprResult E = getDerived().TransformExpr(C->getNumTeams()); |
| 9023 | if (E.isInvalid()) |
| 9024 | return nullptr; |
| 9025 | return getDerived().RebuildOMPNumTeamsClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9026 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9027 | } |
| 9028 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9029 | template <typename Derived> |
| 9030 | OMPClause * |
| 9031 | TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 9032 | ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); |
| 9033 | if (E.isInvalid()) |
| 9034 | return nullptr; |
| 9035 | return getDerived().RebuildOMPThreadLimitClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9036 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9037 | } |
| 9038 | |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9039 | template <typename Derived> |
| 9040 | OMPClause * |
| 9041 | TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 9042 | ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 9043 | if (E.isInvalid()) |
| 9044 | return nullptr; |
| 9045 | return getDerived().RebuildOMPPriorityClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9046 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9047 | } |
| 9048 | |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9049 | template <typename Derived> |
| 9050 | OMPClause * |
| 9051 | TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 9052 | ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 9053 | if (E.isInvalid()) |
| 9054 | return nullptr; |
| 9055 | return getDerived().RebuildOMPGrainsizeClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9056 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9057 | } |
| 9058 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9059 | template <typename Derived> |
| 9060 | OMPClause * |
| 9061 | TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 9062 | ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 9063 | if (E.isInvalid()) |
| 9064 | return nullptr; |
| 9065 | return getDerived().RebuildOMPNumTasksClause( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9066 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9067 | } |
| 9068 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9069 | template <typename Derived> |
| 9070 | OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 9071 | ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 9072 | if (E.isInvalid()) |
| 9073 | return nullptr; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9074 | return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9075 | C->getLParenLoc(), C->getEndLoc()); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9076 | } |
| 9077 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9078 | template <typename Derived> |
| 9079 | OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 9080 | OMPDistScheduleClause *C) { |
| 9081 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 9082 | if (E.isInvalid()) |
| 9083 | return nullptr; |
| 9084 | return getDerived().RebuildOMPDistScheduleClause( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9085 | C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9086 | C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9087 | } |
| 9088 | |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9089 | template <typename Derived> |
| 9090 | OMPClause * |
| 9091 | TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 9092 | return C; |
| 9093 | } |
| 9094 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9095 | template <typename Derived> |
| 9096 | OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9097 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 9098 | llvm::SmallVector<Expr *, 16> Vars; |
| 9099 | CXXScopeSpec MapperIdScopeSpec; |
| 9100 | DeclarationNameInfo MapperIdInfo; |
| 9101 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9102 | if (transformOMPMappableExprListClause<Derived, OMPToClause>( |
| 9103 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9104 | return nullptr; |
| 9105 | return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo, |
| 9106 | Locs, UnresolvedMappers); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9107 | } |
| 9108 | |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9109 | template <typename Derived> |
| 9110 | OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9111 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 9112 | llvm::SmallVector<Expr *, 16> Vars; |
| 9113 | CXXScopeSpec MapperIdScopeSpec; |
| 9114 | DeclarationNameInfo MapperIdInfo; |
| 9115 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9116 | if (transformOMPMappableExprListClause<Derived, OMPFromClause>( |
| 9117 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9118 | return nullptr; |
| 9119 | return getDerived().RebuildOMPFromClause( |
| 9120 | Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9121 | } |
| 9122 | |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9123 | template <typename Derived> |
| 9124 | OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( |
| 9125 | OMPUseDevicePtrClause *C) { |
| 9126 | llvm::SmallVector<Expr *, 16> Vars; |
| 9127 | Vars.reserve(C->varlist_size()); |
| 9128 | for (auto *VE : C->varlists()) { |
| 9129 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9130 | if (EVar.isInvalid()) |
| 9131 | return nullptr; |
| 9132 | Vars.push_back(EVar.get()); |
| 9133 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9134 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9135 | return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9136 | } |
| 9137 | |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9138 | template <typename Derived> |
| 9139 | OMPClause * |
| 9140 | TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 9141 | llvm::SmallVector<Expr *, 16> Vars; |
| 9142 | Vars.reserve(C->varlist_size()); |
| 9143 | for (auto *VE : C->varlists()) { |
| 9144 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9145 | if (EVar.isInvalid()) |
| 9146 | return nullptr; |
| 9147 | Vars.push_back(EVar.get()); |
| 9148 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9149 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9150 | return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9151 | } |
| 9152 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9153 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9154 | // Expression transformation |
| 9155 | //===----------------------------------------------------------------------===// |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9156 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9157 | ExprResult |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 9158 | TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { |
| 9159 | return TransformExpr(E->getSubExpr()); |
| 9160 | } |
| 9161 | |
| 9162 | template<typename Derived> |
| 9163 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9164 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 9165 | if (!E->isTypeDependent()) |
| 9166 | return E; |
| 9167 | |
| 9168 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 9169 | E->getIdentKind()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9170 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9171 | |
| 9172 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9173 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9174 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9175 | NestedNameSpecifierLoc QualifierLoc; |
| 9176 | if (E->getQualifierLoc()) { |
| 9177 | QualifierLoc |
| 9178 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9179 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9180 | return ExprError(); |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9181 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9182 | |
| 9183 | ValueDecl *ND |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9184 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 9185 | E->getDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9186 | if (!ND) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9187 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9188 | |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 9189 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 9190 | if (NameInfo.getName()) { |
| 9191 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9192 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9193 | return ExprError(); |
| John McCall | 815039a | 2010-08-17 21:27:17 +0000 | [diff] [blame] | 9194 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9195 | |
| 9196 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9197 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9198 | ND == E->getDecl() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 9199 | NameInfo.getName() == E->getDecl()->getDeclName() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9200 | !E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9201 | |
| 9202 | // Mark it referenced in the new context regardless. |
| 9203 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9204 | SemaRef.MarkDeclRefReferenced(E); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9205 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9206 | return E; |
| Douglas Gregor | 4bd90e5 | 2009-10-23 18:54:35 +0000 | [diff] [blame] | 9207 | } |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9208 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9209 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9210 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9211 | TemplateArgs = &TransArgs; |
| 9212 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9213 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9214 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9215 | E->getNumTemplateArgs(), |
| 9216 | TransArgs)) |
| 9217 | return ExprError(); |
| John McCall | ce54657 | 2009-12-08 09:08:17 +0000 | [diff] [blame] | 9218 | } |
| 9219 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9220 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9221 | TemplateArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9222 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9223 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9224 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9225 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9226 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9227 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9228 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9229 | |
| Leonard Chan | db01c3a | 2018-06-20 17:19:40 +0000 | [diff] [blame] | 9230 | template <typename Derived> |
| 9231 | ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( |
| 9232 | FixedPointLiteral *E) { |
| 9233 | return E; |
| 9234 | } |
| 9235 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9236 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9237 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9238 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9239 | return E; |
| 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>::TransformImaginaryLiteral(ImaginaryLiteral *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 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9248 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9249 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9250 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9251 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9252 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 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>::TransformCharacterLiteral(CharacterLiteral *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9257 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9258 | } |
| 9259 | |
| 9260 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9261 | ExprResult |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 9262 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| Argyrios Kyrtzidis | 2504909 | 2013-04-09 01:17:02 +0000 | [diff] [blame] | 9263 | if (FunctionDecl *FD = E->getDirectCallee()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9264 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD); |
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 9265 | return SemaRef.MaybeBindToTemporary(E); |
| 9266 | } |
| 9267 | |
| 9268 | template<typename Derived> |
| 9269 | ExprResult |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9270 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 9271 | ExprResult ControllingExpr = |
| 9272 | getDerived().TransformExpr(E->getControllingExpr()); |
| 9273 | if (ControllingExpr.isInvalid()) |
| 9274 | return ExprError(); |
| 9275 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9276 | SmallVector<Expr *, 4> AssocExprs; |
| 9277 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| Bruno Ricci | 1ec7fd3 | 2019-01-29 12:57:11 +0000 | [diff] [blame] | 9278 | for (const GenericSelectionExpr::Association &Assoc : E->associations()) { |
| 9279 | TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); |
| 9280 | if (TSI) { |
| 9281 | TypeSourceInfo *AssocType = getDerived().TransformType(TSI); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9282 | if (!AssocType) |
| 9283 | return ExprError(); |
| 9284 | AssocTypes.push_back(AssocType); |
| 9285 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9286 | AssocTypes.push_back(nullptr); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9287 | } |
| 9288 | |
| Bruno Ricci | 1ec7fd3 | 2019-01-29 12:57:11 +0000 | [diff] [blame] | 9289 | ExprResult AssocExpr = |
| 9290 | getDerived().TransformExpr(Assoc.getAssociationExpr()); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9291 | if (AssocExpr.isInvalid()) |
| 9292 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9293 | AssocExprs.push_back(AssocExpr.get()); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9294 | } |
| 9295 | |
| 9296 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 9297 | E->getDefaultLoc(), |
| 9298 | E->getRParenLoc(), |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9299 | ControllingExpr.get(), |
| Dmitri Gribenko | 8236037 | 2013-05-10 13:06:58 +0000 | [diff] [blame] | 9300 | AssocTypes, |
| 9301 | AssocExprs); |
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 9302 | } |
| 9303 | |
| 9304 | template<typename Derived> |
| 9305 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9306 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9307 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9308 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9309 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9310 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9311 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9312 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9313 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9314 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9315 | E->getRParen()); |
| 9316 | } |
| 9317 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9318 | /// 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] | 9319 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 9320 | /// object available. |
| 9321 | template<typename Derived> |
| 9322 | ExprResult |
| 9323 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 9324 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9325 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 9326 | else |
| 9327 | return getDerived().TransformExpr(E); |
| 9328 | } |
| 9329 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9330 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9331 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9332 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| Richard Smith | eebe125f | 2013-05-21 23:29:46 +0000 | [diff] [blame] | 9333 | ExprResult SubExpr; |
| 9334 | if (E->getOpcode() == UO_AddrOf) |
| 9335 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 9336 | else |
| 9337 | SubExpr = TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9338 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9339 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9340 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9341 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9342 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9343 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9344 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 9345 | E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9346 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9347 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9348 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9349 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9350 | ExprResult |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9351 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 9352 | // Transform the type. |
| 9353 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 9354 | if (!Type) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9355 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9356 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9357 | // Transform all of the components into components similar to what the |
| 9358 | // parser uses. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9359 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 9360 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 9361 | // the fields again. However, __builtin_offsetof is rare enough in |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9362 | // template code that we don't care. |
| 9363 | bool ExprChanged = false; |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9364 | typedef Sema::OffsetOfComponent Component; |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 9365 | SmallVector<Component, 4> Components; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9366 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9367 | const OffsetOfNode &ON = E->getComponent(I); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9368 | Component Comp; |
| Douglas Gregor | 0be628f | 2010-04-30 20:35:01 +0000 | [diff] [blame] | 9369 | Comp.isBrackets = true; |
| Abramo Bagnara | 6b6f051 | 2011-03-12 09:45:03 +0000 | [diff] [blame] | 9370 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 9371 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9372 | switch (ON.getKind()) { |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9373 | case OffsetOfNode::Array: { |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9374 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9375 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9376 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9377 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9378 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9379 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 9380 | Comp.isBrackets = true; |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9381 | Comp.U.E = Index.get(); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9382 | break; |
| 9383 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9384 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9385 | case OffsetOfNode::Field: |
| 9386 | case OffsetOfNode::Identifier: |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9387 | Comp.isBrackets = false; |
| 9388 | Comp.U.IdentInfo = ON.getFieldName(); |
| Douglas Gregor | ea679ec | 2010-04-28 22:43:14 +0000 | [diff] [blame] | 9389 | if (!Comp.U.IdentInfo) |
| 9390 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9391 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9392 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9393 | |
| James Y Knight | 7281c35 | 2015-12-29 22:31:18 +0000 | [diff] [blame] | 9394 | case OffsetOfNode::Base: |
| Douglas Gregor | d170206 | 2010-04-29 00:18:15 +0000 | [diff] [blame] | 9395 | // Will be recomputed during the rebuild. |
| 9396 | continue; |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9397 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9398 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9399 | Components.push_back(Comp); |
| 9400 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9401 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9402 | // If nothing changed, retain the existing expression. |
| 9403 | if (!getDerived().AlwaysRebuild() && |
| 9404 | Type == E->getTypeSourceInfo() && |
| 9405 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9406 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9407 | |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9408 | // Build a new offsetof expression. |
| 9409 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| Craig Topper | b551824 | 2015-10-22 04:59:59 +0000 | [diff] [blame] | 9410 | Components, E->getRParenLoc()); |
| Douglas Gregor | 882211c | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 9411 | } |
| 9412 | |
| 9413 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9414 | ExprResult |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9415 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| Hubert Tong | 2cded44 | 2015-09-01 22:50:31 +0000 | [diff] [blame] | 9416 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9417 | "opaque value expression requires transformation"); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9418 | return E; |
| John McCall | 8d69a21 | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 9419 | } |
| 9420 | |
| 9421 | template<typename Derived> |
| 9422 | ExprResult |
| Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 9423 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 9424 | return E; |
| 9425 | } |
| 9426 | |
| 9427 | template<typename Derived> |
| 9428 | ExprResult |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9429 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
| John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 9430 | // Rebuild the syntactic form. The original syntactic form has |
| 9431 | // opaque-value expressions in it, so strip those away and rebuild |
| 9432 | // the result. This is a really awful way of doing this, but the |
| 9433 | // better solution (rebuilding the semantic expressions and |
| 9434 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 9435 | // TreeTransform to not strip away implicit conversions. |
| 9436 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 9437 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9438 | if (result.isInvalid()) return ExprError(); |
| 9439 | |
| 9440 | // If that gives us a pseudo-object result back, the pseudo-object |
| 9441 | // expression must have been an lvalue-to-rvalue conversion which we |
| 9442 | // should reapply. |
| 9443 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9444 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
| John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 9445 | |
| 9446 | return result; |
| 9447 | } |
| 9448 | |
| 9449 | template<typename Derived> |
| 9450 | ExprResult |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9451 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 9452 | UnaryExprOrTypeTraitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9453 | if (E->isArgumentType()) { |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9454 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9455 | |
| John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 9456 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9457 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9458 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9459 | |
| John McCall | 4c98fd8 | 2009-11-04 07:28:41 +0000 | [diff] [blame] | 9460 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9461 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9462 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9463 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 9464 | E->getKind(), |
| 9465 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9466 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9467 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9468 | // C++0x [expr.sizeof]p1: |
| 9469 | // The operand is either an expression, which is an unevaluated operand |
| 9470 | // [...] |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 9471 | EnterExpressionEvaluationContext Unevaluated( |
| 9472 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 9473 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9474 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 9475 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 9476 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 9477 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 9478 | ExprResult SubExpr; |
| 9479 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 9480 | if (auto *DRE = |
| 9481 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 9482 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 9483 | PE, DRE, false, &RecoveryTSI); |
| 9484 | else |
| 9485 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 9486 | |
| 9487 | if (RecoveryTSI) { |
| 9488 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 9489 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 9490 | } else if (SubExpr.isInvalid()) |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9491 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9492 | |
| Eli Friedman | e4f22df | 2012-02-29 04:03:55 +0000 | [diff] [blame] | 9493 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9494 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9495 | |
| Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 9496 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 9497 | E->getOperatorLoc(), |
| 9498 | E->getKind(), |
| 9499 | E->getSourceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9500 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9501 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9502 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9503 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9504 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9505 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9506 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9507 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9508 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9509 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9510 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9511 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9512 | |
| 9513 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9514 | if (!getDerived().AlwaysRebuild() && |
| 9515 | LHS.get() == E->getLHS() && |
| 9516 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9517 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9518 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9519 | return getDerived().RebuildArraySubscriptExpr( |
| 9520 | LHS.get(), |
| 9521 | /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9522 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9523 | |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9524 | template <typename Derived> |
| 9525 | ExprResult |
| 9526 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 9527 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 9528 | if (Base.isInvalid()) |
| 9529 | return ExprError(); |
| 9530 | |
| 9531 | ExprResult LowerBound; |
| 9532 | if (E->getLowerBound()) { |
| 9533 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 9534 | if (LowerBound.isInvalid()) |
| 9535 | return ExprError(); |
| 9536 | } |
| 9537 | |
| 9538 | ExprResult Length; |
| 9539 | if (E->getLength()) { |
| 9540 | Length = getDerived().TransformExpr(E->getLength()); |
| 9541 | if (Length.isInvalid()) |
| 9542 | return ExprError(); |
| 9543 | } |
| 9544 | |
| 9545 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 9546 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 9547 | return E; |
| 9548 | |
| 9549 | return getDerived().RebuildOMPArraySectionExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9550 | Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(), |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 9551 | Length.get(), E->getRBracketLoc()); |
| 9552 | } |
| 9553 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9554 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9555 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9556 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9557 | // Transform the callee. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9558 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9559 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9560 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9561 | |
| 9562 | // Transform arguments. |
| 9563 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9564 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9565 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9566 | &ArgChanged)) |
| 9567 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9568 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9569 | if (!getDerived().AlwaysRebuild() && |
| 9570 | Callee.get() == E->getCallee() && |
| 9571 | !ArgChanged) |
| Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 9572 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9573 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9574 | // FIXME: Wrong source location information for the '('. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9575 | SourceLocation FakeLParenLoc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9576 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9577 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9578 | Args, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9579 | E->getRParenLoc()); |
| 9580 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9581 | |
| 9582 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9583 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9584 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9585 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9586 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9587 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9588 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9589 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9590 | if (E->hasQualifier()) { |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9591 | QualifierLoc |
| 9592 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9593 | |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9594 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9595 | return ExprError(); |
| Douglas Gregor | f405d7e | 2009-08-31 23:41:50 +0000 | [diff] [blame] | 9596 | } |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9597 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9598 | |
| Eli Friedman | 2cfcef6 | 2009-12-04 06:40:45 +0000 | [diff] [blame] | 9599 | ValueDecl *Member |
| Douglas Gregor | a04f2ca | 2010-03-01 15:56:25 +0000 | [diff] [blame] | 9600 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 9601 | E->getMemberDecl())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9602 | if (!Member) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9603 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9604 | |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9605 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 9606 | if (FoundDecl == E->getMemberDecl()) { |
| 9607 | FoundDecl = Member; |
| 9608 | } else { |
| 9609 | FoundDecl = cast_or_null<NamedDecl>( |
| 9610 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 9611 | if (!FoundDecl) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9612 | return ExprError(); |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9613 | } |
| 9614 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9615 | if (!getDerived().AlwaysRebuild() && |
| 9616 | Base.get() == E->getBase() && |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9617 | QualifierLoc == E->getQualifierLoc() && |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9618 | Member == E->getMemberDecl() && |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9619 | FoundDecl == E->getFoundDecl() && |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9620 | !E->hasExplicitTemplateArgs()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9621 | |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9622 | // Mark it referenced in the new context regardless. |
| 9623 | // FIXME: this is a bit instantiation-specific. |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 9624 | SemaRef.MarkMemberReferenced(E); |
| 9625 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9626 | return E; |
| Anders Carlsson | 9c45ad7 | 2009-12-22 05:24:09 +0000 | [diff] [blame] | 9627 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9628 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9629 | TemplateArgumentListInfo TransArgs; |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9630 | if (E->hasExplicitTemplateArgs()) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 9631 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9632 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 9633 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 9634 | E->getNumTemplateArgs(), |
| 9635 | TransArgs)) |
| 9636 | return ExprError(); |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9637 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9638 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9639 | // FIXME: Bogus source location for the operator |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9640 | SourceLocation FakeOperatorLoc = |
| 9641 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9642 | |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9643 | // FIXME: to do this check properly, we will need to preserve the |
| 9644 | // first-qualifier-in-scope here, just in case we had a dependent |
| 9645 | // base (and therefore couldn't do the check) and a |
| 9646 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9647 | NamedDecl *FirstQualifierInScope = nullptr; |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9648 | DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); |
| 9649 | if (MemberNameInfo.getName()) { |
| 9650 | MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); |
| 9651 | if (!MemberNameInfo.getName()) |
| 9652 | return ExprError(); |
| 9653 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9654 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9655 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9656 | E->isArrow(), |
| Douglas Gregor | ea972d3 | 2011-02-28 21:54:11 +0000 | [diff] [blame] | 9657 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 9658 | TemplateKWLoc, |
| Akira Hatanaka | 59e3b43 | 2017-01-31 19:53:32 +0000 | [diff] [blame] | 9659 | MemberNameInfo, |
| Douglas Gregor | b184f0d | 2009-11-04 23:20:05 +0000 | [diff] [blame] | 9660 | Member, |
| John McCall | 16df1e5 | 2010-03-30 21:47:33 +0000 | [diff] [blame] | 9661 | FoundDecl, |
| John McCall | b3774b5 | 2010-08-19 23:49:38 +0000 | [diff] [blame] | 9662 | (E->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9663 | ? &TransArgs : nullptr), |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 9664 | FirstQualifierInScope); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9665 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9666 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9667 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9668 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9669 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9670 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9671 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9672 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9673 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9674 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9675 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9676 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9677 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9678 | if (!getDerived().AlwaysRebuild() && |
| 9679 | LHS.get() == E->getLHS() && |
| 9680 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9681 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9682 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9683 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 9684 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 9685 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9686 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9687 | LHS.get(), RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9688 | } |
| 9689 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9690 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9691 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9692 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9693 | CompoundAssignOperator *E) { |
| 9694 | return getDerived().TransformBinaryOperator(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9695 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9696 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9697 | template<typename Derived> |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9698 | ExprResult TreeTransform<Derived>:: |
| 9699 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 9700 | // Just rebuild the common and RHS expressions and see whether we |
| 9701 | // get any changes. |
| 9702 | |
| 9703 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 9704 | if (commonExpr.isInvalid()) |
| 9705 | return ExprError(); |
| 9706 | |
| 9707 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 9708 | if (rhs.isInvalid()) |
| 9709 | return ExprError(); |
| 9710 | |
| 9711 | if (!getDerived().AlwaysRebuild() && |
| 9712 | commonExpr.get() == e->getCommon() && |
| 9713 | rhs.get() == e->getFalseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9714 | return e; |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9715 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9716 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9717 | e->getQuestionLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 9718 | nullptr, |
| John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 9719 | e->getColonLoc(), |
| 9720 | rhs.get()); |
| 9721 | } |
| 9722 | |
| 9723 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9724 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9725 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9726 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9727 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9728 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9729 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9730 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9731 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9732 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9733 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9734 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9735 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9736 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9737 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9738 | if (!getDerived().AlwaysRebuild() && |
| 9739 | Cond.get() == E->getCond() && |
| 9740 | LHS.get() == E->getLHS() && |
| 9741 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9742 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9743 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9744 | return getDerived().RebuildConditionalOperator(Cond.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9745 | E->getQuestionLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9746 | LHS.get(), |
| Douglas Gregor | 7e112b0 | 2009-08-26 14:37:04 +0000 | [diff] [blame] | 9747 | E->getColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9748 | RHS.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9749 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9750 | |
| 9751 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9752 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9753 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
| Douglas Gregor | 6131b44 | 2009-12-12 18:16:41 +0000 | [diff] [blame] | 9754 | // Implicit casts are eliminated during transformation, since they |
| 9755 | // will be recomputed by semantic analysis after transformation. |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9756 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9757 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9758 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9759 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9760 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9761 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9762 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 9763 | if (!Type) |
| 9764 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9765 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9766 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 9767 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9768 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9769 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9770 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9771 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9772 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9773 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9774 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9775 | |
| John McCall | 9751396 | 2010-01-15 18:39:57 +0000 | [diff] [blame] | 9776 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 9777 | Type, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9778 | E->getRParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9779 | SubExpr.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9780 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9781 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9782 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9783 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9784 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9785 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 9786 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 9787 | if (!NewT) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9788 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9789 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9790 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9791 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9792 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9793 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9794 | if (!getDerived().AlwaysRebuild() && |
| John McCall | e15bbff | 2010-01-18 19:35:47 +0000 | [diff] [blame] | 9795 | OldT == NewT && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9796 | Init.get() == E->getInitializer()) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 9797 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9798 | |
| John McCall | 5d7aa7f | 2010-01-19 22:33:45 +0000 | [diff] [blame] | 9799 | // Note: the expression type doesn't necessarily match the |
| 9800 | // type-as-written, but that's okay, because it should always be |
| 9801 | // derivable from the initializer. |
| 9802 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9803 | return getDerived().RebuildCompoundLiteralExpr( |
| 9804 | E->getLParenLoc(), NewT, |
| 9805 | /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9806 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9807 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9808 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9809 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9810 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9811 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9812 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9813 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9814 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9815 | if (!getDerived().AlwaysRebuild() && |
| 9816 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9817 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9818 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9819 | // FIXME: Bad source location |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 9820 | SourceLocation FakeOperatorLoc = |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9821 | SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9822 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9823 | E->getAccessorLoc(), |
| 9824 | E->getAccessor()); |
| 9825 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9826 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9827 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9828 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9829 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9830 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 9831 | E = Syntactic; |
| 9832 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9833 | bool InitChanged = false; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9834 | |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 9835 | EnterExpressionEvaluationContext Context( |
| 9836 | getSema(), EnterExpressionEvaluationContext::InitList); |
| 9837 | |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9838 | SmallVector<Expr*, 4> Inits; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9839 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 9840 | Inits, &InitChanged)) |
| 9841 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9842 | |
| Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 9843 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 9844 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 9845 | // in some cases. We can't reuse it in general, because the syntactic and |
| 9846 | // semantic forms are linked, and we can't know that semantic form will |
| 9847 | // match even if the syntactic form does. |
| 9848 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9849 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9850 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
| Richard Smith | d103612 | 2018-01-12 22:21:33 +0000 | [diff] [blame] | 9851 | E->getRBraceLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9852 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9853 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9854 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9855 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9856 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9857 | Designation Desig; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9858 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9859 | // transform the initializer value |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9860 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9861 | if (Init.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9862 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9863 | |
| Douglas Gregor | ebe1010 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 9864 | // transform the designators. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 9865 | SmallVector<Expr*, 4> ArrayExprs; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9866 | bool ExprChanged = false; |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9867 | for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 9868 | if (D.isFieldDesignator()) { |
| 9869 | Desig.AddDesignator(Designator::getField(D.getFieldName(), |
| 9870 | D.getDotLoc(), |
| 9871 | D.getFieldLoc())); |
| Alex Lorenz | cb642b9 | 2016-10-24 09:33:32 +0000 | [diff] [blame] | 9872 | if (D.getField()) { |
| 9873 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 9874 | getDerived().TransformDecl(D.getFieldLoc(), D.getField())); |
| 9875 | if (Field != D.getField()) |
| 9876 | // Rebuild the expression when the transformed FieldDecl is |
| 9877 | // different to the already assigned FieldDecl. |
| 9878 | ExprChanged = true; |
| 9879 | } else { |
| 9880 | // Ensure that the designator expression is rebuilt when there isn't |
| 9881 | // a resolved FieldDecl in the designator as we don't want to assign |
| 9882 | // a FieldDecl to a pattern designator that will be instantiated again. |
| 9883 | ExprChanged = true; |
| 9884 | } |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9885 | continue; |
| 9886 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9887 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9888 | if (D.isArrayDesignator()) { |
| 9889 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9890 | if (Index.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9891 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9892 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9893 | Desig.AddDesignator( |
| 9894 | Designator::getArray(Index.get(), D.getLBracketLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9895 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9896 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9897 | ArrayExprs.push_back(Index.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9898 | continue; |
| 9899 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9900 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9901 | assert(D.isArrayRangeDesignator() && "New kind of designator?"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9902 | ExprResult Start |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9903 | = getDerived().TransformExpr(E->getArrayRangeStart(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9904 | if (Start.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9905 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9906 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9907 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9908 | if (End.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 | |
| 9911 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9912 | End.get(), |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9913 | D.getLBracketLoc(), |
| 9914 | D.getEllipsisLoc())); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9915 | |
| David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 9916 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 9917 | End.get() != E->getArrayRangeEnd(D); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9918 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9919 | ArrayExprs.push_back(Start.get()); |
| 9920 | ArrayExprs.push_back(End.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9921 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9922 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9923 | if (!getDerived().AlwaysRebuild() && |
| 9924 | Init.get() == E->getInit() && |
| 9925 | !ExprChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9926 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9927 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 9928 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9929 | E->getEqualOrColonLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 9930 | E->usesGNUSyntax(), Init.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9931 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9932 | |
| Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 9933 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 9934 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 9935 | template<typename Derived> |
| 9936 | ExprResult |
| 9937 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 9938 | DesignatedInitUpdateExpr *E) { |
| 9939 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 9940 | "initializer"); |
| 9941 | return ExprError(); |
| 9942 | } |
| 9943 | |
| 9944 | template<typename Derived> |
| 9945 | ExprResult |
| 9946 | TreeTransform<Derived>::TransformNoInitExpr( |
| 9947 | NoInitExpr *E) { |
| 9948 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 9949 | return ExprError(); |
| 9950 | } |
| 9951 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9952 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9953 | ExprResult |
| Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 9954 | TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 9955 | llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); |
| 9956 | return ExprError(); |
| 9957 | } |
| 9958 | |
| 9959 | template<typename Derived> |
| 9960 | ExprResult |
| 9961 | TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 9962 | llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); |
| 9963 | return ExprError(); |
| 9964 | } |
| 9965 | |
| 9966 | template<typename Derived> |
| 9967 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9968 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9969 | ImplicitValueInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9970 | TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 9971 | |
| Douglas Gregor | 3da3c06 | 2009-10-28 00:29:27 +0000 | [diff] [blame] | 9972 | // FIXME: Will we ever have proper type location here? Will we actually |
| 9973 | // need to transform the type? |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9974 | QualType T = getDerived().TransformType(E->getType()); |
| 9975 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9976 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9977 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9978 | if (!getDerived().AlwaysRebuild() && |
| 9979 | T == E->getType()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9980 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9981 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9982 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 9983 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9984 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9985 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9986 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 9987 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| Douglas Gregor | 7058c26 | 2010-08-10 14:27:00 +0000 | [diff] [blame] | 9988 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 9989 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 9990 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9991 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 9992 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9993 | if (SubExpr.isInvalid()) |
| 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() && |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 9997 | TInfo == E->getWrittenTypeInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 9998 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9999 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10000 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10001 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
| Abramo Bagnara | 27db239 | 2010-08-10 10:06:15 +0000 | [diff] [blame] | 10002 | TInfo, E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10003 | } |
| 10004 | |
| 10005 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10006 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10007 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10008 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10009 | SmallVector<Expr*, 4> Inits; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10010 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 10011 | &ArgumentChanged)) |
| 10012 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10013 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10014 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10015 | Inits, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10016 | E->getRParenLoc()); |
| 10017 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10018 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10019 | /// Transform an address-of-label expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10020 | /// |
| 10021 | /// By default, the transformation of an address-of-label expression always |
| 10022 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 10023 | /// the corresponding label statement by semantic analysis. |
| 10024 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10025 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10026 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 10027 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 10028 | E->getLabel()); |
| 10029 | if (!LD) |
| 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().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 10033 | cast<LabelDecl>(LD)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10034 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10035 | |
| 10036 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10037 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10038 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10039 | SemaRef.ActOnStartStmtExpr(); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10040 | StmtResult SubStmt |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10041 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10042 | if (SubStmt.isInvalid()) { |
| 10043 | SemaRef.ActOnStmtExprError(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10044 | return ExprError(); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10045 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10046 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10047 | if (!getDerived().AlwaysRebuild() && |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10048 | SubStmt.get() == E->getSubStmt()) { |
| 10049 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 10050 | SemaRef.ActOnStmtExprError(); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10051 | return SemaRef.MaybeBindToTemporary(E); |
| John McCall | ed7b278 | 2012-04-06 18:20:53 +0000 | [diff] [blame] | 10052 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10053 | |
| 10054 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10055 | SubStmt.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10056 | E->getRParenLoc()); |
| 10057 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10058 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10059 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10060 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10061 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10062 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10063 | if (Cond.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10064 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10065 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10066 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10067 | if (LHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10068 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10069 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10070 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10071 | if (RHS.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10072 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10073 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10074 | if (!getDerived().AlwaysRebuild() && |
| 10075 | Cond.get() == E->getCond() && |
| 10076 | LHS.get() == E->getLHS() && |
| 10077 | RHS.get() == E->getRHS()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10078 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10079 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10080 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10081 | Cond.get(), LHS.get(), RHS.get(), |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10082 | E->getRParenLoc()); |
| 10083 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10084 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10085 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10086 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10087 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10088 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10089 | } |
| 10090 | |
| 10091 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10092 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10093 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10094 | switch (E->getOperator()) { |
| 10095 | case OO_New: |
| 10096 | case OO_Delete: |
| 10097 | case OO_Array_New: |
| 10098 | case OO_Array_Delete: |
| 10099 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10100 | |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10101 | case OO_Call: { |
| 10102 | // This is a call to an object's operator(). |
| 10103 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 10104 | |
| 10105 | // Transform the object itself. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10106 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10107 | if (Object.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10108 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10109 | |
| 10110 | // FIXME: Poor location information |
| Alp Toker | b6cc592 | 2014-05-03 03:45:55 +0000 | [diff] [blame] | 10111 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10112 | static_cast<Expr *>(Object.get())->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10113 | |
| 10114 | // Transform the call arguments. |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10115 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10116 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10117 | Args)) |
| 10118 | return ExprError(); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10119 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10120 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, |
| 10121 | E->getEndLoc()); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 10125 | case OO_##Name: |
| 10126 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 10127 | #include "clang/Basic/OperatorKinds.def" |
| 10128 | case OO_Subscript: |
| 10129 | // Handled below. |
| 10130 | break; |
| 10131 | |
| 10132 | case OO_Conditional: |
| 10133 | llvm_unreachable("conditional operator is not actually overloadable"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10134 | |
| 10135 | case OO_None: |
| 10136 | case NUM_OVERLOADED_OPERATORS: |
| 10137 | llvm_unreachable("not an overloaded operator?"); |
| Douglas Gregor | b08f1a7 | 2009-12-13 20:44:55 +0000 | [diff] [blame] | 10138 | } |
| 10139 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10140 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10141 | if (Callee.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10142 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10143 | |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 10144 | ExprResult First; |
| 10145 | if (E->getOperator() == OO_Amp) |
| 10146 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 10147 | else |
| 10148 | First = getDerived().TransformExpr(E->getArg(0)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10149 | if (First.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10150 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10151 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10152 | ExprResult Second; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10153 | if (E->getNumArgs() == 2) { |
| 10154 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 10155 | if (Second.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10156 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10157 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10158 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10159 | if (!getDerived().AlwaysRebuild() && |
| 10160 | Callee.get() == E->getCallee() && |
| 10161 | First.get() == E->getArg(0) && |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10162 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10163 | return SemaRef.MaybeBindToTemporary(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10164 | |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 10165 | Sema::FPContractStateRAII FPContractState(getSema()); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 10166 | getSema().FPFeatures = E->getFPFeatures(); |
| Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 10167 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10168 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 10169 | E->getOperatorLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10170 | Callee.get(), |
| 10171 | First.get(), |
| 10172 | Second.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10173 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10174 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10175 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10176 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10177 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 10178 | return getDerived().TransformCallExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10179 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10180 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10181 | template <typename Derived> |
| 10182 | ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { |
| 10183 | bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function && |
| 10184 | getSema().CurContext != E->getParentContext(); |
| 10185 | |
| 10186 | if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) |
| 10187 | return E; |
| 10188 | |
| 10189 | return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(), |
| 10190 | E->getEndLoc(), |
| 10191 | getSema().CurContext); |
| 10192 | } |
| 10193 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10194 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10195 | ExprResult |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10196 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 10197 | // Transform the callee. |
| 10198 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 10199 | if (Callee.isInvalid()) |
| 10200 | return ExprError(); |
| 10201 | |
| 10202 | // Transform exec config. |
| 10203 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 10204 | if (EC.isInvalid()) |
| 10205 | return ExprError(); |
| 10206 | |
| 10207 | // Transform arguments. |
| 10208 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10209 | SmallVector<Expr*, 8> Args; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10210 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10211 | &ArgChanged)) |
| 10212 | return ExprError(); |
| 10213 | |
| 10214 | if (!getDerived().AlwaysRebuild() && |
| 10215 | Callee.get() == E->getCallee() && |
| 10216 | !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 10217 | return SemaRef.MaybeBindToTemporary(E); |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10218 | |
| 10219 | // FIXME: Wrong source location information for the '('. |
| 10220 | SourceLocation FakeLParenLoc |
| 10221 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 10222 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 10223 | Args, |
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 10224 | E->getRParenLoc(), EC.get()); |
| 10225 | } |
| 10226 | |
| 10227 | template<typename Derived> |
| 10228 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10229 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10230 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 10231 | if (!Type) |
| 10232 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10233 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10234 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 10235 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10236 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10237 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10238 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10239 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10240 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10241 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10242 | return E; |
| Nico Weber | c153d24 | 2014-07-28 00:02:09 +0000 | [diff] [blame] | 10243 | return getDerived().RebuildCXXNamedCastExpr( |
| 10244 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 10245 | Type, E->getAngleBrackets().getEnd(), |
| 10246 | // FIXME. this should be '(' location |
| 10247 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10248 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10249 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10250 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10251 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10252 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 10253 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10254 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10255 | |
| 10256 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10257 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10258 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 10259 | return getDerived().TransformCXXNamedCastExpr(E); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10260 | } |
| 10261 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10262 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10263 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10264 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10265 | CXXReinterpretCastExpr *E) { |
| 10266 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10267 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10268 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10269 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10270 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10271 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 10272 | return getDerived().TransformCXXNamedCastExpr(E); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10273 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10274 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10275 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10276 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10277 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10278 | CXXFunctionalCastExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10279 | TypeSourceInfo *Type = |
| 10280 | getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10281 | if (!Type) |
| 10282 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10283 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10284 | ExprResult SubExpr |
| Douglas Gregor | d196a58 | 2009-12-14 19:27:10 +0000 | [diff] [blame] | 10285 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10286 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10287 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10288 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10289 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10290 | Type == E->getTypeInfoAsWritten() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10291 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10292 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10293 | |
| Douglas Gregor | 3b29b2c | 2010-09-09 16:55:46 +0000 | [diff] [blame] | 10294 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
| Eli Friedman | 89fe0d5 | 2013-08-15 22:02:56 +0000 | [diff] [blame] | 10295 | E->getLParenLoc(), |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10296 | SubExpr.get(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 10297 | E->getRParenLoc(), |
| 10298 | E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10299 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10300 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10301 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10302 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10303 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10304 | if (E->isTypeOperand()) { |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 10305 | TypeSourceInfo *TInfo |
| 10306 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 10307 | if (!TInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10308 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10309 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10310 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 9da6419 | 2010-04-26 22:37:10 +0000 | [diff] [blame] | 10311 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10312 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10313 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10314 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10315 | TInfo, E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10316 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10317 | |
| Eli Friedman | 456f018 | 2012-01-20 01:26:23 +0000 | [diff] [blame] | 10318 | // We don't know whether the subexpression is potentially evaluated until |
| 10319 | // after we perform semantic analysis. We speculatively assume it is |
| 10320 | // unevaluated; it will get fixed later if the subexpression is in fact |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10321 | // potentially evaluated. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10322 | EnterExpressionEvaluationContext Unevaluated( |
| 10323 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 10324 | Sema::ReuseLambdaContextDecl); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10325 | |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10326 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10327 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10328 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10329 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10330 | if (!getDerived().AlwaysRebuild() && |
| 10331 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10332 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10333 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10334 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10335 | SubExpr.get(), E->getEndLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10336 | } |
| 10337 | |
| 10338 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10339 | ExprResult |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10340 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 10341 | if (E->isTypeOperand()) { |
| 10342 | TypeSourceInfo *TInfo |
| 10343 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 10344 | if (!TInfo) |
| 10345 | return ExprError(); |
| 10346 | |
| 10347 | if (!getDerived().AlwaysRebuild() && |
| 10348 | TInfo == E->getTypeOperandSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10349 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10350 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10351 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10352 | TInfo, E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10353 | } |
| 10354 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10355 | EnterExpressionEvaluationContext Unevaluated( |
| 10356 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10357 | |
| 10358 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 10359 | if (SubExpr.isInvalid()) |
| 10360 | return ExprError(); |
| 10361 | |
| 10362 | if (!getDerived().AlwaysRebuild() && |
| 10363 | SubExpr.get() == E->getExprOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10364 | return E; |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10365 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10366 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10367 | SubExpr.get(), E->getEndLoc()); |
| Francois Pichet | 9f4f207 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 10368 | } |
| 10369 | |
| 10370 | template<typename Derived> |
| 10371 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10372 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10373 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10374 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10375 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10376 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10377 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10378 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10379 | CXXNullPtrLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10380 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10381 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10382 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10383 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10384 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10385 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| Richard Smith | c3d2ebb | 2013-06-07 02:33:37 +0000 | [diff] [blame] | 10386 | QualType T = getSema().getCurrentThisType(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10387 | |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10388 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| Richard Smith | 8458c9e | 2019-05-24 01:35:07 +0000 | [diff] [blame] | 10389 | // Mark it referenced in the new context regardless. |
| 10390 | // FIXME: this is a bit instantiation-specific. |
| 10391 | getSema().MarkThisReferenced(E); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10392 | return E; |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 10393 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10394 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10395 | return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10396 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10397 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10398 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10399 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10400 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10401 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10402 | if (SubExpr.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10403 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10404 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10405 | if (!getDerived().AlwaysRebuild() && |
| 10406 | SubExpr.get() == E->getSubExpr()) |
| 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 | |
| Douglas Gregor | 53e191ed | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 10409 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 10410 | E->isThrownVariableInScope()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10411 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10412 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10413 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10414 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10415 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10416 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 10417 | getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10418 | if (!Param) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10419 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10420 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10421 | if (!getDerived().AlwaysRebuild() && Param == E->getParam() && |
| 10422 | E->getUsedContext() == SemaRef.CurContext) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10423 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10424 | |
| Douglas Gregor | 033f675 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 10425 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10426 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10427 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10428 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10429 | ExprResult |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10430 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10431 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 10432 | getDerived().TransformDecl(E->getBeginLoc(), E->getField())); |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10433 | if (!Field) |
| 10434 | return ExprError(); |
| 10435 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 10436 | if (!getDerived().AlwaysRebuild() && Field == E->getField() && |
| 10437 | E->getUsedContext() == SemaRef.CurContext) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10438 | return E; |
| Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 10439 | |
| 10440 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 10441 | } |
| 10442 | |
| 10443 | template<typename Derived> |
| 10444 | ExprResult |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10445 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 10446 | CXXScalarValueInitExpr *E) { |
| 10447 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10448 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10449 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10450 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10451 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10452 | T == E->getTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10453 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10454 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10455 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 10456 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
| Douglas Gregor | 747eb78 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 10457 | E->getRParenLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10458 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10459 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10460 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10461 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10462 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10463 | // Transform the type that we're allocating |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 10464 | TypeSourceInfo *AllocTypeInfo = |
| 10465 | getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10466 | if (!AllocTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10467 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10468 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10469 | // Transform the size of the array we're allocating (if any). |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10470 | Optional<Expr *> ArraySize; |
| 10471 | if (Optional<Expr *> OldArraySize = E->getArraySize()) { |
| 10472 | ExprResult NewArraySize; |
| 10473 | if (*OldArraySize) { |
| 10474 | NewArraySize = getDerived().TransformExpr(*OldArraySize); |
| 10475 | if (NewArraySize.isInvalid()) |
| 10476 | return ExprError(); |
| 10477 | } |
| 10478 | ArraySize = NewArraySize.get(); |
| 10479 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10480 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10481 | // Transform the placement arguments (if any). |
| 10482 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 10483 | SmallVector<Expr*, 8> PlacementArgs; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10484 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 10485 | E->getNumPlacementArgs(), true, |
| 10486 | PlacementArgs, &ArgumentChanged)) |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10487 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10488 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10489 | // Transform the initializer (if any). |
| 10490 | Expr *OldInit = E->getInitializer(); |
| 10491 | ExprResult NewInit; |
| 10492 | if (OldInit) |
| Richard Smith | c6abd96 | 2014-07-25 01:12:44 +0000 | [diff] [blame] | 10493 | NewInit = getDerived().TransformInitializer(OldInit, true); |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10494 | if (NewInit.isInvalid()) |
| 10495 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10496 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10497 | // Transform new operator and delete operator. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10498 | FunctionDecl *OperatorNew = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10499 | if (E->getOperatorNew()) { |
| 10500 | OperatorNew = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10501 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10502 | if (!OperatorNew) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10503 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10504 | } |
| 10505 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10506 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10507 | if (E->getOperatorDelete()) { |
| 10508 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10509 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10510 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10511 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10512 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10513 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10514 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10515 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10516 | ArraySize == E->getArraySize() && |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10517 | NewInit.get() == OldInit && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10518 | OperatorNew == E->getOperatorNew() && |
| 10519 | OperatorDelete == E->getOperatorDelete() && |
| 10520 | !ArgumentChanged) { |
| 10521 | // Mark any declarations we need as referenced. |
| 10522 | // FIXME: instantiation-specific. |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10523 | if (OperatorNew) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10524 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10525 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10526 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10527 | |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10528 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10529 | QualType ElementType |
| 10530 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 10531 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 10532 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 10533 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10534 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); |
| Douglas Gregor | 72912fb | 2011-07-26 15:11:03 +0000 | [diff] [blame] | 10535 | } |
| 10536 | } |
| 10537 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10538 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10539 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10540 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10541 | |
| Douglas Gregor | 0744ef6 | 2010-09-07 21:49:58 +0000 | [diff] [blame] | 10542 | QualType AllocType = AllocTypeInfo->getType(); |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10543 | if (!ArraySize) { |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10544 | // If no array size was specified, but the new expression was |
| 10545 | // instantiated with an array type (e.g., "new T" where T is |
| 10546 | // instantiated with "int[4]"), extract the outer bound from the |
| 10547 | // array type as our array size. We do this with constant and |
| 10548 | // dependently-sized array types. |
| 10549 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 10550 | if (!ArrayT) { |
| 10551 | // Do nothing |
| 10552 | } else if (const ConstantArrayType *ConsArrayT |
| 10553 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10554 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 10555 | SemaRef.Context.getSizeType(), |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10556 | /*FIXME:*/ E->getBeginLoc()); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10557 | AllocType = ConsArrayT->getElementType(); |
| 10558 | } else if (const DependentSizedArrayType *DepArrayT |
| 10559 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 10560 | if (DepArrayT->getSizeExpr()) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10561 | ArraySize = DepArrayT->getSizeExpr(); |
| Douglas Gregor | 2e9c795 | 2009-12-22 17:13:37 +0000 | [diff] [blame] | 10562 | AllocType = DepArrayT->getElementType(); |
| 10563 | } |
| 10564 | } |
| 10565 | } |
| Sebastian Redl | 6047f07 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 10566 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10567 | return getDerived().RebuildCXXNewExpr( |
| 10568 | E->getBeginLoc(), E->isGlobalNew(), |
| 10569 | /*FIXME:*/ E->getBeginLoc(), PlacementArgs, |
| 10570 | /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 10571 | AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10572 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10573 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10574 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10575 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10576 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10577 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10578 | if (Operand.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10579 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10580 | |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10581 | // Transform the delete operator, if known. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10582 | FunctionDecl *OperatorDelete = nullptr; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10583 | if (E->getOperatorDelete()) { |
| 10584 | OperatorDelete = cast_or_null<FunctionDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10585 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10586 | if (!OperatorDelete) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10587 | return ExprError(); |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10588 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10589 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10590 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10591 | Operand.get() == E->getArgument() && |
| 10592 | OperatorDelete == E->getOperatorDelete()) { |
| 10593 | // Mark any declarations we need as referenced. |
| 10594 | // FIXME: instantiation-specific. |
| 10595 | if (OperatorDelete) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10596 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10597 | |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10598 | if (!E->getArgument()->isTypeDependent()) { |
| 10599 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 10600 | E->getDestroyedType()); |
| 10601 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 10602 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10603 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| Eli Friedman | fa0df83 | 2012-02-02 03:46:19 +0000 | [diff] [blame] | 10604 | SemaRef.LookupDestructor(Record)); |
| Douglas Gregor | 6ed2fee | 2010-09-14 22:55:20 +0000 | [diff] [blame] | 10605 | } |
| 10606 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10607 | |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10608 | return E; |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 10609 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10610 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10611 | return getDerived().RebuildCXXDeleteExpr( |
| 10612 | E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10613 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10614 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10615 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10616 | ExprResult |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10617 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10618 | CXXPseudoDestructorExpr *E) { |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10619 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10620 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10621 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10622 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10623 | ParsedType ObjectTypePtr; |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10624 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10625 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10626 | E->getOperatorLoc(), |
| 10627 | E->isArrow()? tok::arrow : tok::period, |
| 10628 | ObjectTypePtr, |
| 10629 | MayBePseudoDestructor); |
| 10630 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10631 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10632 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10633 | QualType ObjectType = ObjectTypePtr.get(); |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10634 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 10635 | if (QualifierLoc) { |
| 10636 | QualifierLoc |
| 10637 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 10638 | if (!QualifierLoc) |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10639 | return ExprError(); |
| 10640 | } |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10641 | CXXScopeSpec SS; |
| 10642 | SS.Adopt(QualifierLoc); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10643 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10644 | PseudoDestructorTypeStorage Destroyed; |
| 10645 | if (E->getDestroyedTypeInfo()) { |
| 10646 | TypeSourceInfo *DestroyedTypeInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 10647 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10648 | ObjectType, nullptr, SS); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10649 | if (!DestroyedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10650 | return ExprError(); |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10651 | Destroyed = DestroyedTypeInfo; |
| Douglas Gregor | f39a8dd | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 10652 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10653 | // We aren't likely to be able to resolve the identifier down to a type |
| 10654 | // now anyway, so just retain the identifier. |
| 10655 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 10656 | E->getDestroyedTypeLoc()); |
| 10657 | } else { |
| 10658 | // Look for a destructor known with the given name. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 10659 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10660 | *E->getDestroyedTypeIdentifier(), |
| 10661 | E->getDestroyedTypeLoc(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10662 | /*Scope=*/nullptr, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10663 | SS, ObjectTypePtr, |
| 10664 | false); |
| 10665 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10666 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10667 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10668 | Destroyed |
| 10669 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 10670 | E->getDestroyedTypeLoc()); |
| 10671 | } |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10672 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10673 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10674 | if (E->getScopeTypeInfo()) { |
| Douglas Gregor | a88c55b | 2013-03-08 21:25:01 +0000 | [diff] [blame] | 10675 | CXXScopeSpec EmptySS; |
| 10676 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 10677 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10678 | if (!ScopeTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10679 | return ExprError(); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10680 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10681 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 10682 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10683 | E->getOperatorLoc(), |
| 10684 | E->isArrow(), |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 10685 | SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 10686 | ScopeTypeInfo, |
| 10687 | E->getColonColonLoc(), |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 10688 | E->getTildeLoc(), |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 10689 | Destroyed); |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10690 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10691 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10692 | template <typename Derived> |
| 10693 | bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, |
| 10694 | bool RequiresADL, |
| 10695 | LookupResult &R) { |
| 10696 | // Transform all the decls. |
| 10697 | bool AllEmptyPacks = true; |
| 10698 | for (auto *OldD : Old->decls()) { |
| 10699 | Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); |
| 10700 | if (!InstD) { |
| 10701 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 10702 | // This can happen because of dependent hiding. |
| 10703 | if (isa<UsingShadowDecl>(OldD)) |
| 10704 | continue; |
| 10705 | else { |
| 10706 | R.clear(); |
| 10707 | return true; |
| 10708 | } |
| 10709 | } |
| 10710 | |
| 10711 | // Expand using pack declarations. |
| 10712 | NamedDecl *SingleDecl = cast<NamedDecl>(InstD); |
| 10713 | ArrayRef<NamedDecl*> Decls = SingleDecl; |
| 10714 | if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) |
| 10715 | Decls = UPD->expansions(); |
| 10716 | |
| 10717 | // Expand using declarations. |
| 10718 | for (auto *D : Decls) { |
| 10719 | if (auto *UD = dyn_cast<UsingDecl>(D)) { |
| 10720 | for (auto *SD : UD->shadows()) |
| 10721 | R.addDecl(SD); |
| 10722 | } else { |
| 10723 | R.addDecl(D); |
| 10724 | } |
| 10725 | } |
| 10726 | |
| 10727 | AllEmptyPacks &= Decls.empty(); |
| 10728 | }; |
| 10729 | |
| 10730 | // C++ [temp.res]/8.4.2: |
| 10731 | // The program is ill-formed, no diagnostic required, if [...] lookup for |
| 10732 | // a name in the template definition found a using-declaration, but the |
| 10733 | // lookup in the corresponding scope in the instantiation odoes not find |
| 10734 | // any declarations because the using-declaration was a pack expansion and |
| 10735 | // the corresponding pack is empty |
| 10736 | if (AllEmptyPacks && !RequiresADL) { |
| 10737 | getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) |
| Richard Trieu | b402580 | 2018-03-28 04:16:13 +0000 | [diff] [blame] | 10738 | << isa<UnresolvedMemberExpr>(Old) << Old->getName(); |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10739 | return true; |
| 10740 | } |
| 10741 | |
| 10742 | // Resolve a kind, but don't do any further analysis. If it's |
| 10743 | // ambiguous, the callee needs to deal with it. |
| 10744 | R.resolveKind(); |
| 10745 | return false; |
| 10746 | } |
| 10747 | |
| Douglas Gregor | ad8a336 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 10748 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10749 | ExprResult |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 10750 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 10751 | UnresolvedLookupExpr *Old) { |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10752 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 10753 | Sema::LookupOrdinaryName); |
| 10754 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 10755 | // Transform the declaration set. |
| 10756 | if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) |
| 10757 | return ExprError(); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10758 | |
| 10759 | // Rebuild the nested-name qualifier, if present. |
| 10760 | CXXScopeSpec SS; |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10761 | if (Old->getQualifierLoc()) { |
| 10762 | NestedNameSpecifierLoc QualifierLoc |
| 10763 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 10764 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10765 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10766 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 10767 | SS.Adopt(QualifierLoc); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10768 | } |
| 10769 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 10770 | if (Old->getNamingClass()) { |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10771 | CXXRecordDecl *NamingClass |
| 10772 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 10773 | Old->getNameLoc(), |
| 10774 | Old->getNamingClass())); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10775 | if (!NamingClass) { |
| 10776 | R.clear(); |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 10777 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10778 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10779 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 10780 | R.setNamingClass(NamingClass); |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10781 | } |
| 10782 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10783 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 10784 | |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10785 | // If we have neither explicit template arguments, nor the template keyword, |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10786 | // it's a normal declaration name or member reference. |
| 10787 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 10788 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 10789 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 10790 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 10791 | // give a good diagnostic. |
| 10792 | if (D && D->isCXXInstanceMember()) { |
| 10793 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 10794 | /*TemplateArgs=*/nullptr, |
| 10795 | /*Scope=*/nullptr); |
| 10796 | } |
| 10797 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10798 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 10799 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10800 | |
| 10801 | // If we have template arguments, rebuild them, then rebuild the |
| 10802 | // templateid expression. |
| 10803 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| Rafael Espindola | 3dd531d | 2012-08-28 04:13:54 +0000 | [diff] [blame] | 10804 | if (Old->hasExplicitTemplateArgs() && |
| 10805 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10806 | Old->getNumTemplateArgs(), |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10807 | TransArgs)) { |
| 10808 | R.clear(); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 10809 | return ExprError(); |
| Serge Pavlov | 8260530 | 2013-09-04 04:50:29 +0000 | [diff] [blame] | 10810 | } |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 10811 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 10812 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
| Abramo Bagnara | 65f7c3d | 2012-02-06 14:31:00 +0000 | [diff] [blame] | 10813 | Old->requiresADL(), &TransArgs); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10814 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10815 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 10816 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 10817 | ExprResult |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10818 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 10819 | bool ArgChanged = false; |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 10820 | SmallVector<TypeSourceInfo *, 4> Args; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10821 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 10822 | TypeSourceInfo *From = E->getArg(I); |
| 10823 | TypeLoc FromTL = From->getTypeLoc(); |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10824 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10825 | TypeLocBuilder TLB; |
| 10826 | TLB.reserve(FromTL.getFullDataSize()); |
| 10827 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 10828 | if (To.isNull()) |
| 10829 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10830 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10831 | if (To == From->getType()) |
| 10832 | Args.push_back(From); |
| 10833 | else { |
| 10834 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10835 | ArgChanged = true; |
| 10836 | } |
| 10837 | continue; |
| 10838 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10839 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10840 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10841 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10842 | // We have a pack expansion. Instantiate it. |
| David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 10843 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10844 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 10845 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 10846 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10847 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10848 | // Determine whether the set of unexpanded parameter packs can and should |
| 10849 | // be expanded. |
| 10850 | bool Expand = true; |
| 10851 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 10852 | Optional<unsigned> OrigNumExpansions = |
| 10853 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 10854 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10855 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 10856 | PatternTL.getSourceRange(), |
| 10857 | Unexpanded, |
| 10858 | Expand, RetainExpansion, |
| 10859 | NumExpansions)) |
| 10860 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10861 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10862 | if (!Expand) { |
| 10863 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10864 | // transformation on the pack expansion, producing another pack |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10865 | // expansion. |
| 10866 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10867 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10868 | TypeLocBuilder TLB; |
| 10869 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 10870 | |
| 10871 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10872 | if (To.isNull()) |
| 10873 | return ExprError(); |
| 10874 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10875 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10876 | PatternTL.getSourceRange(), |
| 10877 | ExpansionTL.getEllipsisLoc(), |
| 10878 | NumExpansions); |
| 10879 | if (To.isNull()) |
| 10880 | return ExprError(); |
| 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 | PackExpansionTypeLoc ToExpansionTL |
| 10883 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10884 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10885 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10886 | continue; |
| 10887 | } |
| 10888 | |
| 10889 | // Expand the pack expansion by substituting for each argument in the |
| 10890 | // pack(s). |
| 10891 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 10892 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 10893 | TypeLocBuilder TLB; |
| 10894 | TLB.reserve(PatternTL.getFullDataSize()); |
| 10895 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10896 | if (To.isNull()) |
| 10897 | return ExprError(); |
| 10898 | |
| Eli Friedman | 5e05c4a | 2013-07-19 21:49:32 +0000 | [diff] [blame] | 10899 | if (To->containsUnexpandedParameterPack()) { |
| 10900 | To = getDerived().RebuildPackExpansionType(To, |
| 10901 | PatternTL.getSourceRange(), |
| 10902 | ExpansionTL.getEllipsisLoc(), |
| 10903 | NumExpansions); |
| 10904 | if (To.isNull()) |
| 10905 | return ExprError(); |
| 10906 | |
| 10907 | PackExpansionTypeLoc ToExpansionTL |
| 10908 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10909 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10910 | } |
| 10911 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10912 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10913 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10914 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10915 | if (!RetainExpansion) |
| 10916 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10917 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10918 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 10919 | // forgetting the partially-substituted parameter pack. |
| 10920 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 10921 | |
| 10922 | TypeLocBuilder TLB; |
| 10923 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10924 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10925 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 10926 | if (To.isNull()) |
| 10927 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10928 | |
| 10929 | To = getDerived().RebuildPackExpansionType(To, |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10930 | PatternTL.getSourceRange(), |
| 10931 | ExpansionTL.getEllipsisLoc(), |
| 10932 | NumExpansions); |
| 10933 | if (To.isNull()) |
| 10934 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10935 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10936 | PackExpansionTypeLoc ToExpansionTL |
| 10937 | = TLB.push<PackExpansionTypeLoc>(To); |
| 10938 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 10939 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 10940 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 10941 | |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10942 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10943 | return E; |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10944 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10945 | return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10946 | E->getEndLoc()); |
| Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 10947 | } |
| 10948 | |
| 10949 | template<typename Derived> |
| 10950 | ExprResult |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10951 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 10952 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 10953 | if (!T) |
| 10954 | return ExprError(); |
| 10955 | |
| 10956 | if (!getDerived().AlwaysRebuild() && |
| 10957 | T == E->getQueriedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10958 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10959 | |
| 10960 | ExprResult SubExpr; |
| 10961 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10962 | EnterExpressionEvaluationContext Unevaluated( |
| 10963 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10964 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 10965 | if (SubExpr.isInvalid()) |
| 10966 | return ExprError(); |
| 10967 | |
| 10968 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10969 | return E; |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10970 | } |
| 10971 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10972 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10973 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 10974 | } |
| 10975 | |
| 10976 | template<typename Derived> |
| 10977 | ExprResult |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10978 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 10979 | ExprResult SubExpr; |
| 10980 | { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10981 | EnterExpressionEvaluationContext Unevaluated( |
| 10982 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10983 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 10984 | if (SubExpr.isInvalid()) |
| 10985 | return ExprError(); |
| 10986 | |
| 10987 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 10988 | return E; |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10989 | } |
| 10990 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10991 | return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 10992 | SubExpr.get(), E->getEndLoc()); |
| John Wiegley | f9f6584 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 10993 | } |
| 10994 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 10995 | template <typename Derived> |
| 10996 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 10997 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 10998 | TypeSourceInfo **RecoveryTSI) { |
| 10999 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 11000 | DRE, AddrTaken, RecoveryTSI); |
| 11001 | |
| 11002 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 11003 | if (!NewDRE.isUsable()) |
| 11004 | return NewDRE; |
| 11005 | |
| 11006 | // We got an expr, wrap it up in parens. |
| 11007 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 11008 | return PE; |
| 11009 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 11010 | PE->getRParen()); |
| 11011 | } |
| 11012 | |
| 11013 | template <typename Derived> |
| 11014 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 11015 | DependentScopeDeclRefExpr *E) { |
| 11016 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 11017 | nullptr); |
| Richard Smith | db2630f | 2012-10-21 03:28:35 +0000 | [diff] [blame] | 11018 | } |
| 11019 | |
| 11020 | template<typename Derived> |
| 11021 | ExprResult |
| 11022 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 11023 | DependentScopeDeclRefExpr *E, |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11024 | bool IsAddressOfOperand, |
| 11025 | TypeSourceInfo **RecoveryTSI) { |
| Reid Kleckner | 916ac4d | 2013-10-15 18:38:02 +0000 | [diff] [blame] | 11026 | assert(E->getQualifierLoc()); |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 11027 | NestedNameSpecifierLoc QualifierLoc |
| 11028 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 11029 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11030 | return ExprError(); |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11031 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11032 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11033 | // TODO: If this is a conversion-function-id, verify that the |
| 11034 | // destination type name (if present) resolves the same way after |
| 11035 | // instantiation as it did in the local scope. |
| 11036 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11037 | DeclarationNameInfo NameInfo |
| 11038 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 11039 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11040 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11041 | |
| John McCall | e66edc1 | 2009-11-24 19:00:30 +0000 | [diff] [blame] | 11042 | if (!E->hasExplicitTemplateArgs()) { |
| 11043 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 3a43fd6 | 2011-02-25 20:49:16 +0000 | [diff] [blame] | 11044 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11045 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 11046 | // if name has not changed, DNLoc has not changed either. |
| 11047 | NameInfo.getName() == E->getDeclName()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11048 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11049 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11050 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 11051 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 11052 | IsAddressOfOperand, RecoveryTSI); |
| Douglas Gregor | d019ff6 | 2009-10-22 17:20:55 +0000 | [diff] [blame] | 11053 | } |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11054 | |
| 11055 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11056 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 11057 | E->getNumTemplateArgs(), |
| 11058 | TransArgs)) |
| 11059 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11060 | |
| Reid Kleckner | 32506ed | 2014-06-12 23:03:48 +0000 | [diff] [blame] | 11061 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 11062 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 11063 | RecoveryTSI); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11064 | } |
| 11065 | |
| 11066 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11067 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11068 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 11069 | // CXXConstructExprs other than for list-initialization and |
| 11070 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 11071 | // a 1-argument construction we just transform that argument. |
| Richard Smith | dd2ca57 | 2012-11-26 08:32:48 +0000 | [diff] [blame] | 11072 | if ((E->getNumArgs() == 1 || |
| 11073 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| Richard Smith | d59b832 | 2012-12-19 01:39:02 +0000 | [diff] [blame] | 11074 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 11075 | !E->isListInitialization()) |
| Douglas Gregor | db56b91 | 2010-02-03 03:01:57 +0000 | [diff] [blame] | 11076 | return getDerived().TransformExpr(E->getArg(0)); |
| 11077 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11078 | TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11079 | |
| 11080 | QualType T = getDerived().TransformType(E->getType()); |
| 11081 | if (T.isNull()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11082 | return ExprError(); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11083 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11084 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 11085 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11086 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11087 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11088 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11089 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11090 | SmallVector<Expr*, 8> Args; |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11091 | { |
| 11092 | EnterExpressionEvaluationContext Context( |
| 11093 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11094 | E->isListInitialization()); |
| 11095 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 11096 | &ArgumentChanged)) |
| 11097 | return ExprError(); |
| 11098 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11099 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11100 | if (!getDerived().AlwaysRebuild() && |
| 11101 | T == E->getType() && |
| 11102 | Constructor == E->getConstructor() && |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 11103 | !ArgumentChanged) { |
| Douglas Gregor | d2d9da0 | 2010-02-26 00:38:10 +0000 | [diff] [blame] | 11104 | // Mark the constructor as referenced. |
| 11105 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11106 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11107 | return E; |
| Douglas Gregor | de55035 | 2010-02-26 00:01:57 +0000 | [diff] [blame] | 11108 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11109 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11110 | return getDerived().RebuildCXXConstructExpr( |
| 11111 | T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, |
| 11112 | E->hadMultipleCandidates(), E->isListInitialization(), |
| 11113 | E->isStdInitListInitialization(), E->requiresZeroInitialization(), |
| 11114 | E->getConstructionKind(), E->getParenOrBraceRange()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11115 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11116 | |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11117 | template<typename Derived> |
| 11118 | ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 11119 | CXXInheritedCtorInitExpr *E) { |
| 11120 | QualType T = getDerived().TransformType(E->getType()); |
| 11121 | if (T.isNull()) |
| 11122 | return ExprError(); |
| 11123 | |
| 11124 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11125 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11126 | if (!Constructor) |
| 11127 | return ExprError(); |
| 11128 | |
| 11129 | if (!getDerived().AlwaysRebuild() && |
| 11130 | T == E->getType() && |
| 11131 | Constructor == E->getConstructor()) { |
| 11132 | // Mark the constructor as referenced. |
| 11133 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11134 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 11135 | return E; |
| 11136 | } |
| 11137 | |
| 11138 | return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 11139 | T, E->getLocation(), Constructor, |
| 11140 | E->constructsVBase(), E->inheritedFromVBase()); |
| 11141 | } |
| 11142 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11143 | /// Transform a C++ temporary-binding expression. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11144 | /// |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11145 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 11146 | /// transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11147 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11148 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11149 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11150 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11151 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11152 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11153 | /// Transform a C++ expression that contains cleanups that should |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11154 | /// be run after the expression is evaluated. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11155 | /// |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11156 | /// Since ExprWithCleanups nodes are implicitly generated, we |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11157 | /// just transform the subexpression and return that. |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11158 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11159 | ExprResult |
| John McCall | 5d41378 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 11160 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
| Douglas Gregor | 363b151 | 2009-12-24 18:51:59 +0000 | [diff] [blame] | 11161 | return getDerived().TransformExpr(E->getSubExpr()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11162 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11163 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11164 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11165 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11166 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11167 | CXXTemporaryObjectExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 11168 | TypeSourceInfo *T = |
| 11169 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11170 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11171 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11172 | |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11173 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 11174 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11175 | if (!Constructor) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11176 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11177 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11178 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11179 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11180 | Args.reserve(E->getNumArgs()); |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11181 | { |
| 11182 | EnterExpressionEvaluationContext Context( |
| 11183 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11184 | E->isListInitialization()); |
| 11185 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 11186 | &ArgumentChanged)) |
| 11187 | return ExprError(); |
| 11188 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11189 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11190 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11191 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11192 | Constructor == E->getConstructor() && |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 11193 | !ArgumentChanged) { |
| 11194 | // FIXME: Instantiation-specific |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11195 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| John McCall | c3007a2 | 2010-10-26 07:05:15 +0000 | [diff] [blame] | 11196 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | 9bc6b7f | 2010-03-02 17:18:33 +0000 | [diff] [blame] | 11197 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11198 | |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11199 | // FIXME: We should just pass E->isListInitialization(), but we're not |
| 11200 | // prepared to handle list-initialization without a child InitListExpr. |
| 11201 | SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); |
| 11202 | return getDerived().RebuildCXXTemporaryObjectExpr( |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11203 | T, LParenLoc, Args, E->getEndLoc(), |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11204 | /*ListInitialization=*/LParenLoc.isInvalid()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11205 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11206 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11207 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11208 | ExprResult |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11209 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11210 | // Transform any init-capture expressions before entering the scope of the |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11211 | // lambda body, because they are not semantically within that scope. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11212 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11213 | struct TransformedInitCapture { |
| 11214 | // The location of the ... if the result is retaining a pack expansion. |
| 11215 | SourceLocation EllipsisLoc; |
| 11216 | // Zero or more expansions of the init-capture. |
| 11217 | SmallVector<InitCaptureInfoTy, 4> Expansions; |
| 11218 | }; |
| 11219 | SmallVector<TransformedInitCapture, 4> InitCaptures; |
| 11220 | InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11221 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11222 | CEnd = E->capture_end(); |
| 11223 | C != CEnd; ++C) { |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 11224 | if (!E->isInitCapture(C)) |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11225 | continue; |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11226 | |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11227 | TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11228 | VarDecl *OldVD = C->getCapturedVar(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11229 | |
| 11230 | auto SubstInitCapture = [&](SourceLocation EllipsisLoc, |
| 11231 | Optional<unsigned> NumExpansions) { |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11232 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 11233 | OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); |
| 11234 | |
| 11235 | if (NewExprInitResult.isInvalid()) { |
| 11236 | Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); |
| 11237 | return; |
| 11238 | } |
| 11239 | Expr *NewExprInit = NewExprInitResult.get(); |
| 11240 | |
| 11241 | QualType NewInitCaptureType = |
| 11242 | getSema().buildLambdaInitCaptureInitialization( |
| 11243 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 11244 | EllipsisLoc, NumExpansions, OldVD->getIdentifier(), |
| 11245 | C->getCapturedVar()->getInitStyle() != VarDecl::CInit, |
| 11246 | NewExprInit); |
| 11247 | Result.Expansions.push_back( |
| 11248 | InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); |
| 11249 | }; |
| 11250 | |
| 11251 | // If this is an init-capture pack, consider expanding the pack now. |
| 11252 | if (OldVD->isParameterPack()) { |
| 11253 | PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() |
| 11254 | ->getTypeLoc() |
| 11255 | .castAs<PackExpansionTypeLoc>(); |
| 11256 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11257 | SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); |
| 11258 | |
| 11259 | // Determine whether the set of unexpanded parameter packs can and should |
| 11260 | // be expanded. |
| 11261 | bool Expand = true; |
| 11262 | bool RetainExpansion = false; |
| 11263 | Optional<unsigned> OrigNumExpansions = |
| 11264 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 11265 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 11266 | if (getDerived().TryExpandParameterPacks( |
| 11267 | ExpansionTL.getEllipsisLoc(), |
| 11268 | OldVD->getInit()->getSourceRange(), Unexpanded, Expand, |
| 11269 | RetainExpansion, NumExpansions)) |
| 11270 | return ExprError(); |
| 11271 | if (Expand) { |
| 11272 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11273 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11274 | SubstInitCapture(SourceLocation(), None); |
| 11275 | } |
| 11276 | } |
| 11277 | if (!Expand || RetainExpansion) { |
| 11278 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 11279 | SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); |
| 11280 | Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); |
| 11281 | } |
| 11282 | } else { |
| 11283 | SubstInitCapture(SourceLocation(), None); |
| 11284 | } |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11285 | } |
| 11286 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11287 | // Transform the template parameters, and add them to the current |
| 11288 | // instantiation scope. The null case is handled correctly. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11289 | auto TPL = getDerived().TransformTemplateParameterList( |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11290 | E->getTemplateParameterList()); |
| 11291 | |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11292 | // Transform the type of the original lambda's call operator. |
| 11293 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 11294 | // it introduces a mapping of the original to the newly created |
| 11295 | // transformed parameters. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11296 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11297 | { |
| 11298 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 11299 | FunctionProtoTypeLoc OldCallOpFPTL = |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11300 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11301 | |
| 11302 | TypeLocBuilder NewCallOpTLBuilder; |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11303 | SmallVector<QualType, 4> ExceptionStorage; |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 11304 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11305 | QualType NewCallOpType = TransformFunctionProtoType( |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 11306 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(), |
| Richard Smith | 775118a | 2014-11-12 02:09:03 +0000 | [diff] [blame] | 11307 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 11308 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 11309 | ExceptionStorage, Changed); |
| Richard Smith | 2e32155 | 2014-11-12 02:00:47 +0000 | [diff] [blame] | 11310 | }); |
| Reid Kleckner | aac43c6 | 2014-12-15 21:07:16 +0000 | [diff] [blame] | 11311 | if (NewCallOpType.isNull()) |
| 11312 | return ExprError(); |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11313 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 11314 | NewCallOpType); |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 11315 | } |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11316 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11317 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 11318 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 11319 | LSI->GLTemplateParameterList = TPL; |
| 11320 | |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11321 | // Create the local class that will describe the lambda. |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11322 | CXXRecordDecl *OldClass = E->getLambdaClass(); |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11323 | CXXRecordDecl *Class |
| 11324 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11325 | NewCallOpTSI, |
| Faisal Vali | c1a6dc4 | 2013-10-23 16:10:50 +0000 | [diff] [blame] | 11326 | /*KnownDependent=*/false, |
| 11327 | E->getCaptureDefault()); |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11328 | getDerived().transformedLocalDecl(OldClass, {Class}); |
| 11329 | |
| 11330 | Optional<std::pair<unsigned, Decl*>> Mangling; |
| 11331 | if (getDerived().ReplacingOriginal()) |
| 11332 | Mangling = std::make_pair(OldClass->getLambdaManglingNumber(), |
| 11333 | OldClass->getLambdaContextDecl()); |
| Eli Friedman | d564afb | 2012-09-19 01:18:11 +0000 | [diff] [blame] | 11334 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11335 | // Build the call operator. |
| Richard Smith | 01014ce | 2014-11-20 23:53:14 +0000 | [diff] [blame] | 11336 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 11337 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11338 | E->getCallOperator()->getEndLoc(), |
| Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 11339 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 11340 | E->getCallOperator()->getConstexprKind(), Mangling); |
| Faisal Vali | a734ab9 | 2016-03-26 16:11:37 +0000 | [diff] [blame] | 11341 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11342 | LSI->CallOperator = NewCallOperator; |
| Rafael Espindola | 4b35f27 | 2013-10-04 14:28:51 +0000 | [diff] [blame] | 11343 | |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 11344 | for (unsigned I = 0, NumParams = NewCallOperator->getNumParams(); |
| 11345 | I != NumParams; ++I) { |
| 11346 | auto *P = NewCallOperator->getParamDecl(I); |
| 11347 | if (P->hasUninstantiatedDefaultArg()) { |
| 11348 | EnterExpressionEvaluationContext Eval( |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11349 | getSema(), |
| 11350 | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P); |
| Akira Hatanaka | 40281846 | 2016-12-16 21:16:57 +0000 | [diff] [blame] | 11351 | ExprResult R = getDerived().TransformExpr( |
| 11352 | E->getCallOperator()->getParamDecl(I)->getDefaultArg()); |
| 11353 | P->setDefaultArg(R.get()); |
| 11354 | } |
| 11355 | } |
| 11356 | |
| Faisal Vali | 2cba133 | 2013-10-23 06:44:28 +0000 | [diff] [blame] | 11357 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11358 | getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11359 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11360 | // Introduce the context of the call operator. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11361 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
| Richard Smith | 7ff2bcb | 2014-01-24 01:54:52 +0000 | [diff] [blame] | 11362 | /*NewThisContext*/false); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11363 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11364 | // Enter the scope of the lambda. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11365 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 11366 | E->getIntroducerRange(), |
| 11367 | E->getCaptureDefault(), |
| 11368 | E->getCaptureDefaultLoc(), |
| 11369 | E->hasExplicitParameters(), |
| 11370 | E->hasExplicitResultType(), |
| 11371 | E->isMutable()); |
| 11372 | |
| 11373 | bool Invalid = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11374 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11375 | // Transform captures. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11376 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11377 | CEnd = E->capture_end(); |
| 11378 | C != CEnd; ++C) { |
| 11379 | // When we hit the first implicit capture, tell Sema that we've finished |
| 11380 | // the list of explicit captures. |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11381 | if (C->isImplicit()) |
| 11382 | break; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11383 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11384 | // Capturing 'this' is trivial. |
| 11385 | if (C->capturesThis()) { |
| Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 11386 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 11387 | /*BuildAndDiagnose*/ true, nullptr, |
| 11388 | C->getCaptureKind() == LCK_StarThis); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11389 | continue; |
| 11390 | } |
| Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 11391 | // Captured expression will be recaptured during captured variables |
| 11392 | // rebuilding. |
| 11393 | if (C->capturesVLAType()) |
| 11394 | continue; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11395 | |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11396 | // Rebuild init-captures, including the implied field declaration. |
| James Dennett | dd2ffea2 | 2015-05-07 18:48:18 +0000 | [diff] [blame] | 11397 | if (E->isInitCapture(C)) { |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11398 | TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; |
| 11399 | |
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 11400 | VarDecl *OldVD = C->getCapturedVar(); |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11401 | llvm::SmallVector<Decl*, 4> NewVDs; |
| 11402 | |
| 11403 | for (InitCaptureInfoTy &Info : NewC.Expansions) { |
| 11404 | ExprResult Init = Info.first; |
| 11405 | QualType InitQualType = Info.second; |
| 11406 | if (Init.isInvalid() || InitQualType.isNull()) { |
| 11407 | Invalid = true; |
| 11408 | break; |
| 11409 | } |
| 11410 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 11411 | OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, |
| 11412 | OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get()); |
| 11413 | if (!NewVD) { |
| 11414 | Invalid = true; |
| 11415 | break; |
| 11416 | } |
| 11417 | NewVDs.push_back(NewVD); |
| Richard Smith | 3011653 | 2019-05-28 23:09:46 +0000 | [diff] [blame] | 11418 | getSema().addInitCapture(LSI, NewVD); |
| Faisal Vali | 5fb7c3c | 2013-12-05 01:40:41 +0000 | [diff] [blame] | 11419 | } |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 11420 | |
| 11421 | if (Invalid) |
| 11422 | break; |
| 11423 | |
| 11424 | getDerived().transformedLocalDecl(OldVD, NewVDs); |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11425 | continue; |
| 11426 | } |
| 11427 | |
| 11428 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 11429 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11430 | // Determine the capture kind for Sema. |
| 11431 | Sema::TryCaptureKind Kind |
| 11432 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 11433 | : C->getCaptureKind() == LCK_ByCopy |
| 11434 | ? Sema::TryCapture_ExplicitByVal |
| 11435 | : Sema::TryCapture_ExplicitByRef; |
| 11436 | SourceLocation EllipsisLoc; |
| 11437 | if (C->isPackExpansion()) { |
| 11438 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 11439 | bool ShouldExpand = false; |
| 11440 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 11441 | Optional<unsigned> NumExpansions; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11442 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 11443 | C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11444 | Unexpanded, |
| 11445 | ShouldExpand, RetainExpansion, |
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 11446 | NumExpansions)) { |
| 11447 | Invalid = true; |
| 11448 | continue; |
| 11449 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11450 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11451 | if (ShouldExpand) { |
| 11452 | // The transform has determined that we should perform an expansion; |
| 11453 | // transform and capture each of the arguments. |
| 11454 | // expansion of the pattern. Do so. |
| 11455 | VarDecl *Pack = C->getCapturedVar(); |
| 11456 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11457 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 11458 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11459 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11460 | Pack)); |
| 11461 | if (!CapturedVar) { |
| 11462 | Invalid = true; |
| 11463 | continue; |
| 11464 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11465 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11466 | // Capture the transformed variable. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11467 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 11468 | } |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 11469 | |
| 11470 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 11471 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11472 | continue; |
| 11473 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11474 | |
| Douglas Gregor | 3e308b1 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 11475 | EllipsisLoc = C->getEllipsisLoc(); |
| 11476 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11477 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11478 | // Transform the captured variable. |
| 11479 | VarDecl *CapturedVar |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11480 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11481 | C->getCapturedVar())); |
| Richard Trieu | b292604 | 2014-09-02 19:32:44 +0000 | [diff] [blame] | 11482 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11483 | Invalid = true; |
| 11484 | continue; |
| 11485 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11486 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11487 | // Capture the transformed variable. |
| Meador Inge | 4f9dee7 | 2015-06-26 00:09:55 +0000 | [diff] [blame] | 11488 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 11489 | EllipsisLoc); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11490 | } |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11491 | getSema().finishLambdaExplicitCaptures(LSI); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11492 | |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11493 | // FIXME: Sema's lambda-building mechanism expects us to push an expression |
| 11494 | // evaluation context even if we're not transforming the function body. |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11495 | getSema().PushExpressionEvaluationContext( |
| 11496 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11497 | |
| Douglas Gregor | 0c46b2b | 2012-02-13 22:00:16 +0000 | [diff] [blame] | 11498 | // Instantiate the body of the lambda expression. |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11499 | StmtResult Body = |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11500 | Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody()); |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11501 | |
| 11502 | // ActOnLambda* will pop the function scope for us. |
| 11503 | FuncScopeCleanup.disable(); |
| 11504 | |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11505 | if (Body.isInvalid()) { |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11506 | SavedContext.pop(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11507 | getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11508 | /*IsInstantiation=*/true); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11509 | return ExprError(); |
| Douglas Gregor | b432823 | 2012-02-14 00:00:48 +0000 | [diff] [blame] | 11510 | } |
| Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 11511 | |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11512 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 11513 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 11514 | // the call operator. |
| 11515 | auto LSICopy = *LSI; |
| 11516 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 11517 | /*IsInstantiation*/ true); |
| 11518 | SavedContext.pop(); |
| 11519 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 11520 | return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), |
| Richard Smith | c38498f | 2015-04-27 21:27:54 +0000 | [diff] [blame] | 11521 | &LSICopy); |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11522 | } |
| 11523 | |
| 11524 | template<typename Derived> |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11525 | StmtResult |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11526 | TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { |
| Richard Smith | 87346a1 | 2019-06-02 18:53:44 +0000 | [diff] [blame] | 11527 | return TransformStmt(S); |
| 11528 | } |
| 11529 | |
| 11530 | template<typename Derived> |
| Richard Smith | 7bf8f6f | 2019-06-04 17:17:20 +0000 | [diff] [blame] | 11531 | StmtResult |
| 11532 | TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { |
| 11533 | // Transform captures. |
| 11534 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 11535 | CEnd = E->capture_end(); |
| 11536 | C != CEnd; ++C) { |
| 11537 | // When we hit the first implicit capture, tell Sema that we've finished |
| 11538 | // the list of explicit captures. |
| 11539 | if (!C->isImplicit()) |
| 11540 | continue; |
| 11541 | |
| 11542 | // Capturing 'this' is trivial. |
| 11543 | if (C->capturesThis()) { |
| 11544 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 11545 | /*BuildAndDiagnose*/ true, nullptr, |
| 11546 | C->getCaptureKind() == LCK_StarThis); |
| 11547 | continue; |
| 11548 | } |
| 11549 | // Captured expression will be recaptured during captured variables |
| 11550 | // rebuilding. |
| 11551 | if (C->capturesVLAType()) |
| 11552 | continue; |
| 11553 | |
| 11554 | assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 11555 | assert(!E->isInitCapture(C) && "implicit init-capture?"); |
| 11556 | |
| 11557 | // Transform the captured variable. |
| 11558 | VarDecl *CapturedVar = cast_or_null<VarDecl>( |
| 11559 | getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); |
| 11560 | if (!CapturedVar || CapturedVar->isInvalidDecl()) |
| 11561 | return StmtError(); |
| 11562 | |
| 11563 | // Capture the transformed variable. |
| 11564 | getSema().tryCaptureVariable(CapturedVar, C->getLocation()); |
| 11565 | } |
| 11566 | |
| 11567 | return S; |
| 11568 | } |
| 11569 | |
| 11570 | template<typename Derived> |
| Douglas Gregor | e31e606 | 2012-02-07 10:09:13 +0000 | [diff] [blame] | 11571 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11572 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11573 | CXXUnresolvedConstructExpr *E) { |
| Richard Smith | ee57984 | 2017-01-30 20:39:26 +0000 | [diff] [blame] | 11574 | TypeSourceInfo *T = |
| 11575 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11576 | if (!T) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11577 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11578 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11579 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 11580 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 11581 | Args.reserve(E->arg_size()); |
| Richard Smith | 12938cf | 2018-09-26 04:36:55 +0000 | [diff] [blame] | 11582 | { |
| 11583 | EnterExpressionEvaluationContext Context( |
| 11584 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 11585 | E->isListInitialization()); |
| 11586 | if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, |
| 11587 | &ArgumentChanged)) |
| 11588 | return ExprError(); |
| 11589 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11590 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11591 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | 2b88c11 | 2010-09-08 00:15:04 +0000 | [diff] [blame] | 11592 | T == E->getTypeSourceInfo() && |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11593 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11594 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11595 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11596 | // FIXME: we're faking the locations of the commas |
| Vedant Kumar | a14a1f9 | 2018-01-17 18:53:51 +0000 | [diff] [blame] | 11597 | return getDerived().RebuildCXXUnresolvedConstructExpr( |
| 11598 | T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11599 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11600 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11601 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11602 | ExprResult |
| John McCall | 8cd7813 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 11603 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11604 | CXXDependentScopeMemberExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11605 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11606 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11607 | Expr *OldBase; |
| 11608 | QualType BaseType; |
| 11609 | QualType ObjectType; |
| 11610 | if (!E->isImplicitAccess()) { |
| 11611 | OldBase = E->getBase(); |
| 11612 | Base = getDerived().TransformExpr(OldBase); |
| 11613 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11614 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11615 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11616 | // Start the member reference and compute the object's type. |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11617 | ParsedType ObjectTy; |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11618 | bool MayBePseudoDestructor = false; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11619 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11620 | E->getOperatorLoc(), |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11621 | E->isArrow()? tok::arrow : tok::period, |
| Douglas Gregor | e610ada | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 11622 | ObjectTy, |
| 11623 | MayBePseudoDestructor); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11624 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11625 | return ExprError(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11626 | |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 11627 | ObjectType = ObjectTy.get(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11628 | BaseType = ((Expr*) Base.get())->getType(); |
| 11629 | } else { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11630 | OldBase = nullptr; |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11631 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 11632 | ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 11633 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11634 | |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11635 | // Transform the first part of the nested-name-specifier that qualifies |
| 11636 | // the member name. |
| Douglas Gregor | 2b6ca46 | 2009-09-03 21:38:09 +0000 | [diff] [blame] | 11637 | NamedDecl *FirstQualifierInScope |
| Douglas Gregor | a5cb6da | 2009-10-20 05:58:46 +0000 | [diff] [blame] | 11638 | = getDerived().TransformFirstQualifierInScope( |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11639 | E->getFirstQualifierFoundInScope(), |
| 11640 | E->getQualifierLoc().getBeginLoc()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11641 | |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11642 | NestedNameSpecifierLoc QualifierLoc; |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11643 | if (E->getQualifier()) { |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11644 | QualifierLoc |
| 11645 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 11646 | ObjectType, |
| 11647 | FirstQualifierInScope); |
| 11648 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11649 | return ExprError(); |
| Douglas Gregor | c26e0f6 | 2009-09-03 16:14:30 +0000 | [diff] [blame] | 11650 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11651 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11652 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 11653 | |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11654 | // TODO: If this is a conversion-function-id, verify that the |
| 11655 | // destination type name (if present) resolves the same way after |
| 11656 | // instantiation as it did in the local scope. |
| 11657 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11658 | DeclarationNameInfo NameInfo |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 11659 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11660 | if (!NameInfo.getName()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11661 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11662 | |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11663 | if (!E->hasExplicitTemplateArgs()) { |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11664 | // This is a reference to a member without an explicitly-specified |
| 11665 | // template argument list. Optimize for this common case. |
| 11666 | if (!getDerived().AlwaysRebuild() && |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11667 | Base.get() == OldBase && |
| 11668 | BaseType == E->getBaseType() && |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11669 | QualifierLoc == E->getQualifierLoc() && |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11670 | NameInfo.getName() == E->getMember() && |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11671 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11672 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11673 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11674 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11675 | BaseType, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11676 | E->isArrow(), |
| 11677 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11678 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11679 | TemplateKWLoc, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11680 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11681 | NameInfo, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11682 | /*TemplateArgs*/nullptr); |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11683 | } |
| 11684 | |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 11685 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11686 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 11687 | E->getNumTemplateArgs(), |
| 11688 | TransArgs)) |
| 11689 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 11690 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11691 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11692 | BaseType, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11693 | E->isArrow(), |
| 11694 | E->getOperatorLoc(), |
| Douglas Gregor | e16af53 | 2011-02-28 18:50:33 +0000 | [diff] [blame] | 11695 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11696 | TemplateKWLoc, |
| Douglas Gregor | 308047d | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 11697 | FirstQualifierInScope, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11698 | NameInfo, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11699 | &TransArgs); |
| 11700 | } |
| 11701 | |
| 11702 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11703 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 11704 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11705 | // Transform the base of the expression. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11706 | ExprResult Base((Expr*) nullptr); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11707 | QualType BaseType; |
| 11708 | if (!Old->isImplicitAccess()) { |
| 11709 | Base = getDerived().TransformExpr(Old->getBase()); |
| 11710 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11711 | return ExprError(); |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11712 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
| Richard Smith | cab9a7d | 2011-10-26 19:06:56 +0000 | [diff] [blame] | 11713 | Old->isArrow()); |
| 11714 | if (Base.isInvalid()) |
| 11715 | return ExprError(); |
| 11716 | BaseType = Base.get()->getType(); |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11717 | } else { |
| 11718 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 11719 | } |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11720 | |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11721 | NestedNameSpecifierLoc QualifierLoc; |
| 11722 | if (Old->getQualifierLoc()) { |
| 11723 | QualifierLoc |
| 11724 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 11725 | if (!QualifierLoc) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11726 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11727 | } |
| 11728 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11729 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 11730 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 11731 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11732 | Sema::LookupOrdinaryName); |
| 11733 | |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 11734 | // Transform the declaration set. |
| 11735 | if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R)) |
| 11736 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11737 | |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11738 | // Determine the naming class. |
| Chandler Carruth | eba788e | 2010-05-19 01:37:01 +0000 | [diff] [blame] | 11739 | if (Old->getNamingClass()) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11740 | CXXRecordDecl *NamingClass |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11741 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11742 | Old->getMemberLoc(), |
| 11743 | Old->getNamingClass())); |
| 11744 | if (!NamingClass) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 11745 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11746 | |
| Douglas Gregor | da7be08 | 2010-04-27 16:10:10 +0000 | [diff] [blame] | 11747 | R.setNamingClass(NamingClass); |
| Douglas Gregor | 9262f47 | 2010-04-27 18:19:34 +0000 | [diff] [blame] | 11748 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11749 | |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11750 | TemplateArgumentListInfo TransArgs; |
| 11751 | if (Old->hasExplicitTemplateArgs()) { |
| 11752 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 11753 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| Douglas Gregor | 62e06f2 | 2010-12-20 17:31:10 +0000 | [diff] [blame] | 11754 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 11755 | Old->getNumTemplateArgs(), |
| 11756 | TransArgs)) |
| 11757 | return ExprError(); |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11758 | } |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11759 | |
| 11760 | // FIXME: to do this check properly, we will need to preserve the |
| 11761 | // first-qualifier-in-scope here, just in case we had a dependent |
| 11762 | // base (and therefore couldn't do the check) and a |
| 11763 | // nested-name-qualifier (and therefore could do the lookup). |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11764 | NamedDecl *FirstQualifierInScope = nullptr; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11765 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 11766 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
| John McCall | 2d74de9 | 2009-12-01 22:10:20 +0000 | [diff] [blame] | 11767 | BaseType, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11768 | Old->getOperatorLoc(), |
| 11769 | Old->isArrow(), |
| Douglas Gregor | 0da1d43 | 2011-02-28 20:01:57 +0000 | [diff] [blame] | 11770 | QualifierLoc, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 11771 | TemplateKWLoc, |
| John McCall | 38836f0 | 2010-01-15 08:34:02 +0000 | [diff] [blame] | 11772 | FirstQualifierInScope, |
| John McCall | 10eae18 | 2009-11-30 22:42:35 +0000 | [diff] [blame] | 11773 | R, |
| 11774 | (Old->hasExplicitTemplateArgs() |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 11775 | ? &TransArgs : nullptr)); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 11776 | } |
| 11777 | |
| 11778 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 11779 | ExprResult |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11780 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11781 | EnterExpressionEvaluationContext Unevaluated( |
| 11782 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11783 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 11784 | if (SubExpr.isInvalid()) |
| 11785 | return ExprError(); |
| 11786 | |
| 11787 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11788 | return E; |
| Sebastian Redl | 4202c0f | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 11789 | |
| 11790 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 11791 | } |
| 11792 | |
| 11793 | template<typename Derived> |
| 11794 | ExprResult |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11795 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11796 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 11797 | if (Pattern.isInvalid()) |
| 11798 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11799 | |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11800 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11801 | return E; |
| Douglas Gregor | 0f836ea | 2011-01-13 00:19:55 +0000 | [diff] [blame] | 11802 | |
| Douglas Gregor | b884000 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 11803 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 11804 | E->getNumExpansions()); |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11805 | } |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11806 | |
| 11807 | template<typename Derived> |
| 11808 | ExprResult |
| 11809 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 11810 | // If E is not value-dependent, then nothing will change when we transform it. |
| 11811 | // Note: This is an instantiation-centric view. |
| 11812 | if (!E->isValueDependent()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11813 | return E; |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11814 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11815 | EnterExpressionEvaluationContext Unevaluated( |
| 11816 | getSema(), Sema::ExpressionEvaluationContext::Unevaluated); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11817 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11818 | ArrayRef<TemplateArgument> PackArgs; |
| 11819 | TemplateArgument ArgStorage; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11820 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11821 | // Find the argument list to transform. |
| 11822 | if (E->isPartiallySubstituted()) { |
| 11823 | PackArgs = E->getPartialArguments(); |
| 11824 | } else if (E->isValueDependent()) { |
| 11825 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 11826 | bool ShouldExpand = false; |
| 11827 | bool RetainExpansion = false; |
| 11828 | Optional<unsigned> NumExpansions; |
| 11829 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 11830 | Unexpanded, |
| 11831 | ShouldExpand, RetainExpansion, |
| 11832 | NumExpansions)) |
| 11833 | return ExprError(); |
| 11834 | |
| 11835 | // If we need to expand the pack, build a template argument from it and |
| 11836 | // expand that. |
| 11837 | if (ShouldExpand) { |
| 11838 | auto *Pack = E->getPack(); |
| 11839 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 11840 | ArgStorage = getSema().Context.getPackExpansionType( |
| 11841 | getSema().Context.getTypeDeclType(TTPD), None); |
| 11842 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 11843 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 11844 | } else { |
| 11845 | auto *VD = cast<ValueDecl>(Pack); |
| Richard Smith | f1f20e6 | 2018-02-14 02:07:53 +0000 | [diff] [blame] | 11846 | ExprResult DRE = getSema().BuildDeclRefExpr( |
| 11847 | VD, VD->getType().getNonLValueExprType(getSema().Context), |
| 11848 | VD->getType()->isReferenceType() ? VK_LValue : VK_RValue, |
| 11849 | E->getPackLoc()); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11850 | if (DRE.isInvalid()) |
| 11851 | return ExprError(); |
| 11852 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 11853 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 11854 | } |
| 11855 | PackArgs = ArgStorage; |
| 11856 | } |
| 11857 | } |
| 11858 | |
| 11859 | // If we're not expanding the pack, just transform the decl. |
| 11860 | if (!PackArgs.size()) { |
| 11861 | auto *Pack = cast_or_null<NamedDecl>( |
| 11862 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11863 | if (!Pack) |
| 11864 | return ExprError(); |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11865 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 11866 | E->getPackLoc(), |
| 11867 | E->getRParenLoc(), None, None); |
| 11868 | } |
| 11869 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11870 | // Try to compute the result without performing a partial substitution. |
| 11871 | Optional<unsigned> Result = 0; |
| 11872 | for (const TemplateArgument &Arg : PackArgs) { |
| 11873 | if (!Arg.isPackExpansion()) { |
| 11874 | Result = *Result + 1; |
| 11875 | continue; |
| 11876 | } |
| 11877 | |
| 11878 | TemplateArgumentLoc ArgLoc; |
| 11879 | InventTemplateArgumentLoc(Arg, ArgLoc); |
| 11880 | |
| 11881 | // Find the pattern of the pack expansion. |
| 11882 | SourceLocation Ellipsis; |
| 11883 | Optional<unsigned> OrigNumExpansions; |
| 11884 | TemplateArgumentLoc Pattern = |
| 11885 | getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, |
| 11886 | OrigNumExpansions); |
| 11887 | |
| 11888 | // Substitute under the pack expansion. Do not expand the pack (yet). |
| 11889 | TemplateArgumentLoc OutPattern; |
| 11890 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11891 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, |
| 11892 | /*Uneval*/ true)) |
| 11893 | return true; |
| 11894 | |
| 11895 | // See if we can determine the number of arguments from the result. |
| 11896 | Optional<unsigned> NumExpansions = |
| 11897 | getSema().getFullyPackExpandedSize(OutPattern.getArgument()); |
| 11898 | if (!NumExpansions) { |
| 11899 | // No: we must be in an alias template expansion, and we're going to need |
| 11900 | // to actually expand the packs. |
| 11901 | Result = None; |
| 11902 | break; |
| 11903 | } |
| 11904 | |
| 11905 | Result = *Result + *NumExpansions; |
| 11906 | } |
| 11907 | |
| 11908 | // Common case: we could determine the number of expansions without |
| 11909 | // substituting. |
| 11910 | if (Result) |
| 11911 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11912 | E->getPackLoc(), |
| 11913 | E->getRParenLoc(), *Result, None); |
| 11914 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11915 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 11916 | E->getPackLoc()); |
| 11917 | { |
| 11918 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 11919 | typedef TemplateArgumentLocInventIterator< |
| 11920 | Derived, const TemplateArgument*> PackLocIterator; |
| 11921 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 11922 | PackLocIterator(*this, PackArgs.end()), |
| 11923 | TransformedPackArgs, /*Uneval*/true)) |
| 11924 | return ExprError(); |
| Douglas Gregor | ab96bcf | 2011-10-10 18:59:29 +0000 | [diff] [blame] | 11925 | } |
| 11926 | |
| Richard Smith | c5452ed | 2016-10-19 22:18:42 +0000 | [diff] [blame] | 11927 | // Check whether we managed to fully-expand the pack. |
| 11928 | // 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] | 11929 | SmallVector<TemplateArgument, 8> Args; |
| 11930 | bool PartialSubstitution = false; |
| 11931 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 11932 | Args.push_back(Loc.getArgument()); |
| 11933 | if (Loc.getArgument().isPackExpansion()) |
| 11934 | PartialSubstitution = true; |
| 11935 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11936 | |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11937 | if (PartialSubstitution) |
| 11938 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 11939 | E->getPackLoc(), |
| 11940 | E->getRParenLoc(), None, Args); |
| 11941 | |
| 11942 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11943 | E->getPackLoc(), E->getRParenLoc(), |
| Richard Smith | d784e68 | 2015-09-23 21:41:42 +0000 | [diff] [blame] | 11944 | Args.size(), None); |
| Douglas Gregor | 820ba7b | 2011-01-04 17:33:58 +0000 | [diff] [blame] | 11945 | } |
| 11946 | |
| Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 11947 | template<typename Derived> |
| 11948 | ExprResult |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11949 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 11950 | SubstNonTypeTemplateParmPackExpr *E) { |
| 11951 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11952 | return E; |
| Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 11953 | } |
| 11954 | |
| 11955 | template<typename Derived> |
| 11956 | ExprResult |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11957 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 11958 | SubstNonTypeTemplateParmExpr *E) { |
| 11959 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11960 | return E; |
| John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 11961 | } |
| 11962 | |
| 11963 | template<typename Derived> |
| 11964 | ExprResult |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 11965 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 11966 | // Default behavior is to do nothing with this transformation. |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 11967 | return E; |
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 11968 | } |
| 11969 | |
| 11970 | template<typename Derived> |
| 11971 | ExprResult |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 11972 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 11973 | MaterializeTemporaryExpr *E) { |
| 11974 | return getDerived().TransformExpr(E->GetTemporaryExpr()); |
| 11975 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 11976 | |
| Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 11977 | template<typename Derived> |
| 11978 | ExprResult |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11979 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 11980 | Expr *Pattern = E->getPattern(); |
| 11981 | |
| 11982 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11983 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 11984 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 11985 | |
| 11986 | // Determine whether the set of unexpanded parameter packs can and should |
| 11987 | // be expanded. |
| 11988 | bool Expand = true; |
| 11989 | bool RetainExpansion = false; |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 11990 | Optional<unsigned> OrigNumExpansions = E->getNumExpansions(), |
| 11991 | NumExpansions = OrigNumExpansions; |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 11992 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 11993 | Pattern->getSourceRange(), |
| 11994 | Unexpanded, |
| 11995 | Expand, RetainExpansion, |
| 11996 | NumExpansions)) |
| 11997 | return true; |
| 11998 | |
| 11999 | if (!Expand) { |
| 12000 | // Do not expand any packs here, just transform and rebuild a fold |
| 12001 | // expression. |
| 12002 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 12003 | |
| 12004 | ExprResult LHS = |
| 12005 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 12006 | if (LHS.isInvalid()) |
| 12007 | return true; |
| 12008 | |
| 12009 | ExprResult RHS = |
| 12010 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 12011 | if (RHS.isInvalid()) |
| 12012 | return true; |
| 12013 | |
| 12014 | if (!getDerived().AlwaysRebuild() && |
| 12015 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 12016 | return E; |
| 12017 | |
| 12018 | return getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12019 | E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12020 | RHS.get(), E->getEndLoc(), NumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12021 | } |
| 12022 | |
| 12023 | // The transform has determined that we should perform an elementwise |
| 12024 | // expansion of the pattern. Do so. |
| 12025 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 12026 | if (Result.isInvalid()) |
| 12027 | return true; |
| 12028 | bool LeftFold = E->isLeftFold(); |
| 12029 | |
| 12030 | // If we're retaining an expansion for a right fold, it is the innermost |
| 12031 | // component and takes the init (if any). |
| 12032 | if (!LeftFold && RetainExpansion) { |
| 12033 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 12034 | |
| 12035 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12036 | if (Out.isInvalid()) |
| 12037 | return true; |
| 12038 | |
| 12039 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12040 | E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12041 | Result.get(), E->getEndLoc(), OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12042 | if (Result.isInvalid()) |
| 12043 | return true; |
| 12044 | } |
| 12045 | |
| 12046 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12047 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 12048 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 12049 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12050 | if (Out.isInvalid()) |
| 12051 | return true; |
| 12052 | |
| 12053 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 12054 | // We still have a pack; retain a pack expansion for this slice. |
| 12055 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12056 | E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12057 | E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12058 | LeftFold ? Out.get() : Result.get(), E->getEndLoc(), |
| 12059 | OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12060 | } else if (Result.isUsable()) { |
| 12061 | // We've got down to a single element; build a binary operator. |
| 12062 | Result = getDerived().RebuildBinaryOperator( |
| 12063 | E->getEllipsisLoc(), E->getOperator(), |
| 12064 | LeftFold ? Result.get() : Out.get(), |
| 12065 | LeftFold ? Out.get() : Result.get()); |
| 12066 | } else |
| 12067 | Result = Out; |
| 12068 | |
| 12069 | if (Result.isInvalid()) |
| 12070 | return true; |
| 12071 | } |
| 12072 | |
| 12073 | // If we're retaining an expansion for a left fold, it is the outermost |
| 12074 | // component and takes the complete expansion so far as its init (if any). |
| 12075 | if (LeftFold && RetainExpansion) { |
| 12076 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 12077 | |
| 12078 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 12079 | if (Out.isInvalid()) |
| 12080 | return true; |
| 12081 | |
| 12082 | Result = getDerived().RebuildCXXFoldExpr( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12083 | E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(), |
| Richard Smith | c7214f6 | 2019-05-13 08:31:14 +0000 | [diff] [blame] | 12084 | Out.get(), E->getEndLoc(), OrigNumExpansions); |
| Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 12085 | if (Result.isInvalid()) |
| 12086 | return true; |
| 12087 | } |
| 12088 | |
| 12089 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 12090 | // then produce a fallback value or error. |
| 12091 | if (Result.isUnset()) |
| 12092 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 12093 | E->getOperator()); |
| 12094 | |
| 12095 | return Result; |
| 12096 | } |
| 12097 | |
| 12098 | template<typename Derived> |
| 12099 | ExprResult |
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 12100 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 12101 | CXXStdInitializerListExpr *E) { |
| 12102 | return getDerived().TransformExpr(E->getSubExpr()); |
| 12103 | } |
| 12104 | |
| 12105 | template<typename Derived> |
| 12106 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12107 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12108 | return SemaRef.MaybeBindToTemporary(E); |
| 12109 | } |
| 12110 | |
| 12111 | template<typename Derived> |
| 12112 | ExprResult |
| 12113 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12114 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12115 | } |
| 12116 | |
| 12117 | template<typename Derived> |
| 12118 | ExprResult |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 12119 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 12120 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 12121 | if (SubExpr.isInvalid()) |
| 12122 | return ExprError(); |
| 12123 | |
| 12124 | if (!getDerived().AlwaysRebuild() && |
| 12125 | SubExpr.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12126 | return E; |
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 12127 | |
| 12128 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12129 | } |
| 12130 | |
| 12131 | template<typename Derived> |
| 12132 | ExprResult |
| 12133 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 12134 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 12135 | SmallVector<Expr *, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12136 | bool ArgChanged = false; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12137 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12138 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 12139 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12140 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12141 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 12142 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12143 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12144 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 12145 | Elements.data(), |
| 12146 | Elements.size()); |
| 12147 | } |
| 12148 | |
| 12149 | template<typename Derived> |
| 12150 | ExprResult |
| 12151 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12152 | ObjCDictionaryLiteral *E) { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12153 | // Transform each of the elements. |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 12154 | SmallVector<ObjCDictionaryElement, 8> Elements; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12155 | bool ArgChanged = false; |
| 12156 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 12157 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12158 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12159 | if (OrigElement.isPackExpansion()) { |
| 12160 | // This key/value element is a pack expansion. |
| 12161 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 12162 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 12163 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 12164 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 12165 | |
| 12166 | // Determine whether the set of unexpanded parameter packs can |
| 12167 | // and should be expanded. |
| 12168 | bool Expand = true; |
| 12169 | bool RetainExpansion = false; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 12170 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 12171 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12172 | SourceRange PatternRange(OrigElement.Key->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 12173 | OrigElement.Value->getEndLoc()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12174 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 12175 | PatternRange, Unexpanded, Expand, |
| 12176 | RetainExpansion, NumExpansions)) |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12177 | return ExprError(); |
| 12178 | |
| 12179 | if (!Expand) { |
| 12180 | // The transform has determined that we should perform a simple |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12181 | // transformation on the pack expansion, producing another pack |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12182 | // expansion. |
| 12183 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 12184 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12185 | if (Key.isInvalid()) |
| 12186 | return ExprError(); |
| 12187 | |
| 12188 | if (Key.get() != OrigElement.Key) |
| 12189 | ArgChanged = true; |
| 12190 | |
| 12191 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 12192 | if (Value.isInvalid()) |
| 12193 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12194 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12195 | if (Value.get() != OrigElement.Value) |
| 12196 | ArgChanged = true; |
| 12197 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12198 | ObjCDictionaryElement Expansion = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12199 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 12200 | }; |
| 12201 | Elements.push_back(Expansion); |
| 12202 | continue; |
| 12203 | } |
| 12204 | |
| 12205 | // Record right away that the argument was changed. This needs |
| 12206 | // to happen even if the array expands to nothing. |
| 12207 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12208 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12209 | // The transform has determined that we should perform an elementwise |
| 12210 | // expansion of the pattern. Do so. |
| 12211 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12212 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 12213 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12214 | if (Key.isInvalid()) |
| 12215 | return ExprError(); |
| 12216 | |
| 12217 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 12218 | if (Value.isInvalid()) |
| 12219 | return ExprError(); |
| 12220 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12221 | ObjCDictionaryElement Element = { |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12222 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 12223 | }; |
| 12224 | |
| 12225 | // If any unexpanded parameter packs remain, we still have a |
| 12226 | // pack expansion. |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 12227 | // FIXME: Can this really happen? |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12228 | if (Key.get()->containsUnexpandedParameterPack() || |
| 12229 | Value.get()->containsUnexpandedParameterPack()) |
| 12230 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12231 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12232 | Elements.push_back(Element); |
| 12233 | } |
| 12234 | |
| Richard Smith | 9467be4 | 2014-06-06 17:33:35 +0000 | [diff] [blame] | 12235 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 12236 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12237 | // We've finished with this pack expansion. |
| 12238 | continue; |
| 12239 | } |
| 12240 | |
| 12241 | // Transform and check key. |
| 12242 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 12243 | if (Key.isInvalid()) |
| 12244 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12245 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12246 | if (Key.get() != OrigElement.Key) |
| 12247 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12248 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12249 | // Transform and check value. |
| 12250 | ExprResult Value |
| 12251 | = getDerived().TransformExpr(OrigElement.Value); |
| 12252 | if (Value.isInvalid()) |
| 12253 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12254 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12255 | if (Value.get() != OrigElement.Value) |
| 12256 | ArgChanged = true; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12257 | |
| 12258 | ObjCDictionaryElement Element = { |
| David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 12259 | Key.get(), Value.get(), SourceLocation(), None |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12260 | }; |
| 12261 | Elements.push_back(Element); |
| 12262 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12263 | |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12264 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 12265 | return SemaRef.MaybeBindToTemporary(E); |
| 12266 | |
| 12267 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| Craig Topper | d4336e0 | 2015-12-24 23:58:15 +0000 | [diff] [blame] | 12268 | Elements); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12269 | } |
| 12270 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12271 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12272 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12273 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12274 | TypeSourceInfo *EncodedTypeInfo |
| 12275 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 12276 | if (!EncodedTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12277 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12278 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12279 | if (!getDerived().AlwaysRebuild() && |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12280 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12281 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12282 | |
| 12283 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| Douglas Gregor | abd9e96 | 2010-04-20 15:39:42 +0000 | [diff] [blame] | 12284 | EncodedTypeInfo, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12285 | E->getRParenLoc()); |
| 12286 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12287 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12288 | template<typename Derived> |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12289 | ExprResult TreeTransform<Derived>:: |
| 12290 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| John McCall | bc48989 | 2013-04-11 02:14:26 +0000 | [diff] [blame] | 12291 | // This is a kind of implicit conversion, and it needs to get dropped |
| 12292 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 12293 | // do, as well a more specific one: this expression is only valid when |
| 12294 | // it appears *immediately* as an argument expression. |
| 12295 | return getDerived().TransformExpr(E->getSubExpr()); |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12296 | } |
| 12297 | |
| 12298 | template<typename Derived> |
| 12299 | ExprResult TreeTransform<Derived>:: |
| 12300 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12301 | TypeSourceInfo *TSInfo |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12302 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 12303 | if (!TSInfo) |
| 12304 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12305 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12306 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12307 | if (Result.isInvalid()) |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12308 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12309 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12310 | if (!getDerived().AlwaysRebuild() && |
| 12311 | TSInfo == E->getTypeInfoAsWritten() && |
| 12312 | Result.get() == E->getSubExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12313 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12314 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12315 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12316 | E->getBridgeKeywordLoc(), TSInfo, |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12317 | Result.get()); |
| 12318 | } |
| 12319 | |
| Erik Pilkington | 29099de | 2016-07-16 00:35:23 +0000 | [diff] [blame] | 12320 | template <typename Derived> |
| 12321 | ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( |
| 12322 | ObjCAvailabilityCheckExpr *E) { |
| 12323 | return E; |
| 12324 | } |
| 12325 | |
| John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 12326 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12327 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12328 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12329 | // Transform arguments. |
| 12330 | bool ArgChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12331 | SmallVector<Expr*, 8> Args; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12332 | Args.reserve(E->getNumArgs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12333 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12334 | &ArgChanged)) |
| 12335 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12336 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12337 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 12338 | // Class message: transform the receiver type. |
| 12339 | TypeSourceInfo *ReceiverTypeInfo |
| 12340 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 12341 | if (!ReceiverTypeInfo) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12342 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12343 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12344 | // If nothing changed, just retain the existing message send. |
| 12345 | if (!getDerived().AlwaysRebuild() && |
| 12346 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12347 | return SemaRef.MaybeBindToTemporary(E); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12348 | |
| 12349 | // Build a new class message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12350 | SmallVector<SourceLocation, 16> SelLocs; |
| 12351 | E->getSelectorLocs(SelLocs); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12352 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 12353 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12354 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12355 | E->getMethodDecl(), |
| 12356 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12357 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12358 | E->getRightLoc()); |
| 12359 | } |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12360 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 12361 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| Bruno Cardoso Lopes | 25f02cf | 2016-08-22 21:50:22 +0000 | [diff] [blame] | 12362 | if (!E->getMethodDecl()) |
| 12363 | return ExprError(); |
| 12364 | |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12365 | // Build a new class message send to 'super'. |
| 12366 | SmallVector<SourceLocation, 16> SelLocs; |
| 12367 | E->getSelectorLocs(SelLocs); |
| 12368 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 12369 | E->getSelector(), |
| 12370 | SelLocs, |
| Argyrios Kyrtzidis | c2a5891 | 2015-07-28 06:12:24 +0000 | [diff] [blame] | 12371 | E->getReceiverType(), |
| Fariborz Jahanian | a8c2a0b0 | 2015-03-30 23:30:24 +0000 | [diff] [blame] | 12372 | E->getMethodDecl(), |
| 12373 | E->getLeftLoc(), |
| 12374 | Args, |
| 12375 | E->getRightLoc()); |
| 12376 | } |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12377 | |
| 12378 | // Instance message: transform the receiver |
| 12379 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 12380 | "Only class and instance messages may be instantiated"); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12381 | ExprResult Receiver |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12382 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 12383 | if (Receiver.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12384 | return ExprError(); |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12385 | |
| 12386 | // If nothing changed, just retain the existing message send. |
| 12387 | if (!getDerived().AlwaysRebuild() && |
| 12388 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12389 | return SemaRef.MaybeBindToTemporary(E); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12390 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12391 | // Build a new instance message send. |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12392 | SmallVector<SourceLocation, 16> SelLocs; |
| 12393 | E->getSelectorLocs(SelLocs); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12394 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12395 | E->getSelector(), |
| Argyrios Kyrtzidis | a6011e2 | 2011-10-03 06:36:51 +0000 | [diff] [blame] | 12396 | SelLocs, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12397 | E->getMethodDecl(), |
| 12398 | E->getLeftLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12399 | Args, |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12400 | E->getRightLoc()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12401 | } |
| 12402 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12403 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12404 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12405 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12406 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12407 | } |
| 12408 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12409 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12410 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12411 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12412 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12413 | } |
| 12414 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12415 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12416 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12417 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12418 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12419 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12420 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12421 | return ExprError(); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12422 | |
| 12423 | // We don't need to transform the ivar; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12424 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12425 | // If nothing changed, just retain the existing expression. |
| 12426 | if (!getDerived().AlwaysRebuild() && |
| 12427 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12428 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12429 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12430 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12431 | E->getLocation(), |
| 12432 | E->isArrow(), E->isFreeIvar()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12433 | } |
| 12434 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12435 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12436 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12437 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12438 | // 'super' and types never change. Property never changes. Just |
| 12439 | // retain the existing expression. |
| 12440 | if (!E->isObjectReceiver()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12441 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12442 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12443 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12444 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12445 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12446 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12447 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12448 | // We don't need to transform the property; it will never change. |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12449 | |
| Douglas Gregor | 9faee21 | 2010-04-26 20:47:02 +0000 | [diff] [blame] | 12450 | // If nothing changed, just retain the existing expression. |
| 12451 | if (!getDerived().AlwaysRebuild() && |
| 12452 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12453 | return E; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12454 | |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12455 | if (E->isExplicitProperty()) |
| 12456 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 12457 | E->getExplicitProperty(), |
| 12458 | E->getLocation()); |
| 12459 | |
| 12460 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 12461 | SemaRef.Context.PseudoObjectTy, |
| John McCall | b7bd14f | 2010-12-02 01:19:52 +0000 | [diff] [blame] | 12462 | E->getImplicitPropertyGetter(), |
| 12463 | E->getImplicitPropertySetter(), |
| 12464 | E->getLocation()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12465 | } |
| 12466 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12467 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12468 | ExprResult |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12469 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 12470 | // Transform the base expression. |
| 12471 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 12472 | if (Base.isInvalid()) |
| 12473 | return ExprError(); |
| 12474 | |
| 12475 | // Transform the key expression. |
| 12476 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 12477 | if (Key.isInvalid()) |
| 12478 | return ExprError(); |
| 12479 | |
| 12480 | // If nothing changed, just retain the existing expression. |
| 12481 | if (!getDerived().AlwaysRebuild() && |
| 12482 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12483 | return E; |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12484 | |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12485 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 12486 | Base.get(), Key.get(), |
| 12487 | E->getAtIndexMethodDecl(), |
| 12488 | E->setAtIndexMethodDecl()); |
| 12489 | } |
| 12490 | |
| 12491 | template<typename Derived> |
| 12492 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12493 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12494 | // Transform the base expression. |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12495 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12496 | if (Base.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 12497 | return ExprError(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12498 | |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12499 | // If nothing changed, just retain the existing expression. |
| 12500 | if (!getDerived().AlwaysRebuild() && |
| 12501 | Base.get() == E->getBase()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12502 | return E; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12503 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12504 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
| Fariborz Jahanian | 06bb7f7 | 2013-03-28 19:50:55 +0000 | [diff] [blame] | 12505 | E->getOpLoc(), |
| Douglas Gregor | d51d90d | 2010-04-26 20:11:03 +0000 | [diff] [blame] | 12506 | E->isArrow()); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12507 | } |
| 12508 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12509 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12510 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12511 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12512 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12513 | SmallVector<Expr*, 8> SubExprs; |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12514 | SubExprs.reserve(E->getNumSubExprs()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12515 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| Douglas Gregor | a3efea1 | 2011-01-03 19:04:46 +0000 | [diff] [blame] | 12516 | SubExprs, &ArgumentChanged)) |
| 12517 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12518 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12519 | if (!getDerived().AlwaysRebuild() && |
| 12520 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12521 | return E; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12522 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12523 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12524 | SubExprs, |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12525 | E->getRParenLoc()); |
| 12526 | } |
| 12527 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12528 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12529 | ExprResult |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12530 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 12531 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 12532 | if (SrcExpr.isInvalid()) |
| 12533 | return ExprError(); |
| 12534 | |
| 12535 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 12536 | if (!Type) |
| 12537 | return ExprError(); |
| 12538 | |
| 12539 | if (!getDerived().AlwaysRebuild() && |
| 12540 | Type == E->getTypeSourceInfo() && |
| 12541 | SrcExpr.get() == E->getSrcExpr()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12542 | return E; |
| Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 12543 | |
| 12544 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 12545 | SrcExpr.get(), Type, |
| 12546 | E->getRParenLoc()); |
| 12547 | } |
| 12548 | |
| 12549 | template<typename Derived> |
| 12550 | ExprResult |
| John McCall | 47f29ea | 2009-12-08 09:21:05 +0000 | [diff] [blame] | 12551 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12552 | BlockDecl *oldBlock = E->getBlockDecl(); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12553 | |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12554 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12555 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 12556 | |
| 12557 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 12558 | blockScope->TheDecl->setBlockMissingReturnType( |
| 12559 | oldBlock->blockMissingReturnType()); |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12560 | |
| Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 12561 | SmallVector<ParmVarDecl*, 4> params; |
| 12562 | SmallVector<QualType, 4> paramTypes; |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12563 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12564 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 12565 | |
| Fariborz Jahanian | 1babe77 | 2010-07-09 18:44:02 +0000 | [diff] [blame] | 12566 | // Parameter substitution. |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12567 | Sema::ExtParameterInfoBuilder extParamInfos; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 12568 | if (getDerived().TransformFunctionTypeParams( |
| 12569 | E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 12570 | exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 12571 | extParamInfos)) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12572 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| Douglas Gregor | c7f46f2 | 2011-12-10 00:23:21 +0000 | [diff] [blame] | 12573 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12574 | } |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12575 | |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12576 | QualType exprResultType = |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 12577 | getDerived().TransformType(exprFunctionType->getReturnType()); |
| Douglas Gregor | 476e302 | 2011-01-19 21:32:01 +0000 | [diff] [blame] | 12578 | |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12579 | auto epi = exprFunctionType->getExtProtoInfo(); |
| 12580 | epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 12581 | |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12582 | QualType functionType = |
| John McCall | c8e321d | 2016-03-01 02:09:25 +0000 | [diff] [blame] | 12583 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12584 | blockScope->FunctionType = functionType; |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12585 | |
| 12586 | // Set the parameters on the block decl. |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12587 | if (!params.empty()) |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 12588 | blockScope->TheDecl->setParams(params); |
| Eli Friedman | 34b4906 | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 12589 | |
| 12590 | if (!oldBlock->blockMissingReturnType()) { |
| 12591 | blockScope->HasImplicitReturnType = false; |
| 12592 | blockScope->ReturnType = exprResultType; |
| 12593 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12594 | |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12595 | // Transform the body |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12596 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12597 | if (body.isInvalid()) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12598 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12599 | return ExprError(); |
| Argyrios Kyrtzidis | 34172b8 | 2012-01-25 03:53:04 +0000 | [diff] [blame] | 12600 | } |
| John McCall | 3882ace | 2011-01-05 12:14:39 +0000 | [diff] [blame] | 12601 | |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12602 | #ifndef NDEBUG |
| 12603 | // In builds with assertions, make sure that we captured everything we |
| 12604 | // captured before. |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12605 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 12606 | for (const auto &I : oldBlock->captures()) { |
| 12607 | VarDecl *oldCapture = I.getVariable(); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12608 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12609 | // Ignore parameter packs. |
| Richard Smith | b2997f5 | 2019-05-21 20:10:50 +0000 | [diff] [blame] | 12610 | if (oldCapture->isParameterPack()) |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12611 | continue; |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12612 | |
| Douglas Gregor | 4385d8b | 2011-05-20 15:32:55 +0000 | [diff] [blame] | 12613 | VarDecl *newCapture = |
| 12614 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 12615 | oldCapture)); |
| 12616 | assert(blockScope->CaptureMap.count(newCapture)); |
| 12617 | } |
| Douglas Gregor | 3a08c1c | 2012-02-24 17:41:38 +0000 | [diff] [blame] | 12618 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
| John McCall | 490112f | 2011-02-04 18:33:18 +0000 | [diff] [blame] | 12619 | } |
| 12620 | #endif |
| 12621 | |
| 12622 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12623 | /*Scope=*/nullptr); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12624 | } |
| 12625 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12626 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 12627 | ExprResult |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12628 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 12629 | llvm_unreachable("Cannot transform asType expressions yet"); |
| Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 12630 | } |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12631 | |
| 12632 | template<typename Derived> |
| 12633 | ExprResult |
| 12634 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12635 | QualType RetTy = getDerived().TransformType(E->getType()); |
| 12636 | bool ArgumentChanged = false; |
| Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 12637 | SmallVector<Expr*, 8> SubExprs; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12638 | SubExprs.reserve(E->getNumSubExprs()); |
| 12639 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 12640 | SubExprs, &ArgumentChanged)) |
| 12641 | return ExprError(); |
| 12642 | |
| 12643 | if (!getDerived().AlwaysRebuild() && |
| 12644 | !ArgumentChanged) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 12645 | return E; |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12646 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 12647 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
| Eli Friedman | 8d3e43f | 2011-10-14 22:48:56 +0000 | [diff] [blame] | 12648 | RetTy, E->getOp(), E->getRParenLoc()); |
| Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 12649 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 12650 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12651 | //===----------------------------------------------------------------------===// |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12652 | // Type reconstruction |
| 12653 | //===----------------------------------------------------------------------===// |
| 12654 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12655 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12656 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 12657 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12658 | return SemaRef.BuildPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12659 | getDerived().getBaseEntity()); |
| 12660 | } |
| 12661 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12662 | template<typename Derived> |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12663 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 12664 | SourceLocation Star) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12665 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12666 | getDerived().getBaseEntity()); |
| 12667 | } |
| 12668 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12669 | template<typename Derived> |
| 12670 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12671 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 12672 | bool WrittenAsLValue, |
| 12673 | SourceLocation Sigil) { |
| John McCall | cb0f89a | 2010-06-05 06:41:15 +0000 | [diff] [blame] | 12674 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12675 | Sigil, getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12676 | } |
| 12677 | |
| 12678 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12679 | QualType |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12680 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 12681 | QualType ClassType, |
| 12682 | SourceLocation Sigil) { |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 12683 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 12684 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12685 | } |
| 12686 | |
| 12687 | template<typename Derived> |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 12688 | QualType TreeTransform<Derived>::RebuildObjCTypeParamType( |
| 12689 | const ObjCTypeParamDecl *Decl, |
| 12690 | SourceLocation ProtocolLAngleLoc, |
| 12691 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12692 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12693 | SourceLocation ProtocolRAngleLoc) { |
| 12694 | return SemaRef.BuildObjCTypeParamType(Decl, |
| 12695 | ProtocolLAngleLoc, Protocols, |
| 12696 | ProtocolLocs, ProtocolRAngleLoc, |
| 12697 | /*FailOnError=*/true); |
| 12698 | } |
| 12699 | |
| 12700 | template<typename Derived> |
| Douglas Gregor | 9bda6cf | 2015-07-07 03:58:14 +0000 | [diff] [blame] | 12701 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 12702 | QualType BaseType, |
| 12703 | SourceLocation Loc, |
| 12704 | SourceLocation TypeArgsLAngleLoc, |
| 12705 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 12706 | SourceLocation TypeArgsRAngleLoc, |
| 12707 | SourceLocation ProtocolLAngleLoc, |
| 12708 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 12709 | ArrayRef<SourceLocation> ProtocolLocs, |
| 12710 | SourceLocation ProtocolRAngleLoc) { |
| 12711 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 12712 | TypeArgs, TypeArgsRAngleLoc, |
| 12713 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 12714 | ProtocolRAngleLoc, |
| 12715 | /*FailOnError=*/true); |
| 12716 | } |
| 12717 | |
| 12718 | template<typename Derived> |
| 12719 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 12720 | QualType PointeeType, |
| 12721 | SourceLocation Star) { |
| 12722 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 12723 | } |
| 12724 | |
| 12725 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12726 | QualType |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12727 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 12728 | ArrayType::ArraySizeModifier SizeMod, |
| 12729 | const llvm::APInt *Size, |
| 12730 | Expr *SizeExpr, |
| 12731 | unsigned IndexTypeQuals, |
| 12732 | SourceRange BracketsRange) { |
| 12733 | if (SizeExpr || !Size) |
| 12734 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 12735 | IndexTypeQuals, BracketsRange, |
| 12736 | getDerived().getBaseEntity()); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12737 | |
| 12738 | QualType Types[] = { |
| 12739 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 12740 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 12741 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12742 | }; |
| Craig Topper | e5ce831 | 2013-07-15 03:38:40 +0000 | [diff] [blame] | 12743 | const unsigned NumTypes = llvm::array_lengthof(Types); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12744 | QualType SizeType; |
| 12745 | for (unsigned I = 0; I != NumTypes; ++I) |
| 12746 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 12747 | SizeType = Types[I]; |
| 12748 | break; |
| 12749 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12750 | |
| Eli Friedman | 9562f39 | 2012-01-25 23:20:27 +0000 | [diff] [blame] | 12751 | // Note that we can return a VariableArrayType here in the case where |
| 12752 | // the element type was a dependent VariableArrayType. |
| 12753 | IntegerLiteral *ArraySize |
| 12754 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 12755 | /*FIXME*/BracketsRange.getBegin()); |
| 12756 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12757 | IndexTypeQuals, BracketsRange, |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12758 | getDerived().getBaseEntity()); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12759 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12760 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12761 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12762 | QualType |
| 12763 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12764 | ArrayType::ArraySizeModifier SizeMod, |
| 12765 | const llvm::APInt &Size, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12766 | unsigned IndexTypeQuals, |
| 12767 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12768 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12769 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12770 | } |
| 12771 | |
| 12772 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12773 | QualType |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12774 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12775 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12776 | unsigned IndexTypeQuals, |
| 12777 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12778 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
| John McCall | 70dd5f6 | 2009-10-30 00:06:24 +0000 | [diff] [blame] | 12779 | IndexTypeQuals, BracketsRange); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12780 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12781 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12782 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12783 | QualType |
| 12784 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12785 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12786 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12787 | unsigned IndexTypeQuals, |
| 12788 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12789 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12790 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12791 | IndexTypeQuals, BracketsRange); |
| 12792 | } |
| 12793 | |
| 12794 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12795 | QualType |
| 12796 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12797 | ArrayType::ArraySizeModifier SizeMod, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12798 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12799 | unsigned IndexTypeQuals, |
| 12800 | SourceRange BracketsRange) { |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12801 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12802 | SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12803 | IndexTypeQuals, BracketsRange); |
| 12804 | } |
| 12805 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 12806 | template <typename Derived> |
| 12807 | QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( |
| 12808 | QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { |
| 12809 | return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, |
| 12810 | AttributeLoc); |
| 12811 | } |
| 12812 | |
| 12813 | template <typename Derived> |
| 12814 | QualType |
| 12815 | TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 12816 | unsigned NumElements, |
| 12817 | VectorType::VectorKind VecKind) { |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12818 | // FIXME: semantic checking! |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 12819 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12820 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12821 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 12822 | template <typename Derived> |
| 12823 | QualType TreeTransform<Derived>::RebuildDependentVectorType( |
| 12824 | QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, |
| 12825 | VectorType::VectorKind VecKind) { |
| 12826 | return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); |
| 12827 | } |
| 12828 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12829 | template<typename Derived> |
| 12830 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 12831 | unsigned NumElements, |
| 12832 | SourceLocation AttributeLoc) { |
| 12833 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 12834 | NumElements, true); |
| 12835 | IntegerLiteral *VectorSize |
| Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 12836 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 12837 | AttributeLoc); |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12838 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12839 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12840 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12841 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12842 | QualType |
| 12843 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12844 | Expr *SizeExpr, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12845 | SourceLocation AttributeLoc) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 12846 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12847 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12848 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12849 | template<typename Derived> |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 12850 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 12851 | QualType T, |
| Craig Topper | e3d2ecbe | 2014-06-28 23:22:33 +0000 | [diff] [blame] | 12852 | MutableArrayRef<QualType> ParamTypes, |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12853 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 12854 | return SemaRef.BuildFunctionType(T, ParamTypes, |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12855 | getDerived().getBaseLocation(), |
| Eli Friedman | d8725a9 | 2010-08-05 02:54:05 +0000 | [diff] [blame] | 12856 | getDerived().getBaseEntity(), |
| Jordan Rose | a0a86be | 2013-03-08 22:25:36 +0000 | [diff] [blame] | 12857 | EPI); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12858 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12859 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12860 | template<typename Derived> |
| John McCall | 550e0c2 | 2009-10-21 00:40:46 +0000 | [diff] [blame] | 12861 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 12862 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 12863 | } |
| 12864 | |
| 12865 | template<typename Derived> |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12866 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, |
| 12867 | Decl *D) { |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12868 | assert(D && "no decl found"); |
| 12869 | if (D->isInvalidDecl()) return QualType(); |
| 12870 | |
| Douglas Gregor | c298ffc | 2010-04-22 16:44:27 +0000 | [diff] [blame] | 12871 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12872 | TypeDecl *Ty; |
| Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 12873 | if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { |
| 12874 | // A valid resolved using typename pack expansion decl can have multiple |
| 12875 | // UsingDecls, but they must each have exactly one type, and it must be |
| 12876 | // the same type in every case. But we must have at least one expansion! |
| 12877 | if (UPD->expansions().empty()) { |
| 12878 | getSema().Diag(Loc, diag::err_using_pack_expansion_empty) |
| 12879 | << UPD->isCXXClassMember() << UPD; |
| 12880 | return QualType(); |
| 12881 | } |
| 12882 | |
| 12883 | // We might still have some unresolved types. Try to pick a resolved type |
| 12884 | // if we can. The final instantiation will check that the remaining |
| 12885 | // unresolved types instantiate to the type we pick. |
| 12886 | QualType FallbackT; |
| 12887 | QualType T; |
| 12888 | for (auto *E : UPD->expansions()) { |
| 12889 | QualType ThisT = RebuildUnresolvedUsingType(Loc, E); |
| 12890 | if (ThisT.isNull()) |
| 12891 | continue; |
| 12892 | else if (ThisT->getAs<UnresolvedUsingType>()) |
| 12893 | FallbackT = ThisT; |
| 12894 | else if (T.isNull()) |
| 12895 | T = ThisT; |
| 12896 | else |
| 12897 | assert(getSema().Context.hasSameType(ThisT, T) && |
| 12898 | "mismatched resolved types in using pack expansion"); |
| 12899 | } |
| 12900 | return T.isNull() ? FallbackT : T; |
| 12901 | } else if (auto *Using = dyn_cast<UsingDecl>(D)) { |
| Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 12902 | assert(Using->hasTypename() && |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12903 | "UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 12904 | |
| 12905 | // A valid resolved using typename decl points to exactly one type decl. |
| 12906 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 12907 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 12908 | } else { |
| 12909 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 12910 | "UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 12911 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 12912 | } |
| 12913 | |
| 12914 | return SemaRef.Context.getTypeDeclType(Ty); |
| 12915 | } |
| 12916 | |
| 12917 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12918 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 12919 | SourceLocation Loc) { |
| 12920 | return SemaRef.BuildTypeofExprType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12921 | } |
| 12922 | |
| 12923 | template<typename Derived> |
| 12924 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 12925 | return SemaRef.Context.getTypeOfType(Underlying); |
| 12926 | } |
| 12927 | |
| 12928 | template<typename Derived> |
| John McCall | 36e7fe3 | 2010-10-12 00:20:44 +0000 | [diff] [blame] | 12929 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 12930 | SourceLocation Loc) { |
| 12931 | return SemaRef.BuildDecltypeType(E, Loc); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12932 | } |
| 12933 | |
| 12934 | template<typename Derived> |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 12935 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 12936 | UnaryTransformType::UTTKind UKind, |
| 12937 | SourceLocation Loc) { |
| 12938 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 12939 | } |
| 12940 | |
| 12941 | template<typename Derived> |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12942 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 12943 | TemplateName Template, |
| 12944 | SourceLocation TemplateNameLoc, |
| Douglas Gregor | 739b107a | 2011-03-03 02:41:12 +0000 | [diff] [blame] | 12945 | TemplateArgumentListInfo &TemplateArgs) { |
| John McCall | 6b51f28 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 12946 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 12947 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12948 | |
| Douglas Gregor | 1135c35 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 12949 | template<typename Derived> |
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 12950 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 12951 | SourceLocation KWLoc) { |
| 12952 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 12953 | } |
| 12954 | |
| 12955 | template<typename Derived> |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12956 | QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 12957 | SourceLocation KWLoc, |
| 12958 | bool isReadPipe) { |
| 12959 | return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) |
| 12960 | : SemaRef.BuildWritePipeType(ValueType, KWLoc); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 12961 | } |
| 12962 | |
| 12963 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12964 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12965 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12966 | bool TemplateKW, |
| 12967 | TemplateDecl *Template) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12968 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12969 | Template); |
| 12970 | } |
| 12971 | |
| 12972 | template<typename Derived> |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12973 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12974 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 12975 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12976 | const IdentifierInfo &Name, |
| 12977 | SourceLocation NameLoc, |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 12978 | QualType ObjectType, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12979 | NamedDecl *FirstQualifierInScope, |
| 12980 | bool AllowInjectedClassName) { |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12981 | UnqualifiedId TemplateName; |
| 12982 | TemplateName.setIdentifier(&Name, NameLoc); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12983 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 12984 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 12985 | SS, TemplateKWLoc, TemplateName, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 12986 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 12987 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12988 | Template, AllowInjectedClassName); |
| John McCall | 31f8272 | 2010-11-12 08:19:04 +0000 | [diff] [blame] | 12989 | return Template.get(); |
| Douglas Gregor | 71dc509 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 12990 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 12991 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 12992 | template<typename Derived> |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12993 | TemplateName |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12994 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| Richard Smith | 7981004 | 2018-05-11 02:43:08 +0000 | [diff] [blame] | 12995 | SourceLocation TemplateKWLoc, |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 12996 | OverloadedOperatorKind Operator, |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 12997 | SourceLocation NameLoc, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 12998 | QualType ObjectType, |
| 12999 | bool AllowInjectedClassName) { |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13000 | UnqualifiedId Name; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13001 | // FIXME: Bogus location information. |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13002 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| Douglas Gregor | 9db5350 | 2011-03-02 18:07:45 +0000 | [diff] [blame] | 13003 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13004 | Sema::TemplateTy Template; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13005 | getSema().ActOnDependentTemplateName(/*Scope=*/nullptr, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13006 | SS, TemplateKWLoc, Name, |
| John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 13007 | ParsedType::make(ObjectType), |
| Douglas Gregor | bb11965 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 13008 | /*EnteringContext=*/false, |
| Richard Smith | fd3dae0 | 2017-01-20 00:20:39 +0000 | [diff] [blame] | 13009 | Template, AllowInjectedClassName); |
| Serge Pavlov | 9ddb76e | 2013-08-27 13:15:56 +0000 | [diff] [blame] | 13010 | return Template.get(); |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13011 | } |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13012 | |
| Douglas Gregor | 71395fa | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 13013 | template<typename Derived> |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 13014 | ExprResult |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13015 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 13016 | SourceLocation OpLoc, |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13017 | Expr *OrigCallee, |
| 13018 | Expr *First, |
| 13019 | Expr *Second) { |
| 13020 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 13021 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13022 | |
| Argyrios Kyrtzidis | 0f99537 | 2014-06-19 14:45:16 +0000 | [diff] [blame] | 13023 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 13024 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 13025 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 13026 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 13027 | First, Second); |
| 13028 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 13029 | if (Result.isInvalid()) |
| 13030 | return ExprError(); |
| 13031 | First = Result.get(); |
| 13032 | } |
| 13033 | |
| 13034 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 13035 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 13036 | if (Result.isInvalid()) |
| 13037 | return ExprError(); |
| 13038 | Second = Result.get(); |
| 13039 | } |
| 13040 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13041 | // Determine whether this should be a builtin operation. |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 13042 | if (Op == OO_Subscript) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13043 | if (!First->getType()->isOverloadableType() && |
| 13044 | !Second->getType()->isOverloadableType()) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13045 | return getSema().CreateBuiltinArraySubscriptExpr( |
| 13046 | First, Callee->getBeginLoc(), Second, OpLoc); |
| Eli Friedman | f2f534d | 2009-11-16 19:13:03 +0000 | [diff] [blame] | 13047 | } else if (Op == OO_Arrow) { |
| 13048 | // -> is never a builtin operation. |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13049 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 13050 | } else if (Second == nullptr || isPostIncDec) { |
| Richard Smith | cc4ad95 | 2018-07-22 05:21:47 +0000 | [diff] [blame] | 13051 | if (!First->getType()->isOverloadableType() || |
| 13052 | (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { |
| 13053 | // The argument is not of overloadable type, or this is an expression |
| 13054 | // of the form &Class::member, so try to create a built-in unary |
| 13055 | // operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13056 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13057 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13058 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13059 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13060 | } |
| 13061 | } else { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13062 | if (!First->getType()->isOverloadableType() && |
| 13063 | !Second->getType()->isOverloadableType()) { |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13064 | // Neither of the arguments is an overloadable type, so try to |
| 13065 | // create a built-in binary operation. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13066 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 13067 | ExprResult Result |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13068 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13069 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 13070 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13071 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 13072 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13073 | } |
| 13074 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13075 | |
| 13076 | // Compute the transformed set of functions (and function templates) to be |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13077 | // used during overload resolution. |
| John McCall | 4c4c1df | 2010-01-26 03:27:55 +0000 | [diff] [blame] | 13078 | UnresolvedSet<16> Functions; |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13079 | bool RequiresADL; |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13080 | |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13081 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
| Richard Smith | 100b24a | 2014-04-17 01:52:14 +0000 | [diff] [blame] | 13082 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13083 | // If the overload could not be resolved in the template definition |
| 13084 | // (because we had a dependent argument), ADL is performed as part of |
| 13085 | // template instantiation. |
| 13086 | RequiresADL = ULE->requiresADL(); |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 13087 | } else { |
| Richard Smith | 58db83d | 2012-11-28 21:47:39 +0000 | [diff] [blame] | 13088 | // If we've resolved this to a particular non-member function, just call |
| 13089 | // that function. If we resolved it to a member function, |
| 13090 | // CreateOverloaded* will find that function for us. |
| 13091 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 13092 | if (!isa<CXXMethodDecl>(ND)) |
| 13093 | Functions.addDecl(ND); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13094 | RequiresADL = false; |
| John McCall | d14a864 | 2009-11-21 08:51:07 +0000 | [diff] [blame] | 13095 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13096 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13097 | // Add any functions found via argument-dependent lookup. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13098 | Expr *Args[2] = { First, Second }; |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13099 | unsigned NumArgs = 1 + (Second != nullptr); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13100 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13101 | // Create the overloaded operator invocation for unary operators. |
| 13102 | if (NumArgs == 1 || isPostIncDec) { |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13103 | UnaryOperatorKind Opc |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13104 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13105 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, |
| 13106 | RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13107 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13108 | |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13109 | if (Op == OO_Subscript) { |
| 13110 | SourceLocation LBrace; |
| 13111 | SourceLocation RBrace; |
| 13112 | |
| 13113 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| NAKAMURA Takumi | 44d4d9a | 2014-10-29 08:11:47 +0000 | [diff] [blame] | 13114 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13115 | LBrace = SourceLocation::getFromRawEncoding( |
| 13116 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 13117 | RBrace = SourceLocation::getFromRawEncoding( |
| 13118 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 13119 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13120 | LBrace = Callee->getBeginLoc(); |
| 13121 | RBrace = OpLoc; |
| Douglas Gregor | e9d6293 | 2011-07-15 16:25:15 +0000 | [diff] [blame] | 13122 | } |
| 13123 | |
| 13124 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 13125 | First, Second); |
| 13126 | } |
| Sebastian Redl | adba46e | 2009-10-29 20:17:01 +0000 | [diff] [blame] | 13127 | |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13128 | // Create the overloaded operator invocation for binary operators. |
| John McCall | e302792 | 2010-08-25 11:45:40 +0000 | [diff] [blame] | 13129 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| Richard Smith | 91fc7d8 | 2017-10-05 19:35:51 +0000 | [diff] [blame] | 13130 | ExprResult Result = SemaRef.CreateOverloadedBinOp( |
| 13131 | OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13132 | if (Result.isInvalid()) |
| John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 13133 | return ExprError(); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13134 | |
| Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 13135 | return Result; |
| Douglas Gregor | a16548e | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 13136 | } |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 13137 | |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13138 | template<typename Derived> |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13139 | ExprResult |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13140 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13141 | SourceLocation OperatorLoc, |
| 13142 | bool isArrow, |
| Douglas Gregor | a6ce608 | 2011-02-25 18:19:59 +0000 | [diff] [blame] | 13143 | CXXScopeSpec &SS, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13144 | TypeSourceInfo *ScopeType, |
| 13145 | SourceLocation CCLoc, |
| Douglas Gregor | cdbd515 | 2010-02-24 23:50:37 +0000 | [diff] [blame] | 13146 | SourceLocation TildeLoc, |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 13147 | PseudoDestructorTypeStorage Destroyed) { |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13148 | QualType BaseType = Base->getType(); |
| 13149 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13150 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| Chad Rosier | 1dcde96 | 2012-08-08 18:46:20 +0000 | [diff] [blame] | 13151 | (isArrow && BaseType->getAs<PointerType>() && |
| Gabor Greif | 5c07926 | 2010-02-25 13:04:33 +0000 | [diff] [blame] | 13152 | !BaseType->getAs<PointerType>()->getPointeeType() |
| 13153 | ->template getAs<RecordType>())){ |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13154 | // This pseudo-destructor expression is still a pseudo-destructor. |
| David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 13155 | return SemaRef.BuildPseudoDestructorExpr( |
| 13156 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 13157 | CCLoc, TildeLoc, Destroyed); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13158 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13159 | |
| Douglas Gregor | 678f90d | 2010-02-25 01:56:36 +0000 | [diff] [blame] | 13160 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13161 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 13162 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 13163 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 13164 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 13165 | |
| Richard Smith | 8e4a386 | 2012-05-15 06:15:11 +0000 | [diff] [blame] | 13166 | // The scope type is now known to be a valid nested name specifier |
| 13167 | // component. Tack it on to the end of the nested name specifier. |
| Alexey Bataev | 2a06681 | 2014-10-16 03:04:35 +0000 | [diff] [blame] | 13168 | if (ScopeType) { |
| 13169 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 13170 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 13171 | diag::err_expected_class_or_namespace) |
| 13172 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 13173 | return ExprError(); |
| 13174 | } |
| 13175 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 13176 | CCLoc); |
| 13177 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13178 | |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13179 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
| John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 13180 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13181 | OperatorLoc, isArrow, |
| Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 13182 | SS, TemplateKWLoc, |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13183 | /*FIXME: FirstQualifier*/ nullptr, |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 13184 | NameInfo, |
| Aaron Ballman | 6924dcd | 2015-09-01 14:49:24 +0000 | [diff] [blame] | 13185 | /*TemplateArgs*/ nullptr, |
| 13186 | /*S*/nullptr); |
| Douglas Gregor | 651fe5e | 2010-02-24 23:40:28 +0000 | [diff] [blame] | 13187 | } |
| 13188 | |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 13189 | template<typename Derived> |
| 13190 | StmtResult |
| 13191 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13192 | SourceLocation Loc = S->getBeginLoc(); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 13193 | CapturedDecl *CD = S->getCapturedDecl(); |
| 13194 | unsigned NumParams = CD->getNumParams(); |
| 13195 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 13196 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 13197 | for (unsigned I = 0; I < NumParams; ++I) { |
| 13198 | if (I != ContextParamPos) { |
| 13199 | Params.push_back( |
| 13200 | std::make_pair( |
| 13201 | CD->getParam(I)->getName(), |
| 13202 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 13203 | } else { |
| 13204 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 13205 | } |
| 13206 | } |
| Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 13207 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 13208 | S->getCapturedRegionKind(), Params); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 13209 | StmtResult Body; |
| 13210 | { |
| 13211 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 13212 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 13213 | } |
| Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 13214 | |
| 13215 | if (Body.isInvalid()) { |
| 13216 | getSema().ActOnCapturedRegionError(); |
| 13217 | return StmtError(); |
| 13218 | } |
| 13219 | |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 13220 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
| Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 13221 | } |
| 13222 | |
| Douglas Gregor | d6ff332 | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 13223 | } // end namespace clang |
| 13224 | |
| Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 13225 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |