| 1 |
//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
| 2 |
// |
| 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 |
| 6 |
//===----------------------------------------------------------------------===// |
| 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 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 13 |
#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 14 |
#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 15 |
|
| 16 |
#include "CoroutineStmtBuilder.h" |
| 17 |
#include "TypeLocBuilder.h" |
| 18 |
#include "clang/AST/Decl.h" |
| 19 |
#include "clang/AST/DeclObjC.h" |
| 20 |
#include "clang/AST/DeclTemplate.h" |
| 21 |
#include "clang/AST/Expr.h" |
| 22 |
#include "clang/AST/ExprCXX.h" |
| 23 |
#include "clang/AST/ExprConcepts.h" |
| 24 |
#include "clang/AST/ExprObjC.h" |
| 25 |
#include "clang/AST/ExprOpenMP.h" |
| 26 |
#include "clang/AST/OpenMPClause.h" |
| 27 |
#include "clang/AST/Stmt.h" |
| 28 |
#include "clang/AST/StmtCXX.h" |
| 29 |
#include "clang/AST/StmtObjC.h" |
| 30 |
#include "clang/AST/StmtOpenACC.h" |
| 31 |
#include "clang/AST/StmtOpenMP.h" |
| 32 |
#include "clang/AST/StmtSYCL.h" |
| 33 |
#include "clang/Basic/DiagnosticParse.h" |
| 34 |
#include "clang/Basic/OpenMPKinds.h" |
| 35 |
#include "clang/Sema/Designator.h" |
| 36 |
#include "clang/Sema/EnterExpressionEvaluationContext.h" |
| 37 |
#include "clang/Sema/Lookup.h" |
| 38 |
#include "clang/Sema/Ownership.h" |
| 39 |
#include "clang/Sema/ParsedTemplate.h" |
| 40 |
#include "clang/Sema/ScopeInfo.h" |
| 41 |
#include "clang/Sema/SemaDiagnostic.h" |
| 42 |
#include "clang/Sema/SemaInternal.h" |
| 43 |
#include "clang/Sema/SemaObjC.h" |
| 44 |
#include "clang/Sema/SemaOpenACC.h" |
| 45 |
#include "clang/Sema/SemaOpenMP.h" |
| 46 |
#include "clang/Sema/SemaPseudoObject.h" |
| 47 |
#include "clang/Sema/SemaSYCL.h" |
| 48 |
#include "clang/Sema/Template.h" |
| 49 |
#include "llvm/ADT/ArrayRef.h" |
| 50 |
#include "llvm/Support/ErrorHandling.h" |
| 51 |
#include <algorithm> |
| 52 |
#include <optional> |
| 53 |
|
| 54 |
using namespace llvm::omp; |
| 55 |
|
| 56 |
namespace clang { |
| 57 |
using namespace sema; |
| 58 |
|
| 59 |
// This helper class is used to facilitate pack expansion during tree transform. |
| 60 |
struct UnexpandedInfo { |
| 61 |
SourceLocation Ellipsis; |
| 62 |
UnsignedOrNone OrigNumExpansions = std::nullopt; |
| 63 |
|
| 64 |
bool Expand = false; |
| 65 |
bool RetainExpansion = false; |
| 66 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 67 |
bool ExpandUnderForgetSubstitions = false; |
| 68 |
}; |
| 69 |
|
| 70 |
/// A semantic tree transformation that allows one to transform one |
| 71 |
/// abstract syntax tree into another. |
| 72 |
/// |
| 73 |
/// A new tree transformation is defined by creating a new subclass \c X of |
| 74 |
/// \c TreeTransform<X> and then overriding certain operations to provide |
| 75 |
/// behavior specific to that transformation. For example, template |
| 76 |
/// instantiation is implemented as a tree transformation where the |
| 77 |
/// transformation of TemplateTypeParmType nodes involves substituting the |
| 78 |
/// template arguments for their corresponding template parameters; a similar |
| 79 |
/// transformation is performed for non-type template parameters and |
| 80 |
/// template template parameters. |
| 81 |
/// |
| 82 |
/// This tree-transformation template uses static polymorphism to allow |
| 83 |
/// subclasses to customize any of its operations. Thus, a subclass can |
| 84 |
/// override any of the transformation or rebuild operators by providing an |
| 85 |
/// operation with the same signature as the default implementation. The |
| 86 |
/// overriding function should not be virtual. |
| 87 |
/// |
| 88 |
/// Semantic tree transformations are split into two stages, either of which |
| 89 |
/// can be replaced by a subclass. The "transform" step transforms an AST node |
| 90 |
/// or the parts of an AST node using the various transformation functions, |
| 91 |
/// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 92 |
/// node of the appropriate kind from the pieces. The default transformation |
| 93 |
/// routines recursively transform the operands to composite AST nodes (e.g., |
| 94 |
/// the pointee type of a PointerType node) and, if any of those operand nodes |
| 95 |
/// were changed by the transformation, invokes the rebuild operation to create |
| 96 |
/// a new AST node. |
| 97 |
/// |
| 98 |
/// Subclasses can customize the transformation at various levels. The |
| 99 |
/// most coarse-grained transformations involve replacing TransformType(), |
| 100 |
/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
| 101 |
/// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 102 |
/// new implementations. |
| 103 |
/// |
| 104 |
/// For more fine-grained transformations, subclasses can replace any of the |
| 105 |
/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
| 106 |
/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
| 107 |
/// replacing TransformTemplateTypeParmType() allows template instantiation |
| 108 |
/// to substitute template arguments for their corresponding template |
| 109 |
/// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 110 |
/// functions to control how AST nodes are rebuilt when their operands change. |
| 111 |
/// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 112 |
/// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 113 |
/// be able to use more efficient rebuild steps. |
| 114 |
/// |
| 115 |
/// There are a handful of other functions that can be overridden, allowing one |
| 116 |
/// to avoid traversing nodes that don't need any transformation |
| 117 |
/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 118 |
/// operands have not changed (\c AlwaysRebuild()), and customize the |
| 119 |
/// default locations and entity names used for type-checking |
| 120 |
/// (\c getBaseLocation(), \c getBaseEntity()). |
| 121 |
template<typename Derived> |
| 122 |
class TreeTransform { |
| 123 |
/// Private RAII object that helps us forget and then re-remember |
| 124 |
/// the template argument corresponding to a partially-substituted parameter |
| 125 |
/// pack. |
| 126 |
class ForgetPartiallySubstitutedPackRAII { |
| 127 |
Derived &Self; |
| 128 |
TemplateArgument Old; |
| 129 |
// Set the pack expansion index to -1 to avoid pack substitution and |
| 130 |
// indicate that parameter packs should be instantiated as themselves. |
| 131 |
Sema::ArgPackSubstIndexRAII ResetPackSubstIndex; |
| 132 |
|
| 133 |
public: |
| 134 |
ForgetPartiallySubstitutedPackRAII(Derived &Self) |
| 135 |
: Self(Self), ResetPackSubstIndex(Self.getSema(), std::nullopt) { |
| 136 |
Old = Self.ForgetPartiallySubstitutedPack(); |
| 137 |
} |
| 138 |
|
| 139 |
~ForgetPartiallySubstitutedPackRAII() { |
| 140 |
Self.RememberPartiallySubstitutedPack(Old); |
| 141 |
} |
| 142 |
ForgetPartiallySubstitutedPackRAII( |
| 143 |
const ForgetPartiallySubstitutedPackRAII &) = delete; |
| 144 |
ForgetPartiallySubstitutedPackRAII & |
| 145 |
operator=(const ForgetPartiallySubstitutedPackRAII &) = delete; |
| 146 |
}; |
| 147 |
|
| 148 |
protected: |
| 149 |
Sema &SemaRef; |
| 150 |
|
| 151 |
/// The set of local declarations that have been transformed, for |
| 152 |
/// cases where we are forced to build new declarations within the transformer |
| 153 |
/// rather than in the subclass (e.g., lambda closure types). |
| 154 |
llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
| 155 |
|
| 156 |
public: |
| 157 |
/// Initializes a new tree transformer. |
| 158 |
TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
| 159 |
|
| 160 |
/// Retrieves a reference to the derived class. |
| 161 |
Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 162 |
|
| 163 |
/// Retrieves a reference to the derived class. |
| 164 |
const Derived &getDerived() const { |
| 165 |
return static_cast<const Derived&>(*this); |
| 166 |
} |
| 167 |
|
| 168 |
static inline ExprResult Owned(Expr *E) { return E; } |
| 169 |
static inline StmtResult Owned(Stmt *S) { return S; } |
| 170 |
|
| 171 |
/// Retrieves a reference to the semantic analysis object used for |
| 172 |
/// this tree transform. |
| 173 |
Sema &getSema() const { return SemaRef; } |
| 174 |
|
| 175 |
/// Whether the transformation should always rebuild AST nodes, even |
| 176 |
/// if none of the children have changed. |
| 177 |
/// |
| 178 |
/// Subclasses may override this function to specify when the transformation |
| 179 |
/// should rebuild all AST nodes. |
| 180 |
/// |
| 181 |
/// We must always rebuild all AST nodes when performing variadic template |
| 182 |
/// pack expansion, in order to avoid violating the AST invariant that each |
| 183 |
/// statement node appears at most once in its containing declaration. |
| 184 |
bool AlwaysRebuild() { return static_cast<bool>(SemaRef.ArgPackSubstIndex); } |
| 185 |
|
| 186 |
/// Whether the transformation is forming an expression or statement that |
| 187 |
/// replaces the original. In this case, we'll reuse mangling numbers from |
| 188 |
/// existing lambdas. |
| 189 |
bool ReplacingOriginal() { return false; } |
| 190 |
|
| 191 |
/// Wether CXXConstructExpr can be skipped when they are implicit. |
| 192 |
/// They will be reconstructed when used if needed. |
| 193 |
/// This is useful when the user that cause rebuilding of the |
| 194 |
/// CXXConstructExpr is outside of the expression at which the TreeTransform |
| 195 |
/// started. |
| 196 |
bool AllowSkippingCXXConstructExpr() { return true; } |
| 197 |
|
| 198 |
/// Returns the location of the entity being transformed, if that |
| 199 |
/// information was not available elsewhere in the AST. |
| 200 |
/// |
| 201 |
/// By default, returns no source-location information. Subclasses can |
| 202 |
/// provide an alternative implementation that provides better location |
| 203 |
/// information. |
| 204 |
SourceLocation getBaseLocation() { return SourceLocation(); } |
| 205 |
|
| 206 |
/// Returns the name of the entity being transformed, if that |
| 207 |
/// information was not available elsewhere in the AST. |
| 208 |
/// |
| 209 |
/// By default, returns an empty name. Subclasses can provide an alternative |
| 210 |
/// implementation with a more precise name. |
| 211 |
DeclarationName getBaseEntity() { return DeclarationName(); } |
| 212 |
|
| 213 |
/// Sets the "base" location and entity when that |
| 214 |
/// information is known based on another transformation. |
| 215 |
/// |
| 216 |
/// By default, the source location and entity are ignored. Subclasses can |
| 217 |
/// override this function to provide a customized implementation. |
| 218 |
void setBase(SourceLocation Loc, DeclarationName Entity) { } |
| 219 |
|
| 220 |
/// RAII object that temporarily sets the base location and entity |
| 221 |
/// used for reporting diagnostics in types. |
| 222 |
class TemporaryBase { |
| 223 |
TreeTransform &Self; |
| 224 |
SourceLocation OldLocation; |
| 225 |
DeclarationName OldEntity; |
| 226 |
|
| 227 |
public: |
| 228 |
TemporaryBase(TreeTransform &Self, SourceLocation Location, |
| 229 |
DeclarationName Entity) : Self(Self) { |
| 230 |
OldLocation = Self.getDerived().getBaseLocation(); |
| 231 |
OldEntity = Self.getDerived().getBaseEntity(); |
| 232 |
|
| 233 |
if (Location.isValid()) |
| 234 |
Self.getDerived().setBase(Location, Entity); |
| 235 |
} |
| 236 |
|
| 237 |
~TemporaryBase() { |
| 238 |
Self.getDerived().setBase(OldLocation, OldEntity); |
| 239 |
} |
| 240 |
TemporaryBase(const TemporaryBase &) = delete; |
| 241 |
TemporaryBase &operator=(const TemporaryBase &) = delete; |
| 242 |
}; |
| 243 |
|
| 244 |
/// Determine whether the given type \p T has already been |
| 245 |
/// transformed. |
| 246 |
/// |
| 247 |
/// Subclasses can provide an alternative implementation of this routine |
| 248 |
/// to short-circuit evaluation when it is known that a given type will |
| 249 |
/// not change. For example, template instantiation need not traverse |
| 250 |
/// non-dependent types. |
| 251 |
bool AlreadyTransformed(QualType T) { |
| 252 |
return T.isNull(); |
| 253 |
} |
| 254 |
|
| 255 |
/// Transform a template parameter depth level. |
| 256 |
/// |
| 257 |
/// During a transformation that transforms template parameters, this maps |
| 258 |
/// an old template parameter depth to a new depth. |
| 259 |
unsigned TransformTemplateDepth(unsigned Depth) { |
| 260 |
return Depth; |
| 261 |
} |
| 262 |
|
| 263 |
/// Determine whether the given call argument should be dropped, e.g., |
| 264 |
/// because it is a default argument. |
| 265 |
/// |
| 266 |
/// Subclasses can provide an alternative implementation of this routine to |
| 267 |
/// determine which kinds of call arguments get dropped. By default, |
| 268 |
/// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 269 |
bool DropCallArgument(Expr *E) { |
| 270 |
return E->isDefaultArgument(); |
| 271 |
} |
| 272 |
|
| 273 |
/// Determine whether we should expand a pack expansion with the |
| 274 |
/// given set of parameter packs into separate arguments by repeatedly |
| 275 |
/// transforming the pattern. |
| 276 |
/// |
| 277 |
/// By default, the transformer never tries to expand pack expansions. |
| 278 |
/// Subclasses can override this routine to provide different behavior. |
| 279 |
/// |
| 280 |
/// \param EllipsisLoc The location of the ellipsis that identifies the |
| 281 |
/// pack expansion. |
| 282 |
/// |
| 283 |
/// \param PatternRange The source range that covers the entire pattern of |
| 284 |
/// the pack expansion. |
| 285 |
/// |
| 286 |
/// \param Unexpanded The set of unexpanded parameter packs within the |
| 287 |
/// pattern. |
| 288 |
/// |
| 289 |
/// \param ShouldExpand Will be set to \c true if the transformer should |
| 290 |
/// expand the corresponding pack expansions into separate arguments. When |
| 291 |
/// set, \c NumExpansions must also be set. |
| 292 |
/// |
| 293 |
/// \param RetainExpansion Whether the caller should add an unexpanded |
| 294 |
/// pack expansion after all of the expanded arguments. This is used |
| 295 |
/// when extending explicitly-specified template argument packs per |
| 296 |
/// C++0x [temp.arg.explicit]p9. |
| 297 |
/// |
| 298 |
/// \param NumExpansions The number of separate arguments that will be in |
| 299 |
/// the expanded form of the corresponding pack expansion. This is both an |
| 300 |
/// input and an output parameter, which can be set by the caller if the |
| 301 |
/// number of expansions is known a priori (e.g., due to a prior substitution) |
| 302 |
/// and will be set by the callee when the number of expansions is known. |
| 303 |
/// The callee must set this value when \c ShouldExpand is \c true; it may |
| 304 |
/// set this value in other cases. |
| 305 |
/// |
| 306 |
/// \returns true if an error occurred (e.g., because the parameter packs |
| 307 |
/// are to be instantiated with arguments of different lengths), false |
| 308 |
/// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 309 |
/// must be set. |
| 310 |
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 311 |
SourceRange PatternRange, |
| 312 |
ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 313 |
bool FailOnPackProducingTemplates, |
| 314 |
bool &ShouldExpand, bool &RetainExpansion, |
| 315 |
UnsignedOrNone &NumExpansions) { |
| 316 |
ShouldExpand = false; |
| 317 |
return false; |
| 318 |
} |
| 319 |
|
| 320 |
/// "Forget" about the partially-substituted pack template argument, |
| 321 |
/// when performing an instantiation that must preserve the parameter pack |
| 322 |
/// use. |
| 323 |
/// |
| 324 |
/// This routine is meant to be overridden by the template instantiator. |
| 325 |
TemplateArgument ForgetPartiallySubstitutedPack() { |
| 326 |
return TemplateArgument(); |
| 327 |
} |
| 328 |
|
| 329 |
/// "Remember" the partially-substituted pack template argument |
| 330 |
/// after performing an instantiation that must preserve the parameter pack |
| 331 |
/// use. |
| 332 |
/// |
| 333 |
/// This routine is meant to be overridden by the template instantiator. |
| 334 |
void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 335 |
|
| 336 |
/// "Forget" the template substitution to allow transforming the AST without |
| 337 |
/// any template instantiations. This is used to expand template packs when |
| 338 |
/// their size is not known in advance (e.g. for builtins that produce type |
| 339 |
/// packs). |
| 340 |
MultiLevelTemplateArgumentList ForgetSubstitution() { return {}; } |
| 341 |
void RememberSubstitution(MultiLevelTemplateArgumentList) {} |
| 342 |
|
| 343 |
private: |
| 344 |
struct ForgetSubstitutionRAII { |
| 345 |
Derived &Self; |
| 346 |
MultiLevelTemplateArgumentList Old; |
| 347 |
|
| 348 |
public: |
| 349 |
ForgetSubstitutionRAII(Derived &Self) : Self(Self) { |
| 350 |
Old = Self.ForgetSubstitution(); |
| 351 |
} |
| 352 |
|
| 353 |
~ForgetSubstitutionRAII() { Self.RememberSubstitution(std::move(Old)); } |
| 354 |
}; |
| 355 |
|
| 356 |
public: |
| 357 |
/// Note to the derived class when a function parameter pack is |
| 358 |
/// being expanded. |
| 359 |
void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 360 |
|
| 361 |
/// Transforms the given type into another type. |
| 362 |
/// |
| 363 |
/// By default, this routine transforms a type by creating a |
| 364 |
/// TypeSourceInfo for it and delegating to the appropriate |
| 365 |
/// function. This is expensive, but we don't mind, because |
| 366 |
/// this method is deprecated anyway; all users should be |
| 367 |
/// switched to storing TypeSourceInfos. |
| 368 |
/// |
| 369 |
/// \returns the transformed type. |
| 370 |
QualType TransformType(QualType T); |
| 371 |
|
| 372 |
/// Transforms the given type-with-location into a new |
| 373 |
/// type-with-location. |
| 374 |
/// |
| 375 |
/// By default, this routine transforms a type by delegating to the |
| 376 |
/// appropriate TransformXXXType to build a new type. Subclasses |
| 377 |
/// may override this function (to take over all type |
| 378 |
/// transformations) or some set of the TransformXXXType functions |
| 379 |
/// to alter the transformation. |
| 380 |
TypeSourceInfo *TransformType(TypeSourceInfo *TSI); |
| 381 |
|
| 382 |
/// Transform the given type-with-location into a new |
| 383 |
/// type, collecting location information in the given builder |
| 384 |
/// as necessary. |
| 385 |
/// |
| 386 |
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
| 387 |
|
| 388 |
/// Transform a type that is permitted to produce a |
| 389 |
/// DeducedTemplateSpecializationType. |
| 390 |
/// |
| 391 |
/// This is used in the (relatively rare) contexts where it is acceptable |
| 392 |
/// for transformation to produce a class template type with deduced |
| 393 |
/// template arguments. |
| 394 |
/// @{ |
| 395 |
QualType TransformTypeWithDeducedTST(QualType T); |
| 396 |
TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *TSI); |
| 397 |
/// @} |
| 398 |
|
| 399 |
/// The reason why the value of a statement is not discarded, if any. |
| 400 |
enum class StmtDiscardKind { |
| 401 |
Discarded, |
| 402 |
NotDiscarded, |
| 403 |
StmtExprResult, |
| 404 |
}; |
| 405 |
|
| 406 |
/// Transform the given statement. |
| 407 |
/// |
| 408 |
/// By default, this routine transforms a statement by delegating to the |
| 409 |
/// appropriate TransformXXXStmt function to transform a specific kind of |
| 410 |
/// statement or the TransformExpr() function to transform an expression. |
| 411 |
/// Subclasses may override this function to transform statements using some |
| 412 |
/// other mechanism. |
| 413 |
/// |
| 414 |
/// \returns the transformed statement. |
| 415 |
StmtResult TransformStmt(Stmt *S, |
| 416 |
StmtDiscardKind SDK = StmtDiscardKind::Discarded); |
| 417 |
|
| 418 |
/// Transform the given statement. |
| 419 |
/// |
| 420 |
/// By default, this routine transforms a statement by delegating to the |
| 421 |
/// appropriate TransformOMPXXXClause function to transform a specific kind |
| 422 |
/// of clause. Subclasses may override this function to transform statements |
| 423 |
/// using some other mechanism. |
| 424 |
/// |
| 425 |
/// \returns the transformed OpenMP clause. |
| 426 |
OMPClause *TransformOMPClause(OMPClause *S); |
| 427 |
|
| 428 |
/// Transform the given attribute. |
| 429 |
/// |
| 430 |
/// By default, this routine transforms a statement by delegating to the |
| 431 |
/// appropriate TransformXXXAttr function to transform a specific kind |
| 432 |
/// of attribute. Subclasses may override this function to transform |
| 433 |
/// attributed statements/types using some other mechanism. |
| 434 |
/// |
| 435 |
/// \returns the transformed attribute |
| 436 |
const Attr *TransformAttr(const Attr *S); |
| 437 |
|
| 438 |
// Transform the given statement attribute. |
| 439 |
// |
| 440 |
// Delegates to the appropriate TransformXXXAttr function to transform a |
| 441 |
// specific kind of statement attribute. Unlike the non-statement taking |
| 442 |
// version of this, this implements all attributes, not just pragmas. |
| 443 |
const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, |
| 444 |
const Attr *A); |
| 445 |
|
| 446 |
// Transform the specified attribute. |
| 447 |
// |
| 448 |
// Subclasses should override the transformation of attributes with a pragma |
| 449 |
// spelling to transform expressions stored within the attribute. |
| 450 |
// |
| 451 |
// \returns the transformed attribute. |
| 452 |
#define ATTR(X) \ |
| 453 |
const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 454 |
#include "clang/Basic/AttrList.inc" |
| 455 |
|
| 456 |
// Transform the specified attribute. |
| 457 |
// |
| 458 |
// Subclasses should override the transformation of attributes to do |
| 459 |
// transformation and checking of statement attributes. By default, this |
| 460 |
// delegates to the non-statement taking version. |
| 461 |
// |
| 462 |
// \returns the transformed attribute. |
| 463 |
#define ATTR(X) \ |
| 464 |
const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \ |
| 465 |
const X##Attr *A) { \ |
| 466 |
return getDerived().Transform##X##Attr(A); \ |
| 467 |
} |
| 468 |
#include "clang/Basic/AttrList.inc" |
| 469 |
|
| 470 |
/// Transform the given expression. |
| 471 |
/// |
| 472 |
/// By default, this routine transforms an expression by delegating to the |
| 473 |
/// appropriate TransformXXXExpr function to build a new expression. |
| 474 |
/// Subclasses may override this function to transform expressions using some |
| 475 |
/// other mechanism. |
| 476 |
/// |
| 477 |
/// \returns the transformed expression. |
| 478 |
ExprResult TransformExpr(Expr *E); |
| 479 |
|
| 480 |
/// Transform the given initializer. |
| 481 |
/// |
| 482 |
/// By default, this routine transforms an initializer by stripping off the |
| 483 |
/// semantic nodes added by initialization, then passing the result to |
| 484 |
/// TransformExpr or TransformExprs. |
| 485 |
/// |
| 486 |
/// \returns the transformed initializer. |
| 487 |
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
| 488 |
|
| 489 |
/// Transform the given list of expressions. |
| 490 |
/// |
| 491 |
/// This routine transforms a list of expressions by invoking |
| 492 |
/// \c TransformExpr() for each subexpression. However, it also provides |
| 493 |
/// support for variadic templates by expanding any pack expansions (if the |
| 494 |
/// derived class permits such expansion) along the way. When pack expansions |
| 495 |
/// are present, the number of outputs may not equal the number of inputs. |
| 496 |
/// |
| 497 |
/// \param Inputs The set of expressions to be transformed. |
| 498 |
/// |
| 499 |
/// \param NumInputs The number of expressions in \c Inputs. |
| 500 |
/// |
| 501 |
/// \param IsCall If \c true, then this transform is being performed on |
| 502 |
/// function-call arguments, and any arguments that should be dropped, will |
| 503 |
/// be. |
| 504 |
/// |
| 505 |
/// \param Outputs The transformed input expressions will be added to this |
| 506 |
/// vector. |
| 507 |
/// |
| 508 |
/// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 509 |
/// due to transformation. |
| 510 |
/// |
| 511 |
/// \returns true if an error occurred, false otherwise. |
| 512 |
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, |
| 513 |
SmallVectorImpl<Expr *> &Outputs, |
| 514 |
bool *ArgChanged = nullptr); |
| 515 |
|
| 516 |
/// Transform the given declaration, which is referenced from a type |
| 517 |
/// or expression. |
| 518 |
/// |
| 519 |
/// By default, acts as the identity function on declarations, unless the |
| 520 |
/// transformer has had to transform the declaration itself. Subclasses |
| 521 |
/// may override this function to provide alternate behavior. |
| 522 |
Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| 523 |
llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 524 |
= TransformedLocalDecls.find(D); |
| 525 |
if (Known != TransformedLocalDecls.end()) |
| 526 |
return Known->second; |
| 527 |
|
| 528 |
return D; |
| 529 |
} |
| 530 |
|
| 531 |
/// Transform the specified condition. |
| 532 |
/// |
| 533 |
/// By default, this transforms the variable and expression and rebuilds |
| 534 |
/// the condition. |
| 535 |
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
| 536 |
Expr *Expr, |
| 537 |
Sema::ConditionKind Kind); |
| 538 |
|
| 539 |
/// Transform the attributes associated with the given declaration and |
| 540 |
/// place them on the new declaration. |
| 541 |
/// |
| 542 |
/// By default, this operation does nothing. Subclasses may override this |
| 543 |
/// behavior to transform attributes. |
| 544 |
void transformAttrs(Decl *Old, Decl *New) { } |
| 545 |
|
| 546 |
/// Note that a local declaration has been transformed by this |
| 547 |
/// transformer. |
| 548 |
/// |
| 549 |
/// Local declarations are typically transformed via a call to |
| 550 |
/// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 551 |
/// the transformer itself has to transform the declarations. This routine |
| 552 |
/// can be overridden by a subclass that keeps track of such mappings. |
| 553 |
void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { |
| 554 |
assert(New.size() == 1 && |
| 555 |
"must override transformedLocalDecl if performing pack expansion"); |
| 556 |
TransformedLocalDecls[Old] = New.front(); |
| 557 |
} |
| 558 |
|
| 559 |
/// Transform the definition of the given declaration. |
| 560 |
/// |
| 561 |
/// By default, invokes TransformDecl() to transform the declaration. |
| 562 |
/// Subclasses may override this function to provide alternate behavior. |
| 563 |
Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 564 |
return getDerived().TransformDecl(Loc, D); |
| 565 |
} |
| 566 |
|
| 567 |
/// Transform the given declaration, which was the first part of a |
| 568 |
/// nested-name-specifier in a member access expression. |
| 569 |
/// |
| 570 |
/// This specific declaration transformation only applies to the first |
| 571 |
/// identifier in a nested-name-specifier of a member access expression, e.g., |
| 572 |
/// the \c T in \c x->T::member |
| 573 |
/// |
| 574 |
/// By default, invokes TransformDecl() to transform the declaration. |
| 575 |
/// Subclasses may override this function to provide alternate behavior. |
| 576 |
NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 577 |
return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
| 578 |
} |
| 579 |
|
| 580 |
/// Transform the set of declarations in an OverloadExpr. |
| 581 |
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, |
| 582 |
LookupResult &R); |
| 583 |
|
| 584 |
/// Transform the given nested-name-specifier with source-location |
| 585 |
/// information. |
| 586 |
/// |
| 587 |
/// By default, transforms all of the types and declarations within the |
| 588 |
/// nested-name-specifier. Subclasses may override this function to provide |
| 589 |
/// alternate behavior. |
| 590 |
NestedNameSpecifierLoc |
| 591 |
TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 592 |
QualType ObjectType = QualType(), |
| 593 |
NamedDecl *FirstQualifierInScope = nullptr); |
| 594 |
|
| 595 |
/// Transform the given declaration name. |
| 596 |
/// |
| 597 |
/// By default, transforms the types of conversion function, constructor, |
| 598 |
/// and destructor names and then (if needed) rebuilds the declaration name. |
| 599 |
/// Identifiers and selectors are returned unmodified. Subclasses may |
| 600 |
/// override this function to provide alternate behavior. |
| 601 |
DeclarationNameInfo |
| 602 |
TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
| 603 |
|
| 604 |
bool TransformRequiresExprRequirements( |
| 605 |
ArrayRef<concepts::Requirement *> Reqs, |
| 606 |
llvm::SmallVectorImpl<concepts::Requirement *> &Transformed); |
| 607 |
concepts::TypeRequirement * |
| 608 |
TransformTypeRequirement(concepts::TypeRequirement *Req); |
| 609 |
concepts::ExprRequirement * |
| 610 |
TransformExprRequirement(concepts::ExprRequirement *Req); |
| 611 |
concepts::NestedRequirement * |
| 612 |
TransformNestedRequirement(concepts::NestedRequirement *Req); |
| 613 |
|
| 614 |
/// Transform the given template name. |
| 615 |
/// |
| 616 |
/// \param SS The nested-name-specifier that qualifies the template |
| 617 |
/// name. This nested-name-specifier must already have been transformed. |
| 618 |
/// |
| 619 |
/// \param Name The template name to transform. |
| 620 |
/// |
| 621 |
/// \param NameLoc The source location of the template name. |
| 622 |
/// |
| 623 |
/// \param ObjectType If we're translating a template name within a member |
| 624 |
/// access expression, this is the type of the object whose member template |
| 625 |
/// is being referenced. |
| 626 |
/// |
| 627 |
/// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 628 |
/// also refers to a name within the current (lexical) scope, this is the |
| 629 |
/// declaration it refers to. |
| 630 |
/// |
| 631 |
/// By default, transforms the template name by transforming the declarations |
| 632 |
/// and nested-name-specifiers that occur within the template name. |
| 633 |
/// Subclasses may override this function to provide alternate behavior. |
| 634 |
TemplateName TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc, |
| 635 |
SourceLocation TemplateKWLoc, |
| 636 |
TemplateName Name, SourceLocation NameLoc, |
| 637 |
QualType ObjectType = QualType(), |
| 638 |
NamedDecl *FirstQualifierInScope = nullptr, |
| 639 |
bool AllowInjectedClassName = false); |
| 640 |
|
| 641 |
/// Transform the given template argument. |
| 642 |
/// |
| 643 |
/// By default, this operation transforms the type, expression, or |
| 644 |
/// declaration stored within the template argument and constructs a |
| 645 |
/// new template argument from the transformed result. Subclasses may |
| 646 |
/// override this function to provide alternate behavior. |
| 647 |
/// |
| 648 |
/// Returns true if there was an error. |
| 649 |
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 650 |
TemplateArgumentLoc &Output, |
| 651 |
bool Uneval = false); |
| 652 |
|
| 653 |
TemplateArgument TransformNamedTemplateTemplateArgument( |
| 654 |
NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, |
| 655 |
TemplateName Name, SourceLocation NameLoc); |
| 656 |
|
| 657 |
/// Transform the given set of template arguments. |
| 658 |
/// |
| 659 |
/// By default, this operation transforms all of the template arguments |
| 660 |
/// in the input set using \c TransformTemplateArgument(), and appends |
| 661 |
/// the transformed arguments to the output list. |
| 662 |
/// |
| 663 |
/// Note that this overload of \c TransformTemplateArguments() is merely |
| 664 |
/// a convenience function. Subclasses that wish to override this behavior |
| 665 |
/// should override the iterator-based member template version. |
| 666 |
/// |
| 667 |
/// \param Inputs The set of template arguments to be transformed. |
| 668 |
/// |
| 669 |
/// \param NumInputs The number of template arguments in \p Inputs. |
| 670 |
/// |
| 671 |
/// \param Outputs The set of transformed template arguments output by this |
| 672 |
/// routine. |
| 673 |
/// |
| 674 |
/// Returns true if an error occurred. |
| 675 |
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 676 |
unsigned NumInputs, |
| 677 |
TemplateArgumentListInfo &Outputs, |
| 678 |
bool Uneval = false) { |
| 679 |
return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 680 |
Uneval); |
| 681 |
} |
| 682 |
|
| 683 |
/// Transform the given set of template arguments. |
| 684 |
/// |
| 685 |
/// By default, this operation transforms all of the template arguments |
| 686 |
/// in the input set using \c TransformTemplateArgument(), and appends |
| 687 |
/// the transformed arguments to the output list. |
| 688 |
/// |
| 689 |
/// \param First An iterator to the first template argument. |
| 690 |
/// |
| 691 |
/// \param Last An iterator one step past the last template argument. |
| 692 |
/// |
| 693 |
/// \param Outputs The set of transformed template arguments output by this |
| 694 |
/// routine. |
| 695 |
/// |
| 696 |
/// Returns true if an error occurred. |
| 697 |
template<typename InputIterator> |
| 698 |
bool TransformTemplateArguments(InputIterator First, |
| 699 |
InputIterator Last, |
| 700 |
TemplateArgumentListInfo &Outputs, |
| 701 |
bool Uneval = false); |
| 702 |
|
| 703 |
template <typename InputIterator> |
| 704 |
bool TransformConceptTemplateArguments(InputIterator First, |
| 705 |
InputIterator Last, |
| 706 |
TemplateArgumentListInfo &Outputs, |
| 707 |
bool Uneval = false); |
| 708 |
|
| 709 |
/// Checks if the argument pack from \p In will need to be expanded and does |
| 710 |
/// the necessary prework. |
| 711 |
/// Whether the expansion is needed is captured in Info.Expand. |
| 712 |
/// |
| 713 |
/// - When the expansion is required, \p Out will be a template pattern that |
| 714 |
/// would need to be expanded. |
| 715 |
/// - When the expansion must not happen, \p Out will be a pack that must be |
| 716 |
/// returned to the outputs directly. |
| 717 |
/// |
| 718 |
/// \return true iff the error occurred |
| 719 |
bool PreparePackForExpansion(TemplateArgumentLoc In, bool Uneval, |
| 720 |
TemplateArgumentLoc &Out, UnexpandedInfo &Info); |
| 721 |
|
| 722 |
/// Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 723 |
void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 724 |
TemplateArgumentLoc &ArgLoc); |
| 725 |
|
| 726 |
/// Fakes up a TypeSourceInfo for a type. |
| 727 |
TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 728 |
return SemaRef.Context.getTrivialTypeSourceInfo(T, |
| 729 |
getDerived().getBaseLocation()); |
| 730 |
} |
| 731 |
|
| 732 |
#define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 733 |
#define TYPELOC(CLASS, PARENT) \ |
| 734 |
QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 735 |
#include "clang/AST/TypeLocNodes.def" |
| 736 |
|
| 737 |
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, |
| 738 |
TemplateTypeParmTypeLoc TL, |
| 739 |
bool SuppressObjCLifetime); |
| 740 |
QualType |
| 741 |
TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, |
| 742 |
SubstTemplateTypeParmPackTypeLoc TL, |
| 743 |
bool SuppressObjCLifetime); |
| 744 |
|
| 745 |
template<typename Fn> |
| 746 |
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 747 |
FunctionProtoTypeLoc TL, |
| 748 |
CXXRecordDecl *ThisContext, |
| 749 |
Qualifiers ThisTypeQuals, |
| 750 |
Fn TransformExceptionSpec); |
| 751 |
|
| 752 |
bool TransformExceptionSpec(SourceLocation Loc, |
| 753 |
FunctionProtoType::ExceptionSpecInfo &ESI, |
| 754 |
SmallVectorImpl<QualType> &Exceptions, |
| 755 |
bool &Changed); |
| 756 |
|
| 757 |
StmtResult TransformSEHHandler(Stmt *Handler); |
| 758 |
|
| 759 |
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 760 |
TemplateSpecializationTypeLoc TL, |
| 761 |
QualType ObjectType, |
| 762 |
NamedDecl *FirstQualifierInScope, |
| 763 |
bool AllowInjectedClassName); |
| 764 |
|
| 765 |
QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL); |
| 766 |
|
| 767 |
/// Transforms the parameters of a function type into the |
| 768 |
/// given vectors. |
| 769 |
/// |
| 770 |
/// The result vectors should be kept in sync; null entries in the |
| 771 |
/// variables vector are acceptable. |
| 772 |
/// |
| 773 |
/// LastParamTransformed, if non-null, will be set to the index of the last |
| 774 |
/// parameter on which transformation was started. In the event of an error, |
| 775 |
/// this will contain the parameter which failed to instantiate. |
| 776 |
/// |
| 777 |
/// Return true on error. |
| 778 |
bool TransformFunctionTypeParams( |
| 779 |
SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 780 |
const QualType *ParamTypes, |
| 781 |
const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 782 |
SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 783 |
Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed); |
| 784 |
|
| 785 |
bool TransformFunctionTypeParams( |
| 786 |
SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 787 |
const QualType *ParamTypes, |
| 788 |
const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 789 |
SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 790 |
Sema::ExtParameterInfoBuilder &PInfos) { |
| 791 |
return getDerived().TransformFunctionTypeParams( |
| 792 |
Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr); |
| 793 |
} |
| 794 |
|
| 795 |
/// Transforms the parameters of a requires expresison into the given vectors. |
| 796 |
/// |
| 797 |
/// The result vectors should be kept in sync; null entries in the |
| 798 |
/// variables vector are acceptable. |
| 799 |
/// |
| 800 |
/// Returns an unset ExprResult on success. Returns an ExprResult the 'not |
| 801 |
/// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of |
| 802 |
/// which are cases where transformation shouldn't continue. |
| 803 |
ExprResult TransformRequiresTypeParams( |
| 804 |
SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, |
| 805 |
RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params, |
| 806 |
SmallVectorImpl<QualType> &PTypes, |
| 807 |
SmallVectorImpl<ParmVarDecl *> &TransParams, |
| 808 |
Sema::ExtParameterInfoBuilder &PInfos) { |
| 809 |
if (getDerived().TransformFunctionTypeParams( |
| 810 |
KWLoc, Params, /*ParamTypes=*/nullptr, |
| 811 |
/*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos)) |
| 812 |
return ExprError(); |
| 813 |
|
| 814 |
return ExprResult{}; |
| 815 |
} |
| 816 |
|
| 817 |
/// Transforms a single function-type parameter. Return null |
| 818 |
/// on error. |
| 819 |
/// |
| 820 |
/// \param indexAdjustment - A number to add to the parameter's |
| 821 |
/// scope index; can be negative |
| 822 |
ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 823 |
int indexAdjustment, |
| 824 |
UnsignedOrNone NumExpansions, |
| 825 |
bool ExpectParameterPack); |
| 826 |
|
| 827 |
/// Transform the body of a lambda-expression. |
| 828 |
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); |
| 829 |
/// Alternative implementation of TransformLambdaBody that skips transforming |
| 830 |
/// the body. |
| 831 |
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); |
| 832 |
|
| 833 |
CXXRecordDecl::LambdaDependencyKind |
| 834 |
ComputeLambdaDependency(LambdaScopeInfo *LSI) { |
| 835 |
return static_cast<CXXRecordDecl::LambdaDependencyKind>( |
| 836 |
LSI->Lambda->getLambdaDependencyKind()); |
| 837 |
} |
| 838 |
|
| 839 |
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 840 |
|
| 841 |
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 842 |
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 843 |
|
| 844 |
TemplateParameterList *TransformTemplateParameterList( |
| 845 |
TemplateParameterList *TPL) { |
| 846 |
return TPL; |
| 847 |
} |
| 848 |
|
| 849 |
ExprResult TransformAddressOfOperand(Expr *E); |
| 850 |
|
| 851 |
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 852 |
bool IsAddressOfOperand, |
| 853 |
TypeSourceInfo **RecoveryTSI); |
| 854 |
|
| 855 |
ExprResult TransformParenDependentScopeDeclRefExpr( |
| 856 |
ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 857 |
TypeSourceInfo **RecoveryTSI); |
| 858 |
|
| 859 |
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, |
| 860 |
bool IsAddressOfOperand); |
| 861 |
|
| 862 |
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
| 863 |
|
| 864 |
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S); |
| 865 |
|
| 866 |
// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 867 |
// amount of stack usage with clang. |
| 868 |
#define STMT(Node, Parent) \ |
| 869 |
LLVM_ATTRIBUTE_NOINLINE \ |
| 870 |
StmtResult Transform##Node(Node *S); |
| 871 |
#define VALUESTMT(Node, Parent) \ |
| 872 |
LLVM_ATTRIBUTE_NOINLINE \ |
| 873 |
StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); |
| 874 |
#define EXPR(Node, Parent) \ |
| 875 |
LLVM_ATTRIBUTE_NOINLINE \ |
| 876 |
ExprResult Transform##Node(Node *E); |
| 877 |
#define ABSTRACT_STMT(Stmt) |
| 878 |
#include "clang/AST/StmtNodes.inc" |
| 879 |
|
| 880 |
#define GEN_CLANG_CLAUSE_CLASS |
| 881 |
#define CLAUSE_CLASS(Enum, Str, Class) \ |
| 882 |
LLVM_ATTRIBUTE_NOINLINE \ |
| 883 |
OMPClause *Transform##Class(Class *S); |
| 884 |
#include "llvm/Frontend/OpenMP/OMP.inc" |
| 885 |
|
| 886 |
/// Build a new qualified type given its unqualified type and type location. |
| 887 |
/// |
| 888 |
/// By default, this routine adds type qualifiers only to types that can |
| 889 |
/// have qualifiers, and silently suppresses those qualifiers that are not |
| 890 |
/// permitted. Subclasses may override this routine to provide different |
| 891 |
/// behavior. |
| 892 |
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); |
| 893 |
|
| 894 |
/// Build a new pointer type given its pointee type. |
| 895 |
/// |
| 896 |
/// By default, performs semantic analysis when building the pointer type. |
| 897 |
/// Subclasses may override this routine to provide different behavior. |
| 898 |
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
| 899 |
|
| 900 |
/// Build a new block pointer type given its pointee type. |
| 901 |
/// |
| 902 |
/// By default, performs semantic analysis when building the block pointer |
| 903 |
/// type. Subclasses may override this routine to provide different behavior. |
| 904 |
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
| 905 |
|
| 906 |
/// Build a new reference type given the type it references. |
| 907 |
/// |
| 908 |
/// By default, performs semantic analysis when building the |
| 909 |
/// reference type. Subclasses may override this routine to provide |
| 910 |
/// different behavior. |
| 911 |
/// |
| 912 |
/// \param LValue whether the type was written with an lvalue sigil |
| 913 |
/// or an rvalue sigil. |
| 914 |
QualType RebuildReferenceType(QualType ReferentType, |
| 915 |
bool LValue, |
| 916 |
SourceLocation Sigil); |
| 917 |
|
| 918 |
/// Build a new member pointer type given the pointee type and the |
| 919 |
/// qualifier it refers into. |
| 920 |
/// |
| 921 |
/// By default, performs semantic analysis when building the member pointer |
| 922 |
/// type. Subclasses may override this routine to provide different behavior. |
| 923 |
QualType RebuildMemberPointerType(QualType PointeeType, |
| 924 |
const CXXScopeSpec &SS, CXXRecordDecl *Cls, |
| 925 |
SourceLocation Sigil); |
| 926 |
|
| 927 |
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 928 |
SourceLocation ProtocolLAngleLoc, |
| 929 |
ArrayRef<ObjCProtocolDecl *> Protocols, |
| 930 |
ArrayRef<SourceLocation> ProtocolLocs, |
| 931 |
SourceLocation ProtocolRAngleLoc); |
| 932 |
|
| 933 |
/// Build an Objective-C object type. |
| 934 |
/// |
| 935 |
/// By default, performs semantic analysis when building the object type. |
| 936 |
/// Subclasses may override this routine to provide different behavior. |
| 937 |
QualType RebuildObjCObjectType(QualType BaseType, |
| 938 |
SourceLocation Loc, |
| 939 |
SourceLocation TypeArgsLAngleLoc, |
| 940 |
ArrayRef<TypeSourceInfo *> TypeArgs, |
| 941 |
SourceLocation TypeArgsRAngleLoc, |
| 942 |
SourceLocation ProtocolLAngleLoc, |
| 943 |
ArrayRef<ObjCProtocolDecl *> Protocols, |
| 944 |
ArrayRef<SourceLocation> ProtocolLocs, |
| 945 |
SourceLocation ProtocolRAngleLoc); |
| 946 |
|
| 947 |
/// Build a new Objective-C object pointer type given the pointee type. |
| 948 |
/// |
| 949 |
/// By default, directly builds the pointer type, with no additional semantic |
| 950 |
/// analysis. |
| 951 |
QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 952 |
SourceLocation Star); |
| 953 |
|
| 954 |
/// Build a new array type given the element type, size |
| 955 |
/// modifier, size of the array (if known), size expression, and index type |
| 956 |
/// qualifiers. |
| 957 |
/// |
| 958 |
/// By default, performs semantic analysis when building the array type. |
| 959 |
/// Subclasses may override this routine to provide different behavior. |
| 960 |
/// Also by default, all of the other Rebuild*Array |
| 961 |
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, |
| 962 |
const llvm::APInt *Size, Expr *SizeExpr, |
| 963 |
unsigned IndexTypeQuals, SourceRange BracketsRange); |
| 964 |
|
| 965 |
/// Build a new constant array type given the element type, size |
| 966 |
/// modifier, (known) size of the array, and index type qualifiers. |
| 967 |
/// |
| 968 |
/// By default, performs semantic analysis when building the array type. |
| 969 |
/// Subclasses may override this routine to provide different behavior. |
| 970 |
QualType RebuildConstantArrayType(QualType ElementType, |
| 971 |
ArraySizeModifier SizeMod, |
| 972 |
const llvm::APInt &Size, Expr *SizeExpr, |
| 973 |
unsigned IndexTypeQuals, |
| 974 |
SourceRange BracketsRange); |
| 975 |
|
| 976 |
/// Build a new incomplete array type given the element type, size |
| 977 |
/// modifier, and index type qualifiers. |
| 978 |
/// |
| 979 |
/// By default, performs semantic analysis when building the array type. |
| 980 |
/// Subclasses may override this routine to provide different behavior. |
| 981 |
QualType RebuildIncompleteArrayType(QualType ElementType, |
| 982 |
ArraySizeModifier SizeMod, |
| 983 |
unsigned IndexTypeQuals, |
| 984 |
SourceRange BracketsRange); |
| 985 |
|
| 986 |
/// Build a new variable-length array type given the element type, |
| 987 |
/// size modifier, size expression, and index type qualifiers. |
| 988 |
/// |
| 989 |
/// By default, performs semantic analysis when building the array type. |
| 990 |
/// Subclasses may override this routine to provide different behavior. |
| 991 |
QualType RebuildVariableArrayType(QualType ElementType, |
| 992 |
ArraySizeModifier SizeMod, Expr *SizeExpr, |
| 993 |
unsigned IndexTypeQuals, |
| 994 |
SourceRange BracketsRange); |
| 995 |
|
| 996 |
/// Build a new dependent-sized array type given the element type, |
| 997 |
/// size modifier, size expression, and index type qualifiers. |
| 998 |
/// |
| 999 |
/// By default, performs semantic analysis when building the array type. |
| 1000 |
/// Subclasses may override this routine to provide different behavior. |
| 1001 |
QualType RebuildDependentSizedArrayType(QualType ElementType, |
| 1002 |
ArraySizeModifier SizeMod, |
| 1003 |
Expr *SizeExpr, |
| 1004 |
unsigned IndexTypeQuals, |
| 1005 |
SourceRange BracketsRange); |
| 1006 |
|
| 1007 |
/// Build a new vector type given the element type and |
| 1008 |
/// number of elements. |
| 1009 |
/// |
| 1010 |
/// By default, performs semantic analysis when building the vector type. |
| 1011 |
/// Subclasses may override this routine to provide different behavior. |
| 1012 |
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 1013 |
VectorKind VecKind); |
| 1014 |
|
| 1015 |
/// Build a new potentially dependently-sized extended vector type |
| 1016 |
/// given the element type and number of elements. |
| 1017 |
/// |
| 1018 |
/// By default, performs semantic analysis when building the vector type. |
| 1019 |
/// Subclasses may override this routine to provide different behavior. |
| 1020 |
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, |
| 1021 |
SourceLocation AttributeLoc, VectorKind); |
| 1022 |
|
| 1023 |
/// Build a new extended vector type given the element type and |
| 1024 |
/// number of elements. |
| 1025 |
/// |
| 1026 |
/// By default, performs semantic analysis when building the vector type. |
| 1027 |
/// Subclasses may override this routine to provide different behavior. |
| 1028 |
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 1029 |
SourceLocation AttributeLoc); |
| 1030 |
|
| 1031 |
/// Build a new potentially dependently-sized extended vector type |
| 1032 |
/// given the element type and number of elements. |
| 1033 |
/// |
| 1034 |
/// By default, performs semantic analysis when building the vector type. |
| 1035 |
/// Subclasses may override this routine to provide different behavior. |
| 1036 |
QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
| 1037 |
Expr *SizeExpr, |
| 1038 |
SourceLocation AttributeLoc); |
| 1039 |
|
| 1040 |
/// Build a new matrix type given the element type and dimensions. |
| 1041 |
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, |
| 1042 |
unsigned NumColumns); |
| 1043 |
|
| 1044 |
/// Build a new matrix type given the type and dependently-defined |
| 1045 |
/// dimensions. |
| 1046 |
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, |
| 1047 |
Expr *ColumnExpr, |
| 1048 |
SourceLocation AttributeLoc); |
| 1049 |
|
| 1050 |
/// Build a new DependentAddressSpaceType or return the pointee |
| 1051 |
/// type variable with the correct address space (retrieved from |
| 1052 |
/// AddrSpaceExpr) applied to it. The former will be returned in cases |
| 1053 |
/// where the address space remains dependent. |
| 1054 |
/// |
| 1055 |
/// By default, performs semantic analysis when building the type with address |
| 1056 |
/// space applied. Subclasses may override this routine to provide different |
| 1057 |
/// behavior. |
| 1058 |
QualType RebuildDependentAddressSpaceType(QualType PointeeType, |
| 1059 |
Expr *AddrSpaceExpr, |
| 1060 |
SourceLocation AttributeLoc); |
| 1061 |
|
| 1062 |
/// Build a new function type. |
| 1063 |
/// |
| 1064 |
/// By default, performs semantic analysis when building the function type. |
| 1065 |
/// Subclasses may override this routine to provide different behavior. |
| 1066 |
QualType RebuildFunctionProtoType(QualType T, |
| 1067 |
MutableArrayRef<QualType> ParamTypes, |
| 1068 |
const FunctionProtoType::ExtProtoInfo &EPI); |
| 1069 |
|
| 1070 |
/// Build a new unprototyped function type. |
| 1071 |
QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 1072 |
|
| 1073 |
/// Rebuild an unresolved typename type, given the decl that |
| 1074 |
/// the UnresolvedUsingTypenameDecl was transformed to. |
| 1075 |
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, |
| 1076 |
NestedNameSpecifier Qualifier, |
| 1077 |
SourceLocation NameLoc, Decl *D); |
| 1078 |
|
| 1079 |
/// Build a new type found via an alias. |
| 1080 |
QualType RebuildUsingType(ElaboratedTypeKeyword Keyword, |
| 1081 |
NestedNameSpecifier Qualifier, UsingShadowDecl *D, |
| 1082 |
QualType UnderlyingType) { |
| 1083 |
return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType); |
| 1084 |
} |
| 1085 |
|
| 1086 |
/// Build a new typedef type. |
| 1087 |
QualType RebuildTypedefType(ElaboratedTypeKeyword Keyword, |
| 1088 |
NestedNameSpecifier Qualifier, |
| 1089 |
TypedefNameDecl *Typedef) { |
| 1090 |
return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef); |
| 1091 |
} |
| 1092 |
|
| 1093 |
/// Build a new MacroDefined type. |
| 1094 |
QualType RebuildMacroQualifiedType(QualType T, |
| 1095 |
const IdentifierInfo *MacroII) { |
| 1096 |
return SemaRef.Context.getMacroQualifiedType(T, MacroII); |
| 1097 |
} |
| 1098 |
|
| 1099 |
/// Build a new class/struct/union/enum type. |
| 1100 |
QualType RebuildTagType(ElaboratedTypeKeyword Keyword, |
| 1101 |
NestedNameSpecifier Qualifier, TagDecl *Tag) { |
| 1102 |
return SemaRef.Context.getTagType(Keyword, Qualifier, Tag, |
| 1103 |
/*OwnsTag=*/false); |
| 1104 |
} |
| 1105 |
QualType RebuildCanonicalTagType(TagDecl *Tag) { |
| 1106 |
return SemaRef.Context.getCanonicalTagType(Tag); |
| 1107 |
} |
| 1108 |
|
| 1109 |
/// Build a new typeof(expr) type. |
| 1110 |
/// |
| 1111 |
/// By default, performs semantic analysis when building the typeof type. |
| 1112 |
/// Subclasses may override this routine to provide different behavior. |
| 1113 |
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, |
| 1114 |
TypeOfKind Kind); |
| 1115 |
|
| 1116 |
/// Build a new typeof(type) type. |
| 1117 |
/// |
| 1118 |
/// By default, builds a new TypeOfType with the given underlying type. |
| 1119 |
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind); |
| 1120 |
|
| 1121 |
/// Build a new unary transform type. |
| 1122 |
QualType RebuildUnaryTransformType(QualType BaseType, |
| 1123 |
UnaryTransformType::UTTKind UKind, |
| 1124 |
SourceLocation Loc); |
| 1125 |
|
| 1126 |
/// Build a new C++11 decltype type. |
| 1127 |
/// |
| 1128 |
/// By default, performs semantic analysis when building the decltype type. |
| 1129 |
/// Subclasses may override this routine to provide different behavior. |
| 1130 |
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
| 1131 |
|
| 1132 |
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, |
| 1133 |
SourceLocation Loc, |
| 1134 |
SourceLocation EllipsisLoc, |
| 1135 |
bool FullySubstituted, |
| 1136 |
ArrayRef<QualType> Expansions = {}); |
| 1137 |
|
| 1138 |
/// Build a new C++11 auto type. |
| 1139 |
/// |
| 1140 |
/// By default, builds a new AutoType with the given deduced type. |
| 1141 |
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, |
| 1142 |
ConceptDecl *TypeConstraintConcept, |
| 1143 |
ArrayRef<TemplateArgument> TypeConstraintArgs) { |
| 1144 |
// Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 1145 |
// which has been deduced to a dependent type into an undeduced 'auto', so |
| 1146 |
// that we'll retry deduction after the transformation. |
| 1147 |
return SemaRef.Context.getAutoType(Deduced, Keyword, |
| 1148 |
/*IsDependent*/ false, /*IsPack=*/false, |
| 1149 |
TypeConstraintConcept, |
| 1150 |
TypeConstraintArgs); |
| 1151 |
} |
| 1152 |
|
| 1153 |
/// By default, builds a new DeducedTemplateSpecializationType with the given |
| 1154 |
/// deduced type. |
| 1155 |
QualType RebuildDeducedTemplateSpecializationType( |
| 1156 |
ElaboratedTypeKeyword Keyword, TemplateName Template, QualType Deduced) { |
| 1157 |
return SemaRef.Context.getDeducedTemplateSpecializationType( |
| 1158 |
Keyword, Template, Deduced, /*IsDependent*/ false); |
| 1159 |
} |
| 1160 |
|
| 1161 |
/// Build a new template specialization type. |
| 1162 |
/// |
| 1163 |
/// By default, performs semantic analysis when building the template |
| 1164 |
/// specialization type. Subclasses may override this routine to provide |
| 1165 |
/// different behavior. |
| 1166 |
QualType RebuildTemplateSpecializationType(ElaboratedTypeKeyword Keyword, |
| 1167 |
TemplateName Template, |
| 1168 |
SourceLocation TemplateLoc, |
| 1169 |
TemplateArgumentListInfo &Args); |
| 1170 |
|
| 1171 |
/// Build a new parenthesized type. |
| 1172 |
/// |
| 1173 |
/// By default, builds a new ParenType type from the inner type. |
| 1174 |
/// Subclasses may override this routine to provide different behavior. |
| 1175 |
QualType RebuildParenType(QualType InnerType) { |
| 1176 |
return SemaRef.BuildParenType(InnerType); |
| 1177 |
} |
| 1178 |
|
| 1179 |
/// Build a new typename type that refers to an identifier. |
| 1180 |
/// |
| 1181 |
/// By default, performs semantic analysis when building the typename type |
| 1182 |
/// (or elaborated type). Subclasses may override this routine to provide |
| 1183 |
/// different behavior. |
| 1184 |
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 1185 |
SourceLocation KeywordLoc, |
| 1186 |
NestedNameSpecifierLoc QualifierLoc, |
| 1187 |
const IdentifierInfo *Id, |
| 1188 |
SourceLocation IdLoc, |
| 1189 |
bool DeducedTSTContext) { |
| 1190 |
CXXScopeSpec SS; |
| 1191 |
SS.Adopt(QualifierLoc); |
| 1192 |
|
| 1193 |
if (QualifierLoc.getNestedNameSpecifier().isDependent()) { |
| 1194 |
// If the name is still dependent, just build a new dependent name type. |
| 1195 |
if (!SemaRef.computeDeclContext(SS)) |
| 1196 |
return SemaRef.Context.getDependentNameType(Keyword, |
| 1197 |
QualifierLoc.getNestedNameSpecifier(), |
| 1198 |
Id); |
| 1199 |
} |
| 1200 |
|
| 1201 |
if (Keyword == ElaboratedTypeKeyword::None || |
| 1202 |
Keyword == ElaboratedTypeKeyword::Typename) { |
| 1203 |
return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
| 1204 |
*Id, IdLoc, DeducedTSTContext); |
| 1205 |
} |
| 1206 |
|
| 1207 |
TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 1208 |
|
| 1209 |
// We had a dependent elaborated-type-specifier that has been transformed |
| 1210 |
// into a non-dependent elaborated-type-specifier. Find the tag we're |
| 1211 |
// referring to. |
| 1212 |
LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1213 |
DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 1214 |
if (!DC) |
| 1215 |
return QualType(); |
| 1216 |
|
| 1217 |
if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 1218 |
return QualType(); |
| 1219 |
|
| 1220 |
TagDecl *Tag = nullptr; |
| 1221 |
SemaRef.LookupQualifiedName(Result, DC); |
| 1222 |
switch (Result.getResultKind()) { |
| 1223 |
case LookupResultKind::NotFound: |
| 1224 |
case LookupResultKind::NotFoundInCurrentInstantiation: |
| 1225 |
break; |
| 1226 |
|
| 1227 |
case LookupResultKind::Found: |
| 1228 |
Tag = Result.getAsSingle<TagDecl>(); |
| 1229 |
break; |
| 1230 |
|
| 1231 |
case LookupResultKind::FoundOverloaded: |
| 1232 |
case LookupResultKind::FoundUnresolvedValue: |
| 1233 |
llvm_unreachable("Tag lookup cannot find non-tags"); |
| 1234 |
|
| 1235 |
case LookupResultKind::Ambiguous: |
| 1236 |
// Let the LookupResult structure handle ambiguities. |
| 1237 |
return QualType(); |
| 1238 |
} |
| 1239 |
|
| 1240 |
if (!Tag) { |
| 1241 |
// Check where the name exists but isn't a tag type and use that to emit |
| 1242 |
// better diagnostics. |
| 1243 |
LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1244 |
SemaRef.LookupQualifiedName(Result, DC); |
| 1245 |
switch (Result.getResultKind()) { |
| 1246 |
case LookupResultKind::Found: |
| 1247 |
case LookupResultKind::FoundOverloaded: |
| 1248 |
case LookupResultKind::FoundUnresolvedValue: { |
| 1249 |
NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 1250 |
NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); |
| 1251 |
SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) |
| 1252 |
<< SomeDecl << NTK << Kind; |
| 1253 |
SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1254 |
break; |
| 1255 |
} |
| 1256 |
default: |
| 1257 |
SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 1258 |
<< Kind << Id << DC << QualifierLoc.getSourceRange(); |
| 1259 |
break; |
| 1260 |
} |
| 1261 |
return QualType(); |
| 1262 |
} |
| 1263 |
if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 1264 |
IdLoc, Id)) { |
| 1265 |
SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
| 1266 |
SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1267 |
return QualType(); |
| 1268 |
} |
| 1269 |
return getDerived().RebuildTagType( |
| 1270 |
Keyword, QualifierLoc.getNestedNameSpecifier(), Tag); |
| 1271 |
} |
| 1272 |
|
| 1273 |
/// Build a new pack expansion type. |
| 1274 |
/// |
| 1275 |
/// By default, builds a new PackExpansionType type from the given pattern. |
| 1276 |
/// Subclasses may override this routine to provide different behavior. |
| 1277 |
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, |
| 1278 |
SourceLocation EllipsisLoc, |
| 1279 |
UnsignedOrNone NumExpansions) { |
| 1280 |
return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1281 |
NumExpansions); |
| 1282 |
} |
| 1283 |
|
| 1284 |
/// Build a new atomic type given its value type. |
| 1285 |
/// |
| 1286 |
/// By default, performs semantic analysis when building the atomic type. |
| 1287 |
/// Subclasses may override this routine to provide different behavior. |
| 1288 |
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1289 |
|
| 1290 |
/// Build a new pipe type given its value type. |
| 1291 |
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, |
| 1292 |
bool isReadPipe); |
| 1293 |
|
| 1294 |
/// Build a bit-precise int given its value type. |
| 1295 |
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, |
| 1296 |
SourceLocation Loc); |
| 1297 |
|
| 1298 |
/// Build a dependent bit-precise int given its value type. |
| 1299 |
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, |
| 1300 |
SourceLocation Loc); |
| 1301 |
|
| 1302 |
/// Build a new template name given a nested name specifier, a flag |
| 1303 |
/// indicating whether the "template" keyword was provided, and the template |
| 1304 |
/// that the template name refers to. |
| 1305 |
/// |
| 1306 |
/// By default, builds the new template name directly. Subclasses may override |
| 1307 |
/// this routine to provide different behavior. |
| 1308 |
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, |
| 1309 |
TemplateName Name); |
| 1310 |
|
| 1311 |
/// Build a new template name given a nested name specifier and the |
| 1312 |
/// name that is referred to as a template. |
| 1313 |
/// |
| 1314 |
/// By default, performs semantic analysis to determine whether the name can |
| 1315 |
/// be resolved to a specific template, then builds the appropriate kind of |
| 1316 |
/// template name. Subclasses may override this routine to provide different |
| 1317 |
/// behavior. |
| 1318 |
TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1319 |
SourceLocation TemplateKWLoc, |
| 1320 |
const IdentifierInfo &Name, |
| 1321 |
SourceLocation NameLoc, QualType ObjectType, |
| 1322 |
bool AllowInjectedClassName); |
| 1323 |
|
| 1324 |
/// Build a new template name given a nested name specifier and the |
| 1325 |
/// overloaded operator name that is referred to as a template. |
| 1326 |
/// |
| 1327 |
/// By default, performs semantic analysis to determine whether the name can |
| 1328 |
/// be resolved to a specific template, then builds the appropriate kind of |
| 1329 |
/// template name. Subclasses may override this routine to provide different |
| 1330 |
/// behavior. |
| 1331 |
TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1332 |
SourceLocation TemplateKWLoc, |
| 1333 |
OverloadedOperatorKind Operator, |
| 1334 |
SourceLocation NameLoc, QualType ObjectType, |
| 1335 |
bool AllowInjectedClassName); |
| 1336 |
|
| 1337 |
TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1338 |
SourceLocation TemplateKWLoc, |
| 1339 |
IdentifierOrOverloadedOperator IO, |
| 1340 |
SourceLocation NameLoc, QualType ObjectType, |
| 1341 |
bool AllowInjectedClassName); |
| 1342 |
|
| 1343 |
/// Build a new template name given a template template parameter pack |
| 1344 |
/// and the |
| 1345 |
/// |
| 1346 |
/// By default, performs semantic analysis to determine whether the name can |
| 1347 |
/// be resolved to a specific template, then builds the appropriate kind of |
| 1348 |
/// template name. Subclasses may override this routine to provide different |
| 1349 |
/// behavior. |
| 1350 |
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, |
| 1351 |
Decl *AssociatedDecl, unsigned Index, |
| 1352 |
bool Final) { |
| 1353 |
return getSema().Context.getSubstTemplateTemplateParmPack( |
| 1354 |
ArgPack, AssociatedDecl, Index, Final); |
| 1355 |
} |
| 1356 |
|
| 1357 |
/// Build a new compound statement. |
| 1358 |
/// |
| 1359 |
/// By default, performs semantic analysis to build the new statement. |
| 1360 |
/// Subclasses may override this routine to provide different behavior. |
| 1361 |
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 1362 |
MultiStmtArg Statements, |
| 1363 |
SourceLocation RBraceLoc, |
| 1364 |
bool IsStmtExpr) { |
| 1365 |
return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
| 1366 |
IsStmtExpr); |
| 1367 |
} |
| 1368 |
|
| 1369 |
/// Build a new case statement. |
| 1370 |
/// |
| 1371 |
/// By default, performs semantic analysis to build the new statement. |
| 1372 |
/// Subclasses may override this routine to provide different behavior. |
| 1373 |
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 1374 |
Expr *LHS, |
| 1375 |
SourceLocation EllipsisLoc, |
| 1376 |
Expr *RHS, |
| 1377 |
SourceLocation ColonLoc) { |
| 1378 |
return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
| 1379 |
ColonLoc); |
| 1380 |
} |
| 1381 |
|
| 1382 |
/// Attach the body to a new case statement. |
| 1383 |
/// |
| 1384 |
/// By default, performs semantic analysis to build the new statement. |
| 1385 |
/// Subclasses may override this routine to provide different behavior. |
| 1386 |
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
| 1387 |
getSema().ActOnCaseStmtBody(S, Body); |
| 1388 |
return S; |
| 1389 |
} |
| 1390 |
|
| 1391 |
/// Build a new default statement. |
| 1392 |
/// |
| 1393 |
/// By default, performs semantic analysis to build the new statement. |
| 1394 |
/// Subclasses may override this routine to provide different behavior. |
| 1395 |
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
| 1396 |
SourceLocation ColonLoc, |
| 1397 |
Stmt *SubStmt) { |
| 1398 |
return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
| 1399 |
/*CurScope=*/nullptr); |
| 1400 |
} |
| 1401 |
|
| 1402 |
/// Build a new label statement. |
| 1403 |
/// |
| 1404 |
/// By default, performs semantic analysis to build the new statement. |
| 1405 |
/// Subclasses may override this routine to provide different behavior. |
| 1406 |
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1407 |
SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1408 |
return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
| 1409 |
} |
| 1410 |
|
| 1411 |
/// Build a new attributed statement. |
| 1412 |
/// |
| 1413 |
/// By default, performs semantic analysis to build the new statement. |
| 1414 |
/// Subclasses may override this routine to provide different behavior. |
| 1415 |
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1416 |
ArrayRef<const Attr *> Attrs, |
| 1417 |
Stmt *SubStmt) { |
| 1418 |
if (SemaRef.CheckRebuiltStmtAttributes(Attrs)) |
| 1419 |
return StmtError(); |
| 1420 |
return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1421 |
} |
| 1422 |
|
| 1423 |
/// Build a new "if" statement. |
| 1424 |
/// |
| 1425 |
/// By default, performs semantic analysis to build the new statement. |
| 1426 |
/// Subclasses may override this routine to provide different behavior. |
| 1427 |
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, |
| 1428 |
SourceLocation LParenLoc, Sema::ConditionResult Cond, |
| 1429 |
SourceLocation RParenLoc, Stmt *Init, Stmt *Then, |
| 1430 |
SourceLocation ElseLoc, Stmt *Else) { |
| 1431 |
return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc, |
| 1432 |
Then, ElseLoc, Else); |
| 1433 |
} |
| 1434 |
|
| 1435 |
/// Start building a new switch statement. |
| 1436 |
/// |
| 1437 |
/// By default, performs semantic analysis to build the new statement. |
| 1438 |
/// Subclasses may override this routine to provide different behavior. |
| 1439 |
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 1440 |
SourceLocation LParenLoc, Stmt *Init, |
| 1441 |
Sema::ConditionResult Cond, |
| 1442 |
SourceLocation RParenLoc) { |
| 1443 |
return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond, |
| 1444 |
RParenLoc); |
| 1445 |
} |
| 1446 |
|
| 1447 |
/// Attach the body to the switch statement. |
| 1448 |
/// |
| 1449 |
/// By default, performs semantic analysis to build the new statement. |
| 1450 |
/// Subclasses may override this routine to provide different behavior. |
| 1451 |
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
| 1452 |
Stmt *Switch, Stmt *Body) { |
| 1453 |
return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
| 1454 |
} |
| 1455 |
|
| 1456 |
/// Build a new while statement. |
| 1457 |
/// |
| 1458 |
/// By default, performs semantic analysis to build the new statement. |
| 1459 |
/// Subclasses may override this routine to provide different behavior. |
| 1460 |
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1461 |
Sema::ConditionResult Cond, |
| 1462 |
SourceLocation RParenLoc, Stmt *Body) { |
| 1463 |
return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body); |
| 1464 |
} |
| 1465 |
|
| 1466 |
/// Build a new do-while statement. |
| 1467 |
/// |
| 1468 |
/// By default, performs semantic analysis to build the new statement. |
| 1469 |
/// Subclasses may override this routine to provide different behavior. |
| 1470 |
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
| 1471 |
SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1472 |
Expr *Cond, SourceLocation RParenLoc) { |
| 1473 |
return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1474 |
Cond, RParenLoc); |
| 1475 |
} |
| 1476 |
|
| 1477 |
/// Build a new for statement. |
| 1478 |
/// |
| 1479 |
/// By default, performs semantic analysis to build the new statement. |
| 1480 |
/// Subclasses may override this routine to provide different behavior. |
| 1481 |
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1482 |
Stmt *Init, Sema::ConditionResult Cond, |
| 1483 |
Sema::FullExprArg Inc, SourceLocation RParenLoc, |
| 1484 |
Stmt *Body) { |
| 1485 |
return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
| 1486 |
Inc, RParenLoc, Body); |
| 1487 |
} |
| 1488 |
|
| 1489 |
/// Build a new goto statement. |
| 1490 |
/// |
| 1491 |
/// By default, performs semantic analysis to build the new statement. |
| 1492 |
/// Subclasses may override this routine to provide different behavior. |
| 1493 |
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1494 |
LabelDecl *Label) { |
| 1495 |
return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
| 1496 |
} |
| 1497 |
|
| 1498 |
/// Build a new indirect goto statement. |
| 1499 |
/// |
| 1500 |
/// By default, performs semantic analysis to build the new statement. |
| 1501 |
/// Subclasses may override this routine to provide different behavior. |
| 1502 |
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 1503 |
SourceLocation StarLoc, |
| 1504 |
Expr *Target) { |
| 1505 |
return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
| 1506 |
} |
| 1507 |
|
| 1508 |
/// Build a new return statement. |
| 1509 |
/// |
| 1510 |
/// By default, performs semantic analysis to build the new statement. |
| 1511 |
/// Subclasses may override this routine to provide different behavior. |
| 1512 |
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
| 1513 |
return getSema().BuildReturnStmt(ReturnLoc, Result); |
| 1514 |
} |
| 1515 |
|
| 1516 |
/// Build a new declaration statement. |
| 1517 |
/// |
| 1518 |
/// By default, performs semantic analysis to build the new statement. |
| 1519 |
/// Subclasses may override this routine to provide different behavior. |
| 1520 |
StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
| 1521 |
SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1522 |
Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
| 1523 |
return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
| 1524 |
} |
| 1525 |
|
| 1526 |
/// Build a new inline asm statement. |
| 1527 |
/// |
| 1528 |
/// By default, performs semantic analysis to build the new statement. |
| 1529 |
/// Subclasses may override this routine to provide different behavior. |
| 1530 |
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1531 |
bool IsVolatile, unsigned NumOutputs, |
| 1532 |
unsigned NumInputs, IdentifierInfo **Names, |
| 1533 |
MultiExprArg Constraints, MultiExprArg Exprs, |
| 1534 |
Expr *AsmString, MultiExprArg Clobbers, |
| 1535 |
unsigned NumLabels, |
| 1536 |
SourceLocation RParenLoc) { |
| 1537 |
return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1538 |
NumInputs, Names, Constraints, Exprs, |
| 1539 |
AsmString, Clobbers, NumLabels, RParenLoc); |
| 1540 |
} |
| 1541 |
|
| 1542 |
/// Build a new MS style inline asm statement. |
| 1543 |
/// |
| 1544 |
/// By default, performs semantic analysis to build the new statement. |
| 1545 |
/// Subclasses may override this routine to provide different behavior. |
| 1546 |
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 1547 |
ArrayRef<Token> AsmToks, |
| 1548 |
StringRef AsmString, |
| 1549 |
unsigned NumOutputs, unsigned NumInputs, |
| 1550 |
ArrayRef<StringRef> Constraints, |
| 1551 |
ArrayRef<StringRef> Clobbers, |
| 1552 |
ArrayRef<Expr*> Exprs, |
| 1553 |
SourceLocation EndLoc) { |
| 1554 |
return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1555 |
NumOutputs, NumInputs, |
| 1556 |
Constraints, Clobbers, Exprs, EndLoc); |
| 1557 |
} |
| 1558 |
|
| 1559 |
/// Build a new co_return statement. |
| 1560 |
/// |
| 1561 |
/// By default, performs semantic analysis to build the new statement. |
| 1562 |
/// Subclasses may override this routine to provide different behavior. |
| 1563 |
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, |
| 1564 |
bool IsImplicit) { |
| 1565 |
return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); |
| 1566 |
} |
| 1567 |
|
| 1568 |
/// Build a new co_await expression. |
| 1569 |
/// |
| 1570 |
/// By default, performs semantic analysis to build the new expression. |
| 1571 |
/// Subclasses may override this routine to provide different behavior. |
| 1572 |
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, |
| 1573 |
UnresolvedLookupExpr *OpCoawaitLookup, |
| 1574 |
bool IsImplicit) { |
| 1575 |
// This function rebuilds a coawait-expr given its operator. |
| 1576 |
// For an explicit coawait-expr, the rebuild involves the full set |
| 1577 |
// of transformations performed by BuildUnresolvedCoawaitExpr(), |
| 1578 |
// including calling await_transform(). |
| 1579 |
// For an implicit coawait-expr, we need to rebuild the "operator |
| 1580 |
// coawait" but not await_transform(), so use BuildResolvedCoawaitExpr(). |
| 1581 |
// This mirrors how the implicit CoawaitExpr is originally created |
| 1582 |
// in Sema::ActOnCoroutineBodyStart(). |
| 1583 |
if (IsImplicit) { |
| 1584 |
ExprResult Suspend = getSema().BuildOperatorCoawaitCall( |
| 1585 |
CoawaitLoc, Operand, OpCoawaitLookup); |
| 1586 |
if (Suspend.isInvalid()) |
| 1587 |
return ExprError(); |
| 1588 |
return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand, |
| 1589 |
Suspend.get(), true); |
| 1590 |
} |
| 1591 |
|
| 1592 |
return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand, |
| 1593 |
OpCoawaitLookup); |
| 1594 |
} |
| 1595 |
|
| 1596 |
/// Build a new co_await expression. |
| 1597 |
/// |
| 1598 |
/// By default, performs semantic analysis to build the new expression. |
| 1599 |
/// Subclasses may override this routine to provide different behavior. |
| 1600 |
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, |
| 1601 |
Expr *Result, |
| 1602 |
UnresolvedLookupExpr *Lookup) { |
| 1603 |
return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); |
| 1604 |
} |
| 1605 |
|
| 1606 |
/// Build a new co_yield expression. |
| 1607 |
/// |
| 1608 |
/// By default, performs semantic analysis to build the new expression. |
| 1609 |
/// Subclasses may override this routine to provide different behavior. |
| 1610 |
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
| 1611 |
return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
| 1612 |
} |
| 1613 |
|
| 1614 |
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { |
| 1615 |
return getSema().BuildCoroutineBodyStmt(Args); |
| 1616 |
} |
| 1617 |
|
| 1618 |
/// Build a new Objective-C \@try statement. |
| 1619 |
/// |
| 1620 |
/// By default, performs semantic analysis to build the new statement. |
| 1621 |
/// Subclasses may override this routine to provide different behavior. |
| 1622 |
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 1623 |
Stmt *TryBody, |
| 1624 |
MultiStmtArg CatchStmts, |
| 1625 |
Stmt *Finally) { |
| 1626 |
return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
| 1627 |
Finally); |
| 1628 |
} |
| 1629 |
|
| 1630 |
/// Rebuild an Objective-C exception declaration. |
| 1631 |
/// |
| 1632 |
/// By default, performs semantic analysis to build the new declaration. |
| 1633 |
/// Subclasses may override this routine to provide different behavior. |
| 1634 |
VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1635 |
TypeSourceInfo *TInfo, QualType T) { |
| 1636 |
return getSema().ObjC().BuildObjCExceptionDecl( |
| 1637 |
TInfo, T, ExceptionDecl->getInnerLocStart(), |
| 1638 |
ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| 1639 |
} |
| 1640 |
|
| 1641 |
/// Build a new Objective-C \@catch statement. |
| 1642 |
/// |
| 1643 |
/// By default, performs semantic analysis to build the new statement. |
| 1644 |
/// Subclasses may override this routine to provide different behavior. |
| 1645 |
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 1646 |
SourceLocation RParenLoc, |
| 1647 |
VarDecl *Var, |
| 1648 |
Stmt *Body) { |
| 1649 |
return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body); |
| 1650 |
} |
| 1651 |
|
| 1652 |
/// Build a new Objective-C \@finally statement. |
| 1653 |
/// |
| 1654 |
/// By default, performs semantic analysis to build the new statement. |
| 1655 |
/// Subclasses may override this routine to provide different behavior. |
| 1656 |
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 1657 |
Stmt *Body) { |
| 1658 |
return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body); |
| 1659 |
} |
| 1660 |
|
| 1661 |
/// Build a new Objective-C \@throw statement. |
| 1662 |
/// |
| 1663 |
/// By default, performs semantic analysis to build the new statement. |
| 1664 |
/// Subclasses may override this routine to provide different behavior. |
| 1665 |
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 1666 |
Expr *Operand) { |
| 1667 |
return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand); |
| 1668 |
} |
| 1669 |
|
| 1670 |
/// Build a new OpenMP Canonical loop. |
| 1671 |
/// |
| 1672 |
/// Ensures that the outermost loop in @p LoopStmt is wrapped by a |
| 1673 |
/// OMPCanonicalLoop. |
| 1674 |
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt) { |
| 1675 |
return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt); |
| 1676 |
} |
| 1677 |
|
| 1678 |
/// Build a new OpenMP executable directive. |
| 1679 |
/// |
| 1680 |
/// By default, performs semantic analysis to build the new statement. |
| 1681 |
/// Subclasses may override this routine to provide different behavior. |
| 1682 |
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
| 1683 |
DeclarationNameInfo DirName, |
| 1684 |
OpenMPDirectiveKind CancelRegion, |
| 1685 |
ArrayRef<OMPClause *> Clauses, |
| 1686 |
Stmt *AStmt, SourceLocation StartLoc, |
| 1687 |
SourceLocation EndLoc) { |
| 1688 |
|
| 1689 |
return getSema().OpenMP().ActOnOpenMPExecutableDirective( |
| 1690 |
Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
| 1691 |
} |
| 1692 |
|
| 1693 |
/// Build a new OpenMP informational directive. |
| 1694 |
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, |
| 1695 |
DeclarationNameInfo DirName, |
| 1696 |
ArrayRef<OMPClause *> Clauses, |
| 1697 |
Stmt *AStmt, |
| 1698 |
SourceLocation StartLoc, |
| 1699 |
SourceLocation EndLoc) { |
| 1700 |
|
| 1701 |
return getSema().OpenMP().ActOnOpenMPInformationalDirective( |
| 1702 |
Kind, DirName, Clauses, AStmt, StartLoc, EndLoc); |
| 1703 |
} |
| 1704 |
|
| 1705 |
/// Build a new OpenMP 'if' clause. |
| 1706 |
/// |
| 1707 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1708 |
/// Subclasses may override this routine to provide different behavior. |
| 1709 |
OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1710 |
Expr *Condition, SourceLocation StartLoc, |
| 1711 |
SourceLocation LParenLoc, |
| 1712 |
SourceLocation NameModifierLoc, |
| 1713 |
SourceLocation ColonLoc, |
| 1714 |
SourceLocation EndLoc) { |
| 1715 |
return getSema().OpenMP().ActOnOpenMPIfClause( |
| 1716 |
NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc, |
| 1717 |
EndLoc); |
| 1718 |
} |
| 1719 |
|
| 1720 |
/// Build a new OpenMP 'final' clause. |
| 1721 |
/// |
| 1722 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1723 |
/// Subclasses may override this routine to provide different behavior. |
| 1724 |
OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1725 |
SourceLocation LParenLoc, |
| 1726 |
SourceLocation EndLoc) { |
| 1727 |
return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc, |
| 1728 |
LParenLoc, EndLoc); |
| 1729 |
} |
| 1730 |
|
| 1731 |
/// Build a new OpenMP 'num_threads' clause. |
| 1732 |
/// |
| 1733 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1734 |
/// Subclasses may override this routine to provide different behavior. |
| 1735 |
OMPClause *RebuildOMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, |
| 1736 |
Expr *NumThreads, |
| 1737 |
SourceLocation StartLoc, |
| 1738 |
SourceLocation LParenLoc, |
| 1739 |
SourceLocation ModifierLoc, |
| 1740 |
SourceLocation EndLoc) { |
| 1741 |
return getSema().OpenMP().ActOnOpenMPNumThreadsClause( |
| 1742 |
Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc); |
| 1743 |
} |
| 1744 |
|
| 1745 |
/// Build a new OpenMP 'safelen' clause. |
| 1746 |
/// |
| 1747 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1748 |
/// Subclasses may override this routine to provide different behavior. |
| 1749 |
OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1750 |
SourceLocation LParenLoc, |
| 1751 |
SourceLocation EndLoc) { |
| 1752 |
return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, |
| 1753 |
EndLoc); |
| 1754 |
} |
| 1755 |
|
| 1756 |
/// Build a new OpenMP 'simdlen' clause. |
| 1757 |
/// |
| 1758 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1759 |
/// Subclasses may override this routine to provide different behavior. |
| 1760 |
OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1761 |
SourceLocation LParenLoc, |
| 1762 |
SourceLocation EndLoc) { |
| 1763 |
return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, |
| 1764 |
EndLoc); |
| 1765 |
} |
| 1766 |
|
| 1767 |
OMPClause *RebuildOMPSizesClause(ArrayRef<Expr *> Sizes, |
| 1768 |
SourceLocation StartLoc, |
| 1769 |
SourceLocation LParenLoc, |
| 1770 |
SourceLocation EndLoc) { |
| 1771 |
return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, |
| 1772 |
EndLoc); |
| 1773 |
} |
| 1774 |
|
| 1775 |
/// Build a new OpenMP 'permutation' clause. |
| 1776 |
OMPClause *RebuildOMPPermutationClause(ArrayRef<Expr *> PermExprs, |
| 1777 |
SourceLocation StartLoc, |
| 1778 |
SourceLocation LParenLoc, |
| 1779 |
SourceLocation EndLoc) { |
| 1780 |
return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc, |
| 1781 |
LParenLoc, EndLoc); |
| 1782 |
} |
| 1783 |
|
| 1784 |
/// Build a new OpenMP 'full' clause. |
| 1785 |
OMPClause *RebuildOMPFullClause(SourceLocation StartLoc, |
| 1786 |
SourceLocation EndLoc) { |
| 1787 |
return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc); |
| 1788 |
} |
| 1789 |
|
| 1790 |
/// Build a new OpenMP 'partial' clause. |
| 1791 |
OMPClause *RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, |
| 1792 |
SourceLocation LParenLoc, |
| 1793 |
SourceLocation EndLoc) { |
| 1794 |
return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc, |
| 1795 |
LParenLoc, EndLoc); |
| 1796 |
} |
| 1797 |
|
| 1798 |
OMPClause * |
| 1799 |
RebuildOMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, |
| 1800 |
SourceLocation LParenLoc, SourceLocation FirstLoc, |
| 1801 |
SourceLocation CountLoc, SourceLocation EndLoc) { |
| 1802 |
return getSema().OpenMP().ActOnOpenMPLoopRangeClause( |
| 1803 |
First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc); |
| 1804 |
} |
| 1805 |
|
| 1806 |
/// Build a new OpenMP 'allocator' clause. |
| 1807 |
/// |
| 1808 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1809 |
/// Subclasses may override this routine to provide different behavior. |
| 1810 |
OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, |
| 1811 |
SourceLocation LParenLoc, |
| 1812 |
SourceLocation EndLoc) { |
| 1813 |
return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, |
| 1814 |
EndLoc); |
| 1815 |
} |
| 1816 |
|
| 1817 |
/// Build a new OpenMP 'collapse' clause. |
| 1818 |
/// |
| 1819 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1820 |
/// Subclasses may override this routine to provide different behavior. |
| 1821 |
OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1822 |
SourceLocation LParenLoc, |
| 1823 |
SourceLocation EndLoc) { |
| 1824 |
return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc, |
| 1825 |
LParenLoc, EndLoc); |
| 1826 |
} |
| 1827 |
|
| 1828 |
/// Build a new OpenMP 'default' clause. |
| 1829 |
/// |
| 1830 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1831 |
/// Subclasses may override this routine to provide different behavior. |
| 1832 |
OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, |
| 1833 |
OpenMPDefaultClauseVariableCategory VCKind, |
| 1834 |
SourceLocation VCLoc, |
| 1835 |
SourceLocation StartLoc, |
| 1836 |
SourceLocation LParenLoc, |
| 1837 |
SourceLocation EndLoc) { |
| 1838 |
return getSema().OpenMP().ActOnOpenMPDefaultClause( |
| 1839 |
Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc); |
| 1840 |
} |
| 1841 |
|
| 1842 |
/// Build a new OpenMP 'proc_bind' clause. |
| 1843 |
/// |
| 1844 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1845 |
/// Subclasses may override this routine to provide different behavior. |
| 1846 |
OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind, |
| 1847 |
SourceLocation KindKwLoc, |
| 1848 |
SourceLocation StartLoc, |
| 1849 |
SourceLocation LParenLoc, |
| 1850 |
SourceLocation EndLoc) { |
| 1851 |
return getSema().OpenMP().ActOnOpenMPProcBindClause( |
| 1852 |
Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| 1853 |
} |
| 1854 |
|
| 1855 |
/// Build a new OpenMP 'schedule' clause. |
| 1856 |
/// |
| 1857 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1858 |
/// Subclasses may override this routine to provide different behavior. |
| 1859 |
OMPClause *RebuildOMPScheduleClause( |
| 1860 |
OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 1861 |
OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 1862 |
SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 1863 |
SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 1864 |
return getSema().OpenMP().ActOnOpenMPScheduleClause( |
| 1865 |
M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
| 1866 |
CommaLoc, EndLoc); |
| 1867 |
} |
| 1868 |
|
| 1869 |
/// Build a new OpenMP 'ordered' clause. |
| 1870 |
/// |
| 1871 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1872 |
/// Subclasses may override this routine to provide different behavior. |
| 1873 |
OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1874 |
SourceLocation EndLoc, |
| 1875 |
SourceLocation LParenLoc, Expr *Num) { |
| 1876 |
return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc, |
| 1877 |
LParenLoc, Num); |
| 1878 |
} |
| 1879 |
|
| 1880 |
/// Build a new OpenMP 'nowait' clause. |
| 1881 |
/// |
| 1882 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1883 |
/// Subclasses may override this routine to provide different behavior. |
| 1884 |
OMPClause *RebuildOMPNowaitClause(Expr *Condition, SourceLocation StartLoc, |
| 1885 |
SourceLocation LParenLoc, |
| 1886 |
SourceLocation EndLoc) { |
| 1887 |
return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc, |
| 1888 |
LParenLoc, Condition); |
| 1889 |
} |
| 1890 |
|
| 1891 |
/// Build a new OpenMP 'private' clause. |
| 1892 |
/// |
| 1893 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1894 |
/// Subclasses may override this routine to provide different behavior. |
| 1895 |
OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1896 |
SourceLocation StartLoc, |
| 1897 |
SourceLocation LParenLoc, |
| 1898 |
SourceLocation EndLoc) { |
| 1899 |
return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc, |
| 1900 |
LParenLoc, EndLoc); |
| 1901 |
} |
| 1902 |
|
| 1903 |
/// Build a new OpenMP 'firstprivate' clause. |
| 1904 |
/// |
| 1905 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1906 |
/// Subclasses may override this routine to provide different behavior. |
| 1907 |
OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1908 |
SourceLocation StartLoc, |
| 1909 |
SourceLocation LParenLoc, |
| 1910 |
SourceLocation EndLoc) { |
| 1911 |
return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc, |
| 1912 |
LParenLoc, EndLoc); |
| 1913 |
} |
| 1914 |
|
| 1915 |
/// Build a new OpenMP 'lastprivate' clause. |
| 1916 |
/// |
| 1917 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1918 |
/// Subclasses may override this routine to provide different behavior. |
| 1919 |
OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1920 |
OpenMPLastprivateModifier LPKind, |
| 1921 |
SourceLocation LPKindLoc, |
| 1922 |
SourceLocation ColonLoc, |
| 1923 |
SourceLocation StartLoc, |
| 1924 |
SourceLocation LParenLoc, |
| 1925 |
SourceLocation EndLoc) { |
| 1926 |
return getSema().OpenMP().ActOnOpenMPLastprivateClause( |
| 1927 |
VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc); |
| 1928 |
} |
| 1929 |
|
| 1930 |
/// Build a new OpenMP 'shared' clause. |
| 1931 |
/// |
| 1932 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1933 |
/// Subclasses may override this routine to provide different behavior. |
| 1934 |
OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1935 |
SourceLocation StartLoc, |
| 1936 |
SourceLocation LParenLoc, |
| 1937 |
SourceLocation EndLoc) { |
| 1938 |
return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc, |
| 1939 |
LParenLoc, EndLoc); |
| 1940 |
} |
| 1941 |
|
| 1942 |
/// Build a new OpenMP 'reduction' clause. |
| 1943 |
/// |
| 1944 |
/// By default, performs semantic analysis to build the new statement. |
| 1945 |
/// Subclasses may override this routine to provide different behavior. |
| 1946 |
OMPClause *RebuildOMPReductionClause( |
| 1947 |
ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
| 1948 |
OpenMPOriginalSharingModifier OriginalSharingModifier, |
| 1949 |
SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1950 |
SourceLocation ModifierLoc, SourceLocation ColonLoc, |
| 1951 |
SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 1952 |
const DeclarationNameInfo &ReductionId, |
| 1953 |
ArrayRef<Expr *> UnresolvedReductions) { |
| 1954 |
return getSema().OpenMP().ActOnOpenMPReductionClause( |
| 1955 |
VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc, |
| 1956 |
ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId, |
| 1957 |
UnresolvedReductions); |
| 1958 |
} |
| 1959 |
|
| 1960 |
/// Build a new OpenMP 'task_reduction' clause. |
| 1961 |
/// |
| 1962 |
/// By default, performs semantic analysis to build the new statement. |
| 1963 |
/// Subclasses may override this routine to provide different behavior. |
| 1964 |
OMPClause *RebuildOMPTaskReductionClause( |
| 1965 |
ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1966 |
SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 1967 |
CXXScopeSpec &ReductionIdScopeSpec, |
| 1968 |
const DeclarationNameInfo &ReductionId, |
| 1969 |
ArrayRef<Expr *> UnresolvedReductions) { |
| 1970 |
return getSema().OpenMP().ActOnOpenMPTaskReductionClause( |
| 1971 |
VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1972 |
ReductionId, UnresolvedReductions); |
| 1973 |
} |
| 1974 |
|
| 1975 |
/// Build a new OpenMP 'in_reduction' clause. |
| 1976 |
/// |
| 1977 |
/// By default, performs semantic analysis to build the new statement. |
| 1978 |
/// Subclasses may override this routine to provide different behavior. |
| 1979 |
OMPClause * |
| 1980 |
RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1981 |
SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1982 |
SourceLocation EndLoc, |
| 1983 |
CXXScopeSpec &ReductionIdScopeSpec, |
| 1984 |
const DeclarationNameInfo &ReductionId, |
| 1985 |
ArrayRef<Expr *> UnresolvedReductions) { |
| 1986 |
return getSema().OpenMP().ActOnOpenMPInReductionClause( |
| 1987 |
VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1988 |
ReductionId, UnresolvedReductions); |
| 1989 |
} |
| 1990 |
|
| 1991 |
/// Build a new OpenMP 'linear' clause. |
| 1992 |
/// |
| 1993 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 1994 |
/// Subclasses may override this routine to provide different behavior. |
| 1995 |
OMPClause *RebuildOMPLinearClause( |
| 1996 |
ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 1997 |
SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, |
| 1998 |
SourceLocation ModifierLoc, SourceLocation ColonLoc, |
| 1999 |
SourceLocation StepModifierLoc, SourceLocation EndLoc) { |
| 2000 |
return getSema().OpenMP().ActOnOpenMPLinearClause( |
| 2001 |
VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, |
| 2002 |
StepModifierLoc, EndLoc); |
| 2003 |
} |
| 2004 |
|
| 2005 |
/// Build a new OpenMP 'aligned' clause. |
| 2006 |
/// |
| 2007 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2008 |
/// Subclasses may override this routine to provide different behavior. |
| 2009 |
OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 2010 |
SourceLocation StartLoc, |
| 2011 |
SourceLocation LParenLoc, |
| 2012 |
SourceLocation ColonLoc, |
| 2013 |
SourceLocation EndLoc) { |
| 2014 |
return getSema().OpenMP().ActOnOpenMPAlignedClause( |
| 2015 |
VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc); |
| 2016 |
} |
| 2017 |
|
| 2018 |
/// Build a new OpenMP 'copyin' clause. |
| 2019 |
/// |
| 2020 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2021 |
/// Subclasses may override this routine to provide different behavior. |
| 2022 |
OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 2023 |
SourceLocation StartLoc, |
| 2024 |
SourceLocation LParenLoc, |
| 2025 |
SourceLocation EndLoc) { |
| 2026 |
return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc, |
| 2027 |
LParenLoc, EndLoc); |
| 2028 |
} |
| 2029 |
|
| 2030 |
/// Build a new OpenMP 'copyprivate' clause. |
| 2031 |
/// |
| 2032 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2033 |
/// Subclasses may override this routine to provide different behavior. |
| 2034 |
OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 2035 |
SourceLocation StartLoc, |
| 2036 |
SourceLocation LParenLoc, |
| 2037 |
SourceLocation EndLoc) { |
| 2038 |
return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc, |
| 2039 |
LParenLoc, EndLoc); |
| 2040 |
} |
| 2041 |
|
| 2042 |
/// Build a new OpenMP 'flush' pseudo clause. |
| 2043 |
/// |
| 2044 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2045 |
/// Subclasses may override this routine to provide different behavior. |
| 2046 |
OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 2047 |
SourceLocation StartLoc, |
| 2048 |
SourceLocation LParenLoc, |
| 2049 |
SourceLocation EndLoc) { |
| 2050 |
return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc, |
| 2051 |
LParenLoc, EndLoc); |
| 2052 |
} |
| 2053 |
|
| 2054 |
/// Build a new OpenMP 'depobj' pseudo clause. |
| 2055 |
/// |
| 2056 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2057 |
/// Subclasses may override this routine to provide different behavior. |
| 2058 |
OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
| 2059 |
SourceLocation LParenLoc, |
| 2060 |
SourceLocation EndLoc) { |
| 2061 |
return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc, |
| 2062 |
LParenLoc, EndLoc); |
| 2063 |
} |
| 2064 |
|
| 2065 |
/// Build a new OpenMP 'depend' pseudo clause. |
| 2066 |
/// |
| 2067 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2068 |
/// Subclasses may override this routine to provide different behavior. |
| 2069 |
OMPClause *RebuildOMPDependClause(OMPDependClause::DependDataTy Data, |
| 2070 |
Expr *DepModifier, ArrayRef<Expr *> VarList, |
| 2071 |
SourceLocation StartLoc, |
| 2072 |
SourceLocation LParenLoc, |
| 2073 |
SourceLocation EndLoc) { |
| 2074 |
return getSema().OpenMP().ActOnOpenMPDependClause( |
| 2075 |
Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc); |
| 2076 |
} |
| 2077 |
|
| 2078 |
/// Build a new OpenMP 'device' clause. |
| 2079 |
/// |
| 2080 |
/// By default, performs semantic analysis to build the new statement. |
| 2081 |
/// Subclasses may override this routine to provide different behavior. |
| 2082 |
OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
| 2083 |
Expr *Device, SourceLocation StartLoc, |
| 2084 |
SourceLocation LParenLoc, |
| 2085 |
SourceLocation ModifierLoc, |
| 2086 |
SourceLocation EndLoc) { |
| 2087 |
return getSema().OpenMP().ActOnOpenMPDeviceClause( |
| 2088 |
Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc); |
| 2089 |
} |
| 2090 |
|
| 2091 |
/// Build a new OpenMP 'map' clause. |
| 2092 |
/// |
| 2093 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2094 |
/// Subclasses may override this routine to provide different behavior. |
| 2095 |
OMPClause *RebuildOMPMapClause( |
| 2096 |
Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 2097 |
ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 2098 |
CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, |
| 2099 |
OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 2100 |
SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 2101 |
const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
| 2102 |
return getSema().OpenMP().ActOnOpenMPMapClause( |
| 2103 |
IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc, |
| 2104 |
MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc, |
| 2105 |
ColonLoc, VarList, Locs, |
| 2106 |
/*NoDiagnose=*/false, UnresolvedMappers); |
| 2107 |
} |
| 2108 |
|
| 2109 |
/// Build a new OpenMP 'allocate' clause. |
| 2110 |
/// |
| 2111 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2112 |
/// Subclasses may override this routine to provide different behavior. |
| 2113 |
OMPClause * |
| 2114 |
RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, |
| 2115 |
OpenMPAllocateClauseModifier FirstModifier, |
| 2116 |
SourceLocation FirstModifierLoc, |
| 2117 |
OpenMPAllocateClauseModifier SecondModifier, |
| 2118 |
SourceLocation SecondModifierLoc, |
| 2119 |
ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 2120 |
SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 2121 |
SourceLocation EndLoc) { |
| 2122 |
return getSema().OpenMP().ActOnOpenMPAllocateClause( |
| 2123 |
Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier, |
| 2124 |
SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc); |
| 2125 |
} |
| 2126 |
|
| 2127 |
/// Build a new OpenMP 'num_teams' clause. |
| 2128 |
/// |
| 2129 |
/// By default, performs semantic analysis to build the new statement. |
| 2130 |
/// Subclasses may override this routine to provide different behavior. |
| 2131 |
OMPClause *RebuildOMPNumTeamsClause(ArrayRef<Expr *> VarList, |
| 2132 |
SourceLocation StartLoc, |
| 2133 |
SourceLocation LParenLoc, |
| 2134 |
SourceLocation EndLoc) { |
| 2135 |
return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc, |
| 2136 |
LParenLoc, EndLoc); |
| 2137 |
} |
| 2138 |
|
| 2139 |
/// Build a new OpenMP 'thread_limit' clause. |
| 2140 |
/// |
| 2141 |
/// By default, performs semantic analysis to build the new statement. |
| 2142 |
/// Subclasses may override this routine to provide different behavior. |
| 2143 |
OMPClause *RebuildOMPThreadLimitClause(ArrayRef<Expr *> VarList, |
| 2144 |
SourceLocation StartLoc, |
| 2145 |
SourceLocation LParenLoc, |
| 2146 |
SourceLocation EndLoc) { |
| 2147 |
return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc, |
| 2148 |
LParenLoc, EndLoc); |
| 2149 |
} |
| 2150 |
|
| 2151 |
/// Build a new OpenMP 'priority' clause. |
| 2152 |
/// |
| 2153 |
/// By default, performs semantic analysis to build the new statement. |
| 2154 |
/// Subclasses may override this routine to provide different behavior. |
| 2155 |
OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 2156 |
SourceLocation LParenLoc, |
| 2157 |
SourceLocation EndLoc) { |
| 2158 |
return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc, |
| 2159 |
LParenLoc, EndLoc); |
| 2160 |
} |
| 2161 |
|
| 2162 |
/// Build a new OpenMP 'grainsize' clause. |
| 2163 |
/// |
| 2164 |
/// By default, performs semantic analysis to build the new statement. |
| 2165 |
/// Subclasses may override this routine to provide different behavior. |
| 2166 |
OMPClause *RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, |
| 2167 |
Expr *Device, SourceLocation StartLoc, |
| 2168 |
SourceLocation LParenLoc, |
| 2169 |
SourceLocation ModifierLoc, |
| 2170 |
SourceLocation EndLoc) { |
| 2171 |
return getSema().OpenMP().ActOnOpenMPGrainsizeClause( |
| 2172 |
Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc); |
| 2173 |
} |
| 2174 |
|
| 2175 |
/// Build a new OpenMP 'num_tasks' clause. |
| 2176 |
/// |
| 2177 |
/// By default, performs semantic analysis to build the new statement. |
| 2178 |
/// Subclasses may override this routine to provide different behavior. |
| 2179 |
OMPClause *RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, |
| 2180 |
Expr *NumTasks, SourceLocation StartLoc, |
| 2181 |
SourceLocation LParenLoc, |
| 2182 |
SourceLocation ModifierLoc, |
| 2183 |
SourceLocation EndLoc) { |
| 2184 |
return getSema().OpenMP().ActOnOpenMPNumTasksClause( |
| 2185 |
Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc); |
| 2186 |
} |
| 2187 |
|
| 2188 |
/// Build a new OpenMP 'hint' clause. |
| 2189 |
/// |
| 2190 |
/// By default, performs semantic analysis to build the new statement. |
| 2191 |
/// Subclasses may override this routine to provide different behavior. |
| 2192 |
OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 2193 |
SourceLocation LParenLoc, |
| 2194 |
SourceLocation EndLoc) { |
| 2195 |
return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, |
| 2196 |
EndLoc); |
| 2197 |
} |
| 2198 |
|
| 2199 |
/// Build a new OpenMP 'detach' clause. |
| 2200 |
/// |
| 2201 |
/// By default, performs semantic analysis to build the new statement. |
| 2202 |
/// Subclasses may override this routine to provide different behavior. |
| 2203 |
OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
| 2204 |
SourceLocation LParenLoc, |
| 2205 |
SourceLocation EndLoc) { |
| 2206 |
return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, |
| 2207 |
EndLoc); |
| 2208 |
} |
| 2209 |
|
| 2210 |
/// Build a new OpenMP 'dist_schedule' clause. |
| 2211 |
/// |
| 2212 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2213 |
/// Subclasses may override this routine to provide different behavior. |
| 2214 |
OMPClause * |
| 2215 |
RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
| 2216 |
Expr *ChunkSize, SourceLocation StartLoc, |
| 2217 |
SourceLocation LParenLoc, SourceLocation KindLoc, |
| 2218 |
SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 2219 |
return getSema().OpenMP().ActOnOpenMPDistScheduleClause( |
| 2220 |
Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 2221 |
} |
| 2222 |
|
| 2223 |
/// Build a new OpenMP 'to' clause. |
| 2224 |
/// |
| 2225 |
/// By default, performs semantic analysis to build the new statement. |
| 2226 |
/// Subclasses may override this routine to provide different behavior. |
| 2227 |
OMPClause * |
| 2228 |
RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 2229 |
ArrayRef<SourceLocation> MotionModifiersLoc, |
| 2230 |
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, |
| 2231 |
DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 2232 |
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 2233 |
ArrayRef<Expr *> UnresolvedMappers) { |
| 2234 |
return getSema().OpenMP().ActOnOpenMPToClause( |
| 2235 |
MotionModifiers, MotionModifiersLoc, IteratorModifier, |
| 2236 |
MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs, |
| 2237 |
UnresolvedMappers); |
| 2238 |
} |
| 2239 |
|
| 2240 |
/// Build a new OpenMP 'from' clause. |
| 2241 |
/// |
| 2242 |
/// By default, performs semantic analysis to build the new statement. |
| 2243 |
/// Subclasses may override this routine to provide different behavior. |
| 2244 |
OMPClause * |
| 2245 |
RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 2246 |
ArrayRef<SourceLocation> MotionModifiersLoc, |
| 2247 |
Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, |
| 2248 |
DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 2249 |
ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 2250 |
ArrayRef<Expr *> UnresolvedMappers) { |
| 2251 |
return getSema().OpenMP().ActOnOpenMPFromClause( |
| 2252 |
MotionModifiers, MotionModifiersLoc, IteratorModifier, |
| 2253 |
MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs, |
| 2254 |
UnresolvedMappers); |
| 2255 |
} |
| 2256 |
|
| 2257 |
/// Build a new OpenMP 'use_device_ptr' clause. |
| 2258 |
/// |
| 2259 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2260 |
/// Subclasses may override this routine to provide different behavior. |
| 2261 |
OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 2262 |
const OMPVarListLocTy &Locs) { |
| 2263 |
return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
| 2264 |
} |
| 2265 |
|
| 2266 |
/// Build a new OpenMP 'use_device_addr' clause. |
| 2267 |
/// |
| 2268 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2269 |
/// Subclasses may override this routine to provide different behavior. |
| 2270 |
OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
| 2271 |
const OMPVarListLocTy &Locs) { |
| 2272 |
return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs); |
| 2273 |
} |
| 2274 |
|
| 2275 |
/// Build a new OpenMP 'is_device_ptr' clause. |
| 2276 |
/// |
| 2277 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2278 |
/// Subclasses may override this routine to provide different behavior. |
| 2279 |
OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 2280 |
const OMPVarListLocTy &Locs) { |
| 2281 |
return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
| 2282 |
} |
| 2283 |
|
| 2284 |
/// Build a new OpenMP 'has_device_addr' clause. |
| 2285 |
/// |
| 2286 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2287 |
/// Subclasses may override this routine to provide different behavior. |
| 2288 |
OMPClause *RebuildOMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, |
| 2289 |
const OMPVarListLocTy &Locs) { |
| 2290 |
return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs); |
| 2291 |
} |
| 2292 |
|
| 2293 |
/// Build a new OpenMP 'defaultmap' clause. |
| 2294 |
/// |
| 2295 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2296 |
/// Subclasses may override this routine to provide different behavior. |
| 2297 |
OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, |
| 2298 |
OpenMPDefaultmapClauseKind Kind, |
| 2299 |
SourceLocation StartLoc, |
| 2300 |
SourceLocation LParenLoc, |
| 2301 |
SourceLocation MLoc, |
| 2302 |
SourceLocation KindLoc, |
| 2303 |
SourceLocation EndLoc) { |
| 2304 |
return getSema().OpenMP().ActOnOpenMPDefaultmapClause( |
| 2305 |
M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc); |
| 2306 |
} |
| 2307 |
|
| 2308 |
/// Build a new OpenMP 'nontemporal' clause. |
| 2309 |
/// |
| 2310 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2311 |
/// Subclasses may override this routine to provide different behavior. |
| 2312 |
OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList, |
| 2313 |
SourceLocation StartLoc, |
| 2314 |
SourceLocation LParenLoc, |
| 2315 |
SourceLocation EndLoc) { |
| 2316 |
return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc, |
| 2317 |
LParenLoc, EndLoc); |
| 2318 |
} |
| 2319 |
|
| 2320 |
/// Build a new OpenMP 'inclusive' clause. |
| 2321 |
/// |
| 2322 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2323 |
/// Subclasses may override this routine to provide different behavior. |
| 2324 |
OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList, |
| 2325 |
SourceLocation StartLoc, |
| 2326 |
SourceLocation LParenLoc, |
| 2327 |
SourceLocation EndLoc) { |
| 2328 |
return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc, |
| 2329 |
LParenLoc, EndLoc); |
| 2330 |
} |
| 2331 |
|
| 2332 |
/// Build a new OpenMP 'exclusive' clause. |
| 2333 |
/// |
| 2334 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2335 |
/// Subclasses may override this routine to provide different behavior. |
| 2336 |
OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList, |
| 2337 |
SourceLocation StartLoc, |
| 2338 |
SourceLocation LParenLoc, |
| 2339 |
SourceLocation EndLoc) { |
| 2340 |
return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc, |
| 2341 |
LParenLoc, EndLoc); |
| 2342 |
} |
| 2343 |
|
| 2344 |
/// Build a new OpenMP 'uses_allocators' clause. |
| 2345 |
/// |
| 2346 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2347 |
/// Subclasses may override this routine to provide different behavior. |
| 2348 |
OMPClause *RebuildOMPUsesAllocatorsClause( |
| 2349 |
ArrayRef<SemaOpenMP::UsesAllocatorsData> Data, SourceLocation StartLoc, |
| 2350 |
SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 2351 |
return getSema().OpenMP().ActOnOpenMPUsesAllocatorClause( |
| 2352 |
StartLoc, LParenLoc, EndLoc, Data); |
| 2353 |
} |
| 2354 |
|
| 2355 |
/// Build a new OpenMP 'affinity' clause. |
| 2356 |
/// |
| 2357 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2358 |
/// Subclasses may override this routine to provide different behavior. |
| 2359 |
OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc, |
| 2360 |
SourceLocation LParenLoc, |
| 2361 |
SourceLocation ColonLoc, |
| 2362 |
SourceLocation EndLoc, Expr *Modifier, |
| 2363 |
ArrayRef<Expr *> Locators) { |
| 2364 |
return getSema().OpenMP().ActOnOpenMPAffinityClause( |
| 2365 |
StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators); |
| 2366 |
} |
| 2367 |
|
| 2368 |
/// Build a new OpenMP 'order' clause. |
| 2369 |
/// |
| 2370 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2371 |
/// Subclasses may override this routine to provide different behavior. |
| 2372 |
OMPClause *RebuildOMPOrderClause( |
| 2373 |
OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, |
| 2374 |
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, |
| 2375 |
OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) { |
| 2376 |
return getSema().OpenMP().ActOnOpenMPOrderClause( |
| 2377 |
Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc); |
| 2378 |
} |
| 2379 |
|
| 2380 |
/// Build a new OpenMP 'init' clause. |
| 2381 |
/// |
| 2382 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2383 |
/// Subclasses may override this routine to provide different behavior. |
| 2384 |
OMPClause *RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, |
| 2385 |
SourceLocation StartLoc, |
| 2386 |
SourceLocation LParenLoc, |
| 2387 |
SourceLocation VarLoc, |
| 2388 |
SourceLocation EndLoc) { |
| 2389 |
return getSema().OpenMP().ActOnOpenMPInitClause( |
| 2390 |
InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc); |
| 2391 |
} |
| 2392 |
|
| 2393 |
/// Build a new OpenMP 'use' clause. |
| 2394 |
/// |
| 2395 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2396 |
/// Subclasses may override this routine to provide different behavior. |
| 2397 |
OMPClause *RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
| 2398 |
SourceLocation LParenLoc, |
| 2399 |
SourceLocation VarLoc, SourceLocation EndLoc) { |
| 2400 |
return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc, |
| 2401 |
LParenLoc, VarLoc, EndLoc); |
| 2402 |
} |
| 2403 |
|
| 2404 |
/// Build a new OpenMP 'destroy' clause. |
| 2405 |
/// |
| 2406 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2407 |
/// Subclasses may override this routine to provide different behavior. |
| 2408 |
OMPClause *RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
| 2409 |
SourceLocation LParenLoc, |
| 2410 |
SourceLocation VarLoc, |
| 2411 |
SourceLocation EndLoc) { |
| 2412 |
return getSema().OpenMP().ActOnOpenMPDestroyClause( |
| 2413 |
InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc); |
| 2414 |
} |
| 2415 |
|
| 2416 |
/// Build a new OpenMP 'novariants' clause. |
| 2417 |
/// |
| 2418 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2419 |
/// Subclasses may override this routine to provide different behavior. |
| 2420 |
OMPClause *RebuildOMPNovariantsClause(Expr *Condition, |
| 2421 |
SourceLocation StartLoc, |
| 2422 |
SourceLocation LParenLoc, |
| 2423 |
SourceLocation EndLoc) { |
| 2424 |
return getSema().OpenMP().ActOnOpenMPNovariantsClause(Condition, StartLoc, |
| 2425 |
LParenLoc, EndLoc); |
| 2426 |
} |
| 2427 |
|
| 2428 |
/// Build a new OpenMP 'nocontext' clause. |
| 2429 |
/// |
| 2430 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2431 |
/// Subclasses may override this routine to provide different behavior. |
| 2432 |
OMPClause *RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, |
| 2433 |
SourceLocation LParenLoc, |
| 2434 |
SourceLocation EndLoc) { |
| 2435 |
return getSema().OpenMP().ActOnOpenMPNocontextClause(Condition, StartLoc, |
| 2436 |
LParenLoc, EndLoc); |
| 2437 |
} |
| 2438 |
|
| 2439 |
/// Build a new OpenMP 'filter' clause. |
| 2440 |
/// |
| 2441 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2442 |
/// Subclasses may override this routine to provide different behavior. |
| 2443 |
OMPClause *RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
| 2444 |
SourceLocation LParenLoc, |
| 2445 |
SourceLocation EndLoc) { |
| 2446 |
return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc, |
| 2447 |
LParenLoc, EndLoc); |
| 2448 |
} |
| 2449 |
|
| 2450 |
/// Build a new OpenMP 'bind' clause. |
| 2451 |
/// |
| 2452 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2453 |
/// Subclasses may override this routine to provide different behavior. |
| 2454 |
OMPClause *RebuildOMPBindClause(OpenMPBindClauseKind Kind, |
| 2455 |
SourceLocation KindLoc, |
| 2456 |
SourceLocation StartLoc, |
| 2457 |
SourceLocation LParenLoc, |
| 2458 |
SourceLocation EndLoc) { |
| 2459 |
return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, |
| 2460 |
LParenLoc, EndLoc); |
| 2461 |
} |
| 2462 |
|
| 2463 |
/// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause. |
| 2464 |
/// |
| 2465 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2466 |
/// Subclasses may override this routine to provide different behavior. |
| 2467 |
OMPClause *RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, |
| 2468 |
SourceLocation LParenLoc, |
| 2469 |
SourceLocation EndLoc) { |
| 2470 |
return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc, |
| 2471 |
LParenLoc, EndLoc); |
| 2472 |
} |
| 2473 |
|
| 2474 |
/// Build a new OpenMP 'dyn_groupprivate' clause. |
| 2475 |
/// |
| 2476 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2477 |
/// Subclasses may override this routine to provide different behavior. |
| 2478 |
OMPClause *RebuildOMPDynGroupprivateClause( |
| 2479 |
OpenMPDynGroupprivateClauseModifier M1, |
| 2480 |
OpenMPDynGroupprivateClauseFallbackModifier M2, Expr *Size, |
| 2481 |
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, |
| 2482 |
SourceLocation M2Loc, SourceLocation EndLoc) { |
| 2483 |
return getSema().OpenMP().ActOnOpenMPDynGroupprivateClause( |
| 2484 |
M1, M2, Size, StartLoc, LParenLoc, M1Loc, M2Loc, EndLoc); |
| 2485 |
} |
| 2486 |
|
| 2487 |
/// Build a new OpenMP 'ompx_attribute' clause. |
| 2488 |
/// |
| 2489 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2490 |
/// Subclasses may override this routine to provide different behavior. |
| 2491 |
OMPClause *RebuildOMPXAttributeClause(ArrayRef<const Attr *> Attrs, |
| 2492 |
SourceLocation StartLoc, |
| 2493 |
SourceLocation LParenLoc, |
| 2494 |
SourceLocation EndLoc) { |
| 2495 |
return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc, |
| 2496 |
LParenLoc, EndLoc); |
| 2497 |
} |
| 2498 |
|
| 2499 |
/// Build a new OpenMP 'ompx_bare' clause. |
| 2500 |
/// |
| 2501 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2502 |
/// Subclasses may override this routine to provide different behavior. |
| 2503 |
OMPClause *RebuildOMPXBareClause(SourceLocation StartLoc, |
| 2504 |
SourceLocation EndLoc) { |
| 2505 |
return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc); |
| 2506 |
} |
| 2507 |
|
| 2508 |
/// Build a new OpenMP 'align' clause. |
| 2509 |
/// |
| 2510 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2511 |
/// Subclasses may override this routine to provide different behavior. |
| 2512 |
OMPClause *RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, |
| 2513 |
SourceLocation LParenLoc, |
| 2514 |
SourceLocation EndLoc) { |
| 2515 |
return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, |
| 2516 |
EndLoc); |
| 2517 |
} |
| 2518 |
|
| 2519 |
/// Build a new OpenMP 'at' clause. |
| 2520 |
/// |
| 2521 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2522 |
/// Subclasses may override this routine to provide different behavior. |
| 2523 |
OMPClause *RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, |
| 2524 |
SourceLocation StartLoc, |
| 2525 |
SourceLocation LParenLoc, |
| 2526 |
SourceLocation EndLoc) { |
| 2527 |
return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc, |
| 2528 |
LParenLoc, EndLoc); |
| 2529 |
} |
| 2530 |
|
| 2531 |
/// Build a new OpenMP 'severity' clause. |
| 2532 |
/// |
| 2533 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2534 |
/// Subclasses may override this routine to provide different behavior. |
| 2535 |
OMPClause *RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, |
| 2536 |
SourceLocation KwLoc, |
| 2537 |
SourceLocation StartLoc, |
| 2538 |
SourceLocation LParenLoc, |
| 2539 |
SourceLocation EndLoc) { |
| 2540 |
return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc, |
| 2541 |
LParenLoc, EndLoc); |
| 2542 |
} |
| 2543 |
|
| 2544 |
/// Build a new OpenMP 'message' clause. |
| 2545 |
/// |
| 2546 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2547 |
/// Subclasses may override this routine to provide different behavior. |
| 2548 |
OMPClause *RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, |
| 2549 |
SourceLocation LParenLoc, |
| 2550 |
SourceLocation EndLoc) { |
| 2551 |
return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc, |
| 2552 |
EndLoc); |
| 2553 |
} |
| 2554 |
|
| 2555 |
/// Build a new OpenMP 'doacross' clause. |
| 2556 |
/// |
| 2557 |
/// By default, performs semantic analysis to build the new OpenMP clause. |
| 2558 |
/// Subclasses may override this routine to provide different behavior. |
| 2559 |
OMPClause * |
| 2560 |
RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, |
| 2561 |
SourceLocation DepLoc, SourceLocation ColonLoc, |
| 2562 |
ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 2563 |
SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 2564 |
return getSema().OpenMP().ActOnOpenMPDoacrossClause( |
| 2565 |
DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc); |
| 2566 |
} |
| 2567 |
|
| 2568 |
/// Build a new OpenMP 'holds' clause. |
| 2569 |
OMPClause *RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, |
| 2570 |
SourceLocation LParenLoc, |
| 2571 |
SourceLocation EndLoc) { |
| 2572 |
return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc, |
| 2573 |
EndLoc); |
| 2574 |
} |
| 2575 |
|
| 2576 |
/// Rebuild the operand to an Objective-C \@synchronized statement. |
| 2577 |
/// |
| 2578 |
/// By default, performs semantic analysis to build the new statement. |
| 2579 |
/// Subclasses may override this routine to provide different behavior. |
| 2580 |
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 2581 |
Expr *object) { |
| 2582 |
return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 2583 |
} |
| 2584 |
|
| 2585 |
/// Build a new Objective-C \@synchronized statement. |
| 2586 |
/// |
| 2587 |
/// By default, performs semantic analysis to build the new statement. |
| 2588 |
/// Subclasses may override this routine to provide different behavior. |
| 2589 |
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 2590 |
Expr *Object, Stmt *Body) { |
| 2591 |
return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
| 2592 |
} |
| 2593 |
|
| 2594 |
/// Build a new Objective-C \@autoreleasepool statement. |
| 2595 |
/// |
| 2596 |
/// By default, performs semantic analysis to build the new statement. |
| 2597 |
/// Subclasses may override this routine to provide different behavior. |
| 2598 |
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 2599 |
Stmt *Body) { |
| 2600 |
return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 2601 |
} |
| 2602 |
|
| 2603 |
/// Build a new Objective-C fast enumeration statement. |
| 2604 |
/// |
| 2605 |
/// By default, performs semantic analysis to build the new statement. |
| 2606 |
/// Subclasses may override this routine to provide different behavior. |
| 2607 |
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 2608 |
Stmt *Element, |
| 2609 |
Expr *Collection, |
| 2610 |
SourceLocation RParenLoc, |
| 2611 |
Stmt *Body) { |
| 2612 |
StmtResult ForEachStmt = getSema().ObjC().ActOnObjCForCollectionStmt( |
| 2613 |
ForLoc, Element, Collection, RParenLoc); |
| 2614 |
if (ForEachStmt.isInvalid()) |
| 2615 |
return StmtError(); |
| 2616 |
|
| 2617 |
return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(), |
| 2618 |
Body); |
| 2619 |
} |
| 2620 |
|
| 2621 |
/// Build a new C++ exception declaration. |
| 2622 |
/// |
| 2623 |
/// By default, performs semantic analysis to build the new decaration. |
| 2624 |
/// Subclasses may override this routine to provide different behavior. |
| 2625 |
VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 2626 |
TypeSourceInfo *Declarator, |
| 2627 |
SourceLocation StartLoc, |
| 2628 |
SourceLocation IdLoc, |
| 2629 |
IdentifierInfo *Id) { |
| 2630 |
VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
| 2631 |
StartLoc, IdLoc, Id); |
| 2632 |
if (Var) |
| 2633 |
getSema().CurContext->addDecl(Var); |
| 2634 |
return Var; |
| 2635 |
} |
| 2636 |
|
| 2637 |
/// Build a new C++ catch statement. |
| 2638 |
/// |
| 2639 |
/// By default, performs semantic analysis to build the new statement. |
| 2640 |
/// Subclasses may override this routine to provide different behavior. |
| 2641 |
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 2642 |
VarDecl *ExceptionDecl, |
| 2643 |
Stmt *Handler) { |
| 2644 |
return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 2645 |
Handler)); |
| 2646 |
} |
| 2647 |
|
| 2648 |
/// Build a new C++ try statement. |
| 2649 |
/// |
| 2650 |
/// By default, performs semantic analysis to build the new statement. |
| 2651 |
/// Subclasses may override this routine to provide different behavior. |
| 2652 |
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 2653 |
ArrayRef<Stmt *> Handlers) { |
| 2654 |
return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
| 2655 |
} |
| 2656 |
|
| 2657 |
/// Build a new C++0x range-based for statement. |
| 2658 |
/// |
| 2659 |
/// By default, performs semantic analysis to build the new statement. |
| 2660 |
/// Subclasses may override this routine to provide different behavior. |
| 2661 |
StmtResult RebuildCXXForRangeStmt( |
| 2662 |
SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, |
| 2663 |
SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, |
| 2664 |
Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, |
| 2665 |
ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) { |
| 2666 |
// If we've just learned that the range is actually an Objective-C |
| 2667 |
// collection, treat this as an Objective-C fast enumeration loop. |
| 2668 |
if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 2669 |
if (RangeStmt->isSingleDecl()) { |
| 2670 |
if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
| 2671 |
if (RangeVar->isInvalidDecl()) |
| 2672 |
return StmtError(); |
| 2673 |
|
| 2674 |
Expr *RangeExpr = RangeVar->getInit(); |
| 2675 |
if (!RangeExpr->isTypeDependent() && |
| 2676 |
RangeExpr->getType()->isObjCObjectPointerType()) { |
| 2677 |
// FIXME: Support init-statements in Objective-C++20 ranged for |
| 2678 |
// statement. |
| 2679 |
if (Init) { |
| 2680 |
return SemaRef.Diag(Init->getBeginLoc(), |
| 2681 |
diag::err_objc_for_range_init_stmt) |
| 2682 |
<< Init->getSourceRange(); |
| 2683 |
} |
| 2684 |
return getSema().ObjC().ActOnObjCForCollectionStmt( |
| 2685 |
ForLoc, LoopVar, RangeExpr, RParenLoc); |
| 2686 |
} |
| 2687 |
} |
| 2688 |
} |
| 2689 |
} |
| 2690 |
|
| 2691 |
return getSema().BuildCXXForRangeStmt( |
| 2692 |
ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc, |
| 2693 |
LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps); |
| 2694 |
} |
| 2695 |
|
| 2696 |
/// Build a new C++0x range-based for statement. |
| 2697 |
/// |
| 2698 |
/// By default, performs semantic analysis to build the new statement. |
| 2699 |
/// Subclasses may override this routine to provide different behavior. |
| 2700 |
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 2701 |
bool IsIfExists, |
| 2702 |
NestedNameSpecifierLoc QualifierLoc, |
| 2703 |
DeclarationNameInfo NameInfo, |
| 2704 |
Stmt *Nested) { |
| 2705 |
return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 2706 |
QualifierLoc, NameInfo, Nested); |
| 2707 |
} |
| 2708 |
|
| 2709 |
/// Attach body to a C++0x range-based for statement. |
| 2710 |
/// |
| 2711 |
/// By default, performs semantic analysis to finish the new statement. |
| 2712 |
/// Subclasses may override this routine to provide different behavior. |
| 2713 |
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 2714 |
return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 2715 |
} |
| 2716 |
|
| 2717 |
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| 2718 |
Stmt *TryBlock, Stmt *Handler) { |
| 2719 |
return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
| 2720 |
} |
| 2721 |
|
| 2722 |
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
| 2723 |
Stmt *Block) { |
| 2724 |
return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
| 2725 |
} |
| 2726 |
|
| 2727 |
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 2728 |
return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
| 2729 |
} |
| 2730 |
|
| 2731 |
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
| 2732 |
SourceLocation LParen, |
| 2733 |
SourceLocation RParen, |
| 2734 |
TypeSourceInfo *TSI) { |
| 2735 |
return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen, |
| 2736 |
TSI); |
| 2737 |
} |
| 2738 |
|
| 2739 |
/// Build a new predefined expression. |
| 2740 |
/// |
| 2741 |
/// By default, performs semantic analysis to build the new expression. |
| 2742 |
/// Subclasses may override this routine to provide different behavior. |
| 2743 |
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK) { |
| 2744 |
return getSema().BuildPredefinedExpr(Loc, IK); |
| 2745 |
} |
| 2746 |
|
| 2747 |
/// Build a new expression that references a declaration. |
| 2748 |
/// |
| 2749 |
/// By default, performs semantic analysis to build the new expression. |
| 2750 |
/// Subclasses may override this routine to provide different behavior. |
| 2751 |
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 2752 |
LookupResult &R, |
| 2753 |
bool RequiresADL) { |
| 2754 |
return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 2755 |
} |
| 2756 |
|
| 2757 |
|
| 2758 |
/// Build a new expression that references a declaration. |
| 2759 |
/// |
| 2760 |
/// By default, performs semantic analysis to build the new expression. |
| 2761 |
/// Subclasses may override this routine to provide different behavior. |
| 2762 |
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
| 2763 |
ValueDecl *VD, |
| 2764 |
const DeclarationNameInfo &NameInfo, |
| 2765 |
NamedDecl *Found, |
| 2766 |
TemplateArgumentListInfo *TemplateArgs) { |
| 2767 |
CXXScopeSpec SS; |
| 2768 |
SS.Adopt(QualifierLoc); |
| 2769 |
return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found, |
| 2770 |
TemplateArgs); |
| 2771 |
} |
| 2772 |
|
| 2773 |
/// Build a new expression in parentheses. |
| 2774 |
/// |
| 2775 |
/// By default, performs semantic analysis to build the new expression. |
| 2776 |
/// Subclasses may override this routine to provide different behavior. |
| 2777 |
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
| 2778 |
SourceLocation RParen) { |
| 2779 |
return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
| 2780 |
} |
| 2781 |
|
| 2782 |
/// Build a new pseudo-destructor expression. |
| 2783 |
/// |
| 2784 |
/// By default, performs semantic analysis to build the new expression. |
| 2785 |
/// Subclasses may override this routine to provide different behavior. |
| 2786 |
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
| 2787 |
SourceLocation OperatorLoc, |
| 2788 |
bool isArrow, |
| 2789 |
CXXScopeSpec &SS, |
| 2790 |
TypeSourceInfo *ScopeType, |
| 2791 |
SourceLocation CCLoc, |
| 2792 |
SourceLocation TildeLoc, |
| 2793 |
PseudoDestructorTypeStorage Destroyed); |
| 2794 |
|
| 2795 |
/// Build a new unary operator expression. |
| 2796 |
/// |
| 2797 |
/// By default, performs semantic analysis to build the new expression. |
| 2798 |
/// Subclasses may override this routine to provide different behavior. |
| 2799 |
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 2800 |
UnaryOperatorKind Opc, |
| 2801 |
Expr *SubExpr) { |
| 2802 |
return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
| 2803 |
} |
| 2804 |
|
| 2805 |
/// Build a new builtin offsetof expression. |
| 2806 |
/// |
| 2807 |
/// By default, performs semantic analysis to build the new expression. |
| 2808 |
/// Subclasses may override this routine to provide different behavior. |
| 2809 |
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 2810 |
TypeSourceInfo *Type, |
| 2811 |
ArrayRef<Sema::OffsetOfComponent> Components, |
| 2812 |
SourceLocation RParenLoc) { |
| 2813 |
return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 2814 |
RParenLoc); |
| 2815 |
} |
| 2816 |
|
| 2817 |
/// Build a new sizeof, alignof or vec_step expression with a |
| 2818 |
/// type argument. |
| 2819 |
/// |
| 2820 |
/// By default, performs semantic analysis to build the new expression. |
| 2821 |
/// Subclasses may override this routine to provide different behavior. |
| 2822 |
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 2823 |
SourceLocation OpLoc, |
| 2824 |
UnaryExprOrTypeTrait ExprKind, |
| 2825 |
SourceRange R) { |
| 2826 |
return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
| 2827 |
} |
| 2828 |
|
| 2829 |
/// Build a new sizeof, alignof or vec step expression with an |
| 2830 |
/// expression argument. |
| 2831 |
/// |
| 2832 |
/// By default, performs semantic analysis to build the new expression. |
| 2833 |
/// Subclasses may override this routine to provide different behavior. |
| 2834 |
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 2835 |
UnaryExprOrTypeTrait ExprKind, |
| 2836 |
SourceRange R) { |
| 2837 |
ExprResult Result |
| 2838 |
= getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
| 2839 |
if (Result.isInvalid()) |
| 2840 |
return ExprError(); |
| 2841 |
|
| 2842 |
return Result; |
| 2843 |
} |
| 2844 |
|
| 2845 |
/// Build a new array subscript expression. |
| 2846 |
/// |
| 2847 |
/// By default, performs semantic analysis to build the new expression. |
| 2848 |
/// Subclasses may override this routine to provide different behavior. |
| 2849 |
ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
| 2850 |
SourceLocation LBracketLoc, |
| 2851 |
Expr *RHS, |
| 2852 |
SourceLocation RBracketLoc) { |
| 2853 |
return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
| 2854 |
LBracketLoc, RHS, |
| 2855 |
RBracketLoc); |
| 2856 |
} |
| 2857 |
|
| 2858 |
/// Build a new matrix single subscript expression. |
| 2859 |
/// |
| 2860 |
/// By default, performs semantic analysis to build the new expression. |
| 2861 |
/// Subclasses may override this routine to provide different behavior. |
| 2862 |
ExprResult RebuildMatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 2863 |
SourceLocation RBracketLoc) { |
| 2864 |
return getSema().CreateBuiltinMatrixSingleSubscriptExpr(Base, RowIdx, |
| 2865 |
RBracketLoc); |
| 2866 |
} |
| 2867 |
|
| 2868 |
/// Build a new matrix subscript expression. |
| 2869 |
/// |
| 2870 |
/// By default, performs semantic analysis to build the new expression. |
| 2871 |
/// Subclasses may override this routine to provide different behavior. |
| 2872 |
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 2873 |
Expr *ColumnIdx, |
| 2874 |
SourceLocation RBracketLoc) { |
| 2875 |
return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx, |
| 2876 |
RBracketLoc); |
| 2877 |
} |
| 2878 |
|
| 2879 |
/// Build a new array section expression. |
| 2880 |
/// |
| 2881 |
/// By default, performs semantic analysis to build the new expression. |
| 2882 |
/// Subclasses may override this routine to provide different behavior. |
| 2883 |
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, |
| 2884 |
SourceLocation LBracketLoc, |
| 2885 |
Expr *LowerBound, |
| 2886 |
SourceLocation ColonLocFirst, |
| 2887 |
SourceLocation ColonLocSecond, |
| 2888 |
Expr *Length, Expr *Stride, |
| 2889 |
SourceLocation RBracketLoc) { |
| 2890 |
if (IsOMPArraySection) |
| 2891 |
return getSema().OpenMP().ActOnOMPArraySectionExpr( |
| 2892 |
Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length, |
| 2893 |
Stride, RBracketLoc); |
| 2894 |
|
| 2895 |
assert(Stride == nullptr && !ColonLocSecond.isValid() && |
| 2896 |
"Stride/second colon not allowed for OpenACC"); |
| 2897 |
|
| 2898 |
return getSema().OpenACC().ActOnArraySectionExpr( |
| 2899 |
Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc); |
| 2900 |
} |
| 2901 |
|
| 2902 |
/// Build a new array shaping expression. |
| 2903 |
/// |
| 2904 |
/// By default, performs semantic analysis to build the new expression. |
| 2905 |
/// Subclasses may override this routine to provide different behavior. |
| 2906 |
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
| 2907 |
SourceLocation RParenLoc, |
| 2908 |
ArrayRef<Expr *> Dims, |
| 2909 |
ArrayRef<SourceRange> BracketsRanges) { |
| 2910 |
return getSema().OpenMP().ActOnOMPArrayShapingExpr( |
| 2911 |
Base, LParenLoc, RParenLoc, Dims, BracketsRanges); |
| 2912 |
} |
| 2913 |
|
| 2914 |
/// Build a new iterator expression. |
| 2915 |
/// |
| 2916 |
/// By default, performs semantic analysis to build the new expression. |
| 2917 |
/// Subclasses may override this routine to provide different behavior. |
| 2918 |
ExprResult |
| 2919 |
RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, |
| 2920 |
SourceLocation RLoc, |
| 2921 |
ArrayRef<SemaOpenMP::OMPIteratorData> Data) { |
| 2922 |
return getSema().OpenMP().ActOnOMPIteratorExpr( |
| 2923 |
/*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data); |
| 2924 |
} |
| 2925 |
|
| 2926 |
/// Build a new call expression. |
| 2927 |
/// |
| 2928 |
/// By default, performs semantic analysis to build the new expression. |
| 2929 |
/// Subclasses may override this routine to provide different behavior. |
| 2930 |
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
| 2931 |
MultiExprArg Args, |
| 2932 |
SourceLocation RParenLoc, |
| 2933 |
Expr *ExecConfig = nullptr) { |
| 2934 |
return getSema().ActOnCallExpr( |
| 2935 |
/*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig); |
| 2936 |
} |
| 2937 |
|
| 2938 |
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, |
| 2939 |
MultiExprArg Args, |
| 2940 |
SourceLocation RParenLoc) { |
| 2941 |
return getSema().ActOnArraySubscriptExpr( |
| 2942 |
/*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc); |
| 2943 |
} |
| 2944 |
|
| 2945 |
/// Build a new member access expression. |
| 2946 |
/// |
| 2947 |
/// By default, performs semantic analysis to build the new expression. |
| 2948 |
/// Subclasses may override this routine to provide different behavior. |
| 2949 |
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
| 2950 |
bool isArrow, |
| 2951 |
NestedNameSpecifierLoc QualifierLoc, |
| 2952 |
SourceLocation TemplateKWLoc, |
| 2953 |
const DeclarationNameInfo &MemberNameInfo, |
| 2954 |
ValueDecl *Member, |
| 2955 |
NamedDecl *FoundDecl, |
| 2956 |
const TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 2957 |
NamedDecl *FirstQualifierInScope) { |
| 2958 |
ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 2959 |
isArrow); |
| 2960 |
if (!Member->getDeclName()) { |
| 2961 |
// We have a reference to an unnamed field. This is always the |
| 2962 |
// base of an anonymous struct/union member access, i.e. the |
| 2963 |
// field is always of record type. |
| 2964 |
assert(Member->getType()->isRecordType() && |
| 2965 |
"unnamed member not of record type?"); |
| 2966 |
|
| 2967 |
BaseResult = |
| 2968 |
getSema().PerformObjectMemberConversion(BaseResult.get(), |
| 2969 |
QualifierLoc.getNestedNameSpecifier(), |
| 2970 |
FoundDecl, Member); |
| 2971 |
if (BaseResult.isInvalid()) |
| 2972 |
return ExprError(); |
| 2973 |
Base = BaseResult.get(); |
| 2974 |
|
| 2975 |
// `TranformMaterializeTemporaryExpr()` removes materialized temporaries |
| 2976 |
// from the AST, so we need to re-insert them if needed (since |
| 2977 |
// `BuildFieldRefereneExpr()` doesn't do this). |
| 2978 |
if (!isArrow && Base->isPRValue()) { |
| 2979 |
BaseResult = getSema().TemporaryMaterializationConversion(Base); |
| 2980 |
if (BaseResult.isInvalid()) |
| 2981 |
return ExprError(); |
| 2982 |
Base = BaseResult.get(); |
| 2983 |
} |
| 2984 |
|
| 2985 |
CXXScopeSpec EmptySS; |
| 2986 |
return getSema().BuildFieldReferenceExpr( |
| 2987 |
Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), |
| 2988 |
DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), |
| 2989 |
MemberNameInfo); |
| 2990 |
} |
| 2991 |
|
| 2992 |
CXXScopeSpec SS; |
| 2993 |
SS.Adopt(QualifierLoc); |
| 2994 |
|
| 2995 |
Base = BaseResult.get(); |
| 2996 |
if (Base->containsErrors()) |
| 2997 |
return ExprError(); |
| 2998 |
|
| 2999 |
QualType BaseType = Base->getType(); |
| 3000 |
|
| 3001 |
if (isArrow && !BaseType->isPointerType()) |
| 3002 |
return ExprError(); |
| 3003 |
|
| 3004 |
// FIXME: this involves duplicating earlier analysis in a lot of |
| 3005 |
// cases; we should avoid this when possible. |
| 3006 |
LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
| 3007 |
R.addDecl(FoundDecl); |
| 3008 |
R.resolveKind(); |
| 3009 |
|
| 3010 |
if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() && |
| 3011 |
isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) { |
| 3012 |
if (auto *ThisClass = cast<CXXThisExpr>(Base) |
| 3013 |
->getType() |
| 3014 |
->getPointeeType() |
| 3015 |
->getAsCXXRecordDecl()) { |
| 3016 |
auto *Class = cast<CXXRecordDecl>(Member->getDeclContext()); |
| 3017 |
// In unevaluated contexts, an expression supposed to be a member access |
| 3018 |
// might reference a member in an unrelated class. |
| 3019 |
if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class)) |
| 3020 |
return getSema().BuildDeclRefExpr(Member, Member->getType(), |
| 3021 |
VK_LValue, Member->getLocation()); |
| 3022 |
} |
| 3023 |
} |
| 3024 |
|
| 3025 |
return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
| 3026 |
SS, TemplateKWLoc, |
| 3027 |
FirstQualifierInScope, |
| 3028 |
R, ExplicitTemplateArgs, |
| 3029 |
/*S*/nullptr); |
| 3030 |
} |
| 3031 |
|
| 3032 |
/// Build a new binary operator expression. |
| 3033 |
/// |
| 3034 |
/// By default, performs semantic analysis to build the new expression. |
| 3035 |
/// Subclasses may override this routine to provide different behavior. |
| 3036 |
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 3037 |
Expr *LHS, Expr *RHS, |
| 3038 |
bool ForFoldExpression = false) { |
| 3039 |
return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS, |
| 3040 |
ForFoldExpression); |
| 3041 |
} |
| 3042 |
|
| 3043 |
/// Build a new rewritten operator expression. |
| 3044 |
/// |
| 3045 |
/// By default, performs semantic analysis to build the new expression. |
| 3046 |
/// Subclasses may override this routine to provide different behavior. |
| 3047 |
ExprResult RebuildCXXRewrittenBinaryOperator( |
| 3048 |
SourceLocation OpLoc, BinaryOperatorKind Opcode, |
| 3049 |
const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) { |
| 3050 |
return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS, |
| 3051 |
RHS, /*RequiresADL*/false); |
| 3052 |
} |
| 3053 |
|
| 3054 |
/// Build a new conditional operator expression. |
| 3055 |
/// |
| 3056 |
/// By default, performs semantic analysis to build the new expression. |
| 3057 |
/// Subclasses may override this routine to provide different behavior. |
| 3058 |
ExprResult RebuildConditionalOperator(Expr *Cond, |
| 3059 |
SourceLocation QuestionLoc, |
| 3060 |
Expr *LHS, |
| 3061 |
SourceLocation ColonLoc, |
| 3062 |
Expr *RHS) { |
| 3063 |
return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 3064 |
LHS, RHS); |
| 3065 |
} |
| 3066 |
|
| 3067 |
/// Build a new C-style cast expression. |
| 3068 |
/// |
| 3069 |
/// By default, performs semantic analysis to build the new expression. |
| 3070 |
/// Subclasses may override this routine to provide different behavior. |
| 3071 |
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 3072 |
TypeSourceInfo *TInfo, |
| 3073 |
SourceLocation RParenLoc, |
| 3074 |
Expr *SubExpr) { |
| 3075 |
return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 3076 |
SubExpr); |
| 3077 |
} |
| 3078 |
|
| 3079 |
/// Build a new compound literal expression. |
| 3080 |
/// |
| 3081 |
/// By default, performs semantic analysis to build the new expression. |
| 3082 |
/// Subclasses may override this routine to provide different behavior. |
| 3083 |
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 3084 |
TypeSourceInfo *TInfo, |
| 3085 |
SourceLocation RParenLoc, |
| 3086 |
Expr *Init) { |
| 3087 |
return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 3088 |
Init); |
| 3089 |
} |
| 3090 |
|
| 3091 |
/// Build a new extended vector element access expression. |
| 3092 |
/// |
| 3093 |
/// By default, performs semantic analysis to build the new expression. |
| 3094 |
/// Subclasses may override this routine to provide different behavior. |
| 3095 |
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, |
| 3096 |
bool IsArrow, |
| 3097 |
SourceLocation AccessorLoc, |
| 3098 |
IdentifierInfo &Accessor) { |
| 3099 |
|
| 3100 |
CXXScopeSpec SS; |
| 3101 |
DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
| 3102 |
return getSema().BuildMemberReferenceExpr( |
| 3103 |
Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(), |
| 3104 |
/*FirstQualifierInScope*/ nullptr, NameInfo, |
| 3105 |
/* TemplateArgs */ nullptr, |
| 3106 |
/*S*/ nullptr); |
| 3107 |
} |
| 3108 |
|
| 3109 |
/// Build a new initializer list expression. |
| 3110 |
/// |
| 3111 |
/// By default, performs semantic analysis to build the new expression. |
| 3112 |
/// Subclasses may override this routine to provide different behavior. |
| 3113 |
ExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 3114 |
MultiExprArg Inits, |
| 3115 |
SourceLocation RBraceLoc) { |
| 3116 |
return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc); |
| 3117 |
} |
| 3118 |
|
| 3119 |
/// Build a new designated initializer expression. |
| 3120 |
/// |
| 3121 |
/// By default, performs semantic analysis to build the new expression. |
| 3122 |
/// Subclasses may override this routine to provide different behavior. |
| 3123 |
ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 3124 |
MultiExprArg ArrayExprs, |
| 3125 |
SourceLocation EqualOrColonLoc, |
| 3126 |
bool GNUSyntax, |
| 3127 |
Expr *Init) { |
| 3128 |
ExprResult Result |
| 3129 |
= SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 3130 |
Init); |
| 3131 |
if (Result.isInvalid()) |
| 3132 |
return ExprError(); |
| 3133 |
|
| 3134 |
return Result; |
| 3135 |
} |
| 3136 |
|
| 3137 |
/// Build a new value-initialized expression. |
| 3138 |
/// |
| 3139 |
/// By default, builds the implicit value initialization without performing |
| 3140 |
/// any semantic analysis. Subclasses may override this routine to provide |
| 3141 |
/// different behavior. |
| 3142 |
ExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 3143 |
return new (SemaRef.Context) ImplicitValueInitExpr(T); |
| 3144 |
} |
| 3145 |
|
| 3146 |
/// Build a new \c va_arg expression. |
| 3147 |
/// |
| 3148 |
/// By default, performs semantic analysis to build the new expression. |
| 3149 |
/// Subclasses may override this routine to provide different behavior. |
| 3150 |
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| 3151 |
Expr *SubExpr, TypeSourceInfo *TInfo, |
| 3152 |
SourceLocation RParenLoc) { |
| 3153 |
return getSema().BuildVAArgExpr(BuiltinLoc, |
| 3154 |
SubExpr, TInfo, |
| 3155 |
RParenLoc); |
| 3156 |
} |
| 3157 |
|
| 3158 |
/// Build a new expression list in parentheses. |
| 3159 |
/// |
| 3160 |
/// By default, performs semantic analysis to build the new expression. |
| 3161 |
/// Subclasses may override this routine to provide different behavior. |
| 3162 |
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 3163 |
MultiExprArg SubExprs, |
| 3164 |
SourceLocation RParenLoc) { |
| 3165 |
return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
| 3166 |
} |
| 3167 |
|
| 3168 |
ExprResult RebuildCXXParenListInitExpr(ArrayRef<Expr *> Args, QualType T, |
| 3169 |
unsigned NumUserSpecifiedExprs, |
| 3170 |
SourceLocation InitLoc, |
| 3171 |
SourceLocation LParenLoc, |
| 3172 |
SourceLocation RParenLoc) { |
| 3173 |
return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs, |
| 3174 |
InitLoc, LParenLoc, RParenLoc); |
| 3175 |
} |
| 3176 |
|
| 3177 |
/// Build a new address-of-label expression. |
| 3178 |
/// |
| 3179 |
/// By default, performs semantic analysis, using the name of the label |
| 3180 |
/// rather than attempting to map the label statement itself. |
| 3181 |
/// Subclasses may override this routine to provide different behavior. |
| 3182 |
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 3183 |
SourceLocation LabelLoc, LabelDecl *Label) { |
| 3184 |
return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
| 3185 |
} |
| 3186 |
|
| 3187 |
/// Build a new GNU statement expression. |
| 3188 |
/// |
| 3189 |
/// By default, performs semantic analysis to build the new expression. |
| 3190 |
/// Subclasses may override this routine to provide different behavior. |
| 3191 |
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, |
| 3192 |
SourceLocation RParenLoc, unsigned TemplateDepth) { |
| 3193 |
return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc, |
| 3194 |
TemplateDepth); |
| 3195 |
} |
| 3196 |
|
| 3197 |
/// Build a new __builtin_choose_expr expression. |
| 3198 |
/// |
| 3199 |
/// By default, performs semantic analysis to build the new expression. |
| 3200 |
/// Subclasses may override this routine to provide different behavior. |
| 3201 |
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 3202 |
Expr *Cond, Expr *LHS, Expr *RHS, |
| 3203 |
SourceLocation RParenLoc) { |
| 3204 |
return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 3205 |
Cond, LHS, RHS, |
| 3206 |
RParenLoc); |
| 3207 |
} |
| 3208 |
|
| 3209 |
/// Build a new generic selection expression with an expression predicate. |
| 3210 |
/// |
| 3211 |
/// By default, performs semantic analysis to build the new expression. |
| 3212 |
/// Subclasses may override this routine to provide different behavior. |
| 3213 |
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 3214 |
SourceLocation DefaultLoc, |
| 3215 |
SourceLocation RParenLoc, |
| 3216 |
Expr *ControllingExpr, |
| 3217 |
ArrayRef<TypeSourceInfo *> Types, |
| 3218 |
ArrayRef<Expr *> Exprs) { |
| 3219 |
return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 3220 |
/*PredicateIsExpr=*/true, |
| 3221 |
ControllingExpr, Types, Exprs); |
| 3222 |
} |
| 3223 |
|
| 3224 |
/// Build a new generic selection expression with a type predicate. |
| 3225 |
/// |
| 3226 |
/// By default, performs semantic analysis to build the new expression. |
| 3227 |
/// Subclasses may override this routine to provide different behavior. |
| 3228 |
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 3229 |
SourceLocation DefaultLoc, |
| 3230 |
SourceLocation RParenLoc, |
| 3231 |
TypeSourceInfo *ControllingType, |
| 3232 |
ArrayRef<TypeSourceInfo *> Types, |
| 3233 |
ArrayRef<Expr *> Exprs) { |
| 3234 |
return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 3235 |
/*PredicateIsExpr=*/false, |
| 3236 |
ControllingType, Types, Exprs); |
| 3237 |
} |
| 3238 |
|
| 3239 |
/// Build a new overloaded operator call expression. |
| 3240 |
/// |
| 3241 |
/// By default, performs semantic analysis to build the new expression. |
| 3242 |
/// The semantic analysis provides the behavior of template instantiation, |
| 3243 |
/// copying with transformations that turn what looks like an overloaded |
| 3244 |
/// operator call into a use of a builtin operator, performing |
| 3245 |
/// argument-dependent lookup, etc. Subclasses may override this routine to |
| 3246 |
/// provide different behavior. |
| 3247 |
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 3248 |
SourceLocation OpLoc, |
| 3249 |
SourceLocation CalleeLoc, |
| 3250 |
bool RequiresADL, |
| 3251 |
const UnresolvedSetImpl &Functions, |
| 3252 |
Expr *First, Expr *Second); |
| 3253 |
|
| 3254 |
/// Build a new C++ "named" cast expression, such as static_cast or |
| 3255 |
/// reinterpret_cast. |
| 3256 |
/// |
| 3257 |
/// By default, this routine dispatches to one of the more-specific routines |
| 3258 |
/// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
| 3259 |
/// Subclasses may override this routine to provide different behavior. |
| 3260 |
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 3261 |
Stmt::StmtClass Class, |
| 3262 |
SourceLocation LAngleLoc, |
| 3263 |
TypeSourceInfo *TInfo, |
| 3264 |
SourceLocation RAngleLoc, |
| 3265 |
SourceLocation LParenLoc, |
| 3266 |
Expr *SubExpr, |
| 3267 |
SourceLocation RParenLoc) { |
| 3268 |
switch (Class) { |
| 3269 |
case Stmt::CXXStaticCastExprClass: |
| 3270 |
return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
| 3271 |
RAngleLoc, LParenLoc, |
| 3272 |
SubExpr, RParenLoc); |
| 3273 |
|
| 3274 |
case Stmt::CXXDynamicCastExprClass: |
| 3275 |
return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
| 3276 |
RAngleLoc, LParenLoc, |
| 3277 |
SubExpr, RParenLoc); |
| 3278 |
|
| 3279 |
case Stmt::CXXReinterpretCastExprClass: |
| 3280 |
return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
| 3281 |
RAngleLoc, LParenLoc, |
| 3282 |
SubExpr, |
| 3283 |
RParenLoc); |
| 3284 |
|
| 3285 |
case Stmt::CXXConstCastExprClass: |
| 3286 |
return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
| 3287 |
RAngleLoc, LParenLoc, |
| 3288 |
SubExpr, RParenLoc); |
| 3289 |
|
| 3290 |
case Stmt::CXXAddrspaceCastExprClass: |
| 3291 |
return getDerived().RebuildCXXAddrspaceCastExpr( |
| 3292 |
OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc); |
| 3293 |
|
| 3294 |
default: |
| 3295 |
llvm_unreachable("Invalid C++ named cast"); |
| 3296 |
} |
| 3297 |
} |
| 3298 |
|
| 3299 |
/// Build a new C++ static_cast expression. |
| 3300 |
/// |
| 3301 |
/// By default, performs semantic analysis to build the new expression. |
| 3302 |
/// Subclasses may override this routine to provide different behavior. |
| 3303 |
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 3304 |
SourceLocation LAngleLoc, |
| 3305 |
TypeSourceInfo *TInfo, |
| 3306 |
SourceLocation RAngleLoc, |
| 3307 |
SourceLocation LParenLoc, |
| 3308 |
Expr *SubExpr, |
| 3309 |
SourceLocation RParenLoc) { |
| 3310 |
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 3311 |
TInfo, SubExpr, |
| 3312 |
SourceRange(LAngleLoc, RAngleLoc), |
| 3313 |
SourceRange(LParenLoc, RParenLoc)); |
| 3314 |
} |
| 3315 |
|
| 3316 |
/// Build a new C++ dynamic_cast expression. |
| 3317 |
/// |
| 3318 |
/// By default, performs semantic analysis to build the new expression. |
| 3319 |
/// Subclasses may override this routine to provide different behavior. |
| 3320 |
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 3321 |
SourceLocation LAngleLoc, |
| 3322 |
TypeSourceInfo *TInfo, |
| 3323 |
SourceLocation RAngleLoc, |
| 3324 |
SourceLocation LParenLoc, |
| 3325 |
Expr *SubExpr, |
| 3326 |
SourceLocation RParenLoc) { |
| 3327 |
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 3328 |
TInfo, SubExpr, |
| 3329 |
SourceRange(LAngleLoc, RAngleLoc), |
| 3330 |
SourceRange(LParenLoc, RParenLoc)); |
| 3331 |
} |
| 3332 |
|
| 3333 |
/// Build a new C++ reinterpret_cast expression. |
| 3334 |
/// |
| 3335 |
/// By default, performs semantic analysis to build the new expression. |
| 3336 |
/// Subclasses may override this routine to provide different behavior. |
| 3337 |
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 3338 |
SourceLocation LAngleLoc, |
| 3339 |
TypeSourceInfo *TInfo, |
| 3340 |
SourceLocation RAngleLoc, |
| 3341 |
SourceLocation LParenLoc, |
| 3342 |
Expr *SubExpr, |
| 3343 |
SourceLocation RParenLoc) { |
| 3344 |
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 3345 |
TInfo, SubExpr, |
| 3346 |
SourceRange(LAngleLoc, RAngleLoc), |
| 3347 |
SourceRange(LParenLoc, RParenLoc)); |
| 3348 |
} |
| 3349 |
|
| 3350 |
/// Build a new C++ const_cast expression. |
| 3351 |
/// |
| 3352 |
/// By default, performs semantic analysis to build the new expression. |
| 3353 |
/// Subclasses may override this routine to provide different behavior. |
| 3354 |
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 3355 |
SourceLocation LAngleLoc, |
| 3356 |
TypeSourceInfo *TInfo, |
| 3357 |
SourceLocation RAngleLoc, |
| 3358 |
SourceLocation LParenLoc, |
| 3359 |
Expr *SubExpr, |
| 3360 |
SourceLocation RParenLoc) { |
| 3361 |
return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 3362 |
TInfo, SubExpr, |
| 3363 |
SourceRange(LAngleLoc, RAngleLoc), |
| 3364 |
SourceRange(LParenLoc, RParenLoc)); |
| 3365 |
} |
| 3366 |
|
| 3367 |
ExprResult |
| 3368 |
RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, |
| 3369 |
TypeSourceInfo *TInfo, SourceLocation RAngleLoc, |
| 3370 |
SourceLocation LParenLoc, Expr *SubExpr, |
| 3371 |
SourceLocation RParenLoc) { |
| 3372 |
return getSema().BuildCXXNamedCast( |
| 3373 |
OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr, |
| 3374 |
SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); |
| 3375 |
} |
| 3376 |
|
| 3377 |
/// Build a new C++ functional-style cast expression. |
| 3378 |
/// |
| 3379 |
/// By default, performs semantic analysis to build the new expression. |
| 3380 |
/// Subclasses may override this routine to provide different behavior. |
| 3381 |
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 3382 |
SourceLocation LParenLoc, |
| 3383 |
Expr *Sub, |
| 3384 |
SourceLocation RParenLoc, |
| 3385 |
bool ListInitialization) { |
| 3386 |
// If Sub is a ParenListExpr, then Sub is the syntatic form of a |
| 3387 |
// CXXParenListInitExpr. Pass its expanded arguments so that the |
| 3388 |
// CXXParenListInitExpr can be rebuilt. |
| 3389 |
if (auto *PLE = dyn_cast<ParenListExpr>(Sub)) |
| 3390 |
return getSema().BuildCXXTypeConstructExpr( |
| 3391 |
TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()), |
| 3392 |
RParenLoc, ListInitialization); |
| 3393 |
|
| 3394 |
if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub)) |
| 3395 |
return getSema().BuildCXXTypeConstructExpr( |
| 3396 |
TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization); |
| 3397 |
|
| 3398 |
return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
| 3399 |
MultiExprArg(&Sub, 1), RParenLoc, |
| 3400 |
ListInitialization); |
| 3401 |
} |
| 3402 |
|
| 3403 |
/// Build a new C++ __builtin_bit_cast expression. |
| 3404 |
/// |
| 3405 |
/// By default, performs semantic analysis to build the new expression. |
| 3406 |
/// Subclasses may override this routine to provide different behavior. |
| 3407 |
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, |
| 3408 |
TypeSourceInfo *TSI, Expr *Sub, |
| 3409 |
SourceLocation RParenLoc) { |
| 3410 |
return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc); |
| 3411 |
} |
| 3412 |
|
| 3413 |
/// Build a new C++ typeid(type) expression. |
| 3414 |
/// |
| 3415 |
/// By default, performs semantic analysis to build the new expression. |
| 3416 |
/// Subclasses may override this routine to provide different behavior. |
| 3417 |
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 3418 |
SourceLocation TypeidLoc, |
| 3419 |
TypeSourceInfo *Operand, |
| 3420 |
SourceLocation RParenLoc) { |
| 3421 |
return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| 3422 |
RParenLoc); |
| 3423 |
} |
| 3424 |
|
| 3425 |
|
| 3426 |
/// Build a new C++ typeid(expr) expression. |
| 3427 |
/// |
| 3428 |
/// By default, performs semantic analysis to build the new expression. |
| 3429 |
/// Subclasses may override this routine to provide different behavior. |
| 3430 |
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 3431 |
SourceLocation TypeidLoc, |
| 3432 |
Expr *Operand, |
| 3433 |
SourceLocation RParenLoc) { |
| 3434 |
return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| 3435 |
RParenLoc); |
| 3436 |
} |
| 3437 |
|
| 3438 |
/// Build a new C++ __uuidof(type) expression. |
| 3439 |
/// |
| 3440 |
/// By default, performs semantic analysis to build the new expression. |
| 3441 |
/// Subclasses may override this routine to provide different behavior. |
| 3442 |
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, |
| 3443 |
TypeSourceInfo *Operand, |
| 3444 |
SourceLocation RParenLoc) { |
| 3445 |
return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); |
| 3446 |
} |
| 3447 |
|
| 3448 |
/// Build a new C++ __uuidof(expr) expression. |
| 3449 |
/// |
| 3450 |
/// By default, performs semantic analysis to build the new expression. |
| 3451 |
/// Subclasses may override this routine to provide different behavior. |
| 3452 |
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, |
| 3453 |
Expr *Operand, SourceLocation RParenLoc) { |
| 3454 |
return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); |
| 3455 |
} |
| 3456 |
|
| 3457 |
/// Build a new C++ "this" expression. |
| 3458 |
/// |
| 3459 |
/// By default, performs semantic analysis to build a new "this" expression. |
| 3460 |
/// Subclasses may override this routine to provide different behavior. |
| 3461 |
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
| 3462 |
QualType ThisType, |
| 3463 |
bool isImplicit) { |
| 3464 |
if (getSema().CheckCXXThisType(ThisLoc, ThisType)) |
| 3465 |
return ExprError(); |
| 3466 |
return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); |
| 3467 |
} |
| 3468 |
|
| 3469 |
/// Build a new C++ throw expression. |
| 3470 |
/// |
| 3471 |
/// By default, performs semantic analysis to build the new expression. |
| 3472 |
/// Subclasses may override this routine to provide different behavior. |
| 3473 |
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 3474 |
bool IsThrownVariableInScope) { |
| 3475 |
return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
| 3476 |
} |
| 3477 |
|
| 3478 |
/// Build a new C++ default-argument expression. |
| 3479 |
/// |
| 3480 |
/// By default, builds a new default-argument expression, which does not |
| 3481 |
/// require any semantic analysis. Subclasses may override this routine to |
| 3482 |
/// provide different behavior. |
| 3483 |
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, |
| 3484 |
Expr *RewrittenExpr) { |
| 3485 |
return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, |
| 3486 |
RewrittenExpr, getSema().CurContext); |
| 3487 |
} |
| 3488 |
|
| 3489 |
/// Build a new C++11 default-initialization expression. |
| 3490 |
/// |
| 3491 |
/// By default, builds a new default field initialization expression, which |
| 3492 |
/// does not require any semantic analysis. Subclasses may override this |
| 3493 |
/// routine to provide different behavior. |
| 3494 |
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 3495 |
FieldDecl *Field) { |
| 3496 |
return getSema().BuildCXXDefaultInitExpr(Loc, Field); |
| 3497 |
} |
| 3498 |
|
| 3499 |
/// Build a new C++ zero-initialization expression. |
| 3500 |
/// |
| 3501 |
/// By default, performs semantic analysis to build the new expression. |
| 3502 |
/// Subclasses may override this routine to provide different behavior. |
| 3503 |
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 3504 |
SourceLocation LParenLoc, |
| 3505 |
SourceLocation RParenLoc) { |
| 3506 |
return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc, |
| 3507 |
/*ListInitialization=*/false); |
| 3508 |
} |
| 3509 |
|
| 3510 |
/// Build a new C++ "new" expression. |
| 3511 |
/// |
| 3512 |
/// By default, performs semantic analysis to build the new expression. |
| 3513 |
/// Subclasses may override this routine to provide different behavior. |
| 3514 |
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, |
| 3515 |
SourceLocation PlacementLParen, |
| 3516 |
MultiExprArg PlacementArgs, |
| 3517 |
SourceLocation PlacementRParen, |
| 3518 |
SourceRange TypeIdParens, QualType AllocatedType, |
| 3519 |
TypeSourceInfo *AllocatedTypeInfo, |
| 3520 |
std::optional<Expr *> ArraySize, |
| 3521 |
SourceRange DirectInitRange, Expr *Initializer) { |
| 3522 |
return getSema().BuildCXXNew(StartLoc, UseGlobal, |
| 3523 |
PlacementLParen, |
| 3524 |
PlacementArgs, |
| 3525 |
PlacementRParen, |
| 3526 |
TypeIdParens, |
| 3527 |
AllocatedType, |
| 3528 |
AllocatedTypeInfo, |
| 3529 |
ArraySize, |
| 3530 |
DirectInitRange, |
| 3531 |
Initializer); |
| 3532 |
} |
| 3533 |
|
| 3534 |
/// Build a new C++ "delete" expression. |
| 3535 |
/// |
| 3536 |
/// By default, performs semantic analysis to build the new expression. |
| 3537 |
/// Subclasses may override this routine to provide different behavior. |
| 3538 |
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 3539 |
bool IsGlobalDelete, |
| 3540 |
bool IsArrayForm, |
| 3541 |
Expr *Operand) { |
| 3542 |
return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 3543 |
Operand); |
| 3544 |
} |
| 3545 |
|
| 3546 |
/// Build a new type trait expression. |
| 3547 |
/// |
| 3548 |
/// By default, performs semantic analysis to build the new expression. |
| 3549 |
/// Subclasses may override this routine to provide different behavior. |
| 3550 |
ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 3551 |
SourceLocation StartLoc, |
| 3552 |
ArrayRef<TypeSourceInfo *> Args, |
| 3553 |
SourceLocation RParenLoc) { |
| 3554 |
return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 3555 |
} |
| 3556 |
|
| 3557 |
/// Build a new array type trait expression. |
| 3558 |
/// |
| 3559 |
/// By default, performs semantic analysis to build the new expression. |
| 3560 |
/// Subclasses may override this routine to provide different behavior. |
| 3561 |
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 3562 |
SourceLocation StartLoc, |
| 3563 |
TypeSourceInfo *TSInfo, |
| 3564 |
Expr *DimExpr, |
| 3565 |
SourceLocation RParenLoc) { |
| 3566 |
return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 3567 |
} |
| 3568 |
|
| 3569 |
/// Build a new expression trait expression. |
| 3570 |
/// |
| 3571 |
/// By default, performs semantic analysis to build the new expression. |
| 3572 |
/// Subclasses may override this routine to provide different behavior. |
| 3573 |
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 3574 |
SourceLocation StartLoc, |
| 3575 |
Expr *Queried, |
| 3576 |
SourceLocation RParenLoc) { |
| 3577 |
return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 3578 |
} |
| 3579 |
|
| 3580 |
/// Build a new (previously unresolved) declaration reference |
| 3581 |
/// expression. |
| 3582 |
/// |
| 3583 |
/// By default, performs semantic analysis to build the new expression. |
| 3584 |
/// Subclasses may override this routine to provide different behavior. |
| 3585 |
ExprResult RebuildDependentScopeDeclRefExpr( |
| 3586 |
NestedNameSpecifierLoc QualifierLoc, |
| 3587 |
SourceLocation TemplateKWLoc, |
| 3588 |
const DeclarationNameInfo &NameInfo, |
| 3589 |
const TemplateArgumentListInfo *TemplateArgs, |
| 3590 |
bool IsAddressOfOperand, |
| 3591 |
TypeSourceInfo **RecoveryTSI) { |
| 3592 |
CXXScopeSpec SS; |
| 3593 |
SS.Adopt(QualifierLoc); |
| 3594 |
|
| 3595 |
if (TemplateArgs || TemplateKWLoc.isValid()) |
| 3596 |
return getSema().BuildQualifiedTemplateIdExpr( |
| 3597 |
SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand); |
| 3598 |
|
| 3599 |
return getSema().BuildQualifiedDeclarationNameExpr( |
| 3600 |
SS, NameInfo, IsAddressOfOperand, RecoveryTSI); |
| 3601 |
} |
| 3602 |
|
| 3603 |
/// Build a new template-id expression. |
| 3604 |
/// |
| 3605 |
/// By default, performs semantic analysis to build the new expression. |
| 3606 |
/// Subclasses may override this routine to provide different behavior. |
| 3607 |
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 3608 |
SourceLocation TemplateKWLoc, |
| 3609 |
LookupResult &R, |
| 3610 |
bool RequiresADL, |
| 3611 |
const TemplateArgumentListInfo *TemplateArgs) { |
| 3612 |
return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 3613 |
TemplateArgs); |
| 3614 |
} |
| 3615 |
|
| 3616 |
/// Build a new object-construction expression. |
| 3617 |
/// |
| 3618 |
/// By default, performs semantic analysis to build the new expression. |
| 3619 |
/// Subclasses may override this routine to provide different behavior. |
| 3620 |
ExprResult RebuildCXXConstructExpr( |
| 3621 |
QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, |
| 3622 |
bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, |
| 3623 |
bool ListInitialization, bool StdInitListInitialization, |
| 3624 |
bool RequiresZeroInit, CXXConstructionKind ConstructKind, |
| 3625 |
SourceRange ParenRange) { |
| 3626 |
// Reconstruct the constructor we originally found, which might be |
| 3627 |
// different if this is a call to an inherited constructor. |
| 3628 |
CXXConstructorDecl *FoundCtor = Constructor; |
| 3629 |
if (Constructor->isInheritingConstructor()) |
| 3630 |
FoundCtor = Constructor->getInheritedConstructor().getConstructor(); |
| 3631 |
|
| 3632 |
SmallVector<Expr *, 8> ConvertedArgs; |
| 3633 |
if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc, |
| 3634 |
ConvertedArgs)) |
| 3635 |
return ExprError(); |
| 3636 |
|
| 3637 |
return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
| 3638 |
IsElidable, |
| 3639 |
ConvertedArgs, |
| 3640 |
HadMultipleCandidates, |
| 3641 |
ListInitialization, |
| 3642 |
StdInitListInitialization, |
| 3643 |
RequiresZeroInit, ConstructKind, |
| 3644 |
ParenRange); |
| 3645 |
} |
| 3646 |
|
| 3647 |
/// Build a new implicit construction via inherited constructor |
| 3648 |
/// expression. |
| 3649 |
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 3650 |
CXXConstructorDecl *Constructor, |
| 3651 |
bool ConstructsVBase, |
| 3652 |
bool InheritedFromVBase) { |
| 3653 |
return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 3654 |
Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 3655 |
} |
| 3656 |
|
| 3657 |
/// Build a new object-construction expression. |
| 3658 |
/// |
| 3659 |
/// By default, performs semantic analysis to build the new expression. |
| 3660 |
/// Subclasses may override this routine to provide different behavior. |
| 3661 |
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 3662 |
SourceLocation LParenOrBraceLoc, |
| 3663 |
MultiExprArg Args, |
| 3664 |
SourceLocation RParenOrBraceLoc, |
| 3665 |
bool ListInitialization) { |
| 3666 |
return getSema().BuildCXXTypeConstructExpr( |
| 3667 |
TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); |
| 3668 |
} |
| 3669 |
|
| 3670 |
/// Build a new object-construction expression. |
| 3671 |
/// |
| 3672 |
/// By default, performs semantic analysis to build the new expression. |
| 3673 |
/// Subclasses may override this routine to provide different behavior. |
| 3674 |
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 3675 |
SourceLocation LParenLoc, |
| 3676 |
MultiExprArg Args, |
| 3677 |
SourceLocation RParenLoc, |
| 3678 |
bool ListInitialization) { |
| 3679 |
return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, |
| 3680 |
RParenLoc, ListInitialization); |
| 3681 |
} |
| 3682 |
|
| 3683 |
/// Build a new member reference expression. |
| 3684 |
/// |
| 3685 |
/// By default, performs semantic analysis to build the new expression. |
| 3686 |
/// Subclasses may override this routine to provide different behavior. |
| 3687 |
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
| 3688 |
QualType BaseType, |
| 3689 |
bool IsArrow, |
| 3690 |
SourceLocation OperatorLoc, |
| 3691 |
NestedNameSpecifierLoc QualifierLoc, |
| 3692 |
SourceLocation TemplateKWLoc, |
| 3693 |
NamedDecl *FirstQualifierInScope, |
| 3694 |
const DeclarationNameInfo &MemberNameInfo, |
| 3695 |
const TemplateArgumentListInfo *TemplateArgs) { |
| 3696 |
CXXScopeSpec SS; |
| 3697 |
SS.Adopt(QualifierLoc); |
| 3698 |
|
| 3699 |
return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| 3700 |
OperatorLoc, IsArrow, |
| 3701 |
SS, TemplateKWLoc, |
| 3702 |
FirstQualifierInScope, |
| 3703 |
MemberNameInfo, |
| 3704 |
TemplateArgs, /*S*/nullptr); |
| 3705 |
} |
| 3706 |
|
| 3707 |
/// Build a new member reference expression. |
| 3708 |
/// |
| 3709 |
/// By default, performs semantic analysis to build the new expression. |
| 3710 |
/// Subclasses may override this routine to provide different behavior. |
| 3711 |
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 3712 |
SourceLocation OperatorLoc, |
| 3713 |
bool IsArrow, |
| 3714 |
NestedNameSpecifierLoc QualifierLoc, |
| 3715 |
SourceLocation TemplateKWLoc, |
| 3716 |
NamedDecl *FirstQualifierInScope, |
| 3717 |
LookupResult &R, |
| 3718 |
const TemplateArgumentListInfo *TemplateArgs) { |
| 3719 |
CXXScopeSpec SS; |
| 3720 |
SS.Adopt(QualifierLoc); |
| 3721 |
|
| 3722 |
return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| 3723 |
OperatorLoc, IsArrow, |
| 3724 |
SS, TemplateKWLoc, |
| 3725 |
FirstQualifierInScope, |
| 3726 |
R, TemplateArgs, /*S*/nullptr); |
| 3727 |
} |
| 3728 |
|
| 3729 |
/// Build a new noexcept expression. |
| 3730 |
/// |
| 3731 |
/// By default, performs semantic analysis to build the new expression. |
| 3732 |
/// Subclasses may override this routine to provide different behavior. |
| 3733 |
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 3734 |
return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 3735 |
} |
| 3736 |
|
| 3737 |
UnsignedOrNone |
| 3738 |
ComputeSizeOfPackExprWithoutSubstitution(ArrayRef<TemplateArgument> PackArgs); |
| 3739 |
|
| 3740 |
/// Build a new expression to compute the length of a parameter pack. |
| 3741 |
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, |
| 3742 |
SourceLocation PackLoc, |
| 3743 |
SourceLocation RParenLoc, |
| 3744 |
UnsignedOrNone Length, |
| 3745 |
ArrayRef<TemplateArgument> PartialArgs) { |
| 3746 |
return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 3747 |
RParenLoc, Length, PartialArgs); |
| 3748 |
} |
| 3749 |
|
| 3750 |
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, |
| 3751 |
SourceLocation RSquareLoc, |
| 3752 |
Expr *PackIdExpression, Expr *IndexExpr, |
| 3753 |
ArrayRef<Expr *> ExpandedExprs, |
| 3754 |
bool FullySubstituted = false) { |
| 3755 |
return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc, |
| 3756 |
IndexExpr, RSquareLoc, ExpandedExprs, |
| 3757 |
FullySubstituted); |
| 3758 |
} |
| 3759 |
|
| 3760 |
/// Build a new expression representing a call to a source location |
| 3761 |
/// builtin. |
| 3762 |
/// |
| 3763 |
/// By default, performs semantic analysis to build the new expression. |
| 3764 |
/// Subclasses may override this routine to provide different behavior. |
| 3765 |
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, |
| 3766 |
SourceLocation BuiltinLoc, |
| 3767 |
SourceLocation RPLoc, |
| 3768 |
DeclContext *ParentContext) { |
| 3769 |
return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc, |
| 3770 |
ParentContext); |
| 3771 |
} |
| 3772 |
|
| 3773 |
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, |
| 3774 |
SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, |
| 3775 |
NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
| 3776 |
TemplateArgumentListInfo *TALI) { |
| 3777 |
CXXScopeSpec SS; |
| 3778 |
SS.Adopt(NNS); |
| 3779 |
ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc, |
| 3780 |
ConceptNameInfo, |
| 3781 |
FoundDecl, |
| 3782 |
NamedConcept, TALI); |
| 3783 |
if (Result.isInvalid()) |
| 3784 |
return ExprError(); |
| 3785 |
return Result; |
| 3786 |
} |
| 3787 |
|
| 3788 |
/// \brief Build a new requires expression. |
| 3789 |
/// |
| 3790 |
/// By default, performs semantic analysis to build the new expression. |
| 3791 |
/// Subclasses may override this routine to provide different behavior. |
| 3792 |
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, |
| 3793 |
RequiresExprBodyDecl *Body, |
| 3794 |
SourceLocation LParenLoc, |
| 3795 |
ArrayRef<ParmVarDecl *> LocalParameters, |
| 3796 |
SourceLocation RParenLoc, |
| 3797 |
ArrayRef<concepts::Requirement *> Requirements, |
| 3798 |
SourceLocation ClosingBraceLoc) { |
| 3799 |
return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc, |
| 3800 |
LocalParameters, RParenLoc, Requirements, |
| 3801 |
ClosingBraceLoc); |
| 3802 |
} |
| 3803 |
|
| 3804 |
concepts::TypeRequirement * |
| 3805 |
RebuildTypeRequirement( |
| 3806 |
concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { |
| 3807 |
return SemaRef.BuildTypeRequirement(SubstDiag); |
| 3808 |
} |
| 3809 |
|
| 3810 |
concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) { |
| 3811 |
return SemaRef.BuildTypeRequirement(T); |
| 3812 |
} |
| 3813 |
|
| 3814 |
concepts::ExprRequirement * |
| 3815 |
RebuildExprRequirement( |
| 3816 |
concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, |
| 3817 |
SourceLocation NoexceptLoc, |
| 3818 |
concepts::ExprRequirement::ReturnTypeRequirement Ret) { |
| 3819 |
return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc, |
| 3820 |
std::move(Ret)); |
| 3821 |
} |
| 3822 |
|
| 3823 |
concepts::ExprRequirement * |
| 3824 |
RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, |
| 3825 |
concepts::ExprRequirement::ReturnTypeRequirement Ret) { |
| 3826 |
return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc, |
| 3827 |
std::move(Ret)); |
| 3828 |
} |
| 3829 |
|
| 3830 |
concepts::NestedRequirement * |
| 3831 |
RebuildNestedRequirement(StringRef InvalidConstraintEntity, |
| 3832 |
const ASTConstraintSatisfaction &Satisfaction) { |
| 3833 |
return SemaRef.BuildNestedRequirement(InvalidConstraintEntity, |
| 3834 |
Satisfaction); |
| 3835 |
} |
| 3836 |
|
| 3837 |
concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) { |
| 3838 |
return SemaRef.BuildNestedRequirement(Constraint); |
| 3839 |
} |
| 3840 |
|
| 3841 |
/// \brief Build a new Objective-C boxed expression. |
| 3842 |
/// |
| 3843 |
/// By default, performs semantic analysis to build the new expression. |
| 3844 |
/// Subclasses may override this routine to provide different behavior. |
| 3845 |
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 3846 |
return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr); |
| 3847 |
} |
| 3848 |
|
| 3849 |
/// Build a new Objective-C array literal. |
| 3850 |
/// |
| 3851 |
/// By default, performs semantic analysis to build the new expression. |
| 3852 |
/// Subclasses may override this routine to provide different behavior. |
| 3853 |
ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 3854 |
Expr **Elements, unsigned NumElements) { |
| 3855 |
return getSema().ObjC().BuildObjCArrayLiteral( |
| 3856 |
Range, MultiExprArg(Elements, NumElements)); |
| 3857 |
} |
| 3858 |
|
| 3859 |
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| 3860 |
Expr *Base, Expr *Key, |
| 3861 |
ObjCMethodDecl *getterMethod, |
| 3862 |
ObjCMethodDecl *setterMethod) { |
| 3863 |
return getSema().ObjC().BuildObjCSubscriptExpression( |
| 3864 |
RB, Base, Key, getterMethod, setterMethod); |
| 3865 |
} |
| 3866 |
|
| 3867 |
/// Build a new Objective-C dictionary literal. |
| 3868 |
/// |
| 3869 |
/// By default, performs semantic analysis to build the new expression. |
| 3870 |
/// Subclasses may override this routine to provide different behavior. |
| 3871 |
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 3872 |
MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 3873 |
return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements); |
| 3874 |
} |
| 3875 |
|
| 3876 |
/// Build a new Objective-C \@encode expression. |
| 3877 |
/// |
| 3878 |
/// By default, performs semantic analysis to build the new expression. |
| 3879 |
/// Subclasses may override this routine to provide different behavior. |
| 3880 |
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 3881 |
TypeSourceInfo *EncodeTypeInfo, |
| 3882 |
SourceLocation RParenLoc) { |
| 3883 |
return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, |
| 3884 |
RParenLoc); |
| 3885 |
} |
| 3886 |
|
| 3887 |
/// Build a new Objective-C class message. |
| 3888 |
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 3889 |
Selector Sel, |
| 3890 |
ArrayRef<SourceLocation> SelectorLocs, |
| 3891 |
ObjCMethodDecl *Method, |
| 3892 |
SourceLocation LBracLoc, |
| 3893 |
MultiExprArg Args, |
| 3894 |
SourceLocation RBracLoc) { |
| 3895 |
return SemaRef.ObjC().BuildClassMessage( |
| 3896 |
ReceiverTypeInfo, ReceiverTypeInfo->getType(), |
| 3897 |
/*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs, |
| 3898 |
RBracLoc, Args); |
| 3899 |
} |
| 3900 |
|
| 3901 |
/// Build a new Objective-C instance message. |
| 3902 |
ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
| 3903 |
Selector Sel, |
| 3904 |
ArrayRef<SourceLocation> SelectorLocs, |
| 3905 |
ObjCMethodDecl *Method, |
| 3906 |
SourceLocation LBracLoc, |
| 3907 |
MultiExprArg Args, |
| 3908 |
SourceLocation RBracLoc) { |
| 3909 |
return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(), |
| 3910 |
/*SuperLoc=*/SourceLocation(), |
| 3911 |
Sel, Method, LBracLoc, |
| 3912 |
SelectorLocs, RBracLoc, Args); |
| 3913 |
} |
| 3914 |
|
| 3915 |
/// Build a new Objective-C instance/class message to 'super'. |
| 3916 |
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 3917 |
Selector Sel, |
| 3918 |
ArrayRef<SourceLocation> SelectorLocs, |
| 3919 |
QualType SuperType, |
| 3920 |
ObjCMethodDecl *Method, |
| 3921 |
SourceLocation LBracLoc, |
| 3922 |
MultiExprArg Args, |
| 3923 |
SourceLocation RBracLoc) { |
| 3924 |
return Method->isInstanceMethod() |
| 3925 |
? SemaRef.ObjC().BuildInstanceMessage( |
| 3926 |
nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc, |
| 3927 |
SelectorLocs, RBracLoc, Args) |
| 3928 |
: SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc, |
| 3929 |
Sel, Method, LBracLoc, |
| 3930 |
SelectorLocs, RBracLoc, Args); |
| 3931 |
} |
| 3932 |
|
| 3933 |
/// Build a new Objective-C ivar reference expression. |
| 3934 |
/// |
| 3935 |
/// By default, performs semantic analysis to build the new expression. |
| 3936 |
/// Subclasses may override this routine to provide different behavior. |
| 3937 |
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
| 3938 |
SourceLocation IvarLoc, |
| 3939 |
bool IsArrow, bool IsFreeIvar) { |
| 3940 |
CXXScopeSpec SS; |
| 3941 |
DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 3942 |
ExprResult Result = getSema().BuildMemberReferenceExpr( |
| 3943 |
BaseArg, BaseArg->getType(), |
| 3944 |
/*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), |
| 3945 |
/*FirstQualifierInScope=*/nullptr, NameInfo, |
| 3946 |
/*TemplateArgs=*/nullptr, |
| 3947 |
/*S=*/nullptr); |
| 3948 |
if (IsFreeIvar && Result.isUsable()) |
| 3949 |
cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); |
| 3950 |
return Result; |
| 3951 |
} |
| 3952 |
|
| 3953 |
/// Build a new Objective-C property reference expression. |
| 3954 |
/// |
| 3955 |
/// By default, performs semantic analysis to build the new expression. |
| 3956 |
/// Subclasses may override this routine to provide different behavior. |
| 3957 |
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
| 3958 |
ObjCPropertyDecl *Property, |
| 3959 |
SourceLocation PropertyLoc) { |
| 3960 |
CXXScopeSpec SS; |
| 3961 |
DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 3962 |
return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3963 |
/*FIXME:*/PropertyLoc, |
| 3964 |
/*IsArrow=*/false, |
| 3965 |
SS, SourceLocation(), |
| 3966 |
/*FirstQualifierInScope=*/nullptr, |
| 3967 |
NameInfo, |
| 3968 |
/*TemplateArgs=*/nullptr, |
| 3969 |
/*S=*/nullptr); |
| 3970 |
} |
| 3971 |
|
| 3972 |
/// Build a new Objective-C property reference expression. |
| 3973 |
/// |
| 3974 |
/// By default, performs semantic analysis to build the new expression. |
| 3975 |
/// Subclasses may override this routine to provide different behavior. |
| 3976 |
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 3977 |
ObjCMethodDecl *Getter, |
| 3978 |
ObjCMethodDecl *Setter, |
| 3979 |
SourceLocation PropertyLoc) { |
| 3980 |
// Since these expressions can only be value-dependent, we do not |
| 3981 |
// need to perform semantic analysis again. |
| 3982 |
return Owned( |
| 3983 |
new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 3984 |
VK_LValue, OK_ObjCProperty, |
| 3985 |
PropertyLoc, Base)); |
| 3986 |
} |
| 3987 |
|
| 3988 |
/// Build a new Objective-C "isa" expression. |
| 3989 |
/// |
| 3990 |
/// By default, performs semantic analysis to build the new expression. |
| 3991 |
/// Subclasses may override this routine to provide different behavior. |
| 3992 |
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
| 3993 |
SourceLocation OpLoc, bool IsArrow) { |
| 3994 |
CXXScopeSpec SS; |
| 3995 |
DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); |
| 3996 |
return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3997 |
OpLoc, IsArrow, |
| 3998 |
SS, SourceLocation(), |
| 3999 |
/*FirstQualifierInScope=*/nullptr, |
| 4000 |
NameInfo, |
| 4001 |
/*TemplateArgs=*/nullptr, |
| 4002 |
/*S=*/nullptr); |
| 4003 |
} |
| 4004 |
|
| 4005 |
/// Build a new shuffle vector expression. |
| 4006 |
/// |
| 4007 |
/// By default, performs semantic analysis to build the new expression. |
| 4008 |
/// Subclasses may override this routine to provide different behavior. |
| 4009 |
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 4010 |
MultiExprArg SubExprs, |
| 4011 |
SourceLocation RParenLoc) { |
| 4012 |
// Find the declaration for __builtin_shufflevector |
| 4013 |
const IdentifierInfo &Name |
| 4014 |
= SemaRef.Context.Idents.get("__builtin_shufflevector"); |
| 4015 |
TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 4016 |
DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 4017 |
assert(!Lookup.empty() && "No __builtin_shufflevector?"); |
| 4018 |
|
| 4019 |
// Build a reference to the __builtin_shufflevector builtin |
| 4020 |
FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
| 4021 |
Expr *Callee = new (SemaRef.Context) |
| 4022 |
DeclRefExpr(SemaRef.Context, Builtin, false, |
| 4023 |
SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc); |
| 4024 |
QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 4025 |
Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 4026 |
CK_BuiltinFnToFnPtr).get(); |
| 4027 |
|
| 4028 |
// Build the CallExpr |
| 4029 |
ExprResult TheCall = CallExpr::Create( |
| 4030 |
SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| 4031 |
Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc, |
| 4032 |
FPOptionsOverride()); |
| 4033 |
|
| 4034 |
// Type-check the __builtin_shufflevector expression. |
| 4035 |
return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
| 4036 |
} |
| 4037 |
|
| 4038 |
/// Build a new convert vector expression. |
| 4039 |
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 4040 |
Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 4041 |
SourceLocation RParenLoc) { |
| 4042 |
return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc); |
| 4043 |
} |
| 4044 |
|
| 4045 |
/// Build a new template argument pack expansion. |
| 4046 |
/// |
| 4047 |
/// By default, performs semantic analysis to build a new pack expansion |
| 4048 |
/// for a template argument. Subclasses may override this routine to provide |
| 4049 |
/// different behavior. |
| 4050 |
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
| 4051 |
SourceLocation EllipsisLoc, |
| 4052 |
UnsignedOrNone NumExpansions) { |
| 4053 |
switch (Pattern.getArgument().getKind()) { |
| 4054 |
case TemplateArgument::Expression: { |
| 4055 |
ExprResult Result |
| 4056 |
= getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 4057 |
EllipsisLoc, NumExpansions); |
| 4058 |
if (Result.isInvalid()) |
| 4059 |
return TemplateArgumentLoc(); |
| 4060 |
|
| 4061 |
return TemplateArgumentLoc(TemplateArgument(Result.get(), |
| 4062 |
/*IsCanonical=*/false), |
| 4063 |
Result.get()); |
| 4064 |
} |
| 4065 |
|
| 4066 |
case TemplateArgument::Template: |
| 4067 |
return TemplateArgumentLoc( |
| 4068 |
SemaRef.Context, |
| 4069 |
TemplateArgument(Pattern.getArgument().getAsTemplate(), |
| 4070 |
NumExpansions), |
| 4071 |
Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(), |
| 4072 |
Pattern.getTemplateNameLoc(), EllipsisLoc); |
| 4073 |
|
| 4074 |
case TemplateArgument::Null: |
| 4075 |
case TemplateArgument::Integral: |
| 4076 |
case TemplateArgument::Declaration: |
| 4077 |
case TemplateArgument::StructuralValue: |
| 4078 |
case TemplateArgument::Pack: |
| 4079 |
case TemplateArgument::TemplateExpansion: |
| 4080 |
case TemplateArgument::NullPtr: |
| 4081 |
llvm_unreachable("Pack expansion pattern has no parameter packs"); |
| 4082 |
|
| 4083 |
case TemplateArgument::Type: |
| 4084 |
if (TypeSourceInfo *Expansion |
| 4085 |
= getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
| 4086 |
EllipsisLoc, |
| 4087 |
NumExpansions)) |
| 4088 |
return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 4089 |
Expansion); |
| 4090 |
break; |
| 4091 |
} |
| 4092 |
|
| 4093 |
return TemplateArgumentLoc(); |
| 4094 |
} |
| 4095 |
|
| 4096 |
/// Build a new expression pack expansion. |
| 4097 |
/// |
| 4098 |
/// By default, performs semantic analysis to build a new pack expansion |
| 4099 |
/// for an expression. Subclasses may override this routine to provide |
| 4100 |
/// different behavior. |
| 4101 |
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 4102 |
UnsignedOrNone NumExpansions) { |
| 4103 |
return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
| 4104 |
} |
| 4105 |
|
| 4106 |
/// Build a new C++1z fold-expression. |
| 4107 |
/// |
| 4108 |
/// By default, performs semantic analysis in order to build a new fold |
| 4109 |
/// expression. |
| 4110 |
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, |
| 4111 |
SourceLocation LParenLoc, Expr *LHS, |
| 4112 |
BinaryOperatorKind Operator, |
| 4113 |
SourceLocation EllipsisLoc, Expr *RHS, |
| 4114 |
SourceLocation RParenLoc, |
| 4115 |
UnsignedOrNone NumExpansions) { |
| 4116 |
return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator, |
| 4117 |
EllipsisLoc, RHS, RParenLoc, |
| 4118 |
NumExpansions); |
| 4119 |
} |
| 4120 |
|
| 4121 |
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
| 4122 |
LambdaScopeInfo *LSI) { |
| 4123 |
for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) { |
| 4124 |
if (Expr *Init = PVD->getInit()) |
| 4125 |
LSI->ContainsUnexpandedParameterPack |= |
| 4126 |
Init->containsUnexpandedParameterPack(); |
| 4127 |
else if (PVD->hasUninstantiatedDefaultArg()) |
| 4128 |
LSI->ContainsUnexpandedParameterPack |= |
| 4129 |
PVD->getUninstantiatedDefaultArg() |
| 4130 |
->containsUnexpandedParameterPack(); |
| 4131 |
} |
| 4132 |
return getSema().BuildLambdaExpr(StartLoc, EndLoc); |
| 4133 |
} |
| 4134 |
|
| 4135 |
/// Build an empty C++1z fold-expression with the given operator. |
| 4136 |
/// |
| 4137 |
/// By default, produces the fallback value for the fold-expression, or |
| 4138 |
/// produce an error if there is no fallback value. |
| 4139 |
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 4140 |
BinaryOperatorKind Operator) { |
| 4141 |
return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 4142 |
} |
| 4143 |
|
| 4144 |
/// Build a new atomic operation expression. |
| 4145 |
/// |
| 4146 |
/// By default, performs semantic analysis to build the new expression. |
| 4147 |
/// Subclasses may override this routine to provide different behavior. |
| 4148 |
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, |
| 4149 |
AtomicExpr::AtomicOp Op, |
| 4150 |
SourceLocation RParenLoc) { |
| 4151 |
// Use this for all of the locations, since we don't know the difference |
| 4152 |
// between the call and the expr at this point. |
| 4153 |
SourceRange Range{BuiltinLoc, RParenLoc}; |
| 4154 |
return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op, |
| 4155 |
Sema::AtomicArgumentOrder::AST); |
| 4156 |
} |
| 4157 |
|
| 4158 |
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, |
| 4159 |
ArrayRef<Expr *> SubExprs, QualType Type) { |
| 4160 |
return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type); |
| 4161 |
} |
| 4162 |
|
| 4163 |
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, |
| 4164 |
SourceLocation BeginLoc, |
| 4165 |
SourceLocation DirLoc, |
| 4166 |
SourceLocation EndLoc, |
| 4167 |
ArrayRef<OpenACCClause *> Clauses, |
| 4168 |
StmtResult StrBlock) { |
| 4169 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4170 |
K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {}, |
| 4171 |
OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock); |
| 4172 |
} |
| 4173 |
|
| 4174 |
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, |
| 4175 |
SourceLocation DirLoc, |
| 4176 |
SourceLocation EndLoc, |
| 4177 |
ArrayRef<OpenACCClause *> Clauses, |
| 4178 |
StmtResult Loop) { |
| 4179 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4180 |
OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{}, |
| 4181 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4182 |
Clauses, Loop); |
| 4183 |
} |
| 4184 |
|
| 4185 |
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, |
| 4186 |
SourceLocation BeginLoc, |
| 4187 |
SourceLocation DirLoc, |
| 4188 |
SourceLocation EndLoc, |
| 4189 |
ArrayRef<OpenACCClause *> Clauses, |
| 4190 |
StmtResult Loop) { |
| 4191 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4192 |
K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {}, |
| 4193 |
OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop); |
| 4194 |
} |
| 4195 |
|
| 4196 |
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, |
| 4197 |
SourceLocation DirLoc, |
| 4198 |
SourceLocation EndLoc, |
| 4199 |
ArrayRef<OpenACCClause *> Clauses, |
| 4200 |
StmtResult StrBlock) { |
| 4201 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4202 |
OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{}, |
| 4203 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4204 |
Clauses, StrBlock); |
| 4205 |
} |
| 4206 |
|
| 4207 |
StmtResult |
| 4208 |
RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, |
| 4209 |
SourceLocation DirLoc, SourceLocation EndLoc, |
| 4210 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4211 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4212 |
OpenACCDirectiveKind::EnterData, BeginLoc, DirLoc, SourceLocation{}, |
| 4213 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4214 |
Clauses, {}); |
| 4215 |
} |
| 4216 |
|
| 4217 |
StmtResult |
| 4218 |
RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, |
| 4219 |
SourceLocation DirLoc, SourceLocation EndLoc, |
| 4220 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4221 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4222 |
OpenACCDirectiveKind::ExitData, BeginLoc, DirLoc, SourceLocation{}, |
| 4223 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4224 |
Clauses, {}); |
| 4225 |
} |
| 4226 |
|
| 4227 |
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, |
| 4228 |
SourceLocation DirLoc, |
| 4229 |
SourceLocation EndLoc, |
| 4230 |
ArrayRef<OpenACCClause *> Clauses, |
| 4231 |
StmtResult StrBlock) { |
| 4232 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4233 |
OpenACCDirectiveKind::HostData, BeginLoc, DirLoc, SourceLocation{}, |
| 4234 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4235 |
Clauses, StrBlock); |
| 4236 |
} |
| 4237 |
|
| 4238 |
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, |
| 4239 |
SourceLocation DirLoc, |
| 4240 |
SourceLocation EndLoc, |
| 4241 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4242 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4243 |
OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{}, |
| 4244 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4245 |
Clauses, {}); |
| 4246 |
} |
| 4247 |
|
| 4248 |
StmtResult |
| 4249 |
RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, |
| 4250 |
SourceLocation DirLoc, SourceLocation EndLoc, |
| 4251 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4252 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4253 |
OpenACCDirectiveKind::Shutdown, BeginLoc, DirLoc, SourceLocation{}, |
| 4254 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4255 |
Clauses, {}); |
| 4256 |
} |
| 4257 |
|
| 4258 |
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, |
| 4259 |
SourceLocation DirLoc, |
| 4260 |
SourceLocation EndLoc, |
| 4261 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4262 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4263 |
OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{}, |
| 4264 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4265 |
Clauses, {}); |
| 4266 |
} |
| 4267 |
|
| 4268 |
StmtResult RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, |
| 4269 |
SourceLocation DirLoc, |
| 4270 |
SourceLocation EndLoc, |
| 4271 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4272 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4273 |
OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{}, |
| 4274 |
SourceLocation{}, {}, OpenACCAtomicKind::None, SourceLocation{}, EndLoc, |
| 4275 |
Clauses, {}); |
| 4276 |
} |
| 4277 |
|
| 4278 |
StmtResult RebuildOpenACCWaitConstruct( |
| 4279 |
SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, |
| 4280 |
Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs, |
| 4281 |
SourceLocation RParenLoc, SourceLocation EndLoc, |
| 4282 |
ArrayRef<OpenACCClause *> Clauses) { |
| 4283 |
llvm::SmallVector<Expr *> Exprs; |
| 4284 |
Exprs.push_back(DevNumExpr); |
| 4285 |
llvm::append_range(Exprs, QueueIdExprs); |
| 4286 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4287 |
OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc, |
| 4288 |
Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {}); |
| 4289 |
} |
| 4290 |
|
| 4291 |
StmtResult RebuildOpenACCCacheConstruct( |
| 4292 |
SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, |
| 4293 |
SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList, |
| 4294 |
SourceLocation RParenLoc, SourceLocation EndLoc) { |
| 4295 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4296 |
OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc, |
| 4297 |
VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {}); |
| 4298 |
} |
| 4299 |
|
| 4300 |
StmtResult RebuildOpenACCAtomicConstruct(SourceLocation BeginLoc, |
| 4301 |
SourceLocation DirLoc, |
| 4302 |
OpenACCAtomicKind AtKind, |
| 4303 |
SourceLocation EndLoc, |
| 4304 |
ArrayRef<OpenACCClause *> Clauses, |
| 4305 |
StmtResult AssociatedStmt) { |
| 4306 |
return getSema().OpenACC().ActOnEndStmtDirective( |
| 4307 |
OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{}, |
| 4308 |
SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses, |
| 4309 |
AssociatedStmt); |
| 4310 |
} |
| 4311 |
|
| 4312 |
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc) { |
| 4313 |
return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc); |
| 4314 |
} |
| 4315 |
|
| 4316 |
ExprResult |
| 4317 |
RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, |
| 4318 |
const NonTypeTemplateParmDecl *NTTP, |
| 4319 |
SourceLocation Loc, TemplateArgument Arg, |
| 4320 |
UnsignedOrNone PackIndex, bool Final) { |
| 4321 |
return getSema().BuildSubstNonTypeTemplateParmExpr( |
| 4322 |
AssociatedDecl, NTTP, Loc, Arg, PackIndex, Final); |
| 4323 |
} |
| 4324 |
|
| 4325 |
private: |
| 4326 |
QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL, |
| 4327 |
QualType ObjectType, |
| 4328 |
NamedDecl *FirstQualifierInScope); |
| 4329 |
|
| 4330 |
TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4331 |
QualType ObjectType, |
| 4332 |
NamedDecl *FirstQualifierInScope) { |
| 4333 |
if (getDerived().AlreadyTransformed(TSInfo->getType())) |
| 4334 |
return TSInfo; |
| 4335 |
|
| 4336 |
TypeLocBuilder TLB; |
| 4337 |
QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(), |
| 4338 |
ObjectType, FirstQualifierInScope); |
| 4339 |
if (T.isNull()) |
| 4340 |
return nullptr; |
| 4341 |
return TLB.getTypeSourceInfo(SemaRef.Context, T); |
| 4342 |
} |
| 4343 |
|
| 4344 |
QualType TransformDependentNameType(TypeLocBuilder &TLB, |
| 4345 |
DependentNameTypeLoc TL, |
| 4346 |
bool DeducibleTSTContext, |
| 4347 |
QualType ObjectType = QualType(), |
| 4348 |
NamedDecl *UnqualLookup = nullptr); |
| 4349 |
|
| 4350 |
llvm::SmallVector<OpenACCClause *> |
| 4351 |
TransformOpenACCClauseList(OpenACCDirectiveKind DirKind, |
| 4352 |
ArrayRef<const OpenACCClause *> OldClauses); |
| 4353 |
|
| 4354 |
OpenACCClause * |
| 4355 |
TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses, |
| 4356 |
OpenACCDirectiveKind DirKind, |
| 4357 |
const OpenACCClause *OldClause); |
| 4358 |
}; |
| 4359 |
|
| 4360 |
template <typename Derived> |
| 4361 |
StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { |
| 4362 |
if (!S) |
| 4363 |
return S; |
| 4364 |
|
| 4365 |
switch (S->getStmtClass()) { |
| 4366 |
case Stmt::NoStmtClass: break; |
| 4367 |
|
| 4368 |
// Transform individual statement nodes |
| 4369 |
// Pass SDK into statements that can produce a value |
| 4370 |
#define STMT(Node, Parent) \ |
| 4371 |
case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 4372 |
#define VALUESTMT(Node, Parent) \ |
| 4373 |
case Stmt::Node##Class: \ |
| 4374 |
return getDerived().Transform##Node(cast<Node>(S), SDK); |
| 4375 |
#define ABSTRACT_STMT(Node) |
| 4376 |
#define EXPR(Node, Parent) |
| 4377 |
#include "clang/AST/StmtNodes.inc" |
| 4378 |
|
| 4379 |
// Transform expressions by calling TransformExpr. |
| 4380 |
#define STMT(Node, Parent) |
| 4381 |
#define ABSTRACT_STMT(Stmt) |
| 4382 |
#define EXPR(Node, Parent) case Stmt::Node##Class: |
| 4383 |
#include "clang/AST/StmtNodes.inc" |
| 4384 |
{ |
| 4385 |
ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 4386 |
|
| 4387 |
if (SDK == StmtDiscardKind::StmtExprResult) |
| 4388 |
E = getSema().ActOnStmtExprResult(E); |
| 4389 |
return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded); |
| 4390 |
} |
| 4391 |
} |
| 4392 |
|
| 4393 |
return S; |
| 4394 |
} |
| 4395 |
|
| 4396 |
template<typename Derived> |
| 4397 |
OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 4398 |
if (!S) |
| 4399 |
return S; |
| 4400 |
|
| 4401 |
switch (S->getClauseKind()) { |
| 4402 |
default: break; |
| 4403 |
// Transform individual clause nodes |
| 4404 |
#define GEN_CLANG_CLAUSE_CLASS |
| 4405 |
#define CLAUSE_CLASS(Enum, Str, Class) \ |
| 4406 |
case Enum: \ |
| 4407 |
return getDerived().Transform##Class(cast<Class>(S)); |
| 4408 |
#include "llvm/Frontend/OpenMP/OMP.inc" |
| 4409 |
} |
| 4410 |
|
| 4411 |
return S; |
| 4412 |
} |
| 4413 |
|
| 4414 |
|
| 4415 |
template<typename Derived> |
| 4416 |
ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
| 4417 |
if (!E) |
| 4418 |
return E; |
| 4419 |
|
| 4420 |
switch (E->getStmtClass()) { |
| 4421 |
case Stmt::NoStmtClass: break; |
| 4422 |
#define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 4423 |
#define ABSTRACT_STMT(Stmt) |
| 4424 |
#define EXPR(Node, Parent) \ |
| 4425 |
case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| 4426 |
#include "clang/AST/StmtNodes.inc" |
| 4427 |
} |
| 4428 |
|
| 4429 |
return E; |
| 4430 |
} |
| 4431 |
|
| 4432 |
template<typename Derived> |
| 4433 |
ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 4434 |
bool NotCopyInit) { |
| 4435 |
// Initializers are instantiated like expressions, except that various outer |
| 4436 |
// layers are stripped. |
| 4437 |
if (!Init) |
| 4438 |
return Init; |
| 4439 |
|
| 4440 |
if (auto *FE = dyn_cast<FullExpr>(Init)) |
| 4441 |
Init = FE->getSubExpr(); |
| 4442 |
|
| 4443 |
if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) { |
| 4444 |
OpaqueValueExpr *OVE = AIL->getCommonExpr(); |
| 4445 |
Init = OVE->getSourceExpr(); |
| 4446 |
} |
| 4447 |
|
| 4448 |
if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 4449 |
Init = MTE->getSubExpr(); |
| 4450 |
|
| 4451 |
while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 4452 |
Init = Binder->getSubExpr(); |
| 4453 |
|
| 4454 |
if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 4455 |
Init = ICE->getSubExprAsWritten(); |
| 4456 |
|
| 4457 |
if (CXXStdInitializerListExpr *ILE = |
| 4458 |
dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 4459 |
return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
| 4460 |
|
| 4461 |
// If this is copy-initialization, we only need to reconstruct |
| 4462 |
// InitListExprs. Other forms of copy-initialization will be a no-op if |
| 4463 |
// the initializer is already the right type. |
| 4464 |
CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 4465 |
if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
| 4466 |
return getDerived().TransformExpr(Init); |
| 4467 |
|
| 4468 |
// Revert value-initialization back to empty parens. |
| 4469 |
if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 4470 |
SourceRange Parens = VIE->getSourceRange(); |
| 4471 |
return getDerived().RebuildParenListExpr(Parens.getBegin(), {}, |
| 4472 |
Parens.getEnd()); |
| 4473 |
} |
| 4474 |
|
| 4475 |
// FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 4476 |
if (isa<ImplicitValueInitExpr>(Init)) |
| 4477 |
return getDerived().RebuildParenListExpr(SourceLocation(), {}, |
| 4478 |
SourceLocation()); |
| 4479 |
|
| 4480 |
// Revert initialization by constructor back to a parenthesized or braced list |
| 4481 |
// of expressions. Any other form of initializer can just be reused directly. |
| 4482 |
if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
| 4483 |
return getDerived().TransformExpr(Init); |
| 4484 |
|
| 4485 |
// If the initialization implicitly converted an initializer list to a |
| 4486 |
// std::initializer_list object, unwrap the std::initializer_list too. |
| 4487 |
if (Construct && Construct->isStdInitListInitialization()) |
| 4488 |
return TransformInitializer(Construct->getArg(0), NotCopyInit); |
| 4489 |
|
| 4490 |
// Enter a list-init context if this was list initialization. |
| 4491 |
EnterExpressionEvaluationContext Context( |
| 4492 |
getSema(), EnterExpressionEvaluationContext::InitList, |
| 4493 |
Construct->isListInitialization()); |
| 4494 |
|
| 4495 |
getSema().currentEvaluationContext().InLifetimeExtendingContext = |
| 4496 |
getSema().parentEvaluationContext().InLifetimeExtendingContext; |
| 4497 |
getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit = |
| 4498 |
getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit; |
| 4499 |
SmallVector<Expr*, 8> NewArgs; |
| 4500 |
bool ArgChanged = false; |
| 4501 |
if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 4502 |
/*IsCall*/true, NewArgs, &ArgChanged)) |
| 4503 |
return ExprError(); |
| 4504 |
|
| 4505 |
// If this was list initialization, revert to syntactic list form. |
| 4506 |
if (Construct->isListInitialization()) |
| 4507 |
return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, |
| 4508 |
Construct->getEndLoc()); |
| 4509 |
|
| 4510 |
// Build a ParenListExpr to represent anything else. |
| 4511 |
SourceRange Parens = Construct->getParenOrBraceRange(); |
| 4512 |
if (Parens.isInvalid()) { |
| 4513 |
// This was a variable declaration's initialization for which no initializer |
| 4514 |
// was specified. |
| 4515 |
assert(NewArgs.empty() && |
| 4516 |
"no parens or braces but have direct init with arguments?"); |
| 4517 |
return ExprEmpty(); |
| 4518 |
} |
| 4519 |
return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 4520 |
Parens.getEnd()); |
| 4521 |
} |
| 4522 |
|
| 4523 |
template<typename Derived> |
| 4524 |
bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
| 4525 |
unsigned NumInputs, |
| 4526 |
bool IsCall, |
| 4527 |
SmallVectorImpl<Expr *> &Outputs, |
| 4528 |
bool *ArgChanged) { |
| 4529 |
for (unsigned I = 0; I != NumInputs; ++I) { |
| 4530 |
// If requested, drop call arguments that need to be dropped. |
| 4531 |
if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 4532 |
if (ArgChanged) |
| 4533 |
*ArgChanged = true; |
| 4534 |
|
| 4535 |
break; |
| 4536 |
} |
| 4537 |
|
| 4538 |
if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 4539 |
Expr *Pattern = Expansion->getPattern(); |
| 4540 |
|
| 4541 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 4542 |
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4543 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 4544 |
|
| 4545 |
// Determine whether the set of unexpanded parameter packs can and should |
| 4546 |
// be expanded. |
| 4547 |
bool Expand = true; |
| 4548 |
bool RetainExpansion = false; |
| 4549 |
UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions(); |
| 4550 |
UnsignedOrNone NumExpansions = OrigNumExpansions; |
| 4551 |
if (getDerived().TryExpandParameterPacks( |
| 4552 |
Expansion->getEllipsisLoc(), Pattern->getSourceRange(), |
| 4553 |
Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand, |
| 4554 |
RetainExpansion, NumExpansions)) |
| 4555 |
return true; |
| 4556 |
|
| 4557 |
if (!Expand) { |
| 4558 |
// The transform has determined that we should perform a simple |
| 4559 |
// transformation on the pack expansion, producing another pack |
| 4560 |
// expansion. |
| 4561 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 4562 |
ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 4563 |
if (OutPattern.isInvalid()) |
| 4564 |
return true; |
| 4565 |
|
| 4566 |
ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
| 4567 |
Expansion->getEllipsisLoc(), |
| 4568 |
NumExpansions); |
| 4569 |
if (Out.isInvalid()) |
| 4570 |
return true; |
| 4571 |
|
| 4572 |
if (ArgChanged) |
| 4573 |
*ArgChanged = true; |
| 4574 |
Outputs.push_back(Out.get()); |
| 4575 |
continue; |
| 4576 |
} |
| 4577 |
|
| 4578 |
// Record right away that the argument was changed. This needs |
| 4579 |
// to happen even if the array expands to nothing. |
| 4580 |
if (ArgChanged) *ArgChanged = true; |
| 4581 |
|
| 4582 |
// The transform has determined that we should perform an elementwise |
| 4583 |
// expansion of the pattern. Do so. |
| 4584 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 4585 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 4586 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 4587 |
if (Out.isInvalid()) |
| 4588 |
return true; |
| 4589 |
|
| 4590 |
if (Out.get()->containsUnexpandedParameterPack()) { |
| 4591 |
Out = getDerived().RebuildPackExpansion( |
| 4592 |
Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 4593 |
if (Out.isInvalid()) |
| 4594 |
return true; |
| 4595 |
} |
| 4596 |
|
| 4597 |
Outputs.push_back(Out.get()); |
| 4598 |
} |
| 4599 |
|
| 4600 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 4601 |
// forgetting the partially-substituted parameter pack. |
| 4602 |
if (RetainExpansion) { |
| 4603 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4604 |
|
| 4605 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 4606 |
if (Out.isInvalid()) |
| 4607 |
return true; |
| 4608 |
|
| 4609 |
Out = getDerived().RebuildPackExpansion( |
| 4610 |
Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 4611 |
if (Out.isInvalid()) |
| 4612 |
return true; |
| 4613 |
|
| 4614 |
Outputs.push_back(Out.get()); |
| 4615 |
} |
| 4616 |
|
| 4617 |
continue; |
| 4618 |
} |
| 4619 |
|
| 4620 |
ExprResult Result = |
| 4621 |
IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 4622 |
: getDerived().TransformExpr(Inputs[I]); |
| 4623 |
if (Result.isInvalid()) |
| 4624 |
return true; |
| 4625 |
|
| 4626 |
if (Result.get() != Inputs[I] && ArgChanged) |
| 4627 |
*ArgChanged = true; |
| 4628 |
|
| 4629 |
Outputs.push_back(Result.get()); |
| 4630 |
} |
| 4631 |
|
| 4632 |
return false; |
| 4633 |
} |
| 4634 |
|
| 4635 |
template <typename Derived> |
| 4636 |
Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 4637 |
SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 4638 |
|
| 4639 |
EnterExpressionEvaluationContext Eval( |
| 4640 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 4641 |
/*LambdaContextDecl=*/nullptr, |
| 4642 |
/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other, |
| 4643 |
/*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf); |
| 4644 |
|
| 4645 |
if (Var) { |
| 4646 |
VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 4647 |
getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 4648 |
|
| 4649 |
if (!ConditionVar) |
| 4650 |
return Sema::ConditionError(); |
| 4651 |
|
| 4652 |
return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 4653 |
} |
| 4654 |
|
| 4655 |
if (Expr) { |
| 4656 |
ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 4657 |
|
| 4658 |
if (CondExpr.isInvalid()) |
| 4659 |
return Sema::ConditionError(); |
| 4660 |
|
| 4661 |
return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind, |
| 4662 |
/*MissingOK=*/true); |
| 4663 |
} |
| 4664 |
|
| 4665 |
return Sema::ConditionResult(); |
| 4666 |
} |
| 4667 |
|
| 4668 |
template <typename Derived> |
| 4669 |
NestedNameSpecifierLoc TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 4670 |
NestedNameSpecifierLoc NNS, QualType ObjectType, |
| 4671 |
NamedDecl *FirstQualifierInScope) { |
| 4672 |
SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 4673 |
|
| 4674 |
auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) { |
| 4675 |
for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 4676 |
Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix) |
| 4677 |
Qualifiers.push_back(Qualifier); |
| 4678 |
}; |
| 4679 |
insertNNS(NNS); |
| 4680 |
|
| 4681 |
CXXScopeSpec SS; |
| 4682 |
while (!Qualifiers.empty()) { |
| 4683 |
NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 4684 |
NestedNameSpecifier QNNS = Q.getNestedNameSpecifier(); |
| 4685 |
|
| 4686 |
switch (QNNS.getKind()) { |
| 4687 |
case NestedNameSpecifier::Kind::Null: |
| 4688 |
llvm_unreachable("unexpected null nested name specifier"); |
| 4689 |
|
| 4690 |
case NestedNameSpecifier::Kind::Namespace: { |
| 4691 |
auto *NS = cast<NamespaceBaseDecl>(getDerived().TransformDecl( |
| 4692 |
Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>( |
| 4693 |
QNNS.getAsNamespaceAndPrefix().Namespace))); |
| 4694 |
SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 4695 |
break; |
| 4696 |
} |
| 4697 |
|
| 4698 |
case NestedNameSpecifier::Kind::Global: |
| 4699 |
// There is no meaningful transformation that one could perform on the |
| 4700 |
// global scope. |
| 4701 |
SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 4702 |
break; |
| 4703 |
|
| 4704 |
case NestedNameSpecifier::Kind::MicrosoftSuper: { |
| 4705 |
CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>( |
| 4706 |
getDerived().TransformDecl(SourceLocation(), QNNS.getAsRecordDecl())); |
| 4707 |
SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(), |
| 4708 |
Q.getEndLoc()); |
| 4709 |
break; |
| 4710 |
} |
| 4711 |
|
| 4712 |
case NestedNameSpecifier::Kind::Type: { |
| 4713 |
assert(SS.isEmpty()); |
| 4714 |
TypeLoc TL = Q.castAsTypeLoc(); |
| 4715 |
|
| 4716 |
if (auto DNT = TL.getAs<DependentNameTypeLoc>()) { |
| 4717 |
NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc(); |
| 4718 |
if (QualifierLoc) { |
| 4719 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc( |
| 4720 |
QualifierLoc, ObjectType, FirstQualifierInScope); |
| 4721 |
if (!QualifierLoc) |
| 4722 |
return NestedNameSpecifierLoc(); |
| 4723 |
ObjectType = QualType(); |
| 4724 |
FirstQualifierInScope = nullptr; |
| 4725 |
} |
| 4726 |
SS.Adopt(QualifierLoc); |
| 4727 |
Sema::NestedNameSpecInfo IdInfo( |
| 4728 |
const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()), |
| 4729 |
DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType); |
| 4730 |
if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, |
| 4731 |
false, SS, |
| 4732 |
FirstQualifierInScope, false)) |
| 4733 |
return NestedNameSpecifierLoc(); |
| 4734 |
return SS.getWithLocInContext(SemaRef.Context); |
| 4735 |
} |
| 4736 |
|
| 4737 |
QualType T = TL.getType(); |
| 4738 |
TypeLocBuilder TLB; |
| 4739 |
if (!getDerived().AlreadyTransformed(T)) { |
| 4740 |
T = TransformTypeInObjectScope(TLB, TL, ObjectType, |
| 4741 |
FirstQualifierInScope); |
| 4742 |
if (T.isNull()) |
| 4743 |
return NestedNameSpecifierLoc(); |
| 4744 |
TL = TLB.getTypeLocInContext(SemaRef.Context, T); |
| 4745 |
} |
| 4746 |
|
| 4747 |
if (T->isDependentType() || T->isRecordType() || |
| 4748 |
(SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) { |
| 4749 |
if (T->isEnumeralType()) |
| 4750 |
SemaRef.Diag(TL.getBeginLoc(), |
| 4751 |
diag::warn_cxx98_compat_enum_nested_name_spec); |
| 4752 |
SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc()); |
| 4753 |
break; |
| 4754 |
} |
| 4755 |
// If the nested-name-specifier is an invalid type def, don't emit an |
| 4756 |
// error because a previous error should have already been emitted. |
| 4757 |
TypedefTypeLoc TTL = TL.getAsAdjusted<TypedefTypeLoc>(); |
| 4758 |
if (!TTL || !TTL.getDecl()->isInvalidDecl()) { |
| 4759 |
SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 4760 |
<< T << SS.getRange(); |
| 4761 |
} |
| 4762 |
return NestedNameSpecifierLoc(); |
| 4763 |
} |
| 4764 |
} |
| 4765 |
} |
| 4766 |
|
| 4767 |
// Don't rebuild the nested-name-specifier if we don't have to. |
| 4768 |
if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 4769 |
!getDerived().AlwaysRebuild()) |
| 4770 |
return NNS; |
| 4771 |
|
| 4772 |
// If we can re-use the source-location data from the original |
| 4773 |
// nested-name-specifier, do so. |
| 4774 |
if (SS.location_size() == NNS.getDataLength() && |
| 4775 |
memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 4776 |
return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 4777 |
|
| 4778 |
// Allocate new nested-name-specifier location information. |
| 4779 |
return SS.getWithLocInContext(SemaRef.Context); |
| 4780 |
} |
| 4781 |
|
| 4782 |
template<typename Derived> |
| 4783 |
DeclarationNameInfo |
| 4784 |
TreeTransform<Derived> |
| 4785 |
::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
| 4786 |
DeclarationName Name = NameInfo.getName(); |
| 4787 |
if (!Name) |
| 4788 |
return DeclarationNameInfo(); |
| 4789 |
|
| 4790 |
switch (Name.getNameKind()) { |
| 4791 |
case DeclarationName::Identifier: |
| 4792 |
case DeclarationName::ObjCZeroArgSelector: |
| 4793 |
case DeclarationName::ObjCOneArgSelector: |
| 4794 |
case DeclarationName::ObjCMultiArgSelector: |
| 4795 |
case DeclarationName::CXXOperatorName: |
| 4796 |
case DeclarationName::CXXLiteralOperatorName: |
| 4797 |
case DeclarationName::CXXUsingDirective: |
| 4798 |
return NameInfo; |
| 4799 |
|
| 4800 |
case DeclarationName::CXXDeductionGuideName: { |
| 4801 |
TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); |
| 4802 |
TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( |
| 4803 |
getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); |
| 4804 |
if (!NewTemplate) |
| 4805 |
return DeclarationNameInfo(); |
| 4806 |
|
| 4807 |
DeclarationNameInfo NewNameInfo(NameInfo); |
| 4808 |
NewNameInfo.setName( |
| 4809 |
SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); |
| 4810 |
return NewNameInfo; |
| 4811 |
} |
| 4812 |
|
| 4813 |
case DeclarationName::CXXConstructorName: |
| 4814 |
case DeclarationName::CXXDestructorName: |
| 4815 |
case DeclarationName::CXXConversionFunctionName: { |
| 4816 |
TypeSourceInfo *NewTInfo; |
| 4817 |
CanQualType NewCanTy; |
| 4818 |
if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| 4819 |
NewTInfo = getDerived().TransformType(OldTInfo); |
| 4820 |
if (!NewTInfo) |
| 4821 |
return DeclarationNameInfo(); |
| 4822 |
NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| 4823 |
} |
| 4824 |
else { |
| 4825 |
NewTInfo = nullptr; |
| 4826 |
TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| 4827 |
QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
| 4828 |
if (NewT.isNull()) |
| 4829 |
return DeclarationNameInfo(); |
| 4830 |
NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 4831 |
} |
| 4832 |
|
| 4833 |
DeclarationName NewName |
| 4834 |
= SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 4835 |
NewCanTy); |
| 4836 |
DeclarationNameInfo NewNameInfo(NameInfo); |
| 4837 |
NewNameInfo.setName(NewName); |
| 4838 |
NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 4839 |
return NewNameInfo; |
| 4840 |
} |
| 4841 |
} |
| 4842 |
|
| 4843 |
llvm_unreachable("Unknown name kind."); |
| 4844 |
} |
| 4845 |
|
| 4846 |
template <typename Derived> |
| 4847 |
TemplateName TreeTransform<Derived>::RebuildTemplateName( |
| 4848 |
CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 4849 |
IdentifierOrOverloadedOperator IO, SourceLocation NameLoc, |
| 4850 |
QualType ObjectType, bool AllowInjectedClassName) { |
| 4851 |
if (const IdentifierInfo *II = IO.getIdentifier()) |
| 4852 |
return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc, |
| 4853 |
ObjectType, AllowInjectedClassName); |
| 4854 |
return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(), |
| 4855 |
NameLoc, ObjectType, |
| 4856 |
AllowInjectedClassName); |
| 4857 |
} |
| 4858 |
|
| 4859 |
template <typename Derived> |
| 4860 |
TemplateName TreeTransform<Derived>::TransformTemplateName( |
| 4861 |
NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc, |
| 4862 |
TemplateName Name, SourceLocation NameLoc, QualType ObjectType, |
| 4863 |
NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) { |
| 4864 |
if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 4865 |
TemplateName UnderlyingName = QTN->getUnderlyingTemplate(); |
| 4866 |
|
| 4867 |
if (QualifierLoc) { |
| 4868 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc( |
| 4869 |
QualifierLoc, ObjectType, FirstQualifierInScope); |
| 4870 |
if (!QualifierLoc) |
| 4871 |
return TemplateName(); |
| 4872 |
} |
| 4873 |
|
| 4874 |
NestedNameSpecifierLoc UnderlyingQualifier; |
| 4875 |
TemplateName NewUnderlyingName = getDerived().TransformTemplateName( |
| 4876 |
UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType, |
| 4877 |
FirstQualifierInScope, AllowInjectedClassName); |
| 4878 |
if (NewUnderlyingName.isNull()) |
| 4879 |
return TemplateName(); |
| 4880 |
assert(!UnderlyingQualifier && "unexpected qualifier"); |
| 4881 |
|
| 4882 |
if (!getDerived().AlwaysRebuild() && |
| 4883 |
QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() && |
| 4884 |
NewUnderlyingName == UnderlyingName) |
| 4885 |
return Name; |
| 4886 |
CXXScopeSpec SS; |
| 4887 |
SS.Adopt(QualifierLoc); |
| 4888 |
return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 4889 |
NewUnderlyingName); |
| 4890 |
} |
| 4891 |
|
| 4892 |
if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 4893 |
if (QualifierLoc) { |
| 4894 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc( |
| 4895 |
QualifierLoc, ObjectType, FirstQualifierInScope); |
| 4896 |
if (!QualifierLoc) |
| 4897 |
return TemplateName(); |
| 4898 |
// The qualifier-in-scope and object type only apply to the leftmost |
| 4899 |
// entity. |
| 4900 |
ObjectType = QualType(); |
| 4901 |
} |
| 4902 |
|
| 4903 |
if (!getDerived().AlwaysRebuild() && |
| 4904 |
QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() && |
| 4905 |
ObjectType.isNull()) |
| 4906 |
return Name; |
| 4907 |
|
| 4908 |
CXXScopeSpec SS; |
| 4909 |
SS.Adopt(QualifierLoc); |
| 4910 |
return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(), |
| 4911 |
NameLoc, ObjectType, |
| 4912 |
AllowInjectedClassName); |
| 4913 |
} |
| 4914 |
|
| 4915 |
if (SubstTemplateTemplateParmStorage *S = |
| 4916 |
Name.getAsSubstTemplateTemplateParm()) { |
| 4917 |
assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm"); |
| 4918 |
|
| 4919 |
NestedNameSpecifierLoc ReplacementQualifierLoc; |
| 4920 |
TemplateName ReplacementName = S->getReplacement(); |
| 4921 |
if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) { |
| 4922 |
NestedNameSpecifierLocBuilder Builder; |
| 4923 |
Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc); |
| 4924 |
ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context); |
| 4925 |
} |
| 4926 |
|
| 4927 |
TemplateName NewName = getDerived().TransformTemplateName( |
| 4928 |
ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc, |
| 4929 |
ObjectType, FirstQualifierInScope, AllowInjectedClassName); |
| 4930 |
if (NewName.isNull()) |
| 4931 |
return TemplateName(); |
| 4932 |
Decl *AssociatedDecl = |
| 4933 |
getDerived().TransformDecl(NameLoc, S->getAssociatedDecl()); |
| 4934 |
if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() && |
| 4935 |
AssociatedDecl == S->getAssociatedDecl()) |
| 4936 |
return Name; |
| 4937 |
return SemaRef.Context.getSubstTemplateTemplateParm( |
| 4938 |
NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(), |
| 4939 |
S->getFinal()); |
| 4940 |
} |
| 4941 |
|
| 4942 |
assert(!Name.getAsDeducedTemplateName() && |
| 4943 |
"DeducedTemplateName should not escape partial ordering"); |
| 4944 |
|
| 4945 |
// FIXME: Preserve UsingTemplateName. |
| 4946 |
if (auto *Template = Name.getAsTemplateDecl()) { |
| 4947 |
assert(!QualifierLoc && "Unexpected qualifier"); |
| 4948 |
return TemplateName(cast_or_null<TemplateDecl>( |
| 4949 |
getDerived().TransformDecl(NameLoc, Template))); |
| 4950 |
} |
| 4951 |
|
| 4952 |
if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 4953 |
= Name.getAsSubstTemplateTemplateParmPack()) { |
| 4954 |
assert(!QualifierLoc && |
| 4955 |
"Unexpected qualified SubstTemplateTemplateParmPack"); |
| 4956 |
return getDerived().RebuildTemplateName( |
| 4957 |
SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(), |
| 4958 |
SubstPack->getIndex(), SubstPack->getFinal()); |
| 4959 |
} |
| 4960 |
|
| 4961 |
// These should be getting filtered out before they reach the AST. |
| 4962 |
llvm_unreachable("overloaded function decl survived to here"); |
| 4963 |
} |
| 4964 |
|
| 4965 |
template <typename Derived> |
| 4966 |
TemplateArgument TreeTransform<Derived>::TransformNamedTemplateTemplateArgument( |
| 4967 |
NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, |
| 4968 |
TemplateName Name, SourceLocation NameLoc) { |
| 4969 |
TemplateName TN = getDerived().TransformTemplateName( |
| 4970 |
QualifierLoc, TemplateKeywordLoc, Name, NameLoc); |
| 4971 |
if (TN.isNull()) |
| 4972 |
return TemplateArgument(); |
| 4973 |
return TemplateArgument(TN); |
| 4974 |
} |
| 4975 |
|
| 4976 |
template<typename Derived> |
| 4977 |
void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 4978 |
const TemplateArgument &Arg, |
| 4979 |
TemplateArgumentLoc &Output) { |
| 4980 |
Output = getSema().getTrivialTemplateArgumentLoc( |
| 4981 |
Arg, QualType(), getDerived().getBaseLocation()); |
| 4982 |
} |
| 4983 |
|
| 4984 |
template <typename Derived> |
| 4985 |
bool TreeTransform<Derived>::TransformTemplateArgument( |
| 4986 |
const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, |
| 4987 |
bool Uneval) { |
| 4988 |
const TemplateArgument &Arg = Input.getArgument(); |
| 4989 |
switch (Arg.getKind()) { |
| 4990 |
case TemplateArgument::Null: |
| 4991 |
case TemplateArgument::Pack: |
| 4992 |
llvm_unreachable("Unexpected TemplateArgument"); |
| 4993 |
|
| 4994 |
case TemplateArgument::Integral: |
| 4995 |
case TemplateArgument::NullPtr: |
| 4996 |
case TemplateArgument::Declaration: |
| 4997 |
case TemplateArgument::StructuralValue: { |
| 4998 |
// Transform a resolved template argument straight to a resolved template |
| 4999 |
// argument. We get here when substituting into an already-substituted |
| 5000 |
// template type argument during concept satisfaction checking. |
| 5001 |
QualType T = Arg.getNonTypeTemplateArgumentType(); |
| 5002 |
QualType NewT = getDerived().TransformType(T); |
| 5003 |
if (NewT.isNull()) |
| 5004 |
return true; |
| 5005 |
|
| 5006 |
ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration |
| 5007 |
? Arg.getAsDecl() |
| 5008 |
: nullptr; |
| 5009 |
ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl( |
| 5010 |
getDerived().getBaseLocation(), D)) |
| 5011 |
: nullptr; |
| 5012 |
if (D && !NewD) |
| 5013 |
return true; |
| 5014 |
|
| 5015 |
if (NewT == T && D == NewD) |
| 5016 |
Output = Input; |
| 5017 |
else if (Arg.getKind() == TemplateArgument::Integral) |
| 5018 |
Output = TemplateArgumentLoc( |
| 5019 |
TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT), |
| 5020 |
TemplateArgumentLocInfo()); |
| 5021 |
else if (Arg.getKind() == TemplateArgument::NullPtr) |
| 5022 |
Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true), |
| 5023 |
TemplateArgumentLocInfo()); |
| 5024 |
else if (Arg.getKind() == TemplateArgument::Declaration) |
| 5025 |
Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT), |
| 5026 |
TemplateArgumentLocInfo()); |
| 5027 |
else if (Arg.getKind() == TemplateArgument::StructuralValue) |
| 5028 |
Output = TemplateArgumentLoc( |
| 5029 |
TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()), |
| 5030 |
TemplateArgumentLocInfo()); |
| 5031 |
else |
| 5032 |
llvm_unreachable("unexpected template argument kind"); |
| 5033 |
|
| 5034 |
return false; |
| 5035 |
} |
| 5036 |
|
| 5037 |
case TemplateArgument::Type: { |
| 5038 |
TypeSourceInfo *TSI = Input.getTypeSourceInfo(); |
| 5039 |
if (!TSI) |
| 5040 |
TSI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
| 5041 |
|
| 5042 |
TSI = getDerived().TransformType(TSI); |
| 5043 |
if (!TSI) |
| 5044 |
return true; |
| 5045 |
|
| 5046 |
Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI); |
| 5047 |
return false; |
| 5048 |
} |
| 5049 |
|
| 5050 |
case TemplateArgument::Template: { |
| 5051 |
NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 5052 |
|
| 5053 |
TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument( |
| 5054 |
QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(), |
| 5055 |
Input.getTemplateNameLoc()); |
| 5056 |
if (Out.isNull()) |
| 5057 |
return true; |
| 5058 |
Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(), |
| 5059 |
QualifierLoc, Input.getTemplateNameLoc()); |
| 5060 |
return false; |
| 5061 |
} |
| 5062 |
|
| 5063 |
case TemplateArgument::TemplateExpansion: |
| 5064 |
llvm_unreachable("Caller should expand pack expansions"); |
| 5065 |
|
| 5066 |
case TemplateArgument::Expression: { |
| 5067 |
// Template argument expressions are constant expressions. |
| 5068 |
EnterExpressionEvaluationContext Unevaluated( |
| 5069 |
getSema(), |
| 5070 |
Uneval ? Sema::ExpressionEvaluationContext::Unevaluated |
| 5071 |
: Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 5072 |
Sema::ReuseLambdaContextDecl, /*ExprContext=*/ |
| 5073 |
Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); |
| 5074 |
|
| 5075 |
Expr *InputExpr = Input.getSourceExpression(); |
| 5076 |
if (!InputExpr) |
| 5077 |
InputExpr = Input.getArgument().getAsExpr(); |
| 5078 |
|
| 5079 |
ExprResult E = getDerived().TransformExpr(InputExpr); |
| 5080 |
E = SemaRef.ActOnConstantExpression(E); |
| 5081 |
if (E.isInvalid()) |
| 5082 |
return true; |
| 5083 |
Output = TemplateArgumentLoc( |
| 5084 |
TemplateArgument(E.get(), /*IsCanonical=*/false), E.get()); |
| 5085 |
return false; |
| 5086 |
} |
| 5087 |
} |
| 5088 |
|
| 5089 |
// Work around bogus GCC warning |
| 5090 |
return true; |
| 5091 |
} |
| 5092 |
|
| 5093 |
/// Iterator adaptor that invents template argument location information |
| 5094 |
/// for each of the template arguments in its underlying iterator. |
| 5095 |
template<typename Derived, typename InputIterator> |
| 5096 |
class TemplateArgumentLocInventIterator { |
| 5097 |
TreeTransform<Derived> &Self; |
| 5098 |
InputIterator Iter; |
| 5099 |
|
| 5100 |
public: |
| 5101 |
typedef TemplateArgumentLoc value_type; |
| 5102 |
typedef TemplateArgumentLoc reference; |
| 5103 |
typedef typename std::iterator_traits<InputIterator>::difference_type |
| 5104 |
difference_type; |
| 5105 |
typedef std::input_iterator_tag iterator_category; |
| 5106 |
|
| 5107 |
class pointer { |
| 5108 |
TemplateArgumentLoc Arg; |
| 5109 |
|
| 5110 |
public: |
| 5111 |
explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 5112 |
|
| 5113 |
const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 5114 |
}; |
| 5115 |
|
| 5116 |
explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 5117 |
InputIterator Iter) |
| 5118 |
: Self(Self), Iter(Iter) { } |
| 5119 |
|
| 5120 |
TemplateArgumentLocInventIterator &operator++() { |
| 5121 |
++Iter; |
| 5122 |
return *this; |
| 5123 |
} |
| 5124 |
|
| 5125 |
TemplateArgumentLocInventIterator operator++(int) { |
| 5126 |
TemplateArgumentLocInventIterator Old(*this); |
| 5127 |
++(*this); |
| 5128 |
return Old; |
| 5129 |
} |
| 5130 |
|
| 5131 |
reference operator*() const { |
| 5132 |
TemplateArgumentLoc Result; |
| 5133 |
Self.InventTemplateArgumentLoc(*Iter, Result); |
| 5134 |
return Result; |
| 5135 |
} |
| 5136 |
|
| 5137 |
pointer operator->() const { return pointer(**this); } |
| 5138 |
|
| 5139 |
friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 5140 |
const TemplateArgumentLocInventIterator &Y) { |
| 5141 |
return X.Iter == Y.Iter; |
| 5142 |
} |
| 5143 |
|
| 5144 |
friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 5145 |
const TemplateArgumentLocInventIterator &Y) { |
| 5146 |
return X.Iter != Y.Iter; |
| 5147 |
} |
| 5148 |
}; |
| 5149 |
|
| 5150 |
template<typename Derived> |
| 5151 |
template<typename InputIterator> |
| 5152 |
bool TreeTransform<Derived>::TransformTemplateArguments( |
| 5153 |
InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 5154 |
bool Uneval) { |
| 5155 |
for (TemplateArgumentLoc In : llvm::make_range(First, Last)) { |
| 5156 |
TemplateArgumentLoc Out; |
| 5157 |
if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 5158 |
// Unpack argument packs, which we translate them into separate |
| 5159 |
// arguments. |
| 5160 |
// FIXME: We could do much better if we could guarantee that the |
| 5161 |
// TemplateArgumentLocInfo for the pack expansion would be usable for |
| 5162 |
// all of the template arguments in the argument pack. |
| 5163 |
typedef TemplateArgumentLocInventIterator<Derived, |
| 5164 |
TemplateArgument::pack_iterator> |
| 5165 |
PackLocIterator; |
| 5166 |
|
| 5167 |
TemplateArgumentListInfo *PackOutput = &Outputs; |
| 5168 |
TemplateArgumentListInfo New; |
| 5169 |
|
| 5170 |
if (TransformTemplateArguments( |
| 5171 |
PackLocIterator(*this, In.getArgument().pack_begin()), |
| 5172 |
PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput, |
| 5173 |
Uneval)) |
| 5174 |
return true; |
| 5175 |
|
| 5176 |
continue; |
| 5177 |
} |
| 5178 |
|
| 5179 |
if (In.getArgument().isPackExpansion()) { |
| 5180 |
UnexpandedInfo Info; |
| 5181 |
TemplateArgumentLoc Prepared; |
| 5182 |
if (getDerived().PreparePackForExpansion(In, Uneval, Prepared, Info)) |
| 5183 |
return true; |
| 5184 |
if (!Info.Expand) { |
| 5185 |
Outputs.addArgument(Prepared); |
| 5186 |
continue; |
| 5187 |
} |
| 5188 |
|
| 5189 |
// The transform has determined that we should perform an elementwise |
| 5190 |
// expansion of the pattern. Do so. |
| 5191 |
std::optional<ForgetSubstitutionRAII> ForgetSubst; |
| 5192 |
if (Info.ExpandUnderForgetSubstitions) |
| 5193 |
ForgetSubst.emplace(getDerived()); |
| 5194 |
for (unsigned I = 0; I != *Info.NumExpansions; ++I) { |
| 5195 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 5196 |
|
| 5197 |
TemplateArgumentLoc Out; |
| 5198 |
if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval)) |
| 5199 |
return true; |
| 5200 |
|
| 5201 |
if (Out.getArgument().containsUnexpandedParameterPack()) { |
| 5202 |
Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis, |
| 5203 |
Info.OrigNumExpansions); |
| 5204 |
if (Out.getArgument().isNull()) |
| 5205 |
return true; |
| 5206 |
} |
| 5207 |
|
| 5208 |
Outputs.addArgument(Out); |
| 5209 |
} |
| 5210 |
|
| 5211 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 5212 |
// forgetting the partially-substituted parameter pack. |
| 5213 |
if (Info.RetainExpansion) { |
| 5214 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5215 |
|
| 5216 |
TemplateArgumentLoc Out; |
| 5217 |
if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval)) |
| 5218 |
return true; |
| 5219 |
|
| 5220 |
Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis, |
| 5221 |
Info.OrigNumExpansions); |
| 5222 |
if (Out.getArgument().isNull()) |
| 5223 |
return true; |
| 5224 |
|
| 5225 |
Outputs.addArgument(Out); |
| 5226 |
} |
| 5227 |
|
| 5228 |
continue; |
| 5229 |
} |
| 5230 |
|
| 5231 |
// The simple case: |
| 5232 |
if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| 5233 |
return true; |
| 5234 |
|
| 5235 |
Outputs.addArgument(Out); |
| 5236 |
} |
| 5237 |
|
| 5238 |
return false; |
| 5239 |
} |
| 5240 |
|
| 5241 |
template <typename Derived> |
| 5242 |
template <typename InputIterator> |
| 5243 |
bool TreeTransform<Derived>::TransformConceptTemplateArguments( |
| 5244 |
InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 5245 |
bool Uneval) { |
| 5246 |
|
| 5247 |
// [C++26][temp.constr.normal] |
| 5248 |
// any non-dependent concept template argument |
| 5249 |
// is substituted into the constraint-expression of C. |
| 5250 |
auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) { |
| 5251 |
return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter(); |
| 5252 |
}; |
| 5253 |
|
| 5254 |
for (; First != Last; ++First) { |
| 5255 |
TemplateArgumentLoc Out; |
| 5256 |
TemplateArgumentLoc In = *First; |
| 5257 |
|
| 5258 |
if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 5259 |
typedef TemplateArgumentLocInventIterator<Derived, |
| 5260 |
TemplateArgument::pack_iterator> |
| 5261 |
PackLocIterator; |
| 5262 |
if (TransformConceptTemplateArguments( |
| 5263 |
PackLocIterator(*this, In.getArgument().pack_begin()), |
| 5264 |
PackLocIterator(*this, In.getArgument().pack_end()), Outputs, |
| 5265 |
Uneval)) |
| 5266 |
return true; |
| 5267 |
continue; |
| 5268 |
} |
| 5269 |
|
| 5270 |
if (!isNonDependentConceptArgument(In.getArgument())) { |
| 5271 |
Outputs.addArgument(In); |
| 5272 |
continue; |
| 5273 |
} |
| 5274 |
|
| 5275 |
if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| 5276 |
return true; |
| 5277 |
|
| 5278 |
Outputs.addArgument(Out); |
| 5279 |
} |
| 5280 |
|
| 5281 |
return false; |
| 5282 |
} |
| 5283 |
|
| 5284 |
// FIXME: Find ways to reduce code duplication for pack expansions. |
| 5285 |
template <typename Derived> |
| 5286 |
bool TreeTransform<Derived>::PreparePackForExpansion(TemplateArgumentLoc In, |
| 5287 |
bool Uneval, |
| 5288 |
TemplateArgumentLoc &Out, |
| 5289 |
UnexpandedInfo &Info) { |
| 5290 |
auto ComputeInfo = [this](TemplateArgumentLoc Arg, |
| 5291 |
bool IsLateExpansionAttempt, UnexpandedInfo &Info, |
| 5292 |
TemplateArgumentLoc &Pattern) { |
| 5293 |
assert(Arg.getArgument().isPackExpansion()); |
| 5294 |
// We have a pack expansion, for which we will be substituting into the |
| 5295 |
// pattern. |
| 5296 |
Pattern = getSema().getTemplateArgumentPackExpansionPattern( |
| 5297 |
Arg, Info.Ellipsis, Info.OrigNumExpansions); |
| 5298 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5299 |
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 5300 |
if (IsLateExpansionAttempt) { |
| 5301 |
// Request expansion only when there is an opportunity to expand a pack |
| 5302 |
// that required a substituion first. |
| 5303 |
bool SawPackTypes = |
| 5304 |
llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) { |
| 5305 |
return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>(); |
| 5306 |
}); |
| 5307 |
if (!SawPackTypes) { |
| 5308 |
Info.Expand = false; |
| 5309 |
return false; |
| 5310 |
} |
| 5311 |
} |
| 5312 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 5313 |
|
| 5314 |
// Determine whether the set of unexpanded parameter packs can and |
| 5315 |
// should be expanded. |
| 5316 |
Info.Expand = true; |
| 5317 |
Info.RetainExpansion = false; |
| 5318 |
Info.NumExpansions = Info.OrigNumExpansions; |
| 5319 |
return getDerived().TryExpandParameterPacks( |
| 5320 |
Info.Ellipsis, Pattern.getSourceRange(), Unexpanded, |
| 5321 |
/*FailOnPackProducingTemplates=*/false, Info.Expand, |
| 5322 |
Info.RetainExpansion, Info.NumExpansions); |
| 5323 |
}; |
| 5324 |
|
| 5325 |
TemplateArgumentLoc Pattern; |
| 5326 |
if (ComputeInfo(In, false, Info, Pattern)) |
| 5327 |
return true; |
| 5328 |
|
| 5329 |
if (Info.Expand) { |
| 5330 |
Out = Pattern; |
| 5331 |
return false; |
| 5332 |
} |
| 5333 |
|
| 5334 |
// The transform has determined that we should perform a simple |
| 5335 |
// transformation on the pack expansion, producing another pack |
| 5336 |
// expansion. |
| 5337 |
TemplateArgumentLoc OutPattern; |
| 5338 |
std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex( |
| 5339 |
std::in_place, getSema(), std::nullopt); |
| 5340 |
if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
| 5341 |
return true; |
| 5342 |
|
| 5343 |
Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis, |
| 5344 |
Info.NumExpansions); |
| 5345 |
if (Out.getArgument().isNull()) |
| 5346 |
return true; |
| 5347 |
SubstIndex.reset(); |
| 5348 |
|
| 5349 |
if (!OutPattern.getArgument().containsUnexpandedParameterPack()) |
| 5350 |
return false; |
| 5351 |
|
| 5352 |
// Some packs will learn their length after substitution, e.g. |
| 5353 |
// __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution |
| 5354 |
// value of `T`. |
| 5355 |
// |
| 5356 |
// We only expand after we know sizes of all packs, check if this is the case |
| 5357 |
// or not. However, we avoid a full template substitution and only do |
| 5358 |
// expanstions after this point. |
| 5359 |
|
| 5360 |
// E.g. when substituting template arguments of tuple with {T -> int} in the |
| 5361 |
// following example: |
| 5362 |
// template <class T> |
| 5363 |
// struct TupleWithInt { |
| 5364 |
// using type = std::tuple<__builtin_dedup_pack<T, int>...>; |
| 5365 |
// }; |
| 5366 |
// TupleWithInt<int>::type y; |
| 5367 |
// At this point we will see the `__builtin_dedup_pack<int, int>` with a known |
| 5368 |
// lenght and run `ComputeInfo()` to provide the necessary information to our |
| 5369 |
// caller. |
| 5370 |
// |
| 5371 |
// Note that we may still have situations where builtin is not going to be |
| 5372 |
// expanded. For example: |
| 5373 |
// template <class T> |
| 5374 |
// struct Foo { |
| 5375 |
// template <class U> using tuple_with_t = |
| 5376 |
// std::tuple<__builtin_dedup_pack<T, U, int>...>; using type = |
| 5377 |
// tuple_with_t<short>; |
| 5378 |
// } |
| 5379 |
// Because the substitution into `type` happens in dependent context, `type` |
| 5380 |
// will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution |
| 5381 |
// and the caller will not be able to expand it. |
| 5382 |
ForgetSubstitutionRAII ForgetSubst(getDerived()); |
| 5383 |
if (ComputeInfo(Out, true, Info, OutPattern)) |
| 5384 |
return true; |
| 5385 |
if (!Info.Expand) |
| 5386 |
return false; |
| 5387 |
Out = OutPattern; |
| 5388 |
Info.ExpandUnderForgetSubstitions = true; |
| 5389 |
return false; |
| 5390 |
} |
| 5391 |
|
| 5392 |
//===----------------------------------------------------------------------===// |
| 5393 |
// Type transformation |
| 5394 |
//===----------------------------------------------------------------------===// |
| 5395 |
|
| 5396 |
template<typename Derived> |
| 5397 |
QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 5398 |
if (getDerived().AlreadyTransformed(T)) |
| 5399 |
return T; |
| 5400 |
|
| 5401 |
// Temporary workaround. All of these transformations should |
| 5402 |
// eventually turn into transformations on TypeLocs. |
| 5403 |
TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo( |
| 5404 |
T, getDerived().getBaseLocation()); |
| 5405 |
|
| 5406 |
TypeSourceInfo *NewTSI = getDerived().TransformType(TSI); |
| 5407 |
|
| 5408 |
if (!NewTSI) |
| 5409 |
return QualType(); |
| 5410 |
|
| 5411 |
return NewTSI->getType(); |
| 5412 |
} |
| 5413 |
|
| 5414 |
template <typename Derived> |
| 5415 |
TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *TSI) { |
| 5416 |
// Refine the base location to the type's location. |
| 5417 |
TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(), |
| 5418 |
getDerived().getBaseEntity()); |
| 5419 |
if (getDerived().AlreadyTransformed(TSI->getType())) |
| 5420 |
return TSI; |
| 5421 |
|
| 5422 |
TypeLocBuilder TLB; |
| 5423 |
|
| 5424 |
TypeLoc TL = TSI->getTypeLoc(); |
| 5425 |
TLB.reserve(TL.getFullDataSize()); |
| 5426 |
|
| 5427 |
QualType Result = getDerived().TransformType(TLB, TL); |
| 5428 |
if (Result.isNull()) |
| 5429 |
return nullptr; |
| 5430 |
|
| 5431 |
return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 5432 |
} |
| 5433 |
|
| 5434 |
template<typename Derived> |
| 5435 |
QualType |
| 5436 |
TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 5437 |
switch (T.getTypeLocClass()) { |
| 5438 |
#define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 5439 |
#define TYPELOC(CLASS, PARENT) \ |
| 5440 |
case TypeLoc::CLASS: \ |
| 5441 |
return getDerived().Transform##CLASS##Type(TLB, \ |
| 5442 |
T.castAs<CLASS##TypeLoc>()); |
| 5443 |
#include "clang/AST/TypeLocNodes.def" |
| 5444 |
} |
| 5445 |
|
| 5446 |
llvm_unreachable("unhandled type loc!"); |
| 5447 |
} |
| 5448 |
|
| 5449 |
template<typename Derived> |
| 5450 |
QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { |
| 5451 |
if (!isa<DependentNameType>(T)) |
| 5452 |
return TransformType(T); |
| 5453 |
|
| 5454 |
if (getDerived().AlreadyTransformed(T)) |
| 5455 |
return T; |
| 5456 |
TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo( |
| 5457 |
T, getDerived().getBaseLocation()); |
| 5458 |
TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI); |
| 5459 |
return NewTSI ? NewTSI->getType() : QualType(); |
| 5460 |
} |
| 5461 |
|
| 5462 |
template <typename Derived> |
| 5463 |
TypeSourceInfo * |
| 5464 |
TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *TSI) { |
| 5465 |
if (!isa<DependentNameType>(TSI->getType())) |
| 5466 |
return TransformType(TSI); |
| 5467 |
|
| 5468 |
// Refine the base location to the type's location. |
| 5469 |
TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(), |
| 5470 |
getDerived().getBaseEntity()); |
| 5471 |
if (getDerived().AlreadyTransformed(TSI->getType())) |
| 5472 |
return TSI; |
| 5473 |
|
| 5474 |
TypeLocBuilder TLB; |
| 5475 |
|
| 5476 |
TypeLoc TL = TSI->getTypeLoc(); |
| 5477 |
TLB.reserve(TL.getFullDataSize()); |
| 5478 |
|
| 5479 |
auto QTL = TL.getAs<QualifiedTypeLoc>(); |
| 5480 |
if (QTL) |
| 5481 |
TL = QTL.getUnqualifiedLoc(); |
| 5482 |
|
| 5483 |
auto DNTL = TL.castAs<DependentNameTypeLoc>(); |
| 5484 |
|
| 5485 |
QualType Result = getDerived().TransformDependentNameType( |
| 5486 |
TLB, DNTL, /*DeducedTSTContext*/true); |
| 5487 |
if (Result.isNull()) |
| 5488 |
return nullptr; |
| 5489 |
|
| 5490 |
if (QTL) { |
| 5491 |
Result = getDerived().RebuildQualifiedType(Result, QTL); |
| 5492 |
if (Result.isNull()) |
| 5493 |
return nullptr; |
| 5494 |
TLB.TypeWasModifiedSafely(Result); |
| 5495 |
} |
| 5496 |
|
| 5497 |
return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 5498 |
} |
| 5499 |
|
| 5500 |
template<typename Derived> |
| 5501 |
QualType |
| 5502 |
TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 5503 |
QualifiedTypeLoc T) { |
| 5504 |
QualType Result; |
| 5505 |
TypeLoc UnqualTL = T.getUnqualifiedLoc(); |
| 5506 |
auto SuppressObjCLifetime = |
| 5507 |
T.getType().getLocalQualifiers().hasObjCLifetime(); |
| 5508 |
if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) { |
| 5509 |
Result = getDerived().TransformTemplateTypeParmType(TLB, TTP, |
| 5510 |
SuppressObjCLifetime); |
| 5511 |
} else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) { |
| 5512 |
Result = getDerived().TransformSubstTemplateTypeParmPackType( |
| 5513 |
TLB, STTP, SuppressObjCLifetime); |
| 5514 |
} else { |
| 5515 |
Result = getDerived().TransformType(TLB, UnqualTL); |
| 5516 |
} |
| 5517 |
|
| 5518 |
if (Result.isNull()) |
| 5519 |
return QualType(); |
| 5520 |
|
| 5521 |
Result = getDerived().RebuildQualifiedType(Result, T); |
| 5522 |
|
| 5523 |
if (Result.isNull()) |
| 5524 |
return QualType(); |
| 5525 |
|
| 5526 |
// RebuildQualifiedType might have updated the type, but not in a way |
| 5527 |
// that invalidates the TypeLoc. (There's no location information for |
| 5528 |
// qualifiers.) |
| 5529 |
TLB.TypeWasModifiedSafely(Result); |
| 5530 |
|
| 5531 |
return Result; |
| 5532 |
} |
| 5533 |
|
| 5534 |
template <typename Derived> |
| 5535 |
QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, |
| 5536 |
QualifiedTypeLoc TL) { |
| 5537 |
|
| 5538 |
SourceLocation Loc = TL.getBeginLoc(); |
| 5539 |
Qualifiers Quals = TL.getType().getLocalQualifiers(); |
| 5540 |
|
| 5541 |
if ((T.getAddressSpace() != LangAS::Default && |
| 5542 |
Quals.getAddressSpace() != LangAS::Default) && |
| 5543 |
T.getAddressSpace() != Quals.getAddressSpace()) { |
| 5544 |
SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) |
| 5545 |
<< TL.getType() << T; |
| 5546 |
return QualType(); |
| 5547 |
} |
| 5548 |
|
| 5549 |
PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth(); |
| 5550 |
if (LocalPointerAuth.isPresent()) { |
| 5551 |
if (T.getPointerAuth().isPresent()) { |
| 5552 |
SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType(); |
| 5553 |
return QualType(); |
| 5554 |
} |
| 5555 |
if (!T->isDependentType()) { |
| 5556 |
if (!T->isSignableType(SemaRef.getASTContext())) { |
| 5557 |
SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T; |
| 5558 |
return QualType(); |
| 5559 |
} |
| 5560 |
} |
| 5561 |
} |
| 5562 |
// C++ [dcl.fct]p7: |
| 5563 |
// [When] adding cv-qualifications on top of the function type [...] the |
| 5564 |
// cv-qualifiers are ignored. |
| 5565 |
if (T->isFunctionType()) { |
| 5566 |
T = SemaRef.getASTContext().getAddrSpaceQualType(T, |
| 5567 |
Quals.getAddressSpace()); |
| 5568 |
return T; |
| 5569 |
} |
| 5570 |
|
| 5571 |
// C++ [dcl.ref]p1: |
| 5572 |
// when the cv-qualifiers are introduced through the use of a typedef-name |
| 5573 |
// or decltype-specifier [...] the cv-qualifiers are ignored. |
| 5574 |
// Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be |
| 5575 |
// applied to a reference type. |
| 5576 |
if (T->isReferenceType()) { |
| 5577 |
// The only qualifier that applies to a reference type is restrict. |
| 5578 |
if (!Quals.hasRestrict()) |
| 5579 |
return T; |
| 5580 |
Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); |
| 5581 |
} |
| 5582 |
|
| 5583 |
// Suppress Objective-C lifetime qualifiers if they don't make sense for the |
| 5584 |
// resulting type. |
| 5585 |
if (Quals.hasObjCLifetime()) { |
| 5586 |
if (!T->isObjCLifetimeType() && !T->isDependentType()) |
| 5587 |
Quals.removeObjCLifetime(); |
| 5588 |
else if (T.getObjCLifetime()) { |
| 5589 |
// Objective-C ARC: |
| 5590 |
// A lifetime qualifier applied to a substituted template parameter |
| 5591 |
// overrides the lifetime qualifier from the template argument. |
| 5592 |
const AutoType *AutoTy; |
| 5593 |
if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { |
| 5594 |
// 'auto' types behave the same way as template parameters. |
| 5595 |
QualType Deduced = AutoTy->getDeducedType(); |
| 5596 |
Qualifiers Qs = Deduced.getQualifiers(); |
| 5597 |
Qs.removeObjCLifetime(); |
| 5598 |
Deduced = |
| 5599 |
SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); |
| 5600 |
T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
| 5601 |
AutoTy->isDependentType(), |
| 5602 |
/*isPack=*/false, |
| 5603 |
AutoTy->getTypeConstraintConcept(), |
| 5604 |
AutoTy->getTypeConstraintArguments()); |
| 5605 |
} else { |
| 5606 |
// Otherwise, complain about the addition of a qualifier to an |
| 5607 |
// already-qualified type. |
| 5608 |
// FIXME: Why is this check not in Sema::BuildQualifiedType? |
| 5609 |
SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; |
| 5610 |
Quals.removeObjCLifetime(); |
| 5611 |
} |
| 5612 |
} |
| 5613 |
} |
| 5614 |
|
| 5615 |
return SemaRef.BuildQualifiedType(T, Loc, Quals); |
| 5616 |
} |
| 5617 |
|
| 5618 |
template <typename Derived> |
| 5619 |
QualType TreeTransform<Derived>::TransformTypeInObjectScope( |
| 5620 |
TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType, |
| 5621 |
NamedDecl *FirstQualifierInScope) { |
| 5622 |
assert(!getDerived().AlreadyTransformed(TL.getType())); |
| 5623 |
|
| 5624 |
switch (TL.getTypeLocClass()) { |
| 5625 |
case TypeLoc::TemplateSpecialization: |
| 5626 |
return getDerived().TransformTemplateSpecializationType( |
| 5627 |
TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType, |
| 5628 |
FirstQualifierInScope, /*AllowInjectedClassName=*/true); |
| 5629 |
case TypeLoc::DependentName: |
| 5630 |
return getDerived().TransformDependentNameType( |
| 5631 |
TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false, |
| 5632 |
ObjectType, FirstQualifierInScope); |
| 5633 |
default: |
| 5634 |
// Any dependent canonical type can appear here, through type alias |
| 5635 |
// templates. |
| 5636 |
return getDerived().TransformType(TLB, TL); |
| 5637 |
} |
| 5638 |
} |
| 5639 |
|
| 5640 |
template <class TyLoc> static inline |
| 5641 |
QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 5642 |
TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 5643 |
NewT.setNameLoc(T.getNameLoc()); |
| 5644 |
return T.getType(); |
| 5645 |
} |
| 5646 |
|
| 5647 |
template<typename Derived> |
| 5648 |
QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 5649 |
BuiltinTypeLoc T) { |
| 5650 |
BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 5651 |
NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 5652 |
if (T.needsExtraLocalData()) |
| 5653 |
NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 5654 |
return T.getType(); |
| 5655 |
} |
| 5656 |
|
| 5657 |
template<typename Derived> |
| 5658 |
QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 5659 |
ComplexTypeLoc T) { |
| 5660 |
// FIXME: recurse? |
| 5661 |
return TransformTypeSpecType(TLB, T); |
| 5662 |
} |
| 5663 |
|
| 5664 |
template <typename Derived> |
| 5665 |
QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 5666 |
AdjustedTypeLoc TL) { |
| 5667 |
// Adjustments applied during transformation are handled elsewhere. |
| 5668 |
return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 5669 |
} |
| 5670 |
|
| 5671 |
template<typename Derived> |
| 5672 |
QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 5673 |
DecayedTypeLoc TL) { |
| 5674 |
QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 5675 |
if (OriginalType.isNull()) |
| 5676 |
return QualType(); |
| 5677 |
|
| 5678 |
QualType Result = TL.getType(); |
| 5679 |
if (getDerived().AlwaysRebuild() || |
| 5680 |
OriginalType != TL.getOriginalLoc().getType()) |
| 5681 |
Result = SemaRef.Context.getDecayedType(OriginalType); |
| 5682 |
TLB.push<DecayedTypeLoc>(Result); |
| 5683 |
// Nothing to set for DecayedTypeLoc. |
| 5684 |
return Result; |
| 5685 |
} |
| 5686 |
|
| 5687 |
template <typename Derived> |
| 5688 |
QualType |
| 5689 |
TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB, |
| 5690 |
ArrayParameterTypeLoc TL) { |
| 5691 |
QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5692 |
if (OriginalType.isNull()) |
| 5693 |
return QualType(); |
| 5694 |
|
| 5695 |
QualType Result = TL.getType(); |
| 5696 |
if (getDerived().AlwaysRebuild() || |
| 5697 |
OriginalType != TL.getElementLoc().getType()) |
| 5698 |
Result = SemaRef.Context.getArrayParameterType(OriginalType); |
| 5699 |
TLB.push<ArrayParameterTypeLoc>(Result); |
| 5700 |
// Nothing to set for ArrayParameterTypeLoc. |
| 5701 |
return Result; |
| 5702 |
} |
| 5703 |
|
| 5704 |
template<typename Derived> |
| 5705 |
QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 5706 |
PointerTypeLoc TL) { |
| 5707 |
QualType PointeeType |
| 5708 |
= getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5709 |
if (PointeeType.isNull()) |
| 5710 |
return QualType(); |
| 5711 |
|
| 5712 |
QualType Result = TL.getType(); |
| 5713 |
if (PointeeType->getAs<ObjCObjectType>()) { |
| 5714 |
// A dependent pointer type 'T *' has is being transformed such |
| 5715 |
// that an Objective-C class type is being replaced for 'T'. The |
| 5716 |
// resulting pointer type is an ObjCObjectPointerType, not a |
| 5717 |
// PointerType. |
| 5718 |
Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 5719 |
|
| 5720 |
ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 5721 |
NewT.setStarLoc(TL.getStarLoc()); |
| 5722 |
return Result; |
| 5723 |
} |
| 5724 |
|
| 5725 |
if (getDerived().AlwaysRebuild() || |
| 5726 |
PointeeType != TL.getPointeeLoc().getType()) { |
| 5727 |
Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 5728 |
if (Result.isNull()) |
| 5729 |
return QualType(); |
| 5730 |
} |
| 5731 |
|
| 5732 |
// Objective-C ARC can add lifetime qualifiers to the type that we're |
| 5733 |
// pointing to. |
| 5734 |
TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| 5735 |
|
| 5736 |
PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 5737 |
NewT.setSigilLoc(TL.getSigilLoc()); |
| 5738 |
return Result; |
| 5739 |
} |
| 5740 |
|
| 5741 |
template<typename Derived> |
| 5742 |
QualType |
| 5743 |
TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 5744 |
BlockPointerTypeLoc TL) { |
| 5745 |
QualType PointeeType |
| 5746 |
= getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5747 |
if (PointeeType.isNull()) |
| 5748 |
return QualType(); |
| 5749 |
|
| 5750 |
QualType Result = TL.getType(); |
| 5751 |
if (getDerived().AlwaysRebuild() || |
| 5752 |
PointeeType != TL.getPointeeLoc().getType()) { |
| 5753 |
Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 5754 |
TL.getSigilLoc()); |
| 5755 |
if (Result.isNull()) |
| 5756 |
return QualType(); |
| 5757 |
} |
| 5758 |
|
| 5759 |
BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
| 5760 |
NewT.setSigilLoc(TL.getSigilLoc()); |
| 5761 |
return Result; |
| 5762 |
} |
| 5763 |
|
| 5764 |
/// Transforms a reference type. Note that somewhat paradoxically we |
| 5765 |
/// don't care whether the type itself is an l-value type or an r-value |
| 5766 |
/// type; we only care if the type was *written* as an l-value type |
| 5767 |
/// or an r-value type. |
| 5768 |
template<typename Derived> |
| 5769 |
QualType |
| 5770 |
TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 5771 |
ReferenceTypeLoc TL) { |
| 5772 |
const ReferenceType *T = TL.getTypePtr(); |
| 5773 |
|
| 5774 |
// Note that this works with the pointee-as-written. |
| 5775 |
QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5776 |
if (PointeeType.isNull()) |
| 5777 |
return QualType(); |
| 5778 |
|
| 5779 |
QualType Result = TL.getType(); |
| 5780 |
if (getDerived().AlwaysRebuild() || |
| 5781 |
PointeeType != T->getPointeeTypeAsWritten()) { |
| 5782 |
Result = getDerived().RebuildReferenceType(PointeeType, |
| 5783 |
T->isSpelledAsLValue(), |
| 5784 |
TL.getSigilLoc()); |
| 5785 |
if (Result.isNull()) |
| 5786 |
return QualType(); |
| 5787 |
} |
| 5788 |
|
| 5789 |
// Objective-C ARC can add lifetime qualifiers to the type that we're |
| 5790 |
// referring to. |
| 5791 |
TLB.TypeWasModifiedSafely( |
| 5792 |
Result->castAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 5793 |
|
| 5794 |
// r-value references can be rebuilt as l-value references. |
| 5795 |
ReferenceTypeLoc NewTL; |
| 5796 |
if (isa<LValueReferenceType>(Result)) |
| 5797 |
NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 5798 |
else |
| 5799 |
NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 5800 |
NewTL.setSigilLoc(TL.getSigilLoc()); |
| 5801 |
|
| 5802 |
return Result; |
| 5803 |
} |
| 5804 |
|
| 5805 |
template<typename Derived> |
| 5806 |
QualType |
| 5807 |
TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 5808 |
LValueReferenceTypeLoc TL) { |
| 5809 |
return TransformReferenceType(TLB, TL); |
| 5810 |
} |
| 5811 |
|
| 5812 |
template<typename Derived> |
| 5813 |
QualType |
| 5814 |
TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 5815 |
RValueReferenceTypeLoc TL) { |
| 5816 |
return TransformReferenceType(TLB, TL); |
| 5817 |
} |
| 5818 |
|
| 5819 |
template<typename Derived> |
| 5820 |
QualType |
| 5821 |
TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 5822 |
MemberPointerTypeLoc TL) { |
| 5823 |
QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 5824 |
if (PointeeType.isNull()) |
| 5825 |
return QualType(); |
| 5826 |
|
| 5827 |
const MemberPointerType *T = TL.getTypePtr(); |
| 5828 |
|
| 5829 |
NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc(); |
| 5830 |
NestedNameSpecifierLoc NewQualifierLoc = |
| 5831 |
getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc); |
| 5832 |
if (!NewQualifierLoc) |
| 5833 |
return QualType(); |
| 5834 |
|
| 5835 |
CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr; |
| 5836 |
if (OldCls) { |
| 5837 |
NewCls = cast_or_null<CXXRecordDecl>( |
| 5838 |
getDerived().TransformDecl(TL.getStarLoc(), OldCls)); |
| 5839 |
if (!NewCls) |
| 5840 |
return QualType(); |
| 5841 |
} |
| 5842 |
|
| 5843 |
QualType Result = TL.getType(); |
| 5844 |
if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() || |
| 5845 |
NewQualifierLoc.getNestedNameSpecifier() != |
| 5846 |
OldQualifierLoc.getNestedNameSpecifier() || |
| 5847 |
NewCls != OldCls) { |
| 5848 |
CXXScopeSpec SS; |
| 5849 |
SS.Adopt(NewQualifierLoc); |
| 5850 |
Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls, |
| 5851 |
TL.getStarLoc()); |
| 5852 |
if (Result.isNull()) |
| 5853 |
return QualType(); |
| 5854 |
} |
| 5855 |
|
| 5856 |
// If we had to adjust the pointee type when building a member pointer, make |
| 5857 |
// sure to push TypeLoc info for it. |
| 5858 |
const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 5859 |
if (MPT && PointeeType != MPT->getPointeeType()) { |
| 5860 |
assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 5861 |
TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 5862 |
} |
| 5863 |
|
| 5864 |
MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 5865 |
NewTL.setSigilLoc(TL.getSigilLoc()); |
| 5866 |
NewTL.setQualifierLoc(NewQualifierLoc); |
| 5867 |
|
| 5868 |
return Result; |
| 5869 |
} |
| 5870 |
|
| 5871 |
template<typename Derived> |
| 5872 |
QualType |
| 5873 |
TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 5874 |
ConstantArrayTypeLoc TL) { |
| 5875 |
const ConstantArrayType *T = TL.getTypePtr(); |
| 5876 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5877 |
if (ElementType.isNull()) |
| 5878 |
return QualType(); |
| 5879 |
|
| 5880 |
// Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 5881 |
Expr *OldSize = TL.getSizeExpr(); |
| 5882 |
if (!OldSize) |
| 5883 |
OldSize = const_cast<Expr*>(T->getSizeExpr()); |
| 5884 |
Expr *NewSize = nullptr; |
| 5885 |
if (OldSize) { |
| 5886 |
EnterExpressionEvaluationContext Unevaluated( |
| 5887 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5888 |
NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>(); |
| 5889 |
NewSize = SemaRef.ActOnConstantExpression(NewSize).get(); |
| 5890 |
} |
| 5891 |
|
| 5892 |
QualType Result = TL.getType(); |
| 5893 |
if (getDerived().AlwaysRebuild() || |
| 5894 |
ElementType != T->getElementType() || |
| 5895 |
(T->getSizeExpr() && NewSize != OldSize)) { |
| 5896 |
Result = getDerived().RebuildConstantArrayType(ElementType, |
| 5897 |
T->getSizeModifier(), |
| 5898 |
T->getSize(), NewSize, |
| 5899 |
T->getIndexTypeCVRQualifiers(), |
| 5900 |
TL.getBracketsRange()); |
| 5901 |
if (Result.isNull()) |
| 5902 |
return QualType(); |
| 5903 |
} |
| 5904 |
|
| 5905 |
// We might have either a ConstantArrayType or a VariableArrayType now: |
| 5906 |
// a ConstantArrayType is allowed to have an element type which is a |
| 5907 |
// VariableArrayType if the type is dependent. Fortunately, all array |
| 5908 |
// types have the same location layout. |
| 5909 |
ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 5910 |
NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5911 |
NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5912 |
NewTL.setSizeExpr(NewSize); |
| 5913 |
|
| 5914 |
return Result; |
| 5915 |
} |
| 5916 |
|
| 5917 |
template<typename Derived> |
| 5918 |
QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
| 5919 |
TypeLocBuilder &TLB, |
| 5920 |
IncompleteArrayTypeLoc TL) { |
| 5921 |
const IncompleteArrayType *T = TL.getTypePtr(); |
| 5922 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5923 |
if (ElementType.isNull()) |
| 5924 |
return QualType(); |
| 5925 |
|
| 5926 |
QualType Result = TL.getType(); |
| 5927 |
if (getDerived().AlwaysRebuild() || |
| 5928 |
ElementType != T->getElementType()) { |
| 5929 |
Result = getDerived().RebuildIncompleteArrayType(ElementType, |
| 5930 |
T->getSizeModifier(), |
| 5931 |
T->getIndexTypeCVRQualifiers(), |
| 5932 |
TL.getBracketsRange()); |
| 5933 |
if (Result.isNull()) |
| 5934 |
return QualType(); |
| 5935 |
} |
| 5936 |
|
| 5937 |
IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 5938 |
NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5939 |
NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5940 |
NewTL.setSizeExpr(nullptr); |
| 5941 |
|
| 5942 |
return Result; |
| 5943 |
} |
| 5944 |
|
| 5945 |
template<typename Derived> |
| 5946 |
QualType |
| 5947 |
TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 5948 |
VariableArrayTypeLoc TL) { |
| 5949 |
const VariableArrayType *T = TL.getTypePtr(); |
| 5950 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5951 |
if (ElementType.isNull()) |
| 5952 |
return QualType(); |
| 5953 |
|
| 5954 |
ExprResult SizeResult; |
| 5955 |
{ |
| 5956 |
EnterExpressionEvaluationContext Context( |
| 5957 |
SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 5958 |
SizeResult = getDerived().TransformExpr(T->getSizeExpr()); |
| 5959 |
} |
| 5960 |
if (SizeResult.isInvalid()) |
| 5961 |
return QualType(); |
| 5962 |
SizeResult = |
| 5963 |
SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); |
| 5964 |
if (SizeResult.isInvalid()) |
| 5965 |
return QualType(); |
| 5966 |
|
| 5967 |
Expr *Size = SizeResult.get(); |
| 5968 |
|
| 5969 |
QualType Result = TL.getType(); |
| 5970 |
if (getDerived().AlwaysRebuild() || |
| 5971 |
ElementType != T->getElementType() || |
| 5972 |
Size != T->getSizeExpr()) { |
| 5973 |
Result = getDerived().RebuildVariableArrayType(ElementType, |
| 5974 |
T->getSizeModifier(), |
| 5975 |
Size, |
| 5976 |
T->getIndexTypeCVRQualifiers(), |
| 5977 |
TL.getBracketsRange()); |
| 5978 |
if (Result.isNull()) |
| 5979 |
return QualType(); |
| 5980 |
} |
| 5981 |
|
| 5982 |
// We might have constant size array now, but fortunately it has the same |
| 5983 |
// location layout. |
| 5984 |
ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 5985 |
NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5986 |
NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5987 |
NewTL.setSizeExpr(Size); |
| 5988 |
|
| 5989 |
return Result; |
| 5990 |
} |
| 5991 |
|
| 5992 |
template<typename Derived> |
| 5993 |
QualType |
| 5994 |
TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 5995 |
DependentSizedArrayTypeLoc TL) { |
| 5996 |
const DependentSizedArrayType *T = TL.getTypePtr(); |
| 5997 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5998 |
if (ElementType.isNull()) |
| 5999 |
return QualType(); |
| 6000 |
|
| 6001 |
// Array bounds are constant expressions. |
| 6002 |
EnterExpressionEvaluationContext Unevaluated( |
| 6003 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6004 |
|
| 6005 |
// If we have a VLA then it won't be a constant. |
| 6006 |
SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true; |
| 6007 |
|
| 6008 |
// Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 6009 |
Expr *origSize = TL.getSizeExpr(); |
| 6010 |
if (!origSize) origSize = T->getSizeExpr(); |
| 6011 |
|
| 6012 |
ExprResult sizeResult |
| 6013 |
= getDerived().TransformExpr(origSize); |
| 6014 |
sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
| 6015 |
if (sizeResult.isInvalid()) |
| 6016 |
return QualType(); |
| 6017 |
|
| 6018 |
Expr *size = sizeResult.get(); |
| 6019 |
|
| 6020 |
QualType Result = TL.getType(); |
| 6021 |
if (getDerived().AlwaysRebuild() || |
| 6022 |
ElementType != T->getElementType() || |
| 6023 |
size != origSize) { |
| 6024 |
Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 6025 |
T->getSizeModifier(), |
| 6026 |
size, |
| 6027 |
T->getIndexTypeCVRQualifiers(), |
| 6028 |
TL.getBracketsRange()); |
| 6029 |
if (Result.isNull()) |
| 6030 |
return QualType(); |
| 6031 |
} |
| 6032 |
|
| 6033 |
// We might have any sort of array type now, but fortunately they |
| 6034 |
// all have the same location layout. |
| 6035 |
ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 6036 |
NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 6037 |
NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 6038 |
NewTL.setSizeExpr(size); |
| 6039 |
|
| 6040 |
return Result; |
| 6041 |
} |
| 6042 |
|
| 6043 |
template <typename Derived> |
| 6044 |
QualType TreeTransform<Derived>::TransformDependentVectorType( |
| 6045 |
TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { |
| 6046 |
const DependentVectorType *T = TL.getTypePtr(); |
| 6047 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 6048 |
if (ElementType.isNull()) |
| 6049 |
return QualType(); |
| 6050 |
|
| 6051 |
EnterExpressionEvaluationContext Unevaluated( |
| 6052 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6053 |
|
| 6054 |
ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 6055 |
Size = SemaRef.ActOnConstantExpression(Size); |
| 6056 |
if (Size.isInvalid()) |
| 6057 |
return QualType(); |
| 6058 |
|
| 6059 |
QualType Result = TL.getType(); |
| 6060 |
if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 6061 |
Size.get() != T->getSizeExpr()) { |
| 6062 |
Result = getDerived().RebuildDependentVectorType( |
| 6063 |
ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); |
| 6064 |
if (Result.isNull()) |
| 6065 |
return QualType(); |
| 6066 |
} |
| 6067 |
|
| 6068 |
// Result might be dependent or not. |
| 6069 |
if (isa<DependentVectorType>(Result)) { |
| 6070 |
DependentVectorTypeLoc NewTL = |
| 6071 |
TLB.push<DependentVectorTypeLoc>(Result); |
| 6072 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6073 |
} else { |
| 6074 |
VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 6075 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6076 |
} |
| 6077 |
|
| 6078 |
return Result; |
| 6079 |
} |
| 6080 |
|
| 6081 |
template<typename Derived> |
| 6082 |
QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
| 6083 |
TypeLocBuilder &TLB, |
| 6084 |
DependentSizedExtVectorTypeLoc TL) { |
| 6085 |
const DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 6086 |
|
| 6087 |
// FIXME: ext vector locs should be nested |
| 6088 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 6089 |
if (ElementType.isNull()) |
| 6090 |
return QualType(); |
| 6091 |
|
| 6092 |
// Vector sizes are constant expressions. |
| 6093 |
EnterExpressionEvaluationContext Unevaluated( |
| 6094 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6095 |
|
| 6096 |
ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 6097 |
Size = SemaRef.ActOnConstantExpression(Size); |
| 6098 |
if (Size.isInvalid()) |
| 6099 |
return QualType(); |
| 6100 |
|
| 6101 |
QualType Result = TL.getType(); |
| 6102 |
if (getDerived().AlwaysRebuild() || |
| 6103 |
ElementType != T->getElementType() || |
| 6104 |
Size.get() != T->getSizeExpr()) { |
| 6105 |
Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
| 6106 |
Size.get(), |
| 6107 |
T->getAttributeLoc()); |
| 6108 |
if (Result.isNull()) |
| 6109 |
return QualType(); |
| 6110 |
} |
| 6111 |
|
| 6112 |
// Result might be dependent or not. |
| 6113 |
if (isa<DependentSizedExtVectorType>(Result)) { |
| 6114 |
DependentSizedExtVectorTypeLoc NewTL |
| 6115 |
= TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 6116 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6117 |
} else { |
| 6118 |
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 6119 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6120 |
} |
| 6121 |
|
| 6122 |
return Result; |
| 6123 |
} |
| 6124 |
|
| 6125 |
template <typename Derived> |
| 6126 |
QualType |
| 6127 |
TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB, |
| 6128 |
ConstantMatrixTypeLoc TL) { |
| 6129 |
const ConstantMatrixType *T = TL.getTypePtr(); |
| 6130 |
QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 6131 |
if (ElementType.isNull()) |
| 6132 |
return QualType(); |
| 6133 |
|
| 6134 |
QualType Result = TL.getType(); |
| 6135 |
if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) { |
| 6136 |
Result = getDerived().RebuildConstantMatrixType( |
| 6137 |
ElementType, T->getNumRows(), T->getNumColumns()); |
| 6138 |
if (Result.isNull()) |
| 6139 |
return QualType(); |
| 6140 |
} |
| 6141 |
|
| 6142 |
ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result); |
| 6143 |
NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 6144 |
NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 6145 |
NewTL.setAttrRowOperand(TL.getAttrRowOperand()); |
| 6146 |
NewTL.setAttrColumnOperand(TL.getAttrColumnOperand()); |
| 6147 |
|
| 6148 |
return Result; |
| 6149 |
} |
| 6150 |
|
| 6151 |
template <typename Derived> |
| 6152 |
QualType TreeTransform<Derived>::TransformDependentSizedMatrixType( |
| 6153 |
TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) { |
| 6154 |
const DependentSizedMatrixType *T = TL.getTypePtr(); |
| 6155 |
|
| 6156 |
QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 6157 |
if (ElementType.isNull()) { |
| 6158 |
return QualType(); |
| 6159 |
} |
| 6160 |
|
| 6161 |
// Matrix dimensions are constant expressions. |
| 6162 |
EnterExpressionEvaluationContext Unevaluated( |
| 6163 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6164 |
|
| 6165 |
Expr *origRows = TL.getAttrRowOperand(); |
| 6166 |
if (!origRows) |
| 6167 |
origRows = T->getRowExpr(); |
| 6168 |
Expr *origColumns = TL.getAttrColumnOperand(); |
| 6169 |
if (!origColumns) |
| 6170 |
origColumns = T->getColumnExpr(); |
| 6171 |
|
| 6172 |
ExprResult rowResult = getDerived().TransformExpr(origRows); |
| 6173 |
rowResult = SemaRef.ActOnConstantExpression(rowResult); |
| 6174 |
if (rowResult.isInvalid()) |
| 6175 |
return QualType(); |
| 6176 |
|
| 6177 |
ExprResult columnResult = getDerived().TransformExpr(origColumns); |
| 6178 |
columnResult = SemaRef.ActOnConstantExpression(columnResult); |
| 6179 |
if (columnResult.isInvalid()) |
| 6180 |
return QualType(); |
| 6181 |
|
| 6182 |
Expr *rows = rowResult.get(); |
| 6183 |
Expr *columns = columnResult.get(); |
| 6184 |
|
| 6185 |
QualType Result = TL.getType(); |
| 6186 |
if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 6187 |
rows != origRows || columns != origColumns) { |
| 6188 |
Result = getDerived().RebuildDependentSizedMatrixType( |
| 6189 |
ElementType, rows, columns, T->getAttributeLoc()); |
| 6190 |
|
| 6191 |
if (Result.isNull()) |
| 6192 |
return QualType(); |
| 6193 |
} |
| 6194 |
|
| 6195 |
// We might have any sort of matrix type now, but fortunately they |
| 6196 |
// all have the same location layout. |
| 6197 |
MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result); |
| 6198 |
NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 6199 |
NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 6200 |
NewTL.setAttrRowOperand(rows); |
| 6201 |
NewTL.setAttrColumnOperand(columns); |
| 6202 |
return Result; |
| 6203 |
} |
| 6204 |
|
| 6205 |
template <typename Derived> |
| 6206 |
QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( |
| 6207 |
TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { |
| 6208 |
const DependentAddressSpaceType *T = TL.getTypePtr(); |
| 6209 |
|
| 6210 |
QualType pointeeType = |
| 6211 |
getDerived().TransformType(TLB, TL.getPointeeTypeLoc()); |
| 6212 |
|
| 6213 |
if (pointeeType.isNull()) |
| 6214 |
return QualType(); |
| 6215 |
|
| 6216 |
// Address spaces are constant expressions. |
| 6217 |
EnterExpressionEvaluationContext Unevaluated( |
| 6218 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6219 |
|
| 6220 |
ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); |
| 6221 |
AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); |
| 6222 |
if (AddrSpace.isInvalid()) |
| 6223 |
return QualType(); |
| 6224 |
|
| 6225 |
QualType Result = TL.getType(); |
| 6226 |
if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || |
| 6227 |
AddrSpace.get() != T->getAddrSpaceExpr()) { |
| 6228 |
Result = getDerived().RebuildDependentAddressSpaceType( |
| 6229 |
pointeeType, AddrSpace.get(), T->getAttributeLoc()); |
| 6230 |
if (Result.isNull()) |
| 6231 |
return QualType(); |
| 6232 |
} |
| 6233 |
|
| 6234 |
// Result might be dependent or not. |
| 6235 |
if (isa<DependentAddressSpaceType>(Result)) { |
| 6236 |
DependentAddressSpaceTypeLoc NewTL = |
| 6237 |
TLB.push<DependentAddressSpaceTypeLoc>(Result); |
| 6238 |
|
| 6239 |
NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 6240 |
NewTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 6241 |
NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 6242 |
|
| 6243 |
} else { |
| 6244 |
TLB.TypeWasModifiedSafely(Result); |
| 6245 |
} |
| 6246 |
|
| 6247 |
return Result; |
| 6248 |
} |
| 6249 |
|
| 6250 |
template <typename Derived> |
| 6251 |
QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 6252 |
VectorTypeLoc TL) { |
| 6253 |
const VectorType *T = TL.getTypePtr(); |
| 6254 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 6255 |
if (ElementType.isNull()) |
| 6256 |
return QualType(); |
| 6257 |
|
| 6258 |
QualType Result = TL.getType(); |
| 6259 |
if (getDerived().AlwaysRebuild() || |
| 6260 |
ElementType != T->getElementType()) { |
| 6261 |
Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 6262 |
T->getVectorKind()); |
| 6263 |
if (Result.isNull()) |
| 6264 |
return QualType(); |
| 6265 |
} |
| 6266 |
|
| 6267 |
VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 6268 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6269 |
|
| 6270 |
return Result; |
| 6271 |
} |
| 6272 |
|
| 6273 |
template<typename Derived> |
| 6274 |
QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 6275 |
ExtVectorTypeLoc TL) { |
| 6276 |
const VectorType *T = TL.getTypePtr(); |
| 6277 |
QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 6278 |
if (ElementType.isNull()) |
| 6279 |
return QualType(); |
| 6280 |
|
| 6281 |
QualType Result = TL.getType(); |
| 6282 |
if (getDerived().AlwaysRebuild() || |
| 6283 |
ElementType != T->getElementType()) { |
| 6284 |
Result = getDerived().RebuildExtVectorType(ElementType, |
| 6285 |
T->getNumElements(), |
| 6286 |
/*FIXME*/ SourceLocation()); |
| 6287 |
if (Result.isNull()) |
| 6288 |
return QualType(); |
| 6289 |
} |
| 6290 |
|
| 6291 |
ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 6292 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 6293 |
|
| 6294 |
return Result; |
| 6295 |
} |
| 6296 |
|
| 6297 |
template <typename Derived> |
| 6298 |
ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 6299 |
ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, |
| 6300 |
bool ExpectParameterPack) { |
| 6301 |
TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo(); |
| 6302 |
TypeSourceInfo *NewTSI = nullptr; |
| 6303 |
|
| 6304 |
if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) { |
| 6305 |
// If we're substituting into a pack expansion type and we know the |
| 6306 |
// length we want to expand to, just substitute for the pattern. |
| 6307 |
TypeLoc OldTL = OldTSI->getTypeLoc(); |
| 6308 |
PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
| 6309 |
|
| 6310 |
TypeLocBuilder TLB; |
| 6311 |
TypeLoc NewTL = OldTSI->getTypeLoc(); |
| 6312 |
TLB.reserve(NewTL.getFullDataSize()); |
| 6313 |
|
| 6314 |
QualType Result = getDerived().TransformType(TLB, |
| 6315 |
OldExpansionTL.getPatternLoc()); |
| 6316 |
if (Result.isNull()) |
| 6317 |
return nullptr; |
| 6318 |
|
| 6319 |
Result = RebuildPackExpansionType(Result, |
| 6320 |
OldExpansionTL.getPatternLoc().getSourceRange(), |
| 6321 |
OldExpansionTL.getEllipsisLoc(), |
| 6322 |
NumExpansions); |
| 6323 |
if (Result.isNull()) |
| 6324 |
return nullptr; |
| 6325 |
|
| 6326 |
PackExpansionTypeLoc NewExpansionTL |
| 6327 |
= TLB.push<PackExpansionTypeLoc>(Result); |
| 6328 |
NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 6329 |
NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 6330 |
} else |
| 6331 |
NewTSI = getDerived().TransformType(OldTSI); |
| 6332 |
if (!NewTSI) |
| 6333 |
return nullptr; |
| 6334 |
|
| 6335 |
if (NewTSI == OldTSI && indexAdjustment == 0) |
| 6336 |
return OldParm; |
| 6337 |
|
| 6338 |
ParmVarDecl *newParm = ParmVarDecl::Create( |
| 6339 |
SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(), |
| 6340 |
OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(), |
| 6341 |
NewTSI, OldParm->getStorageClass(), |
| 6342 |
/* DefArg */ nullptr); |
| 6343 |
newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 6344 |
OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 6345 |
getDerived().transformedLocalDecl(OldParm, {newParm}); |
| 6346 |
return newParm; |
| 6347 |
} |
| 6348 |
|
| 6349 |
template <typename Derived> |
| 6350 |
bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 6351 |
SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 6352 |
const QualType *ParamTypes, |
| 6353 |
const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 6354 |
SmallVectorImpl<QualType> &OutParamTypes, |
| 6355 |
SmallVectorImpl<ParmVarDecl *> *PVars, |
| 6356 |
Sema::ExtParameterInfoBuilder &PInfos, |
| 6357 |
unsigned *LastParamTransformed) { |
| 6358 |
int indexAdjustment = 0; |
| 6359 |
|
| 6360 |
unsigned NumParams = Params.size(); |
| 6361 |
for (unsigned i = 0; i != NumParams; ++i) { |
| 6362 |
if (LastParamTransformed) |
| 6363 |
*LastParamTransformed = i; |
| 6364 |
if (ParmVarDecl *OldParm = Params[i]) { |
| 6365 |
assert(OldParm->getFunctionScopeIndex() == i); |
| 6366 |
|
| 6367 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 6368 |
ParmVarDecl *NewParm = nullptr; |
| 6369 |
if (OldParm->isParameterPack()) { |
| 6370 |
// We have a function parameter pack that may need to be expanded. |
| 6371 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6372 |
|
| 6373 |
// Find the parameter packs that could be expanded. |
| 6374 |
TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 6375 |
PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
| 6376 |
TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 6377 |
SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 6378 |
|
| 6379 |
// Determine whether we should expand the parameter packs. |
| 6380 |
bool ShouldExpand = false; |
| 6381 |
bool RetainExpansion = false; |
| 6382 |
UnsignedOrNone OrigNumExpansions = std::nullopt; |
| 6383 |
if (Unexpanded.size() > 0) { |
| 6384 |
OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 6385 |
NumExpansions = OrigNumExpansions; |
| 6386 |
if (getDerived().TryExpandParameterPacks( |
| 6387 |
ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(), |
| 6388 |
Unexpanded, /*FailOnPackProducingTemplates=*/true, |
| 6389 |
ShouldExpand, RetainExpansion, NumExpansions)) { |
| 6390 |
return true; |
| 6391 |
} |
| 6392 |
} else { |
| 6393 |
#ifndef NDEBUG |
| 6394 |
const AutoType *AT = |
| 6395 |
Pattern.getType().getTypePtr()->getContainedAutoType(); |
| 6396 |
assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) && |
| 6397 |
"Could not find parameter packs or undeduced auto type!"); |
| 6398 |
#endif |
| 6399 |
} |
| 6400 |
|
| 6401 |
if (ShouldExpand) { |
| 6402 |
// Expand the function parameter pack into multiple, separate |
| 6403 |
// parameters. |
| 6404 |
getDerived().ExpandingFunctionParameterPack(OldParm); |
| 6405 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 6406 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 6407 |
ParmVarDecl *NewParm |
| 6408 |
= getDerived().TransformFunctionTypeParam(OldParm, |
| 6409 |
indexAdjustment++, |
| 6410 |
OrigNumExpansions, |
| 6411 |
/*ExpectParameterPack=*/false); |
| 6412 |
if (!NewParm) |
| 6413 |
return true; |
| 6414 |
|
| 6415 |
if (ParamInfos) |
| 6416 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6417 |
OutParamTypes.push_back(NewParm->getType()); |
| 6418 |
if (PVars) |
| 6419 |
PVars->push_back(NewParm); |
| 6420 |
} |
| 6421 |
|
| 6422 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 6423 |
// forgetting the partially-substituted parameter pack. |
| 6424 |
if (RetainExpansion) { |
| 6425 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 6426 |
ParmVarDecl *NewParm |
| 6427 |
= getDerived().TransformFunctionTypeParam(OldParm, |
| 6428 |
indexAdjustment++, |
| 6429 |
OrigNumExpansions, |
| 6430 |
/*ExpectParameterPack=*/false); |
| 6431 |
if (!NewParm) |
| 6432 |
return true; |
| 6433 |
|
| 6434 |
if (ParamInfos) |
| 6435 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6436 |
OutParamTypes.push_back(NewParm->getType()); |
| 6437 |
if (PVars) |
| 6438 |
PVars->push_back(NewParm); |
| 6439 |
} |
| 6440 |
|
| 6441 |
// The next parameter should have the same adjustment as the |
| 6442 |
// last thing we pushed, but we post-incremented indexAdjustment |
| 6443 |
// on every push. Also, if we push nothing, the adjustment should |
| 6444 |
// go down by one. |
| 6445 |
indexAdjustment--; |
| 6446 |
|
| 6447 |
// We're done with the pack expansion. |
| 6448 |
continue; |
| 6449 |
} |
| 6450 |
|
| 6451 |
// We'll substitute the parameter now without expanding the pack |
| 6452 |
// expansion. |
| 6453 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 6454 |
NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 6455 |
indexAdjustment, |
| 6456 |
NumExpansions, |
| 6457 |
/*ExpectParameterPack=*/true); |
| 6458 |
assert(NewParm->isParameterPack() && |
| 6459 |
"Parameter pack no longer a parameter pack after " |
| 6460 |
"transformation."); |
| 6461 |
} else { |
| 6462 |
NewParm = getDerived().TransformFunctionTypeParam( |
| 6463 |
OldParm, indexAdjustment, std::nullopt, |
| 6464 |
/*ExpectParameterPack=*/false); |
| 6465 |
} |
| 6466 |
|
| 6467 |
if (!NewParm) |
| 6468 |
return true; |
| 6469 |
|
| 6470 |
if (ParamInfos) |
| 6471 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6472 |
OutParamTypes.push_back(NewParm->getType()); |
| 6473 |
if (PVars) |
| 6474 |
PVars->push_back(NewParm); |
| 6475 |
continue; |
| 6476 |
} |
| 6477 |
|
| 6478 |
// Deal with the possibility that we don't have a parameter |
| 6479 |
// declaration for this parameter. |
| 6480 |
assert(ParamTypes); |
| 6481 |
QualType OldType = ParamTypes[i]; |
| 6482 |
bool IsPackExpansion = false; |
| 6483 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 6484 |
QualType NewType; |
| 6485 |
if (const PackExpansionType *Expansion |
| 6486 |
= dyn_cast<PackExpansionType>(OldType)) { |
| 6487 |
// We have a function parameter pack that may need to be expanded. |
| 6488 |
QualType Pattern = Expansion->getPattern(); |
| 6489 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6490 |
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 6491 |
|
| 6492 |
// Determine whether we should expand the parameter packs. |
| 6493 |
bool ShouldExpand = false; |
| 6494 |
bool RetainExpansion = false; |
| 6495 |
if (getDerived().TryExpandParameterPacks( |
| 6496 |
Loc, SourceRange(), Unexpanded, |
| 6497 |
/*FailOnPackProducingTemplates=*/true, ShouldExpand, |
| 6498 |
RetainExpansion, NumExpansions)) { |
| 6499 |
return true; |
| 6500 |
} |
| 6501 |
|
| 6502 |
if (ShouldExpand) { |
| 6503 |
// Expand the function parameter pack into multiple, separate |
| 6504 |
// parameters. |
| 6505 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 6506 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 6507 |
QualType NewType = getDerived().TransformType(Pattern); |
| 6508 |
if (NewType.isNull()) |
| 6509 |
return true; |
| 6510 |
|
| 6511 |
if (NewType->containsUnexpandedParameterPack()) { |
| 6512 |
NewType = getSema().getASTContext().getPackExpansionType( |
| 6513 |
NewType, std::nullopt); |
| 6514 |
|
| 6515 |
if (NewType.isNull()) |
| 6516 |
return true; |
| 6517 |
} |
| 6518 |
|
| 6519 |
if (ParamInfos) |
| 6520 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6521 |
OutParamTypes.push_back(NewType); |
| 6522 |
if (PVars) |
| 6523 |
PVars->push_back(nullptr); |
| 6524 |
} |
| 6525 |
|
| 6526 |
// We're done with the pack expansion. |
| 6527 |
continue; |
| 6528 |
} |
| 6529 |
|
| 6530 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 6531 |
// forgetting the partially-substituted parameter pack. |
| 6532 |
if (RetainExpansion) { |
| 6533 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 6534 |
QualType NewType = getDerived().TransformType(Pattern); |
| 6535 |
if (NewType.isNull()) |
| 6536 |
return true; |
| 6537 |
|
| 6538 |
if (ParamInfos) |
| 6539 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6540 |
OutParamTypes.push_back(NewType); |
| 6541 |
if (PVars) |
| 6542 |
PVars->push_back(nullptr); |
| 6543 |
} |
| 6544 |
|
| 6545 |
// We'll substitute the parameter now without expanding the pack |
| 6546 |
// expansion. |
| 6547 |
OldType = Expansion->getPattern(); |
| 6548 |
IsPackExpansion = true; |
| 6549 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 6550 |
NewType = getDerived().TransformType(OldType); |
| 6551 |
} else { |
| 6552 |
NewType = getDerived().TransformType(OldType); |
| 6553 |
} |
| 6554 |
|
| 6555 |
if (NewType.isNull()) |
| 6556 |
return true; |
| 6557 |
|
| 6558 |
if (IsPackExpansion) |
| 6559 |
NewType = getSema().Context.getPackExpansionType(NewType, |
| 6560 |
NumExpansions); |
| 6561 |
|
| 6562 |
if (ParamInfos) |
| 6563 |
PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 6564 |
OutParamTypes.push_back(NewType); |
| 6565 |
if (PVars) |
| 6566 |
PVars->push_back(nullptr); |
| 6567 |
} |
| 6568 |
|
| 6569 |
#ifndef NDEBUG |
| 6570 |
if (PVars) { |
| 6571 |
for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 6572 |
if (ParmVarDecl *parm = (*PVars)[i]) |
| 6573 |
assert(parm->getFunctionScopeIndex() == i); |
| 6574 |
} |
| 6575 |
#endif |
| 6576 |
|
| 6577 |
return false; |
| 6578 |
} |
| 6579 |
|
| 6580 |
template<typename Derived> |
| 6581 |
QualType |
| 6582 |
TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 6583 |
FunctionProtoTypeLoc TL) { |
| 6584 |
SmallVector<QualType, 4> ExceptionStorage; |
| 6585 |
return getDerived().TransformFunctionProtoType( |
| 6586 |
TLB, TL, nullptr, Qualifiers(), |
| 6587 |
[&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 6588 |
return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 6589 |
ExceptionStorage, Changed); |
| 6590 |
}); |
| 6591 |
} |
| 6592 |
|
| 6593 |
template<typename Derived> template<typename Fn> |
| 6594 |
QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 6595 |
TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 6596 |
Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { |
| 6597 |
|
| 6598 |
// Transform the parameters and return type. |
| 6599 |
// |
| 6600 |
// We are required to instantiate the params and return type in source order. |
| 6601 |
// When the function has a trailing return type, we instantiate the |
| 6602 |
// parameters before the return type, since the return type can then refer |
| 6603 |
// to the parameters themselves (via decltype, sizeof, etc.). |
| 6604 |
// |
| 6605 |
SmallVector<QualType, 4> ParamTypes; |
| 6606 |
SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 6607 |
Sema::ExtParameterInfoBuilder ExtParamInfos; |
| 6608 |
const FunctionProtoType *T = TL.getTypePtr(); |
| 6609 |
|
| 6610 |
QualType ResultType; |
| 6611 |
|
| 6612 |
if (T->hasTrailingReturn()) { |
| 6613 |
if (getDerived().TransformFunctionTypeParams( |
| 6614 |
TL.getBeginLoc(), TL.getParams(), |
| 6615 |
TL.getTypePtr()->param_type_begin(), |
| 6616 |
T->getExtParameterInfosOrNull(), |
| 6617 |
ParamTypes, &ParamDecls, ExtParamInfos)) |
| 6618 |
return QualType(); |
| 6619 |
|
| 6620 |
{ |
| 6621 |
// C++11 [expr.prim.general]p3: |
| 6622 |
// If a declaration declares a member function or member function |
| 6623 |
// template of a class X, the expression this is a prvalue of type |
| 6624 |
// "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| 6625 |
// and the end of the function-definition, member-declarator, or |
| 6626 |
// declarator. |
| 6627 |
auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext()); |
| 6628 |
Sema::CXXThisScopeRAII ThisScope( |
| 6629 |
SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals); |
| 6630 |
|
| 6631 |
ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 6632 |
if (ResultType.isNull()) |
| 6633 |
return QualType(); |
| 6634 |
} |
| 6635 |
} |
| 6636 |
else { |
| 6637 |
ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 6638 |
if (ResultType.isNull()) |
| 6639 |
return QualType(); |
| 6640 |
|
| 6641 |
if (getDerived().TransformFunctionTypeParams( |
| 6642 |
TL.getBeginLoc(), TL.getParams(), |
| 6643 |
TL.getTypePtr()->param_type_begin(), |
| 6644 |
T->getExtParameterInfosOrNull(), |
| 6645 |
ParamTypes, &ParamDecls, ExtParamInfos)) |
| 6646 |
return QualType(); |
| 6647 |
} |
| 6648 |
|
| 6649 |
FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 6650 |
|
| 6651 |
bool EPIChanged = false; |
| 6652 |
if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 6653 |
return QualType(); |
| 6654 |
|
| 6655 |
// Handle extended parameter information. |
| 6656 |
if (auto NewExtParamInfos = |
| 6657 |
ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 6658 |
if (!EPI.ExtParameterInfos || |
| 6659 |
llvm::ArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) != |
| 6660 |
llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 6661 |
EPIChanged = true; |
| 6662 |
} |
| 6663 |
EPI.ExtParameterInfos = NewExtParamInfos; |
| 6664 |
} else if (EPI.ExtParameterInfos) { |
| 6665 |
EPIChanged = true; |
| 6666 |
EPI.ExtParameterInfos = nullptr; |
| 6667 |
} |
| 6668 |
|
| 6669 |
// Transform any function effects with unevaluated conditions. |
| 6670 |
// Hold this set in a local for the rest of this function, since EPI |
| 6671 |
// may need to hold a FunctionEffectsRef pointing into it. |
| 6672 |
std::optional<FunctionEffectSet> NewFX; |
| 6673 |
if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) { |
| 6674 |
NewFX.emplace(); |
| 6675 |
EnterExpressionEvaluationContext Unevaluated( |
| 6676 |
getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6677 |
|
| 6678 |
for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) { |
| 6679 |
FunctionEffectWithCondition NewEC = PrevEC; |
| 6680 |
if (Expr *CondExpr = PrevEC.Cond.getCondition()) { |
| 6681 |
ExprResult NewExpr = getDerived().TransformExpr(CondExpr); |
| 6682 |
if (NewExpr.isInvalid()) |
| 6683 |
return QualType(); |
| 6684 |
std::optional<FunctionEffectMode> Mode = |
| 6685 |
SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name()); |
| 6686 |
if (!Mode) |
| 6687 |
return QualType(); |
| 6688 |
|
| 6689 |
// The condition expression has been transformed, and re-evaluated. |
| 6690 |
// It may or may not have become constant. |
| 6691 |
switch (*Mode) { |
| 6692 |
case FunctionEffectMode::True: |
| 6693 |
NewEC.Cond = {}; |
| 6694 |
break; |
| 6695 |
case FunctionEffectMode::False: |
| 6696 |
NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind()); |
| 6697 |
NewEC.Cond = {}; |
| 6698 |
break; |
| 6699 |
case FunctionEffectMode::Dependent: |
| 6700 |
NewEC.Cond = EffectConditionExpr(NewExpr.get()); |
| 6701 |
break; |
| 6702 |
case FunctionEffectMode::None: |
| 6703 |
llvm_unreachable( |
| 6704 |
"FunctionEffectMode::None shouldn't be possible here"); |
| 6705 |
} |
| 6706 |
} |
| 6707 |
if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC, |
| 6708 |
TL.getBeginLoc())) { |
| 6709 |
FunctionEffectSet::Conflicts Errs; |
| 6710 |
NewFX->insert(NewEC, Errs); |
| 6711 |
assert(Errs.empty()); |
| 6712 |
} |
| 6713 |
} |
| 6714 |
EPI.FunctionEffects = *NewFX; |
| 6715 |
EPIChanged = true; |
| 6716 |
} |
| 6717 |
|
| 6718 |
QualType Result = TL.getType(); |
| 6719 |
if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
| 6720 |
T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) { |
| 6721 |
Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
| 6722 |
if (Result.isNull()) |
| 6723 |
return QualType(); |
| 6724 |
} |
| 6725 |
|
| 6726 |
FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 6727 |
NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 6728 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6729 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6730 |
NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); |
| 6731 |
NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| 6732 |
for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 6733 |
NewTL.setParam(i, ParamDecls[i]); |
| 6734 |
|
| 6735 |
return Result; |
| 6736 |
} |
| 6737 |
|
| 6738 |
template<typename Derived> |
| 6739 |
bool TreeTransform<Derived>::TransformExceptionSpec( |
| 6740 |
SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 6741 |
SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 6742 |
assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 6743 |
|
| 6744 |
// Instantiate a dynamic noexcept expression, if any. |
| 6745 |
if (isComputedNoexcept(ESI.Type)) { |
| 6746 |
// Update this scrope because ContextDecl in Sema will be used in |
| 6747 |
// TransformExpr. |
| 6748 |
auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate); |
| 6749 |
Sema::CXXThisScopeRAII ThisScope( |
| 6750 |
SemaRef, Method ? Method->getParent() : nullptr, |
| 6751 |
Method ? Method->getMethodQualifiers() : Qualifiers{}, |
| 6752 |
Method != nullptr); |
| 6753 |
EnterExpressionEvaluationContext Unevaluated( |
| 6754 |
getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6755 |
ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 6756 |
if (NoexceptExpr.isInvalid()) |
| 6757 |
return true; |
| 6758 |
|
| 6759 |
ExceptionSpecificationType EST = ESI.Type; |
| 6760 |
NoexceptExpr = |
| 6761 |
getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST); |
| 6762 |
if (NoexceptExpr.isInvalid()) |
| 6763 |
return true; |
| 6764 |
|
| 6765 |
if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) |
| 6766 |
Changed = true; |
| 6767 |
ESI.NoexceptExpr = NoexceptExpr.get(); |
| 6768 |
ESI.Type = EST; |
| 6769 |
} |
| 6770 |
|
| 6771 |
if (ESI.Type != EST_Dynamic) |
| 6772 |
return false; |
| 6773 |
|
| 6774 |
// Instantiate a dynamic exception specification's type. |
| 6775 |
for (QualType T : ESI.Exceptions) { |
| 6776 |
if (const PackExpansionType *PackExpansion = |
| 6777 |
T->getAs<PackExpansionType>()) { |
| 6778 |
Changed = true; |
| 6779 |
|
| 6780 |
// We have a pack expansion. Instantiate it. |
| 6781 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6782 |
SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 6783 |
Unexpanded); |
| 6784 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 6785 |
|
| 6786 |
// Determine whether the set of unexpanded parameter packs can and |
| 6787 |
// should |
| 6788 |
// be expanded. |
| 6789 |
bool Expand = false; |
| 6790 |
bool RetainExpansion = false; |
| 6791 |
UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions(); |
| 6792 |
// FIXME: Track the location of the ellipsis (and track source location |
| 6793 |
// information for the types in the exception specification in general). |
| 6794 |
if (getDerived().TryExpandParameterPacks( |
| 6795 |
Loc, SourceRange(), Unexpanded, |
| 6796 |
/*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion, |
| 6797 |
NumExpansions)) |
| 6798 |
return true; |
| 6799 |
|
| 6800 |
if (!Expand) { |
| 6801 |
// We can't expand this pack expansion into separate arguments yet; |
| 6802 |
// just substitute into the pattern and create a new pack expansion |
| 6803 |
// type. |
| 6804 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 6805 |
QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 6806 |
if (U.isNull()) |
| 6807 |
return true; |
| 6808 |
|
| 6809 |
U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 6810 |
Exceptions.push_back(U); |
| 6811 |
continue; |
| 6812 |
} |
| 6813 |
|
| 6814 |
// Substitute into the pack expansion pattern for each slice of the |
| 6815 |
// pack. |
| 6816 |
for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 6817 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx); |
| 6818 |
|
| 6819 |
QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 6820 |
if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 6821 |
return true; |
| 6822 |
|
| 6823 |
Exceptions.push_back(U); |
| 6824 |
} |
| 6825 |
} else { |
| 6826 |
QualType U = getDerived().TransformType(T); |
| 6827 |
if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 6828 |
return true; |
| 6829 |
if (T != U) |
| 6830 |
Changed = true; |
| 6831 |
|
| 6832 |
Exceptions.push_back(U); |
| 6833 |
} |
| 6834 |
} |
| 6835 |
|
| 6836 |
ESI.Exceptions = Exceptions; |
| 6837 |
if (ESI.Exceptions.empty()) |
| 6838 |
ESI.Type = EST_DynamicNone; |
| 6839 |
return false; |
| 6840 |
} |
| 6841 |
|
| 6842 |
template<typename Derived> |
| 6843 |
QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
| 6844 |
TypeLocBuilder &TLB, |
| 6845 |
FunctionNoProtoTypeLoc TL) { |
| 6846 |
const FunctionNoProtoType *T = TL.getTypePtr(); |
| 6847 |
QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 6848 |
if (ResultType.isNull()) |
| 6849 |
return QualType(); |
| 6850 |
|
| 6851 |
QualType Result = TL.getType(); |
| 6852 |
if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
| 6853 |
Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 6854 |
|
| 6855 |
FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 6856 |
NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 6857 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6858 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6859 |
NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| 6860 |
|
| 6861 |
return Result; |
| 6862 |
} |
| 6863 |
|
| 6864 |
template <typename Derived> |
| 6865 |
QualType TreeTransform<Derived>::TransformUnresolvedUsingType( |
| 6866 |
TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) { |
| 6867 |
|
| 6868 |
const UnresolvedUsingType *T = TL.getTypePtr(); |
| 6869 |
bool Changed = false; |
| 6870 |
|
| 6871 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 6872 |
if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) { |
| 6873 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 6874 |
if (!QualifierLoc) |
| 6875 |
return QualType(); |
| 6876 |
Changed |= QualifierLoc != OldQualifierLoc; |
| 6877 |
} |
| 6878 |
|
| 6879 |
auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
| 6880 |
if (!D) |
| 6881 |
return QualType(); |
| 6882 |
Changed |= D != T->getDecl(); |
| 6883 |
|
| 6884 |
QualType Result = TL.getType(); |
| 6885 |
if (getDerived().AlwaysRebuild() || Changed) { |
| 6886 |
Result = getDerived().RebuildUnresolvedUsingType( |
| 6887 |
T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(), |
| 6888 |
D); |
| 6889 |
if (Result.isNull()) |
| 6890 |
return QualType(); |
| 6891 |
} |
| 6892 |
|
| 6893 |
if (isa<UsingType>(Result)) |
| 6894 |
TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), |
| 6895 |
QualifierLoc, TL.getNameLoc()); |
| 6896 |
else |
| 6897 |
TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), |
| 6898 |
QualifierLoc, TL.getNameLoc()); |
| 6899 |
return Result; |
| 6900 |
} |
| 6901 |
|
| 6902 |
template <typename Derived> |
| 6903 |
QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB, |
| 6904 |
UsingTypeLoc TL) { |
| 6905 |
const UsingType *T = TL.getTypePtr(); |
| 6906 |
bool Changed = false; |
| 6907 |
|
| 6908 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 6909 |
if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) { |
| 6910 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 6911 |
if (!QualifierLoc) |
| 6912 |
return QualType(); |
| 6913 |
Changed |= QualifierLoc != OldQualifierLoc; |
| 6914 |
} |
| 6915 |
|
| 6916 |
auto *D = cast_or_null<UsingShadowDecl>( |
| 6917 |
getDerived().TransformDecl(TL.getNameLoc(), T->getDecl())); |
| 6918 |
if (!D) |
| 6919 |
return QualType(); |
| 6920 |
Changed |= D != T->getDecl(); |
| 6921 |
|
| 6922 |
QualType UnderlyingType = getDerived().TransformType(T->desugar()); |
| 6923 |
if (UnderlyingType.isNull()) |
| 6924 |
return QualType(); |
| 6925 |
Changed |= UnderlyingType != T->desugar(); |
| 6926 |
|
| 6927 |
QualType Result = TL.getType(); |
| 6928 |
if (getDerived().AlwaysRebuild() || Changed) { |
| 6929 |
Result = getDerived().RebuildUsingType( |
| 6930 |
T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D, |
| 6931 |
UnderlyingType); |
| 6932 |
if (Result.isNull()) |
| 6933 |
return QualType(); |
| 6934 |
} |
| 6935 |
TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc, |
| 6936 |
TL.getNameLoc()); |
| 6937 |
return Result; |
| 6938 |
} |
| 6939 |
|
| 6940 |
template<typename Derived> |
| 6941 |
QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 6942 |
TypedefTypeLoc TL) { |
| 6943 |
const TypedefType *T = TL.getTypePtr(); |
| 6944 |
bool Changed = false; |
| 6945 |
|
| 6946 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 6947 |
if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) { |
| 6948 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 6949 |
if (!QualifierLoc) |
| 6950 |
return QualType(); |
| 6951 |
Changed |= QualifierLoc != OldQualifierLoc; |
| 6952 |
} |
| 6953 |
|
| 6954 |
auto *Typedef = cast_or_null<TypedefNameDecl>( |
| 6955 |
getDerived().TransformDecl(TL.getNameLoc(), T->getDecl())); |
| 6956 |
if (!Typedef) |
| 6957 |
return QualType(); |
| 6958 |
Changed |= Typedef != T->getDecl(); |
| 6959 |
|
| 6960 |
// FIXME: Transform the UnderlyingType if different from decl. |
| 6961 |
|
| 6962 |
QualType Result = TL.getType(); |
| 6963 |
if (getDerived().AlwaysRebuild() || Changed) { |
| 6964 |
Result = getDerived().RebuildTypedefType( |
| 6965 |
T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef); |
| 6966 |
if (Result.isNull()) |
| 6967 |
return QualType(); |
| 6968 |
} |
| 6969 |
|
| 6970 |
TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), |
| 6971 |
QualifierLoc, TL.getNameLoc()); |
| 6972 |
return Result; |
| 6973 |
} |
| 6974 |
|
| 6975 |
template<typename Derived> |
| 6976 |
QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 6977 |
TypeOfExprTypeLoc TL) { |
| 6978 |
// typeof expressions are not potentially evaluated contexts |
| 6979 |
EnterExpressionEvaluationContext Unevaluated( |
| 6980 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 6981 |
Sema::ReuseLambdaContextDecl); |
| 6982 |
|
| 6983 |
ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
| 6984 |
if (E.isInvalid()) |
| 6985 |
return QualType(); |
| 6986 |
|
| 6987 |
E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 6988 |
if (E.isInvalid()) |
| 6989 |
return QualType(); |
| 6990 |
|
| 6991 |
QualType Result = TL.getType(); |
| 6992 |
TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind(); |
| 6993 |
if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) { |
| 6994 |
Result = |
| 6995 |
getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind); |
| 6996 |
if (Result.isNull()) |
| 6997 |
return QualType(); |
| 6998 |
} |
| 6999 |
|
| 7000 |
TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 7001 |
NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 7002 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 7003 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7004 |
|
| 7005 |
return Result; |
| 7006 |
} |
| 7007 |
|
| 7008 |
template<typename Derived> |
| 7009 |
QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 7010 |
TypeOfTypeLoc TL) { |
| 7011 |
TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo(); |
| 7012 |
TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 7013 |
if (!New_Under_TI) |
| 7014 |
return QualType(); |
| 7015 |
|
| 7016 |
QualType Result = TL.getType(); |
| 7017 |
TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind(); |
| 7018 |
if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 7019 |
Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind); |
| 7020 |
if (Result.isNull()) |
| 7021 |
return QualType(); |
| 7022 |
} |
| 7023 |
|
| 7024 |
TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 7025 |
NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 7026 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 7027 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7028 |
NewTL.setUnmodifiedTInfo(New_Under_TI); |
| 7029 |
|
| 7030 |
return Result; |
| 7031 |
} |
| 7032 |
|
| 7033 |
template<typename Derived> |
| 7034 |
QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 7035 |
DecltypeTypeLoc TL) { |
| 7036 |
const DecltypeType *T = TL.getTypePtr(); |
| 7037 |
|
| 7038 |
// decltype expressions are not potentially evaluated contexts |
| 7039 |
EnterExpressionEvaluationContext Unevaluated( |
| 7040 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| 7041 |
Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| 7042 |
|
| 7043 |
ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 7044 |
if (E.isInvalid()) |
| 7045 |
return QualType(); |
| 7046 |
|
| 7047 |
E = getSema().ActOnDecltypeExpression(E.get()); |
| 7048 |
if (E.isInvalid()) |
| 7049 |
return QualType(); |
| 7050 |
|
| 7051 |
QualType Result = TL.getType(); |
| 7052 |
if (getDerived().AlwaysRebuild() || |
| 7053 |
E.get() != T->getUnderlyingExpr()) { |
| 7054 |
Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc()); |
| 7055 |
if (Result.isNull()) |
| 7056 |
return QualType(); |
| 7057 |
} |
| 7058 |
else E.get(); |
| 7059 |
|
| 7060 |
DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 7061 |
NewTL.setDecltypeLoc(TL.getDecltypeLoc()); |
| 7062 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7063 |
return Result; |
| 7064 |
} |
| 7065 |
|
| 7066 |
template <typename Derived> |
| 7067 |
QualType |
| 7068 |
TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB, |
| 7069 |
PackIndexingTypeLoc TL) { |
| 7070 |
// Transform the index |
| 7071 |
ExprResult IndexExpr; |
| 7072 |
{ |
| 7073 |
EnterExpressionEvaluationContext ConstantContext( |
| 7074 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 7075 |
|
| 7076 |
IndexExpr = getDerived().TransformExpr(TL.getIndexExpr()); |
| 7077 |
if (IndexExpr.isInvalid()) |
| 7078 |
return QualType(); |
| 7079 |
} |
| 7080 |
QualType Pattern = TL.getPattern(); |
| 7081 |
|
| 7082 |
const PackIndexingType *PIT = TL.getTypePtr(); |
| 7083 |
SmallVector<QualType, 5> SubtitutedTypes; |
| 7084 |
llvm::ArrayRef<QualType> Types = PIT->getExpansions(); |
| 7085 |
|
| 7086 |
bool NotYetExpanded = Types.empty(); |
| 7087 |
bool FullySubstituted = true; |
| 7088 |
|
| 7089 |
if (Types.empty() && !PIT->expandsToEmptyPack()) |
| 7090 |
Types = llvm::ArrayRef<QualType>(&Pattern, 1); |
| 7091 |
|
| 7092 |
for (QualType T : Types) { |
| 7093 |
if (!T->containsUnexpandedParameterPack()) { |
| 7094 |
QualType Transformed = getDerived().TransformType(T); |
| 7095 |
if (Transformed.isNull()) |
| 7096 |
return QualType(); |
| 7097 |
SubtitutedTypes.push_back(Transformed); |
| 7098 |
continue; |
| 7099 |
} |
| 7100 |
|
| 7101 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7102 |
getSema().collectUnexpandedParameterPacks(T, Unexpanded); |
| 7103 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 7104 |
// Determine whether the set of unexpanded parameter packs can and should |
| 7105 |
// be expanded. |
| 7106 |
bool ShouldExpand = true; |
| 7107 |
bool RetainExpansion = false; |
| 7108 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 7109 |
if (getDerived().TryExpandParameterPacks( |
| 7110 |
TL.getEllipsisLoc(), SourceRange(), Unexpanded, |
| 7111 |
/*FailOnPackProducingTemplates=*/true, ShouldExpand, |
| 7112 |
RetainExpansion, NumExpansions)) |
| 7113 |
return QualType(); |
| 7114 |
if (!ShouldExpand) { |
| 7115 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 7116 |
// FIXME: should we keep TypeLoc for individual expansions in |
| 7117 |
// PackIndexingTypeLoc? |
| 7118 |
TypeSourceInfo *TI = |
| 7119 |
SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc()); |
| 7120 |
QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc()); |
| 7121 |
if (Pack.isNull()) |
| 7122 |
return QualType(); |
| 7123 |
if (NotYetExpanded) { |
| 7124 |
FullySubstituted = false; |
| 7125 |
QualType Out = getDerived().RebuildPackIndexingType( |
| 7126 |
Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(), |
| 7127 |
FullySubstituted); |
| 7128 |
if (Out.isNull()) |
| 7129 |
return QualType(); |
| 7130 |
|
| 7131 |
PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out); |
| 7132 |
Loc.setEllipsisLoc(TL.getEllipsisLoc()); |
| 7133 |
return Out; |
| 7134 |
} |
| 7135 |
SubtitutedTypes.push_back(Pack); |
| 7136 |
continue; |
| 7137 |
} |
| 7138 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 7139 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 7140 |
QualType Out = getDerived().TransformType(T); |
| 7141 |
if (Out.isNull()) |
| 7142 |
return QualType(); |
| 7143 |
SubtitutedTypes.push_back(Out); |
| 7144 |
FullySubstituted &= !Out->containsUnexpandedParameterPack(); |
| 7145 |
} |
| 7146 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 7147 |
// forgetting the partially-substituted parameter pack. |
| 7148 |
if (RetainExpansion) { |
| 7149 |
FullySubstituted = false; |
| 7150 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 7151 |
QualType Out = getDerived().TransformType(T); |
| 7152 |
if (Out.isNull()) |
| 7153 |
return QualType(); |
| 7154 |
SubtitutedTypes.push_back(Out); |
| 7155 |
} |
| 7156 |
} |
| 7157 |
|
| 7158 |
// A pack indexing type can appear in a larger pack expansion, |
| 7159 |
// e.g. `Pack...[pack_of_indexes]...` |
| 7160 |
// so we need to temporarily disable substitution of pack elements |
| 7161 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 7162 |
QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 7163 |
|
| 7164 |
QualType Out = getDerived().RebuildPackIndexingType( |
| 7165 |
Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(), |
| 7166 |
FullySubstituted, SubtitutedTypes); |
| 7167 |
if (Out.isNull()) |
| 7168 |
return Out; |
| 7169 |
|
| 7170 |
PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out); |
| 7171 |
Loc.setEllipsisLoc(TL.getEllipsisLoc()); |
| 7172 |
return Out; |
| 7173 |
} |
| 7174 |
|
| 7175 |
template<typename Derived> |
| 7176 |
QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 7177 |
TypeLocBuilder &TLB, |
| 7178 |
UnaryTransformTypeLoc TL) { |
| 7179 |
QualType Result = TL.getType(); |
| 7180 |
TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo(); |
| 7181 |
if (Result->isDependentType()) { |
| 7182 |
const UnaryTransformType *T = TL.getTypePtr(); |
| 7183 |
|
| 7184 |
NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo()); |
| 7185 |
if (!NewBaseTSI) |
| 7186 |
return QualType(); |
| 7187 |
QualType NewBase = NewBaseTSI->getType(); |
| 7188 |
|
| 7189 |
Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 7190 |
T->getUTTKind(), |
| 7191 |
TL.getKWLoc()); |
| 7192 |
if (Result.isNull()) |
| 7193 |
return QualType(); |
| 7194 |
} |
| 7195 |
|
| 7196 |
UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 7197 |
NewTL.setKWLoc(TL.getKWLoc()); |
| 7198 |
NewTL.setParensRange(TL.getParensRange()); |
| 7199 |
NewTL.setUnderlyingTInfo(NewBaseTSI); |
| 7200 |
return Result; |
| 7201 |
} |
| 7202 |
|
| 7203 |
template<typename Derived> |
| 7204 |
QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( |
| 7205 |
TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { |
| 7206 |
const DeducedTemplateSpecializationType *T = TL.getTypePtr(); |
| 7207 |
|
| 7208 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 7209 |
TemplateName TemplateName = getDerived().TransformTemplateName( |
| 7210 |
QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(), |
| 7211 |
TL.getTemplateNameLoc()); |
| 7212 |
if (TemplateName.isNull()) |
| 7213 |
return QualType(); |
| 7214 |
|
| 7215 |
QualType OldDeduced = T->getDeducedType(); |
| 7216 |
QualType NewDeduced; |
| 7217 |
if (!OldDeduced.isNull()) { |
| 7218 |
NewDeduced = getDerived().TransformType(OldDeduced); |
| 7219 |
if (NewDeduced.isNull()) |
| 7220 |
return QualType(); |
| 7221 |
} |
| 7222 |
|
| 7223 |
QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( |
| 7224 |
T->getKeyword(), TemplateName, NewDeduced); |
| 7225 |
if (Result.isNull()) |
| 7226 |
return QualType(); |
| 7227 |
|
| 7228 |
auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 7229 |
NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 7230 |
NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 7231 |
NewTL.setQualifierLoc(QualifierLoc); |
| 7232 |
return Result; |
| 7233 |
} |
| 7234 |
|
| 7235 |
template <typename Derived> |
| 7236 |
QualType TreeTransform<Derived>::TransformTagType(TypeLocBuilder &TLB, |
| 7237 |
TagTypeLoc TL) { |
| 7238 |
const TagType *T = TL.getTypePtr(); |
| 7239 |
|
| 7240 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 7241 |
if (QualifierLoc) { |
| 7242 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 7243 |
if (!QualifierLoc) |
| 7244 |
return QualType(); |
| 7245 |
} |
| 7246 |
|
| 7247 |
auto *TD = cast_or_null<TagDecl>( |
| 7248 |
getDerived().TransformDecl(TL.getNameLoc(), T->getDecl())); |
| 7249 |
if (!TD) |
| 7250 |
return QualType(); |
| 7251 |
|
| 7252 |
QualType Result = TL.getType(); |
| 7253 |
if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() || |
| 7254 |
TD != T->getDecl()) { |
| 7255 |
if (T->isCanonicalUnqualified()) |
| 7256 |
Result = getDerived().RebuildCanonicalTagType(TD); |
| 7257 |
else |
| 7258 |
Result = getDerived().RebuildTagType( |
| 7259 |
T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD); |
| 7260 |
if (Result.isNull()) |
| 7261 |
return QualType(); |
| 7262 |
} |
| 7263 |
|
| 7264 |
TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result); |
| 7265 |
NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 7266 |
NewTL.setQualifierLoc(QualifierLoc); |
| 7267 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7268 |
|
| 7269 |
return Result; |
| 7270 |
} |
| 7271 |
|
| 7272 |
template <typename Derived> |
| 7273 |
QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, |
| 7274 |
EnumTypeLoc TL) { |
| 7275 |
return getDerived().TransformTagType(TLB, TL); |
| 7276 |
} |
| 7277 |
|
| 7278 |
template <typename Derived> |
| 7279 |
QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 7280 |
RecordTypeLoc TL) { |
| 7281 |
return getDerived().TransformTagType(TLB, TL); |
| 7282 |
} |
| 7283 |
|
| 7284 |
template<typename Derived> |
| 7285 |
QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 7286 |
TypeLocBuilder &TLB, |
| 7287 |
InjectedClassNameTypeLoc TL) { |
| 7288 |
return getDerived().TransformTagType(TLB, TL); |
| 7289 |
} |
| 7290 |
|
| 7291 |
template<typename Derived> |
| 7292 |
QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| 7293 |
TypeLocBuilder &TLB, |
| 7294 |
TemplateTypeParmTypeLoc TL) { |
| 7295 |
return getDerived().TransformTemplateTypeParmType( |
| 7296 |
TLB, TL, |
| 7297 |
/*SuppressObjCLifetime=*/false); |
| 7298 |
} |
| 7299 |
|
| 7300 |
template <typename Derived> |
| 7301 |
QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| 7302 |
TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) { |
| 7303 |
return TransformTypeSpecType(TLB, TL); |
| 7304 |
} |
| 7305 |
|
| 7306 |
template<typename Derived> |
| 7307 |
QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
| 7308 |
TypeLocBuilder &TLB, |
| 7309 |
SubstTemplateTypeParmTypeLoc TL) { |
| 7310 |
const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 7311 |
|
| 7312 |
Decl *NewReplaced = |
| 7313 |
getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl()); |
| 7314 |
|
| 7315 |
// Substitute into the replacement type, which itself might involve something |
| 7316 |
// that needs to be transformed. This only tends to occur with default |
| 7317 |
// template arguments of template template parameters. |
| 7318 |
TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 7319 |
QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 7320 |
if (Replacement.isNull()) |
| 7321 |
return QualType(); |
| 7322 |
|
| 7323 |
QualType Result = SemaRef.Context.getSubstTemplateTypeParmType( |
| 7324 |
Replacement, NewReplaced, T->getIndex(), T->getPackIndex(), |
| 7325 |
T->getFinal()); |
| 7326 |
|
| 7327 |
// Propagate type-source information. |
| 7328 |
SubstTemplateTypeParmTypeLoc NewTL |
| 7329 |
= TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 7330 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7331 |
return Result; |
| 7332 |
|
| 7333 |
} |
| 7334 |
template <typename Derived> |
| 7335 |
QualType TreeTransform<Derived>::TransformSubstBuiltinTemplatePackType( |
| 7336 |
TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) { |
| 7337 |
return TransformTypeSpecType(TLB, TL); |
| 7338 |
} |
| 7339 |
|
| 7340 |
template<typename Derived> |
| 7341 |
QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 7342 |
TypeLocBuilder &TLB, |
| 7343 |
SubstTemplateTypeParmPackTypeLoc TL) { |
| 7344 |
return getDerived().TransformSubstTemplateTypeParmPackType( |
| 7345 |
TLB, TL, /*SuppressObjCLifetime=*/false); |
| 7346 |
} |
| 7347 |
|
| 7348 |
template <typename Derived> |
| 7349 |
QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 7350 |
TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool) { |
| 7351 |
return TransformTypeSpecType(TLB, TL); |
| 7352 |
} |
| 7353 |
|
| 7354 |
template<typename Derived> |
| 7355 |
QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 7356 |
AtomicTypeLoc TL) { |
| 7357 |
QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 7358 |
if (ValueType.isNull()) |
| 7359 |
return QualType(); |
| 7360 |
|
| 7361 |
QualType Result = TL.getType(); |
| 7362 |
if (getDerived().AlwaysRebuild() || |
| 7363 |
ValueType != TL.getValueLoc().getType()) { |
| 7364 |
Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 7365 |
if (Result.isNull()) |
| 7366 |
return QualType(); |
| 7367 |
} |
| 7368 |
|
| 7369 |
AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 7370 |
NewTL.setKWLoc(TL.getKWLoc()); |
| 7371 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 7372 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7373 |
|
| 7374 |
return Result; |
| 7375 |
} |
| 7376 |
|
| 7377 |
template <typename Derived> |
| 7378 |
QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 7379 |
PipeTypeLoc TL) { |
| 7380 |
QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 7381 |
if (ValueType.isNull()) |
| 7382 |
return QualType(); |
| 7383 |
|
| 7384 |
QualType Result = TL.getType(); |
| 7385 |
if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| 7386 |
const PipeType *PT = Result->castAs<PipeType>(); |
| 7387 |
bool isReadPipe = PT->isReadOnly(); |
| 7388 |
Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); |
| 7389 |
if (Result.isNull()) |
| 7390 |
return QualType(); |
| 7391 |
} |
| 7392 |
|
| 7393 |
PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 7394 |
NewTL.setKWLoc(TL.getKWLoc()); |
| 7395 |
|
| 7396 |
return Result; |
| 7397 |
} |
| 7398 |
|
| 7399 |
template <typename Derived> |
| 7400 |
QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB, |
| 7401 |
BitIntTypeLoc TL) { |
| 7402 |
const BitIntType *EIT = TL.getTypePtr(); |
| 7403 |
QualType Result = TL.getType(); |
| 7404 |
|
| 7405 |
if (getDerived().AlwaysRebuild()) { |
| 7406 |
Result = getDerived().RebuildBitIntType(EIT->isUnsigned(), |
| 7407 |
EIT->getNumBits(), TL.getNameLoc()); |
| 7408 |
if (Result.isNull()) |
| 7409 |
return QualType(); |
| 7410 |
} |
| 7411 |
|
| 7412 |
BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result); |
| 7413 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7414 |
return Result; |
| 7415 |
} |
| 7416 |
|
| 7417 |
template <typename Derived> |
| 7418 |
QualType TreeTransform<Derived>::TransformDependentBitIntType( |
| 7419 |
TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) { |
| 7420 |
const DependentBitIntType *EIT = TL.getTypePtr(); |
| 7421 |
|
| 7422 |
EnterExpressionEvaluationContext Unevaluated( |
| 7423 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 7424 |
ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr()); |
| 7425 |
BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr); |
| 7426 |
|
| 7427 |
if (BitsExpr.isInvalid()) |
| 7428 |
return QualType(); |
| 7429 |
|
| 7430 |
QualType Result = TL.getType(); |
| 7431 |
|
| 7432 |
if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) { |
| 7433 |
Result = getDerived().RebuildDependentBitIntType( |
| 7434 |
EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc()); |
| 7435 |
|
| 7436 |
if (Result.isNull()) |
| 7437 |
return QualType(); |
| 7438 |
} |
| 7439 |
|
| 7440 |
if (isa<DependentBitIntType>(Result)) { |
| 7441 |
DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result); |
| 7442 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7443 |
} else { |
| 7444 |
BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result); |
| 7445 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7446 |
} |
| 7447 |
return Result; |
| 7448 |
} |
| 7449 |
|
| 7450 |
template <typename Derived> |
| 7451 |
QualType TreeTransform<Derived>::TransformPredefinedSugarType( |
| 7452 |
TypeLocBuilder &TLB, PredefinedSugarTypeLoc TL) { |
| 7453 |
llvm_unreachable("This type does not need to be transformed."); |
| 7454 |
} |
| 7455 |
|
| 7456 |
/// Simple iterator that traverses the template arguments in a |
| 7457 |
/// container that provides a \c getArgLoc() member function. |
| 7458 |
/// |
| 7459 |
/// This iterator is intended to be used with the iterator form of |
| 7460 |
/// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 7461 |
template<typename ArgLocContainer> |
| 7462 |
class TemplateArgumentLocContainerIterator { |
| 7463 |
ArgLocContainer *Container; |
| 7464 |
unsigned Index; |
| 7465 |
|
| 7466 |
public: |
| 7467 |
typedef TemplateArgumentLoc value_type; |
| 7468 |
typedef TemplateArgumentLoc reference; |
| 7469 |
typedef int difference_type; |
| 7470 |
typedef std::input_iterator_tag iterator_category; |
| 7471 |
|
| 7472 |
class pointer { |
| 7473 |
TemplateArgumentLoc Arg; |
| 7474 |
|
| 7475 |
public: |
| 7476 |
explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 7477 |
|
| 7478 |
const TemplateArgumentLoc *operator->() const { |
| 7479 |
return &Arg; |
| 7480 |
} |
| 7481 |
}; |
| 7482 |
|
| 7483 |
|
| 7484 |
TemplateArgumentLocContainerIterator() {} |
| 7485 |
|
| 7486 |
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 7487 |
unsigned Index) |
| 7488 |
: Container(&Container), Index(Index) { } |
| 7489 |
|
| 7490 |
TemplateArgumentLocContainerIterator &operator++() { |
| 7491 |
++Index; |
| 7492 |
return *this; |
| 7493 |
} |
| 7494 |
|
| 7495 |
TemplateArgumentLocContainerIterator operator++(int) { |
| 7496 |
TemplateArgumentLocContainerIterator Old(*this); |
| 7497 |
++(*this); |
| 7498 |
return Old; |
| 7499 |
} |
| 7500 |
|
| 7501 |
TemplateArgumentLoc operator*() const { |
| 7502 |
return Container->getArgLoc(Index); |
| 7503 |
} |
| 7504 |
|
| 7505 |
pointer operator->() const { |
| 7506 |
return pointer(Container->getArgLoc(Index)); |
| 7507 |
} |
| 7508 |
|
| 7509 |
friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
| 7510 |
const TemplateArgumentLocContainerIterator &Y) { |
| 7511 |
return X.Container == Y.Container && X.Index == Y.Index; |
| 7512 |
} |
| 7513 |
|
| 7514 |
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
| 7515 |
const TemplateArgumentLocContainerIterator &Y) { |
| 7516 |
return !(X == Y); |
| 7517 |
} |
| 7518 |
}; |
| 7519 |
|
| 7520 |
template<typename Derived> |
| 7521 |
QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 7522 |
AutoTypeLoc TL) { |
| 7523 |
const AutoType *T = TL.getTypePtr(); |
| 7524 |
QualType OldDeduced = T->getDeducedType(); |
| 7525 |
QualType NewDeduced; |
| 7526 |
if (!OldDeduced.isNull()) { |
| 7527 |
NewDeduced = getDerived().TransformType(OldDeduced); |
| 7528 |
if (NewDeduced.isNull()) |
| 7529 |
return QualType(); |
| 7530 |
} |
| 7531 |
|
| 7532 |
ConceptDecl *NewCD = nullptr; |
| 7533 |
TemplateArgumentListInfo NewTemplateArgs; |
| 7534 |
NestedNameSpecifierLoc NewNestedNameSpec; |
| 7535 |
if (T->isConstrained()) { |
| 7536 |
assert(TL.getConceptReference()); |
| 7537 |
NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl( |
| 7538 |
TL.getConceptNameLoc(), T->getTypeConstraintConcept())); |
| 7539 |
|
| 7540 |
NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 7541 |
NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 7542 |
typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator; |
| 7543 |
if (getDerived().TransformTemplateArguments( |
| 7544 |
ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()), |
| 7545 |
NewTemplateArgs)) |
| 7546 |
return QualType(); |
| 7547 |
|
| 7548 |
if (TL.getNestedNameSpecifierLoc()) { |
| 7549 |
NewNestedNameSpec |
| 7550 |
= getDerived().TransformNestedNameSpecifierLoc( |
| 7551 |
TL.getNestedNameSpecifierLoc()); |
| 7552 |
if (!NewNestedNameSpec) |
| 7553 |
return QualType(); |
| 7554 |
} |
| 7555 |
} |
| 7556 |
|
| 7557 |
QualType Result = TL.getType(); |
| 7558 |
if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 7559 |
T->isDependentType() || T->isConstrained()) { |
| 7560 |
// FIXME: Maybe don't rebuild if all template arguments are the same. |
| 7561 |
llvm::SmallVector<TemplateArgument, 4> NewArgList; |
| 7562 |
NewArgList.reserve(NewTemplateArgs.size()); |
| 7563 |
for (const auto &ArgLoc : NewTemplateArgs.arguments()) |
| 7564 |
NewArgList.push_back(ArgLoc.getArgument()); |
| 7565 |
Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD, |
| 7566 |
NewArgList); |
| 7567 |
if (Result.isNull()) |
| 7568 |
return QualType(); |
| 7569 |
} |
| 7570 |
|
| 7571 |
AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 7572 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7573 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7574 |
NewTL.setConceptReference(nullptr); |
| 7575 |
|
| 7576 |
if (T->isConstrained()) { |
| 7577 |
DeclarationNameInfo DNI = DeclarationNameInfo( |
| 7578 |
TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(), |
| 7579 |
TL.getConceptNameLoc(), |
| 7580 |
TL.getTypePtr()->getTypeConstraintConcept()->getDeclName()); |
| 7581 |
auto *CR = ConceptReference::Create( |
| 7582 |
SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI, |
| 7583 |
TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(), |
| 7584 |
ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs)); |
| 7585 |
NewTL.setConceptReference(CR); |
| 7586 |
} |
| 7587 |
|
| 7588 |
return Result; |
| 7589 |
} |
| 7590 |
|
| 7591 |
template <typename Derived> |
| 7592 |
QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 7593 |
TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL) { |
| 7594 |
return getDerived().TransformTemplateSpecializationType( |
| 7595 |
TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr, |
| 7596 |
/*AllowInjectedClassName=*/false); |
| 7597 |
} |
| 7598 |
|
| 7599 |
template <typename Derived> |
| 7600 |
QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 7601 |
TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, QualType ObjectType, |
| 7602 |
NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) { |
| 7603 |
const TemplateSpecializationType *T = TL.getTypePtr(); |
| 7604 |
|
| 7605 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 7606 |
TemplateName Template = getDerived().TransformTemplateName( |
| 7607 |
QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(), |
| 7608 |
TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope, |
| 7609 |
AllowInjectedClassName); |
| 7610 |
if (Template.isNull()) |
| 7611 |
return QualType(); |
| 7612 |
|
| 7613 |
TemplateArgumentListInfo NewTemplateArgs; |
| 7614 |
NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 7615 |
NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 7616 |
typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 7617 |
ArgIterator; |
| 7618 |
if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 7619 |
ArgIterator(TL, TL.getNumArgs()), |
| 7620 |
NewTemplateArgs)) |
| 7621 |
return QualType(); |
| 7622 |
|
| 7623 |
// This needs to be rebuilt if either the arguments changed, or if the |
| 7624 |
// original template changed. If the template changed, and even if the |
| 7625 |
// arguments didn't change, these arguments might not correspond to their |
| 7626 |
// respective parameters, therefore needing conversions. |
| 7627 |
QualType Result = getDerived().RebuildTemplateSpecializationType( |
| 7628 |
TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(), |
| 7629 |
NewTemplateArgs); |
| 7630 |
|
| 7631 |
if (!Result.isNull()) { |
| 7632 |
TLB.push<TemplateSpecializationTypeLoc>(Result).set( |
| 7633 |
TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(), |
| 7634 |
TL.getTemplateNameLoc(), NewTemplateArgs); |
| 7635 |
} |
| 7636 |
|
| 7637 |
return Result; |
| 7638 |
} |
| 7639 |
|
| 7640 |
template <typename Derived> |
| 7641 |
QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB, |
| 7642 |
AttributedTypeLoc TL) { |
| 7643 |
const AttributedType *oldType = TL.getTypePtr(); |
| 7644 |
QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 7645 |
if (modifiedType.isNull()) |
| 7646 |
return QualType(); |
| 7647 |
|
| 7648 |
// oldAttr can be null if we started with a QualType rather than a TypeLoc. |
| 7649 |
const Attr *oldAttr = TL.getAttr(); |
| 7650 |
const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; |
| 7651 |
if (oldAttr && !newAttr) |
| 7652 |
return QualType(); |
| 7653 |
|
| 7654 |
QualType result = TL.getType(); |
| 7655 |
|
| 7656 |
// FIXME: dependent operand expressions? |
| 7657 |
if (getDerived().AlwaysRebuild() || |
| 7658 |
modifiedType != oldType->getModifiedType()) { |
| 7659 |
// If the equivalent type is equal to the modified type, we don't want to |
| 7660 |
// transform it as well because: |
| 7661 |
// |
| 7662 |
// 1. The transformation would yield the same result and is therefore |
| 7663 |
// superfluous, and |
| 7664 |
// |
| 7665 |
// 2. Transforming the same type twice can cause problems, e.g. if it |
| 7666 |
// is a FunctionProtoType, we may end up instantiating the function |
| 7667 |
// parameters twice, which causes an assertion since the parameters |
| 7668 |
// are already bound to their counterparts in the template for this |
| 7669 |
// instantiation. |
| 7670 |
// |
| 7671 |
QualType equivalentType = modifiedType; |
| 7672 |
if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) { |
| 7673 |
TypeLocBuilder AuxiliaryTLB; |
| 7674 |
AuxiliaryTLB.reserve(TL.getFullDataSize()); |
| 7675 |
equivalentType = |
| 7676 |
getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc()); |
| 7677 |
if (equivalentType.isNull()) |
| 7678 |
return QualType(); |
| 7679 |
} |
| 7680 |
|
| 7681 |
// Check whether we can add nullability; it is only represented as |
| 7682 |
// type sugar, and therefore cannot be diagnosed in any other way. |
| 7683 |
if (auto nullability = oldType->getImmediateNullability()) { |
| 7684 |
if (!modifiedType->canHaveNullability()) { |
| 7685 |
SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation() |
| 7686 |
: TL.getModifiedLoc().getBeginLoc()), |
| 7687 |
diag::err_nullability_nonpointer) |
| 7688 |
<< DiagNullabilityKind(*nullability, false) << modifiedType; |
| 7689 |
return QualType(); |
| 7690 |
} |
| 7691 |
} |
| 7692 |
|
| 7693 |
result = SemaRef.Context.getAttributedType(TL.getAttrKind(), |
| 7694 |
modifiedType, |
| 7695 |
equivalentType, |
| 7696 |
TL.getAttr()); |
| 7697 |
} |
| 7698 |
|
| 7699 |
AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 7700 |
newTL.setAttr(newAttr); |
| 7701 |
return result; |
| 7702 |
} |
| 7703 |
|
| 7704 |
template <typename Derived> |
| 7705 |
QualType TreeTransform<Derived>::TransformCountAttributedType( |
| 7706 |
TypeLocBuilder &TLB, CountAttributedTypeLoc TL) { |
| 7707 |
const CountAttributedType *OldTy = TL.getTypePtr(); |
| 7708 |
QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 7709 |
if (InnerTy.isNull()) |
| 7710 |
return QualType(); |
| 7711 |
|
| 7712 |
Expr *OldCount = TL.getCountExpr(); |
| 7713 |
Expr *NewCount = nullptr; |
| 7714 |
if (OldCount) { |
| 7715 |
ExprResult CountResult = getDerived().TransformExpr(OldCount); |
| 7716 |
if (CountResult.isInvalid()) |
| 7717 |
return QualType(); |
| 7718 |
NewCount = CountResult.get(); |
| 7719 |
} |
| 7720 |
|
| 7721 |
QualType Result = TL.getType(); |
| 7722 |
if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() || |
| 7723 |
OldCount != NewCount) { |
| 7724 |
// Currently, CountAttributedType can only wrap incomplete array types. |
| 7725 |
Result = SemaRef.BuildCountAttributedArrayOrPointerType( |
| 7726 |
InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull()); |
| 7727 |
} |
| 7728 |
|
| 7729 |
TLB.push<CountAttributedTypeLoc>(Result); |
| 7730 |
return Result; |
| 7731 |
} |
| 7732 |
|
| 7733 |
template <typename Derived> |
| 7734 |
QualType TreeTransform<Derived>::TransformBTFTagAttributedType( |
| 7735 |
TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) { |
| 7736 |
// The BTFTagAttributedType is available for C only. |
| 7737 |
llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType"); |
| 7738 |
} |
| 7739 |
|
| 7740 |
template <typename Derived> |
| 7741 |
QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType( |
| 7742 |
TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) { |
| 7743 |
|
| 7744 |
const HLSLAttributedResourceType *oldType = TL.getTypePtr(); |
| 7745 |
|
| 7746 |
QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc()); |
| 7747 |
if (WrappedTy.isNull()) |
| 7748 |
return QualType(); |
| 7749 |
|
| 7750 |
QualType ContainedTy = QualType(); |
| 7751 |
QualType OldContainedTy = oldType->getContainedType(); |
| 7752 |
if (!OldContainedTy.isNull()) { |
| 7753 |
TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo(); |
| 7754 |
if (!oldContainedTSI) |
| 7755 |
oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo( |
| 7756 |
OldContainedTy, SourceLocation()); |
| 7757 |
TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI); |
| 7758 |
if (!ContainedTSI) |
| 7759 |
return QualType(); |
| 7760 |
ContainedTy = ContainedTSI->getType(); |
| 7761 |
} |
| 7762 |
|
| 7763 |
QualType Result = TL.getType(); |
| 7764 |
if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() || |
| 7765 |
ContainedTy != oldType->getContainedType()) { |
| 7766 |
Result = SemaRef.Context.getHLSLAttributedResourceType( |
| 7767 |
WrappedTy, ContainedTy, oldType->getAttrs()); |
| 7768 |
} |
| 7769 |
|
| 7770 |
TLB.push<HLSLAttributedResourceTypeLoc>(Result); |
| 7771 |
return Result; |
| 7772 |
} |
| 7773 |
|
| 7774 |
template <typename Derived> |
| 7775 |
QualType TreeTransform<Derived>::TransformHLSLInlineSpirvType( |
| 7776 |
TypeLocBuilder &TLB, HLSLInlineSpirvTypeLoc TL) { |
| 7777 |
// No transformations needed. |
| 7778 |
return TL.getType(); |
| 7779 |
} |
| 7780 |
|
| 7781 |
template<typename Derived> |
| 7782 |
QualType |
| 7783 |
TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 7784 |
ParenTypeLoc TL) { |
| 7785 |
QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 7786 |
if (Inner.isNull()) |
| 7787 |
return QualType(); |
| 7788 |
|
| 7789 |
QualType Result = TL.getType(); |
| 7790 |
if (getDerived().AlwaysRebuild() || |
| 7791 |
Inner != TL.getInnerLoc().getType()) { |
| 7792 |
Result = getDerived().RebuildParenType(Inner); |
| 7793 |
if (Result.isNull()) |
| 7794 |
return QualType(); |
| 7795 |
} |
| 7796 |
|
| 7797 |
ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 7798 |
NewTL.setLParenLoc(TL.getLParenLoc()); |
| 7799 |
NewTL.setRParenLoc(TL.getRParenLoc()); |
| 7800 |
return Result; |
| 7801 |
} |
| 7802 |
|
| 7803 |
template <typename Derived> |
| 7804 |
QualType |
| 7805 |
TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, |
| 7806 |
MacroQualifiedTypeLoc TL) { |
| 7807 |
QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 7808 |
if (Inner.isNull()) |
| 7809 |
return QualType(); |
| 7810 |
|
| 7811 |
QualType Result = TL.getType(); |
| 7812 |
if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { |
| 7813 |
Result = |
| 7814 |
getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); |
| 7815 |
if (Result.isNull()) |
| 7816 |
return QualType(); |
| 7817 |
} |
| 7818 |
|
| 7819 |
MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); |
| 7820 |
NewTL.setExpansionLoc(TL.getExpansionLoc()); |
| 7821 |
return Result; |
| 7822 |
} |
| 7823 |
|
| 7824 |
template<typename Derived> |
| 7825 |
QualType TreeTransform<Derived>::TransformDependentNameType( |
| 7826 |
TypeLocBuilder &TLB, DependentNameTypeLoc TL) { |
| 7827 |
return TransformDependentNameType(TLB, TL, false); |
| 7828 |
} |
| 7829 |
|
| 7830 |
template <typename Derived> |
| 7831 |
QualType TreeTransform<Derived>::TransformDependentNameType( |
| 7832 |
TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext, |
| 7833 |
QualType ObjectType, NamedDecl *UnqualLookup) { |
| 7834 |
const DependentNameType *T = TL.getTypePtr(); |
| 7835 |
|
| 7836 |
NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc(); |
| 7837 |
if (QualifierLoc) { |
| 7838 |
QualifierLoc = getDerived().TransformNestedNameSpecifierLoc( |
| 7839 |
QualifierLoc, ObjectType, UnqualLookup); |
| 7840 |
if (!QualifierLoc) |
| 7841 |
return QualType(); |
| 7842 |
} else { |
| 7843 |
assert((ObjectType.isNull() && !UnqualLookup) && |
| 7844 |
"must be transformed by TransformNestedNameSpecifierLoc"); |
| 7845 |
} |
| 7846 |
|
| 7847 |
QualType Result |
| 7848 |
= getDerived().RebuildDependentNameType(T->getKeyword(), |
| 7849 |
TL.getElaboratedKeywordLoc(), |
| 7850 |
QualifierLoc, |
| 7851 |
T->getIdentifier(), |
| 7852 |
TL.getNameLoc(), |
| 7853 |
DeducedTSTContext); |
| 7854 |
if (Result.isNull()) |
| 7855 |
return QualType(); |
| 7856 |
|
| 7857 |
if (isa<TagType>(Result)) { |
| 7858 |
auto NewTL = TLB.push<TagTypeLoc>(Result); |
| 7859 |
NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 7860 |
NewTL.setQualifierLoc(QualifierLoc); |
| 7861 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7862 |
} else if (isa<DeducedTemplateSpecializationType>(Result)) { |
| 7863 |
auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 7864 |
NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 7865 |
NewTL.setTemplateNameLoc(TL.getNameLoc()); |
| 7866 |
NewTL.setQualifierLoc(QualifierLoc); |
| 7867 |
} else if (isa<TypedefType>(Result)) { |
| 7868 |
TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), |
| 7869 |
QualifierLoc, TL.getNameLoc()); |
| 7870 |
} else if (isa<UnresolvedUsingType>(Result)) { |
| 7871 |
auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result); |
| 7872 |
NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc()); |
| 7873 |
} else { |
| 7874 |
auto NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 7875 |
NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 7876 |
NewTL.setQualifierLoc(QualifierLoc); |
| 7877 |
NewTL.setNameLoc(TL.getNameLoc()); |
| 7878 |
} |
| 7879 |
return Result; |
| 7880 |
} |
| 7881 |
|
| 7882 |
template<typename Derived> |
| 7883 |
QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 7884 |
PackExpansionTypeLoc TL) { |
| 7885 |
QualType Pattern |
| 7886 |
= getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 7887 |
if (Pattern.isNull()) |
| 7888 |
return QualType(); |
| 7889 |
|
| 7890 |
QualType Result = TL.getType(); |
| 7891 |
if (getDerived().AlwaysRebuild() || |
| 7892 |
Pattern != TL.getPatternLoc().getType()) { |
| 7893 |
Result = getDerived().RebuildPackExpansionType(Pattern, |
| 7894 |
TL.getPatternLoc().getSourceRange(), |
| 7895 |
TL.getEllipsisLoc(), |
| 7896 |
TL.getTypePtr()->getNumExpansions()); |
| 7897 |
if (Result.isNull()) |
| 7898 |
return QualType(); |
| 7899 |
} |
| 7900 |
|
| 7901 |
PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 7902 |
NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 7903 |
return Result; |
| 7904 |
} |
| 7905 |
|
| 7906 |
template<typename Derived> |
| 7907 |
QualType |
| 7908 |
TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 7909 |
ObjCInterfaceTypeLoc TL) { |
| 7910 |
// ObjCInterfaceType is never dependent. |
| 7911 |
TLB.pushFullCopy(TL); |
| 7912 |
return TL.getType(); |
| 7913 |
} |
| 7914 |
|
| 7915 |
template<typename Derived> |
| 7916 |
QualType |
| 7917 |
TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, |
| 7918 |
ObjCTypeParamTypeLoc TL) { |
| 7919 |
const ObjCTypeParamType *T = TL.getTypePtr(); |
| 7920 |
ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( |
| 7921 |
getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); |
| 7922 |
if (!OTP) |
| 7923 |
return QualType(); |
| 7924 |
|
| 7925 |
QualType Result = TL.getType(); |
| 7926 |
if (getDerived().AlwaysRebuild() || |
| 7927 |
OTP != T->getDecl()) { |
| 7928 |
Result = getDerived().RebuildObjCTypeParamType( |
| 7929 |
OTP, TL.getProtocolLAngleLoc(), |
| 7930 |
llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 7931 |
TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| 7932 |
if (Result.isNull()) |
| 7933 |
return QualType(); |
| 7934 |
} |
| 7935 |
|
| 7936 |
ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); |
| 7937 |
if (TL.getNumProtocols()) { |
| 7938 |
NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 7939 |
for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 7940 |
NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 7941 |
NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 7942 |
} |
| 7943 |
return Result; |
| 7944 |
} |
| 7945 |
|
| 7946 |
template<typename Derived> |
| 7947 |
QualType |
| 7948 |
TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 7949 |
ObjCObjectTypeLoc TL) { |
| 7950 |
// Transform base type. |
| 7951 |
QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 7952 |
if (BaseType.isNull()) |
| 7953 |
return QualType(); |
| 7954 |
|
| 7955 |
bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 7956 |
|
| 7957 |
// Transform type arguments. |
| 7958 |
SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 7959 |
for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 7960 |
TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 7961 |
TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 7962 |
QualType TypeArg = TypeArgInfo->getType(); |
| 7963 |
if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 7964 |
AnyChanged = true; |
| 7965 |
|
| 7966 |
// We have a pack expansion. Instantiate it. |
| 7967 |
const auto *PackExpansion = PackExpansionLoc.getType() |
| 7968 |
->castAs<PackExpansionType>(); |
| 7969 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 7970 |
SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 7971 |
Unexpanded); |
| 7972 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 7973 |
|
| 7974 |
// Determine whether the set of unexpanded parameter packs can |
| 7975 |
// and should be expanded. |
| 7976 |
TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 7977 |
bool Expand = false; |
| 7978 |
bool RetainExpansion = false; |
| 7979 |
UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions(); |
| 7980 |
if (getDerived().TryExpandParameterPacks( |
| 7981 |
PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 7982 |
Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand, |
| 7983 |
RetainExpansion, NumExpansions)) |
| 7984 |
return QualType(); |
| 7985 |
|
| 7986 |
if (!Expand) { |
| 7987 |
// We can't expand this pack expansion into separate arguments yet; |
| 7988 |
// just substitute into the pattern and create a new pack expansion |
| 7989 |
// type. |
| 7990 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 7991 |
|
| 7992 |
TypeLocBuilder TypeArgBuilder; |
| 7993 |
TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 7994 |
QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| 7995 |
PatternLoc); |
| 7996 |
if (NewPatternType.isNull()) |
| 7997 |
return QualType(); |
| 7998 |
|
| 7999 |
QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 8000 |
NewPatternType, NumExpansions); |
| 8001 |
auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 8002 |
NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 8003 |
NewTypeArgInfos.push_back( |
| 8004 |
TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 8005 |
continue; |
| 8006 |
} |
| 8007 |
|
| 8008 |
// Substitute into the pack expansion pattern for each slice of the |
| 8009 |
// pack. |
| 8010 |
for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 8011 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx); |
| 8012 |
|
| 8013 |
TypeLocBuilder TypeArgBuilder; |
| 8014 |
TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 8015 |
|
| 8016 |
QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 8017 |
PatternLoc); |
| 8018 |
if (NewTypeArg.isNull()) |
| 8019 |
return QualType(); |
| 8020 |
|
| 8021 |
NewTypeArgInfos.push_back( |
| 8022 |
TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 8023 |
} |
| 8024 |
|
| 8025 |
continue; |
| 8026 |
} |
| 8027 |
|
| 8028 |
TypeLocBuilder TypeArgBuilder; |
| 8029 |
TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 8030 |
QualType NewTypeArg = |
| 8031 |
getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 8032 |
if (NewTypeArg.isNull()) |
| 8033 |
return QualType(); |
| 8034 |
|
| 8035 |
// If nothing changed, just keep the old TypeSourceInfo. |
| 8036 |
if (NewTypeArg == TypeArg) { |
| 8037 |
NewTypeArgInfos.push_back(TypeArgInfo); |
| 8038 |
continue; |
| 8039 |
} |
| 8040 |
|
| 8041 |
NewTypeArgInfos.push_back( |
| 8042 |
TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 8043 |
AnyChanged = true; |
| 8044 |
} |
| 8045 |
|
| 8046 |
QualType Result = TL.getType(); |
| 8047 |
if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 8048 |
// Rebuild the type. |
| 8049 |
Result = getDerived().RebuildObjCObjectType( |
| 8050 |
BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, |
| 8051 |
TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), |
| 8052 |
llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 8053 |
TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| 8054 |
|
| 8055 |
if (Result.isNull()) |
| 8056 |
return QualType(); |
| 8057 |
} |
| 8058 |
|
| 8059 |
ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| 8060 |
NewT.setHasBaseTypeAsWritten(true); |
| 8061 |
NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 8062 |
for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 8063 |
NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 8064 |
NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 8065 |
NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 8066 |
for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 8067 |
NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 8068 |
NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 8069 |
return Result; |
| 8070 |
} |
| 8071 |
|
| 8072 |
template<typename Derived> |
| 8073 |
QualType |
| 8074 |
TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 8075 |
ObjCObjectPointerTypeLoc TL) { |
| 8076 |
QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 8077 |
if (PointeeType.isNull()) |
| 8078 |
return QualType(); |
| 8079 |
|
| 8080 |
QualType Result = TL.getType(); |
| 8081 |
if (getDerived().AlwaysRebuild() || |
| 8082 |
PointeeType != TL.getPointeeLoc().getType()) { |
| 8083 |
Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 8084 |
TL.getStarLoc()); |
| 8085 |
if (Result.isNull()) |
| 8086 |
return QualType(); |
| 8087 |
} |
| 8088 |
|
| 8089 |
ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 8090 |
NewT.setStarLoc(TL.getStarLoc()); |
| 8091 |
return Result; |
| 8092 |
} |
| 8093 |
|
| 8094 |
//===----------------------------------------------------------------------===// |
| 8095 |
// Statement transformation |
| 8096 |
//===----------------------------------------------------------------------===// |
| 8097 |
template<typename Derived> |
| 8098 |
StmtResult |
| 8099 |
TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 8100 |
return S; |
| 8101 |
} |
| 8102 |
|
| 8103 |
template<typename Derived> |
| 8104 |
StmtResult |
| 8105 |
TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 8106 |
return getDerived().TransformCompoundStmt(S, false); |
| 8107 |
} |
| 8108 |
|
| 8109 |
template<typename Derived> |
| 8110 |
StmtResult |
| 8111 |
TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
| 8112 |
bool IsStmtExpr) { |
| 8113 |
Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 8114 |
Sema::FPFeaturesStateRAII FPSave(getSema()); |
| 8115 |
if (S->hasStoredFPFeatures()) |
| 8116 |
getSema().resetFPOptions( |
| 8117 |
S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts())); |
| 8118 |
|
| 8119 |
bool SubStmtInvalid = false; |
| 8120 |
bool SubStmtChanged = false; |
| 8121 |
SmallVector<Stmt*, 8> Statements; |
| 8122 |
for (auto *B : S->body()) { |
| 8123 |
StmtResult Result = getDerived().TransformStmt( |
| 8124 |
B, IsStmtExpr && B == S->body_back() ? StmtDiscardKind::StmtExprResult |
| 8125 |
: StmtDiscardKind::Discarded); |
| 8126 |
|
| 8127 |
if (Result.isInvalid()) { |
| 8128 |
// Immediately fail if this was a DeclStmt, since it's very |
| 8129 |
// likely that this will cause problems for future statements. |
| 8130 |
if (isa<DeclStmt>(B)) |
| 8131 |
return StmtError(); |
| 8132 |
|
| 8133 |
// Otherwise, just keep processing substatements and fail later. |
| 8134 |
SubStmtInvalid = true; |
| 8135 |
continue; |
| 8136 |
} |
| 8137 |
|
| 8138 |
SubStmtChanged = SubStmtChanged || Result.get() != B; |
| 8139 |
Statements.push_back(Result.getAs<Stmt>()); |
| 8140 |
} |
| 8141 |
|
| 8142 |
if (SubStmtInvalid) |
| 8143 |
return StmtError(); |
| 8144 |
|
| 8145 |
if (!getDerived().AlwaysRebuild() && |
| 8146 |
!SubStmtChanged) |
| 8147 |
return S; |
| 8148 |
|
| 8149 |
return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 8150 |
Statements, |
| 8151 |
S->getRBracLoc(), |
| 8152 |
IsStmtExpr); |
| 8153 |
} |
| 8154 |
|
| 8155 |
template<typename Derived> |
| 8156 |
StmtResult |
| 8157 |
TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
| 8158 |
ExprResult LHS, RHS; |
| 8159 |
{ |
| 8160 |
EnterExpressionEvaluationContext Unevaluated( |
| 8161 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 8162 |
|
| 8163 |
// Transform the left-hand case value. |
| 8164 |
LHS = getDerived().TransformExpr(S->getLHS()); |
| 8165 |
LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); |
| 8166 |
if (LHS.isInvalid()) |
| 8167 |
return StmtError(); |
| 8168 |
|
| 8169 |
// Transform the right-hand case value (for the GNU case-range extension). |
| 8170 |
RHS = getDerived().TransformExpr(S->getRHS()); |
| 8171 |
RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); |
| 8172 |
if (RHS.isInvalid()) |
| 8173 |
return StmtError(); |
| 8174 |
} |
| 8175 |
|
| 8176 |
// Build the case statement. |
| 8177 |
// Case statements are always rebuilt so that they will attached to their |
| 8178 |
// transformed switch statement. |
| 8179 |
StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 8180 |
LHS.get(), |
| 8181 |
S->getEllipsisLoc(), |
| 8182 |
RHS.get(), |
| 8183 |
S->getColonLoc()); |
| 8184 |
if (Case.isInvalid()) |
| 8185 |
return StmtError(); |
| 8186 |
|
| 8187 |
// Transform the statement following the case |
| 8188 |
StmtResult SubStmt = |
| 8189 |
getDerived().TransformStmt(S->getSubStmt()); |
| 8190 |
if (SubStmt.isInvalid()) |
| 8191 |
return StmtError(); |
| 8192 |
|
| 8193 |
// Attach the body to the case statement |
| 8194 |
return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
| 8195 |
} |
| 8196 |
|
| 8197 |
template <typename Derived> |
| 8198 |
StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
| 8199 |
// Transform the statement following the default case |
| 8200 |
StmtResult SubStmt = |
| 8201 |
getDerived().TransformStmt(S->getSubStmt()); |
| 8202 |
if (SubStmt.isInvalid()) |
| 8203 |
return StmtError(); |
| 8204 |
|
| 8205 |
// Default statements are always rebuilt |
| 8206 |
return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 8207 |
SubStmt.get()); |
| 8208 |
} |
| 8209 |
|
| 8210 |
template<typename Derived> |
| 8211 |
StmtResult |
| 8212 |
TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { |
| 8213 |
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| 8214 |
if (SubStmt.isInvalid()) |
| 8215 |
return StmtError(); |
| 8216 |
|
| 8217 |
Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 8218 |
S->getDecl()); |
| 8219 |
if (!LD) |
| 8220 |
return StmtError(); |
| 8221 |
|
| 8222 |
// If we're transforming "in-place" (we're not creating new local |
| 8223 |
// declarations), assume we're replacing the old label statement |
| 8224 |
// and clear out the reference to it. |
| 8225 |
if (LD == S->getDecl()) |
| 8226 |
S->getDecl()->setStmt(nullptr); |
| 8227 |
|
| 8228 |
// FIXME: Pass the real colon location in. |
| 8229 |
return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| 8230 |
cast<LabelDecl>(LD), SourceLocation(), |
| 8231 |
SubStmt.get()); |
| 8232 |
} |
| 8233 |
|
| 8234 |
template <typename Derived> |
| 8235 |
const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 8236 |
if (!R) |
| 8237 |
return R; |
| 8238 |
|
| 8239 |
switch (R->getKind()) { |
| 8240 |
// Transform attributes by calling TransformXXXAttr. |
| 8241 |
#define ATTR(X) \ |
| 8242 |
case attr::X: \ |
| 8243 |
return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 8244 |
#include "clang/Basic/AttrList.inc" |
| 8245 |
} |
| 8246 |
return R; |
| 8247 |
} |
| 8248 |
|
| 8249 |
template <typename Derived> |
| 8250 |
const Attr *TreeTransform<Derived>::TransformStmtAttr(const Stmt *OrigS, |
| 8251 |
const Stmt *InstS, |
| 8252 |
const Attr *R) { |
| 8253 |
if (!R) |
| 8254 |
return R; |
| 8255 |
|
| 8256 |
switch (R->getKind()) { |
| 8257 |
// Transform attributes by calling TransformStmtXXXAttr. |
| 8258 |
#define ATTR(X) \ |
| 8259 |
case attr::X: \ |
| 8260 |
return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R)); |
| 8261 |
#include "clang/Basic/AttrList.inc" |
| 8262 |
} |
| 8263 |
return TransformAttr(R); |
| 8264 |
} |
| 8265 |
|
| 8266 |
template <typename Derived> |
| 8267 |
StmtResult |
| 8268 |
TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, |
| 8269 |
StmtDiscardKind SDK) { |
| 8270 |
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| 8271 |
if (SubStmt.isInvalid()) |
| 8272 |
return StmtError(); |
| 8273 |
|
| 8274 |
bool AttrsChanged = false; |
| 8275 |
SmallVector<const Attr *, 1> Attrs; |
| 8276 |
|
| 8277 |
// Visit attributes and keep track if any are transformed. |
| 8278 |
for (const auto *I : S->getAttrs()) { |
| 8279 |
const Attr *R = |
| 8280 |
getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I); |
| 8281 |
AttrsChanged |= (I != R); |
| 8282 |
if (R) |
| 8283 |
Attrs.push_back(R); |
| 8284 |
} |
| 8285 |
|
| 8286 |
if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
| 8287 |
return S; |
| 8288 |
|
| 8289 |
// If transforming the attributes failed for all of the attributes in the |
| 8290 |
// statement, don't make an AttributedStmt without attributes. |
| 8291 |
if (Attrs.empty()) |
| 8292 |
return SubStmt; |
| 8293 |
|
| 8294 |
return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
| 8295 |
SubStmt.get()); |
| 8296 |
} |
| 8297 |
|
| 8298 |
template<typename Derived> |
| 8299 |
StmtResult |
| 8300 |
TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
| 8301 |
// Transform the initialization statement |
| 8302 |
StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 8303 |
if (Init.isInvalid()) |
| 8304 |
return StmtError(); |
| 8305 |
|
| 8306 |
Sema::ConditionResult Cond; |
| 8307 |
if (!S->isConsteval()) { |
| 8308 |
// Transform the condition |
| 8309 |
Cond = getDerived().TransformCondition( |
| 8310 |
S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
| 8311 |
S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 8312 |
: Sema::ConditionKind::Boolean); |
| 8313 |
if (Cond.isInvalid()) |
| 8314 |
return StmtError(); |
| 8315 |
} |
| 8316 |
|
| 8317 |
// If this is a constexpr if, determine which arm we should instantiate. |
| 8318 |
std::optional<bool> ConstexprConditionValue; |
| 8319 |
if (S->isConstexpr()) |
| 8320 |
ConstexprConditionValue = Cond.getKnownValue(); |
| 8321 |
|
| 8322 |
// Transform the "then" branch. |
| 8323 |
StmtResult Then; |
| 8324 |
if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 8325 |
EnterExpressionEvaluationContext Ctx( |
| 8326 |
getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext, |
| 8327 |
nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other, |
| 8328 |
S->isNonNegatedConsteval()); |
| 8329 |
|
| 8330 |
Then = getDerived().TransformStmt(S->getThen()); |
| 8331 |
if (Then.isInvalid()) |
| 8332 |
return StmtError(); |
| 8333 |
} else { |
| 8334 |
// Discarded branch is replaced with empty CompoundStmt so we can keep |
| 8335 |
// proper source location for start and end of original branch, so |
| 8336 |
// subsequent transformations like CoverageMapping work properly |
| 8337 |
Then = new (getSema().Context) |
| 8338 |
CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc()); |
| 8339 |
} |
| 8340 |
|
| 8341 |
// Transform the "else" branch. |
| 8342 |
StmtResult Else; |
| 8343 |
if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 8344 |
EnterExpressionEvaluationContext Ctx( |
| 8345 |
getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext, |
| 8346 |
nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other, |
| 8347 |
S->isNegatedConsteval()); |
| 8348 |
|
| 8349 |
Else = getDerived().TransformStmt(S->getElse()); |
| 8350 |
if (Else.isInvalid()) |
| 8351 |
return StmtError(); |
| 8352 |
} else if (S->getElse() && ConstexprConditionValue && |
| 8353 |
*ConstexprConditionValue) { |
| 8354 |
// Same thing here as with <then> branch, we are discarding it, we can't |
| 8355 |
// replace it with NULL nor NullStmt as we need to keep for source location |
| 8356 |
// range, for CoverageMapping |
| 8357 |
Else = new (getSema().Context) |
| 8358 |
CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc()); |
| 8359 |
} |
| 8360 |
|
| 8361 |
if (!getDerived().AlwaysRebuild() && |
| 8362 |
Init.get() == S->getInit() && |
| 8363 |
Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 8364 |
Then.get() == S->getThen() && |
| 8365 |
Else.get() == S->getElse()) |
| 8366 |
return S; |
| 8367 |
|
| 8368 |
return getDerived().RebuildIfStmt( |
| 8369 |
S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond, |
| 8370 |
S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get()); |
| 8371 |
} |
| 8372 |
|
| 8373 |
template<typename Derived> |
| 8374 |
StmtResult |
| 8375 |
TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
| 8376 |
// Transform the initialization statement |
| 8377 |
StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 8378 |
if (Init.isInvalid()) |
| 8379 |
return StmtError(); |
| 8380 |
|
| 8381 |
// Transform the condition. |
| 8382 |
Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 8383 |
S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 8384 |
Sema::ConditionKind::Switch); |
| 8385 |
if (Cond.isInvalid()) |
| 8386 |
return StmtError(); |
| 8387 |
|
| 8388 |
// Rebuild the switch statement. |
| 8389 |
StmtResult Switch = |
| 8390 |
getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(), |
| 8391 |
Init.get(), Cond, S->getRParenLoc()); |
| 8392 |
if (Switch.isInvalid()) |
| 8393 |
return StmtError(); |
| 8394 |
|
| 8395 |
// Transform the body of the switch statement. |
| 8396 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 8397 |
if (Body.isInvalid()) |
| 8398 |
return StmtError(); |
| 8399 |
|
| 8400 |
// Complete the switch statement. |
| 8401 |
return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 8402 |
Body.get()); |
| 8403 |
} |
| 8404 |
|
| 8405 |
template<typename Derived> |
| 8406 |
StmtResult |
| 8407 |
TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
| 8408 |
// Transform the condition |
| 8409 |
Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 8410 |
S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 8411 |
Sema::ConditionKind::Boolean); |
| 8412 |
if (Cond.isInvalid()) |
| 8413 |
return StmtError(); |
| 8414 |
|
| 8415 |
// OpenACC Restricts a while-loop inside of certain construct/clause |
| 8416 |
// combinations, so diagnose that here in OpenACC mode. |
| 8417 |
SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()}; |
| 8418 |
SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc()); |
| 8419 |
|
| 8420 |
// Transform the body |
| 8421 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 8422 |
if (Body.isInvalid()) |
| 8423 |
return StmtError(); |
| 8424 |
|
| 8425 |
if (!getDerived().AlwaysRebuild() && |
| 8426 |
Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 8427 |
Body.get() == S->getBody()) |
| 8428 |
return Owned(S); |
| 8429 |
|
| 8430 |
return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(), |
| 8431 |
Cond, S->getRParenLoc(), Body.get()); |
| 8432 |
} |
| 8433 |
|
| 8434 |
template<typename Derived> |
| 8435 |
StmtResult |
| 8436 |
TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 8437 |
// OpenACC Restricts a do-loop inside of certain construct/clause |
| 8438 |
// combinations, so diagnose that here in OpenACC mode. |
| 8439 |
SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()}; |
| 8440 |
SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc()); |
| 8441 |
|
| 8442 |
// Transform the body |
| 8443 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 8444 |
if (Body.isInvalid()) |
| 8445 |
return StmtError(); |
| 8446 |
|
| 8447 |
// Transform the condition |
| 8448 |
ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 8449 |
if (Cond.isInvalid()) |
| 8450 |
return StmtError(); |
| 8451 |
|
| 8452 |
if (!getDerived().AlwaysRebuild() && |
| 8453 |
Cond.get() == S->getCond() && |
| 8454 |
Body.get() == S->getBody()) |
| 8455 |
return S; |
| 8456 |
|
| 8457 |
return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 8458 |
/*FIXME:*/S->getWhileLoc(), Cond.get(), |
| 8459 |
S->getRParenLoc()); |
| 8460 |
} |
| 8461 |
|
| 8462 |
template<typename Derived> |
| 8463 |
StmtResult |
| 8464 |
TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
| 8465 |
if (getSema().getLangOpts().OpenMP) |
| 8466 |
getSema().OpenMP().startOpenMPLoop(); |
| 8467 |
|
| 8468 |
// Transform the initialization statement |
| 8469 |
StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 8470 |
if (Init.isInvalid()) |
| 8471 |
return StmtError(); |
| 8472 |
|
| 8473 |
// In OpenMP loop region loop control variable must be captured and be |
| 8474 |
// private. Perform analysis of first part (if any). |
| 8475 |
if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 8476 |
getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(), |
| 8477 |
Init.get()); |
| 8478 |
|
| 8479 |
// Transform the condition |
| 8480 |
Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 8481 |
S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 8482 |
Sema::ConditionKind::Boolean); |
| 8483 |
if (Cond.isInvalid()) |
| 8484 |
return StmtError(); |
| 8485 |
|
| 8486 |
// Transform the increment |
| 8487 |
ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 8488 |
if (Inc.isInvalid()) |
| 8489 |
return StmtError(); |
| 8490 |
|
| 8491 |
Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
| 8492 |
if (S->getInc() && !FullInc.get()) |
| 8493 |
return StmtError(); |
| 8494 |
|
| 8495 |
// OpenACC Restricts a for-loop inside of certain construct/clause |
| 8496 |
// combinations, so diagnose that here in OpenACC mode. |
| 8497 |
SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()}; |
| 8498 |
SemaRef.OpenACC().ActOnForStmtBegin( |
| 8499 |
S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(), |
| 8500 |
Cond.get().second, S->getInc(), Inc.get()); |
| 8501 |
|
| 8502 |
// Transform the body |
| 8503 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 8504 |
if (Body.isInvalid()) |
| 8505 |
return StmtError(); |
| 8506 |
|
| 8507 |
SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body); |
| 8508 |
|
| 8509 |
if (!getDerived().AlwaysRebuild() && |
| 8510 |
Init.get() == S->getInit() && |
| 8511 |
Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 8512 |
Inc.get() == S->getInc() && |
| 8513 |
Body.get() == S->getBody()) |
| 8514 |
return S; |
| 8515 |
|
| 8516 |
return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 8517 |
Init.get(), Cond, FullInc, |
| 8518 |
S->getRParenLoc(), Body.get()); |
| 8519 |
} |
| 8520 |
|
| 8521 |
template<typename Derived> |
| 8522 |
StmtResult |
| 8523 |
TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
| 8524 |
Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 8525 |
S->getLabel()); |
| 8526 |
if (!LD) |
| 8527 |
return StmtError(); |
| 8528 |
|
| 8529 |
// Goto statements must always be rebuilt, to resolve the label. |
| 8530 |
return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
| 8531 |
cast<LabelDecl>(LD)); |
| 8532 |
} |
| 8533 |
|
| 8534 |
template<typename Derived> |
| 8535 |
StmtResult |
| 8536 |
TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
| 8537 |
ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 8538 |
if (Target.isInvalid()) |
| 8539 |
return StmtError(); |
| 8540 |
Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
| 8541 |
|
| 8542 |
if (!getDerived().AlwaysRebuild() && |
| 8543 |
Target.get() == S->getTarget()) |
| 8544 |
return S; |
| 8545 |
|
| 8546 |
return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 8547 |
Target.get()); |
| 8548 |
} |
| 8549 |
|
| 8550 |
template<typename Derived> |
| 8551 |
StmtResult |
| 8552 |
TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 8553 |
if (!S->hasLabelTarget()) |
| 8554 |
return S; |
| 8555 |
|
| 8556 |
Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(), |
| 8557 |
S->getLabelDecl()); |
| 8558 |
if (!LD) |
| 8559 |
return StmtError(); |
| 8560 |
|
| 8561 |
return new (SemaRef.Context) |
| 8562 |
ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD)); |
| 8563 |
} |
| 8564 |
|
| 8565 |
template<typename Derived> |
| 8566 |
StmtResult |
| 8567 |
TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 8568 |
if (!S->hasLabelTarget()) |
| 8569 |
return S; |
| 8570 |
|
| 8571 |
Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(), |
| 8572 |
S->getLabelDecl()); |
| 8573 |
if (!LD) |
| 8574 |
return StmtError(); |
| 8575 |
|
| 8576 |
return new (SemaRef.Context) |
| 8577 |
BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD)); |
| 8578 |
} |
| 8579 |
|
| 8580 |
template <typename Derived> |
| 8581 |
StmtResult TreeTransform<Derived>::TransformDeferStmt(DeferStmt *S) { |
| 8582 |
StmtResult Result = getDerived().TransformStmt(S->getBody()); |
| 8583 |
if (!Result.isUsable()) |
| 8584 |
return StmtError(); |
| 8585 |
return DeferStmt::Create(getSema().Context, S->getDeferLoc(), Result.get()); |
| 8586 |
} |
| 8587 |
|
| 8588 |
template<typename Derived> |
| 8589 |
StmtResult |
| 8590 |
TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
| 8591 |
ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 8592 |
/*NotCopyInit*/false); |
| 8593 |
if (Result.isInvalid()) |
| 8594 |
return StmtError(); |
| 8595 |
|
| 8596 |
// FIXME: We always rebuild the return statement because there is no way |
| 8597 |
// to tell whether the return type of the function has changed. |
| 8598 |
return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
| 8599 |
} |
| 8600 |
|
| 8601 |
template<typename Derived> |
| 8602 |
StmtResult |
| 8603 |
TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
| 8604 |
bool DeclChanged = false; |
| 8605 |
SmallVector<Decl *, 4> Decls; |
| 8606 |
LambdaScopeInfo *LSI = getSema().getCurLambda(); |
| 8607 |
for (auto *D : S->decls()) { |
| 8608 |
Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
| 8609 |
if (!Transformed) |
| 8610 |
return StmtError(); |
| 8611 |
|
| 8612 |
if (Transformed != D) |
| 8613 |
DeclChanged = true; |
| 8614 |
|
| 8615 |
if (LSI) { |
| 8616 |
if (auto *TD = dyn_cast<TypeDecl>(Transformed)) { |
| 8617 |
if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) { |
| 8618 |
LSI->ContainsUnexpandedParameterPack |= |
| 8619 |
TN->getUnderlyingType()->containsUnexpandedParameterPack(); |
| 8620 |
} else { |
| 8621 |
LSI->ContainsUnexpandedParameterPack |= |
| 8622 |
getSema() |
| 8623 |
.getASTContext() |
| 8624 |
.getTypeDeclType(TD) |
| 8625 |
->containsUnexpandedParameterPack(); |
| 8626 |
} |
| 8627 |
} |
| 8628 |
if (auto *VD = dyn_cast<VarDecl>(Transformed)) |
| 8629 |
LSI->ContainsUnexpandedParameterPack |= |
| 8630 |
VD->getType()->containsUnexpandedParameterPack(); |
| 8631 |
} |
| 8632 |
|
| 8633 |
Decls.push_back(Transformed); |
| 8634 |
} |
| 8635 |
|
| 8636 |
if (!getDerived().AlwaysRebuild() && !DeclChanged) |
| 8637 |
return S; |
| 8638 |
|
| 8639 |
return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); |
| 8640 |
} |
| 8641 |
|
| 8642 |
template<typename Derived> |
| 8643 |
StmtResult |
| 8644 |
TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
| 8645 |
|
| 8646 |
SmallVector<Expr*, 8> Constraints; |
| 8647 |
SmallVector<Expr*, 8> Exprs; |
| 8648 |
SmallVector<IdentifierInfo *, 4> Names; |
| 8649 |
|
| 8650 |
SmallVector<Expr*, 8> Clobbers; |
| 8651 |
|
| 8652 |
bool ExprsChanged = false; |
| 8653 |
|
| 8654 |
auto RebuildString = [&](Expr *E) { |
| 8655 |
ExprResult Result = getDerived().TransformExpr(E); |
| 8656 |
if (!Result.isUsable()) |
| 8657 |
return Result; |
| 8658 |
if (Result.get() != E) { |
| 8659 |
ExprsChanged = true; |
| 8660 |
Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false); |
| 8661 |
} |
| 8662 |
return Result; |
| 8663 |
}; |
| 8664 |
|
| 8665 |
// Go through the outputs. |
| 8666 |
for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| 8667 |
Names.push_back(S->getOutputIdentifier(I)); |
| 8668 |
|
| 8669 |
ExprResult Result = RebuildString(S->getOutputConstraintExpr(I)); |
| 8670 |
if (Result.isInvalid()) |
| 8671 |
return StmtError(); |
| 8672 |
|
| 8673 |
Constraints.push_back(Result.get()); |
| 8674 |
|
| 8675 |
// Transform the output expr. |
| 8676 |
Expr *OutputExpr = S->getOutputExpr(I); |
| 8677 |
Result = getDerived().TransformExpr(OutputExpr); |
| 8678 |
if (Result.isInvalid()) |
| 8679 |
return StmtError(); |
| 8680 |
|
| 8681 |
ExprsChanged |= Result.get() != OutputExpr; |
| 8682 |
|
| 8683 |
Exprs.push_back(Result.get()); |
| 8684 |
} |
| 8685 |
|
| 8686 |
// Go through the inputs. |
| 8687 |
for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| 8688 |
Names.push_back(S->getInputIdentifier(I)); |
| 8689 |
|
| 8690 |
ExprResult Result = RebuildString(S->getInputConstraintExpr(I)); |
| 8691 |
if (Result.isInvalid()) |
| 8692 |
return StmtError(); |
| 8693 |
|
| 8694 |
Constraints.push_back(Result.get()); |
| 8695 |
|
| 8696 |
// Transform the input expr. |
| 8697 |
Expr *InputExpr = S->getInputExpr(I); |
| 8698 |
Result = getDerived().TransformExpr(InputExpr); |
| 8699 |
if (Result.isInvalid()) |
| 8700 |
return StmtError(); |
| 8701 |
|
| 8702 |
ExprsChanged |= Result.get() != InputExpr; |
| 8703 |
|
| 8704 |
Exprs.push_back(Result.get()); |
| 8705 |
} |
| 8706 |
|
| 8707 |
// Go through the Labels. |
| 8708 |
for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { |
| 8709 |
Names.push_back(S->getLabelIdentifier(I)); |
| 8710 |
|
| 8711 |
ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); |
| 8712 |
if (Result.isInvalid()) |
| 8713 |
return StmtError(); |
| 8714 |
ExprsChanged |= Result.get() != S->getLabelExpr(I); |
| 8715 |
Exprs.push_back(Result.get()); |
| 8716 |
} |
| 8717 |
|
| 8718 |
// Go through the clobbers. |
| 8719 |
for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) { |
| 8720 |
ExprResult Result = RebuildString(S->getClobberExpr(I)); |
| 8721 |
if (Result.isInvalid()) |
| 8722 |
return StmtError(); |
| 8723 |
Clobbers.push_back(Result.get()); |
| 8724 |
} |
| 8725 |
|
| 8726 |
ExprResult AsmString = RebuildString(S->getAsmStringExpr()); |
| 8727 |
if (AsmString.isInvalid()) |
| 8728 |
return StmtError(); |
| 8729 |
|
| 8730 |
if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 8731 |
return S; |
| 8732 |
|
| 8733 |
return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 8734 |
S->isVolatile(), S->getNumOutputs(), |
| 8735 |
S->getNumInputs(), Names.data(), |
| 8736 |
Constraints, Exprs, AsmString.get(), |
| 8737 |
Clobbers, S->getNumLabels(), |
| 8738 |
S->getRParenLoc()); |
| 8739 |
} |
| 8740 |
|
| 8741 |
template<typename Derived> |
| 8742 |
StmtResult |
| 8743 |
TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| 8744 |
ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
| 8745 |
|
| 8746 |
bool HadError = false, HadChange = false; |
| 8747 |
|
| 8748 |
ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 8749 |
SmallVector<Expr*, 8> TransformedExprs; |
| 8750 |
TransformedExprs.reserve(SrcExprs.size()); |
| 8751 |
for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 8752 |
ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 8753 |
if (!Result.isUsable()) { |
| 8754 |
HadError = true; |
| 8755 |
} else { |
| 8756 |
HadChange |= (Result.get() != SrcExprs[i]); |
| 8757 |
TransformedExprs.push_back(Result.get()); |
| 8758 |
} |
| 8759 |
} |
| 8760 |
|
| 8761 |
if (HadError) return StmtError(); |
| 8762 |
if (!HadChange && !getDerived().AlwaysRebuild()) |
| 8763 |
return Owned(S); |
| 8764 |
|
| 8765 |
return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| 8766 |
AsmToks, S->getAsmString(), |
| 8767 |
S->getNumOutputs(), S->getNumInputs(), |
| 8768 |
S->getAllConstraints(), S->getClobbers(), |
| 8769 |
TransformedExprs, S->getEndLoc()); |
| 8770 |
} |
| 8771 |
|
| 8772 |
// C++ Coroutines |
| 8773 |
template<typename Derived> |
| 8774 |
StmtResult |
| 8775 |
TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| 8776 |
auto *ScopeInfo = SemaRef.getCurFunction(); |
| 8777 |
auto *FD = cast<FunctionDecl>(SemaRef.CurContext); |
| 8778 |
assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && |
| 8779 |
ScopeInfo->NeedsCoroutineSuspends && |
| 8780 |
ScopeInfo->CoroutineSuspends.first == nullptr && |
| 8781 |
ScopeInfo->CoroutineSuspends.second == nullptr && |
| 8782 |
"expected clean scope info"); |
| 8783 |
|
| 8784 |
// Set that we have (possibly-invalid) suspend points before we do anything |
| 8785 |
// that may fail. |
| 8786 |
ScopeInfo->setNeedsCoroutineSuspends(false); |
| 8787 |
|
| 8788 |
// We re-build the coroutine promise object (and the coroutine parameters its |
| 8789 |
// type and constructor depend on) based on the types used in our current |
| 8790 |
// function. We must do so, and set it on the current FunctionScopeInfo, |
| 8791 |
// before attempting to transform the other parts of the coroutine body |
| 8792 |
// statement, such as the implicit suspend statements (because those |
| 8793 |
// statements reference the FunctionScopeInfo::CoroutinePromise). |
| 8794 |
if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) |
| 8795 |
return StmtError(); |
| 8796 |
auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); |
| 8797 |
if (!Promise) |
| 8798 |
return StmtError(); |
| 8799 |
getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); |
| 8800 |
ScopeInfo->CoroutinePromise = Promise; |
| 8801 |
|
| 8802 |
// Transform the implicit coroutine statements constructed using dependent |
| 8803 |
// types during the previous parse: initial and final suspensions, the return |
| 8804 |
// object, and others. We also transform the coroutine function's body. |
| 8805 |
StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); |
| 8806 |
if (InitSuspend.isInvalid()) |
| 8807 |
return StmtError(); |
| 8808 |
StmtResult FinalSuspend = |
| 8809 |
getDerived().TransformStmt(S->getFinalSuspendStmt()); |
| 8810 |
if (FinalSuspend.isInvalid() || |
| 8811 |
!SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get())) |
| 8812 |
return StmtError(); |
| 8813 |
ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); |
| 8814 |
assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); |
| 8815 |
|
| 8816 |
StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); |
| 8817 |
if (BodyRes.isInvalid()) |
| 8818 |
return StmtError(); |
| 8819 |
|
| 8820 |
CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); |
| 8821 |
if (Builder.isInvalid()) |
| 8822 |
return StmtError(); |
| 8823 |
|
| 8824 |
Expr *ReturnObject = S->getReturnValueInit(); |
| 8825 |
assert(ReturnObject && "the return object is expected to be valid"); |
| 8826 |
ExprResult Res = getDerived().TransformInitializer(ReturnObject, |
| 8827 |
/*NoCopyInit*/ false); |
| 8828 |
if (Res.isInvalid()) |
| 8829 |
return StmtError(); |
| 8830 |
Builder.ReturnValue = Res.get(); |
| 8831 |
|
| 8832 |
// If during the previous parse the coroutine still had a dependent promise |
| 8833 |
// statement, we may need to build some implicit coroutine statements |
| 8834 |
// (such as exception and fallthrough handlers) for the first time. |
| 8835 |
if (S->hasDependentPromiseType()) { |
| 8836 |
// We can only build these statements, however, if the current promise type |
| 8837 |
// is not dependent. |
| 8838 |
if (!Promise->getType()->isDependentType()) { |
| 8839 |
assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && |
| 8840 |
!S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && |
| 8841 |
"these nodes should not have been built yet"); |
| 8842 |
if (!Builder.buildDependentStatements()) |
| 8843 |
return StmtError(); |
| 8844 |
} |
| 8845 |
} else { |
| 8846 |
if (auto *OnFallthrough = S->getFallthroughHandler()) { |
| 8847 |
StmtResult Res = getDerived().TransformStmt(OnFallthrough); |
| 8848 |
if (Res.isInvalid()) |
| 8849 |
return StmtError(); |
| 8850 |
Builder.OnFallthrough = Res.get(); |
| 8851 |
} |
| 8852 |
|
| 8853 |
if (auto *OnException = S->getExceptionHandler()) { |
| 8854 |
StmtResult Res = getDerived().TransformStmt(OnException); |
| 8855 |
if (Res.isInvalid()) |
| 8856 |
return StmtError(); |
| 8857 |
Builder.OnException = Res.get(); |
| 8858 |
} |
| 8859 |
|
| 8860 |
if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { |
| 8861 |
StmtResult Res = getDerived().TransformStmt(OnAllocFailure); |
| 8862 |
if (Res.isInvalid()) |
| 8863 |
return StmtError(); |
| 8864 |
Builder.ReturnStmtOnAllocFailure = Res.get(); |
| 8865 |
} |
| 8866 |
|
| 8867 |
// Transform any additional statements we may have already built |
| 8868 |
assert(S->getAllocate() && S->getDeallocate() && |
| 8869 |
"allocation and deallocation calls must already be built"); |
| 8870 |
ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); |
| 8871 |
if (AllocRes.isInvalid()) |
| 8872 |
return StmtError(); |
| 8873 |
Builder.Allocate = AllocRes.get(); |
| 8874 |
|
| 8875 |
ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); |
| 8876 |
if (DeallocRes.isInvalid()) |
| 8877 |
return StmtError(); |
| 8878 |
Builder.Deallocate = DeallocRes.get(); |
| 8879 |
|
| 8880 |
if (auto *ResultDecl = S->getResultDecl()) { |
| 8881 |
StmtResult Res = getDerived().TransformStmt(ResultDecl); |
| 8882 |
if (Res.isInvalid()) |
| 8883 |
return StmtError(); |
| 8884 |
Builder.ResultDecl = Res.get(); |
| 8885 |
} |
| 8886 |
|
| 8887 |
if (auto *ReturnStmt = S->getReturnStmt()) { |
| 8888 |
StmtResult Res = getDerived().TransformStmt(ReturnStmt); |
| 8889 |
if (Res.isInvalid()) |
| 8890 |
return StmtError(); |
| 8891 |
Builder.ReturnStmt = Res.get(); |
| 8892 |
} |
| 8893 |
} |
| 8894 |
|
| 8895 |
return getDerived().RebuildCoroutineBodyStmt(Builder); |
| 8896 |
} |
| 8897 |
|
| 8898 |
template<typename Derived> |
| 8899 |
StmtResult |
| 8900 |
TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 8901 |
ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 8902 |
/*NotCopyInit*/false); |
| 8903 |
if (Result.isInvalid()) |
| 8904 |
return StmtError(); |
| 8905 |
|
| 8906 |
// Always rebuild; we don't know if this needs to be injected into a new |
| 8907 |
// context or if the promise type has changed. |
| 8908 |
return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), |
| 8909 |
S->isImplicit()); |
| 8910 |
} |
| 8911 |
|
| 8912 |
template <typename Derived> |
| 8913 |
ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 8914 |
ExprResult Operand = getDerived().TransformInitializer(E->getOperand(), |
| 8915 |
/*NotCopyInit*/ false); |
| 8916 |
if (Operand.isInvalid()) |
| 8917 |
return ExprError(); |
| 8918 |
|
| 8919 |
// Rebuild the common-expr from the operand rather than transforming it |
| 8920 |
// separately. |
| 8921 |
|
| 8922 |
// FIXME: getCurScope() should not be used during template instantiation. |
| 8923 |
// We should pick up the set of unqualified lookup results for operator |
| 8924 |
// co_await during the initial parse. |
| 8925 |
ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr( |
| 8926 |
getSema().getCurScope(), E->getKeywordLoc()); |
| 8927 |
|
| 8928 |
// Always rebuild; we don't know if this needs to be injected into a new |
| 8929 |
// context or if the promise type has changed. |
| 8930 |
return getDerived().RebuildCoawaitExpr( |
| 8931 |
E->getKeywordLoc(), Operand.get(), |
| 8932 |
cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit()); |
| 8933 |
} |
| 8934 |
|
| 8935 |
template <typename Derived> |
| 8936 |
ExprResult |
| 8937 |
TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { |
| 8938 |
ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), |
| 8939 |
/*NotCopyInit*/ false); |
| 8940 |
if (OperandResult.isInvalid()) |
| 8941 |
return ExprError(); |
| 8942 |
|
| 8943 |
ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( |
| 8944 |
E->getOperatorCoawaitLookup()); |
| 8945 |
|
| 8946 |
if (LookupResult.isInvalid()) |
| 8947 |
return ExprError(); |
| 8948 |
|
| 8949 |
// Always rebuild; we don't know if this needs to be injected into a new |
| 8950 |
// context or if the promise type has changed. |
| 8951 |
return getDerived().RebuildDependentCoawaitExpr( |
| 8952 |
E->getKeywordLoc(), OperandResult.get(), |
| 8953 |
cast<UnresolvedLookupExpr>(LookupResult.get())); |
| 8954 |
} |
| 8955 |
|
| 8956 |
template<typename Derived> |
| 8957 |
ExprResult |
| 8958 |
TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 8959 |
ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 8960 |
/*NotCopyInit*/false); |
| 8961 |
if (Result.isInvalid()) |
| 8962 |
return ExprError(); |
| 8963 |
|
| 8964 |
// Always rebuild; we don't know if this needs to be injected into a new |
| 8965 |
// context or if the promise type has changed. |
| 8966 |
return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 8967 |
} |
| 8968 |
|
| 8969 |
// Objective-C Statements. |
| 8970 |
|
| 8971 |
template<typename Derived> |
| 8972 |
StmtResult |
| 8973 |
TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 8974 |
// Transform the body of the @try. |
| 8975 |
StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 8976 |
if (TryBody.isInvalid()) |
| 8977 |
return StmtError(); |
| 8978 |
|
| 8979 |
// Transform the @catch statements (if present). |
| 8980 |
bool AnyCatchChanged = false; |
| 8981 |
SmallVector<Stmt*, 8> CatchStmts; |
| 8982 |
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 8983 |
StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
| 8984 |
if (Catch.isInvalid()) |
| 8985 |
return StmtError(); |
| 8986 |
if (Catch.get() != S->getCatchStmt(I)) |
| 8987 |
AnyCatchChanged = true; |
| 8988 |
CatchStmts.push_back(Catch.get()); |
| 8989 |
} |
| 8990 |
|
| 8991 |
// Transform the @finally statement (if present). |
| 8992 |
StmtResult Finally; |
| 8993 |
if (S->getFinallyStmt()) { |
| 8994 |
Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 8995 |
if (Finally.isInvalid()) |
| 8996 |
return StmtError(); |
| 8997 |
} |
| 8998 |
|
| 8999 |
// If nothing changed, just retain this statement. |
| 9000 |
if (!getDerived().AlwaysRebuild() && |
| 9001 |
TryBody.get() == S->getTryBody() && |
| 9002 |
!AnyCatchChanged && |
| 9003 |
Finally.get() == S->getFinallyStmt()) |
| 9004 |
return S; |
| 9005 |
|
| 9006 |
// Build a new statement. |
| 9007 |
return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 9008 |
CatchStmts, Finally.get()); |
| 9009 |
} |
| 9010 |
|
| 9011 |
template<typename Derived> |
| 9012 |
StmtResult |
| 9013 |
TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 9014 |
// Transform the @catch parameter, if there is one. |
| 9015 |
VarDecl *Var = nullptr; |
| 9016 |
if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 9017 |
TypeSourceInfo *TSInfo = nullptr; |
| 9018 |
if (FromVar->getTypeSourceInfo()) { |
| 9019 |
TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 9020 |
if (!TSInfo) |
| 9021 |
return StmtError(); |
| 9022 |
} |
| 9023 |
|
| 9024 |
QualType T; |
| 9025 |
if (TSInfo) |
| 9026 |
T = TSInfo->getType(); |
| 9027 |
else { |
| 9028 |
T = getDerived().TransformType(FromVar->getType()); |
| 9029 |
if (T.isNull()) |
| 9030 |
return StmtError(); |
| 9031 |
} |
| 9032 |
|
| 9033 |
Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 9034 |
if (!Var) |
| 9035 |
return StmtError(); |
| 9036 |
} |
| 9037 |
|
| 9038 |
StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 9039 |
if (Body.isInvalid()) |
| 9040 |
return StmtError(); |
| 9041 |
|
| 9042 |
return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| 9043 |
S->getRParenLoc(), |
| 9044 |
Var, Body.get()); |
| 9045 |
} |
| 9046 |
|
| 9047 |
template<typename Derived> |
| 9048 |
StmtResult |
| 9049 |
TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 9050 |
// Transform the body. |
| 9051 |
StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 9052 |
if (Body.isInvalid()) |
| 9053 |
return StmtError(); |
| 9054 |
|
| 9055 |
// If nothing changed, just retain this statement. |
| 9056 |
if (!getDerived().AlwaysRebuild() && |
| 9057 |
Body.get() == S->getFinallyBody()) |
| 9058 |
return S; |
| 9059 |
|
| 9060 |
// Build a new statement. |
| 9061 |
return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 9062 |
Body.get()); |
| 9063 |
} |
| 9064 |
|
| 9065 |
template<typename Derived> |
| 9066 |
StmtResult |
| 9067 |
TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 9068 |
ExprResult Operand; |
| 9069 |
if (S->getThrowExpr()) { |
| 9070 |
Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 9071 |
if (Operand.isInvalid()) |
| 9072 |
return StmtError(); |
| 9073 |
} |
| 9074 |
|
| 9075 |
if (!getDerived().AlwaysRebuild() && |
| 9076 |
Operand.get() == S->getThrowExpr()) |
| 9077 |
return S; |
| 9078 |
|
| 9079 |
return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
| 9080 |
} |
| 9081 |
|
| 9082 |
template<typename Derived> |
| 9083 |
StmtResult |
| 9084 |
TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
| 9085 |
ObjCAtSynchronizedStmt *S) { |
| 9086 |
// Transform the object we are locking. |
| 9087 |
ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 9088 |
if (Object.isInvalid()) |
| 9089 |
return StmtError(); |
| 9090 |
Object = |
| 9091 |
getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 9092 |
Object.get()); |
| 9093 |
if (Object.isInvalid()) |
| 9094 |
return StmtError(); |
| 9095 |
|
| 9096 |
// Transform the body. |
| 9097 |
StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 9098 |
if (Body.isInvalid()) |
| 9099 |
return StmtError(); |
| 9100 |
|
| 9101 |
// If nothing change, just retain the current statement. |
| 9102 |
if (!getDerived().AlwaysRebuild() && |
| 9103 |
Object.get() == S->getSynchExpr() && |
| 9104 |
Body.get() == S->getSynchBody()) |
| 9105 |
return S; |
| 9106 |
|
| 9107 |
// Build a new statement. |
| 9108 |
return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 9109 |
Object.get(), Body.get()); |
| 9110 |
} |
| 9111 |
|
| 9112 |
template<typename Derived> |
| 9113 |
StmtResult |
| 9114 |
TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 9115 |
ObjCAutoreleasePoolStmt *S) { |
| 9116 |
// Transform the body. |
| 9117 |
StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 9118 |
if (Body.isInvalid()) |
| 9119 |
return StmtError(); |
| 9120 |
|
| 9121 |
// If nothing changed, just retain this statement. |
| 9122 |
if (!getDerived().AlwaysRebuild() && |
| 9123 |
Body.get() == S->getSubStmt()) |
| 9124 |
return S; |
| 9125 |
|
| 9126 |
// Build a new statement. |
| 9127 |
return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 9128 |
S->getAtLoc(), Body.get()); |
| 9129 |
} |
| 9130 |
|
| 9131 |
template<typename Derived> |
| 9132 |
StmtResult |
| 9133 |
TreeTransform<Derived>::TransformObjCForCollectionStmt( |
| 9134 |
ObjCForCollectionStmt *S) { |
| 9135 |
// Transform the element statement. |
| 9136 |
StmtResult Element = getDerived().TransformStmt( |
| 9137 |
S->getElement(), StmtDiscardKind::NotDiscarded); |
| 9138 |
if (Element.isInvalid()) |
| 9139 |
return StmtError(); |
| 9140 |
|
| 9141 |
// Transform the collection expression. |
| 9142 |
ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 9143 |
if (Collection.isInvalid()) |
| 9144 |
return StmtError(); |
| 9145 |
|
| 9146 |
// Transform the body. |
| 9147 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 9148 |
if (Body.isInvalid()) |
| 9149 |
return StmtError(); |
| 9150 |
|
| 9151 |
// If nothing changed, just retain this statement. |
| 9152 |
if (!getDerived().AlwaysRebuild() && |
| 9153 |
Element.get() == S->getElement() && |
| 9154 |
Collection.get() == S->getCollection() && |
| 9155 |
Body.get() == S->getBody()) |
| 9156 |
return S; |
| 9157 |
|
| 9158 |
// Build a new statement. |
| 9159 |
return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 9160 |
Element.get(), |
| 9161 |
Collection.get(), |
| 9162 |
S->getRParenLoc(), |
| 9163 |
Body.get()); |
| 9164 |
} |
| 9165 |
|
| 9166 |
template <typename Derived> |
| 9167 |
StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 9168 |
// Transform the exception declaration, if any. |
| 9169 |
VarDecl *Var = nullptr; |
| 9170 |
if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 9171 |
TypeSourceInfo *T = |
| 9172 |
getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
| 9173 |
if (!T) |
| 9174 |
return StmtError(); |
| 9175 |
|
| 9176 |
Var = getDerived().RebuildExceptionDecl( |
| 9177 |
ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 9178 |
ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| 9179 |
if (!Var || Var->isInvalidDecl()) |
| 9180 |
return StmtError(); |
| 9181 |
} |
| 9182 |
|
| 9183 |
// Transform the actual exception handler. |
| 9184 |
StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 9185 |
if (Handler.isInvalid()) |
| 9186 |
return StmtError(); |
| 9187 |
|
| 9188 |
if (!getDerived().AlwaysRebuild() && !Var && |
| 9189 |
Handler.get() == S->getHandlerBlock()) |
| 9190 |
return S; |
| 9191 |
|
| 9192 |
return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
| 9193 |
} |
| 9194 |
|
| 9195 |
template <typename Derived> |
| 9196 |
StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 9197 |
// Transform the try block itself. |
| 9198 |
StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 9199 |
if (TryBlock.isInvalid()) |
| 9200 |
return StmtError(); |
| 9201 |
|
| 9202 |
// Transform the handlers. |
| 9203 |
bool HandlerChanged = false; |
| 9204 |
SmallVector<Stmt *, 8> Handlers; |
| 9205 |
for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
| 9206 |
StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 9207 |
if (Handler.isInvalid()) |
| 9208 |
return StmtError(); |
| 9209 |
|
| 9210 |
HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 9211 |
Handlers.push_back(Handler.getAs<Stmt>()); |
| 9212 |
} |
| 9213 |
|
| 9214 |
getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true); |
| 9215 |
|
| 9216 |
if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 9217 |
!HandlerChanged) |
| 9218 |
return S; |
| 9219 |
|
| 9220 |
return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
| 9221 |
Handlers); |
| 9222 |
} |
| 9223 |
|
| 9224 |
template<typename Derived> |
| 9225 |
StmtResult |
| 9226 |
TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 9227 |
EnterExpressionEvaluationContext ForRangeInitContext( |
| 9228 |
getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated, |
| 9229 |
/*LambdaContextDecl=*/nullptr, |
| 9230 |
Sema::ExpressionEvaluationContextRecord::EK_Other, |
| 9231 |
getSema().getLangOpts().CPlusPlus23); |
| 9232 |
|
| 9233 |
// P2718R0 - Lifetime extension in range-based for loops. |
| 9234 |
if (getSema().getLangOpts().CPlusPlus23) { |
| 9235 |
auto &LastRecord = getSema().currentEvaluationContext(); |
| 9236 |
LastRecord.InLifetimeExtendingContext = true; |
| 9237 |
LastRecord.RebuildDefaultArgOrDefaultInit = true; |
| 9238 |
} |
| 9239 |
StmtResult Init = |
| 9240 |
S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); |
| 9241 |
if (Init.isInvalid()) |
| 9242 |
return StmtError(); |
| 9243 |
|
| 9244 |
StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 9245 |
if (Range.isInvalid()) |
| 9246 |
return StmtError(); |
| 9247 |
|
| 9248 |
// Before c++23, ForRangeLifetimeExtendTemps should be empty. |
| 9249 |
assert(getSema().getLangOpts().CPlusPlus23 || |
| 9250 |
getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty()); |
| 9251 |
auto ForRangeLifetimeExtendTemps = |
| 9252 |
getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps; |
| 9253 |
|
| 9254 |
StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 9255 |
if (Begin.isInvalid()) |
| 9256 |
return StmtError(); |
| 9257 |
StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 9258 |
if (End.isInvalid()) |
| 9259 |
return StmtError(); |
| 9260 |
|
| 9261 |
ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 9262 |
if (Cond.isInvalid()) |
| 9263 |
return StmtError(); |
| 9264 |
if (Cond.get()) |
| 9265 |
Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
| 9266 |
if (Cond.isInvalid()) |
| 9267 |
return StmtError(); |
| 9268 |
if (Cond.get()) |
| 9269 |
Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
| 9270 |
|
| 9271 |
ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 9272 |
if (Inc.isInvalid()) |
| 9273 |
return StmtError(); |
| 9274 |
if (Inc.get()) |
| 9275 |
Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
| 9276 |
|
| 9277 |
StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 9278 |
if (LoopVar.isInvalid()) |
| 9279 |
return StmtError(); |
| 9280 |
|
| 9281 |
StmtResult NewStmt = S; |
| 9282 |
if (getDerived().AlwaysRebuild() || |
| 9283 |
Init.get() != S->getInit() || |
| 9284 |
Range.get() != S->getRangeStmt() || |
| 9285 |
Begin.get() != S->getBeginStmt() || |
| 9286 |
End.get() != S->getEndStmt() || |
| 9287 |
Cond.get() != S->getCond() || |
| 9288 |
Inc.get() != S->getInc() || |
| 9289 |
LoopVar.get() != S->getLoopVarStmt()) { |
| 9290 |
NewStmt = getDerived().RebuildCXXForRangeStmt( |
| 9291 |
S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(), |
| 9292 |
Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(), |
| 9293 |
LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps); |
| 9294 |
if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) { |
| 9295 |
// Might not have attached any initializer to the loop variable. |
| 9296 |
getSema().ActOnInitializerError( |
| 9297 |
cast<DeclStmt>(LoopVar.get())->getSingleDecl()); |
| 9298 |
return StmtError(); |
| 9299 |
} |
| 9300 |
} |
| 9301 |
|
| 9302 |
// OpenACC Restricts a while-loop inside of certain construct/clause |
| 9303 |
// combinations, so diagnose that here in OpenACC mode. |
| 9304 |
SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()}; |
| 9305 |
SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get()); |
| 9306 |
|
| 9307 |
StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 9308 |
if (Body.isInvalid()) |
| 9309 |
return StmtError(); |
| 9310 |
|
| 9311 |
SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body); |
| 9312 |
|
| 9313 |
// Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 9314 |
// it now so we have a new statement to attach the body to. |
| 9315 |
if (Body.get() != S->getBody() && NewStmt.get() == S) { |
| 9316 |
NewStmt = getDerived().RebuildCXXForRangeStmt( |
| 9317 |
S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(), |
| 9318 |
Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(), |
| 9319 |
LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps); |
| 9320 |
if (NewStmt.isInvalid()) |
| 9321 |
return StmtError(); |
| 9322 |
} |
| 9323 |
|
| 9324 |
if (NewStmt.get() == S) |
| 9325 |
return S; |
| 9326 |
|
| 9327 |
return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 9328 |
} |
| 9329 |
|
| 9330 |
template<typename Derived> |
| 9331 |
StmtResult |
| 9332 |
TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 9333 |
MSDependentExistsStmt *S) { |
| 9334 |
// Transform the nested-name-specifier, if any. |
| 9335 |
NestedNameSpecifierLoc QualifierLoc; |
| 9336 |
if (S->getQualifierLoc()) { |
| 9337 |
QualifierLoc |
| 9338 |
= getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 9339 |
if (!QualifierLoc) |
| 9340 |
return StmtError(); |
| 9341 |
} |
| 9342 |
|
| 9343 |
// Transform the declaration name. |
| 9344 |
DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 9345 |
if (NameInfo.getName()) { |
| 9346 |
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9347 |
if (!NameInfo.getName()) |
| 9348 |
return StmtError(); |
| 9349 |
} |
| 9350 |
|
| 9351 |
// Check whether anything changed. |
| 9352 |
if (!getDerived().AlwaysRebuild() && |
| 9353 |
QualifierLoc == S->getQualifierLoc() && |
| 9354 |
NameInfo.getName() == S->getNameInfo().getName()) |
| 9355 |
return S; |
| 9356 |
|
| 9357 |
// Determine whether this name exists, if we can. |
| 9358 |
CXXScopeSpec SS; |
| 9359 |
SS.Adopt(QualifierLoc); |
| 9360 |
bool Dependent = false; |
| 9361 |
switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
| 9362 |
case IfExistsResult::Exists: |
| 9363 |
if (S->isIfExists()) |
| 9364 |
break; |
| 9365 |
|
| 9366 |
return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 9367 |
|
| 9368 |
case IfExistsResult::DoesNotExist: |
| 9369 |
if (S->isIfNotExists()) |
| 9370 |
break; |
| 9371 |
|
| 9372 |
return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 9373 |
|
| 9374 |
case IfExistsResult::Dependent: |
| 9375 |
Dependent = true; |
| 9376 |
break; |
| 9377 |
|
| 9378 |
case IfExistsResult::Error: |
| 9379 |
return StmtError(); |
| 9380 |
} |
| 9381 |
|
| 9382 |
// We need to continue with the instantiation, so do so now. |
| 9383 |
StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 9384 |
if (SubStmt.isInvalid()) |
| 9385 |
return StmtError(); |
| 9386 |
|
| 9387 |
// If we have resolved the name, just transform to the substatement. |
| 9388 |
if (!Dependent) |
| 9389 |
return SubStmt; |
| 9390 |
|
| 9391 |
// The name is still dependent, so build a dependent expression again. |
| 9392 |
return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 9393 |
S->isIfExists(), |
| 9394 |
QualifierLoc, |
| 9395 |
NameInfo, |
| 9396 |
SubStmt.get()); |
| 9397 |
} |
| 9398 |
|
| 9399 |
template<typename Derived> |
| 9400 |
ExprResult |
| 9401 |
TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 9402 |
NestedNameSpecifierLoc QualifierLoc; |
| 9403 |
if (E->getQualifierLoc()) { |
| 9404 |
QualifierLoc |
| 9405 |
= getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9406 |
if (!QualifierLoc) |
| 9407 |
return ExprError(); |
| 9408 |
} |
| 9409 |
|
| 9410 |
MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 9411 |
getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 9412 |
if (!PD) |
| 9413 |
return ExprError(); |
| 9414 |
|
| 9415 |
ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 9416 |
if (Base.isInvalid()) |
| 9417 |
return ExprError(); |
| 9418 |
|
| 9419 |
return new (SemaRef.getASTContext()) |
| 9420 |
MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 9421 |
SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 9422 |
QualifierLoc, E->getMemberLoc()); |
| 9423 |
} |
| 9424 |
|
| 9425 |
template <typename Derived> |
| 9426 |
ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 9427 |
MSPropertySubscriptExpr *E) { |
| 9428 |
auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 9429 |
if (BaseRes.isInvalid()) |
| 9430 |
return ExprError(); |
| 9431 |
auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 9432 |
if (IdxRes.isInvalid()) |
| 9433 |
return ExprError(); |
| 9434 |
|
| 9435 |
if (!getDerived().AlwaysRebuild() && |
| 9436 |
BaseRes.get() == E->getBase() && |
| 9437 |
IdxRes.get() == E->getIdx()) |
| 9438 |
return E; |
| 9439 |
|
| 9440 |
return getDerived().RebuildArraySubscriptExpr( |
| 9441 |
BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 9442 |
} |
| 9443 |
|
| 9444 |
template <typename Derived> |
| 9445 |
StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 9446 |
StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 9447 |
if (TryBlock.isInvalid()) |
| 9448 |
return StmtError(); |
| 9449 |
|
| 9450 |
StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 9451 |
if (Handler.isInvalid()) |
| 9452 |
return StmtError(); |
| 9453 |
|
| 9454 |
if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 9455 |
Handler.get() == S->getHandler()) |
| 9456 |
return S; |
| 9457 |
|
| 9458 |
return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 9459 |
TryBlock.get(), Handler.get()); |
| 9460 |
} |
| 9461 |
|
| 9462 |
template <typename Derived> |
| 9463 |
StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 9464 |
StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| 9465 |
if (Block.isInvalid()) |
| 9466 |
return StmtError(); |
| 9467 |
|
| 9468 |
return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
| 9469 |
} |
| 9470 |
|
| 9471 |
template <typename Derived> |
| 9472 |
StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 9473 |
ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 9474 |
if (FilterExpr.isInvalid()) |
| 9475 |
return StmtError(); |
| 9476 |
|
| 9477 |
StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| 9478 |
if (Block.isInvalid()) |
| 9479 |
return StmtError(); |
| 9480 |
|
| 9481 |
return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 9482 |
Block.get()); |
| 9483 |
} |
| 9484 |
|
| 9485 |
template <typename Derived> |
| 9486 |
StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 9487 |
if (isa<SEHFinallyStmt>(Handler)) |
| 9488 |
return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 9489 |
else |
| 9490 |
return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 9491 |
} |
| 9492 |
|
| 9493 |
template<typename Derived> |
| 9494 |
StmtResult |
| 9495 |
TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 9496 |
return S; |
| 9497 |
} |
| 9498 |
|
| 9499 |
//===----------------------------------------------------------------------===// |
| 9500 |
// OpenMP directive transformation |
| 9501 |
//===----------------------------------------------------------------------===// |
| 9502 |
|
| 9503 |
template <typename Derived> |
| 9504 |
StmtResult |
| 9505 |
TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) { |
| 9506 |
// OMPCanonicalLoops are eliminated during transformation, since they will be |
| 9507 |
// recomputed by semantic analysis of the associated OMPLoopBasedDirective |
| 9508 |
// after transformation. |
| 9509 |
return getDerived().TransformStmt(L->getLoopStmt()); |
| 9510 |
} |
| 9511 |
|
| 9512 |
template <typename Derived> |
| 9513 |
StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 9514 |
OMPExecutableDirective *D) { |
| 9515 |
|
| 9516 |
// Transform the clauses |
| 9517 |
llvm::SmallVector<OMPClause *, 16> TClauses; |
| 9518 |
ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 9519 |
TClauses.reserve(Clauses.size()); |
| 9520 |
for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 9521 |
I != E; ++I) { |
| 9522 |
if (*I) { |
| 9523 |
getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind()); |
| 9524 |
OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| 9525 |
getDerived().getSema().OpenMP().EndOpenMPClause(); |
| 9526 |
if (Clause) |
| 9527 |
TClauses.push_back(Clause); |
| 9528 |
} else { |
| 9529 |
TClauses.push_back(nullptr); |
| 9530 |
} |
| 9531 |
} |
| 9532 |
StmtResult AssociatedStmt; |
| 9533 |
if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| 9534 |
getDerived().getSema().OpenMP().ActOnOpenMPRegionStart( |
| 9535 |
D->getDirectiveKind(), |
| 9536 |
/*CurScope=*/nullptr); |
| 9537 |
StmtResult Body; |
| 9538 |
{ |
| 9539 |
Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 9540 |
Stmt *CS; |
| 9541 |
if (D->getDirectiveKind() == OMPD_atomic || |
| 9542 |
D->getDirectiveKind() == OMPD_critical || |
| 9543 |
D->getDirectiveKind() == OMPD_section || |
| 9544 |
D->getDirectiveKind() == OMPD_master) |
| 9545 |
CS = D->getAssociatedStmt(); |
| 9546 |
else |
| 9547 |
CS = D->getRawStmt(); |
| 9548 |
Body = getDerived().TransformStmt(CS); |
| 9549 |
if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) && |
| 9550 |
getSema().getLangOpts().OpenMPIRBuilder) |
| 9551 |
Body = getDerived().RebuildOMPCanonicalLoop(Body.get()); |
| 9552 |
} |
| 9553 |
AssociatedStmt = |
| 9554 |
getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses); |
| 9555 |
if (AssociatedStmt.isInvalid()) { |
| 9556 |
return StmtError(); |
| 9557 |
} |
| 9558 |
} |
| 9559 |
if (TClauses.size() != Clauses.size()) { |
| 9560 |
return StmtError(); |
| 9561 |
} |
| 9562 |
|
| 9563 |
// Transform directive name for 'omp critical' directive. |
| 9564 |
DeclarationNameInfo DirName; |
| 9565 |
if (D->getDirectiveKind() == OMPD_critical) { |
| 9566 |
DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 9567 |
DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 9568 |
} |
| 9569 |
OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 9570 |
if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 9571 |
CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
| 9572 |
} else if (D->getDirectiveKind() == OMPD_cancel) { |
| 9573 |
CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
| 9574 |
} |
| 9575 |
|
| 9576 |
return getDerived().RebuildOMPExecutableDirective( |
| 9577 |
D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| 9578 |
AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); |
| 9579 |
} |
| 9580 |
|
| 9581 |
/// This is mostly the same as above, but allows 'informational' class |
| 9582 |
/// directives when rebuilding the stmt. It still takes an |
| 9583 |
/// OMPExecutableDirective-type argument because we're reusing that as the |
| 9584 |
/// superclass for the 'assume' directive at present, instead of defining a |
| 9585 |
/// mostly-identical OMPInformationalDirective parent class. |
| 9586 |
template <typename Derived> |
| 9587 |
StmtResult TreeTransform<Derived>::TransformOMPInformationalDirective( |
| 9588 |
OMPExecutableDirective *D) { |
| 9589 |
|
| 9590 |
// Transform the clauses |
| 9591 |
llvm::SmallVector<OMPClause *, 16> TClauses; |
| 9592 |
ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 9593 |
TClauses.reserve(Clauses.size()); |
| 9594 |
for (OMPClause *C : Clauses) { |
| 9595 |
if (C) { |
| 9596 |
getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind()); |
| 9597 |
OMPClause *Clause = getDerived().TransformOMPClause(C); |
| 9598 |
getDerived().getSema().OpenMP().EndOpenMPClause(); |
| 9599 |
if (Clause) |
| 9600 |
TClauses.push_back(Clause); |
| 9601 |
} else { |
| 9602 |
TClauses.push_back(nullptr); |
| 9603 |
} |
| 9604 |
} |
| 9605 |
StmtResult AssociatedStmt; |
| 9606 |
if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| 9607 |
getDerived().getSema().OpenMP().ActOnOpenMPRegionStart( |
| 9608 |
D->getDirectiveKind(), |
| 9609 |
/*CurScope=*/nullptr); |
| 9610 |
StmtResult Body; |
| 9611 |
{ |
| 9612 |
Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 9613 |
assert(D->getDirectiveKind() == OMPD_assume && |
| 9614 |
"Unexpected informational directive"); |
| 9615 |
Stmt *CS = D->getAssociatedStmt(); |
| 9616 |
Body = getDerived().TransformStmt(CS); |
| 9617 |
} |
| 9618 |
AssociatedStmt = |
| 9619 |
getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses); |
| 9620 |
if (AssociatedStmt.isInvalid()) |
| 9621 |
return StmtError(); |
| 9622 |
} |
| 9623 |
if (TClauses.size() != Clauses.size()) |
| 9624 |
return StmtError(); |
| 9625 |
|
| 9626 |
DeclarationNameInfo DirName; |
| 9627 |
|
| 9628 |
return getDerived().RebuildOMPInformationalDirective( |
| 9629 |
D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(), |
| 9630 |
D->getBeginLoc(), D->getEndLoc()); |
| 9631 |
} |
| 9632 |
|
| 9633 |
template <typename Derived> |
| 9634 |
StmtResult |
| 9635 |
TreeTransform<Derived>::TransformOMPMetaDirective(OMPMetaDirective *D) { |
| 9636 |
// TODO: Fix This |
| 9637 |
unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP; |
| 9638 |
SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported) |
| 9639 |
<< getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion); |
| 9640 |
return StmtError(); |
| 9641 |
} |
| 9642 |
|
| 9643 |
template <typename Derived> |
| 9644 |
StmtResult |
| 9645 |
TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 9646 |
DeclarationNameInfo DirName; |
| 9647 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9648 |
OMPD_parallel, DirName, nullptr, D->getBeginLoc()); |
| 9649 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9650 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9651 |
return Res; |
| 9652 |
} |
| 9653 |
|
| 9654 |
template <typename Derived> |
| 9655 |
StmtResult |
| 9656 |
TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 9657 |
DeclarationNameInfo DirName; |
| 9658 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9659 |
OMPD_simd, DirName, nullptr, D->getBeginLoc()); |
| 9660 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9661 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9662 |
return Res; |
| 9663 |
} |
| 9664 |
|
| 9665 |
template <typename Derived> |
| 9666 |
StmtResult |
| 9667 |
TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) { |
| 9668 |
DeclarationNameInfo DirName; |
| 9669 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9670 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9671 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9672 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9673 |
return Res; |
| 9674 |
} |
| 9675 |
|
| 9676 |
template <typename Derived> |
| 9677 |
StmtResult |
| 9678 |
TreeTransform<Derived>::TransformOMPStripeDirective(OMPStripeDirective *D) { |
| 9679 |
DeclarationNameInfo DirName; |
| 9680 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9681 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9682 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9683 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9684 |
return Res; |
| 9685 |
} |
| 9686 |
|
| 9687 |
template <typename Derived> |
| 9688 |
StmtResult |
| 9689 |
TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) { |
| 9690 |
DeclarationNameInfo DirName; |
| 9691 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9692 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9693 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9694 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9695 |
return Res; |
| 9696 |
} |
| 9697 |
|
| 9698 |
template <typename Derived> |
| 9699 |
StmtResult |
| 9700 |
TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) { |
| 9701 |
DeclarationNameInfo DirName; |
| 9702 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9703 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9704 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9705 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9706 |
return Res; |
| 9707 |
} |
| 9708 |
|
| 9709 |
template <typename Derived> |
| 9710 |
StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective( |
| 9711 |
OMPInterchangeDirective *D) { |
| 9712 |
DeclarationNameInfo DirName; |
| 9713 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9714 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9715 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9716 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9717 |
return Res; |
| 9718 |
} |
| 9719 |
|
| 9720 |
template <typename Derived> |
| 9721 |
StmtResult |
| 9722 |
TreeTransform<Derived>::TransformOMPFuseDirective(OMPFuseDirective *D) { |
| 9723 |
DeclarationNameInfo DirName; |
| 9724 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9725 |
D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc()); |
| 9726 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9727 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9728 |
return Res; |
| 9729 |
} |
| 9730 |
|
| 9731 |
template <typename Derived> |
| 9732 |
StmtResult |
| 9733 |
TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 9734 |
DeclarationNameInfo DirName; |
| 9735 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9736 |
OMPD_for, DirName, nullptr, D->getBeginLoc()); |
| 9737 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9738 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9739 |
return Res; |
| 9740 |
} |
| 9741 |
|
| 9742 |
template <typename Derived> |
| 9743 |
StmtResult |
| 9744 |
TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 9745 |
DeclarationNameInfo DirName; |
| 9746 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9747 |
OMPD_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 9748 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9749 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9750 |
return Res; |
| 9751 |
} |
| 9752 |
|
| 9753 |
template <typename Derived> |
| 9754 |
StmtResult |
| 9755 |
TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 9756 |
DeclarationNameInfo DirName; |
| 9757 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9758 |
OMPD_sections, DirName, nullptr, D->getBeginLoc()); |
| 9759 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9760 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9761 |
return Res; |
| 9762 |
} |
| 9763 |
|
| 9764 |
template <typename Derived> |
| 9765 |
StmtResult |
| 9766 |
TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 9767 |
DeclarationNameInfo DirName; |
| 9768 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9769 |
OMPD_section, DirName, nullptr, D->getBeginLoc()); |
| 9770 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9771 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9772 |
return Res; |
| 9773 |
} |
| 9774 |
|
| 9775 |
template <typename Derived> |
| 9776 |
StmtResult |
| 9777 |
TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) { |
| 9778 |
DeclarationNameInfo DirName; |
| 9779 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9780 |
OMPD_scope, DirName, nullptr, D->getBeginLoc()); |
| 9781 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9782 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9783 |
return Res; |
| 9784 |
} |
| 9785 |
|
| 9786 |
template <typename Derived> |
| 9787 |
StmtResult |
| 9788 |
TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 9789 |
DeclarationNameInfo DirName; |
| 9790 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9791 |
OMPD_single, DirName, nullptr, D->getBeginLoc()); |
| 9792 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9793 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9794 |
return Res; |
| 9795 |
} |
| 9796 |
|
| 9797 |
template <typename Derived> |
| 9798 |
StmtResult |
| 9799 |
TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 9800 |
DeclarationNameInfo DirName; |
| 9801 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9802 |
OMPD_master, DirName, nullptr, D->getBeginLoc()); |
| 9803 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9804 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9805 |
return Res; |
| 9806 |
} |
| 9807 |
|
| 9808 |
template <typename Derived> |
| 9809 |
StmtResult |
| 9810 |
TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 9811 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9812 |
OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); |
| 9813 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9814 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9815 |
return Res; |
| 9816 |
} |
| 9817 |
|
| 9818 |
template <typename Derived> |
| 9819 |
StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 9820 |
OMPParallelForDirective *D) { |
| 9821 |
DeclarationNameInfo DirName; |
| 9822 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9823 |
OMPD_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 9824 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9825 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9826 |
return Res; |
| 9827 |
} |
| 9828 |
|
| 9829 |
template <typename Derived> |
| 9830 |
StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 9831 |
OMPParallelForSimdDirective *D) { |
| 9832 |
DeclarationNameInfo DirName; |
| 9833 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9834 |
OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 9835 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9836 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9837 |
return Res; |
| 9838 |
} |
| 9839 |
|
| 9840 |
template <typename Derived> |
| 9841 |
StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective( |
| 9842 |
OMPParallelMasterDirective *D) { |
| 9843 |
DeclarationNameInfo DirName; |
| 9844 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9845 |
OMPD_parallel_master, DirName, nullptr, D->getBeginLoc()); |
| 9846 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9847 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9848 |
return Res; |
| 9849 |
} |
| 9850 |
|
| 9851 |
template <typename Derived> |
| 9852 |
StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective( |
| 9853 |
OMPParallelMaskedDirective *D) { |
| 9854 |
DeclarationNameInfo DirName; |
| 9855 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9856 |
OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc()); |
| 9857 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9858 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9859 |
return Res; |
| 9860 |
} |
| 9861 |
|
| 9862 |
template <typename Derived> |
| 9863 |
StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 9864 |
OMPParallelSectionsDirective *D) { |
| 9865 |
DeclarationNameInfo DirName; |
| 9866 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9867 |
OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc()); |
| 9868 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9869 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9870 |
return Res; |
| 9871 |
} |
| 9872 |
|
| 9873 |
template <typename Derived> |
| 9874 |
StmtResult |
| 9875 |
TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 9876 |
DeclarationNameInfo DirName; |
| 9877 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9878 |
OMPD_task, DirName, nullptr, D->getBeginLoc()); |
| 9879 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9880 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9881 |
return Res; |
| 9882 |
} |
| 9883 |
|
| 9884 |
template <typename Derived> |
| 9885 |
StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 9886 |
OMPTaskyieldDirective *D) { |
| 9887 |
DeclarationNameInfo DirName; |
| 9888 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9889 |
OMPD_taskyield, DirName, nullptr, D->getBeginLoc()); |
| 9890 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9891 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9892 |
return Res; |
| 9893 |
} |
| 9894 |
|
| 9895 |
template <typename Derived> |
| 9896 |
StmtResult |
| 9897 |
TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 9898 |
DeclarationNameInfo DirName; |
| 9899 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9900 |
OMPD_barrier, DirName, nullptr, D->getBeginLoc()); |
| 9901 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9902 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9903 |
return Res; |
| 9904 |
} |
| 9905 |
|
| 9906 |
template <typename Derived> |
| 9907 |
StmtResult |
| 9908 |
TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 9909 |
DeclarationNameInfo DirName; |
| 9910 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9911 |
OMPD_taskwait, DirName, nullptr, D->getBeginLoc()); |
| 9912 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9913 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9914 |
return Res; |
| 9915 |
} |
| 9916 |
|
| 9917 |
template <typename Derived> |
| 9918 |
StmtResult |
| 9919 |
TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) { |
| 9920 |
DeclarationNameInfo DirName; |
| 9921 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9922 |
OMPD_assume, DirName, nullptr, D->getBeginLoc()); |
| 9923 |
StmtResult Res = getDerived().TransformOMPInformationalDirective(D); |
| 9924 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9925 |
return Res; |
| 9926 |
} |
| 9927 |
|
| 9928 |
template <typename Derived> |
| 9929 |
StmtResult |
| 9930 |
TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) { |
| 9931 |
DeclarationNameInfo DirName; |
| 9932 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9933 |
OMPD_error, DirName, nullptr, D->getBeginLoc()); |
| 9934 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9935 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9936 |
return Res; |
| 9937 |
} |
| 9938 |
|
| 9939 |
template <typename Derived> |
| 9940 |
StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 9941 |
OMPTaskgroupDirective *D) { |
| 9942 |
DeclarationNameInfo DirName; |
| 9943 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9944 |
OMPD_taskgroup, DirName, nullptr, D->getBeginLoc()); |
| 9945 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9946 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9947 |
return Res; |
| 9948 |
} |
| 9949 |
|
| 9950 |
template <typename Derived> |
| 9951 |
StmtResult |
| 9952 |
TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 9953 |
DeclarationNameInfo DirName; |
| 9954 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9955 |
OMPD_flush, DirName, nullptr, D->getBeginLoc()); |
| 9956 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9957 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9958 |
return Res; |
| 9959 |
} |
| 9960 |
|
| 9961 |
template <typename Derived> |
| 9962 |
StmtResult |
| 9963 |
TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) { |
| 9964 |
DeclarationNameInfo DirName; |
| 9965 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9966 |
OMPD_depobj, DirName, nullptr, D->getBeginLoc()); |
| 9967 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9968 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9969 |
return Res; |
| 9970 |
} |
| 9971 |
|
| 9972 |
template <typename Derived> |
| 9973 |
StmtResult |
| 9974 |
TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) { |
| 9975 |
DeclarationNameInfo DirName; |
| 9976 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9977 |
OMPD_scan, DirName, nullptr, D->getBeginLoc()); |
| 9978 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9979 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9980 |
return Res; |
| 9981 |
} |
| 9982 |
|
| 9983 |
template <typename Derived> |
| 9984 |
StmtResult |
| 9985 |
TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 9986 |
DeclarationNameInfo DirName; |
| 9987 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9988 |
OMPD_ordered, DirName, nullptr, D->getBeginLoc()); |
| 9989 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 9990 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 9991 |
return Res; |
| 9992 |
} |
| 9993 |
|
| 9994 |
template <typename Derived> |
| 9995 |
StmtResult |
| 9996 |
TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 9997 |
DeclarationNameInfo DirName; |
| 9998 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 9999 |
OMPD_atomic, DirName, nullptr, D->getBeginLoc()); |
| 10000 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10001 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10002 |
return Res; |
| 10003 |
} |
| 10004 |
|
| 10005 |
template <typename Derived> |
| 10006 |
StmtResult |
| 10007 |
TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 10008 |
DeclarationNameInfo DirName; |
| 10009 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10010 |
OMPD_target, DirName, nullptr, D->getBeginLoc()); |
| 10011 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10012 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10013 |
return Res; |
| 10014 |
} |
| 10015 |
|
| 10016 |
template <typename Derived> |
| 10017 |
StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 10018 |
OMPTargetDataDirective *D) { |
| 10019 |
DeclarationNameInfo DirName; |
| 10020 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10021 |
OMPD_target_data, DirName, nullptr, D->getBeginLoc()); |
| 10022 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10023 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10024 |
return Res; |
| 10025 |
} |
| 10026 |
|
| 10027 |
template <typename Derived> |
| 10028 |
StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 10029 |
OMPTargetEnterDataDirective *D) { |
| 10030 |
DeclarationNameInfo DirName; |
| 10031 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10032 |
OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc()); |
| 10033 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10034 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10035 |
return Res; |
| 10036 |
} |
| 10037 |
|
| 10038 |
template <typename Derived> |
| 10039 |
StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 10040 |
OMPTargetExitDataDirective *D) { |
| 10041 |
DeclarationNameInfo DirName; |
| 10042 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10043 |
OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc()); |
| 10044 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10045 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10046 |
return Res; |
| 10047 |
} |
| 10048 |
|
| 10049 |
template <typename Derived> |
| 10050 |
StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 10051 |
OMPTargetParallelDirective *D) { |
| 10052 |
DeclarationNameInfo DirName; |
| 10053 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10054 |
OMPD_target_parallel, DirName, nullptr, D->getBeginLoc()); |
| 10055 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10056 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10057 |
return Res; |
| 10058 |
} |
| 10059 |
|
| 10060 |
template <typename Derived> |
| 10061 |
StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 10062 |
OMPTargetParallelForDirective *D) { |
| 10063 |
DeclarationNameInfo DirName; |
| 10064 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10065 |
OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 10066 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10067 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10068 |
return Res; |
| 10069 |
} |
| 10070 |
|
| 10071 |
template <typename Derived> |
| 10072 |
StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 10073 |
OMPTargetUpdateDirective *D) { |
| 10074 |
DeclarationNameInfo DirName; |
| 10075 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10076 |
OMPD_target_update, DirName, nullptr, D->getBeginLoc()); |
| 10077 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10078 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10079 |
return Res; |
| 10080 |
} |
| 10081 |
|
| 10082 |
template <typename Derived> |
| 10083 |
StmtResult |
| 10084 |
TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 10085 |
DeclarationNameInfo DirName; |
| 10086 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10087 |
OMPD_teams, DirName, nullptr, D->getBeginLoc()); |
| 10088 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10089 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10090 |
return Res; |
| 10091 |
} |
| 10092 |
|
| 10093 |
template <typename Derived> |
| 10094 |
StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 10095 |
OMPCancellationPointDirective *D) { |
| 10096 |
DeclarationNameInfo DirName; |
| 10097 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10098 |
OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc()); |
| 10099 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10100 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10101 |
return Res; |
| 10102 |
} |
| 10103 |
|
| 10104 |
template <typename Derived> |
| 10105 |
StmtResult |
| 10106 |
TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 10107 |
DeclarationNameInfo DirName; |
| 10108 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10109 |
OMPD_cancel, DirName, nullptr, D->getBeginLoc()); |
| 10110 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10111 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10112 |
return Res; |
| 10113 |
} |
| 10114 |
|
| 10115 |
template <typename Derived> |
| 10116 |
StmtResult |
| 10117 |
TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 10118 |
DeclarationNameInfo DirName; |
| 10119 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10120 |
OMPD_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 10121 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10122 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10123 |
return Res; |
| 10124 |
} |
| 10125 |
|
| 10126 |
template <typename Derived> |
| 10127 |
StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 10128 |
OMPTaskLoopSimdDirective *D) { |
| 10129 |
DeclarationNameInfo DirName; |
| 10130 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10131 |
OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 10132 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10133 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10134 |
return Res; |
| 10135 |
} |
| 10136 |
|
| 10137 |
template <typename Derived> |
| 10138 |
StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective( |
| 10139 |
OMPMasterTaskLoopDirective *D) { |
| 10140 |
DeclarationNameInfo DirName; |
| 10141 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10142 |
OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 10143 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10144 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10145 |
return Res; |
| 10146 |
} |
| 10147 |
|
| 10148 |
template <typename Derived> |
| 10149 |
StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective( |
| 10150 |
OMPMaskedTaskLoopDirective *D) { |
| 10151 |
DeclarationNameInfo DirName; |
| 10152 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10153 |
OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 10154 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10155 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10156 |
return Res; |
| 10157 |
} |
| 10158 |
|
| 10159 |
template <typename Derived> |
| 10160 |
StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective( |
| 10161 |
OMPMasterTaskLoopSimdDirective *D) { |
| 10162 |
DeclarationNameInfo DirName; |
| 10163 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10164 |
OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 10165 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10166 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10167 |
return Res; |
| 10168 |
} |
| 10169 |
|
| 10170 |
template <typename Derived> |
| 10171 |
StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective( |
| 10172 |
OMPMaskedTaskLoopSimdDirective *D) { |
| 10173 |
DeclarationNameInfo DirName; |
| 10174 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10175 |
OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 10176 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10177 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10178 |
return Res; |
| 10179 |
} |
| 10180 |
|
| 10181 |
template <typename Derived> |
| 10182 |
StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective( |
| 10183 |
OMPParallelMasterTaskLoopDirective *D) { |
| 10184 |
DeclarationNameInfo DirName; |
| 10185 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10186 |
OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 10187 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10188 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10189 |
return Res; |
| 10190 |
} |
| 10191 |
|
| 10192 |
template <typename Derived> |
| 10193 |
StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective( |
| 10194 |
OMPParallelMaskedTaskLoopDirective *D) { |
| 10195 |
DeclarationNameInfo DirName; |
| 10196 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10197 |
OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 10198 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10199 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10200 |
return Res; |
| 10201 |
} |
| 10202 |
|
| 10203 |
template <typename Derived> |
| 10204 |
StmtResult |
| 10205 |
TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective( |
| 10206 |
OMPParallelMasterTaskLoopSimdDirective *D) { |
| 10207 |
DeclarationNameInfo DirName; |
| 10208 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10209 |
OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 10210 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10211 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10212 |
return Res; |
| 10213 |
} |
| 10214 |
|
| 10215 |
template <typename Derived> |
| 10216 |
StmtResult |
| 10217 |
TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective( |
| 10218 |
OMPParallelMaskedTaskLoopSimdDirective *D) { |
| 10219 |
DeclarationNameInfo DirName; |
| 10220 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10221 |
OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 10222 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10223 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10224 |
return Res; |
| 10225 |
} |
| 10226 |
|
| 10227 |
template <typename Derived> |
| 10228 |
StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 10229 |
OMPDistributeDirective *D) { |
| 10230 |
DeclarationNameInfo DirName; |
| 10231 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10232 |
OMPD_distribute, DirName, nullptr, D->getBeginLoc()); |
| 10233 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10234 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10235 |
return Res; |
| 10236 |
} |
| 10237 |
|
| 10238 |
template <typename Derived> |
| 10239 |
StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 10240 |
OMPDistributeParallelForDirective *D) { |
| 10241 |
DeclarationNameInfo DirName; |
| 10242 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10243 |
OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 10244 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10245 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10246 |
return Res; |
| 10247 |
} |
| 10248 |
|
| 10249 |
template <typename Derived> |
| 10250 |
StmtResult |
| 10251 |
TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 10252 |
OMPDistributeParallelForSimdDirective *D) { |
| 10253 |
DeclarationNameInfo DirName; |
| 10254 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10255 |
OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 10256 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10257 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10258 |
return Res; |
| 10259 |
} |
| 10260 |
|
| 10261 |
template <typename Derived> |
| 10262 |
StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( |
| 10263 |
OMPDistributeSimdDirective *D) { |
| 10264 |
DeclarationNameInfo DirName; |
| 10265 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10266 |
OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| 10267 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10268 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10269 |
return Res; |
| 10270 |
} |
| 10271 |
|
| 10272 |
template <typename Derived> |
| 10273 |
StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( |
| 10274 |
OMPTargetParallelForSimdDirective *D) { |
| 10275 |
DeclarationNameInfo DirName; |
| 10276 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10277 |
OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 10278 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10279 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10280 |
return Res; |
| 10281 |
} |
| 10282 |
|
| 10283 |
template <typename Derived> |
| 10284 |
StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( |
| 10285 |
OMPTargetSimdDirective *D) { |
| 10286 |
DeclarationNameInfo DirName; |
| 10287 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10288 |
OMPD_target_simd, DirName, nullptr, D->getBeginLoc()); |
| 10289 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10290 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10291 |
return Res; |
| 10292 |
} |
| 10293 |
|
| 10294 |
template <typename Derived> |
| 10295 |
StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( |
| 10296 |
OMPTeamsDistributeDirective *D) { |
| 10297 |
DeclarationNameInfo DirName; |
| 10298 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10299 |
OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| 10300 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10301 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10302 |
return Res; |
| 10303 |
} |
| 10304 |
|
| 10305 |
template <typename Derived> |
| 10306 |
StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( |
| 10307 |
OMPTeamsDistributeSimdDirective *D) { |
| 10308 |
DeclarationNameInfo DirName; |
| 10309 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10310 |
OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| 10311 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10312 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10313 |
return Res; |
| 10314 |
} |
| 10315 |
|
| 10316 |
template <typename Derived> |
| 10317 |
StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( |
| 10318 |
OMPTeamsDistributeParallelForSimdDirective *D) { |
| 10319 |
DeclarationNameInfo DirName; |
| 10320 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10321 |
OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 10322 |
D->getBeginLoc()); |
| 10323 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10324 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10325 |
return Res; |
| 10326 |
} |
| 10327 |
|
| 10328 |
template <typename Derived> |
| 10329 |
StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( |
| 10330 |
OMPTeamsDistributeParallelForDirective *D) { |
| 10331 |
DeclarationNameInfo DirName; |
| 10332 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10333 |
OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 10334 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10335 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10336 |
return Res; |
| 10337 |
} |
| 10338 |
|
| 10339 |
template <typename Derived> |
| 10340 |
StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( |
| 10341 |
OMPTargetTeamsDirective *D) { |
| 10342 |
DeclarationNameInfo DirName; |
| 10343 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10344 |
OMPD_target_teams, DirName, nullptr, D->getBeginLoc()); |
| 10345 |
auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 10346 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10347 |
return Res; |
| 10348 |
} |
| 10349 |
|
| 10350 |
template <typename Derived> |
| 10351 |
StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( |
| 10352 |
OMPTargetTeamsDistributeDirective *D) { |
| 10353 |
DeclarationNameInfo DirName; |
| 10354 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10355 |
OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| 10356 |
auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 10357 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10358 |
return Res; |
| 10359 |
} |
| 10360 |
|
| 10361 |
template <typename Derived> |
| 10362 |
StmtResult |
| 10363 |
TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( |
| 10364 |
OMPTargetTeamsDistributeParallelForDirective *D) { |
| 10365 |
DeclarationNameInfo DirName; |
| 10366 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10367 |
OMPD_target_teams_distribute_parallel_for, DirName, nullptr, |
| 10368 |
D->getBeginLoc()); |
| 10369 |
auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 10370 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10371 |
return Res; |
| 10372 |
} |
| 10373 |
|
| 10374 |
template <typename Derived> |
| 10375 |
StmtResult TreeTransform<Derived>:: |
| 10376 |
TransformOMPTargetTeamsDistributeParallelForSimdDirective( |
| 10377 |
OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 10378 |
DeclarationNameInfo DirName; |
| 10379 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10380 |
OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 10381 |
D->getBeginLoc()); |
| 10382 |
auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 10383 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10384 |
return Res; |
| 10385 |
} |
| 10386 |
|
| 10387 |
template <typename Derived> |
| 10388 |
StmtResult |
| 10389 |
TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( |
| 10390 |
OMPTargetTeamsDistributeSimdDirective *D) { |
| 10391 |
DeclarationNameInfo DirName; |
| 10392 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10393 |
OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| 10394 |
auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 10395 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10396 |
return Res; |
| 10397 |
} |
| 10398 |
|
| 10399 |
template <typename Derived> |
| 10400 |
StmtResult |
| 10401 |
TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) { |
| 10402 |
DeclarationNameInfo DirName; |
| 10403 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10404 |
OMPD_interop, DirName, nullptr, D->getBeginLoc()); |
| 10405 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10406 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10407 |
return Res; |
| 10408 |
} |
| 10409 |
|
| 10410 |
template <typename Derived> |
| 10411 |
StmtResult |
| 10412 |
TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) { |
| 10413 |
DeclarationNameInfo DirName; |
| 10414 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10415 |
OMPD_dispatch, DirName, nullptr, D->getBeginLoc()); |
| 10416 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10417 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10418 |
return Res; |
| 10419 |
} |
| 10420 |
|
| 10421 |
template <typename Derived> |
| 10422 |
StmtResult |
| 10423 |
TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) { |
| 10424 |
DeclarationNameInfo DirName; |
| 10425 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10426 |
OMPD_masked, DirName, nullptr, D->getBeginLoc()); |
| 10427 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10428 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10429 |
return Res; |
| 10430 |
} |
| 10431 |
|
| 10432 |
template <typename Derived> |
| 10433 |
StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective( |
| 10434 |
OMPGenericLoopDirective *D) { |
| 10435 |
DeclarationNameInfo DirName; |
| 10436 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10437 |
OMPD_loop, DirName, nullptr, D->getBeginLoc()); |
| 10438 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10439 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10440 |
return Res; |
| 10441 |
} |
| 10442 |
|
| 10443 |
template <typename Derived> |
| 10444 |
StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective( |
| 10445 |
OMPTeamsGenericLoopDirective *D) { |
| 10446 |
DeclarationNameInfo DirName; |
| 10447 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10448 |
OMPD_teams_loop, DirName, nullptr, D->getBeginLoc()); |
| 10449 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10450 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10451 |
return Res; |
| 10452 |
} |
| 10453 |
|
| 10454 |
template <typename Derived> |
| 10455 |
StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective( |
| 10456 |
OMPTargetTeamsGenericLoopDirective *D) { |
| 10457 |
DeclarationNameInfo DirName; |
| 10458 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10459 |
OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc()); |
| 10460 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10461 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10462 |
return Res; |
| 10463 |
} |
| 10464 |
|
| 10465 |
template <typename Derived> |
| 10466 |
StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective( |
| 10467 |
OMPParallelGenericLoopDirective *D) { |
| 10468 |
DeclarationNameInfo DirName; |
| 10469 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10470 |
OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc()); |
| 10471 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10472 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10473 |
return Res; |
| 10474 |
} |
| 10475 |
|
| 10476 |
template <typename Derived> |
| 10477 |
StmtResult |
| 10478 |
TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective( |
| 10479 |
OMPTargetParallelGenericLoopDirective *D) { |
| 10480 |
DeclarationNameInfo DirName; |
| 10481 |
getDerived().getSema().OpenMP().StartOpenMPDSABlock( |
| 10482 |
OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc()); |
| 10483 |
StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 10484 |
getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get()); |
| 10485 |
return Res; |
| 10486 |
} |
| 10487 |
|
| 10488 |
//===----------------------------------------------------------------------===// |
| 10489 |
// OpenMP clause transformation |
| 10490 |
//===----------------------------------------------------------------------===// |
| 10491 |
template <typename Derived> |
| 10492 |
OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| 10493 |
ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 10494 |
if (Cond.isInvalid()) |
| 10495 |
return nullptr; |
| 10496 |
return getDerived().RebuildOMPIfClause( |
| 10497 |
C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 10498 |
C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| 10499 |
} |
| 10500 |
|
| 10501 |
template <typename Derived> |
| 10502 |
OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 10503 |
ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 10504 |
if (Cond.isInvalid()) |
| 10505 |
return nullptr; |
| 10506 |
return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), |
| 10507 |
C->getLParenLoc(), C->getEndLoc()); |
| 10508 |
} |
| 10509 |
|
| 10510 |
template <typename Derived> |
| 10511 |
OMPClause * |
| 10512 |
TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 10513 |
ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 10514 |
if (NumThreads.isInvalid()) |
| 10515 |
return nullptr; |
| 10516 |
return getDerived().RebuildOMPNumThreadsClause( |
| 10517 |
C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 10518 |
C->getModifierLoc(), C->getEndLoc()); |
| 10519 |
} |
| 10520 |
|
| 10521 |
template <typename Derived> |
| 10522 |
OMPClause * |
| 10523 |
TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 10524 |
ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 10525 |
if (E.isInvalid()) |
| 10526 |
return nullptr; |
| 10527 |
return getDerived().RebuildOMPSafelenClause( |
| 10528 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10529 |
} |
| 10530 |
|
| 10531 |
template <typename Derived> |
| 10532 |
OMPClause * |
| 10533 |
TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { |
| 10534 |
ExprResult E = getDerived().TransformExpr(C->getAllocator()); |
| 10535 |
if (E.isInvalid()) |
| 10536 |
return nullptr; |
| 10537 |
return getDerived().RebuildOMPAllocatorClause( |
| 10538 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10539 |
} |
| 10540 |
|
| 10541 |
template <typename Derived> |
| 10542 |
OMPClause * |
| 10543 |
TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 10544 |
ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 10545 |
if (E.isInvalid()) |
| 10546 |
return nullptr; |
| 10547 |
return getDerived().RebuildOMPSimdlenClause( |
| 10548 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10549 |
} |
| 10550 |
|
| 10551 |
template <typename Derived> |
| 10552 |
OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) { |
| 10553 |
SmallVector<Expr *, 4> TransformedSizes; |
| 10554 |
TransformedSizes.reserve(C->getNumSizes()); |
| 10555 |
bool Changed = false; |
| 10556 |
for (Expr *E : C->getSizesRefs()) { |
| 10557 |
if (!E) { |
| 10558 |
TransformedSizes.push_back(nullptr); |
| 10559 |
continue; |
| 10560 |
} |
| 10561 |
|
| 10562 |
ExprResult T = getDerived().TransformExpr(E); |
| 10563 |
if (T.isInvalid()) |
| 10564 |
return nullptr; |
| 10565 |
if (E != T.get()) |
| 10566 |
Changed = true; |
| 10567 |
TransformedSizes.push_back(T.get()); |
| 10568 |
} |
| 10569 |
|
| 10570 |
if (!Changed && !getDerived().AlwaysRebuild()) |
| 10571 |
return C; |
| 10572 |
return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(), |
| 10573 |
C->getLParenLoc(), C->getEndLoc()); |
| 10574 |
} |
| 10575 |
|
| 10576 |
template <typename Derived> |
| 10577 |
OMPClause * |
| 10578 |
TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) { |
| 10579 |
SmallVector<Expr *> TransformedArgs; |
| 10580 |
TransformedArgs.reserve(C->getNumLoops()); |
| 10581 |
bool Changed = false; |
| 10582 |
for (Expr *E : C->getArgsRefs()) { |
| 10583 |
if (!E) { |
| 10584 |
TransformedArgs.push_back(nullptr); |
| 10585 |
continue; |
| 10586 |
} |
| 10587 |
|
| 10588 |
ExprResult T = getDerived().TransformExpr(E); |
| 10589 |
if (T.isInvalid()) |
| 10590 |
return nullptr; |
| 10591 |
if (E != T.get()) |
| 10592 |
Changed = true; |
| 10593 |
TransformedArgs.push_back(T.get()); |
| 10594 |
} |
| 10595 |
|
| 10596 |
if (!Changed && !getDerived().AlwaysRebuild()) |
| 10597 |
return C; |
| 10598 |
return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(), |
| 10599 |
C->getLParenLoc(), C->getEndLoc()); |
| 10600 |
} |
| 10601 |
|
| 10602 |
template <typename Derived> |
| 10603 |
OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) { |
| 10604 |
if (!getDerived().AlwaysRebuild()) |
| 10605 |
return C; |
| 10606 |
return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc()); |
| 10607 |
} |
| 10608 |
|
| 10609 |
template <typename Derived> |
| 10610 |
OMPClause * |
| 10611 |
TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) { |
| 10612 |
ExprResult T = getDerived().TransformExpr(C->getFactor()); |
| 10613 |
if (T.isInvalid()) |
| 10614 |
return nullptr; |
| 10615 |
Expr *Factor = T.get(); |
| 10616 |
bool Changed = Factor != C->getFactor(); |
| 10617 |
|
| 10618 |
if (!Changed && !getDerived().AlwaysRebuild()) |
| 10619 |
return C; |
| 10620 |
return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(), |
| 10621 |
C->getEndLoc()); |
| 10622 |
} |
| 10623 |
|
| 10624 |
template <typename Derived> |
| 10625 |
OMPClause * |
| 10626 |
TreeTransform<Derived>::TransformOMPLoopRangeClause(OMPLoopRangeClause *C) { |
| 10627 |
ExprResult F = getDerived().TransformExpr(C->getFirst()); |
| 10628 |
if (F.isInvalid()) |
| 10629 |
return nullptr; |
| 10630 |
|
| 10631 |
ExprResult Cn = getDerived().TransformExpr(C->getCount()); |
| 10632 |
if (Cn.isInvalid()) |
| 10633 |
return nullptr; |
| 10634 |
|
| 10635 |
Expr *First = F.get(); |
| 10636 |
Expr *Count = Cn.get(); |
| 10637 |
|
| 10638 |
bool Changed = (First != C->getFirst()) || (Count != C->getCount()); |
| 10639 |
|
| 10640 |
// If no changes and AlwaysRebuild() is false, return the original clause |
| 10641 |
if (!Changed && !getDerived().AlwaysRebuild()) |
| 10642 |
return C; |
| 10643 |
|
| 10644 |
return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(), |
| 10645 |
C->getLParenLoc(), C->getFirstLoc(), |
| 10646 |
C->getCountLoc(), C->getEndLoc()); |
| 10647 |
} |
| 10648 |
|
| 10649 |
template <typename Derived> |
| 10650 |
OMPClause * |
| 10651 |
TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 10652 |
ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 10653 |
if (E.isInvalid()) |
| 10654 |
return nullptr; |
| 10655 |
return getDerived().RebuildOMPCollapseClause( |
| 10656 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10657 |
} |
| 10658 |
|
| 10659 |
template <typename Derived> |
| 10660 |
OMPClause * |
| 10661 |
TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 10662 |
return getDerived().RebuildOMPDefaultClause( |
| 10663 |
C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(), |
| 10664 |
C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(), |
| 10665 |
C->getEndLoc()); |
| 10666 |
} |
| 10667 |
|
| 10668 |
template <typename Derived> |
| 10669 |
OMPClause * |
| 10670 |
TreeTransform<Derived>::TransformOMPThreadsetClause(OMPThreadsetClause *C) { |
| 10671 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10672 |
return C; |
| 10673 |
} |
| 10674 |
|
| 10675 |
template <typename Derived> |
| 10676 |
OMPClause * |
| 10677 |
TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
| 10678 |
return getDerived().RebuildOMPProcBindClause( |
| 10679 |
C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), |
| 10680 |
C->getLParenLoc(), C->getEndLoc()); |
| 10681 |
} |
| 10682 |
|
| 10683 |
template <typename Derived> |
| 10684 |
OMPClause * |
| 10685 |
TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 10686 |
ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 10687 |
if (E.isInvalid()) |
| 10688 |
return nullptr; |
| 10689 |
return getDerived().RebuildOMPScheduleClause( |
| 10690 |
C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
| 10691 |
C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 10692 |
C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
| 10693 |
C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| 10694 |
} |
| 10695 |
|
| 10696 |
template <typename Derived> |
| 10697 |
OMPClause * |
| 10698 |
TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| 10699 |
ExprResult E; |
| 10700 |
if (auto *Num = C->getNumForLoops()) { |
| 10701 |
E = getDerived().TransformExpr(Num); |
| 10702 |
if (E.isInvalid()) |
| 10703 |
return nullptr; |
| 10704 |
} |
| 10705 |
return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), |
| 10706 |
C->getLParenLoc(), E.get()); |
| 10707 |
} |
| 10708 |
|
| 10709 |
template <typename Derived> |
| 10710 |
OMPClause * |
| 10711 |
TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) { |
| 10712 |
ExprResult E; |
| 10713 |
if (Expr *Evt = C->getEventHandler()) { |
| 10714 |
E = getDerived().TransformExpr(Evt); |
| 10715 |
if (E.isInvalid()) |
| 10716 |
return nullptr; |
| 10717 |
} |
| 10718 |
return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(), |
| 10719 |
C->getLParenLoc(), C->getEndLoc()); |
| 10720 |
} |
| 10721 |
|
| 10722 |
template <typename Derived> |
| 10723 |
OMPClause * |
| 10724 |
TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 10725 |
ExprResult Cond; |
| 10726 |
if (auto *Condition = C->getCondition()) { |
| 10727 |
Cond = getDerived().TransformExpr(Condition); |
| 10728 |
if (Cond.isInvalid()) |
| 10729 |
return nullptr; |
| 10730 |
} |
| 10731 |
return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(), |
| 10732 |
C->getLParenLoc(), C->getEndLoc()); |
| 10733 |
} |
| 10734 |
|
| 10735 |
template <typename Derived> |
| 10736 |
OMPClause * |
| 10737 |
TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 10738 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10739 |
return C; |
| 10740 |
} |
| 10741 |
|
| 10742 |
template <typename Derived> |
| 10743 |
OMPClause * |
| 10744 |
TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 10745 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10746 |
return C; |
| 10747 |
} |
| 10748 |
|
| 10749 |
template <typename Derived> |
| 10750 |
OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 10751 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10752 |
return C; |
| 10753 |
} |
| 10754 |
|
| 10755 |
template <typename Derived> |
| 10756 |
OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 10757 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10758 |
return C; |
| 10759 |
} |
| 10760 |
|
| 10761 |
template <typename Derived> |
| 10762 |
OMPClause * |
| 10763 |
TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 10764 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10765 |
return C; |
| 10766 |
} |
| 10767 |
|
| 10768 |
template <typename Derived> |
| 10769 |
OMPClause * |
| 10770 |
TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 10771 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10772 |
return C; |
| 10773 |
} |
| 10774 |
|
| 10775 |
template <typename Derived> |
| 10776 |
OMPClause * |
| 10777 |
TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) { |
| 10778 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10779 |
return C; |
| 10780 |
} |
| 10781 |
|
| 10782 |
template <typename Derived> |
| 10783 |
OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) { |
| 10784 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10785 |
return C; |
| 10786 |
} |
| 10787 |
|
| 10788 |
template <typename Derived> |
| 10789 |
OMPClause * |
| 10790 |
TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) { |
| 10791 |
return C; |
| 10792 |
} |
| 10793 |
|
| 10794 |
template <typename Derived> |
| 10795 |
OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) { |
| 10796 |
ExprResult E = getDerived().TransformExpr(C->getExpr()); |
| 10797 |
if (E.isInvalid()) |
| 10798 |
return nullptr; |
| 10799 |
return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(), |
| 10800 |
C->getLParenLoc(), C->getEndLoc()); |
| 10801 |
} |
| 10802 |
|
| 10803 |
template <typename Derived> |
| 10804 |
OMPClause * |
| 10805 |
TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) { |
| 10806 |
return C; |
| 10807 |
} |
| 10808 |
|
| 10809 |
template <typename Derived> |
| 10810 |
OMPClause * |
| 10811 |
TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) { |
| 10812 |
return C; |
| 10813 |
} |
| 10814 |
template <typename Derived> |
| 10815 |
OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause( |
| 10816 |
OMPNoOpenMPRoutinesClause *C) { |
| 10817 |
return C; |
| 10818 |
} |
| 10819 |
template <typename Derived> |
| 10820 |
OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPConstructsClause( |
| 10821 |
OMPNoOpenMPConstructsClause *C) { |
| 10822 |
return C; |
| 10823 |
} |
| 10824 |
template <typename Derived> |
| 10825 |
OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause( |
| 10826 |
OMPNoParallelismClause *C) { |
| 10827 |
return C; |
| 10828 |
} |
| 10829 |
|
| 10830 |
template <typename Derived> |
| 10831 |
OMPClause * |
| 10832 |
TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 10833 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10834 |
return C; |
| 10835 |
} |
| 10836 |
|
| 10837 |
template <typename Derived> |
| 10838 |
OMPClause * |
| 10839 |
TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) { |
| 10840 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10841 |
return C; |
| 10842 |
} |
| 10843 |
|
| 10844 |
template <typename Derived> |
| 10845 |
OMPClause * |
| 10846 |
TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) { |
| 10847 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10848 |
return C; |
| 10849 |
} |
| 10850 |
|
| 10851 |
template <typename Derived> |
| 10852 |
OMPClause * |
| 10853 |
TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) { |
| 10854 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10855 |
return C; |
| 10856 |
} |
| 10857 |
|
| 10858 |
template <typename Derived> |
| 10859 |
OMPClause * |
| 10860 |
TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) { |
| 10861 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10862 |
return C; |
| 10863 |
} |
| 10864 |
|
| 10865 |
template <typename Derived> |
| 10866 |
OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) { |
| 10867 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10868 |
return C; |
| 10869 |
} |
| 10870 |
|
| 10871 |
template <typename Derived> |
| 10872 |
OMPClause * |
| 10873 |
TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 10874 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10875 |
return C; |
| 10876 |
} |
| 10877 |
|
| 10878 |
template <typename Derived> |
| 10879 |
OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 10880 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10881 |
return C; |
| 10882 |
} |
| 10883 |
|
| 10884 |
template <typename Derived> |
| 10885 |
OMPClause * |
| 10886 |
TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 10887 |
// No need to rebuild this clause, no template-dependent parameters. |
| 10888 |
return C; |
| 10889 |
} |
| 10890 |
|
| 10891 |
template <typename Derived> |
| 10892 |
OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) { |
| 10893 |
ExprResult IVR = getDerived().TransformExpr(C->getInteropVar()); |
| 10894 |
if (IVR.isInvalid()) |
| 10895 |
return nullptr; |
| 10896 |
|
| 10897 |
OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync()); |
| 10898 |
InteropInfo.PreferTypes.reserve(C->varlist_size() - 1); |
| 10899 |
for (Expr *E : llvm::drop_begin(C->varlist())) { |
| 10900 |
ExprResult ER = getDerived().TransformExpr(cast<Expr>(E)); |
| 10901 |
if (ER.isInvalid()) |
| 10902 |
return nullptr; |
| 10903 |
InteropInfo.PreferTypes.push_back(ER.get()); |
| 10904 |
} |
| 10905 |
return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo, |
| 10906 |
C->getBeginLoc(), C->getLParenLoc(), |
| 10907 |
C->getVarLoc(), C->getEndLoc()); |
| 10908 |
} |
| 10909 |
|
| 10910 |
template <typename Derived> |
| 10911 |
OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) { |
| 10912 |
ExprResult ER = getDerived().TransformExpr(C->getInteropVar()); |
| 10913 |
if (ER.isInvalid()) |
| 10914 |
return nullptr; |
| 10915 |
return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(), |
| 10916 |
C->getLParenLoc(), C->getVarLoc(), |
| 10917 |
C->getEndLoc()); |
| 10918 |
} |
| 10919 |
|
| 10920 |
template <typename Derived> |
| 10921 |
OMPClause * |
| 10922 |
TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) { |
| 10923 |
ExprResult ER; |
| 10924 |
if (Expr *IV = C->getInteropVar()) { |
| 10925 |
ER = getDerived().TransformExpr(IV); |
| 10926 |
if (ER.isInvalid()) |
| 10927 |
return nullptr; |
| 10928 |
} |
| 10929 |
return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(), |
| 10930 |
C->getLParenLoc(), C->getVarLoc(), |
| 10931 |
C->getEndLoc()); |
| 10932 |
} |
| 10933 |
|
| 10934 |
template <typename Derived> |
| 10935 |
OMPClause * |
| 10936 |
TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) { |
| 10937 |
ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 10938 |
if (Cond.isInvalid()) |
| 10939 |
return nullptr; |
| 10940 |
return getDerived().RebuildOMPNovariantsClause( |
| 10941 |
Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10942 |
} |
| 10943 |
|
| 10944 |
template <typename Derived> |
| 10945 |
OMPClause * |
| 10946 |
TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) { |
| 10947 |
ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 10948 |
if (Cond.isInvalid()) |
| 10949 |
return nullptr; |
| 10950 |
return getDerived().RebuildOMPNocontextClause( |
| 10951 |
Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 10952 |
} |
| 10953 |
|
| 10954 |
template <typename Derived> |
| 10955 |
OMPClause * |
| 10956 |
TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) { |
| 10957 |
ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID()); |
| 10958 |
if (ThreadID.isInvalid()) |
| 10959 |
return nullptr; |
| 10960 |
return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(), |
| 10961 |
C->getLParenLoc(), C->getEndLoc()); |
| 10962 |
} |
| 10963 |
|
| 10964 |
template <typename Derived> |
| 10965 |
OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) { |
| 10966 |
ExprResult E = getDerived().TransformExpr(C->getAlignment()); |
| 10967 |
if (E.isInvalid()) |
| 10968 |
return nullptr; |
| 10969 |
return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(), |
| 10970 |
C->getLParenLoc(), C->getEndLoc()); |
| 10971 |
} |
| 10972 |
|
| 10973 |
template <typename Derived> |
| 10974 |
OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( |
| 10975 |
OMPUnifiedAddressClause *C) { |
| 10976 |
llvm_unreachable("unified_address clause cannot appear in dependent context"); |
| 10977 |
} |
| 10978 |
|
| 10979 |
template <typename Derived> |
| 10980 |
OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( |
| 10981 |
OMPUnifiedSharedMemoryClause *C) { |
| 10982 |
llvm_unreachable( |
| 10983 |
"unified_shared_memory clause cannot appear in dependent context"); |
| 10984 |
} |
| 10985 |
|
| 10986 |
template <typename Derived> |
| 10987 |
OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( |
| 10988 |
OMPReverseOffloadClause *C) { |
| 10989 |
llvm_unreachable("reverse_offload clause cannot appear in dependent context"); |
| 10990 |
} |
| 10991 |
|
| 10992 |
template <typename Derived> |
| 10993 |
OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( |
| 10994 |
OMPDynamicAllocatorsClause *C) { |
| 10995 |
llvm_unreachable( |
| 10996 |
"dynamic_allocators clause cannot appear in dependent context"); |
| 10997 |
} |
| 10998 |
|
| 10999 |
template <typename Derived> |
| 11000 |
OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( |
| 11001 |
OMPAtomicDefaultMemOrderClause *C) { |
| 11002 |
llvm_unreachable( |
| 11003 |
"atomic_default_mem_order clause cannot appear in dependent context"); |
| 11004 |
} |
| 11005 |
|
| 11006 |
template <typename Derived> |
| 11007 |
OMPClause * |
| 11008 |
TreeTransform<Derived>::TransformOMPSelfMapsClause(OMPSelfMapsClause *C) { |
| 11009 |
llvm_unreachable("self_maps clause cannot appear in dependent context"); |
| 11010 |
} |
| 11011 |
|
| 11012 |
template <typename Derived> |
| 11013 |
OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) { |
| 11014 |
return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(), |
| 11015 |
C->getBeginLoc(), C->getLParenLoc(), |
| 11016 |
C->getEndLoc()); |
| 11017 |
} |
| 11018 |
|
| 11019 |
template <typename Derived> |
| 11020 |
OMPClause * |
| 11021 |
TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) { |
| 11022 |
return getDerived().RebuildOMPSeverityClause( |
| 11023 |
C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(), |
| 11024 |
C->getLParenLoc(), C->getEndLoc()); |
| 11025 |
} |
| 11026 |
|
| 11027 |
template <typename Derived> |
| 11028 |
OMPClause * |
| 11029 |
TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) { |
| 11030 |
ExprResult E = getDerived().TransformExpr(C->getMessageString()); |
| 11031 |
if (E.isInvalid()) |
| 11032 |
return nullptr; |
| 11033 |
return getDerived().RebuildOMPMessageClause( |
| 11034 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11035 |
} |
| 11036 |
|
| 11037 |
template <typename Derived> |
| 11038 |
OMPClause * |
| 11039 |
TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| 11040 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11041 |
Vars.reserve(C->varlist_size()); |
| 11042 |
for (auto *VE : C->varlist()) { |
| 11043 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11044 |
if (EVar.isInvalid()) |
| 11045 |
return nullptr; |
| 11046 |
Vars.push_back(EVar.get()); |
| 11047 |
} |
| 11048 |
return getDerived().RebuildOMPPrivateClause( |
| 11049 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11050 |
} |
| 11051 |
|
| 11052 |
template <typename Derived> |
| 11053 |
OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 11054 |
OMPFirstprivateClause *C) { |
| 11055 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11056 |
Vars.reserve(C->varlist_size()); |
| 11057 |
for (auto *VE : C->varlist()) { |
| 11058 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11059 |
if (EVar.isInvalid()) |
| 11060 |
return nullptr; |
| 11061 |
Vars.push_back(EVar.get()); |
| 11062 |
} |
| 11063 |
return getDerived().RebuildOMPFirstprivateClause( |
| 11064 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11065 |
} |
| 11066 |
|
| 11067 |
template <typename Derived> |
| 11068 |
OMPClause * |
| 11069 |
TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 11070 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11071 |
Vars.reserve(C->varlist_size()); |
| 11072 |
for (auto *VE : C->varlist()) { |
| 11073 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11074 |
if (EVar.isInvalid()) |
| 11075 |
return nullptr; |
| 11076 |
Vars.push_back(EVar.get()); |
| 11077 |
} |
| 11078 |
return getDerived().RebuildOMPLastprivateClause( |
| 11079 |
Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(), |
| 11080 |
C->getLParenLoc(), C->getEndLoc()); |
| 11081 |
} |
| 11082 |
|
| 11083 |
template <typename Derived> |
| 11084 |
OMPClause * |
| 11085 |
TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 11086 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11087 |
Vars.reserve(C->varlist_size()); |
| 11088 |
for (auto *VE : C->varlist()) { |
| 11089 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11090 |
if (EVar.isInvalid()) |
| 11091 |
return nullptr; |
| 11092 |
Vars.push_back(EVar.get()); |
| 11093 |
} |
| 11094 |
return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), |
| 11095 |
C->getLParenLoc(), C->getEndLoc()); |
| 11096 |
} |
| 11097 |
|
| 11098 |
template <typename Derived> |
| 11099 |
OMPClause * |
| 11100 |
TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 11101 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11102 |
Vars.reserve(C->varlist_size()); |
| 11103 |
for (auto *VE : C->varlist()) { |
| 11104 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11105 |
if (EVar.isInvalid()) |
| 11106 |
return nullptr; |
| 11107 |
Vars.push_back(EVar.get()); |
| 11108 |
} |
| 11109 |
CXXScopeSpec ReductionIdScopeSpec; |
| 11110 |
ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 11111 |
|
| 11112 |
DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 11113 |
if (NameInfo.getName()) { |
| 11114 |
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 11115 |
if (!NameInfo.getName()) |
| 11116 |
return nullptr; |
| 11117 |
} |
| 11118 |
// Build a list of all UDR decls with the same names ranged by the Scopes. |
| 11119 |
// The Scope boundary is a duplication of the previous decl. |
| 11120 |
llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 11121 |
for (auto *E : C->reduction_ops()) { |
| 11122 |
// Transform all the decls. |
| 11123 |
if (E) { |
| 11124 |
auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 11125 |
UnresolvedSet<8> Decls; |
| 11126 |
for (auto *D : ULE->decls()) { |
| 11127 |
NamedDecl *InstD = |
| 11128 |
cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 11129 |
Decls.addDecl(InstD, InstD->getAccess()); |
| 11130 |
} |
| 11131 |
UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 11132 |
SemaRef.Context, /*NamingClass=*/nullptr, |
| 11133 |
ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 11134 |
/*ADL=*/true, Decls.begin(), Decls.end(), |
| 11135 |
/*KnownDependent=*/false, /*KnownInstantiationDependent=*/false)); |
| 11136 |
} else |
| 11137 |
UnresolvedReductions.push_back(nullptr); |
| 11138 |
} |
| 11139 |
return getDerived().RebuildOMPReductionClause( |
| 11140 |
Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(), |
| 11141 |
C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(), |
| 11142 |
ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 11143 |
} |
| 11144 |
|
| 11145 |
template <typename Derived> |
| 11146 |
OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( |
| 11147 |
OMPTaskReductionClause *C) { |
| 11148 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11149 |
Vars.reserve(C->varlist_size()); |
| 11150 |
for (auto *VE : C->varlist()) { |
| 11151 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11152 |
if (EVar.isInvalid()) |
| 11153 |
return nullptr; |
| 11154 |
Vars.push_back(EVar.get()); |
| 11155 |
} |
| 11156 |
CXXScopeSpec ReductionIdScopeSpec; |
| 11157 |
ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 11158 |
|
| 11159 |
DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 11160 |
if (NameInfo.getName()) { |
| 11161 |
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 11162 |
if (!NameInfo.getName()) |
| 11163 |
return nullptr; |
| 11164 |
} |
| 11165 |
// Build a list of all UDR decls with the same names ranged by the Scopes. |
| 11166 |
// The Scope boundary is a duplication of the previous decl. |
| 11167 |
llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 11168 |
for (auto *E : C->reduction_ops()) { |
| 11169 |
// Transform all the decls. |
| 11170 |
if (E) { |
| 11171 |
auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 11172 |
UnresolvedSet<8> Decls; |
| 11173 |
for (auto *D : ULE->decls()) { |
| 11174 |
NamedDecl *InstD = |
| 11175 |
cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 11176 |
Decls.addDecl(InstD, InstD->getAccess()); |
| 11177 |
} |
| 11178 |
UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 11179 |
SemaRef.Context, /*NamingClass=*/nullptr, |
| 11180 |
ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 11181 |
/*ADL=*/true, Decls.begin(), Decls.end(), |
| 11182 |
/*KnownDependent=*/false, /*KnownInstantiationDependent=*/false)); |
| 11183 |
} else |
| 11184 |
UnresolvedReductions.push_back(nullptr); |
| 11185 |
} |
| 11186 |
return getDerived().RebuildOMPTaskReductionClause( |
| 11187 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 11188 |
C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 11189 |
} |
| 11190 |
|
| 11191 |
template <typename Derived> |
| 11192 |
OMPClause * |
| 11193 |
TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { |
| 11194 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11195 |
Vars.reserve(C->varlist_size()); |
| 11196 |
for (auto *VE : C->varlist()) { |
| 11197 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11198 |
if (EVar.isInvalid()) |
| 11199 |
return nullptr; |
| 11200 |
Vars.push_back(EVar.get()); |
| 11201 |
} |
| 11202 |
CXXScopeSpec ReductionIdScopeSpec; |
| 11203 |
ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 11204 |
|
| 11205 |
DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 11206 |
if (NameInfo.getName()) { |
| 11207 |
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 11208 |
if (!NameInfo.getName()) |
| 11209 |
return nullptr; |
| 11210 |
} |
| 11211 |
// Build a list of all UDR decls with the same names ranged by the Scopes. |
| 11212 |
// The Scope boundary is a duplication of the previous decl. |
| 11213 |
llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 11214 |
for (auto *E : C->reduction_ops()) { |
| 11215 |
// Transform all the decls. |
| 11216 |
if (E) { |
| 11217 |
auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 11218 |
UnresolvedSet<8> Decls; |
| 11219 |
for (auto *D : ULE->decls()) { |
| 11220 |
NamedDecl *InstD = |
| 11221 |
cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 11222 |
Decls.addDecl(InstD, InstD->getAccess()); |
| 11223 |
} |
| 11224 |
UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 11225 |
SemaRef.Context, /*NamingClass=*/nullptr, |
| 11226 |
ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 11227 |
/*ADL=*/true, Decls.begin(), Decls.end(), |
| 11228 |
/*KnownDependent=*/false, /*KnownInstantiationDependent=*/false)); |
| 11229 |
} else |
| 11230 |
UnresolvedReductions.push_back(nullptr); |
| 11231 |
} |
| 11232 |
return getDerived().RebuildOMPInReductionClause( |
| 11233 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 11234 |
C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 11235 |
} |
| 11236 |
|
| 11237 |
template <typename Derived> |
| 11238 |
OMPClause * |
| 11239 |
TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 11240 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11241 |
Vars.reserve(C->varlist_size()); |
| 11242 |
for (auto *VE : C->varlist()) { |
| 11243 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11244 |
if (EVar.isInvalid()) |
| 11245 |
return nullptr; |
| 11246 |
Vars.push_back(EVar.get()); |
| 11247 |
} |
| 11248 |
ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 11249 |
if (Step.isInvalid()) |
| 11250 |
return nullptr; |
| 11251 |
return getDerived().RebuildOMPLinearClause( |
| 11252 |
Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), |
| 11253 |
C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(), |
| 11254 |
C->getEndLoc()); |
| 11255 |
} |
| 11256 |
|
| 11257 |
template <typename Derived> |
| 11258 |
OMPClause * |
| 11259 |
TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 11260 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11261 |
Vars.reserve(C->varlist_size()); |
| 11262 |
for (auto *VE : C->varlist()) { |
| 11263 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11264 |
if (EVar.isInvalid()) |
| 11265 |
return nullptr; |
| 11266 |
Vars.push_back(EVar.get()); |
| 11267 |
} |
| 11268 |
ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 11269 |
if (Alignment.isInvalid()) |
| 11270 |
return nullptr; |
| 11271 |
return getDerived().RebuildOMPAlignedClause( |
| 11272 |
Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11273 |
C->getColonLoc(), C->getEndLoc()); |
| 11274 |
} |
| 11275 |
|
| 11276 |
template <typename Derived> |
| 11277 |
OMPClause * |
| 11278 |
TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 11279 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11280 |
Vars.reserve(C->varlist_size()); |
| 11281 |
for (auto *VE : C->varlist()) { |
| 11282 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11283 |
if (EVar.isInvalid()) |
| 11284 |
return nullptr; |
| 11285 |
Vars.push_back(EVar.get()); |
| 11286 |
} |
| 11287 |
return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), |
| 11288 |
C->getLParenLoc(), C->getEndLoc()); |
| 11289 |
} |
| 11290 |
|
| 11291 |
template <typename Derived> |
| 11292 |
OMPClause * |
| 11293 |
TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 11294 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11295 |
Vars.reserve(C->varlist_size()); |
| 11296 |
for (auto *VE : C->varlist()) { |
| 11297 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11298 |
if (EVar.isInvalid()) |
| 11299 |
return nullptr; |
| 11300 |
Vars.push_back(EVar.get()); |
| 11301 |
} |
| 11302 |
return getDerived().RebuildOMPCopyprivateClause( |
| 11303 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11304 |
} |
| 11305 |
|
| 11306 |
template <typename Derived> |
| 11307 |
OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 11308 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11309 |
Vars.reserve(C->varlist_size()); |
| 11310 |
for (auto *VE : C->varlist()) { |
| 11311 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11312 |
if (EVar.isInvalid()) |
| 11313 |
return nullptr; |
| 11314 |
Vars.push_back(EVar.get()); |
| 11315 |
} |
| 11316 |
return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), |
| 11317 |
C->getLParenLoc(), C->getEndLoc()); |
| 11318 |
} |
| 11319 |
|
| 11320 |
template <typename Derived> |
| 11321 |
OMPClause * |
| 11322 |
TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) { |
| 11323 |
ExprResult E = getDerived().TransformExpr(C->getDepobj()); |
| 11324 |
if (E.isInvalid()) |
| 11325 |
return nullptr; |
| 11326 |
return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(), |
| 11327 |
C->getLParenLoc(), C->getEndLoc()); |
| 11328 |
} |
| 11329 |
|
| 11330 |
template <typename Derived> |
| 11331 |
OMPClause * |
| 11332 |
TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 11333 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11334 |
Expr *DepModifier = C->getModifier(); |
| 11335 |
if (DepModifier) { |
| 11336 |
ExprResult DepModRes = getDerived().TransformExpr(DepModifier); |
| 11337 |
if (DepModRes.isInvalid()) |
| 11338 |
return nullptr; |
| 11339 |
DepModifier = DepModRes.get(); |
| 11340 |
} |
| 11341 |
Vars.reserve(C->varlist_size()); |
| 11342 |
for (auto *VE : C->varlist()) { |
| 11343 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11344 |
if (EVar.isInvalid()) |
| 11345 |
return nullptr; |
| 11346 |
Vars.push_back(EVar.get()); |
| 11347 |
} |
| 11348 |
return getDerived().RebuildOMPDependClause( |
| 11349 |
{C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), |
| 11350 |
C->getOmpAllMemoryLoc()}, |
| 11351 |
DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11352 |
} |
| 11353 |
|
| 11354 |
template <typename Derived> |
| 11355 |
OMPClause * |
| 11356 |
TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 11357 |
ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 11358 |
if (E.isInvalid()) |
| 11359 |
return nullptr; |
| 11360 |
return getDerived().RebuildOMPDeviceClause( |
| 11361 |
C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11362 |
C->getModifierLoc(), C->getEndLoc()); |
| 11363 |
} |
| 11364 |
|
| 11365 |
template <typename Derived, class T> |
| 11366 |
bool transformOMPMappableExprListClause( |
| 11367 |
TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, |
| 11368 |
llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, |
| 11369 |
DeclarationNameInfo &MapperIdInfo, |
| 11370 |
llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { |
| 11371 |
// Transform expressions in the list. |
| 11372 |
Vars.reserve(C->varlist_size()); |
| 11373 |
for (auto *VE : C->varlist()) { |
| 11374 |
ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); |
| 11375 |
if (EVar.isInvalid()) |
| 11376 |
return true; |
| 11377 |
Vars.push_back(EVar.get()); |
| 11378 |
} |
| 11379 |
// Transform mapper scope specifier and identifier. |
| 11380 |
NestedNameSpecifierLoc QualifierLoc; |
| 11381 |
if (C->getMapperQualifierLoc()) { |
| 11382 |
QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( |
| 11383 |
C->getMapperQualifierLoc()); |
| 11384 |
if (!QualifierLoc) |
| 11385 |
return true; |
| 11386 |
} |
| 11387 |
MapperIdScopeSpec.Adopt(QualifierLoc); |
| 11388 |
MapperIdInfo = C->getMapperIdInfo(); |
| 11389 |
if (MapperIdInfo.getName()) { |
| 11390 |
MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); |
| 11391 |
if (!MapperIdInfo.getName()) |
| 11392 |
return true; |
| 11393 |
} |
| 11394 |
// Build a list of all candidate OMPDeclareMapperDecls, which is provided by |
| 11395 |
// the previous user-defined mapper lookup in dependent environment. |
| 11396 |
for (auto *E : C->mapperlists()) { |
| 11397 |
// Transform all the decls. |
| 11398 |
if (E) { |
| 11399 |
auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 11400 |
UnresolvedSet<8> Decls; |
| 11401 |
for (auto *D : ULE->decls()) { |
| 11402 |
NamedDecl *InstD = |
| 11403 |
cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); |
| 11404 |
Decls.addDecl(InstD, InstD->getAccess()); |
| 11405 |
} |
| 11406 |
UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( |
| 11407 |
TT.getSema().Context, /*NamingClass=*/nullptr, |
| 11408 |
MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), |
| 11409 |
MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(), |
| 11410 |
/*KnownDependent=*/false, /*KnownInstantiationDependent=*/false)); |
| 11411 |
} else { |
| 11412 |
UnresolvedMappers.push_back(nullptr); |
| 11413 |
} |
| 11414 |
} |
| 11415 |
return false; |
| 11416 |
} |
| 11417 |
|
| 11418 |
template <typename Derived> |
| 11419 |
OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| 11420 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11421 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11422 |
Expr *IteratorModifier = C->getIteratorModifier(); |
| 11423 |
if (IteratorModifier) { |
| 11424 |
ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier); |
| 11425 |
if (MapModRes.isInvalid()) |
| 11426 |
return nullptr; |
| 11427 |
IteratorModifier = MapModRes.get(); |
| 11428 |
} |
| 11429 |
CXXScopeSpec MapperIdScopeSpec; |
| 11430 |
DeclarationNameInfo MapperIdInfo; |
| 11431 |
llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 11432 |
if (transformOMPMappableExprListClause<Derived, OMPMapClause>( |
| 11433 |
*this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 11434 |
return nullptr; |
| 11435 |
return getDerived().RebuildOMPMapClause( |
| 11436 |
IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), |
| 11437 |
MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(), |
| 11438 |
C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| 11439 |
} |
| 11440 |
|
| 11441 |
template <typename Derived> |
| 11442 |
OMPClause * |
| 11443 |
TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { |
| 11444 |
Expr *Allocator = C->getAllocator(); |
| 11445 |
if (Allocator) { |
| 11446 |
ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); |
| 11447 |
if (AllocatorRes.isInvalid()) |
| 11448 |
return nullptr; |
| 11449 |
Allocator = AllocatorRes.get(); |
| 11450 |
} |
| 11451 |
Expr *Alignment = C->getAlignment(); |
| 11452 |
if (Alignment) { |
| 11453 |
ExprResult AlignmentRes = getDerived().TransformExpr(Alignment); |
| 11454 |
if (AlignmentRes.isInvalid()) |
| 11455 |
return nullptr; |
| 11456 |
Alignment = AlignmentRes.get(); |
| 11457 |
} |
| 11458 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11459 |
Vars.reserve(C->varlist_size()); |
| 11460 |
for (auto *VE : C->varlist()) { |
| 11461 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11462 |
if (EVar.isInvalid()) |
| 11463 |
return nullptr; |
| 11464 |
Vars.push_back(EVar.get()); |
| 11465 |
} |
| 11466 |
return getDerived().RebuildOMPAllocateClause( |
| 11467 |
Allocator, Alignment, C->getFirstAllocateModifier(), |
| 11468 |
C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(), |
| 11469 |
C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(), |
| 11470 |
C->getLParenLoc(), C->getColonLoc(), C->getEndLoc()); |
| 11471 |
} |
| 11472 |
|
| 11473 |
template <typename Derived> |
| 11474 |
OMPClause * |
| 11475 |
TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 11476 |
llvm::SmallVector<Expr *, 3> Vars; |
| 11477 |
Vars.reserve(C->varlist_size()); |
| 11478 |
for (auto *VE : C->varlist()) { |
| 11479 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11480 |
if (EVar.isInvalid()) |
| 11481 |
return nullptr; |
| 11482 |
Vars.push_back(EVar.get()); |
| 11483 |
} |
| 11484 |
return getDerived().RebuildOMPNumTeamsClause( |
| 11485 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11486 |
} |
| 11487 |
|
| 11488 |
template <typename Derived> |
| 11489 |
OMPClause * |
| 11490 |
TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 11491 |
llvm::SmallVector<Expr *, 3> Vars; |
| 11492 |
Vars.reserve(C->varlist_size()); |
| 11493 |
for (auto *VE : C->varlist()) { |
| 11494 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11495 |
if (EVar.isInvalid()) |
| 11496 |
return nullptr; |
| 11497 |
Vars.push_back(EVar.get()); |
| 11498 |
} |
| 11499 |
return getDerived().RebuildOMPThreadLimitClause( |
| 11500 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11501 |
} |
| 11502 |
|
| 11503 |
template <typename Derived> |
| 11504 |
OMPClause * |
| 11505 |
TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 11506 |
ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 11507 |
if (E.isInvalid()) |
| 11508 |
return nullptr; |
| 11509 |
return getDerived().RebuildOMPPriorityClause( |
| 11510 |
E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11511 |
} |
| 11512 |
|
| 11513 |
template <typename Derived> |
| 11514 |
OMPClause * |
| 11515 |
TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 11516 |
ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 11517 |
if (E.isInvalid()) |
| 11518 |
return nullptr; |
| 11519 |
return getDerived().RebuildOMPGrainsizeClause( |
| 11520 |
C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11521 |
C->getModifierLoc(), C->getEndLoc()); |
| 11522 |
} |
| 11523 |
|
| 11524 |
template <typename Derived> |
| 11525 |
OMPClause * |
| 11526 |
TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 11527 |
ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 11528 |
if (E.isInvalid()) |
| 11529 |
return nullptr; |
| 11530 |
return getDerived().RebuildOMPNumTasksClause( |
| 11531 |
C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11532 |
C->getModifierLoc(), C->getEndLoc()); |
| 11533 |
} |
| 11534 |
|
| 11535 |
template <typename Derived> |
| 11536 |
OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 11537 |
ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 11538 |
if (E.isInvalid()) |
| 11539 |
return nullptr; |
| 11540 |
return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), |
| 11541 |
C->getLParenLoc(), C->getEndLoc()); |
| 11542 |
} |
| 11543 |
|
| 11544 |
template <typename Derived> |
| 11545 |
OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 11546 |
OMPDistScheduleClause *C) { |
| 11547 |
ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 11548 |
if (E.isInvalid()) |
| 11549 |
return nullptr; |
| 11550 |
return getDerived().RebuildOMPDistScheduleClause( |
| 11551 |
C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11552 |
C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| 11553 |
} |
| 11554 |
|
| 11555 |
template <typename Derived> |
| 11556 |
OMPClause * |
| 11557 |
TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 11558 |
// Rebuild Defaultmap Clause since we need to invoke the checking of |
| 11559 |
// defaultmap(none:variable-category) after template initialization. |
| 11560 |
return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(), |
| 11561 |
C->getDefaultmapKind(), |
| 11562 |
C->getBeginLoc(), |
| 11563 |
C->getLParenLoc(), |
| 11564 |
C->getDefaultmapModifierLoc(), |
| 11565 |
C->getDefaultmapKindLoc(), |
| 11566 |
C->getEndLoc()); |
| 11567 |
} |
| 11568 |
|
| 11569 |
template <typename Derived> |
| 11570 |
OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| 11571 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11572 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11573 |
Expr *IteratorModifier = C->getIteratorModifier(); |
| 11574 |
if (IteratorModifier) { |
| 11575 |
ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier); |
| 11576 |
if (MapModRes.isInvalid()) |
| 11577 |
return nullptr; |
| 11578 |
IteratorModifier = MapModRes.get(); |
| 11579 |
} |
| 11580 |
CXXScopeSpec MapperIdScopeSpec; |
| 11581 |
DeclarationNameInfo MapperIdInfo; |
| 11582 |
llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 11583 |
if (transformOMPMappableExprListClause<Derived, OMPToClause>( |
| 11584 |
*this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 11585 |
return nullptr; |
| 11586 |
return getDerived().RebuildOMPToClause( |
| 11587 |
C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier, |
| 11588 |
MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs, |
| 11589 |
UnresolvedMappers); |
| 11590 |
} |
| 11591 |
|
| 11592 |
template <typename Derived> |
| 11593 |
OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| 11594 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11595 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11596 |
Expr *IteratorModifier = C->getIteratorModifier(); |
| 11597 |
if (IteratorModifier) { |
| 11598 |
ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier); |
| 11599 |
if (MapModRes.isInvalid()) |
| 11600 |
return nullptr; |
| 11601 |
IteratorModifier = MapModRes.get(); |
| 11602 |
} |
| 11603 |
CXXScopeSpec MapperIdScopeSpec; |
| 11604 |
DeclarationNameInfo MapperIdInfo; |
| 11605 |
llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 11606 |
if (transformOMPMappableExprListClause<Derived, OMPFromClause>( |
| 11607 |
*this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 11608 |
return nullptr; |
| 11609 |
return getDerived().RebuildOMPFromClause( |
| 11610 |
C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier, |
| 11611 |
MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs, |
| 11612 |
UnresolvedMappers); |
| 11613 |
} |
| 11614 |
|
| 11615 |
template <typename Derived> |
| 11616 |
OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( |
| 11617 |
OMPUseDevicePtrClause *C) { |
| 11618 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11619 |
Vars.reserve(C->varlist_size()); |
| 11620 |
for (auto *VE : C->varlist()) { |
| 11621 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11622 |
if (EVar.isInvalid()) |
| 11623 |
return nullptr; |
| 11624 |
Vars.push_back(EVar.get()); |
| 11625 |
} |
| 11626 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11627 |
return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); |
| 11628 |
} |
| 11629 |
|
| 11630 |
template <typename Derived> |
| 11631 |
OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause( |
| 11632 |
OMPUseDeviceAddrClause *C) { |
| 11633 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11634 |
Vars.reserve(C->varlist_size()); |
| 11635 |
for (auto *VE : C->varlist()) { |
| 11636 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11637 |
if (EVar.isInvalid()) |
| 11638 |
return nullptr; |
| 11639 |
Vars.push_back(EVar.get()); |
| 11640 |
} |
| 11641 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11642 |
return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs); |
| 11643 |
} |
| 11644 |
|
| 11645 |
template <typename Derived> |
| 11646 |
OMPClause * |
| 11647 |
TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 11648 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11649 |
Vars.reserve(C->varlist_size()); |
| 11650 |
for (auto *VE : C->varlist()) { |
| 11651 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11652 |
if (EVar.isInvalid()) |
| 11653 |
return nullptr; |
| 11654 |
Vars.push_back(EVar.get()); |
| 11655 |
} |
| 11656 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11657 |
return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); |
| 11658 |
} |
| 11659 |
|
| 11660 |
template <typename Derived> |
| 11661 |
OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause( |
| 11662 |
OMPHasDeviceAddrClause *C) { |
| 11663 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11664 |
Vars.reserve(C->varlist_size()); |
| 11665 |
for (auto *VE : C->varlist()) { |
| 11666 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11667 |
if (EVar.isInvalid()) |
| 11668 |
return nullptr; |
| 11669 |
Vars.push_back(EVar.get()); |
| 11670 |
} |
| 11671 |
OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11672 |
return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs); |
| 11673 |
} |
| 11674 |
|
| 11675 |
template <typename Derived> |
| 11676 |
OMPClause * |
| 11677 |
TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) { |
| 11678 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11679 |
Vars.reserve(C->varlist_size()); |
| 11680 |
for (auto *VE : C->varlist()) { |
| 11681 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11682 |
if (EVar.isInvalid()) |
| 11683 |
return nullptr; |
| 11684 |
Vars.push_back(EVar.get()); |
| 11685 |
} |
| 11686 |
return getDerived().RebuildOMPNontemporalClause( |
| 11687 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11688 |
} |
| 11689 |
|
| 11690 |
template <typename Derived> |
| 11691 |
OMPClause * |
| 11692 |
TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) { |
| 11693 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11694 |
Vars.reserve(C->varlist_size()); |
| 11695 |
for (auto *VE : C->varlist()) { |
| 11696 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11697 |
if (EVar.isInvalid()) |
| 11698 |
return nullptr; |
| 11699 |
Vars.push_back(EVar.get()); |
| 11700 |
} |
| 11701 |
return getDerived().RebuildOMPInclusiveClause( |
| 11702 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11703 |
} |
| 11704 |
|
| 11705 |
template <typename Derived> |
| 11706 |
OMPClause * |
| 11707 |
TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) { |
| 11708 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11709 |
Vars.reserve(C->varlist_size()); |
| 11710 |
for (auto *VE : C->varlist()) { |
| 11711 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11712 |
if (EVar.isInvalid()) |
| 11713 |
return nullptr; |
| 11714 |
Vars.push_back(EVar.get()); |
| 11715 |
} |
| 11716 |
return getDerived().RebuildOMPExclusiveClause( |
| 11717 |
Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11718 |
} |
| 11719 |
|
| 11720 |
template <typename Derived> |
| 11721 |
OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause( |
| 11722 |
OMPUsesAllocatorsClause *C) { |
| 11723 |
SmallVector<SemaOpenMP::UsesAllocatorsData, 16> Data; |
| 11724 |
Data.reserve(C->getNumberOfAllocators()); |
| 11725 |
for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { |
| 11726 |
OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I); |
| 11727 |
ExprResult Allocator = getDerived().TransformExpr(D.Allocator); |
| 11728 |
if (Allocator.isInvalid()) |
| 11729 |
continue; |
| 11730 |
ExprResult AllocatorTraits; |
| 11731 |
if (Expr *AT = D.AllocatorTraits) { |
| 11732 |
AllocatorTraits = getDerived().TransformExpr(AT); |
| 11733 |
if (AllocatorTraits.isInvalid()) |
| 11734 |
continue; |
| 11735 |
} |
| 11736 |
SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back(); |
| 11737 |
NewD.Allocator = Allocator.get(); |
| 11738 |
NewD.AllocatorTraits = AllocatorTraits.get(); |
| 11739 |
NewD.LParenLoc = D.LParenLoc; |
| 11740 |
NewD.RParenLoc = D.RParenLoc; |
| 11741 |
} |
| 11742 |
return getDerived().RebuildOMPUsesAllocatorsClause( |
| 11743 |
Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11744 |
} |
| 11745 |
|
| 11746 |
template <typename Derived> |
| 11747 |
OMPClause * |
| 11748 |
TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) { |
| 11749 |
SmallVector<Expr *, 4> Locators; |
| 11750 |
Locators.reserve(C->varlist_size()); |
| 11751 |
ExprResult ModifierRes; |
| 11752 |
if (Expr *Modifier = C->getModifier()) { |
| 11753 |
ModifierRes = getDerived().TransformExpr(Modifier); |
| 11754 |
if (ModifierRes.isInvalid()) |
| 11755 |
return nullptr; |
| 11756 |
} |
| 11757 |
for (Expr *E : C->varlist()) { |
| 11758 |
ExprResult Locator = getDerived().TransformExpr(E); |
| 11759 |
if (Locator.isInvalid()) |
| 11760 |
continue; |
| 11761 |
Locators.push_back(Locator.get()); |
| 11762 |
} |
| 11763 |
return getDerived().RebuildOMPAffinityClause( |
| 11764 |
C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(), |
| 11765 |
ModifierRes.get(), Locators); |
| 11766 |
} |
| 11767 |
|
| 11768 |
template <typename Derived> |
| 11769 |
OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) { |
| 11770 |
return getDerived().RebuildOMPOrderClause( |
| 11771 |
C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(), |
| 11772 |
C->getEndLoc(), C->getModifier(), C->getModifierKwLoc()); |
| 11773 |
} |
| 11774 |
|
| 11775 |
template <typename Derived> |
| 11776 |
OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) { |
| 11777 |
return getDerived().RebuildOMPBindClause( |
| 11778 |
C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(), |
| 11779 |
C->getLParenLoc(), C->getEndLoc()); |
| 11780 |
} |
| 11781 |
|
| 11782 |
template <typename Derived> |
| 11783 |
OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause( |
| 11784 |
OMPXDynCGroupMemClause *C) { |
| 11785 |
ExprResult Size = getDerived().TransformExpr(C->getSize()); |
| 11786 |
if (Size.isInvalid()) |
| 11787 |
return nullptr; |
| 11788 |
return getDerived().RebuildOMPXDynCGroupMemClause( |
| 11789 |
Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11790 |
} |
| 11791 |
|
| 11792 |
template <typename Derived> |
| 11793 |
OMPClause *TreeTransform<Derived>::TransformOMPDynGroupprivateClause( |
| 11794 |
OMPDynGroupprivateClause *C) { |
| 11795 |
ExprResult Size = getDerived().TransformExpr(C->getSize()); |
| 11796 |
if (Size.isInvalid()) |
| 11797 |
return nullptr; |
| 11798 |
return getDerived().RebuildOMPDynGroupprivateClause( |
| 11799 |
C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(), |
| 11800 |
Size.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 11801 |
C->getDynGroupprivateModifierLoc(), |
| 11802 |
C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc()); |
| 11803 |
} |
| 11804 |
|
| 11805 |
template <typename Derived> |
| 11806 |
OMPClause * |
| 11807 |
TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) { |
| 11808 |
llvm::SmallVector<Expr *, 16> Vars; |
| 11809 |
Vars.reserve(C->varlist_size()); |
| 11810 |
for (auto *VE : C->varlist()) { |
| 11811 |
ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 11812 |
if (EVar.isInvalid()) |
| 11813 |
return nullptr; |
| 11814 |
Vars.push_back(EVar.get()); |
| 11815 |
} |
| 11816 |
return getDerived().RebuildOMPDoacrossClause( |
| 11817 |
C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars, |
| 11818 |
C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11819 |
} |
| 11820 |
|
| 11821 |
template <typename Derived> |
| 11822 |
OMPClause * |
| 11823 |
TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) { |
| 11824 |
SmallVector<const Attr *> NewAttrs; |
| 11825 |
for (auto *A : C->getAttrs()) |
| 11826 |
NewAttrs.push_back(getDerived().TransformAttr(A)); |
| 11827 |
return getDerived().RebuildOMPXAttributeClause( |
| 11828 |
NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 11829 |
} |
| 11830 |
|
| 11831 |
template <typename Derived> |
| 11832 |
OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) { |
| 11833 |
return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc()); |
| 11834 |
} |
| 11835 |
|
| 11836 |
//===----------------------------------------------------------------------===// |
| 11837 |
// OpenACC transformation |
| 11838 |
//===----------------------------------------------------------------------===// |
| 11839 |
namespace { |
| 11840 |
template <typename Derived> |
| 11841 |
class OpenACCClauseTransform final |
| 11842 |
: public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> { |
| 11843 |
TreeTransform<Derived> &Self; |
| 11844 |
ArrayRef<const OpenACCClause *> ExistingClauses; |
| 11845 |
SemaOpenACC::OpenACCParsedClause &ParsedClause; |
| 11846 |
OpenACCClause *NewClause = nullptr; |
| 11847 |
|
| 11848 |
ExprResult VisitVar(Expr *VarRef) { |
| 11849 |
ExprResult Res = Self.TransformExpr(VarRef); |
| 11850 |
|
| 11851 |
if (!Res.isUsable()) |
| 11852 |
return Res; |
| 11853 |
|
| 11854 |
Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(), |
| 11855 |
ParsedClause.getClauseKind(), |
| 11856 |
Res.get()); |
| 11857 |
|
| 11858 |
return Res; |
| 11859 |
} |
| 11860 |
|
| 11861 |
llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) { |
| 11862 |
llvm::SmallVector<Expr *> InstantiatedVarList; |
| 11863 |
for (Expr *CurVar : VarList) { |
| 11864 |
ExprResult VarRef = VisitVar(CurVar); |
| 11865 |
|
| 11866 |
if (VarRef.isUsable()) |
| 11867 |
InstantiatedVarList.push_back(VarRef.get()); |
| 11868 |
} |
| 11869 |
|
| 11870 |
return InstantiatedVarList; |
| 11871 |
} |
| 11872 |
|
| 11873 |
public: |
| 11874 |
OpenACCClauseTransform(TreeTransform<Derived> &Self, |
| 11875 |
ArrayRef<const OpenACCClause *> ExistingClauses, |
| 11876 |
SemaOpenACC::OpenACCParsedClause &PC) |
| 11877 |
: Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {} |
| 11878 |
|
| 11879 |
OpenACCClause *CreatedClause() const { return NewClause; } |
| 11880 |
|
| 11881 |
#define VISIT_CLAUSE(CLAUSE_NAME) \ |
| 11882 |
void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause); |
| 11883 |
#include "clang/Basic/OpenACCClauses.def" |
| 11884 |
}; |
| 11885 |
|
| 11886 |
template <typename Derived> |
| 11887 |
void OpenACCClauseTransform<Derived>::VisitDefaultClause( |
| 11888 |
const OpenACCDefaultClause &C) { |
| 11889 |
ParsedClause.setDefaultDetails(C.getDefaultClauseKind()); |
| 11890 |
|
| 11891 |
NewClause = OpenACCDefaultClause::Create( |
| 11892 |
Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(), |
| 11893 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 11894 |
ParsedClause.getEndLoc()); |
| 11895 |
} |
| 11896 |
|
| 11897 |
template <typename Derived> |
| 11898 |
void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) { |
| 11899 |
Expr *Cond = const_cast<Expr *>(C.getConditionExpr()); |
| 11900 |
assert(Cond && "If constructed with invalid Condition"); |
| 11901 |
Sema::ConditionResult Res = Self.TransformCondition( |
| 11902 |
Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean); |
| 11903 |
|
| 11904 |
if (Res.isInvalid() || !Res.get().second) |
| 11905 |
return; |
| 11906 |
|
| 11907 |
ParsedClause.setConditionDetails(Res.get().second); |
| 11908 |
|
| 11909 |
NewClause = OpenACCIfClause::Create( |
| 11910 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 11911 |
ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(), |
| 11912 |
ParsedClause.getEndLoc()); |
| 11913 |
} |
| 11914 |
|
| 11915 |
template <typename Derived> |
| 11916 |
void OpenACCClauseTransform<Derived>::VisitSelfClause( |
| 11917 |
const OpenACCSelfClause &C) { |
| 11918 |
|
| 11919 |
// If this is an 'update' 'self' clause, this is actually a var list instead. |
| 11920 |
if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) { |
| 11921 |
llvm::SmallVector<Expr *> InstantiatedVarList; |
| 11922 |
for (Expr *CurVar : C.getVarList()) { |
| 11923 |
ExprResult Res = Self.TransformExpr(CurVar); |
| 11924 |
|
| 11925 |
if (!Res.isUsable()) |
| 11926 |
continue; |
| 11927 |
|
| 11928 |
Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(), |
| 11929 |
ParsedClause.getClauseKind(), |
| 11930 |
Res.get()); |
| 11931 |
|
| 11932 |
if (Res.isUsable()) |
| 11933 |
InstantiatedVarList.push_back(Res.get()); |
| 11934 |
} |
| 11935 |
|
| 11936 |
ParsedClause.setVarListDetails(InstantiatedVarList, |
| 11937 |
OpenACCModifierKind::Invalid); |
| 11938 |
|
| 11939 |
NewClause = OpenACCSelfClause::Create( |
| 11940 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 11941 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 11942 |
ParsedClause.getEndLoc()); |
| 11943 |
} else { |
| 11944 |
|
| 11945 |
if (C.hasConditionExpr()) { |
| 11946 |
Expr *Cond = const_cast<Expr *>(C.getConditionExpr()); |
| 11947 |
Sema::ConditionResult Res = |
| 11948 |
Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond, |
| 11949 |
Sema::ConditionKind::Boolean); |
| 11950 |
|
| 11951 |
if (Res.isInvalid() || !Res.get().second) |
| 11952 |
return; |
| 11953 |
|
| 11954 |
ParsedClause.setConditionDetails(Res.get().second); |
| 11955 |
} |
| 11956 |
|
| 11957 |
NewClause = OpenACCSelfClause::Create( |
| 11958 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 11959 |
ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(), |
| 11960 |
ParsedClause.getEndLoc()); |
| 11961 |
} |
| 11962 |
} |
| 11963 |
|
| 11964 |
template <typename Derived> |
| 11965 |
void OpenACCClauseTransform<Derived>::VisitNumGangsClause( |
| 11966 |
const OpenACCNumGangsClause &C) { |
| 11967 |
llvm::SmallVector<Expr *> InstantiatedIntExprs; |
| 11968 |
|
| 11969 |
for (Expr *CurIntExpr : C.getIntExprs()) { |
| 11970 |
ExprResult Res = Self.TransformExpr(CurIntExpr); |
| 11971 |
|
| 11972 |
if (!Res.isUsable()) |
| 11973 |
return; |
| 11974 |
|
| 11975 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 11976 |
C.getClauseKind(), |
| 11977 |
C.getBeginLoc(), Res.get()); |
| 11978 |
if (!Res.isUsable()) |
| 11979 |
return; |
| 11980 |
|
| 11981 |
InstantiatedIntExprs.push_back(Res.get()); |
| 11982 |
} |
| 11983 |
|
| 11984 |
ParsedClause.setIntExprDetails(InstantiatedIntExprs); |
| 11985 |
NewClause = OpenACCNumGangsClause::Create( |
| 11986 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 11987 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(), |
| 11988 |
ParsedClause.getEndLoc()); |
| 11989 |
} |
| 11990 |
|
| 11991 |
template <typename Derived> |
| 11992 |
void OpenACCClauseTransform<Derived>::VisitPrivateClause( |
| 11993 |
const OpenACCPrivateClause &C) { |
| 11994 |
llvm::SmallVector<Expr *> InstantiatedVarList; |
| 11995 |
llvm::SmallVector<OpenACCPrivateRecipe> InitRecipes; |
| 11996 |
|
| 11997 |
for (const auto [RefExpr, InitRecipe] : |
| 11998 |
llvm::zip(C.getVarList(), C.getInitRecipes())) { |
| 11999 |
ExprResult VarRef = VisitVar(RefExpr); |
| 12000 |
|
| 12001 |
if (VarRef.isUsable()) { |
| 12002 |
InstantiatedVarList.push_back(VarRef.get()); |
| 12003 |
|
| 12004 |
// We only have to create a new one if it is dependent, and Sema won't |
| 12005 |
// make one of these unless the type is non-dependent. |
| 12006 |
if (InitRecipe.isSet()) |
| 12007 |
InitRecipes.push_back(InitRecipe); |
| 12008 |
else |
| 12009 |
InitRecipes.push_back( |
| 12010 |
Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get())); |
| 12011 |
} |
| 12012 |
} |
| 12013 |
ParsedClause.setVarListDetails(InstantiatedVarList, |
| 12014 |
OpenACCModifierKind::Invalid); |
| 12015 |
|
| 12016 |
NewClause = OpenACCPrivateClause::Create( |
| 12017 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12018 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes, |
| 12019 |
ParsedClause.getEndLoc()); |
| 12020 |
} |
| 12021 |
|
| 12022 |
template <typename Derived> |
| 12023 |
void OpenACCClauseTransform<Derived>::VisitHostClause( |
| 12024 |
const OpenACCHostClause &C) { |
| 12025 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12026 |
OpenACCModifierKind::Invalid); |
| 12027 |
|
| 12028 |
NewClause = OpenACCHostClause::Create( |
| 12029 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12030 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12031 |
ParsedClause.getEndLoc()); |
| 12032 |
} |
| 12033 |
|
| 12034 |
template <typename Derived> |
| 12035 |
void OpenACCClauseTransform<Derived>::VisitDeviceClause( |
| 12036 |
const OpenACCDeviceClause &C) { |
| 12037 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12038 |
OpenACCModifierKind::Invalid); |
| 12039 |
|
| 12040 |
NewClause = OpenACCDeviceClause::Create( |
| 12041 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12042 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12043 |
ParsedClause.getEndLoc()); |
| 12044 |
} |
| 12045 |
|
| 12046 |
template <typename Derived> |
| 12047 |
void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause( |
| 12048 |
const OpenACCFirstPrivateClause &C) { |
| 12049 |
llvm::SmallVector<Expr *> InstantiatedVarList; |
| 12050 |
llvm::SmallVector<OpenACCFirstPrivateRecipe> InitRecipes; |
| 12051 |
|
| 12052 |
for (const auto [RefExpr, InitRecipe] : |
| 12053 |
llvm::zip(C.getVarList(), C.getInitRecipes())) { |
| 12054 |
ExprResult VarRef = VisitVar(RefExpr); |
| 12055 |
|
| 12056 |
if (VarRef.isUsable()) { |
| 12057 |
InstantiatedVarList.push_back(VarRef.get()); |
| 12058 |
|
| 12059 |
// We only have to create a new one if it is dependent, and Sema won't |
| 12060 |
// make one of these unless the type is non-dependent. |
| 12061 |
if (InitRecipe.isSet()) |
| 12062 |
InitRecipes.push_back(InitRecipe); |
| 12063 |
else |
| 12064 |
InitRecipes.push_back( |
| 12065 |
Self.getSema().OpenACC().CreateFirstPrivateInitRecipe( |
| 12066 |
VarRef.get())); |
| 12067 |
} |
| 12068 |
} |
| 12069 |
ParsedClause.setVarListDetails(InstantiatedVarList, |
| 12070 |
OpenACCModifierKind::Invalid); |
| 12071 |
|
| 12072 |
NewClause = OpenACCFirstPrivateClause::Create( |
| 12073 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12074 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes, |
| 12075 |
ParsedClause.getEndLoc()); |
| 12076 |
} |
| 12077 |
|
| 12078 |
template <typename Derived> |
| 12079 |
void OpenACCClauseTransform<Derived>::VisitNoCreateClause( |
| 12080 |
const OpenACCNoCreateClause &C) { |
| 12081 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12082 |
OpenACCModifierKind::Invalid); |
| 12083 |
|
| 12084 |
NewClause = OpenACCNoCreateClause::Create( |
| 12085 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12086 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12087 |
ParsedClause.getEndLoc()); |
| 12088 |
} |
| 12089 |
|
| 12090 |
template <typename Derived> |
| 12091 |
void OpenACCClauseTransform<Derived>::VisitPresentClause( |
| 12092 |
const OpenACCPresentClause &C) { |
| 12093 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12094 |
OpenACCModifierKind::Invalid); |
| 12095 |
|
| 12096 |
NewClause = OpenACCPresentClause::Create( |
| 12097 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12098 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12099 |
ParsedClause.getEndLoc()); |
| 12100 |
} |
| 12101 |
|
| 12102 |
template <typename Derived> |
| 12103 |
void OpenACCClauseTransform<Derived>::VisitCopyClause( |
| 12104 |
const OpenACCCopyClause &C) { |
| 12105 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12106 |
C.getModifierList()); |
| 12107 |
|
| 12108 |
NewClause = OpenACCCopyClause::Create( |
| 12109 |
Self.getSema().getASTContext(), ParsedClause.getClauseKind(), |
| 12110 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12111 |
ParsedClause.getModifierList(), ParsedClause.getVarList(), |
| 12112 |
ParsedClause.getEndLoc()); |
| 12113 |
} |
| 12114 |
|
| 12115 |
template <typename Derived> |
| 12116 |
void OpenACCClauseTransform<Derived>::VisitLinkClause( |
| 12117 |
const OpenACCLinkClause &C) { |
| 12118 |
llvm_unreachable("link clause not valid unless a decl transform"); |
| 12119 |
} |
| 12120 |
|
| 12121 |
template <typename Derived> |
| 12122 |
void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause( |
| 12123 |
const OpenACCDeviceResidentClause &C) { |
| 12124 |
llvm_unreachable("device_resident clause not valid unless a decl transform"); |
| 12125 |
} |
| 12126 |
template <typename Derived> |
| 12127 |
void OpenACCClauseTransform<Derived>::VisitNoHostClause( |
| 12128 |
const OpenACCNoHostClause &C) { |
| 12129 |
llvm_unreachable("nohost clause not valid unless a decl transform"); |
| 12130 |
} |
| 12131 |
template <typename Derived> |
| 12132 |
void OpenACCClauseTransform<Derived>::VisitBindClause( |
| 12133 |
const OpenACCBindClause &C) { |
| 12134 |
llvm_unreachable("bind clause not valid unless a decl transform"); |
| 12135 |
} |
| 12136 |
|
| 12137 |
template <typename Derived> |
| 12138 |
void OpenACCClauseTransform<Derived>::VisitCopyInClause( |
| 12139 |
const OpenACCCopyInClause &C) { |
| 12140 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12141 |
C.getModifierList()); |
| 12142 |
|
| 12143 |
NewClause = OpenACCCopyInClause::Create( |
| 12144 |
Self.getSema().getASTContext(), ParsedClause.getClauseKind(), |
| 12145 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12146 |
ParsedClause.getModifierList(), ParsedClause.getVarList(), |
| 12147 |
ParsedClause.getEndLoc()); |
| 12148 |
} |
| 12149 |
|
| 12150 |
template <typename Derived> |
| 12151 |
void OpenACCClauseTransform<Derived>::VisitCopyOutClause( |
| 12152 |
const OpenACCCopyOutClause &C) { |
| 12153 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12154 |
C.getModifierList()); |
| 12155 |
|
| 12156 |
NewClause = OpenACCCopyOutClause::Create( |
| 12157 |
Self.getSema().getASTContext(), ParsedClause.getClauseKind(), |
| 12158 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12159 |
ParsedClause.getModifierList(), ParsedClause.getVarList(), |
| 12160 |
ParsedClause.getEndLoc()); |
| 12161 |
} |
| 12162 |
|
| 12163 |
template <typename Derived> |
| 12164 |
void OpenACCClauseTransform<Derived>::VisitCreateClause( |
| 12165 |
const OpenACCCreateClause &C) { |
| 12166 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12167 |
C.getModifierList()); |
| 12168 |
|
| 12169 |
NewClause = OpenACCCreateClause::Create( |
| 12170 |
Self.getSema().getASTContext(), ParsedClause.getClauseKind(), |
| 12171 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12172 |
ParsedClause.getModifierList(), ParsedClause.getVarList(), |
| 12173 |
ParsedClause.getEndLoc()); |
| 12174 |
} |
| 12175 |
template <typename Derived> |
| 12176 |
void OpenACCClauseTransform<Derived>::VisitAttachClause( |
| 12177 |
const OpenACCAttachClause &C) { |
| 12178 |
llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList()); |
| 12179 |
|
| 12180 |
// Ensure each var is a pointer type. |
| 12181 |
llvm::erase_if(VarList, [&](Expr *E) { |
| 12182 |
return Self.getSema().OpenACC().CheckVarIsPointerType( |
| 12183 |
OpenACCClauseKind::Attach, E); |
| 12184 |
}); |
| 12185 |
|
| 12186 |
ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid); |
| 12187 |
NewClause = OpenACCAttachClause::Create( |
| 12188 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12189 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12190 |
ParsedClause.getEndLoc()); |
| 12191 |
} |
| 12192 |
|
| 12193 |
template <typename Derived> |
| 12194 |
void OpenACCClauseTransform<Derived>::VisitDetachClause( |
| 12195 |
const OpenACCDetachClause &C) { |
| 12196 |
llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList()); |
| 12197 |
|
| 12198 |
// Ensure each var is a pointer type. |
| 12199 |
llvm::erase_if(VarList, [&](Expr *E) { |
| 12200 |
return Self.getSema().OpenACC().CheckVarIsPointerType( |
| 12201 |
OpenACCClauseKind::Detach, E); |
| 12202 |
}); |
| 12203 |
|
| 12204 |
ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid); |
| 12205 |
NewClause = OpenACCDetachClause::Create( |
| 12206 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12207 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12208 |
ParsedClause.getEndLoc()); |
| 12209 |
} |
| 12210 |
|
| 12211 |
template <typename Derived> |
| 12212 |
void OpenACCClauseTransform<Derived>::VisitDeleteClause( |
| 12213 |
const OpenACCDeleteClause &C) { |
| 12214 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12215 |
OpenACCModifierKind::Invalid); |
| 12216 |
NewClause = OpenACCDeleteClause::Create( |
| 12217 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12218 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12219 |
ParsedClause.getEndLoc()); |
| 12220 |
} |
| 12221 |
|
| 12222 |
template <typename Derived> |
| 12223 |
void OpenACCClauseTransform<Derived>::VisitUseDeviceClause( |
| 12224 |
const OpenACCUseDeviceClause &C) { |
| 12225 |
ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), |
| 12226 |
OpenACCModifierKind::Invalid); |
| 12227 |
NewClause = OpenACCUseDeviceClause::Create( |
| 12228 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12229 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12230 |
ParsedClause.getEndLoc()); |
| 12231 |
} |
| 12232 |
|
| 12233 |
template <typename Derived> |
| 12234 |
void OpenACCClauseTransform<Derived>::VisitDevicePtrClause( |
| 12235 |
const OpenACCDevicePtrClause &C) { |
| 12236 |
llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList()); |
| 12237 |
|
| 12238 |
// Ensure each var is a pointer type. |
| 12239 |
llvm::erase_if(VarList, [&](Expr *E) { |
| 12240 |
return Self.getSema().OpenACC().CheckVarIsPointerType( |
| 12241 |
OpenACCClauseKind::DevicePtr, E); |
| 12242 |
}); |
| 12243 |
|
| 12244 |
ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid); |
| 12245 |
NewClause = OpenACCDevicePtrClause::Create( |
| 12246 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12247 |
ParsedClause.getLParenLoc(), ParsedClause.getVarList(), |
| 12248 |
ParsedClause.getEndLoc()); |
| 12249 |
} |
| 12250 |
|
| 12251 |
template <typename Derived> |
| 12252 |
void OpenACCClauseTransform<Derived>::VisitNumWorkersClause( |
| 12253 |
const OpenACCNumWorkersClause &C) { |
| 12254 |
Expr *IntExpr = const_cast<Expr *>(C.getIntExpr()); |
| 12255 |
assert(IntExpr && "num_workers clause constructed with invalid int expr"); |
| 12256 |
|
| 12257 |
ExprResult Res = Self.TransformExpr(IntExpr); |
| 12258 |
if (!Res.isUsable()) |
| 12259 |
return; |
| 12260 |
|
| 12261 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12262 |
C.getClauseKind(), |
| 12263 |
C.getBeginLoc(), Res.get()); |
| 12264 |
if (!Res.isUsable()) |
| 12265 |
return; |
| 12266 |
|
| 12267 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12268 |
NewClause = OpenACCNumWorkersClause::Create( |
| 12269 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12270 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0], |
| 12271 |
ParsedClause.getEndLoc()); |
| 12272 |
} |
| 12273 |
|
| 12274 |
template <typename Derived> |
| 12275 |
void OpenACCClauseTransform<Derived>::VisitDeviceNumClause ( |
| 12276 |
const OpenACCDeviceNumClause &C) { |
| 12277 |
Expr *IntExpr = const_cast<Expr *>(C.getIntExpr()); |
| 12278 |
assert(IntExpr && "device_num clause constructed with invalid int expr"); |
| 12279 |
|
| 12280 |
ExprResult Res = Self.TransformExpr(IntExpr); |
| 12281 |
if (!Res.isUsable()) |
| 12282 |
return; |
| 12283 |
|
| 12284 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12285 |
C.getClauseKind(), |
| 12286 |
C.getBeginLoc(), Res.get()); |
| 12287 |
if (!Res.isUsable()) |
| 12288 |
return; |
| 12289 |
|
| 12290 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12291 |
NewClause = OpenACCDeviceNumClause::Create( |
| 12292 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12293 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0], |
| 12294 |
ParsedClause.getEndLoc()); |
| 12295 |
} |
| 12296 |
|
| 12297 |
template <typename Derived> |
| 12298 |
void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause( |
| 12299 |
const OpenACCDefaultAsyncClause &C) { |
| 12300 |
Expr *IntExpr = const_cast<Expr *>(C.getIntExpr()); |
| 12301 |
assert(IntExpr && "default_async clause constructed with invalid int expr"); |
| 12302 |
|
| 12303 |
ExprResult Res = Self.TransformExpr(IntExpr); |
| 12304 |
if (!Res.isUsable()) |
| 12305 |
return; |
| 12306 |
|
| 12307 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12308 |
C.getClauseKind(), |
| 12309 |
C.getBeginLoc(), Res.get()); |
| 12310 |
if (!Res.isUsable()) |
| 12311 |
return; |
| 12312 |
|
| 12313 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12314 |
NewClause = OpenACCDefaultAsyncClause::Create( |
| 12315 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12316 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0], |
| 12317 |
ParsedClause.getEndLoc()); |
| 12318 |
} |
| 12319 |
|
| 12320 |
template <typename Derived> |
| 12321 |
void OpenACCClauseTransform<Derived>::VisitVectorLengthClause( |
| 12322 |
const OpenACCVectorLengthClause &C) { |
| 12323 |
Expr *IntExpr = const_cast<Expr *>(C.getIntExpr()); |
| 12324 |
assert(IntExpr && "vector_length clause constructed with invalid int expr"); |
| 12325 |
|
| 12326 |
ExprResult Res = Self.TransformExpr(IntExpr); |
| 12327 |
if (!Res.isUsable()) |
| 12328 |
return; |
| 12329 |
|
| 12330 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12331 |
C.getClauseKind(), |
| 12332 |
C.getBeginLoc(), Res.get()); |
| 12333 |
if (!Res.isUsable()) |
| 12334 |
return; |
| 12335 |
|
| 12336 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12337 |
NewClause = OpenACCVectorLengthClause::Create( |
| 12338 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12339 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0], |
| 12340 |
ParsedClause.getEndLoc()); |
| 12341 |
} |
| 12342 |
|
| 12343 |
template <typename Derived> |
| 12344 |
void OpenACCClauseTransform<Derived>::VisitAsyncClause( |
| 12345 |
const OpenACCAsyncClause &C) { |
| 12346 |
if (C.hasIntExpr()) { |
| 12347 |
ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr())); |
| 12348 |
if (!Res.isUsable()) |
| 12349 |
return; |
| 12350 |
|
| 12351 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12352 |
C.getClauseKind(), |
| 12353 |
C.getBeginLoc(), Res.get()); |
| 12354 |
if (!Res.isUsable()) |
| 12355 |
return; |
| 12356 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12357 |
} |
| 12358 |
|
| 12359 |
NewClause = OpenACCAsyncClause::Create( |
| 12360 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12361 |
ParsedClause.getLParenLoc(), |
| 12362 |
ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0] |
| 12363 |
: nullptr, |
| 12364 |
ParsedClause.getEndLoc()); |
| 12365 |
} |
| 12366 |
|
| 12367 |
template <typename Derived> |
| 12368 |
void OpenACCClauseTransform<Derived>::VisitWorkerClause( |
| 12369 |
const OpenACCWorkerClause &C) { |
| 12370 |
if (C.hasIntExpr()) { |
| 12371 |
// restrictions on this expression are all "does it exist in certain |
| 12372 |
// situations" that are not possible to be dependent, so the only check we |
| 12373 |
// have is that it transforms, and is an int expression. |
| 12374 |
ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr())); |
| 12375 |
if (!Res.isUsable()) |
| 12376 |
return; |
| 12377 |
|
| 12378 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12379 |
C.getClauseKind(), |
| 12380 |
C.getBeginLoc(), Res.get()); |
| 12381 |
if (!Res.isUsable()) |
| 12382 |
return; |
| 12383 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12384 |
} |
| 12385 |
|
| 12386 |
NewClause = OpenACCWorkerClause::Create( |
| 12387 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12388 |
ParsedClause.getLParenLoc(), |
| 12389 |
ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0] |
| 12390 |
: nullptr, |
| 12391 |
ParsedClause.getEndLoc()); |
| 12392 |
} |
| 12393 |
|
| 12394 |
template <typename Derived> |
| 12395 |
void OpenACCClauseTransform<Derived>::VisitVectorClause( |
| 12396 |
const OpenACCVectorClause &C) { |
| 12397 |
if (C.hasIntExpr()) { |
| 12398 |
// restrictions on this expression are all "does it exist in certain |
| 12399 |
// situations" that are not possible to be dependent, so the only check we |
| 12400 |
// have is that it transforms, and is an int expression. |
| 12401 |
ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr())); |
| 12402 |
if (!Res.isUsable()) |
| 12403 |
return; |
| 12404 |
|
| 12405 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12406 |
C.getClauseKind(), |
| 12407 |
C.getBeginLoc(), Res.get()); |
| 12408 |
if (!Res.isUsable()) |
| 12409 |
return; |
| 12410 |
ParsedClause.setIntExprDetails(Res.get()); |
| 12411 |
} |
| 12412 |
|
| 12413 |
NewClause = OpenACCVectorClause::Create( |
| 12414 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12415 |
ParsedClause.getLParenLoc(), |
| 12416 |
ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0] |
| 12417 |
: nullptr, |
| 12418 |
ParsedClause.getEndLoc()); |
| 12419 |
} |
| 12420 |
|
| 12421 |
template <typename Derived> |
| 12422 |
void OpenACCClauseTransform<Derived>::VisitWaitClause( |
| 12423 |
const OpenACCWaitClause &C) { |
| 12424 |
if (C.hasExprs()) { |
| 12425 |
Expr *DevNumExpr = nullptr; |
| 12426 |
llvm::SmallVector<Expr *> InstantiatedQueueIdExprs; |
| 12427 |
|
| 12428 |
// Instantiate devnum expr if it exists. |
| 12429 |
if (C.getDevNumExpr()) { |
| 12430 |
ExprResult Res = Self.TransformExpr(C.getDevNumExpr()); |
| 12431 |
if (!Res.isUsable()) |
| 12432 |
return; |
| 12433 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12434 |
C.getClauseKind(), |
| 12435 |
C.getBeginLoc(), Res.get()); |
| 12436 |
if (!Res.isUsable()) |
| 12437 |
return; |
| 12438 |
|
| 12439 |
DevNumExpr = Res.get(); |
| 12440 |
} |
| 12441 |
|
| 12442 |
// Instantiate queue ids. |
| 12443 |
for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) { |
| 12444 |
ExprResult Res = Self.TransformExpr(CurQueueIdExpr); |
| 12445 |
if (!Res.isUsable()) |
| 12446 |
return; |
| 12447 |
Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid, |
| 12448 |
C.getClauseKind(), |
| 12449 |
C.getBeginLoc(), Res.get()); |
| 12450 |
if (!Res.isUsable()) |
| 12451 |
return; |
| 12452 |
|
| 12453 |
InstantiatedQueueIdExprs.push_back(Res.get()); |
| 12454 |
} |
| 12455 |
|
| 12456 |
ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(), |
| 12457 |
std::move(InstantiatedQueueIdExprs)); |
| 12458 |
} |
| 12459 |
|
| 12460 |
NewClause = OpenACCWaitClause::Create( |
| 12461 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12462 |
ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(), |
| 12463 |
ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(), |
| 12464 |
ParsedClause.getEndLoc()); |
| 12465 |
} |
| 12466 |
|
| 12467 |
template <typename Derived> |
| 12468 |
void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause( |
| 12469 |
const OpenACCDeviceTypeClause &C) { |
| 12470 |
// Nothing to transform here, just create a new version of 'C'. |
| 12471 |
NewClause = OpenACCDeviceTypeClause::Create( |
| 12472 |
Self.getSema().getASTContext(), C.getClauseKind(), |
| 12473 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12474 |
C.getArchitectures(), ParsedClause.getEndLoc()); |
| 12475 |
} |
| 12476 |
|
| 12477 |
template <typename Derived> |
| 12478 |
void OpenACCClauseTransform<Derived>::VisitAutoClause( |
| 12479 |
const OpenACCAutoClause &C) { |
| 12480 |
// Nothing to do, so just create a new node. |
| 12481 |
NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(), |
| 12482 |
ParsedClause.getBeginLoc(), |
| 12483 |
ParsedClause.getEndLoc()); |
| 12484 |
} |
| 12485 |
|
| 12486 |
template <typename Derived> |
| 12487 |
void OpenACCClauseTransform<Derived>::VisitIndependentClause( |
| 12488 |
const OpenACCIndependentClause &C) { |
| 12489 |
NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(), |
| 12490 |
ParsedClause.getBeginLoc(), |
| 12491 |
ParsedClause.getEndLoc()); |
| 12492 |
} |
| 12493 |
|
| 12494 |
template <typename Derived> |
| 12495 |
void OpenACCClauseTransform<Derived>::VisitSeqClause( |
| 12496 |
const OpenACCSeqClause &C) { |
| 12497 |
NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(), |
| 12498 |
ParsedClause.getBeginLoc(), |
| 12499 |
ParsedClause.getEndLoc()); |
| 12500 |
} |
| 12501 |
template <typename Derived> |
| 12502 |
void OpenACCClauseTransform<Derived>::VisitFinalizeClause( |
| 12503 |
const OpenACCFinalizeClause &C) { |
| 12504 |
NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(), |
| 12505 |
ParsedClause.getBeginLoc(), |
| 12506 |
ParsedClause.getEndLoc()); |
| 12507 |
} |
| 12508 |
|
| 12509 |
template <typename Derived> |
| 12510 |
void OpenACCClauseTransform<Derived>::VisitIfPresentClause( |
| 12511 |
const OpenACCIfPresentClause &C) { |
| 12512 |
NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(), |
| 12513 |
ParsedClause.getBeginLoc(), |
| 12514 |
ParsedClause.getEndLoc()); |
| 12515 |
} |
| 12516 |
|
| 12517 |
template <typename Derived> |
| 12518 |
void OpenACCClauseTransform<Derived>::VisitReductionClause( |
| 12519 |
const OpenACCReductionClause &C) { |
| 12520 |
SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList()); |
| 12521 |
SmallVector<Expr *> ValidVars; |
| 12522 |
llvm::SmallVector<OpenACCReductionRecipeWithStorage> Recipes; |
| 12523 |
|
| 12524 |
for (const auto [Var, OrigRecipe] : |
| 12525 |
llvm::zip(TransformedVars, C.getRecipes())) { |
| 12526 |
ExprResult Res = Self.getSema().OpenACC().CheckReductionVar( |
| 12527 |
ParsedClause.getDirectiveKind(), C.getReductionOp(), Var); |
| 12528 |
if (Res.isUsable()) { |
| 12529 |
ValidVars.push_back(Res.get()); |
| 12530 |
|
| 12531 |
if (OrigRecipe.isSet()) |
| 12532 |
Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes); |
| 12533 |
else |
| 12534 |
Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe( |
| 12535 |
C.getReductionOp(), Res.get())); |
| 12536 |
} |
| 12537 |
} |
| 12538 |
|
| 12539 |
NewClause = Self.getSema().OpenACC().CheckReductionClause( |
| 12540 |
ExistingClauses, ParsedClause.getDirectiveKind(), |
| 12541 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12542 |
C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc()); |
| 12543 |
} |
| 12544 |
|
| 12545 |
template <typename Derived> |
| 12546 |
void OpenACCClauseTransform<Derived>::VisitCollapseClause( |
| 12547 |
const OpenACCCollapseClause &C) { |
| 12548 |
Expr *LoopCount = const_cast<Expr *>(C.getLoopCount()); |
| 12549 |
assert(LoopCount && "collapse clause constructed with invalid loop count"); |
| 12550 |
|
| 12551 |
ExprResult NewLoopCount = Self.TransformExpr(LoopCount); |
| 12552 |
|
| 12553 |
NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr( |
| 12554 |
OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(), |
| 12555 |
NewLoopCount.get()->getBeginLoc(), NewLoopCount.get()); |
| 12556 |
|
| 12557 |
NewLoopCount = |
| 12558 |
Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get()); |
| 12559 |
|
| 12560 |
ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get()); |
| 12561 |
NewClause = OpenACCCollapseClause::Create( |
| 12562 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12563 |
ParsedClause.getLParenLoc(), ParsedClause.isForce(), |
| 12564 |
ParsedClause.getLoopCount(), ParsedClause.getEndLoc()); |
| 12565 |
} |
| 12566 |
|
| 12567 |
template <typename Derived> |
| 12568 |
void OpenACCClauseTransform<Derived>::VisitTileClause( |
| 12569 |
const OpenACCTileClause &C) { |
| 12570 |
|
| 12571 |
llvm::SmallVector<Expr *> TransformedExprs; |
| 12572 |
|
| 12573 |
for (Expr *E : C.getSizeExprs()) { |
| 12574 |
ExprResult NewSizeExpr = Self.TransformExpr(E); |
| 12575 |
|
| 12576 |
if (!NewSizeExpr.isUsable()) |
| 12577 |
return; |
| 12578 |
|
| 12579 |
NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr( |
| 12580 |
OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(), |
| 12581 |
NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get()); |
| 12582 |
|
| 12583 |
NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get()); |
| 12584 |
|
| 12585 |
if (!NewSizeExpr.isUsable()) |
| 12586 |
return; |
| 12587 |
TransformedExprs.push_back(NewSizeExpr.get()); |
| 12588 |
} |
| 12589 |
|
| 12590 |
ParsedClause.setIntExprDetails(TransformedExprs); |
| 12591 |
NewClause = OpenACCTileClause::Create( |
| 12592 |
Self.getSema().getASTContext(), ParsedClause.getBeginLoc(), |
| 12593 |
ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(), |
| 12594 |
ParsedClause.getEndLoc()); |
| 12595 |
} |
| 12596 |
template <typename Derived> |
| 12597 |
void OpenACCClauseTransform<Derived>::VisitGangClause( |
| 12598 |
const OpenACCGangClause &C) { |
| 12599 |
llvm::SmallVector<OpenACCGangKind> TransformedGangKinds; |
| 12600 |
llvm::SmallVector<Expr *> TransformedIntExprs; |
| 12601 |
|
| 12602 |
for (unsigned I = 0; I < C.getNumExprs(); ++I) { |
| 12603 |
ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second)); |
| 12604 |
if (!ER.isUsable()) |
| 12605 |
continue; |
| 12606 |
|
| 12607 |
ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses, |
| 12608 |
ParsedClause.getDirectiveKind(), |
| 12609 |
C.getExpr(I).first, ER.get()); |
| 12610 |
if (!ER.isUsable()) |
| 12611 |
continue; |
| 12612 |
TransformedGangKinds.push_back(C.getExpr(I).first); |
| 12613 |
TransformedIntExprs.push_back(ER.get()); |
| 12614 |
} |
| 12615 |
|
| 12616 |
NewClause = Self.getSema().OpenACC().CheckGangClause( |
| 12617 |
ParsedClause.getDirectiveKind(), ExistingClauses, |
| 12618 |
ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(), |
| 12619 |
TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc()); |
| 12620 |
} |
| 12621 |
} // namespace |
| 12622 |
template <typename Derived> |
| 12623 |
OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause( |
| 12624 |
ArrayRef<const OpenACCClause *> ExistingClauses, |
| 12625 |
OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { |
| 12626 |
|
| 12627 |
SemaOpenACC::OpenACCParsedClause ParsedClause( |
| 12628 |
DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); |
| 12629 |
ParsedClause.setEndLoc(OldClause->getEndLoc()); |
| 12630 |
|
| 12631 |
if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause)) |
| 12632 |
ParsedClause.setLParenLoc(WithParms->getLParenLoc()); |
| 12633 |
|
| 12634 |
OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses, |
| 12635 |
ParsedClause}; |
| 12636 |
Transform.Visit(OldClause); |
| 12637 |
|
| 12638 |
return Transform.CreatedClause(); |
| 12639 |
} |
| 12640 |
|
| 12641 |
template <typename Derived> |
| 12642 |
llvm::SmallVector<OpenACCClause *> |
| 12643 |
TreeTransform<Derived>::TransformOpenACCClauseList( |
| 12644 |
OpenACCDirectiveKind DirKind, ArrayRef<const OpenACCClause *> OldClauses) { |
| 12645 |
llvm::SmallVector<OpenACCClause *> TransformedClauses; |
| 12646 |
for (const auto *Clause : OldClauses) { |
| 12647 |
if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause( |
| 12648 |
TransformedClauses, DirKind, Clause)) |
| 12649 |
TransformedClauses.push_back(TransformedClause); |
| 12650 |
} |
| 12651 |
return TransformedClauses; |
| 12652 |
} |
| 12653 |
|
| 12654 |
template <typename Derived> |
| 12655 |
StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct( |
| 12656 |
OpenACCComputeConstruct *C) { |
| 12657 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12658 |
|
| 12659 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12660 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12661 |
C->clauses()); |
| 12662 |
|
| 12663 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12664 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12665 |
return StmtError(); |
| 12666 |
|
| 12667 |
// Transform Structured Block. |
| 12668 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12669 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), |
| 12670 |
C->clauses(), TransformedClauses); |
| 12671 |
StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock()); |
| 12672 |
StrBlock = getSema().OpenACC().ActOnAssociatedStmt( |
| 12673 |
C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock); |
| 12674 |
|
| 12675 |
return getDerived().RebuildOpenACCComputeConstruct( |
| 12676 |
C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(), |
| 12677 |
C->getEndLoc(), TransformedClauses, StrBlock); |
| 12678 |
} |
| 12679 |
|
| 12680 |
template <typename Derived> |
| 12681 |
StmtResult |
| 12682 |
TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) { |
| 12683 |
|
| 12684 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12685 |
|
| 12686 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12687 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12688 |
C->clauses()); |
| 12689 |
|
| 12690 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12691 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12692 |
return StmtError(); |
| 12693 |
|
| 12694 |
// Transform Loop. |
| 12695 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12696 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), |
| 12697 |
C->clauses(), TransformedClauses); |
| 12698 |
StmtResult Loop = getDerived().TransformStmt(C->getLoop()); |
| 12699 |
Loop = getSema().OpenACC().ActOnAssociatedStmt( |
| 12700 |
C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop); |
| 12701 |
|
| 12702 |
return getDerived().RebuildOpenACCLoopConstruct( |
| 12703 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12704 |
TransformedClauses, Loop); |
| 12705 |
} |
| 12706 |
|
| 12707 |
template <typename Derived> |
| 12708 |
StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct( |
| 12709 |
OpenACCCombinedConstruct *C) { |
| 12710 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12711 |
|
| 12712 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12713 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12714 |
C->clauses()); |
| 12715 |
|
| 12716 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12717 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12718 |
return StmtError(); |
| 12719 |
|
| 12720 |
// Transform Loop. |
| 12721 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12722 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), |
| 12723 |
C->clauses(), TransformedClauses); |
| 12724 |
StmtResult Loop = getDerived().TransformStmt(C->getLoop()); |
| 12725 |
Loop = getSema().OpenACC().ActOnAssociatedStmt( |
| 12726 |
C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop); |
| 12727 |
|
| 12728 |
return getDerived().RebuildOpenACCCombinedConstruct( |
| 12729 |
C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(), |
| 12730 |
C->getEndLoc(), TransformedClauses, Loop); |
| 12731 |
} |
| 12732 |
|
| 12733 |
template <typename Derived> |
| 12734 |
StmtResult |
| 12735 |
TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) { |
| 12736 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12737 |
|
| 12738 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12739 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12740 |
C->clauses()); |
| 12741 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12742 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12743 |
return StmtError(); |
| 12744 |
|
| 12745 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12746 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), |
| 12747 |
C->clauses(), TransformedClauses); |
| 12748 |
StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock()); |
| 12749 |
StrBlock = getSema().OpenACC().ActOnAssociatedStmt( |
| 12750 |
C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock); |
| 12751 |
|
| 12752 |
return getDerived().RebuildOpenACCDataConstruct( |
| 12753 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12754 |
TransformedClauses, StrBlock); |
| 12755 |
} |
| 12756 |
|
| 12757 |
template <typename Derived> |
| 12758 |
StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct( |
| 12759 |
OpenACCEnterDataConstruct *C) { |
| 12760 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12761 |
|
| 12762 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12763 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12764 |
C->clauses()); |
| 12765 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12766 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12767 |
return StmtError(); |
| 12768 |
|
| 12769 |
return getDerived().RebuildOpenACCEnterDataConstruct( |
| 12770 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12771 |
TransformedClauses); |
| 12772 |
} |
| 12773 |
|
| 12774 |
template <typename Derived> |
| 12775 |
StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct( |
| 12776 |
OpenACCExitDataConstruct *C) { |
| 12777 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12778 |
|
| 12779 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12780 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12781 |
C->clauses()); |
| 12782 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12783 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12784 |
return StmtError(); |
| 12785 |
|
| 12786 |
return getDerived().RebuildOpenACCExitDataConstruct( |
| 12787 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12788 |
TransformedClauses); |
| 12789 |
} |
| 12790 |
|
| 12791 |
template <typename Derived> |
| 12792 |
StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct( |
| 12793 |
OpenACCHostDataConstruct *C) { |
| 12794 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12795 |
|
| 12796 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12797 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12798 |
C->clauses()); |
| 12799 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12800 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12801 |
return StmtError(); |
| 12802 |
|
| 12803 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12804 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), |
| 12805 |
C->clauses(), TransformedClauses); |
| 12806 |
StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock()); |
| 12807 |
StrBlock = getSema().OpenACC().ActOnAssociatedStmt( |
| 12808 |
C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock); |
| 12809 |
|
| 12810 |
return getDerived().RebuildOpenACCHostDataConstruct( |
| 12811 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12812 |
TransformedClauses, StrBlock); |
| 12813 |
} |
| 12814 |
|
| 12815 |
template <typename Derived> |
| 12816 |
StmtResult |
| 12817 |
TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) { |
| 12818 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12819 |
|
| 12820 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12821 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12822 |
C->clauses()); |
| 12823 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12824 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12825 |
return StmtError(); |
| 12826 |
|
| 12827 |
return getDerived().RebuildOpenACCInitConstruct( |
| 12828 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12829 |
TransformedClauses); |
| 12830 |
} |
| 12831 |
|
| 12832 |
template <typename Derived> |
| 12833 |
StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct( |
| 12834 |
OpenACCShutdownConstruct *C) { |
| 12835 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12836 |
|
| 12837 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12838 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12839 |
C->clauses()); |
| 12840 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12841 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12842 |
return StmtError(); |
| 12843 |
|
| 12844 |
return getDerived().RebuildOpenACCShutdownConstruct( |
| 12845 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12846 |
TransformedClauses); |
| 12847 |
} |
| 12848 |
template <typename Derived> |
| 12849 |
StmtResult |
| 12850 |
TreeTransform<Derived>::TransformOpenACCSetConstruct(OpenACCSetConstruct *C) { |
| 12851 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12852 |
|
| 12853 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12854 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12855 |
C->clauses()); |
| 12856 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12857 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12858 |
return StmtError(); |
| 12859 |
|
| 12860 |
return getDerived().RebuildOpenACCSetConstruct( |
| 12861 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12862 |
TransformedClauses); |
| 12863 |
} |
| 12864 |
|
| 12865 |
template <typename Derived> |
| 12866 |
StmtResult TreeTransform<Derived>::TransformOpenACCUpdateConstruct( |
| 12867 |
OpenACCUpdateConstruct *C) { |
| 12868 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12869 |
|
| 12870 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12871 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12872 |
C->clauses()); |
| 12873 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12874 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12875 |
return StmtError(); |
| 12876 |
|
| 12877 |
return getDerived().RebuildOpenACCUpdateConstruct( |
| 12878 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(), |
| 12879 |
TransformedClauses); |
| 12880 |
} |
| 12881 |
|
| 12882 |
template <typename Derived> |
| 12883 |
StmtResult |
| 12884 |
TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) { |
| 12885 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12886 |
|
| 12887 |
ExprResult DevNumExpr; |
| 12888 |
if (C->hasDevNumExpr()) { |
| 12889 |
DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr()); |
| 12890 |
|
| 12891 |
if (DevNumExpr.isUsable()) |
| 12892 |
DevNumExpr = getSema().OpenACC().ActOnIntExpr( |
| 12893 |
OpenACCDirectiveKind::Wait, OpenACCClauseKind::Invalid, |
| 12894 |
C->getBeginLoc(), DevNumExpr.get()); |
| 12895 |
} |
| 12896 |
|
| 12897 |
llvm::SmallVector<Expr *> QueueIdExprs; |
| 12898 |
|
| 12899 |
for (Expr *QE : C->getQueueIdExprs()) { |
| 12900 |
assert(QE && "Null queue id expr?"); |
| 12901 |
ExprResult NewEQ = getDerived().TransformExpr(QE); |
| 12902 |
|
| 12903 |
if (!NewEQ.isUsable()) |
| 12904 |
break; |
| 12905 |
NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait, |
| 12906 |
OpenACCClauseKind::Invalid, |
| 12907 |
C->getBeginLoc(), NewEQ.get()); |
| 12908 |
if (NewEQ.isUsable()) |
| 12909 |
QueueIdExprs.push_back(NewEQ.get()); |
| 12910 |
} |
| 12911 |
|
| 12912 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12913 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12914 |
C->clauses()); |
| 12915 |
|
| 12916 |
if (getSema().OpenACC().ActOnStartStmtDirective( |
| 12917 |
C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses)) |
| 12918 |
return StmtError(); |
| 12919 |
|
| 12920 |
return getDerived().RebuildOpenACCWaitConstruct( |
| 12921 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(), |
| 12922 |
DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(), |
| 12923 |
QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses); |
| 12924 |
} |
| 12925 |
template <typename Derived> |
| 12926 |
StmtResult TreeTransform<Derived>::TransformOpenACCCacheConstruct( |
| 12927 |
OpenACCCacheConstruct *C) { |
| 12928 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12929 |
|
| 12930 |
llvm::SmallVector<Expr *> TransformedVarList; |
| 12931 |
for (Expr *Var : C->getVarList()) { |
| 12932 |
assert(Var && "Null var listexpr?"); |
| 12933 |
|
| 12934 |
ExprResult NewVar = getDerived().TransformExpr(Var); |
| 12935 |
|
| 12936 |
if (!NewVar.isUsable()) |
| 12937 |
break; |
| 12938 |
|
| 12939 |
NewVar = getSema().OpenACC().ActOnVar( |
| 12940 |
C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get()); |
| 12941 |
if (!NewVar.isUsable()) |
| 12942 |
break; |
| 12943 |
|
| 12944 |
TransformedVarList.push_back(NewVar.get()); |
| 12945 |
} |
| 12946 |
|
| 12947 |
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(), |
| 12948 |
C->getBeginLoc(), {})) |
| 12949 |
return StmtError(); |
| 12950 |
|
| 12951 |
return getDerived().RebuildOpenACCCacheConstruct( |
| 12952 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(), |
| 12953 |
C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(), |
| 12954 |
C->getEndLoc()); |
| 12955 |
} |
| 12956 |
|
| 12957 |
template <typename Derived> |
| 12958 |
StmtResult TreeTransform<Derived>::TransformOpenACCAtomicConstruct( |
| 12959 |
OpenACCAtomicConstruct *C) { |
| 12960 |
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc()); |
| 12961 |
|
| 12962 |
llvm::SmallVector<OpenACCClause *> TransformedClauses = |
| 12963 |
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(), |
| 12964 |
C->clauses()); |
| 12965 |
|
| 12966 |
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(), |
| 12967 |
C->getBeginLoc(), {})) |
| 12968 |
return StmtError(); |
| 12969 |
|
| 12970 |
// Transform Associated Stmt. |
| 12971 |
SemaOpenACC::AssociatedStmtRAII AssocStmtRAII( |
| 12972 |
getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {}); |
| 12973 |
|
| 12974 |
StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt()); |
| 12975 |
AssocStmt = getSema().OpenACC().ActOnAssociatedStmt( |
| 12976 |
C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {}, |
| 12977 |
AssocStmt); |
| 12978 |
|
| 12979 |
return getDerived().RebuildOpenACCAtomicConstruct( |
| 12980 |
C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(), |
| 12981 |
C->getEndLoc(), TransformedClauses, AssocStmt); |
| 12982 |
} |
| 12983 |
|
| 12984 |
template <typename Derived> |
| 12985 |
ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr( |
| 12986 |
OpenACCAsteriskSizeExpr *E) { |
| 12987 |
if (getDerived().AlwaysRebuild()) |
| 12988 |
return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation()); |
| 12989 |
// Nothing can ever change, so there is never anything to transform. |
| 12990 |
return E; |
| 12991 |
} |
| 12992 |
|
| 12993 |
//===----------------------------------------------------------------------===// |
| 12994 |
// Expression transformation |
| 12995 |
//===----------------------------------------------------------------------===// |
| 12996 |
template<typename Derived> |
| 12997 |
ExprResult |
| 12998 |
TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { |
| 12999 |
return TransformExpr(E->getSubExpr()); |
| 13000 |
} |
| 13001 |
|
| 13002 |
template <typename Derived> |
| 13003 |
ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr( |
| 13004 |
SYCLUniqueStableNameExpr *E) { |
| 13005 |
if (!E->isTypeDependent()) |
| 13006 |
return E; |
| 13007 |
|
| 13008 |
TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo()); |
| 13009 |
|
| 13010 |
if (!NewT) |
| 13011 |
return ExprError(); |
| 13012 |
|
| 13013 |
if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT) |
| 13014 |
return E; |
| 13015 |
|
| 13016 |
return getDerived().RebuildSYCLUniqueStableNameExpr( |
| 13017 |
E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT); |
| 13018 |
} |
| 13019 |
|
| 13020 |
template<typename Derived> |
| 13021 |
ExprResult |
| 13022 |
TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| 13023 |
if (!E->isTypeDependent()) |
| 13024 |
return E; |
| 13025 |
|
| 13026 |
return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 13027 |
E->getIdentKind()); |
| 13028 |
} |
| 13029 |
|
| 13030 |
template<typename Derived> |
| 13031 |
ExprResult |
| 13032 |
TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
| 13033 |
NestedNameSpecifierLoc QualifierLoc; |
| 13034 |
if (E->getQualifierLoc()) { |
| 13035 |
QualifierLoc |
| 13036 |
= getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 13037 |
if (!QualifierLoc) |
| 13038 |
return ExprError(); |
| 13039 |
} |
| 13040 |
|
| 13041 |
ValueDecl *ND |
| 13042 |
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 13043 |
E->getDecl())); |
| 13044 |
if (!ND || ND->isInvalidDecl()) |
| 13045 |
return ExprError(); |
| 13046 |
|
| 13047 |
NamedDecl *Found = ND; |
| 13048 |
if (E->getFoundDecl() != E->getDecl()) { |
| 13049 |
Found = cast_or_null<NamedDecl>( |
| 13050 |
getDerived().TransformDecl(E->getLocation(), E->getFoundDecl())); |
| 13051 |
if (!Found) |
| 13052 |
return ExprError(); |
| 13053 |
} |
| 13054 |
|
| 13055 |
DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 13056 |
if (NameInfo.getName()) { |
| 13057 |
NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 13058 |
if (!NameInfo.getName()) |
| 13059 |
return ExprError(); |
| 13060 |
} |
| 13061 |
|
| 13062 |
if (!getDerived().AlwaysRebuild() && |
| 13063 |
!E->isCapturedByCopyInLambdaWithExplicitObjectParameter() && |
| 13064 |
QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() && |
| 13065 |
Found == E->getFoundDecl() && |
| 13066 |
NameInfo.getName() == E->getDecl()->getDeclName() && |
| 13067 |
!E->hasExplicitTemplateArgs()) { |
| 13068 |
|
| 13069 |
// Mark it referenced in the new context regardless. |
| 13070 |
// FIXME: this is a bit instantiation-specific. |
| 13071 |
SemaRef.MarkDeclRefReferenced(E); |
| 13072 |
|
| 13073 |
return E; |
| 13074 |
} |
| 13075 |
|
| 13076 |
TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
| 13077 |
if (E->hasExplicitTemplateArgs()) { |
| 13078 |
TemplateArgs = &TransArgs; |
| 13079 |
TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 13080 |
TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 13081 |
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 13082 |
E->getNumTemplateArgs(), |
| 13083 |
TransArgs)) |
| 13084 |
return ExprError(); |
| 13085 |
} |
| 13086 |
|
| 13087 |
return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 13088 |
Found, TemplateArgs); |
| 13089 |
} |
| 13090 |
|
| 13091 |
template<typename Derived> |
| 13092 |
ExprResult |
| 13093 |
TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| 13094 |
return E; |
| 13095 |
} |
| 13096 |
|
| 13097 |
template <typename Derived> |
| 13098 |
ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( |
| 13099 |
FixedPointLiteral *E) { |
| 13100 |
return E; |
| 13101 |
} |
| 13102 |
|
| 13103 |
template<typename Derived> |
| 13104 |
ExprResult |
| 13105 |
TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| 13106 |
return E; |
| 13107 |
} |
| 13108 |
|
| 13109 |
template<typename Derived> |
| 13110 |
ExprResult |
| 13111 |
TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| 13112 |
return E; |
| 13113 |
} |
| 13114 |
|
| 13115 |
template<typename Derived> |
| 13116 |
ExprResult |
| 13117 |
TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| 13118 |
return E; |
| 13119 |
} |
| 13120 |
|
| 13121 |
template<typename Derived> |
| 13122 |
ExprResult |
| 13123 |
TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| 13124 |
return E; |
| 13125 |
} |
| 13126 |
|
| 13127 |
template<typename Derived> |
| 13128 |
ExprResult |
| 13129 |
TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| 13130 |
return getDerived().TransformCallExpr(E); |
| 13131 |
} |
| 13132 |
|
| 13133 |
template<typename Derived> |
| 13134 |
ExprResult |
| 13135 |
TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 13136 |
ExprResult ControllingExpr; |
| 13137 |
TypeSourceInfo *ControllingType = nullptr; |
| 13138 |
if (E->isExprPredicate()) |
| 13139 |
ControllingExpr = getDerived().TransformExpr(E->getControllingExpr()); |
| 13140 |
else |
| 13141 |
ControllingType = getDerived().TransformType(E->getControllingType()); |
| 13142 |
|
| 13143 |
if (ControllingExpr.isInvalid() && !ControllingType) |
| 13144 |
return ExprError(); |
| 13145 |
|
| 13146 |
SmallVector<Expr *, 4> AssocExprs; |
| 13147 |
SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| 13148 |
for (const GenericSelectionExpr::Association Assoc : E->associations()) { |
| 13149 |
TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); |
| 13150 |
if (TSI) { |
| 13151 |
TypeSourceInfo *AssocType = getDerived().TransformType(TSI); |
| 13152 |
if (!AssocType) |
| 13153 |
return ExprError(); |
| 13154 |
AssocTypes.push_back(AssocType); |
| 13155 |
} else { |
| 13156 |
AssocTypes.push_back(nullptr); |
| 13157 |
} |
| 13158 |
|
| 13159 |
ExprResult AssocExpr = |
| 13160 |
getDerived().TransformExpr(Assoc.getAssociationExpr()); |
| 13161 |
if (AssocExpr.isInvalid()) |
| 13162 |
return ExprError(); |
| 13163 |
AssocExprs.push_back(AssocExpr.get()); |
| 13164 |
} |
| 13165 |
|
| 13166 |
if (!ControllingType) |
| 13167 |
return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 13168 |
E->getDefaultLoc(), |
| 13169 |
E->getRParenLoc(), |
| 13170 |
ControllingExpr.get(), |
| 13171 |
AssocTypes, |
| 13172 |
AssocExprs); |
| 13173 |
return getDerived().RebuildGenericSelectionExpr( |
| 13174 |
E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(), |
| 13175 |
ControllingType, AssocTypes, AssocExprs); |
| 13176 |
} |
| 13177 |
|
| 13178 |
template<typename Derived> |
| 13179 |
ExprResult |
| 13180 |
TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
| 13181 |
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 13182 |
if (SubExpr.isInvalid()) |
| 13183 |
return ExprError(); |
| 13184 |
|
| 13185 |
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| 13186 |
return E; |
| 13187 |
|
| 13188 |
return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
| 13189 |
E->getRParen()); |
| 13190 |
} |
| 13191 |
|
| 13192 |
/// The operand of a unary address-of operator has special rules: it's |
| 13193 |
/// allowed to refer to a non-static member of a class even if there's no 'this' |
| 13194 |
/// object available. |
| 13195 |
template<typename Derived> |
| 13196 |
ExprResult |
| 13197 |
TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 13198 |
if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 13199 |
return getDerived().TransformDependentScopeDeclRefExpr( |
| 13200 |
DRE, /*IsAddressOfOperand=*/true, nullptr); |
| 13201 |
else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E)) |
| 13202 |
return getDerived().TransformUnresolvedLookupExpr( |
| 13203 |
ULE, /*IsAddressOfOperand=*/true); |
| 13204 |
else |
| 13205 |
return getDerived().TransformExpr(E); |
| 13206 |
} |
| 13207 |
|
| 13208 |
template<typename Derived> |
| 13209 |
ExprResult |
| 13210 |
TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 13211 |
ExprResult SubExpr; |
| 13212 |
if (E->getOpcode() == UO_AddrOf) |
| 13213 |
SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 13214 |
else |
| 13215 |
SubExpr = TransformExpr(E->getSubExpr()); |
| 13216 |
if (SubExpr.isInvalid()) |
| 13217 |
return ExprError(); |
| 13218 |
|
| 13219 |
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| 13220 |
return E; |
| 13221 |
|
| 13222 |
return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 13223 |
E->getOpcode(), |
| 13224 |
SubExpr.get()); |
| 13225 |
} |
| 13226 |
|
| 13227 |
template<typename Derived> |
| 13228 |
ExprResult |
| 13229 |
TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 13230 |
// Transform the type. |
| 13231 |
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 13232 |
if (!Type) |
| 13233 |
return ExprError(); |
| 13234 |
|
| 13235 |
// Transform all of the components into components similar to what the |
| 13236 |
// parser uses. |
| 13237 |
// FIXME: It would be slightly more efficient in the non-dependent case to |
| 13238 |
// just map FieldDecls, rather than requiring the rebuilder to look for |
| 13239 |
// the fields again. However, __builtin_offsetof is rare enough in |
| 13240 |
// template code that we don't care. |
| 13241 |
bool ExprChanged = false; |
| 13242 |
typedef Sema::OffsetOfComponent Component; |
| 13243 |
SmallVector<Component, 4> Components; |
| 13244 |
for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 13245 |
const OffsetOfNode &ON = E->getComponent(I); |
| 13246 |
Component Comp; |
| 13247 |
Comp.isBrackets = true; |
| 13248 |
Comp.LocStart = ON.getSourceRange().getBegin(); |
| 13249 |
Comp.LocEnd = ON.getSourceRange().getEnd(); |
| 13250 |
switch (ON.getKind()) { |
| 13251 |
case OffsetOfNode::Array: { |
| 13252 |
Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 13253 |
ExprResult Index = getDerived().TransformExpr(FromIndex); |
| 13254 |
if (Index.isInvalid()) |
| 13255 |
return ExprError(); |
| 13256 |
|
| 13257 |
ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 13258 |
Comp.isBrackets = true; |
| 13259 |
Comp.U.E = Index.get(); |
| 13260 |
break; |
| 13261 |
} |
| 13262 |
|
| 13263 |
case OffsetOfNode::Field: |
| 13264 |
case OffsetOfNode::Identifier: |
| 13265 |
Comp.isBrackets = false; |
| 13266 |
Comp.U.IdentInfo = ON.getFieldName(); |
| 13267 |
if (!Comp.U.IdentInfo) |
| 13268 |
continue; |
| 13269 |
|
| 13270 |
break; |
| 13271 |
|
| 13272 |
case OffsetOfNode::Base: |
| 13273 |
// Will be recomputed during the rebuild. |
| 13274 |
continue; |
| 13275 |
} |
| 13276 |
|
| 13277 |
Components.push_back(Comp); |
| 13278 |
} |
| 13279 |
|
| 13280 |
// If nothing changed, retain the existing expression. |
| 13281 |
if (!getDerived().AlwaysRebuild() && |
| 13282 |
Type == E->getTypeSourceInfo() && |
| 13283 |
!ExprChanged) |
| 13284 |
return E; |
| 13285 |
|
| 13286 |
// Build a new offsetof expression. |
| 13287 |
return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 13288 |
Components, E->getRParenLoc()); |
| 13289 |
} |
| 13290 |
|
| 13291 |
template<typename Derived> |
| 13292 |
ExprResult |
| 13293 |
TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 13294 |
assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
| 13295 |
"opaque value expression requires transformation"); |
| 13296 |
return E; |
| 13297 |
} |
| 13298 |
|
| 13299 |
template <typename Derived> |
| 13300 |
ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) { |
| 13301 |
llvm::SmallVector<Expr *, 8> Children; |
| 13302 |
bool Changed = false; |
| 13303 |
for (Expr *C : E->subExpressions()) { |
| 13304 |
ExprResult NewC = getDerived().TransformExpr(C); |
| 13305 |
if (NewC.isInvalid()) |
| 13306 |
return ExprError(); |
| 13307 |
Children.push_back(NewC.get()); |
| 13308 |
|
| 13309 |
Changed |= NewC.get() != C; |
| 13310 |
} |
| 13311 |
if (!getDerived().AlwaysRebuild() && !Changed) |
| 13312 |
return E; |
| 13313 |
return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), |
| 13314 |
Children, E->getType()); |
| 13315 |
} |
| 13316 |
|
| 13317 |
template<typename Derived> |
| 13318 |
ExprResult |
| 13319 |
TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
| 13320 |
// Rebuild the syntactic form. The original syntactic form has |
| 13321 |
// opaque-value expressions in it, so strip those away and rebuild |
| 13322 |
// the result. This is a really awful way of doing this, but the |
| 13323 |
// better solution (rebuilding the semantic expressions and |
| 13324 |
// rebinding OVEs as necessary) doesn't work; we'd need |
| 13325 |
// TreeTransform to not strip away implicit conversions. |
| 13326 |
Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E); |
| 13327 |
ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
| 13328 |
if (result.isInvalid()) return ExprError(); |
| 13329 |
|
| 13330 |
// If that gives us a pseudo-object result back, the pseudo-object |
| 13331 |
// expression must have been an lvalue-to-rvalue conversion which we |
| 13332 |
// should reapply. |
| 13333 |
if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 13334 |
result = SemaRef.PseudoObject().checkRValue(result.get()); |
| 13335 |
|
| 13336 |
return result; |
| 13337 |
} |
| 13338 |
|
| 13339 |
template<typename Derived> |
| 13340 |
ExprResult |
| 13341 |
TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 13342 |
UnaryExprOrTypeTraitExpr *E) { |
| 13343 |
if (E->isArgumentType()) { |
| 13344 |
TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
| 13345 |
|
| 13346 |
TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 13347 |
if (!NewT) |
| 13348 |
return ExprError(); |
| 13349 |
|
| 13350 |
if (!getDerived().AlwaysRebuild() && OldT == NewT) |
| 13351 |
return E; |
| 13352 |
|
| 13353 |
return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 13354 |
E->getKind(), |
| 13355 |
E->getSourceRange()); |
| 13356 |
} |
| 13357 |
|
| 13358 |
// C++0x [expr.sizeof]p1: |
| 13359 |
// The operand is either an expression, which is an unevaluated operand |
| 13360 |
// [...] |
| 13361 |
EnterExpressionEvaluationContext Unevaluated( |
| 13362 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 13363 |
Sema::ReuseLambdaContextDecl); |
| 13364 |
|
| 13365 |
// Try to recover if we have something like sizeof(T::X) where X is a type. |
| 13366 |
// Notably, there must be *exactly* one set of parens if X is a type. |
| 13367 |
TypeSourceInfo *RecoveryTSI = nullptr; |
| 13368 |
ExprResult SubExpr; |
| 13369 |
auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 13370 |
if (auto *DRE = |
| 13371 |
PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 13372 |
SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 13373 |
PE, DRE, false, &RecoveryTSI); |
| 13374 |
else |
| 13375 |
SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 13376 |
|
| 13377 |
if (RecoveryTSI) { |
| 13378 |
return getDerived().RebuildUnaryExprOrTypeTrait( |
| 13379 |
RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 13380 |
} else if (SubExpr.isInvalid()) |
| 13381 |
return ExprError(); |
| 13382 |
|
| 13383 |
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 13384 |
return E; |
| 13385 |
|
| 13386 |
return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 13387 |
E->getOperatorLoc(), |
| 13388 |
E->getKind(), |
| 13389 |
E->getSourceRange()); |
| 13390 |
} |
| 13391 |
|
| 13392 |
template<typename Derived> |
| 13393 |
ExprResult |
| 13394 |
TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 13395 |
ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 13396 |
if (LHS.isInvalid()) |
| 13397 |
return ExprError(); |
| 13398 |
|
| 13399 |
ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 13400 |
if (RHS.isInvalid()) |
| 13401 |
return ExprError(); |
| 13402 |
|
| 13403 |
|
| 13404 |
if (!getDerived().AlwaysRebuild() && |
| 13405 |
LHS.get() == E->getLHS() && |
| 13406 |
RHS.get() == E->getRHS()) |
| 13407 |
return E; |
| 13408 |
|
| 13409 |
return getDerived().RebuildArraySubscriptExpr( |
| 13410 |
LHS.get(), |
| 13411 |
/*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); |
| 13412 |
} |
| 13413 |
|
| 13414 |
template <typename Derived> |
| 13415 |
ExprResult TreeTransform<Derived>::TransformMatrixSingleSubscriptExpr( |
| 13416 |
MatrixSingleSubscriptExpr *E) { |
| 13417 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13418 |
if (Base.isInvalid()) |
| 13419 |
return ExprError(); |
| 13420 |
|
| 13421 |
ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx()); |
| 13422 |
if (RowIdx.isInvalid()) |
| 13423 |
return ExprError(); |
| 13424 |
|
| 13425 |
if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 13426 |
RowIdx.get() == E->getRowIdx()) |
| 13427 |
return E; |
| 13428 |
|
| 13429 |
return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(), |
| 13430 |
E->getRBracketLoc()); |
| 13431 |
} |
| 13432 |
|
| 13433 |
template <typename Derived> |
| 13434 |
ExprResult |
| 13435 |
TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) { |
| 13436 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13437 |
if (Base.isInvalid()) |
| 13438 |
return ExprError(); |
| 13439 |
|
| 13440 |
ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx()); |
| 13441 |
if (RowIdx.isInvalid()) |
| 13442 |
return ExprError(); |
| 13443 |
|
| 13444 |
ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx()); |
| 13445 |
if (ColumnIdx.isInvalid()) |
| 13446 |
return ExprError(); |
| 13447 |
|
| 13448 |
if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 13449 |
RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx()) |
| 13450 |
return E; |
| 13451 |
|
| 13452 |
return getDerived().RebuildMatrixSubscriptExpr( |
| 13453 |
Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc()); |
| 13454 |
} |
| 13455 |
|
| 13456 |
template <typename Derived> |
| 13457 |
ExprResult |
| 13458 |
TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) { |
| 13459 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13460 |
if (Base.isInvalid()) |
| 13461 |
return ExprError(); |
| 13462 |
|
| 13463 |
ExprResult LowerBound; |
| 13464 |
if (E->getLowerBound()) { |
| 13465 |
LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 13466 |
if (LowerBound.isInvalid()) |
| 13467 |
return ExprError(); |
| 13468 |
} |
| 13469 |
|
| 13470 |
ExprResult Length; |
| 13471 |
if (E->getLength()) { |
| 13472 |
Length = getDerived().TransformExpr(E->getLength()); |
| 13473 |
if (Length.isInvalid()) |
| 13474 |
return ExprError(); |
| 13475 |
} |
| 13476 |
|
| 13477 |
ExprResult Stride; |
| 13478 |
if (E->isOMPArraySection()) { |
| 13479 |
if (Expr *Str = E->getStride()) { |
| 13480 |
Stride = getDerived().TransformExpr(Str); |
| 13481 |
if (Stride.isInvalid()) |
| 13482 |
return ExprError(); |
| 13483 |
} |
| 13484 |
} |
| 13485 |
|
| 13486 |
if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 13487 |
LowerBound.get() == E->getLowerBound() && |
| 13488 |
Length.get() == E->getLength() && |
| 13489 |
(E->isOpenACCArraySection() || Stride.get() == E->getStride())) |
| 13490 |
return E; |
| 13491 |
|
| 13492 |
return getDerived().RebuildArraySectionExpr( |
| 13493 |
E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(), |
| 13494 |
LowerBound.get(), E->getColonLocFirst(), |
| 13495 |
E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{}, |
| 13496 |
Length.get(), Stride.get(), E->getRBracketLoc()); |
| 13497 |
} |
| 13498 |
|
| 13499 |
template <typename Derived> |
| 13500 |
ExprResult |
| 13501 |
TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) { |
| 13502 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13503 |
if (Base.isInvalid()) |
| 13504 |
return ExprError(); |
| 13505 |
|
| 13506 |
SmallVector<Expr *, 4> Dims; |
| 13507 |
bool ErrorFound = false; |
| 13508 |
for (Expr *Dim : E->getDimensions()) { |
| 13509 |
ExprResult DimRes = getDerived().TransformExpr(Dim); |
| 13510 |
if (DimRes.isInvalid()) { |
| 13511 |
ErrorFound = true; |
| 13512 |
continue; |
| 13513 |
} |
| 13514 |
Dims.push_back(DimRes.get()); |
| 13515 |
} |
| 13516 |
|
| 13517 |
if (ErrorFound) |
| 13518 |
return ExprError(); |
| 13519 |
return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(), |
| 13520 |
E->getRParenLoc(), Dims, |
| 13521 |
E->getBracketsRanges()); |
| 13522 |
} |
| 13523 |
|
| 13524 |
template <typename Derived> |
| 13525 |
ExprResult |
| 13526 |
TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) { |
| 13527 |
unsigned NumIterators = E->numOfIterators(); |
| 13528 |
SmallVector<SemaOpenMP::OMPIteratorData, 4> Data(NumIterators); |
| 13529 |
|
| 13530 |
bool ErrorFound = false; |
| 13531 |
bool NeedToRebuild = getDerived().AlwaysRebuild(); |
| 13532 |
for (unsigned I = 0; I < NumIterators; ++I) { |
| 13533 |
auto *D = cast<VarDecl>(E->getIteratorDecl(I)); |
| 13534 |
Data[I].DeclIdent = D->getIdentifier(); |
| 13535 |
Data[I].DeclIdentLoc = D->getLocation(); |
| 13536 |
if (D->getLocation() == D->getBeginLoc()) { |
| 13537 |
assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) && |
| 13538 |
"Implicit type must be int."); |
| 13539 |
} else { |
| 13540 |
TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo()); |
| 13541 |
QualType DeclTy = getDerived().TransformType(D->getType()); |
| 13542 |
Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI); |
| 13543 |
} |
| 13544 |
OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I); |
| 13545 |
ExprResult Begin = getDerived().TransformExpr(Range.Begin); |
| 13546 |
ExprResult End = getDerived().TransformExpr(Range.End); |
| 13547 |
ExprResult Step = getDerived().TransformExpr(Range.Step); |
| 13548 |
ErrorFound = ErrorFound || |
| 13549 |
!(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() && |
| 13550 |
!Data[I].Type.get().isNull())) || |
| 13551 |
Begin.isInvalid() || End.isInvalid() || Step.isInvalid(); |
| 13552 |
if (ErrorFound) |
| 13553 |
continue; |
| 13554 |
Data[I].Range.Begin = Begin.get(); |
| 13555 |
Data[I].Range.End = End.get(); |
| 13556 |
Data[I].Range.Step = Step.get(); |
| 13557 |
Data[I].AssignLoc = E->getAssignLoc(I); |
| 13558 |
Data[I].ColonLoc = E->getColonLoc(I); |
| 13559 |
Data[I].SecColonLoc = E->getSecondColonLoc(I); |
| 13560 |
NeedToRebuild = |
| 13561 |
NeedToRebuild || |
| 13562 |
(D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() != |
| 13563 |
D->getType().getTypePtrOrNull()) || |
| 13564 |
Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End || |
| 13565 |
Range.Step != Data[I].Range.Step; |
| 13566 |
} |
| 13567 |
if (ErrorFound) |
| 13568 |
return ExprError(); |
| 13569 |
if (!NeedToRebuild) |
| 13570 |
return E; |
| 13571 |
|
| 13572 |
ExprResult Res = getDerived().RebuildOMPIteratorExpr( |
| 13573 |
E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data); |
| 13574 |
if (!Res.isUsable()) |
| 13575 |
return Res; |
| 13576 |
auto *IE = cast<OMPIteratorExpr>(Res.get()); |
| 13577 |
for (unsigned I = 0; I < NumIterators; ++I) |
| 13578 |
getDerived().transformedLocalDecl(E->getIteratorDecl(I), |
| 13579 |
IE->getIteratorDecl(I)); |
| 13580 |
return Res; |
| 13581 |
} |
| 13582 |
|
| 13583 |
template<typename Derived> |
| 13584 |
ExprResult |
| 13585 |
TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| 13586 |
// Transform the callee. |
| 13587 |
ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 13588 |
if (Callee.isInvalid()) |
| 13589 |
return ExprError(); |
| 13590 |
|
| 13591 |
// Transform arguments. |
| 13592 |
bool ArgChanged = false; |
| 13593 |
SmallVector<Expr*, 8> Args; |
| 13594 |
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 13595 |
&ArgChanged)) |
| 13596 |
return ExprError(); |
| 13597 |
|
| 13598 |
if (!getDerived().AlwaysRebuild() && |
| 13599 |
Callee.get() == E->getCallee() && |
| 13600 |
!ArgChanged) |
| 13601 |
return SemaRef.MaybeBindToTemporary(E); |
| 13602 |
|
| 13603 |
// FIXME: Wrong source location information for the '('. |
| 13604 |
SourceLocation FakeLParenLoc |
| 13605 |
= ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 13606 |
|
| 13607 |
Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 13608 |
if (E->hasStoredFPFeatures()) { |
| 13609 |
FPOptionsOverride NewOverrides = E->getFPFeatures(); |
| 13610 |
getSema().CurFPFeatures = |
| 13611 |
NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 13612 |
getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 13613 |
} |
| 13614 |
|
| 13615 |
return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 13616 |
Args, |
| 13617 |
E->getRParenLoc()); |
| 13618 |
} |
| 13619 |
|
| 13620 |
template<typename Derived> |
| 13621 |
ExprResult |
| 13622 |
TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
| 13623 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13624 |
if (Base.isInvalid()) |
| 13625 |
return ExprError(); |
| 13626 |
|
| 13627 |
NestedNameSpecifierLoc QualifierLoc; |
| 13628 |
if (E->hasQualifier()) { |
| 13629 |
QualifierLoc |
| 13630 |
= getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 13631 |
|
| 13632 |
if (!QualifierLoc) |
| 13633 |
return ExprError(); |
| 13634 |
} |
| 13635 |
SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 13636 |
|
| 13637 |
ValueDecl *Member |
| 13638 |
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 13639 |
E->getMemberDecl())); |
| 13640 |
if (!Member) |
| 13641 |
return ExprError(); |
| 13642 |
|
| 13643 |
NamedDecl *FoundDecl = E->getFoundDecl(); |
| 13644 |
if (FoundDecl == E->getMemberDecl()) { |
| 13645 |
FoundDecl = Member; |
| 13646 |
} else { |
| 13647 |
FoundDecl = cast_or_null<NamedDecl>( |
| 13648 |
getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 13649 |
if (!FoundDecl) |
| 13650 |
return ExprError(); |
| 13651 |
} |
| 13652 |
|
| 13653 |
if (!getDerived().AlwaysRebuild() && |
| 13654 |
Base.get() == E->getBase() && |
| 13655 |
QualifierLoc == E->getQualifierLoc() && |
| 13656 |
Member == E->getMemberDecl() && |
| 13657 |
FoundDecl == E->getFoundDecl() && |
| 13658 |
!E->hasExplicitTemplateArgs()) { |
| 13659 |
|
| 13660 |
// Skip for member expression of (this->f), rebuilt thisi->f is needed |
| 13661 |
// for Openmp where the field need to be privatizized in the case. |
| 13662 |
if (!(isa<CXXThisExpr>(E->getBase()) && |
| 13663 |
getSema().OpenMP().isOpenMPRebuildMemberExpr( |
| 13664 |
cast<ValueDecl>(Member)))) { |
| 13665 |
// Mark it referenced in the new context regardless. |
| 13666 |
// FIXME: this is a bit instantiation-specific. |
| 13667 |
SemaRef.MarkMemberReferenced(E); |
| 13668 |
return E; |
| 13669 |
} |
| 13670 |
} |
| 13671 |
|
| 13672 |
TemplateArgumentListInfo TransArgs; |
| 13673 |
if (E->hasExplicitTemplateArgs()) { |
| 13674 |
TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 13675 |
TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 13676 |
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 13677 |
E->getNumTemplateArgs(), |
| 13678 |
TransArgs)) |
| 13679 |
return ExprError(); |
| 13680 |
} |
| 13681 |
|
| 13682 |
// FIXME: Bogus source location for the operator |
| 13683 |
SourceLocation FakeOperatorLoc = |
| 13684 |
SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 13685 |
|
| 13686 |
// FIXME: to do this check properly, we will need to preserve the |
| 13687 |
// first-qualifier-in-scope here, just in case we had a dependent |
| 13688 |
// base (and therefore couldn't do the check) and a |
| 13689 |
// nested-name-qualifier (and therefore could do the lookup). |
| 13690 |
NamedDecl *FirstQualifierInScope = nullptr; |
| 13691 |
DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); |
| 13692 |
if (MemberNameInfo.getName()) { |
| 13693 |
MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); |
| 13694 |
if (!MemberNameInfo.getName()) |
| 13695 |
return ExprError(); |
| 13696 |
} |
| 13697 |
|
| 13698 |
return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
| 13699 |
E->isArrow(), |
| 13700 |
QualifierLoc, |
| 13701 |
TemplateKWLoc, |
| 13702 |
MemberNameInfo, |
| 13703 |
Member, |
| 13704 |
FoundDecl, |
| 13705 |
(E->hasExplicitTemplateArgs() |
| 13706 |
? &TransArgs : nullptr), |
| 13707 |
FirstQualifierInScope); |
| 13708 |
} |
| 13709 |
|
| 13710 |
template<typename Derived> |
| 13711 |
ExprResult |
| 13712 |
TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
| 13713 |
ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 13714 |
if (LHS.isInvalid()) |
| 13715 |
return ExprError(); |
| 13716 |
|
| 13717 |
ExprResult RHS = |
| 13718 |
getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false); |
| 13719 |
if (RHS.isInvalid()) |
| 13720 |
return ExprError(); |
| 13721 |
|
| 13722 |
if (!getDerived().AlwaysRebuild() && |
| 13723 |
LHS.get() == E->getLHS() && |
| 13724 |
RHS.get() == E->getRHS()) |
| 13725 |
return E; |
| 13726 |
|
| 13727 |
if (E->isCompoundAssignmentOp()) |
| 13728 |
// FPFeatures has already been established from trailing storage |
| 13729 |
return getDerived().RebuildBinaryOperator( |
| 13730 |
E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); |
| 13731 |
Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 13732 |
FPOptionsOverride NewOverrides(E->getFPFeatures()); |
| 13733 |
getSema().CurFPFeatures = |
| 13734 |
NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 13735 |
getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 13736 |
return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 13737 |
LHS.get(), RHS.get()); |
| 13738 |
} |
| 13739 |
|
| 13740 |
template <typename Derived> |
| 13741 |
ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator( |
| 13742 |
CXXRewrittenBinaryOperator *E) { |
| 13743 |
CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm(); |
| 13744 |
|
| 13745 |
ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS)); |
| 13746 |
if (LHS.isInvalid()) |
| 13747 |
return ExprError(); |
| 13748 |
|
| 13749 |
ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS)); |
| 13750 |
if (RHS.isInvalid()) |
| 13751 |
return ExprError(); |
| 13752 |
|
| 13753 |
// Extract the already-resolved callee declarations so that we can restrict |
| 13754 |
// ourselves to using them as the unqualified lookup results when rebuilding. |
| 13755 |
UnresolvedSet<2> UnqualLookups; |
| 13756 |
bool ChangedAnyLookups = false; |
| 13757 |
Expr *PossibleBinOps[] = {E->getSemanticForm(), |
| 13758 |
const_cast<Expr *>(Decomp.InnerBinOp)}; |
| 13759 |
for (Expr *PossibleBinOp : PossibleBinOps) { |
| 13760 |
auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit()); |
| 13761 |
if (!Op) |
| 13762 |
continue; |
| 13763 |
auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit()); |
| 13764 |
if (!Callee || isa<CXXMethodDecl>(Callee->getDecl())) |
| 13765 |
continue; |
| 13766 |
|
| 13767 |
// Transform the callee in case we built a call to a local extern |
| 13768 |
// declaration. |
| 13769 |
NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl( |
| 13770 |
E->getOperatorLoc(), Callee->getFoundDecl())); |
| 13771 |
if (!Found) |
| 13772 |
return ExprError(); |
| 13773 |
if (Found != Callee->getFoundDecl()) |
| 13774 |
ChangedAnyLookups = true; |
| 13775 |
UnqualLookups.addDecl(Found); |
| 13776 |
} |
| 13777 |
|
| 13778 |
if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups && |
| 13779 |
LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) { |
| 13780 |
// Mark all functions used in the rewrite as referenced. Note that when |
| 13781 |
// a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be |
| 13782 |
// function calls, and/or there might be a user-defined conversion sequence |
| 13783 |
// applied to the operands of the <. |
| 13784 |
// FIXME: this is a bit instantiation-specific. |
| 13785 |
const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS}; |
| 13786 |
SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt); |
| 13787 |
return E; |
| 13788 |
} |
| 13789 |
|
| 13790 |
return getDerived().RebuildCXXRewrittenBinaryOperator( |
| 13791 |
E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get()); |
| 13792 |
} |
| 13793 |
|
| 13794 |
template<typename Derived> |
| 13795 |
ExprResult |
| 13796 |
TreeTransform<Derived>::TransformCompoundAssignOperator( |
| 13797 |
CompoundAssignOperator *E) { |
| 13798 |
Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 13799 |
FPOptionsOverride NewOverrides(E->getFPFeatures()); |
| 13800 |
getSema().CurFPFeatures = |
| 13801 |
NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 13802 |
getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 13803 |
return getDerived().TransformBinaryOperator(E); |
| 13804 |
} |
| 13805 |
|
| 13806 |
template<typename Derived> |
| 13807 |
ExprResult TreeTransform<Derived>:: |
| 13808 |
TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 13809 |
// Just rebuild the common and RHS expressions and see whether we |
| 13810 |
// get any changes. |
| 13811 |
|
| 13812 |
ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 13813 |
if (commonExpr.isInvalid()) |
| 13814 |
return ExprError(); |
| 13815 |
|
| 13816 |
ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 13817 |
if (rhs.isInvalid()) |
| 13818 |
return ExprError(); |
| 13819 |
|
| 13820 |
if (!getDerived().AlwaysRebuild() && |
| 13821 |
commonExpr.get() == e->getCommon() && |
| 13822 |
rhs.get() == e->getFalseExpr()) |
| 13823 |
return e; |
| 13824 |
|
| 13825 |
return getDerived().RebuildConditionalOperator(commonExpr.get(), |
| 13826 |
e->getQuestionLoc(), |
| 13827 |
nullptr, |
| 13828 |
e->getColonLoc(), |
| 13829 |
rhs.get()); |
| 13830 |
} |
| 13831 |
|
| 13832 |
template<typename Derived> |
| 13833 |
ExprResult |
| 13834 |
TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
| 13835 |
ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 13836 |
if (Cond.isInvalid()) |
| 13837 |
return ExprError(); |
| 13838 |
|
| 13839 |
ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 13840 |
if (LHS.isInvalid()) |
| 13841 |
return ExprError(); |
| 13842 |
|
| 13843 |
ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 13844 |
if (RHS.isInvalid()) |
| 13845 |
return ExprError(); |
| 13846 |
|
| 13847 |
if (!getDerived().AlwaysRebuild() && |
| 13848 |
Cond.get() == E->getCond() && |
| 13849 |
LHS.get() == E->getLHS() && |
| 13850 |
RHS.get() == E->getRHS()) |
| 13851 |
return E; |
| 13852 |
|
| 13853 |
return getDerived().RebuildConditionalOperator(Cond.get(), |
| 13854 |
E->getQuestionLoc(), |
| 13855 |
LHS.get(), |
| 13856 |
E->getColonLoc(), |
| 13857 |
RHS.get()); |
| 13858 |
} |
| 13859 |
|
| 13860 |
template<typename Derived> |
| 13861 |
ExprResult |
| 13862 |
TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
| 13863 |
// Implicit casts are eliminated during transformation, since they |
| 13864 |
// will be recomputed by semantic analysis after transformation. |
| 13865 |
return getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 13866 |
} |
| 13867 |
|
| 13868 |
template<typename Derived> |
| 13869 |
ExprResult |
| 13870 |
TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
| 13871 |
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 13872 |
if (!Type) |
| 13873 |
return ExprError(); |
| 13874 |
|
| 13875 |
ExprResult SubExpr |
| 13876 |
= getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 13877 |
if (SubExpr.isInvalid()) |
| 13878 |
return ExprError(); |
| 13879 |
|
| 13880 |
if (!getDerived().AlwaysRebuild() && |
| 13881 |
Type == E->getTypeInfoAsWritten() && |
| 13882 |
SubExpr.get() == E->getSubExpr()) |
| 13883 |
return E; |
| 13884 |
|
| 13885 |
return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 13886 |
Type, |
| 13887 |
E->getRParenLoc(), |
| 13888 |
SubExpr.get()); |
| 13889 |
} |
| 13890 |
|
| 13891 |
template<typename Derived> |
| 13892 |
ExprResult |
| 13893 |
TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 13894 |
TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 13895 |
TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 13896 |
if (!NewT) |
| 13897 |
return ExprError(); |
| 13898 |
|
| 13899 |
ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 13900 |
if (Init.isInvalid()) |
| 13901 |
return ExprError(); |
| 13902 |
|
| 13903 |
if (!getDerived().AlwaysRebuild() && |
| 13904 |
OldT == NewT && |
| 13905 |
Init.get() == E->getInitializer()) |
| 13906 |
return SemaRef.MaybeBindToTemporary(E); |
| 13907 |
|
| 13908 |
// Note: the expression type doesn't necessarily match the |
| 13909 |
// type-as-written, but that's okay, because it should always be |
| 13910 |
// derivable from the initializer. |
| 13911 |
|
| 13912 |
return getDerived().RebuildCompoundLiteralExpr( |
| 13913 |
E->getLParenLoc(), NewT, |
| 13914 |
/*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); |
| 13915 |
} |
| 13916 |
|
| 13917 |
template<typename Derived> |
| 13918 |
ExprResult |
| 13919 |
TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 13920 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13921 |
if (Base.isInvalid()) |
| 13922 |
return ExprError(); |
| 13923 |
|
| 13924 |
if (!getDerived().AlwaysRebuild() && |
| 13925 |
Base.get() == E->getBase()) |
| 13926 |
return E; |
| 13927 |
|
| 13928 |
// FIXME: Bad source location |
| 13929 |
SourceLocation FakeOperatorLoc = |
| 13930 |
SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); |
| 13931 |
return getDerived().RebuildExtVectorElementExpr( |
| 13932 |
Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(), |
| 13933 |
E->getAccessor()); |
| 13934 |
} |
| 13935 |
|
| 13936 |
template<typename Derived> |
| 13937 |
ExprResult |
| 13938 |
TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
| 13939 |
if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 13940 |
E = Syntactic; |
| 13941 |
|
| 13942 |
bool InitChanged = false; |
| 13943 |
|
| 13944 |
EnterExpressionEvaluationContext Context( |
| 13945 |
getSema(), EnterExpressionEvaluationContext::InitList); |
| 13946 |
|
| 13947 |
SmallVector<Expr*, 4> Inits; |
| 13948 |
if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 13949 |
Inits, &InitChanged)) |
| 13950 |
return ExprError(); |
| 13951 |
|
| 13952 |
if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 13953 |
// FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 13954 |
// in some cases. We can't reuse it in general, because the syntactic and |
| 13955 |
// semantic forms are linked, and we can't know that semantic form will |
| 13956 |
// match even if the syntactic form does. |
| 13957 |
} |
| 13958 |
|
| 13959 |
return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
| 13960 |
E->getRBraceLoc()); |
| 13961 |
} |
| 13962 |
|
| 13963 |
template<typename Derived> |
| 13964 |
ExprResult |
| 13965 |
TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
| 13966 |
Designation Desig; |
| 13967 |
|
| 13968 |
// transform the initializer value |
| 13969 |
ExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 13970 |
if (Init.isInvalid()) |
| 13971 |
return ExprError(); |
| 13972 |
|
| 13973 |
// transform the designators. |
| 13974 |
SmallVector<Expr*, 4> ArrayExprs; |
| 13975 |
bool ExprChanged = false; |
| 13976 |
for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 13977 |
if (D.isFieldDesignator()) { |
| 13978 |
if (D.getFieldDecl()) { |
| 13979 |
FieldDecl *Field = cast_or_null<FieldDecl>( |
| 13980 |
getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl())); |
| 13981 |
if (Field != D.getFieldDecl()) |
| 13982 |
// Rebuild the expression when the transformed FieldDecl is |
| 13983 |
// different to the already assigned FieldDecl. |
| 13984 |
ExprChanged = true; |
| 13985 |
if (Field->isAnonymousStructOrUnion()) |
| 13986 |
continue; |
| 13987 |
} else { |
| 13988 |
// Ensure that the designator expression is rebuilt when there isn't |
| 13989 |
// a resolved FieldDecl in the designator as we don't want to assign |
| 13990 |
// a FieldDecl to a pattern designator that will be instantiated again. |
| 13991 |
ExprChanged = true; |
| 13992 |
} |
| 13993 |
Desig.AddDesignator(Designator::CreateFieldDesignator( |
| 13994 |
D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); |
| 13995 |
continue; |
| 13996 |
} |
| 13997 |
|
| 13998 |
if (D.isArrayDesignator()) { |
| 13999 |
ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
| 14000 |
if (Index.isInvalid()) |
| 14001 |
return ExprError(); |
| 14002 |
|
| 14003 |
Desig.AddDesignator( |
| 14004 |
Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc())); |
| 14005 |
|
| 14006 |
ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D); |
| 14007 |
ArrayExprs.push_back(Index.get()); |
| 14008 |
continue; |
| 14009 |
} |
| 14010 |
|
| 14011 |
assert(D.isArrayRangeDesignator() && "New kind of designator?"); |
| 14012 |
ExprResult Start |
| 14013 |
= getDerived().TransformExpr(E->getArrayRangeStart(D)); |
| 14014 |
if (Start.isInvalid()) |
| 14015 |
return ExprError(); |
| 14016 |
|
| 14017 |
ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
| 14018 |
if (End.isInvalid()) |
| 14019 |
return ExprError(); |
| 14020 |
|
| 14021 |
Desig.AddDesignator(Designator::CreateArrayRangeDesignator( |
| 14022 |
Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc())); |
| 14023 |
|
| 14024 |
ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 14025 |
End.get() != E->getArrayRangeEnd(D); |
| 14026 |
|
| 14027 |
ArrayExprs.push_back(Start.get()); |
| 14028 |
ArrayExprs.push_back(End.get()); |
| 14029 |
} |
| 14030 |
|
| 14031 |
if (!getDerived().AlwaysRebuild() && |
| 14032 |
Init.get() == E->getInit() && |
| 14033 |
!ExprChanged) |
| 14034 |
return E; |
| 14035 |
|
| 14036 |
return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
| 14037 |
E->getEqualOrColonLoc(), |
| 14038 |
E->usesGNUSyntax(), Init.get()); |
| 14039 |
} |
| 14040 |
|
| 14041 |
// Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 14042 |
// InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 14043 |
template<typename Derived> |
| 14044 |
ExprResult |
| 14045 |
TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 14046 |
DesignatedInitUpdateExpr *E) { |
| 14047 |
llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 14048 |
"initializer"); |
| 14049 |
return ExprError(); |
| 14050 |
} |
| 14051 |
|
| 14052 |
template<typename Derived> |
| 14053 |
ExprResult |
| 14054 |
TreeTransform<Derived>::TransformNoInitExpr( |
| 14055 |
NoInitExpr *E) { |
| 14056 |
llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); |
| 14057 |
return ExprError(); |
| 14058 |
} |
| 14059 |
|
| 14060 |
template<typename Derived> |
| 14061 |
ExprResult |
| 14062 |
TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 14063 |
llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); |
| 14064 |
return ExprError(); |
| 14065 |
} |
| 14066 |
|
| 14067 |
template<typename Derived> |
| 14068 |
ExprResult |
| 14069 |
TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 14070 |
llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); |
| 14071 |
return ExprError(); |
| 14072 |
} |
| 14073 |
|
| 14074 |
template<typename Derived> |
| 14075 |
ExprResult |
| 14076 |
TreeTransform<Derived>::TransformImplicitValueInitExpr( |
| 14077 |
ImplicitValueInitExpr *E) { |
| 14078 |
TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); |
| 14079 |
|
| 14080 |
// FIXME: Will we ever have proper type location here? Will we actually |
| 14081 |
// need to transform the type? |
| 14082 |
QualType T = getDerived().TransformType(E->getType()); |
| 14083 |
if (T.isNull()) |
| 14084 |
return ExprError(); |
| 14085 |
|
| 14086 |
if (!getDerived().AlwaysRebuild() && |
| 14087 |
T == E->getType()) |
| 14088 |
return E; |
| 14089 |
|
| 14090 |
return getDerived().RebuildImplicitValueInitExpr(T); |
| 14091 |
} |
| 14092 |
|
| 14093 |
template<typename Derived> |
| 14094 |
ExprResult |
| 14095 |
TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| 14096 |
TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 14097 |
if (!TInfo) |
| 14098 |
return ExprError(); |
| 14099 |
|
| 14100 |
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 14101 |
if (SubExpr.isInvalid()) |
| 14102 |
return ExprError(); |
| 14103 |
|
| 14104 |
if (!getDerived().AlwaysRebuild() && |
| 14105 |
TInfo == E->getWrittenTypeInfo() && |
| 14106 |
SubExpr.get() == E->getSubExpr()) |
| 14107 |
return E; |
| 14108 |
|
| 14109 |
return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
| 14110 |
TInfo, E->getRParenLoc()); |
| 14111 |
} |
| 14112 |
|
| 14113 |
template<typename Derived> |
| 14114 |
ExprResult |
| 14115 |
TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| 14116 |
bool ArgumentChanged = false; |
| 14117 |
SmallVector<Expr*, 4> Inits; |
| 14118 |
if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 14119 |
&ArgumentChanged)) |
| 14120 |
return ExprError(); |
| 14121 |
|
| 14122 |
return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 14123 |
Inits, |
| 14124 |
E->getRParenLoc()); |
| 14125 |
} |
| 14126 |
|
| 14127 |
/// Transform an address-of-label expression. |
| 14128 |
/// |
| 14129 |
/// By default, the transformation of an address-of-label expression always |
| 14130 |
/// rebuilds the expression, so that the label identifier can be resolved to |
| 14131 |
/// the corresponding label statement by semantic analysis. |
| 14132 |
template<typename Derived> |
| 14133 |
ExprResult |
| 14134 |
TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
| 14135 |
Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 14136 |
E->getLabel()); |
| 14137 |
if (!LD) |
| 14138 |
return ExprError(); |
| 14139 |
|
| 14140 |
return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 14141 |
cast<LabelDecl>(LD)); |
| 14142 |
} |
| 14143 |
|
| 14144 |
template<typename Derived> |
| 14145 |
ExprResult |
| 14146 |
TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
| 14147 |
SemaRef.ActOnStartStmtExpr(); |
| 14148 |
StmtResult SubStmt |
| 14149 |
= getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 14150 |
if (SubStmt.isInvalid()) { |
| 14151 |
SemaRef.ActOnStmtExprError(); |
| 14152 |
return ExprError(); |
| 14153 |
} |
| 14154 |
|
| 14155 |
unsigned OldDepth = E->getTemplateDepth(); |
| 14156 |
unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth); |
| 14157 |
|
| 14158 |
if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth && |
| 14159 |
SubStmt.get() == E->getSubStmt()) { |
| 14160 |
// Calling this an 'error' is unintuitive, but it does the right thing. |
| 14161 |
SemaRef.ActOnStmtExprError(); |
| 14162 |
return SemaRef.MaybeBindToTemporary(E); |
| 14163 |
} |
| 14164 |
|
| 14165 |
return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(), |
| 14166 |
E->getRParenLoc(), NewDepth); |
| 14167 |
} |
| 14168 |
|
| 14169 |
template<typename Derived> |
| 14170 |
ExprResult |
| 14171 |
TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
| 14172 |
ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 14173 |
if (Cond.isInvalid()) |
| 14174 |
return ExprError(); |
| 14175 |
|
| 14176 |
ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 14177 |
if (LHS.isInvalid()) |
| 14178 |
return ExprError(); |
| 14179 |
|
| 14180 |
ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 14181 |
if (RHS.isInvalid()) |
| 14182 |
return ExprError(); |
| 14183 |
|
| 14184 |
if (!getDerived().AlwaysRebuild() && |
| 14185 |
Cond.get() == E->getCond() && |
| 14186 |
LHS.get() == E->getLHS() && |
| 14187 |
RHS.get() == E->getRHS()) |
| 14188 |
return E; |
| 14189 |
|
| 14190 |
return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 14191 |
Cond.get(), LHS.get(), RHS.get(), |
| 14192 |
E->getRParenLoc()); |
| 14193 |
} |
| 14194 |
|
| 14195 |
template<typename Derived> |
| 14196 |
ExprResult |
| 14197 |
TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| 14198 |
return E; |
| 14199 |
} |
| 14200 |
|
| 14201 |
template<typename Derived> |
| 14202 |
ExprResult |
| 14203 |
TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 14204 |
switch (E->getOperator()) { |
| 14205 |
case OO_New: |
| 14206 |
case OO_Delete: |
| 14207 |
case OO_Array_New: |
| 14208 |
case OO_Array_Delete: |
| 14209 |
llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); |
| 14210 |
|
| 14211 |
case OO_Subscript: |
| 14212 |
case OO_Call: { |
| 14213 |
// This is a call to an object's operator(). |
| 14214 |
assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); |
| 14215 |
|
| 14216 |
// Transform the object itself. |
| 14217 |
ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 14218 |
if (Object.isInvalid()) |
| 14219 |
return ExprError(); |
| 14220 |
|
| 14221 |
// FIXME: Poor location information. Also, if the location for the end of |
| 14222 |
// the token is within a macro expansion, getLocForEndOfToken() will return |
| 14223 |
// an invalid source location. If that happens and we have an otherwise |
| 14224 |
// valid end location, use the valid one instead of the invalid one. |
| 14225 |
SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc(); |
| 14226 |
SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc); |
| 14227 |
if (FakeLParenLoc.isInvalid() && EndLoc.isValid()) |
| 14228 |
FakeLParenLoc = EndLoc; |
| 14229 |
|
| 14230 |
// Transform the call arguments. |
| 14231 |
SmallVector<Expr*, 8> Args; |
| 14232 |
if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 14233 |
Args)) |
| 14234 |
return ExprError(); |
| 14235 |
|
| 14236 |
if (E->getOperator() == OO_Subscript) |
| 14237 |
return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc, |
| 14238 |
Args, E->getEndLoc()); |
| 14239 |
|
| 14240 |
return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, |
| 14241 |
E->getEndLoc()); |
| 14242 |
} |
| 14243 |
|
| 14244 |
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ |
| 14245 |
case OO_##Name: \ |
| 14246 |
break; |
| 14247 |
|
| 14248 |
#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 14249 |
#include "clang/Basic/OperatorKinds.def" |
| 14250 |
|
| 14251 |
case OO_Conditional: |
| 14252 |
llvm_unreachable("conditional operator is not actually overloadable"); |
| 14253 |
|
| 14254 |
case OO_None: |
| 14255 |
case NUM_OVERLOADED_OPERATORS: |
| 14256 |
llvm_unreachable("not an overloaded operator?"); |
| 14257 |
} |
| 14258 |
|
| 14259 |
ExprResult First; |
| 14260 |
if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp) |
| 14261 |
First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 14262 |
else |
| 14263 |
First = getDerived().TransformExpr(E->getArg(0)); |
| 14264 |
if (First.isInvalid()) |
| 14265 |
return ExprError(); |
| 14266 |
|
| 14267 |
ExprResult Second; |
| 14268 |
if (E->getNumArgs() == 2) { |
| 14269 |
Second = |
| 14270 |
getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false); |
| 14271 |
if (Second.isInvalid()) |
| 14272 |
return ExprError(); |
| 14273 |
} |
| 14274 |
|
| 14275 |
Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 14276 |
FPOptionsOverride NewOverrides(E->getFPFeatures()); |
| 14277 |
getSema().CurFPFeatures = |
| 14278 |
NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 14279 |
getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 14280 |
|
| 14281 |
Expr *Callee = E->getCallee(); |
| 14282 |
if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
| 14283 |
LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(), |
| 14284 |
Sema::LookupOrdinaryName); |
| 14285 |
if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R)) |
| 14286 |
return ExprError(); |
| 14287 |
|
| 14288 |
return getDerived().RebuildCXXOperatorCallExpr( |
| 14289 |
E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(), |
| 14290 |
ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get()); |
| 14291 |
} |
| 14292 |
|
| 14293 |
UnresolvedSet<1> Functions; |
| 14294 |
if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee)) |
| 14295 |
Callee = ICE->getSubExprAsWritten(); |
| 14296 |
NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl(); |
| 14297 |
ValueDecl *VD = cast_or_null<ValueDecl>( |
| 14298 |
getDerived().TransformDecl(DR->getLocation(), DR)); |
| 14299 |
if (!VD) |
| 14300 |
return ExprError(); |
| 14301 |
|
| 14302 |
if (!isa<CXXMethodDecl>(VD)) |
| 14303 |
Functions.addDecl(VD); |
| 14304 |
|
| 14305 |
return getDerived().RebuildCXXOperatorCallExpr( |
| 14306 |
E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(), |
| 14307 |
/*RequiresADL=*/false, Functions, First.get(), Second.get()); |
| 14308 |
} |
| 14309 |
|
| 14310 |
template<typename Derived> |
| 14311 |
ExprResult |
| 14312 |
TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 14313 |
return getDerived().TransformCallExpr(E); |
| 14314 |
} |
| 14315 |
|
| 14316 |
template <typename Derived> |
| 14317 |
ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { |
| 14318 |
bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) && |
| 14319 |
getSema().CurContext != E->getParentContext(); |
| 14320 |
|
| 14321 |
if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) |
| 14322 |
return E; |
| 14323 |
|
| 14324 |
return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(), |
| 14325 |
E->getBeginLoc(), E->getEndLoc(), |
| 14326 |
getSema().CurContext); |
| 14327 |
} |
| 14328 |
|
| 14329 |
template <typename Derived> |
| 14330 |
ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) { |
| 14331 |
return E; |
| 14332 |
} |
| 14333 |
|
| 14334 |
template<typename Derived> |
| 14335 |
ExprResult |
| 14336 |
TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 14337 |
// Transform the callee. |
| 14338 |
ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 14339 |
if (Callee.isInvalid()) |
| 14340 |
return ExprError(); |
| 14341 |
|
| 14342 |
// Transform exec config. |
| 14343 |
ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 14344 |
if (EC.isInvalid()) |
| 14345 |
return ExprError(); |
| 14346 |
|
| 14347 |
// Transform arguments. |
| 14348 |
bool ArgChanged = false; |
| 14349 |
SmallVector<Expr*, 8> Args; |
| 14350 |
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 14351 |
&ArgChanged)) |
| 14352 |
return ExprError(); |
| 14353 |
|
| 14354 |
if (!getDerived().AlwaysRebuild() && |
| 14355 |
Callee.get() == E->getCallee() && |
| 14356 |
!ArgChanged) |
| 14357 |
return SemaRef.MaybeBindToTemporary(E); |
| 14358 |
|
| 14359 |
// FIXME: Wrong source location information for the '('. |
| 14360 |
SourceLocation FakeLParenLoc |
| 14361 |
= ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 14362 |
return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 14363 |
Args, |
| 14364 |
E->getRParenLoc(), EC.get()); |
| 14365 |
} |
| 14366 |
|
| 14367 |
template<typename Derived> |
| 14368 |
ExprResult |
| 14369 |
TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 14370 |
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 14371 |
if (!Type) |
| 14372 |
return ExprError(); |
| 14373 |
|
| 14374 |
ExprResult SubExpr |
| 14375 |
= getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 14376 |
if (SubExpr.isInvalid()) |
| 14377 |
return ExprError(); |
| 14378 |
|
| 14379 |
if (!getDerived().AlwaysRebuild() && |
| 14380 |
Type == E->getTypeInfoAsWritten() && |
| 14381 |
SubExpr.get() == E->getSubExpr()) |
| 14382 |
return E; |
| 14383 |
return getDerived().RebuildCXXNamedCastExpr( |
| 14384 |
E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 14385 |
Type, E->getAngleBrackets().getEnd(), |
| 14386 |
// FIXME. this should be '(' location |
| 14387 |
E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
| 14388 |
} |
| 14389 |
|
| 14390 |
template<typename Derived> |
| 14391 |
ExprResult |
| 14392 |
TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) { |
| 14393 |
TypeSourceInfo *TSI = |
| 14394 |
getDerived().TransformType(BCE->getTypeInfoAsWritten()); |
| 14395 |
if (!TSI) |
| 14396 |
return ExprError(); |
| 14397 |
|
| 14398 |
ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr()); |
| 14399 |
if (Sub.isInvalid()) |
| 14400 |
return ExprError(); |
| 14401 |
|
| 14402 |
return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI, |
| 14403 |
Sub.get(), BCE->getEndLoc()); |
| 14404 |
} |
| 14405 |
|
| 14406 |
template<typename Derived> |
| 14407 |
ExprResult |
| 14408 |
TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 14409 |
return getDerived().TransformCXXNamedCastExpr(E); |
| 14410 |
} |
| 14411 |
|
| 14412 |
template<typename Derived> |
| 14413 |
ExprResult |
| 14414 |
TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 14415 |
return getDerived().TransformCXXNamedCastExpr(E); |
| 14416 |
} |
| 14417 |
|
| 14418 |
template<typename Derived> |
| 14419 |
ExprResult |
| 14420 |
TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
| 14421 |
CXXReinterpretCastExpr *E) { |
| 14422 |
return getDerived().TransformCXXNamedCastExpr(E); |
| 14423 |
} |
| 14424 |
|
| 14425 |
template<typename Derived> |
| 14426 |
ExprResult |
| 14427 |
TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 14428 |
return getDerived().TransformCXXNamedCastExpr(E); |
| 14429 |
} |
| 14430 |
|
| 14431 |
template<typename Derived> |
| 14432 |
ExprResult |
| 14433 |
TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) { |
| 14434 |
return getDerived().TransformCXXNamedCastExpr(E); |
| 14435 |
} |
| 14436 |
|
| 14437 |
template<typename Derived> |
| 14438 |
ExprResult |
| 14439 |
TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
| 14440 |
CXXFunctionalCastExpr *E) { |
| 14441 |
TypeSourceInfo *Type = |
| 14442 |
getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); |
| 14443 |
if (!Type) |
| 14444 |
return ExprError(); |
| 14445 |
|
| 14446 |
ExprResult SubExpr |
| 14447 |
= getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 14448 |
if (SubExpr.isInvalid()) |
| 14449 |
return ExprError(); |
| 14450 |
|
| 14451 |
if (!getDerived().AlwaysRebuild() && |
| 14452 |
Type == E->getTypeInfoAsWritten() && |
| 14453 |
SubExpr.get() == E->getSubExpr()) |
| 14454 |
return E; |
| 14455 |
|
| 14456 |
return getDerived().RebuildCXXFunctionalCastExpr(Type, |
| 14457 |
E->getLParenLoc(), |
| 14458 |
SubExpr.get(), |
| 14459 |
E->getRParenLoc(), |
| 14460 |
E->isListInitialization()); |
| 14461 |
} |
| 14462 |
|
| 14463 |
template<typename Derived> |
| 14464 |
ExprResult |
| 14465 |
TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
| 14466 |
if (E->isTypeOperand()) { |
| 14467 |
TypeSourceInfo *TInfo |
| 14468 |
= getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 14469 |
if (!TInfo) |
| 14470 |
return ExprError(); |
| 14471 |
|
| 14472 |
if (!getDerived().AlwaysRebuild() && |
| 14473 |
TInfo == E->getTypeOperandSourceInfo()) |
| 14474 |
return E; |
| 14475 |
|
| 14476 |
return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| 14477 |
TInfo, E->getEndLoc()); |
| 14478 |
} |
| 14479 |
|
| 14480 |
// Typeid's operand is an unevaluated context, unless it's a polymorphic |
| 14481 |
// type. We must not unilaterally enter unevaluated context here, as then |
| 14482 |
// semantic processing can re-transform an already transformed operand. |
| 14483 |
Expr *Op = E->getExprOperand(); |
| 14484 |
auto EvalCtx = Sema::ExpressionEvaluationContext::Unevaluated; |
| 14485 |
if (E->isGLValue()) |
| 14486 |
if (auto *RD = Op->getType()->getAsCXXRecordDecl(); |
| 14487 |
RD && RD->isPolymorphic()) |
| 14488 |
EvalCtx = SemaRef.ExprEvalContexts.back().Context; |
| 14489 |
|
| 14490 |
EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx, |
| 14491 |
Sema::ReuseLambdaContextDecl); |
| 14492 |
|
| 14493 |
ExprResult SubExpr = getDerived().TransformExpr(Op); |
| 14494 |
if (SubExpr.isInvalid()) |
| 14495 |
return ExprError(); |
| 14496 |
|
| 14497 |
if (!getDerived().AlwaysRebuild() && |
| 14498 |
SubExpr.get() == E->getExprOperand()) |
| 14499 |
return E; |
| 14500 |
|
| 14501 |
return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| 14502 |
SubExpr.get(), E->getEndLoc()); |
| 14503 |
} |
| 14504 |
|
| 14505 |
template<typename Derived> |
| 14506 |
ExprResult |
| 14507 |
TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 14508 |
if (E->isTypeOperand()) { |
| 14509 |
TypeSourceInfo *TInfo |
| 14510 |
= getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 14511 |
if (!TInfo) |
| 14512 |
return ExprError(); |
| 14513 |
|
| 14514 |
if (!getDerived().AlwaysRebuild() && |
| 14515 |
TInfo == E->getTypeOperandSourceInfo()) |
| 14516 |
return E; |
| 14517 |
|
| 14518 |
return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| 14519 |
TInfo, E->getEndLoc()); |
| 14520 |
} |
| 14521 |
|
| 14522 |
EnterExpressionEvaluationContext Unevaluated( |
| 14523 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 14524 |
|
| 14525 |
ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 14526 |
if (SubExpr.isInvalid()) |
| 14527 |
return ExprError(); |
| 14528 |
|
| 14529 |
if (!getDerived().AlwaysRebuild() && |
| 14530 |
SubExpr.get() == E->getExprOperand()) |
| 14531 |
return E; |
| 14532 |
|
| 14533 |
return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| 14534 |
SubExpr.get(), E->getEndLoc()); |
| 14535 |
} |
| 14536 |
|
| 14537 |
template<typename Derived> |
| 14538 |
ExprResult |
| 14539 |
TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 14540 |
return E; |
| 14541 |
} |
| 14542 |
|
| 14543 |
template<typename Derived> |
| 14544 |
ExprResult |
| 14545 |
TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
| 14546 |
CXXNullPtrLiteralExpr *E) { |
| 14547 |
return E; |
| 14548 |
} |
| 14549 |
|
| 14550 |
template<typename Derived> |
| 14551 |
ExprResult |
| 14552 |
TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| 14553 |
|
| 14554 |
// In lambdas, the qualifiers of the type depends of where in |
| 14555 |
// the call operator `this` appear, and we do not have a good way to |
| 14556 |
// rebuild this information, so we transform the type. |
| 14557 |
// |
| 14558 |
// In other contexts, the type of `this` may be overrided |
| 14559 |
// for type deduction, so we need to recompute it. |
| 14560 |
// |
| 14561 |
// Always recompute the type if we're in the body of a lambda, and |
| 14562 |
// 'this' is dependent on a lambda's explicit object parameter; we |
| 14563 |
// also need to always rebuild the expression in this case to clear |
| 14564 |
// the flag. |
| 14565 |
QualType T = [&]() { |
| 14566 |
auto &S = getSema(); |
| 14567 |
if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) |
| 14568 |
return S.getCurrentThisType(); |
| 14569 |
if (S.getCurLambda()) |
| 14570 |
return getDerived().TransformType(E->getType()); |
| 14571 |
return S.getCurrentThisType(); |
| 14572 |
}(); |
| 14573 |
|
| 14574 |
if (!getDerived().AlwaysRebuild() && T == E->getType() && |
| 14575 |
!E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) { |
| 14576 |
// Mark it referenced in the new context regardless. |
| 14577 |
// FIXME: this is a bit instantiation-specific. |
| 14578 |
getSema().MarkThisReferenced(E); |
| 14579 |
return E; |
| 14580 |
} |
| 14581 |
|
| 14582 |
return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); |
| 14583 |
} |
| 14584 |
|
| 14585 |
template<typename Derived> |
| 14586 |
ExprResult |
| 14587 |
TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
| 14588 |
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 14589 |
if (SubExpr.isInvalid()) |
| 14590 |
return ExprError(); |
| 14591 |
|
| 14592 |
getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false); |
| 14593 |
|
| 14594 |
if (!getDerived().AlwaysRebuild() && |
| 14595 |
SubExpr.get() == E->getSubExpr()) |
| 14596 |
return E; |
| 14597 |
|
| 14598 |
return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 14599 |
E->isThrownVariableInScope()); |
| 14600 |
} |
| 14601 |
|
| 14602 |
template<typename Derived> |
| 14603 |
ExprResult |
| 14604 |
TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 14605 |
ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 14606 |
getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); |
| 14607 |
if (!Param) |
| 14608 |
return ExprError(); |
| 14609 |
|
| 14610 |
ExprResult InitRes; |
| 14611 |
if (E->hasRewrittenInit()) { |
| 14612 |
InitRes = getDerived().TransformExpr(E->getRewrittenExpr()); |
| 14613 |
if (InitRes.isInvalid()) |
| 14614 |
return ExprError(); |
| 14615 |
} |
| 14616 |
|
| 14617 |
if (!getDerived().AlwaysRebuild() && Param == E->getParam() && |
| 14618 |
E->getUsedContext() == SemaRef.CurContext && |
| 14619 |
InitRes.get() == E->getRewrittenExpr()) |
| 14620 |
return E; |
| 14621 |
|
| 14622 |
return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param, |
| 14623 |
InitRes.get()); |
| 14624 |
} |
| 14625 |
|
| 14626 |
template<typename Derived> |
| 14627 |
ExprResult |
| 14628 |
TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 14629 |
FieldDecl *Field = cast_or_null<FieldDecl>( |
| 14630 |
getDerived().TransformDecl(E->getBeginLoc(), E->getField())); |
| 14631 |
if (!Field) |
| 14632 |
return ExprError(); |
| 14633 |
|
| 14634 |
if (!getDerived().AlwaysRebuild() && Field == E->getField() && |
| 14635 |
E->getUsedContext() == SemaRef.CurContext) |
| 14636 |
return E; |
| 14637 |
|
| 14638 |
return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 14639 |
} |
| 14640 |
|
| 14641 |
template<typename Derived> |
| 14642 |
ExprResult |
| 14643 |
TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 14644 |
CXXScalarValueInitExpr *E) { |
| 14645 |
TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 14646 |
if (!T) |
| 14647 |
return ExprError(); |
| 14648 |
|
| 14649 |
if (!getDerived().AlwaysRebuild() && |
| 14650 |
T == E->getTypeSourceInfo()) |
| 14651 |
return E; |
| 14652 |
|
| 14653 |
return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 14654 |
/*FIXME:*/T->getTypeLoc().getEndLoc(), |
| 14655 |
E->getRParenLoc()); |
| 14656 |
} |
| 14657 |
|
| 14658 |
template<typename Derived> |
| 14659 |
ExprResult |
| 14660 |
TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
| 14661 |
// Transform the type that we're allocating |
| 14662 |
TypeSourceInfo *AllocTypeInfo = |
| 14663 |
getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); |
| 14664 |
if (!AllocTypeInfo) |
| 14665 |
return ExprError(); |
| 14666 |
|
| 14667 |
// Transform the size of the array we're allocating (if any). |
| 14668 |
std::optional<Expr *> ArraySize; |
| 14669 |
if (E->isArray()) { |
| 14670 |
ExprResult NewArraySize; |
| 14671 |
if (std::optional<Expr *> OldArraySize = E->getArraySize()) { |
| 14672 |
NewArraySize = getDerived().TransformExpr(*OldArraySize); |
| 14673 |
if (NewArraySize.isInvalid()) |
| 14674 |
return ExprError(); |
| 14675 |
} |
| 14676 |
ArraySize = NewArraySize.get(); |
| 14677 |
} |
| 14678 |
|
| 14679 |
// Transform the placement arguments (if any). |
| 14680 |
bool ArgumentChanged = false; |
| 14681 |
SmallVector<Expr*, 8> PlacementArgs; |
| 14682 |
if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 14683 |
E->getNumPlacementArgs(), true, |
| 14684 |
PlacementArgs, &ArgumentChanged)) |
| 14685 |
return ExprError(); |
| 14686 |
|
| 14687 |
// Transform the initializer (if any). |
| 14688 |
Expr *OldInit = E->getInitializer(); |
| 14689 |
ExprResult NewInit; |
| 14690 |
if (OldInit) |
| 14691 |
NewInit = getDerived().TransformInitializer(OldInit, true); |
| 14692 |
if (NewInit.isInvalid()) |
| 14693 |
return ExprError(); |
| 14694 |
|
| 14695 |
// Transform new operator and delete operator. |
| 14696 |
FunctionDecl *OperatorNew = nullptr; |
| 14697 |
if (E->getOperatorNew()) { |
| 14698 |
OperatorNew = cast_or_null<FunctionDecl>( |
| 14699 |
getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); |
| 14700 |
if (!OperatorNew) |
| 14701 |
return ExprError(); |
| 14702 |
} |
| 14703 |
|
| 14704 |
FunctionDecl *OperatorDelete = nullptr; |
| 14705 |
if (E->getOperatorDelete()) { |
| 14706 |
OperatorDelete = cast_or_null<FunctionDecl>( |
| 14707 |
getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| 14708 |
if (!OperatorDelete) |
| 14709 |
return ExprError(); |
| 14710 |
} |
| 14711 |
|
| 14712 |
if (!getDerived().AlwaysRebuild() && |
| 14713 |
AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
| 14714 |
ArraySize == E->getArraySize() && |
| 14715 |
NewInit.get() == OldInit && |
| 14716 |
OperatorNew == E->getOperatorNew() && |
| 14717 |
OperatorDelete == E->getOperatorDelete() && |
| 14718 |
!ArgumentChanged) { |
| 14719 |
// Mark any declarations we need as referenced. |
| 14720 |
// FIXME: instantiation-specific. |
| 14721 |
if (OperatorNew) |
| 14722 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); |
| 14723 |
if (OperatorDelete) |
| 14724 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| 14725 |
|
| 14726 |
if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
| 14727 |
QualType ElementType |
| 14728 |
= SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 14729 |
if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) { |
| 14730 |
if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) |
| 14731 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); |
| 14732 |
} |
| 14733 |
} |
| 14734 |
|
| 14735 |
return E; |
| 14736 |
} |
| 14737 |
|
| 14738 |
QualType AllocType = AllocTypeInfo->getType(); |
| 14739 |
if (!ArraySize) { |
| 14740 |
// If no array size was specified, but the new expression was |
| 14741 |
// instantiated with an array type (e.g., "new T" where T is |
| 14742 |
// instantiated with "int[4]"), extract the outer bound from the |
| 14743 |
// array type as our array size. We do this with constant and |
| 14744 |
// dependently-sized array types. |
| 14745 |
const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 14746 |
if (!ArrayT) { |
| 14747 |
// Do nothing |
| 14748 |
} else if (const ConstantArrayType *ConsArrayT |
| 14749 |
= dyn_cast<ConstantArrayType>(ArrayT)) { |
| 14750 |
ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 14751 |
SemaRef.Context.getSizeType(), |
| 14752 |
/*FIXME:*/ E->getBeginLoc()); |
| 14753 |
AllocType = ConsArrayT->getElementType(); |
| 14754 |
} else if (const DependentSizedArrayType *DepArrayT |
| 14755 |
= dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 14756 |
if (DepArrayT->getSizeExpr()) { |
| 14757 |
ArraySize = DepArrayT->getSizeExpr(); |
| 14758 |
AllocType = DepArrayT->getElementType(); |
| 14759 |
} |
| 14760 |
} |
| 14761 |
} |
| 14762 |
|
| 14763 |
return getDerived().RebuildCXXNewExpr( |
| 14764 |
E->getBeginLoc(), E->isGlobalNew(), |
| 14765 |
/*FIXME:*/ E->getBeginLoc(), PlacementArgs, |
| 14766 |
/*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, |
| 14767 |
AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); |
| 14768 |
} |
| 14769 |
|
| 14770 |
template<typename Derived> |
| 14771 |
ExprResult |
| 14772 |
TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
| 14773 |
ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 14774 |
if (Operand.isInvalid()) |
| 14775 |
return ExprError(); |
| 14776 |
|
| 14777 |
// Transform the delete operator, if known. |
| 14778 |
FunctionDecl *OperatorDelete = nullptr; |
| 14779 |
if (E->getOperatorDelete()) { |
| 14780 |
OperatorDelete = cast_or_null<FunctionDecl>( |
| 14781 |
getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| 14782 |
if (!OperatorDelete) |
| 14783 |
return ExprError(); |
| 14784 |
} |
| 14785 |
|
| 14786 |
if (!getDerived().AlwaysRebuild() && |
| 14787 |
Operand.get() == E->getArgument() && |
| 14788 |
OperatorDelete == E->getOperatorDelete()) { |
| 14789 |
// Mark any declarations we need as referenced. |
| 14790 |
// FIXME: instantiation-specific. |
| 14791 |
if (OperatorDelete) |
| 14792 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| 14793 |
|
| 14794 |
if (!E->getArgument()->isTypeDependent()) { |
| 14795 |
QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 14796 |
E->getDestroyedType()); |
| 14797 |
if (auto *Record = Destroyed->getAsCXXRecordDecl()) |
| 14798 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| 14799 |
SemaRef.LookupDestructor(Record)); |
| 14800 |
} |
| 14801 |
|
| 14802 |
return E; |
| 14803 |
} |
| 14804 |
|
| 14805 |
return getDerived().RebuildCXXDeleteExpr( |
| 14806 |
E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); |
| 14807 |
} |
| 14808 |
|
| 14809 |
template<typename Derived> |
| 14810 |
ExprResult |
| 14811 |
TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| 14812 |
CXXPseudoDestructorExpr *E) { |
| 14813 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 14814 |
if (Base.isInvalid()) |
| 14815 |
return ExprError(); |
| 14816 |
|
| 14817 |
ParsedType ObjectTypePtr; |
| 14818 |
bool MayBePseudoDestructor = false; |
| 14819 |
Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| 14820 |
E->getOperatorLoc(), |
| 14821 |
E->isArrow()? tok::arrow : tok::period, |
| 14822 |
ObjectTypePtr, |
| 14823 |
MayBePseudoDestructor); |
| 14824 |
if (Base.isInvalid()) |
| 14825 |
return ExprError(); |
| 14826 |
|
| 14827 |
QualType ObjectType = ObjectTypePtr.get(); |
| 14828 |
NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 14829 |
if (QualifierLoc) { |
| 14830 |
QualifierLoc |
| 14831 |
= getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 14832 |
if (!QualifierLoc) |
| 14833 |
return ExprError(); |
| 14834 |
} |
| 14835 |
CXXScopeSpec SS; |
| 14836 |
SS.Adopt(QualifierLoc); |
| 14837 |
|
| 14838 |
PseudoDestructorTypeStorage Destroyed; |
| 14839 |
if (E->getDestroyedTypeInfo()) { |
| 14840 |
TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope( |
| 14841 |
E->getDestroyedTypeInfo(), ObjectType, |
| 14842 |
/*FirstQualifierInScope=*/nullptr); |
| 14843 |
if (!DestroyedTypeInfo) |
| 14844 |
return ExprError(); |
| 14845 |
Destroyed = DestroyedTypeInfo; |
| 14846 |
} else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
| 14847 |
// We aren't likely to be able to resolve the identifier down to a type |
| 14848 |
// now anyway, so just retain the identifier. |
| 14849 |
Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 14850 |
E->getDestroyedTypeLoc()); |
| 14851 |
} else { |
| 14852 |
// Look for a destructor known with the given name. |
| 14853 |
ParsedType T = SemaRef.getDestructorName( |
| 14854 |
*E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(), |
| 14855 |
/*Scope=*/nullptr, SS, ObjectTypePtr, false); |
| 14856 |
if (!T) |
| 14857 |
return ExprError(); |
| 14858 |
|
| 14859 |
Destroyed |
| 14860 |
= SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 14861 |
E->getDestroyedTypeLoc()); |
| 14862 |
} |
| 14863 |
|
| 14864 |
TypeSourceInfo *ScopeTypeInfo = nullptr; |
| 14865 |
if (E->getScopeTypeInfo()) { |
| 14866 |
ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 14867 |
E->getScopeTypeInfo(), ObjectType, nullptr); |
| 14868 |
if (!ScopeTypeInfo) |
| 14869 |
return ExprError(); |
| 14870 |
} |
| 14871 |
|
| 14872 |
return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
| 14873 |
E->getOperatorLoc(), |
| 14874 |
E->isArrow(), |
| 14875 |
SS, |
| 14876 |
ScopeTypeInfo, |
| 14877 |
E->getColonColonLoc(), |
| 14878 |
E->getTildeLoc(), |
| 14879 |
Destroyed); |
| 14880 |
} |
| 14881 |
|
| 14882 |
template <typename Derived> |
| 14883 |
bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, |
| 14884 |
bool RequiresADL, |
| 14885 |
LookupResult &R) { |
| 14886 |
// Transform all the decls. |
| 14887 |
bool AllEmptyPacks = true; |
| 14888 |
for (auto *OldD : Old->decls()) { |
| 14889 |
Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); |
| 14890 |
if (!InstD) { |
| 14891 |
// Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 14892 |
// This can happen because of dependent hiding. |
| 14893 |
if (isa<UsingShadowDecl>(OldD)) |
| 14894 |
continue; |
| 14895 |
else { |
| 14896 |
R.clear(); |
| 14897 |
return true; |
| 14898 |
} |
| 14899 |
} |
| 14900 |
|
| 14901 |
// Expand using pack declarations. |
| 14902 |
NamedDecl *SingleDecl = cast<NamedDecl>(InstD); |
| 14903 |
ArrayRef<NamedDecl*> Decls = SingleDecl; |
| 14904 |
if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) |
| 14905 |
Decls = UPD->expansions(); |
| 14906 |
|
| 14907 |
// Expand using declarations. |
| 14908 |
for (auto *D : Decls) { |
| 14909 |
if (auto *UD = dyn_cast<UsingDecl>(D)) { |
| 14910 |
for (auto *SD : UD->shadows()) |
| 14911 |
R.addDecl(SD); |
| 14912 |
} else { |
| 14913 |
R.addDecl(D); |
| 14914 |
} |
| 14915 |
} |
| 14916 |
|
| 14917 |
AllEmptyPacks &= Decls.empty(); |
| 14918 |
} |
| 14919 |
|
| 14920 |
// C++ [temp.res]/8.4.2: |
| 14921 |
// The program is ill-formed, no diagnostic required, if [...] lookup for |
| 14922 |
// a name in the template definition found a using-declaration, but the |
| 14923 |
// lookup in the corresponding scope in the instantiation odoes not find |
| 14924 |
// any declarations because the using-declaration was a pack expansion and |
| 14925 |
// the corresponding pack is empty |
| 14926 |
if (AllEmptyPacks && !RequiresADL) { |
| 14927 |
getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) |
| 14928 |
<< isa<UnresolvedMemberExpr>(Old) << Old->getName(); |
| 14929 |
return true; |
| 14930 |
} |
| 14931 |
|
| 14932 |
// Resolve a kind, but don't do any further analysis. If it's |
| 14933 |
// ambiguous, the callee needs to deal with it. |
| 14934 |
R.resolveKind(); |
| 14935 |
|
| 14936 |
if (Old->hasTemplateKeyword() && !R.empty()) { |
| 14937 |
NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl(); |
| 14938 |
getSema().FilterAcceptableTemplateNames(R, |
| 14939 |
/*AllowFunctionTemplates=*/true, |
| 14940 |
/*AllowDependent=*/true); |
| 14941 |
if (R.empty()) { |
| 14942 |
// If a 'template' keyword was used, a lookup that finds only non-template |
| 14943 |
// names is an error. |
| 14944 |
getSema().Diag(R.getNameLoc(), |
| 14945 |
diag::err_template_kw_refers_to_non_template) |
| 14946 |
<< R.getLookupName() << Old->getQualifierLoc().getSourceRange() |
| 14947 |
<< Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc(); |
| 14948 |
getSema().Diag(FoundDecl->getLocation(), |
| 14949 |
diag::note_template_kw_refers_to_non_template) |
| 14950 |
<< R.getLookupName(); |
| 14951 |
return true; |
| 14952 |
} |
| 14953 |
} |
| 14954 |
|
| 14955 |
return false; |
| 14956 |
} |
| 14957 |
|
| 14958 |
template <typename Derived> |
| 14959 |
ExprResult TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| 14960 |
UnresolvedLookupExpr *Old) { |
| 14961 |
return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false); |
| 14962 |
} |
| 14963 |
|
| 14964 |
template <typename Derived> |
| 14965 |
ExprResult |
| 14966 |
TreeTransform<Derived>::TransformUnresolvedLookupExpr(UnresolvedLookupExpr *Old, |
| 14967 |
bool IsAddressOfOperand) { |
| 14968 |
LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 14969 |
Sema::LookupOrdinaryName); |
| 14970 |
|
| 14971 |
// Transform the declaration set. |
| 14972 |
if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) |
| 14973 |
return ExprError(); |
| 14974 |
|
| 14975 |
// Rebuild the nested-name qualifier, if present. |
| 14976 |
CXXScopeSpec SS; |
| 14977 |
if (Old->getQualifierLoc()) { |
| 14978 |
NestedNameSpecifierLoc QualifierLoc |
| 14979 |
= getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 14980 |
if (!QualifierLoc) |
| 14981 |
return ExprError(); |
| 14982 |
|
| 14983 |
SS.Adopt(QualifierLoc); |
| 14984 |
} |
| 14985 |
|
| 14986 |
if (Old->getNamingClass()) { |
| 14987 |
CXXRecordDecl *NamingClass |
| 14988 |
= cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 14989 |
Old->getNameLoc(), |
| 14990 |
Old->getNamingClass())); |
| 14991 |
if (!NamingClass) { |
| 14992 |
R.clear(); |
| 14993 |
return ExprError(); |
| 14994 |
} |
| 14995 |
|
| 14996 |
R.setNamingClass(NamingClass); |
| 14997 |
} |
| 14998 |
|
| 14999 |
// Rebuild the template arguments, if any. |
| 15000 |
SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 15001 |
TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 15002 |
if (Old->hasExplicitTemplateArgs() && |
| 15003 |
getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 15004 |
Old->getNumTemplateArgs(), |
| 15005 |
TransArgs)) { |
| 15006 |
R.clear(); |
| 15007 |
return ExprError(); |
| 15008 |
} |
| 15009 |
|
| 15010 |
// An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when |
| 15011 |
// a non-static data member is named in an unevaluated operand, or when |
| 15012 |
// a member is named in a dependent class scope function template explicit |
| 15013 |
// specialization that is neither declared static nor with an explicit object |
| 15014 |
// parameter. |
| 15015 |
if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand)) |
| 15016 |
return SemaRef.BuildPossibleImplicitMemberExpr( |
| 15017 |
SS, TemplateKWLoc, R, |
| 15018 |
Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr, |
| 15019 |
/*S=*/nullptr); |
| 15020 |
|
| 15021 |
// If we have neither explicit template arguments, nor the template keyword, |
| 15022 |
// it's a normal declaration name or member reference. |
| 15023 |
if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) |
| 15024 |
return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 15025 |
|
| 15026 |
// If we have template arguments, then rebuild the template-id expression. |
| 15027 |
return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
| 15028 |
Old->requiresADL(), &TransArgs); |
| 15029 |
} |
| 15030 |
|
| 15031 |
template<typename Derived> |
| 15032 |
ExprResult |
| 15033 |
TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 15034 |
bool ArgChanged = false; |
| 15035 |
SmallVector<TypeSourceInfo *, 4> Args; |
| 15036 |
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 15037 |
TypeSourceInfo *From = E->getArg(I); |
| 15038 |
TypeLoc FromTL = From->getTypeLoc(); |
| 15039 |
if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
| 15040 |
TypeLocBuilder TLB; |
| 15041 |
TLB.reserve(FromTL.getFullDataSize()); |
| 15042 |
QualType To = getDerived().TransformType(TLB, FromTL); |
| 15043 |
if (To.isNull()) |
| 15044 |
return ExprError(); |
| 15045 |
|
| 15046 |
if (To == From->getType()) |
| 15047 |
Args.push_back(From); |
| 15048 |
else { |
| 15049 |
Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 15050 |
ArgChanged = true; |
| 15051 |
} |
| 15052 |
continue; |
| 15053 |
} |
| 15054 |
|
| 15055 |
ArgChanged = true; |
| 15056 |
|
| 15057 |
// We have a pack expansion. Instantiate it. |
| 15058 |
PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
| 15059 |
TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 15060 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 15061 |
SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| 15062 |
|
| 15063 |
// Determine whether the set of unexpanded parameter packs can and should |
| 15064 |
// be expanded. |
| 15065 |
bool Expand = true; |
| 15066 |
bool RetainExpansion = false; |
| 15067 |
UnsignedOrNone OrigNumExpansions = |
| 15068 |
ExpansionTL.getTypePtr()->getNumExpansions(); |
| 15069 |
UnsignedOrNone NumExpansions = OrigNumExpansions; |
| 15070 |
if (getDerived().TryExpandParameterPacks( |
| 15071 |
ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(), |
| 15072 |
Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand, |
| 15073 |
RetainExpansion, NumExpansions)) |
| 15074 |
return ExprError(); |
| 15075 |
|
| 15076 |
if (!Expand) { |
| 15077 |
// The transform has determined that we should perform a simple |
| 15078 |
// transformation on the pack expansion, producing another pack |
| 15079 |
// expansion. |
| 15080 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 15081 |
|
| 15082 |
TypeLocBuilder TLB; |
| 15083 |
TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 15084 |
|
| 15085 |
QualType To = getDerived().TransformType(TLB, PatternTL); |
| 15086 |
if (To.isNull()) |
| 15087 |
return ExprError(); |
| 15088 |
|
| 15089 |
To = getDerived().RebuildPackExpansionType(To, |
| 15090 |
PatternTL.getSourceRange(), |
| 15091 |
ExpansionTL.getEllipsisLoc(), |
| 15092 |
NumExpansions); |
| 15093 |
if (To.isNull()) |
| 15094 |
return ExprError(); |
| 15095 |
|
| 15096 |
PackExpansionTypeLoc ToExpansionTL |
| 15097 |
= TLB.push<PackExpansionTypeLoc>(To); |
| 15098 |
ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 15099 |
Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 15100 |
continue; |
| 15101 |
} |
| 15102 |
|
| 15103 |
// Expand the pack expansion by substituting for each argument in the |
| 15104 |
// pack(s). |
| 15105 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 15106 |
Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I); |
| 15107 |
TypeLocBuilder TLB; |
| 15108 |
TLB.reserve(PatternTL.getFullDataSize()); |
| 15109 |
QualType To = getDerived().TransformType(TLB, PatternTL); |
| 15110 |
if (To.isNull()) |
| 15111 |
return ExprError(); |
| 15112 |
|
| 15113 |
if (To->containsUnexpandedParameterPack()) { |
| 15114 |
To = getDerived().RebuildPackExpansionType(To, |
| 15115 |
PatternTL.getSourceRange(), |
| 15116 |
ExpansionTL.getEllipsisLoc(), |
| 15117 |
NumExpansions); |
| 15118 |
if (To.isNull()) |
| 15119 |
return ExprError(); |
| 15120 |
|
| 15121 |
PackExpansionTypeLoc ToExpansionTL |
| 15122 |
= TLB.push<PackExpansionTypeLoc>(To); |
| 15123 |
ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 15124 |
} |
| 15125 |
|
| 15126 |
Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 15127 |
} |
| 15128 |
|
| 15129 |
if (!RetainExpansion) |
| 15130 |
continue; |
| 15131 |
|
| 15132 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 15133 |
// forgetting the partially-substituted parameter pack. |
| 15134 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 15135 |
|
| 15136 |
TypeLocBuilder TLB; |
| 15137 |
TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 15138 |
|
| 15139 |
QualType To = getDerived().TransformType(TLB, PatternTL); |
| 15140 |
if (To.isNull()) |
| 15141 |
return ExprError(); |
| 15142 |
|
| 15143 |
To = getDerived().RebuildPackExpansionType(To, |
| 15144 |
PatternTL.getSourceRange(), |
| 15145 |
ExpansionTL.getEllipsisLoc(), |
| 15146 |
NumExpansions); |
| 15147 |
if (To.isNull()) |
| 15148 |
return ExprError(); |
| 15149 |
|
| 15150 |
PackExpansionTypeLoc ToExpansionTL |
| 15151 |
= TLB.push<PackExpansionTypeLoc>(To); |
| 15152 |
ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 15153 |
Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 15154 |
} |
| 15155 |
|
| 15156 |
if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 15157 |
return E; |
| 15158 |
|
| 15159 |
return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, |
| 15160 |
E->getEndLoc()); |
| 15161 |
} |
| 15162 |
|
| 15163 |
template<typename Derived> |
| 15164 |
ExprResult |
| 15165 |
TreeTransform<Derived>::TransformConceptSpecializationExpr( |
| 15166 |
ConceptSpecializationExpr *E) { |
| 15167 |
const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten(); |
| 15168 |
TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc); |
| 15169 |
if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 15170 |
Old->NumTemplateArgs, TransArgs)) |
| 15171 |
return ExprError(); |
| 15172 |
|
| 15173 |
return getDerived().RebuildConceptSpecializationExpr( |
| 15174 |
E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(), |
| 15175 |
E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(), |
| 15176 |
&TransArgs); |
| 15177 |
} |
| 15178 |
|
| 15179 |
template<typename Derived> |
| 15180 |
ExprResult |
| 15181 |
TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) { |
| 15182 |
SmallVector<ParmVarDecl*, 4> TransParams; |
| 15183 |
SmallVector<QualType, 4> TransParamTypes; |
| 15184 |
Sema::ExtParameterInfoBuilder ExtParamInfos; |
| 15185 |
|
| 15186 |
// C++2a [expr.prim.req]p2 |
| 15187 |
// Expressions appearing within a requirement-body are unevaluated operands. |
| 15188 |
EnterExpressionEvaluationContext Ctx( |
| 15189 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 15190 |
Sema::ReuseLambdaContextDecl); |
| 15191 |
|
| 15192 |
RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create( |
| 15193 |
getSema().Context, getSema().CurContext, |
| 15194 |
E->getBody()->getBeginLoc()); |
| 15195 |
|
| 15196 |
Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false); |
| 15197 |
|
| 15198 |
ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams( |
| 15199 |
E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body, |
| 15200 |
E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos); |
| 15201 |
|
| 15202 |
for (ParmVarDecl *Param : TransParams) |
| 15203 |
if (Param) |
| 15204 |
Param->setDeclContext(Body); |
| 15205 |
|
| 15206 |
// On failure to transform, TransformRequiresTypeParams returns an expression |
| 15207 |
// in the event that the transformation of the type params failed in some way. |
| 15208 |
// It is expected that this will result in a 'not satisfied' Requires clause |
| 15209 |
// when instantiating. |
| 15210 |
if (!TypeParamResult.isUnset()) |
| 15211 |
return TypeParamResult; |
| 15212 |
|
| 15213 |
SmallVector<concepts::Requirement *, 4> TransReqs; |
| 15214 |
if (getDerived().TransformRequiresExprRequirements(E->getRequirements(), |
| 15215 |
TransReqs)) |
| 15216 |
return ExprError(); |
| 15217 |
|
| 15218 |
for (concepts::Requirement *Req : TransReqs) { |
| 15219 |
if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) { |
| 15220 |
if (ER->getReturnTypeRequirement().isTypeConstraint()) { |
| 15221 |
ER->getReturnTypeRequirement() |
| 15222 |
.getTypeConstraintTemplateParameterList()->getParam(0) |
| 15223 |
->setDeclContext(Body); |
| 15224 |
} |
| 15225 |
} |
| 15226 |
} |
| 15227 |
|
| 15228 |
return getDerived().RebuildRequiresExpr( |
| 15229 |
E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams, |
| 15230 |
E->getRParenLoc(), TransReqs, E->getRBraceLoc()); |
| 15231 |
} |
| 15232 |
|
| 15233 |
template<typename Derived> |
| 15234 |
bool TreeTransform<Derived>::TransformRequiresExprRequirements( |
| 15235 |
ArrayRef<concepts::Requirement *> Reqs, |
| 15236 |
SmallVectorImpl<concepts::Requirement *> &Transformed) { |
| 15237 |
for (concepts::Requirement *Req : Reqs) { |
| 15238 |
concepts::Requirement *TransReq = nullptr; |
| 15239 |
if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) |
| 15240 |
TransReq = getDerived().TransformTypeRequirement(TypeReq); |
| 15241 |
else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) |
| 15242 |
TransReq = getDerived().TransformExprRequirement(ExprReq); |
| 15243 |
else |
| 15244 |
TransReq = getDerived().TransformNestedRequirement( |
| 15245 |
cast<concepts::NestedRequirement>(Req)); |
| 15246 |
if (!TransReq) |
| 15247 |
return true; |
| 15248 |
Transformed.push_back(TransReq); |
| 15249 |
} |
| 15250 |
return false; |
| 15251 |
} |
| 15252 |
|
| 15253 |
template<typename Derived> |
| 15254 |
concepts::TypeRequirement * |
| 15255 |
TreeTransform<Derived>::TransformTypeRequirement( |
| 15256 |
concepts::TypeRequirement *Req) { |
| 15257 |
if (Req->isSubstitutionFailure()) { |
| 15258 |
if (getDerived().AlwaysRebuild()) |
| 15259 |
return getDerived().RebuildTypeRequirement( |
| 15260 |
Req->getSubstitutionDiagnostic()); |
| 15261 |
return Req; |
| 15262 |
} |
| 15263 |
TypeSourceInfo *TransType = getDerived().TransformType(Req->getType()); |
| 15264 |
if (!TransType) |
| 15265 |
return nullptr; |
| 15266 |
return getDerived().RebuildTypeRequirement(TransType); |
| 15267 |
} |
| 15268 |
|
| 15269 |
template<typename Derived> |
| 15270 |
concepts::ExprRequirement * |
| 15271 |
TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) { |
| 15272 |
llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr; |
| 15273 |
if (Req->isExprSubstitutionFailure()) |
| 15274 |
TransExpr = Req->getExprSubstitutionDiagnostic(); |
| 15275 |
else { |
| 15276 |
ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr()); |
| 15277 |
if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType()) |
| 15278 |
TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get()); |
| 15279 |
if (TransExprRes.isInvalid()) |
| 15280 |
return nullptr; |
| 15281 |
TransExpr = TransExprRes.get(); |
| 15282 |
} |
| 15283 |
|
| 15284 |
std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; |
| 15285 |
const auto &RetReq = Req->getReturnTypeRequirement(); |
| 15286 |
if (RetReq.isEmpty()) |
| 15287 |
TransRetReq.emplace(); |
| 15288 |
else if (RetReq.isSubstitutionFailure()) |
| 15289 |
TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); |
| 15290 |
else if (RetReq.isTypeConstraint()) { |
| 15291 |
TemplateParameterList *OrigTPL = |
| 15292 |
RetReq.getTypeConstraintTemplateParameterList(); |
| 15293 |
TemplateParameterList *TPL = |
| 15294 |
getDerived().TransformTemplateParameterList(OrigTPL); |
| 15295 |
if (!TPL) |
| 15296 |
return nullptr; |
| 15297 |
TransRetReq.emplace(TPL); |
| 15298 |
} |
| 15299 |
assert(TransRetReq && "All code paths leading here must set TransRetReq"); |
| 15300 |
if (Expr *E = dyn_cast<Expr *>(TransExpr)) |
| 15301 |
return getDerived().RebuildExprRequirement(E, Req->isSimple(), |
| 15302 |
Req->getNoexceptLoc(), |
| 15303 |
std::move(*TransRetReq)); |
| 15304 |
return getDerived().RebuildExprRequirement( |
| 15305 |
cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr), |
| 15306 |
Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); |
| 15307 |
} |
| 15308 |
|
| 15309 |
template<typename Derived> |
| 15310 |
concepts::NestedRequirement * |
| 15311 |
TreeTransform<Derived>::TransformNestedRequirement( |
| 15312 |
concepts::NestedRequirement *Req) { |
| 15313 |
if (Req->hasInvalidConstraint()) { |
| 15314 |
if (getDerived().AlwaysRebuild()) |
| 15315 |
return getDerived().RebuildNestedRequirement( |
| 15316 |
Req->getInvalidConstraintEntity(), Req->getConstraintSatisfaction()); |
| 15317 |
return Req; |
| 15318 |
} |
| 15319 |
ExprResult TransConstraint = |
| 15320 |
getDerived().TransformExpr(Req->getConstraintExpr()); |
| 15321 |
if (TransConstraint.isInvalid()) |
| 15322 |
return nullptr; |
| 15323 |
return getDerived().RebuildNestedRequirement(TransConstraint.get()); |
| 15324 |
} |
| 15325 |
|
| 15326 |
template<typename Derived> |
| 15327 |
ExprResult |
| 15328 |
TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 15329 |
TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 15330 |
if (!T) |
| 15331 |
return ExprError(); |
| 15332 |
|
| 15333 |
if (!getDerived().AlwaysRebuild() && |
| 15334 |
T == E->getQueriedTypeSourceInfo()) |
| 15335 |
return E; |
| 15336 |
|
| 15337 |
ExprResult SubExpr; |
| 15338 |
{ |
| 15339 |
EnterExpressionEvaluationContext Unevaluated( |
| 15340 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 15341 |
SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 15342 |
if (SubExpr.isInvalid()) |
| 15343 |
return ExprError(); |
| 15344 |
} |
| 15345 |
|
| 15346 |
return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, |
| 15347 |
SubExpr.get(), E->getEndLoc()); |
| 15348 |
} |
| 15349 |
|
| 15350 |
template<typename Derived> |
| 15351 |
ExprResult |
| 15352 |
TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 15353 |
ExprResult SubExpr; |
| 15354 |
{ |
| 15355 |
EnterExpressionEvaluationContext Unevaluated( |
| 15356 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 15357 |
SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 15358 |
if (SubExpr.isInvalid()) |
| 15359 |
return ExprError(); |
| 15360 |
|
| 15361 |
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 15362 |
return E; |
| 15363 |
} |
| 15364 |
|
| 15365 |
return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), |
| 15366 |
SubExpr.get(), E->getEndLoc()); |
| 15367 |
} |
| 15368 |
|
| 15369 |
template <typename Derived> |
| 15370 |
ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 15371 |
ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 15372 |
TypeSourceInfo **RecoveryTSI) { |
| 15373 |
ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 15374 |
DRE, AddrTaken, RecoveryTSI); |
| 15375 |
|
| 15376 |
// Propagate both errors and recovered types, which return ExprEmpty. |
| 15377 |
if (!NewDRE.isUsable()) |
| 15378 |
return NewDRE; |
| 15379 |
|
| 15380 |
// We got an expr, wrap it up in parens. |
| 15381 |
if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 15382 |
return PE; |
| 15383 |
return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 15384 |
PE->getRParen()); |
| 15385 |
} |
| 15386 |
|
| 15387 |
template <typename Derived> |
| 15388 |
ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 15389 |
DependentScopeDeclRefExpr *E) { |
| 15390 |
return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 15391 |
nullptr); |
| 15392 |
} |
| 15393 |
|
| 15394 |
template <typename Derived> |
| 15395 |
ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 15396 |
DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, |
| 15397 |
TypeSourceInfo **RecoveryTSI) { |
| 15398 |
assert(E->getQualifierLoc()); |
| 15399 |
NestedNameSpecifierLoc QualifierLoc = |
| 15400 |
getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 15401 |
if (!QualifierLoc) |
| 15402 |
return ExprError(); |
| 15403 |
SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 15404 |
|
| 15405 |
// TODO: If this is a conversion-function-id, verify that the |
| 15406 |
// destination type name (if present) resolves the same way after |
| 15407 |
// instantiation as it did in the local scope. |
| 15408 |
|
| 15409 |
DeclarationNameInfo NameInfo = |
| 15410 |
getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 15411 |
if (!NameInfo.getName()) |
| 15412 |
return ExprError(); |
| 15413 |
|
| 15414 |
if (!E->hasExplicitTemplateArgs()) { |
| 15415 |
if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() && |
| 15416 |
// Note: it is sufficient to compare the Name component of NameInfo: |
| 15417 |
// if name has not changed, DNLoc has not changed either. |
| 15418 |
NameInfo.getName() == E->getDeclName()) |
| 15419 |
return E; |
| 15420 |
|
| 15421 |
return getDerived().RebuildDependentScopeDeclRefExpr( |
| 15422 |
QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 15423 |
IsAddressOfOperand, RecoveryTSI); |
| 15424 |
} |
| 15425 |
|
| 15426 |
TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| 15427 |
if (getDerived().TransformTemplateArguments( |
| 15428 |
E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs)) |
| 15429 |
return ExprError(); |
| 15430 |
|
| 15431 |
return getDerived().RebuildDependentScopeDeclRefExpr( |
| 15432 |
QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 15433 |
RecoveryTSI); |
| 15434 |
} |
| 15435 |
|
| 15436 |
template<typename Derived> |
| 15437 |
ExprResult |
| 15438 |
TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
| 15439 |
// CXXConstructExprs other than for list-initialization and |
| 15440 |
// CXXTemporaryObjectExpr are always implicit, so when we have |
| 15441 |
// a 1-argument construction we just transform that argument. |
| 15442 |
if (getDerived().AllowSkippingCXXConstructExpr() && |
| 15443 |
((E->getNumArgs() == 1 || |
| 15444 |
(E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| 15445 |
(!getDerived().DropCallArgument(E->getArg(0))) && |
| 15446 |
!E->isListInitialization())) |
| 15447 |
return getDerived().TransformInitializer(E->getArg(0), |
| 15448 |
/*DirectInit*/ false); |
| 15449 |
|
| 15450 |
TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); |
| 15451 |
|
| 15452 |
QualType T = getDerived().TransformType(E->getType()); |
| 15453 |
if (T.isNull()) |
| 15454 |
return ExprError(); |
| 15455 |
|
| 15456 |
CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 15457 |
getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 15458 |
if (!Constructor) |
| 15459 |
return ExprError(); |
| 15460 |
|
| 15461 |
bool ArgumentChanged = false; |
| 15462 |
SmallVector<Expr*, 8> Args; |
| 15463 |
{ |
| 15464 |
EnterExpressionEvaluationContext Context( |
| 15465 |
getSema(), EnterExpressionEvaluationContext::InitList, |
| 15466 |
E->isListInitialization()); |
| 15467 |
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 15468 |
&ArgumentChanged)) |
| 15469 |
return ExprError(); |
| 15470 |
} |
| 15471 |
|
| 15472 |
if (!getDerived().AlwaysRebuild() && |
| 15473 |
T == E->getType() && |
| 15474 |
Constructor == E->getConstructor() && |
| 15475 |
!ArgumentChanged) { |
| 15476 |
// Mark the constructor as referenced. |
| 15477 |
// FIXME: Instantiation-specific |
| 15478 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 15479 |
return E; |
| 15480 |
} |
| 15481 |
|
| 15482 |
return getDerived().RebuildCXXConstructExpr( |
| 15483 |
T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, |
| 15484 |
E->hadMultipleCandidates(), E->isListInitialization(), |
| 15485 |
E->isStdInitListInitialization(), E->requiresZeroInitialization(), |
| 15486 |
E->getConstructionKind(), E->getParenOrBraceRange()); |
| 15487 |
} |
| 15488 |
|
| 15489 |
template<typename Derived> |
| 15490 |
ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 15491 |
CXXInheritedCtorInitExpr *E) { |
| 15492 |
QualType T = getDerived().TransformType(E->getType()); |
| 15493 |
if (T.isNull()) |
| 15494 |
return ExprError(); |
| 15495 |
|
| 15496 |
CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 15497 |
getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 15498 |
if (!Constructor) |
| 15499 |
return ExprError(); |
| 15500 |
|
| 15501 |
if (!getDerived().AlwaysRebuild() && |
| 15502 |
T == E->getType() && |
| 15503 |
Constructor == E->getConstructor()) { |
| 15504 |
// Mark the constructor as referenced. |
| 15505 |
// FIXME: Instantiation-specific |
| 15506 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 15507 |
return E; |
| 15508 |
} |
| 15509 |
|
| 15510 |
return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 15511 |
T, E->getLocation(), Constructor, |
| 15512 |
E->constructsVBase(), E->inheritedFromVBase()); |
| 15513 |
} |
| 15514 |
|
| 15515 |
/// Transform a C++ temporary-binding expression. |
| 15516 |
/// |
| 15517 |
/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 15518 |
/// transform the subexpression and return that. |
| 15519 |
template<typename Derived> |
| 15520 |
ExprResult |
| 15521 |
TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 15522 |
if (auto *Dtor = E->getTemporary()->getDestructor()) |
| 15523 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| 15524 |
const_cast<CXXDestructorDecl *>(Dtor)); |
| 15525 |
return getDerived().TransformExpr(E->getSubExpr()); |
| 15526 |
} |
| 15527 |
|
| 15528 |
/// Transform a C++ expression that contains cleanups that should |
| 15529 |
/// be run after the expression is evaluated. |
| 15530 |
/// |
| 15531 |
/// Since ExprWithCleanups nodes are implicitly generated, we |
| 15532 |
/// just transform the subexpression and return that. |
| 15533 |
template<typename Derived> |
| 15534 |
ExprResult |
| 15535 |
TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
| 15536 |
return getDerived().TransformExpr(E->getSubExpr()); |
| 15537 |
} |
| 15538 |
|
| 15539 |
template<typename Derived> |
| 15540 |
ExprResult |
| 15541 |
TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
| 15542 |
CXXTemporaryObjectExpr *E) { |
| 15543 |
TypeSourceInfo *T = |
| 15544 |
getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| 15545 |
if (!T) |
| 15546 |
return ExprError(); |
| 15547 |
|
| 15548 |
CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 15549 |
getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 15550 |
if (!Constructor) |
| 15551 |
return ExprError(); |
| 15552 |
|
| 15553 |
bool ArgumentChanged = false; |
| 15554 |
SmallVector<Expr*, 8> Args; |
| 15555 |
Args.reserve(E->getNumArgs()); |
| 15556 |
{ |
| 15557 |
EnterExpressionEvaluationContext Context( |
| 15558 |
getSema(), EnterExpressionEvaluationContext::InitList, |
| 15559 |
E->isListInitialization()); |
| 15560 |
if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 15561 |
&ArgumentChanged)) |
| 15562 |
return ExprError(); |
| 15563 |
|
| 15564 |
if (E->isListInitialization() && !E->isStdInitListInitialization()) { |
| 15565 |
ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc()); |
| 15566 |
if (Res.isInvalid()) |
| 15567 |
return ExprError(); |
| 15568 |
Args = {Res.get()}; |
| 15569 |
} |
| 15570 |
} |
| 15571 |
|
| 15572 |
if (!getDerived().AlwaysRebuild() && |
| 15573 |
T == E->getTypeSourceInfo() && |
| 15574 |
Constructor == E->getConstructor() && |
| 15575 |
!ArgumentChanged) { |
| 15576 |
// FIXME: Instantiation-specific |
| 15577 |
SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 15578 |
return SemaRef.MaybeBindToTemporary(E); |
| 15579 |
} |
| 15580 |
|
| 15581 |
SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); |
| 15582 |
return getDerived().RebuildCXXTemporaryObjectExpr( |
| 15583 |
T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization()); |
| 15584 |
} |
| 15585 |
|
| 15586 |
template<typename Derived> |
| 15587 |
ExprResult |
| 15588 |
TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
| 15589 |
// Transform any init-capture expressions before entering the scope of the |
| 15590 |
// lambda body, because they are not semantically within that scope. |
| 15591 |
typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
| 15592 |
struct TransformedInitCapture { |
| 15593 |
// The location of the ... if the result is retaining a pack expansion. |
| 15594 |
SourceLocation EllipsisLoc; |
| 15595 |
// Zero or more expansions of the init-capture. |
| 15596 |
SmallVector<InitCaptureInfoTy, 4> Expansions; |
| 15597 |
}; |
| 15598 |
SmallVector<TransformedInitCapture, 4> InitCaptures; |
| 15599 |
InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); |
| 15600 |
for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 15601 |
CEnd = E->capture_end(); |
| 15602 |
C != CEnd; ++C) { |
| 15603 |
if (!E->isInitCapture(C)) |
| 15604 |
continue; |
| 15605 |
|
| 15606 |
TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; |
| 15607 |
auto *OldVD = cast<VarDecl>(C->getCapturedVar()); |
| 15608 |
|
| 15609 |
auto SubstInitCapture = [&](SourceLocation EllipsisLoc, |
| 15610 |
UnsignedOrNone NumExpansions) { |
| 15611 |
ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 15612 |
OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); |
| 15613 |
|
| 15614 |
if (NewExprInitResult.isInvalid()) { |
| 15615 |
Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); |
| 15616 |
return; |
| 15617 |
} |
| 15618 |
Expr *NewExprInit = NewExprInitResult.get(); |
| 15619 |
|
| 15620 |
QualType NewInitCaptureType = |
| 15621 |
getSema().buildLambdaInitCaptureInitialization( |
| 15622 |
C->getLocation(), C->getCaptureKind() == LCK_ByRef, |
| 15623 |
EllipsisLoc, NumExpansions, OldVD->getIdentifier(), |
| 15624 |
cast<VarDecl>(C->getCapturedVar())->getInitStyle() != |
| 15625 |
VarDecl::CInit, |
| 15626 |
NewExprInit); |
| 15627 |
Result.Expansions.push_back( |
| 15628 |
InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); |
| 15629 |
}; |
| 15630 |
|
| 15631 |
// If this is an init-capture pack, consider expanding the pack now. |
| 15632 |
if (OldVD->isParameterPack()) { |
| 15633 |
PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() |
| 15634 |
->getTypeLoc() |
| 15635 |
.castAs<PackExpansionTypeLoc>(); |
| 15636 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 15637 |
SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); |
| 15638 |
|
| 15639 |
// Determine whether the set of unexpanded parameter packs can and should |
| 15640 |
// be expanded. |
| 15641 |
bool Expand = true; |
| 15642 |
bool RetainExpansion = false; |
| 15643 |
UnsignedOrNone OrigNumExpansions = |
| 15644 |
ExpansionTL.getTypePtr()->getNumExpansions(); |
| 15645 |
UnsignedOrNone NumExpansions = OrigNumExpansions; |
| 15646 |
if (getDerived().TryExpandParameterPacks( |
| 15647 |
ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(), |
| 15648 |
Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand, |
| 15649 |
RetainExpansion, NumExpansions)) |
| 15650 |
return ExprError(); |
| 15651 |
assert(!RetainExpansion && "Should not need to retain expansion after a " |
| 15652 |
"capture since it cannot be extended"); |
| 15653 |
if (Expand) { |
| 15654 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 15655 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 15656 |
SubstInitCapture(SourceLocation(), std::nullopt); |
| 15657 |
} |
| 15658 |
} else { |
| 15659 |
SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); |
| 15660 |
Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); |
| 15661 |
} |
| 15662 |
} else { |
| 15663 |
SubstInitCapture(SourceLocation(), std::nullopt); |
| 15664 |
} |
| 15665 |
} |
| 15666 |
|
| 15667 |
LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 15668 |
Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 15669 |
|
| 15670 |
// Create the local class that will describe the lambda. |
| 15671 |
|
| 15672 |
// FIXME: DependencyKind below is wrong when substituting inside a templated |
| 15673 |
// context that isn't a DeclContext (such as a variable template), or when |
| 15674 |
// substituting an unevaluated lambda inside of a function's parameter's type |
| 15675 |
// - as parameter types are not instantiated from within a function's DC. We |
| 15676 |
// use evaluation contexts to distinguish the function parameter case. |
| 15677 |
CXXRecordDecl::LambdaDependencyKind DependencyKind = |
| 15678 |
CXXRecordDecl::LDK_Unknown; |
| 15679 |
DeclContext *DC = getSema().CurContext; |
| 15680 |
// A RequiresExprBodyDecl is not interesting for dependencies. |
| 15681 |
// For the following case, |
| 15682 |
// |
| 15683 |
// template <typename> |
| 15684 |
// concept C = requires { [] {}; }; |
| 15685 |
// |
| 15686 |
// template <class F> |
| 15687 |
// struct Widget; |
| 15688 |
// |
| 15689 |
// template <C F> |
| 15690 |
// struct Widget<F> {}; |
| 15691 |
// |
| 15692 |
// While we are substituting Widget<F>, the parent of DC would be |
| 15693 |
// the template specialization itself. Thus, the lambda expression |
| 15694 |
// will be deemed as dependent even if there are no dependent template |
| 15695 |
// arguments. |
| 15696 |
// (A ClassTemplateSpecializationDecl is always a dependent context.) |
| 15697 |
while (DC->isRequiresExprBody()) |
| 15698 |
DC = DC->getParent(); |
| 15699 |
if ((getSema().isUnevaluatedContext() || |
| 15700 |
getSema().isConstantEvaluatedContext()) && |
| 15701 |
!(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) && |
| 15702 |
cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) && |
| 15703 |
(DC->isFileContext() || !DC->getParent()->isDependentContext())) |
| 15704 |
DependencyKind = CXXRecordDecl::LDK_NeverDependent; |
| 15705 |
|
| 15706 |
CXXRecordDecl *OldClass = E->getLambdaClass(); |
| 15707 |
CXXRecordDecl *Class = getSema().createLambdaClosureType( |
| 15708 |
E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind, |
| 15709 |
E->getCaptureDefault()); |
| 15710 |
getDerived().transformedLocalDecl(OldClass, {Class}); |
| 15711 |
|
| 15712 |
CXXMethodDecl *NewCallOperator = |
| 15713 |
getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class); |
| 15714 |
|
| 15715 |
// Enter the scope of the lambda. |
| 15716 |
getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(), |
| 15717 |
E->getCaptureDefault(), E->getCaptureDefaultLoc(), |
| 15718 |
E->hasExplicitParameters(), E->isMutable()); |
| 15719 |
|
| 15720 |
// Introduce the context of the call operator. |
| 15721 |
Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
| 15722 |
/*NewThisContext*/false); |
| 15723 |
|
| 15724 |
bool Invalid = false; |
| 15725 |
|
| 15726 |
// Transform captures. |
| 15727 |
for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 15728 |
CEnd = E->capture_end(); |
| 15729 |
C != CEnd; ++C) { |
| 15730 |
// When we hit the first implicit capture, tell Sema that we've finished |
| 15731 |
// the list of explicit captures. |
| 15732 |
if (C->isImplicit()) |
| 15733 |
break; |
| 15734 |
|
| 15735 |
// Capturing 'this' is trivial. |
| 15736 |
if (C->capturesThis()) { |
| 15737 |
// If this is a lambda that is part of a default member initialiser |
| 15738 |
// and which we're instantiating outside the class that 'this' is |
| 15739 |
// supposed to refer to, adjust the type of 'this' accordingly. |
| 15740 |
// |
| 15741 |
// Otherwise, leave the type of 'this' as-is. |
| 15742 |
Sema::CXXThisScopeRAII ThisScope( |
| 15743 |
getSema(), |
| 15744 |
dyn_cast_if_present<CXXRecordDecl>( |
| 15745 |
getSema().getFunctionLevelDeclContext()), |
| 15746 |
Qualifiers()); |
| 15747 |
getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 15748 |
/*BuildAndDiagnose*/ true, nullptr, |
| 15749 |
C->getCaptureKind() == LCK_StarThis); |
| 15750 |
continue; |
| 15751 |
} |
| 15752 |
// Captured expression will be recaptured during captured variables |
| 15753 |
// rebuilding. |
| 15754 |
if (C->capturesVLAType()) |
| 15755 |
continue; |
| 15756 |
|
| 15757 |
// Rebuild init-captures, including the implied field declaration. |
| 15758 |
if (E->isInitCapture(C)) { |
| 15759 |
TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; |
| 15760 |
|
| 15761 |
auto *OldVD = cast<VarDecl>(C->getCapturedVar()); |
| 15762 |
llvm::SmallVector<Decl*, 4> NewVDs; |
| 15763 |
|
| 15764 |
for (InitCaptureInfoTy &Info : NewC.Expansions) { |
| 15765 |
ExprResult Init = Info.first; |
| 15766 |
QualType InitQualType = Info.second; |
| 15767 |
if (Init.isInvalid() || InitQualType.isNull()) { |
| 15768 |
Invalid = true; |
| 15769 |
break; |
| 15770 |
} |
| 15771 |
VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 15772 |
OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, |
| 15773 |
OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(), |
| 15774 |
getSema().CurContext); |
| 15775 |
if (!NewVD) { |
| 15776 |
Invalid = true; |
| 15777 |
break; |
| 15778 |
} |
| 15779 |
NewVDs.push_back(NewVD); |
| 15780 |
getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef); |
| 15781 |
// Cases we want to tackle: |
| 15782 |
// ([C(Pack)] {}, ...) |
| 15783 |
// But rule out cases e.g. |
| 15784 |
// [...C = Pack()] {} |
| 15785 |
if (NewC.EllipsisLoc.isInvalid()) |
| 15786 |
LSI->ContainsUnexpandedParameterPack |= |
| 15787 |
Init.get()->containsUnexpandedParameterPack(); |
| 15788 |
} |
| 15789 |
|
| 15790 |
if (Invalid) |
| 15791 |
break; |
| 15792 |
|
| 15793 |
getDerived().transformedLocalDecl(OldVD, NewVDs); |
| 15794 |
continue; |
| 15795 |
} |
| 15796 |
|
| 15797 |
assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 15798 |
|
| 15799 |
// Determine the capture kind for Sema. |
| 15800 |
TryCaptureKind Kind = C->isImplicit() ? TryCaptureKind::Implicit |
| 15801 |
: C->getCaptureKind() == LCK_ByCopy |
| 15802 |
? TryCaptureKind::ExplicitByVal |
| 15803 |
: TryCaptureKind::ExplicitByRef; |
| 15804 |
SourceLocation EllipsisLoc; |
| 15805 |
if (C->isPackExpansion()) { |
| 15806 |
UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 15807 |
bool ShouldExpand = false; |
| 15808 |
bool RetainExpansion = false; |
| 15809 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 15810 |
if (getDerived().TryExpandParameterPacks( |
| 15811 |
C->getEllipsisLoc(), C->getLocation(), Unexpanded, |
| 15812 |
/*FailOnPackProducingTemplates=*/true, ShouldExpand, |
| 15813 |
RetainExpansion, NumExpansions)) { |
| 15814 |
Invalid = true; |
| 15815 |
continue; |
| 15816 |
} |
| 15817 |
|
| 15818 |
if (ShouldExpand) { |
| 15819 |
// The transform has determined that we should perform an expansion; |
| 15820 |
// transform and capture each of the arguments. |
| 15821 |
// expansion of the pattern. Do so. |
| 15822 |
auto *Pack = cast<ValueDecl>(C->getCapturedVar()); |
| 15823 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 15824 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 15825 |
ValueDecl *CapturedVar = cast_if_present<ValueDecl>( |
| 15826 |
getDerived().TransformDecl(C->getLocation(), Pack)); |
| 15827 |
if (!CapturedVar) { |
| 15828 |
Invalid = true; |
| 15829 |
continue; |
| 15830 |
} |
| 15831 |
|
| 15832 |
// Capture the transformed variable. |
| 15833 |
getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 15834 |
} |
| 15835 |
|
| 15836 |
// FIXME: Retain a pack expansion if RetainExpansion is true. |
| 15837 |
|
| 15838 |
continue; |
| 15839 |
} |
| 15840 |
|
| 15841 |
EllipsisLoc = C->getEllipsisLoc(); |
| 15842 |
} |
| 15843 |
|
| 15844 |
// Transform the captured variable. |
| 15845 |
auto *CapturedVar = cast_or_null<ValueDecl>( |
| 15846 |
getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); |
| 15847 |
if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
| 15848 |
Invalid = true; |
| 15849 |
continue; |
| 15850 |
} |
| 15851 |
|
| 15852 |
// This is not an init-capture; however it contains an unexpanded pack e.g. |
| 15853 |
// ([Pack] {}(), ...) |
| 15854 |
if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion()) |
| 15855 |
LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack(); |
| 15856 |
|
| 15857 |
// Capture the transformed variable. |
| 15858 |
getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 15859 |
EllipsisLoc); |
| 15860 |
} |
| 15861 |
getSema().finishLambdaExplicitCaptures(LSI); |
| 15862 |
|
| 15863 |
// Transform the template parameters, and add them to the current |
| 15864 |
// instantiation scope. The null case is handled correctly. |
| 15865 |
auto TPL = getDerived().TransformTemplateParameterList( |
| 15866 |
E->getTemplateParameterList()); |
| 15867 |
LSI->GLTemplateParameterList = TPL; |
| 15868 |
if (TPL) { |
| 15869 |
getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class, |
| 15870 |
TPL); |
| 15871 |
LSI->ContainsUnexpandedParameterPack |= |
| 15872 |
TPL->containsUnexpandedParameterPack(); |
| 15873 |
} |
| 15874 |
|
| 15875 |
TypeLocBuilder NewCallOpTLBuilder; |
| 15876 |
TypeLoc OldCallOpTypeLoc = |
| 15877 |
E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); |
| 15878 |
QualType NewCallOpType = |
| 15879 |
getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc); |
| 15880 |
if (NewCallOpType.isNull()) |
| 15881 |
return ExprError(); |
| 15882 |
LSI->ContainsUnexpandedParameterPack |= |
| 15883 |
NewCallOpType->containsUnexpandedParameterPack(); |
| 15884 |
TypeSourceInfo *NewCallOpTSI = |
| 15885 |
NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType); |
| 15886 |
|
| 15887 |
// The type may be an AttributedType or some other kind of sugar; |
| 15888 |
// get the actual underlying FunctionProtoType. |
| 15889 |
auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>(); |
| 15890 |
assert(FPTL && "Not a FunctionProtoType?"); |
| 15891 |
|
| 15892 |
AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause(); |
| 15893 |
// If the concept refers to any outer parameter packs, we track the SubstIndex |
| 15894 |
// for evaluation. |
| 15895 |
if (TRC && TRC.ConstraintExpr->containsUnexpandedParameterPack() && |
| 15896 |
!TRC.ArgPackSubstIndex) |
| 15897 |
TRC.ArgPackSubstIndex = SemaRef.ArgPackSubstIndex; |
| 15898 |
|
| 15899 |
getSema().CompleteLambdaCallOperator( |
| 15900 |
NewCallOperator, E->getCallOperator()->getLocation(), |
| 15901 |
E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI, |
| 15902 |
E->getCallOperator()->getConstexprKind(), |
| 15903 |
E->getCallOperator()->getStorageClass(), FPTL.getParams(), |
| 15904 |
E->hasExplicitResultType()); |
| 15905 |
|
| 15906 |
getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 15907 |
getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); |
| 15908 |
|
| 15909 |
{ |
| 15910 |
// Number the lambda for linkage purposes if necessary. |
| 15911 |
Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext()); |
| 15912 |
|
| 15913 |
std::optional<CXXRecordDecl::LambdaNumbering> Numbering; |
| 15914 |
if (getDerived().ReplacingOriginal()) { |
| 15915 |
Numbering = OldClass->getLambdaNumbering(); |
| 15916 |
} |
| 15917 |
|
| 15918 |
getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering); |
| 15919 |
} |
| 15920 |
|
| 15921 |
// FIXME: Sema's lambda-building mechanism expects us to push an expression |
| 15922 |
// evaluation context even if we're not transforming the function body. |
| 15923 |
getSema().PushExpressionEvaluationContextForFunction( |
| 15924 |
Sema::ExpressionEvaluationContext::PotentiallyEvaluated, |
| 15925 |
E->getCallOperator()); |
| 15926 |
|
| 15927 |
StmtResult Body; |
| 15928 |
{ |
| 15929 |
Sema::NonSFINAEContext _(getSema()); |
| 15930 |
Sema::CodeSynthesisContext C; |
| 15931 |
C.Kind = clang::Sema::CodeSynthesisContext::LambdaExpressionSubstitution; |
| 15932 |
C.PointOfInstantiation = E->getBody()->getBeginLoc(); |
| 15933 |
getSema().pushCodeSynthesisContext(C); |
| 15934 |
|
| 15935 |
// Instantiate the body of the lambda expression. |
| 15936 |
Body = Invalid ? StmtError() |
| 15937 |
: getDerived().TransformLambdaBody(E, E->getBody()); |
| 15938 |
|
| 15939 |
getSema().popCodeSynthesisContext(); |
| 15940 |
} |
| 15941 |
|
| 15942 |
// ActOnLambda* will pop the function scope for us. |
| 15943 |
FuncScopeCleanup.disable(); |
| 15944 |
|
| 15945 |
if (Body.isInvalid()) { |
| 15946 |
SavedContext.pop(); |
| 15947 |
getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, |
| 15948 |
/*IsInstantiation=*/true); |
| 15949 |
return ExprError(); |
| 15950 |
} |
| 15951 |
|
| 15952 |
getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 15953 |
/*IsInstantiation=*/true, |
| 15954 |
/*RetainFunctionScopeInfo=*/true); |
| 15955 |
SavedContext.pop(); |
| 15956 |
|
| 15957 |
// Recompute the dependency of the lambda so that we can defer the lambda call |
| 15958 |
// construction until after we have all the necessary template arguments. For |
| 15959 |
// example, given |
| 15960 |
// |
| 15961 |
// template <class> struct S { |
| 15962 |
// template <class U> |
| 15963 |
// using Type = decltype([](U){}(42.0)); |
| 15964 |
// }; |
| 15965 |
// void foo() { |
| 15966 |
// using T = S<int>::Type<float>; |
| 15967 |
// ^~~~~~ |
| 15968 |
// } |
| 15969 |
// |
| 15970 |
// We would end up here from instantiating S<int> when ensuring its |
| 15971 |
// completeness. That would transform the lambda call expression regardless of |
| 15972 |
// the absence of the corresponding argument for U. |
| 15973 |
// |
| 15974 |
// Going ahead with unsubstituted type U makes things worse: we would soon |
| 15975 |
// compare the argument type (which is float) against the parameter U |
| 15976 |
// somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus |
| 15977 |
// error suggesting unmatched types 'U' and 'float'! |
| 15978 |
// |
| 15979 |
// That said, everything will be fine if we defer that semantic checking. |
| 15980 |
// Fortunately, we have such a mechanism that bypasses it if the CallExpr is |
| 15981 |
// dependent. Since the CallExpr's dependency boils down to the lambda's |
| 15982 |
// dependency in this case, we can harness that by recomputing the dependency |
| 15983 |
// from the instantiation arguments. |
| 15984 |
// |
| 15985 |
// FIXME: Creating the type of a lambda requires us to have a dependency |
| 15986 |
// value, which happens before its substitution. We update its dependency |
| 15987 |
// *after* the substitution in case we can't decide the dependency |
| 15988 |
// so early, e.g. because we want to see if any of the *substituted* |
| 15989 |
// parameters are dependent. |
| 15990 |
DependencyKind = getDerived().ComputeLambdaDependency(LSI); |
| 15991 |
Class->setLambdaDependencyKind(DependencyKind); |
| 15992 |
|
| 15993 |
return getDerived().RebuildLambdaExpr(E->getBeginLoc(), |
| 15994 |
Body.get()->getEndLoc(), LSI); |
| 15995 |
} |
| 15996 |
|
| 15997 |
template<typename Derived> |
| 15998 |
StmtResult |
| 15999 |
TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { |
| 16000 |
return TransformStmt(S); |
| 16001 |
} |
| 16002 |
|
| 16003 |
template<typename Derived> |
| 16004 |
StmtResult |
| 16005 |
TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { |
| 16006 |
// Transform captures. |
| 16007 |
for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 16008 |
CEnd = E->capture_end(); |
| 16009 |
C != CEnd; ++C) { |
| 16010 |
// When we hit the first implicit capture, tell Sema that we've finished |
| 16011 |
// the list of explicit captures. |
| 16012 |
if (!C->isImplicit()) |
| 16013 |
continue; |
| 16014 |
|
| 16015 |
// Capturing 'this' is trivial. |
| 16016 |
if (C->capturesThis()) { |
| 16017 |
getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 16018 |
/*BuildAndDiagnose*/ true, nullptr, |
| 16019 |
C->getCaptureKind() == LCK_StarThis); |
| 16020 |
continue; |
| 16021 |
} |
| 16022 |
// Captured expression will be recaptured during captured variables |
| 16023 |
// rebuilding. |
| 16024 |
if (C->capturesVLAType()) |
| 16025 |
continue; |
| 16026 |
|
| 16027 |
assert(C->capturesVariable() && "unexpected kind of lambda capture"); |
| 16028 |
assert(!E->isInitCapture(C) && "implicit init-capture?"); |
| 16029 |
|
| 16030 |
// Transform the captured variable. |
| 16031 |
VarDecl *CapturedVar = cast_or_null<VarDecl>( |
| 16032 |
getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); |
| 16033 |
if (!CapturedVar || CapturedVar->isInvalidDecl()) |
| 16034 |
return StmtError(); |
| 16035 |
|
| 16036 |
// Capture the transformed variable. |
| 16037 |
getSema().tryCaptureVariable(CapturedVar, C->getLocation()); |
| 16038 |
} |
| 16039 |
|
| 16040 |
return S; |
| 16041 |
} |
| 16042 |
|
| 16043 |
template<typename Derived> |
| 16044 |
ExprResult |
| 16045 |
TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
| 16046 |
CXXUnresolvedConstructExpr *E) { |
| 16047 |
TypeSourceInfo *T = |
| 16048 |
getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| 16049 |
if (!T) |
| 16050 |
return ExprError(); |
| 16051 |
|
| 16052 |
bool ArgumentChanged = false; |
| 16053 |
SmallVector<Expr*, 8> Args; |
| 16054 |
Args.reserve(E->getNumArgs()); |
| 16055 |
{ |
| 16056 |
EnterExpressionEvaluationContext Context( |
| 16057 |
getSema(), EnterExpressionEvaluationContext::InitList, |
| 16058 |
E->isListInitialization()); |
| 16059 |
if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args, |
| 16060 |
&ArgumentChanged)) |
| 16061 |
return ExprError(); |
| 16062 |
} |
| 16063 |
|
| 16064 |
if (!getDerived().AlwaysRebuild() && |
| 16065 |
T == E->getTypeSourceInfo() && |
| 16066 |
!ArgumentChanged) |
| 16067 |
return E; |
| 16068 |
|
| 16069 |
// FIXME: we're faking the locations of the commas |
| 16070 |
return getDerived().RebuildCXXUnresolvedConstructExpr( |
| 16071 |
T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); |
| 16072 |
} |
| 16073 |
|
| 16074 |
template<typename Derived> |
| 16075 |
ExprResult |
| 16076 |
TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 16077 |
CXXDependentScopeMemberExpr *E) { |
| 16078 |
// Transform the base of the expression. |
| 16079 |
ExprResult Base((Expr*) nullptr); |
| 16080 |
Expr *OldBase; |
| 16081 |
QualType BaseType; |
| 16082 |
QualType ObjectType; |
| 16083 |
if (!E->isImplicitAccess()) { |
| 16084 |
OldBase = E->getBase(); |
| 16085 |
Base = getDerived().TransformExpr(OldBase); |
| 16086 |
if (Base.isInvalid()) |
| 16087 |
return ExprError(); |
| 16088 |
|
| 16089 |
// Start the member reference and compute the object's type. |
| 16090 |
ParsedType ObjectTy; |
| 16091 |
bool MayBePseudoDestructor = false; |
| 16092 |
Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| 16093 |
E->getOperatorLoc(), |
| 16094 |
E->isArrow()? tok::arrow : tok::period, |
| 16095 |
ObjectTy, |
| 16096 |
MayBePseudoDestructor); |
| 16097 |
if (Base.isInvalid()) |
| 16098 |
return ExprError(); |
| 16099 |
|
| 16100 |
ObjectType = ObjectTy.get(); |
| 16101 |
BaseType = ((Expr*) Base.get())->getType(); |
| 16102 |
} else { |
| 16103 |
OldBase = nullptr; |
| 16104 |
BaseType = getDerived().TransformType(E->getBaseType()); |
| 16105 |
ObjectType = BaseType->castAs<PointerType>()->getPointeeType(); |
| 16106 |
} |
| 16107 |
|
| 16108 |
// Transform the first part of the nested-name-specifier that qualifies |
| 16109 |
// the member name. |
| 16110 |
NamedDecl *FirstQualifierInScope |
| 16111 |
= getDerived().TransformFirstQualifierInScope( |
| 16112 |
E->getFirstQualifierFoundInScope(), |
| 16113 |
E->getQualifierLoc().getBeginLoc()); |
| 16114 |
|
| 16115 |
NestedNameSpecifierLoc QualifierLoc; |
| 16116 |
if (E->getQualifier()) { |
| 16117 |
QualifierLoc |
| 16118 |
= getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 16119 |
ObjectType, |
| 16120 |
FirstQualifierInScope); |
| 16121 |
if (!QualifierLoc) |
| 16122 |
return ExprError(); |
| 16123 |
} |
| 16124 |
|
| 16125 |
SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 16126 |
|
| 16127 |
// TODO: If this is a conversion-function-id, verify that the |
| 16128 |
// destination type name (if present) resolves the same way after |
| 16129 |
// instantiation as it did in the local scope. |
| 16130 |
|
| 16131 |
DeclarationNameInfo NameInfo |
| 16132 |
= getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
| 16133 |
if (!NameInfo.getName()) |
| 16134 |
return ExprError(); |
| 16135 |
|
| 16136 |
if (!E->hasExplicitTemplateArgs()) { |
| 16137 |
// This is a reference to a member without an explicitly-specified |
| 16138 |
// template argument list. Optimize for this common case. |
| 16139 |
if (!getDerived().AlwaysRebuild() && |
| 16140 |
Base.get() == OldBase && |
| 16141 |
BaseType == E->getBaseType() && |
| 16142 |
QualifierLoc == E->getQualifierLoc() && |
| 16143 |
NameInfo.getName() == E->getMember() && |
| 16144 |
FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
| 16145 |
return E; |
| 16146 |
|
| 16147 |
return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| 16148 |
BaseType, |
| 16149 |
E->isArrow(), |
| 16150 |
E->getOperatorLoc(), |
| 16151 |
QualifierLoc, |
| 16152 |
TemplateKWLoc, |
| 16153 |
FirstQualifierInScope, |
| 16154 |
NameInfo, |
| 16155 |
/*TemplateArgs*/nullptr); |
| 16156 |
} |
| 16157 |
|
| 16158 |
TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| 16159 |
if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 16160 |
E->getNumTemplateArgs(), |
| 16161 |
TransArgs)) |
| 16162 |
return ExprError(); |
| 16163 |
|
| 16164 |
return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| 16165 |
BaseType, |
| 16166 |
E->isArrow(), |
| 16167 |
E->getOperatorLoc(), |
| 16168 |
QualifierLoc, |
| 16169 |
TemplateKWLoc, |
| 16170 |
FirstQualifierInScope, |
| 16171 |
NameInfo, |
| 16172 |
&TransArgs); |
| 16173 |
} |
| 16174 |
|
| 16175 |
template <typename Derived> |
| 16176 |
ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr( |
| 16177 |
UnresolvedMemberExpr *Old) { |
| 16178 |
// Transform the base of the expression. |
| 16179 |
ExprResult Base((Expr *)nullptr); |
| 16180 |
QualType BaseType; |
| 16181 |
if (!Old->isImplicitAccess()) { |
| 16182 |
Base = getDerived().TransformExpr(Old->getBase()); |
| 16183 |
if (Base.isInvalid()) |
| 16184 |
return ExprError(); |
| 16185 |
Base = |
| 16186 |
getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow()); |
| 16187 |
if (Base.isInvalid()) |
| 16188 |
return ExprError(); |
| 16189 |
BaseType = Base.get()->getType(); |
| 16190 |
} else { |
| 16191 |
BaseType = getDerived().TransformType(Old->getBaseType()); |
| 16192 |
} |
| 16193 |
|
| 16194 |
NestedNameSpecifierLoc QualifierLoc; |
| 16195 |
if (Old->getQualifierLoc()) { |
| 16196 |
QualifierLoc = |
| 16197 |
getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 16198 |
if (!QualifierLoc) |
| 16199 |
return ExprError(); |
| 16200 |
} |
| 16201 |
|
| 16202 |
SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 16203 |
|
| 16204 |
LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName); |
| 16205 |
|
| 16206 |
// Transform the declaration set. |
| 16207 |
if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R)) |
| 16208 |
return ExprError(); |
| 16209 |
|
| 16210 |
// Determine the naming class. |
| 16211 |
if (Old->getNamingClass()) { |
| 16212 |
CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>( |
| 16213 |
getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass())); |
| 16214 |
if (!NamingClass) |
| 16215 |
return ExprError(); |
| 16216 |
|
| 16217 |
R.setNamingClass(NamingClass); |
| 16218 |
} |
| 16219 |
|
| 16220 |
TemplateArgumentListInfo TransArgs; |
| 16221 |
if (Old->hasExplicitTemplateArgs()) { |
| 16222 |
TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 16223 |
TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 16224 |
if (getDerived().TransformTemplateArguments( |
| 16225 |
Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs)) |
| 16226 |
return ExprError(); |
| 16227 |
} |
| 16228 |
|
| 16229 |
// FIXME: to do this check properly, we will need to preserve the |
| 16230 |
// first-qualifier-in-scope here, just in case we had a dependent |
| 16231 |
// base (and therefore couldn't do the check) and a |
| 16232 |
// nested-name-qualifier (and therefore could do the lookup). |
| 16233 |
NamedDecl *FirstQualifierInScope = nullptr; |
| 16234 |
|
| 16235 |
return getDerived().RebuildUnresolvedMemberExpr( |
| 16236 |
Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc, |
| 16237 |
TemplateKWLoc, FirstQualifierInScope, R, |
| 16238 |
(Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr)); |
| 16239 |
} |
| 16240 |
|
| 16241 |
template<typename Derived> |
| 16242 |
ExprResult |
| 16243 |
TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 16244 |
EnterExpressionEvaluationContext Unevaluated( |
| 16245 |
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 16246 |
ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 16247 |
if (SubExpr.isInvalid()) |
| 16248 |
return ExprError(); |
| 16249 |
|
| 16250 |
if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
| 16251 |
return E; |
| 16252 |
|
| 16253 |
return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 16254 |
} |
| 16255 |
|
| 16256 |
template<typename Derived> |
| 16257 |
ExprResult |
| 16258 |
TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
| 16259 |
ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 16260 |
if (Pattern.isInvalid()) |
| 16261 |
return ExprError(); |
| 16262 |
|
| 16263 |
if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 16264 |
return E; |
| 16265 |
|
| 16266 |
return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 16267 |
E->getNumExpansions()); |
| 16268 |
} |
| 16269 |
|
| 16270 |
template <typename Derived> |
| 16271 |
UnsignedOrNone TreeTransform<Derived>::ComputeSizeOfPackExprWithoutSubstitution( |
| 16272 |
ArrayRef<TemplateArgument> PackArgs) { |
| 16273 |
UnsignedOrNone Result = 0u; |
| 16274 |
for (const TemplateArgument &Arg : PackArgs) { |
| 16275 |
if (!Arg.isPackExpansion()) { |
| 16276 |
Result = *Result + 1; |
| 16277 |
continue; |
| 16278 |
} |
| 16279 |
|
| 16280 |
TemplateArgumentLoc ArgLoc; |
| 16281 |
InventTemplateArgumentLoc(Arg, ArgLoc); |
| 16282 |
|
| 16283 |
// Find the pattern of the pack expansion. |
| 16284 |
SourceLocation Ellipsis; |
| 16285 |
UnsignedOrNone OrigNumExpansions = std::nullopt; |
| 16286 |
TemplateArgumentLoc Pattern = |
| 16287 |
getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, |
| 16288 |
OrigNumExpansions); |
| 16289 |
|
| 16290 |
// Substitute under the pack expansion. Do not expand the pack (yet). |
| 16291 |
TemplateArgumentLoc OutPattern; |
| 16292 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 16293 |
if (getDerived().TransformTemplateArgument(Pattern, OutPattern, |
| 16294 |
/*Uneval*/ true)) |
| 16295 |
return 1u; |
| 16296 |
|
| 16297 |
// See if we can determine the number of arguments from the result. |
| 16298 |
UnsignedOrNone NumExpansions = |
| 16299 |
getSema().getFullyPackExpandedSize(OutPattern.getArgument()); |
| 16300 |
if (!NumExpansions) { |
| 16301 |
// No: we must be in an alias template expansion, and we're going to |
| 16302 |
// need to actually expand the packs. |
| 16303 |
Result = std::nullopt; |
| 16304 |
break; |
| 16305 |
} |
| 16306 |
|
| 16307 |
Result = *Result + *NumExpansions; |
| 16308 |
} |
| 16309 |
return Result; |
| 16310 |
} |
| 16311 |
|
| 16312 |
template<typename Derived> |
| 16313 |
ExprResult |
| 16314 |
TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 16315 |
// If E is not value-dependent, then nothing will change when we transform it. |
| 16316 |
// Note: This is an instantiation-centric view. |
| 16317 |
if (!E->isValueDependent()) |
| 16318 |
return E; |
| 16319 |
|
| 16320 |
EnterExpressionEvaluationContext Unevaluated( |
| 16321 |
getSema(), Sema::ExpressionEvaluationContext::Unevaluated); |
| 16322 |
|
| 16323 |
ArrayRef<TemplateArgument> PackArgs; |
| 16324 |
TemplateArgument ArgStorage; |
| 16325 |
|
| 16326 |
// Find the argument list to transform. |
| 16327 |
if (E->isPartiallySubstituted()) { |
| 16328 |
PackArgs = E->getPartialArguments(); |
| 16329 |
} else if (E->isValueDependent()) { |
| 16330 |
UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 16331 |
bool ShouldExpand = false; |
| 16332 |
bool RetainExpansion = false; |
| 16333 |
UnsignedOrNone NumExpansions = std::nullopt; |
| 16334 |
if (getDerived().TryExpandParameterPacks( |
| 16335 |
E->getOperatorLoc(), E->getPackLoc(), Unexpanded, |
| 16336 |
/*FailOnPackProducingTemplates=*/true, ShouldExpand, |
| 16337 |
RetainExpansion, NumExpansions)) |
| 16338 |
return ExprError(); |
| 16339 |
|
| 16340 |
// If we need to expand the pack, build a template argument from it and |
| 16341 |
// expand that. |
| 16342 |
if (ShouldExpand) { |
| 16343 |
auto *Pack = E->getPack(); |
| 16344 |
if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 16345 |
ArgStorage = getSema().Context.getPackExpansionType( |
| 16346 |
getSema().Context.getTypeDeclType(TTPD), std::nullopt); |
| 16347 |
} else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 16348 |
ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt); |
| 16349 |
} else { |
| 16350 |
auto *VD = cast<ValueDecl>(Pack); |
| 16351 |
ExprResult DRE = getSema().BuildDeclRefExpr( |
| 16352 |
VD, VD->getType().getNonLValueExprType(getSema().Context), |
| 16353 |
VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue, |
| 16354 |
E->getPackLoc()); |
| 16355 |
if (DRE.isInvalid()) |
| 16356 |
return ExprError(); |
| 16357 |
ArgStorage = TemplateArgument( |
| 16358 |
new (getSema().Context) |
| 16359 |
PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt), |
| 16360 |
/*IsCanonical=*/false); |
| 16361 |
} |
| 16362 |
PackArgs = ArgStorage; |
| 16363 |
} |
| 16364 |
} |
| 16365 |
|
| 16366 |
// If we're not expanding the pack, just transform the decl. |
| 16367 |
if (!PackArgs.size()) { |
| 16368 |
auto *Pack = cast_or_null<NamedDecl>( |
| 16369 |
getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
| 16370 |
if (!Pack) |
| 16371 |
return ExprError(); |
| 16372 |
return getDerived().RebuildSizeOfPackExpr( |
| 16373 |
E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(), |
| 16374 |
std::nullopt, {}); |
| 16375 |
} |
| 16376 |
|
| 16377 |
// Try to compute the result without performing a partial substitution. |
| 16378 |
UnsignedOrNone Result = |
| 16379 |
getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs); |
| 16380 |
|
| 16381 |
// Common case: we could determine the number of expansions without |
| 16382 |
// substituting. |
| 16383 |
if (Result) |
| 16384 |
return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 16385 |
E->getPackLoc(), |
| 16386 |
E->getRParenLoc(), *Result, {}); |
| 16387 |
|
| 16388 |
TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 16389 |
E->getPackLoc()); |
| 16390 |
{ |
| 16391 |
TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 16392 |
typedef TemplateArgumentLocInventIterator< |
| 16393 |
Derived, const TemplateArgument*> PackLocIterator; |
| 16394 |
if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 16395 |
PackLocIterator(*this, PackArgs.end()), |
| 16396 |
TransformedPackArgs, /*Uneval*/true)) |
| 16397 |
return ExprError(); |
| 16398 |
} |
| 16399 |
|
| 16400 |
// Check whether we managed to fully-expand the pack. |
| 16401 |
// FIXME: Is it possible for us to do so and not hit the early exit path? |
| 16402 |
SmallVector<TemplateArgument, 8> Args; |
| 16403 |
bool PartialSubstitution = false; |
| 16404 |
for (auto &Loc : TransformedPackArgs.arguments()) { |
| 16405 |
Args.push_back(Loc.getArgument()); |
| 16406 |
if (Loc.getArgument().isPackExpansion()) |
| 16407 |
PartialSubstitution = true; |
| 16408 |
} |
| 16409 |
|
| 16410 |
if (PartialSubstitution) |
| 16411 |
return getDerived().RebuildSizeOfPackExpr( |
| 16412 |
E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(), |
| 16413 |
std::nullopt, Args); |
| 16414 |
|
| 16415 |
return getDerived().RebuildSizeOfPackExpr( |
| 16416 |
E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(), |
| 16417 |
/*Length=*/static_cast<unsigned>(Args.size()), |
| 16418 |
/*PartialArgs=*/{}); |
| 16419 |
} |
| 16420 |
|
| 16421 |
template <typename Derived> |
| 16422 |
ExprResult |
| 16423 |
TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) { |
| 16424 |
if (!E->isValueDependent()) |
| 16425 |
return E; |
| 16426 |
|
| 16427 |
// Transform the index |
| 16428 |
ExprResult IndexExpr; |
| 16429 |
{ |
| 16430 |
EnterExpressionEvaluationContext ConstantContext( |
| 16431 |
SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 16432 |
IndexExpr = getDerived().TransformExpr(E->getIndexExpr()); |
| 16433 |
if (IndexExpr.isInvalid()) |
| 16434 |
return ExprError(); |
| 16435 |
} |
| 16436 |
|
| 16437 |
SmallVector<Expr *, 5> ExpandedExprs; |
| 16438 |
bool FullySubstituted = true; |
| 16439 |
if (!E->expandsToEmptyPack() && E->getExpressions().empty()) { |
| 16440 |
Expr *Pattern = E->getPackIdExpression(); |
| 16441 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 16442 |
getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(), |
| 16443 |
Unexpanded); |
| 16444 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 16445 |
|
| 16446 |
// Determine whether the set of unexpanded parameter packs can and should |
| 16447 |
// be expanded. |
| 16448 |
bool ShouldExpand = true; |
| 16449 |
bool RetainExpansion = false; |
| 16450 |
UnsignedOrNone OrigNumExpansions = std::nullopt, |
| 16451 |
NumExpansions = std::nullopt; |
| 16452 |
if (getDerived().TryExpandParameterPacks( |
| 16453 |
E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded, |
| 16454 |
/*FailOnPackProducingTemplates=*/true, ShouldExpand, |
| 16455 |
RetainExpansion, NumExpansions)) |
| 16456 |
return true; |
| 16457 |
if (!ShouldExpand) { |
| 16458 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 16459 |
ExprResult Pack = getDerived().TransformExpr(Pattern); |
| 16460 |
if (Pack.isInvalid()) |
| 16461 |
return ExprError(); |
| 16462 |
return getDerived().RebuildPackIndexingExpr( |
| 16463 |
E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(), |
| 16464 |
{}, /*FullySubstituted=*/false); |
| 16465 |
} |
| 16466 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 16467 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 16468 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 16469 |
if (Out.isInvalid()) |
| 16470 |
return true; |
| 16471 |
if (Out.get()->containsUnexpandedParameterPack()) { |
| 16472 |
Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(), |
| 16473 |
OrigNumExpansions); |
| 16474 |
if (Out.isInvalid()) |
| 16475 |
return true; |
| 16476 |
FullySubstituted = false; |
| 16477 |
} |
| 16478 |
ExpandedExprs.push_back(Out.get()); |
| 16479 |
} |
| 16480 |
// If we're supposed to retain a pack expansion, do so by temporarily |
| 16481 |
// forgetting the partially-substituted parameter pack. |
| 16482 |
if (RetainExpansion) { |
| 16483 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 16484 |
|
| 16485 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 16486 |
if (Out.isInvalid()) |
| 16487 |
return true; |
| 16488 |
|
| 16489 |
Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(), |
| 16490 |
OrigNumExpansions); |
| 16491 |
if (Out.isInvalid()) |
| 16492 |
return true; |
| 16493 |
FullySubstituted = false; |
| 16494 |
ExpandedExprs.push_back(Out.get()); |
| 16495 |
} |
| 16496 |
} else if (!E->expandsToEmptyPack()) { |
| 16497 |
if (getDerived().TransformExprs(E->getExpressions().data(), |
| 16498 |
E->getExpressions().size(), false, |
| 16499 |
ExpandedExprs)) |
| 16500 |
return ExprError(); |
| 16501 |
} |
| 16502 |
|
| 16503 |
return getDerived().RebuildPackIndexingExpr( |
| 16504 |
E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(), |
| 16505 |
IndexExpr.get(), ExpandedExprs, FullySubstituted); |
| 16506 |
} |
| 16507 |
|
| 16508 |
template <typename Derived> |
| 16509 |
ExprResult TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 16510 |
SubstNonTypeTemplateParmPackExpr *E) { |
| 16511 |
if (!getSema().ArgPackSubstIndex) |
| 16512 |
// We aren't expanding the parameter pack, so just return ourselves. |
| 16513 |
return E; |
| 16514 |
|
| 16515 |
TemplateArgument Pack = E->getArgumentPack(); |
| 16516 |
TemplateArgument Arg = SemaRef.getPackSubstitutedTemplateArgument(Pack); |
| 16517 |
return getDerived().RebuildSubstNonTypeTemplateParmExpr( |
| 16518 |
E->getAssociatedDecl(), E->getParameterPack(), |
| 16519 |
E->getParameterPackLocation(), Arg, SemaRef.getPackIndex(Pack), |
| 16520 |
E->getFinal()); |
| 16521 |
} |
| 16522 |
|
| 16523 |
template <typename Derived> |
| 16524 |
ExprResult TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 16525 |
SubstNonTypeTemplateParmExpr *E) { |
| 16526 |
Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten(); |
| 16527 |
ExprResult Replacement = getDerived().TransformExpr(OrigReplacement); |
| 16528 |
if (Replacement.isInvalid()) |
| 16529 |
return true; |
| 16530 |
|
| 16531 |
Decl *AssociatedDecl = |
| 16532 |
getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl()); |
| 16533 |
if (!AssociatedDecl) |
| 16534 |
return true; |
| 16535 |
|
| 16536 |
if (Replacement.get() == OrigReplacement && |
| 16537 |
AssociatedDecl == E->getAssociatedDecl()) |
| 16538 |
return E; |
| 16539 |
|
| 16540 |
auto getParamAndType = [E](Decl *AssociatedDecl) |
| 16541 |
-> std::tuple<NonTypeTemplateParmDecl *, QualType> { |
| 16542 |
auto [PDecl, Arg] = |
| 16543 |
getReplacedTemplateParameter(AssociatedDecl, E->getIndex()); |
| 16544 |
auto *Param = cast<NonTypeTemplateParmDecl>(PDecl); |
| 16545 |
if (Arg.isNull()) |
| 16546 |
return {Param, Param->getType()}; |
| 16547 |
if (UnsignedOrNone PackIndex = E->getPackIndex()) |
| 16548 |
Arg = Arg.getPackAsArray()[*PackIndex]; |
| 16549 |
return {Param, Arg.getNonTypeTemplateArgumentType()}; |
| 16550 |
}; |
| 16551 |
|
| 16552 |
// If the replacement expression did not change, and the parameter type |
| 16553 |
// did not change, we can skip the semantic action because it would |
| 16554 |
// produce the same result anyway. |
| 16555 |
if (auto [Param, ParamType] = getParamAndType(AssociatedDecl); |
| 16556 |
!SemaRef.Context.hasSameType( |
| 16557 |
ParamType, std::get<1>(getParamAndType(E->getAssociatedDecl()))) || |
| 16558 |
Replacement.get() != OrigReplacement) { |
| 16559 |
// When transforming the replacement expression previously, all Sema |
| 16560 |
// specific annotations, such as implicit casts, are discarded. Calling the |
| 16561 |
// corresponding sema action is necessary to recover those. Otherwise, |
| 16562 |
// equivalency of the result would be lost. |
| 16563 |
TemplateArgument SugaredConverted, CanonicalConverted; |
| 16564 |
Replacement = SemaRef.CheckTemplateArgument( |
| 16565 |
Param, ParamType, Replacement.get(), SugaredConverted, |
| 16566 |
CanonicalConverted, |
| 16567 |
/*StrictCheck=*/false, Sema::CTAK_Specified); |
| 16568 |
if (Replacement.isInvalid()) |
| 16569 |
return true; |
| 16570 |
} else { |
| 16571 |
// Otherwise, the same expression would have been produced. |
| 16572 |
Replacement = E->getReplacement(); |
| 16573 |
} |
| 16574 |
|
| 16575 |
return getDerived().RebuildSubstNonTypeTemplateParmExpr( |
| 16576 |
AssociatedDecl, E->getParameter(), E->getNameLoc(), |
| 16577 |
TemplateArgument(Replacement.get(), /*IsCanonical=*/false), |
| 16578 |
E->getPackIndex(), E->getFinal()); |
| 16579 |
} |
| 16580 |
|
| 16581 |
template<typename Derived> |
| 16582 |
ExprResult |
| 16583 |
TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 16584 |
// Default behavior is to do nothing with this transformation. |
| 16585 |
return E; |
| 16586 |
} |
| 16587 |
|
| 16588 |
template<typename Derived> |
| 16589 |
ExprResult |
| 16590 |
TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 16591 |
MaterializeTemporaryExpr *E) { |
| 16592 |
return getDerived().TransformExpr(E->getSubExpr()); |
| 16593 |
} |
| 16594 |
|
| 16595 |
template<typename Derived> |
| 16596 |
ExprResult |
| 16597 |
TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 16598 |
UnresolvedLookupExpr *Callee = nullptr; |
| 16599 |
if (Expr *OldCallee = E->getCallee()) { |
| 16600 |
ExprResult CalleeResult = getDerived().TransformExpr(OldCallee); |
| 16601 |
if (CalleeResult.isInvalid()) |
| 16602 |
return ExprError(); |
| 16603 |
Callee = cast<UnresolvedLookupExpr>(CalleeResult.get()); |
| 16604 |
} |
| 16605 |
|
| 16606 |
Expr *Pattern = E->getPattern(); |
| 16607 |
|
| 16608 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 16609 |
getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 16610 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 16611 |
|
| 16612 |
// Determine whether the set of unexpanded parameter packs can and should |
| 16613 |
// be expanded. |
| 16614 |
bool Expand = true; |
| 16615 |
bool RetainExpansion = false; |
| 16616 |
UnsignedOrNone OrigNumExpansions = E->getNumExpansions(), |
| 16617 |
NumExpansions = OrigNumExpansions; |
| 16618 |
if (getDerived().TryExpandParameterPacks( |
| 16619 |
E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded, |
| 16620 |
/*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion, |
| 16621 |
NumExpansions)) |
| 16622 |
return true; |
| 16623 |
|
| 16624 |
if (!Expand) { |
| 16625 |
// Do not expand any packs here, just transform and rebuild a fold |
| 16626 |
// expression. |
| 16627 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 16628 |
|
| 16629 |
ExprResult LHS = |
| 16630 |
E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 16631 |
if (LHS.isInvalid()) |
| 16632 |
return true; |
| 16633 |
|
| 16634 |
ExprResult RHS = |
| 16635 |
E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 16636 |
if (RHS.isInvalid()) |
| 16637 |
return true; |
| 16638 |
|
| 16639 |
if (!getDerived().AlwaysRebuild() && |
| 16640 |
LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 16641 |
return E; |
| 16642 |
|
| 16643 |
return getDerived().RebuildCXXFoldExpr( |
| 16644 |
Callee, E->getBeginLoc(), LHS.get(), E->getOperator(), |
| 16645 |
E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions); |
| 16646 |
} |
| 16647 |
|
| 16648 |
// Formally a fold expression expands to nested parenthesized expressions. |
| 16649 |
// Enforce this limit to avoid creating trees so deep we can't safely traverse |
| 16650 |
// them. |
| 16651 |
if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) { |
| 16652 |
SemaRef.Diag(E->getEllipsisLoc(), |
| 16653 |
clang::diag::err_fold_expression_limit_exceeded) |
| 16654 |
<< *NumExpansions << SemaRef.getLangOpts().BracketDepth |
| 16655 |
<< E->getSourceRange(); |
| 16656 |
SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth); |
| 16657 |
return ExprError(); |
| 16658 |
} |
| 16659 |
|
| 16660 |
// The transform has determined that we should perform an elementwise |
| 16661 |
// expansion of the pattern. Do so. |
| 16662 |
ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 16663 |
if (Result.isInvalid()) |
| 16664 |
return true; |
| 16665 |
bool LeftFold = E->isLeftFold(); |
| 16666 |
|
| 16667 |
// If we're retaining an expansion for a right fold, it is the innermost |
| 16668 |
// component and takes the init (if any). |
| 16669 |
if (!LeftFold && RetainExpansion) { |
| 16670 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 16671 |
|
| 16672 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 16673 |
if (Out.isInvalid()) |
| 16674 |
return true; |
| 16675 |
|
| 16676 |
Result = getDerived().RebuildCXXFoldExpr( |
| 16677 |
Callee, E->getBeginLoc(), Out.get(), E->getOperator(), |
| 16678 |
E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions); |
| 16679 |
if (Result.isInvalid()) |
| 16680 |
return true; |
| 16681 |
} |
| 16682 |
|
| 16683 |
bool WarnedOnComparison = false; |
| 16684 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 16685 |
Sema::ArgPackSubstIndexRAII SubstIndex( |
| 16686 |
getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 16687 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 16688 |
if (Out.isInvalid()) |
| 16689 |
return true; |
| 16690 |
|
| 16691 |
if (Out.get()->containsUnexpandedParameterPack()) { |
| 16692 |
// We still have a pack; retain a pack expansion for this slice. |
| 16693 |
Result = getDerived().RebuildCXXFoldExpr( |
| 16694 |
Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), |
| 16695 |
E->getOperator(), E->getEllipsisLoc(), |
| 16696 |
LeftFold ? Out.get() : Result.get(), E->getEndLoc(), |
| 16697 |
OrigNumExpansions); |
| 16698 |
} else if (Result.isUsable()) { |
| 16699 |
// We've got down to a single element; build a binary operator. |
| 16700 |
Expr *LHS = LeftFold ? Result.get() : Out.get(); |
| 16701 |
Expr *RHS = LeftFold ? Out.get() : Result.get(); |
| 16702 |
if (Callee) { |
| 16703 |
UnresolvedSet<16> Functions; |
| 16704 |
Functions.append(Callee->decls_begin(), Callee->decls_end()); |
| 16705 |
Result = getDerived().RebuildCXXOperatorCallExpr( |
| 16706 |
BinaryOperator::getOverloadedOperator(E->getOperator()), |
| 16707 |
E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(), |
| 16708 |
Functions, LHS, RHS); |
| 16709 |
} else { |
| 16710 |
Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(), |
| 16711 |
E->getOperator(), LHS, RHS, |
| 16712 |
/*ForFoldExpresion=*/true); |
| 16713 |
if (!WarnedOnComparison && Result.isUsable()) { |
| 16714 |
if (auto *BO = dyn_cast<BinaryOperator>(Result.get()); |
| 16715 |
BO && BO->isComparisonOp()) { |
| 16716 |
WarnedOnComparison = true; |
| 16717 |
SemaRef.Diag(BO->getBeginLoc(), |
| 16718 |
diag::warn_comparison_in_fold_expression) |
| 16719 |
<< BO->getOpcodeStr(); |
| 16720 |
} |
| 16721 |
} |
| 16722 |
} |
| 16723 |
} else |
| 16724 |
Result = Out; |
| 16725 |
|
| 16726 |
if (Result.isInvalid()) |
| 16727 |
return true; |
| 16728 |
} |
| 16729 |
|
| 16730 |
// If we're retaining an expansion for a left fold, it is the outermost |
| 16731 |
// component and takes the complete expansion so far as its init (if any). |
| 16732 |
if (LeftFold && RetainExpansion) { |
| 16733 |
ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 16734 |
|
| 16735 |
ExprResult Out = getDerived().TransformExpr(Pattern); |
| 16736 |
if (Out.isInvalid()) |
| 16737 |
return true; |
| 16738 |
|
| 16739 |
Result = getDerived().RebuildCXXFoldExpr( |
| 16740 |
Callee, E->getBeginLoc(), Result.get(), E->getOperator(), |
| 16741 |
E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions); |
| 16742 |
if (Result.isInvalid()) |
| 16743 |
return true; |
| 16744 |
} |
| 16745 |
|
| 16746 |
if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get())) |
| 16747 |
PE->setIsProducedByFoldExpansion(); |
| 16748 |
|
| 16749 |
// If we had no init and an empty pack, and we're not retaining an expansion, |
| 16750 |
// then produce a fallback value or error. |
| 16751 |
if (Result.isUnset()) |
| 16752 |
return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 16753 |
E->getOperator()); |
| 16754 |
return Result; |
| 16755 |
} |
| 16756 |
|
| 16757 |
template <typename Derived> |
| 16758 |
ExprResult |
| 16759 |
TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) { |
| 16760 |
SmallVector<Expr *, 4> TransformedInits; |
| 16761 |
ArrayRef<Expr *> InitExprs = E->getInitExprs(); |
| 16762 |
|
| 16763 |
QualType T = getDerived().TransformType(E->getType()); |
| 16764 |
|
| 16765 |
bool ArgChanged = false; |
| 16766 |
|
| 16767 |
if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true, |
| 16768 |
TransformedInits, &ArgChanged)) |
| 16769 |
return ExprError(); |
| 16770 |
|
| 16771 |
if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType()) |
| 16772 |
return E; |
| 16773 |
|
| 16774 |
return getDerived().RebuildCXXParenListInitExpr( |
| 16775 |
TransformedInits, T, E->getUserSpecifiedInitExprs().size(), |
| 16776 |
E->getInitLoc(), E->getBeginLoc(), E->getEndLoc()); |
| 16777 |
} |
| 16778 |
|
| 16779 |
template<typename Derived> |
| 16780 |
ExprResult |
| 16781 |
TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 16782 |
CXXStdInitializerListExpr *E) { |
| 16783 |
return getDerived().TransformExpr(E->getSubExpr()); |
| 16784 |
} |
| 16785 |
|
| 16786 |
template<typename Derived> |
| 16787 |
ExprResult |
| 16788 |
TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| 16789 |
return SemaRef.MaybeBindToTemporary(E); |
| 16790 |
} |
| 16791 |
|
| 16792 |
template<typename Derived> |
| 16793 |
ExprResult |
| 16794 |
TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
| 16795 |
return E; |
| 16796 |
} |
| 16797 |
|
| 16798 |
template<typename Derived> |
| 16799 |
ExprResult |
| 16800 |
TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 16801 |
ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 16802 |
if (SubExpr.isInvalid()) |
| 16803 |
return ExprError(); |
| 16804 |
|
| 16805 |
if (!getDerived().AlwaysRebuild() && |
| 16806 |
SubExpr.get() == E->getSubExpr()) |
| 16807 |
return E; |
| 16808 |
|
| 16809 |
return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
| 16810 |
} |
| 16811 |
|
| 16812 |
template<typename Derived> |
| 16813 |
ExprResult |
| 16814 |
TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 16815 |
// Transform each of the elements. |
| 16816 |
SmallVector<Expr *, 8> Elements; |
| 16817 |
bool ArgChanged = false; |
| 16818 |
if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| 16819 |
/*IsCall=*/false, Elements, &ArgChanged)) |
| 16820 |
return ExprError(); |
| 16821 |
|
| 16822 |
if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 16823 |
return SemaRef.MaybeBindToTemporary(E); |
| 16824 |
|
| 16825 |
return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 16826 |
Elements.data(), |
| 16827 |
Elements.size()); |
| 16828 |
} |
| 16829 |
|
| 16830 |
template<typename Derived> |
| 16831 |
ExprResult |
| 16832 |
TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| 16833 |
ObjCDictionaryLiteral *E) { |
| 16834 |
// Transform each of the elements. |
| 16835 |
SmallVector<ObjCDictionaryElement, 8> Elements; |
| 16836 |
bool ArgChanged = false; |
| 16837 |
for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 16838 |
ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| 16839 |
|
| 16840 |
if (OrigElement.isPackExpansion()) { |
| 16841 |
// This key/value element is a pack expansion. |
| 16842 |
SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 16843 |
getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 16844 |
getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 16845 |
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
| 16846 |
|
| 16847 |
// Determine whether the set of unexpanded parameter packs can |
| 16848 |
// and should be expanded. |
| 16849 |
bool Expand = true; |
| 16850 |
bool RetainExpansion = false; |
| 16851 |
UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions; |
| 16852 |
UnsignedOrNone NumExpansions = OrigNumExpansions; |
| 16853 |
SourceRange PatternRange(OrigElement.Key->getBeginLoc(), |
| 16854 |
OrigElement.Value->getEndLoc()); |
| 16855 |
if (getDerived().TryExpandParameterPacks( |
| 16856 |
OrigElement.EllipsisLoc, PatternRange, Unexpanded, |
| 16857 |
/*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion, |
| 16858 |
NumExpansions)) |
| 16859 |
return ExprError(); |
| 16860 |
|
| 16861 |
if (!Expand) { |
| 16862 |
// The transform has determined that we should perform a simple |
| 16863 |
// transformation on the pack expansion, producing another pack |
| 16864 |
// expansion. |
| 16865 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt); |
| 16866 |
ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 16867 |
if (Key.isInvalid()) |
| 16868 |
return ExprError(); |
| 16869 |
|
| 16870 |
if (Key.get() != OrigElement.Key) |
| 16871 |
ArgChanged = true; |
| 16872 |
|
| 16873 |
ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 16874 |
if (Value.isInvalid()) |
| 16875 |
return ExprError(); |
| 16876 |
|
| 16877 |
if (Value.get() != OrigElement.Value) |
| 16878 |
ArgChanged = true; |
| 16879 |
|
| 16880 |
ObjCDictionaryElement Expansion = { |
| 16881 |
Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 16882 |
}; |
| 16883 |
Elements.push_back(Expansion); |
| 16884 |
continue; |
| 16885 |
} |
| 16886 |
|
| 16887 |
// Record right away that the argument was changed. This needs |
| 16888 |
// to happen even if the array expands to nothing. |
| 16889 |
ArgChanged = true; |
| 16890 |
|
| 16891 |
// The transform has determined that we should perform an elementwise |
| 16892 |
// expansion of the pattern. Do so. |
| 16893 |
for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 16894 |
Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I); |
| 16895 |
ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 16896 |
if (Key.isInvalid()) |
| 16897 |
return ExprError(); |
| 16898 |
|
| 16899 |
ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 16900 |
if (Value.isInvalid()) |
| 16901 |
return ExprError(); |
| 16902 |
|
| 16903 |
ObjCDictionaryElement Element = { |
| 16904 |
Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 16905 |
}; |
| 16906 |
|
| 16907 |
// If any unexpanded parameter packs remain, we still have a |
| 16908 |
// pack expansion. |
| 16909 |
// FIXME: Can this really happen? |
| 16910 |
if (Key.get()->containsUnexpandedParameterPack() || |
| 16911 |
Value.get()->containsUnexpandedParameterPack()) |
| 16912 |
Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| 16913 |
|
| 16914 |
Elements.push_back(Element); |
| 16915 |
} |
| 16916 |
|
| 16917 |
// FIXME: Retain a pack expansion if RetainExpansion is true. |
| 16918 |
|
| 16919 |
// We've finished with this pack expansion. |
| 16920 |
continue; |
| 16921 |
} |
| 16922 |
|
| 16923 |
// Transform and check key. |
| 16924 |
ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 16925 |
if (Key.isInvalid()) |
| 16926 |
return ExprError(); |
| 16927 |
|
| 16928 |
if (Key.get() != OrigElement.Key) |
| 16929 |
ArgChanged = true; |
| 16930 |
|
| 16931 |
// Transform and check value. |
| 16932 |
ExprResult Value |
| 16933 |
= getDerived().TransformExpr(OrigElement.Value); |
| 16934 |
if (Value.isInvalid()) |
| 16935 |
return ExprError(); |
| 16936 |
|
| 16937 |
if (Value.get() != OrigElement.Value) |
| 16938 |
ArgChanged = true; |
| 16939 |
|
| 16940 |
ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(), |
| 16941 |
std::nullopt}; |
| 16942 |
Elements.push_back(Element); |
| 16943 |
} |
| 16944 |
|
| 16945 |
if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 16946 |
return SemaRef.MaybeBindToTemporary(E); |
| 16947 |
|
| 16948 |
return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 16949 |
Elements); |
| 16950 |
} |
| 16951 |
|
| 16952 |
template<typename Derived> |
| 16953 |
ExprResult |
| 16954 |
TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 16955 |
TypeSourceInfo *EncodedTypeInfo |
| 16956 |
= getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 16957 |
if (!EncodedTypeInfo) |
| 16958 |
return ExprError(); |
| 16959 |
|
| 16960 |
if (!getDerived().AlwaysRebuild() && |
| 16961 |
EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
| 16962 |
return E; |
| 16963 |
|
| 16964 |
return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 16965 |
EncodedTypeInfo, |
| 16966 |
E->getRParenLoc()); |
| 16967 |
} |
| 16968 |
|
| 16969 |
template<typename Derived> |
| 16970 |
ExprResult TreeTransform<Derived>:: |
| 16971 |
TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 16972 |
// This is a kind of implicit conversion, and it needs to get dropped |
| 16973 |
// and recomputed for the same general reasons that ImplicitCastExprs |
| 16974 |
// do, as well a more specific one: this expression is only valid when |
| 16975 |
// it appears *immediately* as an argument expression. |
| 16976 |
return getDerived().TransformExpr(E->getSubExpr()); |
| 16977 |
} |
| 16978 |
|
| 16979 |
template<typename Derived> |
| 16980 |
ExprResult TreeTransform<Derived>:: |
| 16981 |
TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 16982 |
TypeSourceInfo *TSInfo |
| 16983 |
= getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 16984 |
if (!TSInfo) |
| 16985 |
return ExprError(); |
| 16986 |
|
| 16987 |
ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| 16988 |
if (Result.isInvalid()) |
| 16989 |
return ExprError(); |
| 16990 |
|
| 16991 |
if (!getDerived().AlwaysRebuild() && |
| 16992 |
TSInfo == E->getTypeInfoAsWritten() && |
| 16993 |
Result.get() == E->getSubExpr()) |
| 16994 |
return E; |
| 16995 |
|
| 16996 |
return SemaRef.ObjC().BuildObjCBridgedCast( |
| 16997 |
E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo, |
| 16998 |
Result.get()); |
| 16999 |
} |
| 17000 |
|
| 17001 |
template <typename Derived> |
| 17002 |
ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( |
| 17003 |
ObjCAvailabilityCheckExpr *E) { |
| 17004 |
return E; |
| 17005 |
} |
| 17006 |
|
| 17007 |
template<typename Derived> |
| 17008 |
ExprResult |
| 17009 |
TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
| 17010 |
// Transform arguments. |
| 17011 |
bool ArgChanged = false; |
| 17012 |
SmallVector<Expr*, 8> Args; |
| 17013 |
Args.reserve(E->getNumArgs()); |
| 17014 |
if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 17015 |
&ArgChanged)) |
| 17016 |
return ExprError(); |
| 17017 |
|
| 17018 |
if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 17019 |
// Class message: transform the receiver type. |
| 17020 |
TypeSourceInfo *ReceiverTypeInfo |
| 17021 |
= getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 17022 |
if (!ReceiverTypeInfo) |
| 17023 |
return ExprError(); |
| 17024 |
|
| 17025 |
// If nothing changed, just retain the existing message send. |
| 17026 |
if (!getDerived().AlwaysRebuild() && |
| 17027 |
ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 17028 |
return SemaRef.MaybeBindToTemporary(E); |
| 17029 |
|
| 17030 |
// Build a new class message send. |
| 17031 |
SmallVector<SourceLocation, 16> SelLocs; |
| 17032 |
E->getSelectorLocs(SelLocs); |
| 17033 |
return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 17034 |
E->getSelector(), |
| 17035 |
SelLocs, |
| 17036 |
E->getMethodDecl(), |
| 17037 |
E->getLeftLoc(), |
| 17038 |
Args, |
| 17039 |
E->getRightLoc()); |
| 17040 |
} |
| 17041 |
else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 17042 |
E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| 17043 |
if (!E->getMethodDecl()) |
| 17044 |
return ExprError(); |
| 17045 |
|
| 17046 |
// Build a new class message send to 'super'. |
| 17047 |
SmallVector<SourceLocation, 16> SelLocs; |
| 17048 |
E->getSelectorLocs(SelLocs); |
| 17049 |
return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 17050 |
E->getSelector(), |
| 17051 |
SelLocs, |
| 17052 |
E->getReceiverType(), |
| 17053 |
E->getMethodDecl(), |
| 17054 |
E->getLeftLoc(), |
| 17055 |
Args, |
| 17056 |
E->getRightLoc()); |
| 17057 |
} |
| 17058 |
|
| 17059 |
// Instance message: transform the receiver |
| 17060 |
assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 17061 |
"Only class and instance messages may be instantiated"); |
| 17062 |
ExprResult Receiver |
| 17063 |
= getDerived().TransformExpr(E->getInstanceReceiver()); |
| 17064 |
if (Receiver.isInvalid()) |
| 17065 |
return ExprError(); |
| 17066 |
|
| 17067 |
// If nothing changed, just retain the existing message send. |
| 17068 |
if (!getDerived().AlwaysRebuild() && |
| 17069 |
Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 17070 |
return SemaRef.MaybeBindToTemporary(E); |
| 17071 |
|
| 17072 |
// Build a new instance message send. |
| 17073 |
SmallVector<SourceLocation, 16> SelLocs; |
| 17074 |
E->getSelectorLocs(SelLocs); |
| 17075 |
return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
| 17076 |
E->getSelector(), |
| 17077 |
SelLocs, |
| 17078 |
E->getMethodDecl(), |
| 17079 |
E->getLeftLoc(), |
| 17080 |
Args, |
| 17081 |
E->getRightLoc()); |
| 17082 |
} |
| 17083 |
|
| 17084 |
template<typename Derived> |
| 17085 |
ExprResult |
| 17086 |
TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 17087 |
return E; |
| 17088 |
} |
| 17089 |
|
| 17090 |
template<typename Derived> |
| 17091 |
ExprResult |
| 17092 |
TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 17093 |
return E; |
| 17094 |
} |
| 17095 |
|
| 17096 |
template<typename Derived> |
| 17097 |
ExprResult |
| 17098 |
TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 17099 |
// Transform the base expression. |
| 17100 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 17101 |
if (Base.isInvalid()) |
| 17102 |
return ExprError(); |
| 17103 |
|
| 17104 |
// We don't need to transform the ivar; it will never change. |
| 17105 |
|
| 17106 |
// If nothing changed, just retain the existing expression. |
| 17107 |
if (!getDerived().AlwaysRebuild() && |
| 17108 |
Base.get() == E->getBase()) |
| 17109 |
return E; |
| 17110 |
|
| 17111 |
return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
| 17112 |
E->getLocation(), |
| 17113 |
E->isArrow(), E->isFreeIvar()); |
| 17114 |
} |
| 17115 |
|
| 17116 |
template<typename Derived> |
| 17117 |
ExprResult |
| 17118 |
TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 17119 |
// 'super' and types never change. Property never changes. Just |
| 17120 |
// retain the existing expression. |
| 17121 |
if (!E->isObjectReceiver()) |
| 17122 |
return E; |
| 17123 |
|
| 17124 |
// Transform the base expression. |
| 17125 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 17126 |
if (Base.isInvalid()) |
| 17127 |
return ExprError(); |
| 17128 |
|
| 17129 |
// We don't need to transform the property; it will never change. |
| 17130 |
|
| 17131 |
// If nothing changed, just retain the existing expression. |
| 17132 |
if (!getDerived().AlwaysRebuild() && |
| 17133 |
Base.get() == E->getBase()) |
| 17134 |
return E; |
| 17135 |
|
| 17136 |
if (E->isExplicitProperty()) |
| 17137 |
return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 17138 |
E->getExplicitProperty(), |
| 17139 |
E->getLocation()); |
| 17140 |
|
| 17141 |
return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 17142 |
SemaRef.Context.PseudoObjectTy, |
| 17143 |
E->getImplicitPropertyGetter(), |
| 17144 |
E->getImplicitPropertySetter(), |
| 17145 |
E->getLocation()); |
| 17146 |
} |
| 17147 |
|
| 17148 |
template<typename Derived> |
| 17149 |
ExprResult |
| 17150 |
TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 17151 |
// Transform the base expression. |
| 17152 |
ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 17153 |
if (Base.isInvalid()) |
| 17154 |
return ExprError(); |
| 17155 |
|
| 17156 |
// Transform the key expression. |
| 17157 |
ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 17158 |
if (Key.isInvalid()) |
| 17159 |
return ExprError(); |
| 17160 |
|
| 17161 |
// If nothing changed, just retain the existing expression. |
| 17162 |
if (!getDerived().AlwaysRebuild() && |
| 17163 |
Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 17164 |
return E; |
| 17165 |
|
| 17166 |
return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| 17167 |
Base.get(), Key.get(), |
| 17168 |
E->getAtIndexMethodDecl(), |
| 17169 |
E->setAtIndexMethodDecl()); |
| 17170 |
} |
| 17171 |
|
| 17172 |
template<typename Derived> |
| 17173 |
ExprResult |
| 17174 |
TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
| 17175 |
// Transform the base expression. |
| 17176 |
ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 17177 |
if (Base.isInvalid()) |
| 17178 |
return ExprError(); |
| 17179 |
|
| 17180 |
// If nothing changed, just retain the existing expression. |
| 17181 |
if (!getDerived().AlwaysRebuild() && |
| 17182 |
Base.get() == E->getBase()) |
| 17183 |
return E; |
| 17184 |
|
| 17185 |
return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
| 17186 |
E->getOpLoc(), |
| 17187 |
E->isArrow()); |
| 17188 |
} |
| 17189 |
|
| 17190 |
template<typename Derived> |
| 17191 |
ExprResult |
| 17192 |
TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 17193 |
bool ArgumentChanged = false; |
| 17194 |
SmallVector<Expr*, 8> SubExprs; |
| 17195 |
SubExprs.reserve(E->getNumSubExprs()); |
| 17196 |
if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 17197 |
SubExprs, &ArgumentChanged)) |
| 17198 |
return ExprError(); |
| 17199 |
|
| 17200 |
if (!getDerived().AlwaysRebuild() && |
| 17201 |
!ArgumentChanged) |
| 17202 |
return E; |
| 17203 |
|
| 17204 |
return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 17205 |
SubExprs, |
| 17206 |
E->getRParenLoc()); |
| 17207 |
} |
| 17208 |
|
| 17209 |
template<typename Derived> |
| 17210 |
ExprResult |
| 17211 |
TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 17212 |
ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 17213 |
if (SrcExpr.isInvalid()) |
| 17214 |
return ExprError(); |
| 17215 |
|
| 17216 |
TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 17217 |
if (!Type) |
| 17218 |
return ExprError(); |
| 17219 |
|
| 17220 |
if (!getDerived().AlwaysRebuild() && |
| 17221 |
Type == E->getTypeSourceInfo() && |
| 17222 |
SrcExpr.get() == E->getSrcExpr()) |
| 17223 |
return E; |
| 17224 |
|
| 17225 |
return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 17226 |
SrcExpr.get(), Type, |
| 17227 |
E->getRParenLoc()); |
| 17228 |
} |
| 17229 |
|
| 17230 |
template<typename Derived> |
| 17231 |
ExprResult |
| 17232 |
TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
| 17233 |
BlockDecl *oldBlock = E->getBlockDecl(); |
| 17234 |
|
| 17235 |
SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
| 17236 |
BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 17237 |
|
| 17238 |
blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 17239 |
blockScope->TheDecl->setBlockMissingReturnType( |
| 17240 |
oldBlock->blockMissingReturnType()); |
| 17241 |
|
| 17242 |
SmallVector<ParmVarDecl*, 4> params; |
| 17243 |
SmallVector<QualType, 4> paramTypes; |
| 17244 |
|
| 17245 |
const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 17246 |
|
| 17247 |
// Parameter substitution. |
| 17248 |
Sema::ExtParameterInfoBuilder extParamInfos; |
| 17249 |
if (getDerived().TransformFunctionTypeParams( |
| 17250 |
E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 17251 |
exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 17252 |
extParamInfos)) { |
| 17253 |
getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| 17254 |
return ExprError(); |
| 17255 |
} |
| 17256 |
|
| 17257 |
QualType exprResultType = |
| 17258 |
getDerived().TransformType(exprFunctionType->getReturnType()); |
| 17259 |
|
| 17260 |
auto epi = exprFunctionType->getExtProtoInfo(); |
| 17261 |
epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 17262 |
|
| 17263 |
QualType functionType = |
| 17264 |
getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
| 17265 |
blockScope->FunctionType = functionType; |
| 17266 |
|
| 17267 |
// Set the parameters on the block decl. |
| 17268 |
if (!params.empty()) |
| 17269 |
blockScope->TheDecl->setParams(params); |
| 17270 |
|
| 17271 |
if (!oldBlock->blockMissingReturnType()) { |
| 17272 |
blockScope->HasImplicitReturnType = false; |
| 17273 |
blockScope->ReturnType = exprResultType; |
| 17274 |
} |
| 17275 |
|
| 17276 |
// Transform the body |
| 17277 |
StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 17278 |
if (body.isInvalid()) { |
| 17279 |
getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| 17280 |
return ExprError(); |
| 17281 |
} |
| 17282 |
|
| 17283 |
#ifndef NDEBUG |
| 17284 |
// In builds with assertions, make sure that we captured everything we |
| 17285 |
// captured before. |
| 17286 |
if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 17287 |
for (const auto &I : oldBlock->captures()) { |
| 17288 |
VarDecl *oldCapture = I.getVariable(); |
| 17289 |
|
| 17290 |
// Ignore parameter packs. |
| 17291 |
if (oldCapture->isParameterPack()) |
| 17292 |
continue; |
| 17293 |
|
| 17294 |
VarDecl *newCapture = |
| 17295 |
cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 17296 |
oldCapture)); |
| 17297 |
assert(blockScope->CaptureMap.count(newCapture)); |
| 17298 |
} |
| 17299 |
|
| 17300 |
// The this pointer may not be captured by the instantiated block, even when |
| 17301 |
// it's captured by the original block, if the expression causing the |
| 17302 |
// capture is in the discarded branch of a constexpr if statement. |
| 17303 |
assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) && |
| 17304 |
"this pointer isn't captured in the old block"); |
| 17305 |
} |
| 17306 |
#endif |
| 17307 |
|
| 17308 |
return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 17309 |
/*Scope=*/nullptr); |
| 17310 |
} |
| 17311 |
|
| 17312 |
template<typename Derived> |
| 17313 |
ExprResult |
| 17314 |
TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
| 17315 |
ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 17316 |
if (SrcExpr.isInvalid()) |
| 17317 |
return ExprError(); |
| 17318 |
|
| 17319 |
QualType Type = getDerived().TransformType(E->getType()); |
| 17320 |
|
| 17321 |
return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(), |
| 17322 |
E->getRParenLoc()); |
| 17323 |
} |
| 17324 |
|
| 17325 |
template<typename Derived> |
| 17326 |
ExprResult |
| 17327 |
TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
| 17328 |
bool ArgumentChanged = false; |
| 17329 |
SmallVector<Expr*, 8> SubExprs; |
| 17330 |
SubExprs.reserve(E->getNumSubExprs()); |
| 17331 |
if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 17332 |
SubExprs, &ArgumentChanged)) |
| 17333 |
return ExprError(); |
| 17334 |
|
| 17335 |
if (!getDerived().AlwaysRebuild() && |
| 17336 |
!ArgumentChanged) |
| 17337 |
return E; |
| 17338 |
|
| 17339 |
return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
| 17340 |
E->getOp(), E->getRParenLoc()); |
| 17341 |
} |
| 17342 |
|
| 17343 |
//===----------------------------------------------------------------------===// |
| 17344 |
// Type reconstruction |
| 17345 |
//===----------------------------------------------------------------------===// |
| 17346 |
|
| 17347 |
template<typename Derived> |
| 17348 |
QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 17349 |
SourceLocation Star) { |
| 17350 |
return SemaRef.BuildPointerType(PointeeType, Star, |
| 17351 |
getDerived().getBaseEntity()); |
| 17352 |
} |
| 17353 |
|
| 17354 |
template<typename Derived> |
| 17355 |
QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 17356 |
SourceLocation Star) { |
| 17357 |
return SemaRef.BuildBlockPointerType(PointeeType, Star, |
| 17358 |
getDerived().getBaseEntity()); |
| 17359 |
} |
| 17360 |
|
| 17361 |
template<typename Derived> |
| 17362 |
QualType |
| 17363 |
TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 17364 |
bool WrittenAsLValue, |
| 17365 |
SourceLocation Sigil) { |
| 17366 |
return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
| 17367 |
Sigil, getDerived().getBaseEntity()); |
| 17368 |
} |
| 17369 |
|
| 17370 |
template <typename Derived> |
| 17371 |
QualType TreeTransform<Derived>::RebuildMemberPointerType( |
| 17372 |
QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, |
| 17373 |
SourceLocation Sigil) { |
| 17374 |
return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil, |
| 17375 |
getDerived().getBaseEntity()); |
| 17376 |
} |
| 17377 |
|
| 17378 |
template<typename Derived> |
| 17379 |
QualType TreeTransform<Derived>::RebuildObjCTypeParamType( |
| 17380 |
const ObjCTypeParamDecl *Decl, |
| 17381 |
SourceLocation ProtocolLAngleLoc, |
| 17382 |
ArrayRef<ObjCProtocolDecl *> Protocols, |
| 17383 |
ArrayRef<SourceLocation> ProtocolLocs, |
| 17384 |
SourceLocation ProtocolRAngleLoc) { |
| 17385 |
return SemaRef.ObjC().BuildObjCTypeParamType( |
| 17386 |
Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc, |
| 17387 |
/*FailOnError=*/true); |
| 17388 |
} |
| 17389 |
|
| 17390 |
template<typename Derived> |
| 17391 |
QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 17392 |
QualType BaseType, |
| 17393 |
SourceLocation Loc, |
| 17394 |
SourceLocation TypeArgsLAngleLoc, |
| 17395 |
ArrayRef<TypeSourceInfo *> TypeArgs, |
| 17396 |
SourceLocation TypeArgsRAngleLoc, |
| 17397 |
SourceLocation ProtocolLAngleLoc, |
| 17398 |
ArrayRef<ObjCProtocolDecl *> Protocols, |
| 17399 |
ArrayRef<SourceLocation> ProtocolLocs, |
| 17400 |
SourceLocation ProtocolRAngleLoc) { |
| 17401 |
return SemaRef.ObjC().BuildObjCObjectType( |
| 17402 |
BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc, |
| 17403 |
ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc, |
| 17404 |
/*FailOnError=*/true, |
| 17405 |
/*Rebuilding=*/true); |
| 17406 |
} |
| 17407 |
|
| 17408 |
template<typename Derived> |
| 17409 |
QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 17410 |
QualType PointeeType, |
| 17411 |
SourceLocation Star) { |
| 17412 |
return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 17413 |
} |
| 17414 |
|
| 17415 |
template <typename Derived> |
| 17416 |
QualType TreeTransform<Derived>::RebuildArrayType( |
| 17417 |
QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, |
| 17418 |
Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { |
| 17419 |
if (SizeExpr || !Size) |
| 17420 |
return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 17421 |
IndexTypeQuals, BracketsRange, |
| 17422 |
getDerived().getBaseEntity()); |
| 17423 |
|
| 17424 |
QualType Types[] = { |
| 17425 |
SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 17426 |
SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 17427 |
SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
| 17428 |
}; |
| 17429 |
QualType SizeType; |
| 17430 |
for (const auto &T : Types) |
| 17431 |
if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) { |
| 17432 |
SizeType = T; |
| 17433 |
break; |
| 17434 |
} |
| 17435 |
|
| 17436 |
// Note that we can return a VariableArrayType here in the case where |
| 17437 |
// the element type was a dependent VariableArrayType. |
| 17438 |
IntegerLiteral *ArraySize |
| 17439 |
= IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 17440 |
/*FIXME*/BracketsRange.getBegin()); |
| 17441 |
return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
| 17442 |
IndexTypeQuals, BracketsRange, |
| 17443 |
getDerived().getBaseEntity()); |
| 17444 |
} |
| 17445 |
|
| 17446 |
template <typename Derived> |
| 17447 |
QualType TreeTransform<Derived>::RebuildConstantArrayType( |
| 17448 |
QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, |
| 17449 |
Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { |
| 17450 |
return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, |
| 17451 |
IndexTypeQuals, BracketsRange); |
| 17452 |
} |
| 17453 |
|
| 17454 |
template <typename Derived> |
| 17455 |
QualType TreeTransform<Derived>::RebuildIncompleteArrayType( |
| 17456 |
QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, |
| 17457 |
SourceRange BracketsRange) { |
| 17458 |
return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
| 17459 |
IndexTypeQuals, BracketsRange); |
| 17460 |
} |
| 17461 |
|
| 17462 |
template <typename Derived> |
| 17463 |
QualType TreeTransform<Derived>::RebuildVariableArrayType( |
| 17464 |
QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, |
| 17465 |
unsigned IndexTypeQuals, SourceRange BracketsRange) { |
| 17466 |
return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| 17467 |
SizeExpr, |
| 17468 |
IndexTypeQuals, BracketsRange); |
| 17469 |
} |
| 17470 |
|
| 17471 |
template <typename Derived> |
| 17472 |
QualType TreeTransform<Derived>::RebuildDependentSizedArrayType( |
| 17473 |
QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, |
| 17474 |
unsigned IndexTypeQuals, SourceRange BracketsRange) { |
| 17475 |
return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| 17476 |
SizeExpr, |
| 17477 |
IndexTypeQuals, BracketsRange); |
| 17478 |
} |
| 17479 |
|
| 17480 |
template <typename Derived> |
| 17481 |
QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( |
| 17482 |
QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { |
| 17483 |
return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, |
| 17484 |
AttributeLoc); |
| 17485 |
} |
| 17486 |
|
| 17487 |
template <typename Derived> |
| 17488 |
QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 17489 |
unsigned NumElements, |
| 17490 |
VectorKind VecKind) { |
| 17491 |
// FIXME: semantic checking! |
| 17492 |
return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
| 17493 |
} |
| 17494 |
|
| 17495 |
template <typename Derived> |
| 17496 |
QualType TreeTransform<Derived>::RebuildDependentVectorType( |
| 17497 |
QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, |
| 17498 |
VectorKind VecKind) { |
| 17499 |
return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); |
| 17500 |
} |
| 17501 |
|
| 17502 |
template<typename Derived> |
| 17503 |
QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 17504 |
unsigned NumElements, |
| 17505 |
SourceLocation AttributeLoc) { |
| 17506 |
llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 17507 |
NumElements, true); |
| 17508 |
IntegerLiteral *VectorSize |
| 17509 |
= IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 17510 |
AttributeLoc); |
| 17511 |
return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
| 17512 |
} |
| 17513 |
|
| 17514 |
template<typename Derived> |
| 17515 |
QualType |
| 17516 |
TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
| 17517 |
Expr *SizeExpr, |
| 17518 |
SourceLocation AttributeLoc) { |
| 17519 |
return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
| 17520 |
} |
| 17521 |
|
| 17522 |
template <typename Derived> |
| 17523 |
QualType TreeTransform<Derived>::RebuildConstantMatrixType( |
| 17524 |
QualType ElementType, unsigned NumRows, unsigned NumColumns) { |
| 17525 |
return SemaRef.Context.getConstantMatrixType(ElementType, NumRows, |
| 17526 |
NumColumns); |
| 17527 |
} |
| 17528 |
|
| 17529 |
template <typename Derived> |
| 17530 |
QualType TreeTransform<Derived>::RebuildDependentSizedMatrixType( |
| 17531 |
QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, |
| 17532 |
SourceLocation AttributeLoc) { |
| 17533 |
return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr, |
| 17534 |
AttributeLoc); |
| 17535 |
} |
| 17536 |
|
| 17537 |
template <typename Derived> |
| 17538 |
QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 17539 |
QualType T, MutableArrayRef<QualType> ParamTypes, |
| 17540 |
const FunctionProtoType::ExtProtoInfo &EPI) { |
| 17541 |
return SemaRef.BuildFunctionType(T, ParamTypes, |
| 17542 |
getDerived().getBaseLocation(), |
| 17543 |
getDerived().getBaseEntity(), |
| 17544 |
EPI); |
| 17545 |
} |
| 17546 |
|
| 17547 |
template<typename Derived> |
| 17548 |
QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 17549 |
return SemaRef.Context.getFunctionNoProtoType(T); |
| 17550 |
} |
| 17551 |
|
| 17552 |
template <typename Derived> |
| 17553 |
QualType TreeTransform<Derived>::RebuildUnresolvedUsingType( |
| 17554 |
ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, |
| 17555 |
SourceLocation NameLoc, Decl *D) { |
| 17556 |
assert(D && "no decl found"); |
| 17557 |
if (D->isInvalidDecl()) return QualType(); |
| 17558 |
|
| 17559 |
// FIXME: Doesn't account for ObjCInterfaceDecl! |
| 17560 |
if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { |
| 17561 |
// A valid resolved using typename pack expansion decl can have multiple |
| 17562 |
// UsingDecls, but they must each have exactly one type, and it must be |
| 17563 |
// the same type in every case. But we must have at least one expansion! |
| 17564 |
if (UPD->expansions().empty()) { |
| 17565 |
getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty) |
| 17566 |
<< UPD->isCXXClassMember() << UPD; |
| 17567 |
return QualType(); |
| 17568 |
} |
| 17569 |
|
| 17570 |
// We might still have some unresolved types. Try to pick a resolved type |
| 17571 |
// if we can. The final instantiation will check that the remaining |
| 17572 |
// unresolved types instantiate to the type we pick. |
| 17573 |
QualType FallbackT; |
| 17574 |
QualType T; |
| 17575 |
for (auto *E : UPD->expansions()) { |
| 17576 |
QualType ThisT = |
| 17577 |
RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E); |
| 17578 |
if (ThisT.isNull()) |
| 17579 |
continue; |
| 17580 |
if (ThisT->getAs<UnresolvedUsingType>()) |
| 17581 |
FallbackT = ThisT; |
| 17582 |
else if (T.isNull()) |
| 17583 |
T = ThisT; |
| 17584 |
else |
| 17585 |
assert(getSema().Context.hasSameType(ThisT, T) && |
| 17586 |
"mismatched resolved types in using pack expansion"); |
| 17587 |
} |
| 17588 |
return T.isNull() ? FallbackT : T; |
| 17589 |
} |
| 17590 |
if (auto *Using = dyn_cast<UsingDecl>(D)) { |
| 17591 |
assert(Using->hasTypename() && |
| 17592 |
"UnresolvedUsingTypenameDecl transformed to non-typename using"); |
| 17593 |
|
| 17594 |
// A valid resolved using typename decl points to exactly one type decl. |
| 17595 |
assert(++Using->shadow_begin() == Using->shadow_end()); |
| 17596 |
|
| 17597 |
UsingShadowDecl *Shadow = *Using->shadow_begin(); |
| 17598 |
if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc)) |
| 17599 |
return QualType(); |
| 17600 |
return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow); |
| 17601 |
} |
| 17602 |
assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 17603 |
"UnresolvedUsingTypenameDecl transformed to non-using decl"); |
| 17604 |
return SemaRef.Context.getUnresolvedUsingType( |
| 17605 |
Keyword, Qualifier, cast<UnresolvedUsingTypenameDecl>(D)); |
| 17606 |
} |
| 17607 |
|
| 17608 |
template <typename Derived> |
| 17609 |
QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, SourceLocation, |
| 17610 |
TypeOfKind Kind) { |
| 17611 |
return SemaRef.BuildTypeofExprType(E, Kind); |
| 17612 |
} |
| 17613 |
|
| 17614 |
template<typename Derived> |
| 17615 |
QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying, |
| 17616 |
TypeOfKind Kind) { |
| 17617 |
return SemaRef.Context.getTypeOfType(Underlying, Kind); |
| 17618 |
} |
| 17619 |
|
| 17620 |
template <typename Derived> |
| 17621 |
QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, SourceLocation) { |
| 17622 |
return SemaRef.BuildDecltypeType(E); |
| 17623 |
} |
| 17624 |
|
| 17625 |
template <typename Derived> |
| 17626 |
QualType TreeTransform<Derived>::RebuildPackIndexingType( |
| 17627 |
QualType Pattern, Expr *IndexExpr, SourceLocation Loc, |
| 17628 |
SourceLocation EllipsisLoc, bool FullySubstituted, |
| 17629 |
ArrayRef<QualType> Expansions) { |
| 17630 |
return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc, |
| 17631 |
FullySubstituted, Expansions); |
| 17632 |
} |
| 17633 |
|
| 17634 |
template<typename Derived> |
| 17635 |
QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 17636 |
UnaryTransformType::UTTKind UKind, |
| 17637 |
SourceLocation Loc) { |
| 17638 |
return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 17639 |
} |
| 17640 |
|
| 17641 |
template <typename Derived> |
| 17642 |
QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
| 17643 |
ElaboratedTypeKeyword Keyword, TemplateName Template, |
| 17644 |
SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) { |
| 17645 |
return SemaRef.CheckTemplateIdType( |
| 17646 |
Keyword, Template, TemplateNameLoc, TemplateArgs, |
| 17647 |
/*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false); |
| 17648 |
} |
| 17649 |
|
| 17650 |
template<typename Derived> |
| 17651 |
QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 17652 |
SourceLocation KWLoc) { |
| 17653 |
return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 17654 |
} |
| 17655 |
|
| 17656 |
template<typename Derived> |
| 17657 |
QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| 17658 |
SourceLocation KWLoc, |
| 17659 |
bool isReadPipe) { |
| 17660 |
return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) |
| 17661 |
: SemaRef.BuildWritePipeType(ValueType, KWLoc); |
| 17662 |
} |
| 17663 |
|
| 17664 |
template <typename Derived> |
| 17665 |
QualType TreeTransform<Derived>::RebuildBitIntType(bool IsUnsigned, |
| 17666 |
unsigned NumBits, |
| 17667 |
SourceLocation Loc) { |
| 17668 |
llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 17669 |
NumBits, true); |
| 17670 |
IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP, |
| 17671 |
SemaRef.Context.IntTy, Loc); |
| 17672 |
return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc); |
| 17673 |
} |
| 17674 |
|
| 17675 |
template <typename Derived> |
| 17676 |
QualType TreeTransform<Derived>::RebuildDependentBitIntType( |
| 17677 |
bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) { |
| 17678 |
return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc); |
| 17679 |
} |
| 17680 |
|
| 17681 |
template <typename Derived> |
| 17682 |
TemplateName TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 17683 |
bool TemplateKW, |
| 17684 |
TemplateName Name) { |
| 17685 |
return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
| 17686 |
Name); |
| 17687 |
} |
| 17688 |
|
| 17689 |
template <typename Derived> |
| 17690 |
TemplateName TreeTransform<Derived>::RebuildTemplateName( |
| 17691 |
CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, |
| 17692 |
SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) { |
| 17693 |
UnqualifiedId TemplateName; |
| 17694 |
TemplateName.setIdentifier(&Name, NameLoc); |
| 17695 |
Sema::TemplateTy Template; |
| 17696 |
getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc, |
| 17697 |
TemplateName, ParsedType::make(ObjectType), |
| 17698 |
/*EnteringContext=*/false, Template, |
| 17699 |
AllowInjectedClassName); |
| 17700 |
return Template.get(); |
| 17701 |
} |
| 17702 |
|
| 17703 |
template<typename Derived> |
| 17704 |
TemplateName |
| 17705 |
TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 17706 |
SourceLocation TemplateKWLoc, |
| 17707 |
OverloadedOperatorKind Operator, |
| 17708 |
SourceLocation NameLoc, |
| 17709 |
QualType ObjectType, |
| 17710 |
bool AllowInjectedClassName) { |
| 17711 |
UnqualifiedId Name; |
| 17712 |
// FIXME: Bogus location information. |
| 17713 |
SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| 17714 |
Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
| 17715 |
Sema::TemplateTy Template; |
| 17716 |
getSema().ActOnTemplateName( |
| 17717 |
/*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType), |
| 17718 |
/*EnteringContext=*/false, Template, AllowInjectedClassName); |
| 17719 |
return Template.get(); |
| 17720 |
} |
| 17721 |
|
| 17722 |
template <typename Derived> |
| 17723 |
ExprResult TreeTransform<Derived>::RebuildCXXOperatorCallExpr( |
| 17724 |
OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, |
| 17725 |
bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, |
| 17726 |
Expr *Second) { |
| 17727 |
bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
| 17728 |
|
| 17729 |
if (First->getObjectKind() == OK_ObjCProperty) { |
| 17730 |
BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 17731 |
if (BinaryOperator::isAssignmentOp(Opc)) |
| 17732 |
return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc, |
| 17733 |
Opc, First, Second); |
| 17734 |
ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 17735 |
if (Result.isInvalid()) |
| 17736 |
return ExprError(); |
| 17737 |
First = Result.get(); |
| 17738 |
} |
| 17739 |
|
| 17740 |
if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 17741 |
ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 17742 |
if (Result.isInvalid()) |
| 17743 |
return ExprError(); |
| 17744 |
Second = Result.get(); |
| 17745 |
} |
| 17746 |
|
| 17747 |
// Determine whether this should be a builtin operation. |
| 17748 |
if (Op == OO_Subscript) { |
| 17749 |
if (!First->getType()->isOverloadableType() && |
| 17750 |
!Second->getType()->isOverloadableType()) |
| 17751 |
return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second, |
| 17752 |
OpLoc); |
| 17753 |
} else if (Op == OO_Arrow) { |
| 17754 |
// It is possible that the type refers to a RecoveryExpr created earlier |
| 17755 |
// in the tree transformation. |
| 17756 |
if (First->getType()->isDependentType()) |
| 17757 |
return ExprError(); |
| 17758 |
// -> is never a builtin operation. |
| 17759 |
return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 17760 |
} else if (Second == nullptr || isPostIncDec) { |
| 17761 |
if (!First->getType()->isOverloadableType() || |
| 17762 |
(Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { |
| 17763 |
// The argument is not of overloadable type, or this is an expression |
| 17764 |
// of the form &Class::member, so try to create a built-in unary |
| 17765 |
// operation. |
| 17766 |
UnaryOperatorKind Opc |
| 17767 |
= UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 17768 |
|
| 17769 |
return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
| 17770 |
} |
| 17771 |
} else { |
| 17772 |
if (!First->isTypeDependent() && !Second->isTypeDependent() && |
| 17773 |
!First->getType()->isOverloadableType() && |
| 17774 |
!Second->getType()->isOverloadableType()) { |
| 17775 |
// Neither of the arguments is type-dependent or has an overloadable |
| 17776 |
// type, so try to create a built-in binary operation. |
| 17777 |
BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 17778 |
ExprResult Result |
| 17779 |
= SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
| 17780 |
if (Result.isInvalid()) |
| 17781 |
return ExprError(); |
| 17782 |
|
| 17783 |
return Result; |
| 17784 |
} |
| 17785 |
} |
| 17786 |
|
| 17787 |
// Create the overloaded operator invocation for unary operators. |
| 17788 |
if (!Second || isPostIncDec) { |
| 17789 |
UnaryOperatorKind Opc |
| 17790 |
= UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 17791 |
return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, |
| 17792 |
RequiresADL); |
| 17793 |
} |
| 17794 |
|
| 17795 |
// Create the overloaded operator invocation for binary operators. |
| 17796 |
BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 17797 |
ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, |
| 17798 |
First, Second, RequiresADL); |
| 17799 |
if (Result.isInvalid()) |
| 17800 |
return ExprError(); |
| 17801 |
|
| 17802 |
return Result; |
| 17803 |
} |
| 17804 |
|
| 17805 |
template<typename Derived> |
| 17806 |
ExprResult |
| 17807 |
TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
| 17808 |
SourceLocation OperatorLoc, |
| 17809 |
bool isArrow, |
| 17810 |
CXXScopeSpec &SS, |
| 17811 |
TypeSourceInfo *ScopeType, |
| 17812 |
SourceLocation CCLoc, |
| 17813 |
SourceLocation TildeLoc, |
| 17814 |
PseudoDestructorTypeStorage Destroyed) { |
| 17815 |
QualType CanonicalBaseType = Base->getType().getCanonicalType(); |
| 17816 |
if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
| 17817 |
(!isArrow && !isa<RecordType>(CanonicalBaseType)) || |
| 17818 |
(isArrow && isa<PointerType>(CanonicalBaseType) && |
| 17819 |
!cast<PointerType>(CanonicalBaseType) |
| 17820 |
->getPointeeType() |
| 17821 |
->getAsCanonical<RecordType>())) { |
| 17822 |
// This pseudo-destructor expression is still a pseudo-destructor. |
| 17823 |
return SemaRef.BuildPseudoDestructorExpr( |
| 17824 |
Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 17825 |
CCLoc, TildeLoc, Destroyed); |
| 17826 |
} |
| 17827 |
|
| 17828 |
TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
| 17829 |
DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 17830 |
SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 17831 |
DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 17832 |
NameInfo.setNamedTypeInfo(DestroyedType); |
| 17833 |
|
| 17834 |
// The scope type is now known to be a valid nested name specifier |
| 17835 |
// component. Tack it on to the nested name specifier. |
| 17836 |
if (ScopeType) { |
| 17837 |
if (!isa<TagType>(ScopeType->getType().getCanonicalType())) { |
| 17838 |
getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 17839 |
diag::err_expected_class_or_namespace) |
| 17840 |
<< ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 17841 |
return ExprError(); |
| 17842 |
} |
| 17843 |
SS.clear(); |
| 17844 |
SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc); |
| 17845 |
} |
| 17846 |
|
| 17847 |
SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
| 17848 |
return getSema().BuildMemberReferenceExpr( |
| 17849 |
Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc, |
| 17850 |
/*FIXME: FirstQualifier*/ nullptr, NameInfo, |
| 17851 |
/*TemplateArgs*/ nullptr, |
| 17852 |
/*S*/ nullptr); |
| 17853 |
} |
| 17854 |
|
| 17855 |
template<typename Derived> |
| 17856 |
StmtResult |
| 17857 |
TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| 17858 |
SourceLocation Loc = S->getBeginLoc(); |
| 17859 |
CapturedDecl *CD = S->getCapturedDecl(); |
| 17860 |
unsigned NumParams = CD->getNumParams(); |
| 17861 |
unsigned ContextParamPos = CD->getContextParamPosition(); |
| 17862 |
SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 17863 |
for (unsigned I = 0; I < NumParams; ++I) { |
| 17864 |
if (I != ContextParamPos) { |
| 17865 |
Params.push_back( |
| 17866 |
std::make_pair( |
| 17867 |
CD->getParam(I)->getName(), |
| 17868 |
getDerived().TransformType(CD->getParam(I)->getType()))); |
| 17869 |
} else { |
| 17870 |
Params.push_back(std::make_pair(StringRef(), QualType())); |
| 17871 |
} |
| 17872 |
} |
| 17873 |
getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
| 17874 |
S->getCapturedRegionKind(), Params); |
| 17875 |
StmtResult Body; |
| 17876 |
{ |
| 17877 |
Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 17878 |
Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 17879 |
} |
| 17880 |
|
| 17881 |
if (Body.isInvalid()) { |
| 17882 |
getSema().ActOnCapturedRegionError(); |
| 17883 |
return StmtError(); |
| 17884 |
} |
| 17885 |
|
| 17886 |
return getSema().ActOnCapturedRegionEnd(Body.get()); |
| 17887 |
} |
| 17888 |
|
| 17889 |
template <typename Derived> |
| 17890 |
StmtResult |
| 17891 |
TreeTransform<Derived>::TransformSYCLKernelCallStmt(SYCLKernelCallStmt *S) { |
| 17892 |
// SYCLKernelCallStmt nodes are inserted upon completion of a (non-template) |
| 17893 |
// function definition or instantiation of a function template specialization |
| 17894 |
// and will therefore never appear in a dependent context. |
| 17895 |
llvm_unreachable("SYCL kernel call statement cannot appear in dependent " |
| 17896 |
"context"); |
| 17897 |
} |
| 17898 |
|
| 17899 |
template <typename Derived> |
| 17900 |
ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) { |
| 17901 |
// We can transform the base expression and allow argument resolution to fill |
| 17902 |
// in the rest. |
| 17903 |
return getDerived().TransformExpr(E->getArgLValue()); |
| 17904 |
} |
| 17905 |
|
| 17906 |
} // end namespace clang |
| 17907 |
|
| 17908 |
#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |