1//==--- TypeProperties.td - Type property definitions ---------------------===// 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 9include "clang/AST/PropertiesBase.td" 10include "clang/Basic/TypeNodes.td" 11 12let Class = ComplexType in { 13 def : Property<"elementType", QualType> { 14 let Read = [{ node->getElementType() }]; 15 } 16 17 def : Creator<[{ return ctx.getComplexType(elementType); }]>; 18} 19 20let Class = PointerType in { 21 def : Property<"pointeeType", QualType> { 22 let Read = [{ node->getPointeeType() }]; 23 } 24 25 def : Creator<[{ return ctx.getPointerType(pointeeType); }]>; 26} 27 28let Class = AdjustedType in { 29 def : Property<"originalType", QualType> { 30 let Read = [{ node->getOriginalType() }]; 31 } 32 def : Property<"adjustedType", QualType> { 33 let Read = [{ node->getAdjustedType() }]; 34 } 35 36 def : Creator<[{ return ctx.getAdjustedType(originalType, adjustedType); }]>; 37} 38 39let Class = DecayedType in { 40 def : Override { 41 // We don't need to serialize the adjusted type because we can always 42 // derive it by decaying the original type. 43 let IgnoredProperties = [ "adjustedType" ]; 44 } 45 46 def : Creator<[{ return ctx.getAdjustedParameterType(originalType); }]>; 47} 48 49let Class = BlockPointerType in { 50 def : Property<"pointeeType", QualType> { 51 let Read = [{ node->getPointeeType() }]; 52 } 53 54 def : Creator<[{ return ctx.getBlockPointerType(pointeeType); }]>; 55} 56 57let Class = ReferenceType in { 58 def : Property<"pointeeTypeAsWritten", QualType> { 59 let Read = [{ node->getPointeeTypeAsWritten() }]; 60 } 61} 62 63let Class = LValueReferenceType in { 64 def : Property<"isSpelledAsLValue", Bool> { 65 let Read = [{ node->isSpelledAsLValue() }]; 66 } 67 68 def : Creator<[{ 69 return ctx.getLValueReferenceType(pointeeTypeAsWritten, 70 isSpelledAsLValue); 71 }]>; 72} 73 74let Class = RValueReferenceType in { 75 def : Creator<[{ 76 return ctx.getRValueReferenceType(pointeeTypeAsWritten); 77 }]>; 78} 79 80let Class = MemberPointerType in { 81 def : Property<"pointeeType", QualType> { 82 let Read = [{ node->getPointeeType() }]; 83 } 84 def : Property<"baseType", QualType> { 85 let Read = [{ QualType(node->getClass(), 0) }]; 86 } 87 88 def : Creator<[{ 89 return ctx.getMemberPointerType(pointeeType, baseType.getTypePtr()); 90 }]>; 91} 92 93let Class = ArrayType in { 94 def : Property<"elementType", QualType> { 95 let Read = [{ node->getElementType() }]; 96 } 97 def : Property<"sizeModifier", ArraySizeModifier> { 98 let Read = [{ node->getSizeModifier() }]; 99 } 100 def : Property<"indexQualifiers", Qualifiers> { 101 let Read = [{ Qualifiers::fromCVRMask(node->getIndexTypeCVRQualifiers()) }]; 102 } 103} 104 105let Class = ConstantArrayType in { 106 def : Property<"sizeValue", APInt> { 107 let Read = [{ node->getSize() }]; 108 } 109 def : Property<"size", ExprRef> { 110 let Read = [{ node->getSizeExpr() }]; 111 } 112 113 def : Creator<[{ 114 return ctx.getConstantArrayType(elementType, sizeValue, size, 115 sizeModifier, 116 indexQualifiers.getCVRQualifiers()); 117 }]>; 118} 119 120let Class = IncompleteArrayType in { 121 def : Creator<[{ 122 return ctx.getIncompleteArrayType(elementType, sizeModifier, 123 indexQualifiers.getCVRQualifiers()); 124 }]>; 125} 126 127let Class = VariableArrayType in { 128 def : Property<"leftBracketLoc", SourceLocation> { 129 let Read = [{ node->getLBracketLoc() }]; 130 } 131 def : Property<"rightBracketLoc", SourceLocation> { 132 let Read = [{ node->getRBracketLoc() }]; 133 } 134 def : Property<"size", ExprRef> { 135 let Read = [{ node->getSizeExpr() }]; 136 } 137 138 def : Creator<[{ 139 return ctx.getVariableArrayType(elementType, size, sizeModifier, 140 indexQualifiers.getCVRQualifiers(), 141 SourceRange(leftBracketLoc, 142 rightBracketLoc)); 143 }]>; 144} 145 146let Class = DependentSizedArrayType in { 147 def : Property<"size", ExprRef> { 148 let Read = [{ node->getSizeExpr() }]; 149 } 150 def : Property<"leftBracketLoc", SourceLocation> { 151 let Read = [{ node->getLBracketLoc() }]; 152 } 153 def : Property<"rightBracketLoc", SourceLocation> { 154 let Read = [{ node->getRBracketLoc() }]; 155 } 156 157 def : Creator<[{ 158 return ctx.getDependentSizedArrayType(elementType, size, sizeModifier, 159 indexQualifiers.getCVRQualifiers(), 160 SourceRange(leftBracketLoc, 161 rightBracketLoc)); 162 }]>; 163} 164 165let Class = VectorType in { 166 def : Property<"elementType", QualType> { 167 let Read = [{ node->getElementType() }]; 168 } 169 def : Property<"numElements", UInt32> { 170 let Read = [{ node->getNumElements() }]; 171 } 172 def : Property<"vectorKind", VectorKind> { 173 let Read = [{ node->getVectorKind() }]; 174 } 175 176 def : Creator<[{ 177 return ctx.getVectorType(elementType, numElements, vectorKind); 178 }]>; 179} 180 181let Class = DependentVectorType in { 182 def : Property<"elementType", QualType> { 183 let Read = [{ node->getElementType() }]; 184 } 185 def : Property<"size", ExprRef> { 186 let Read = [{ node->getSizeExpr() }]; 187 } 188 def : Property<"attributeLoc", SourceLocation> { 189 let Read = [{ node->getAttributeLoc() }]; 190 } 191 def : Property<"vectorKind", VectorKind> { 192 let Read = [{ node->getVectorKind() }]; 193 } 194 195 def : Creator<[{ 196 return ctx.getDependentVectorType(elementType, size, attributeLoc, 197 vectorKind); 198 }]>; 199} 200 201let Class = ExtVectorType in { 202 def : Override { 203 let IgnoredProperties = [ "vectorKind" ]; 204 } 205 206 def : Creator<[{ 207 return ctx.getExtVectorType(elementType, numElements); 208 }]>; 209} 210 211let Class = DependentSizedExtVectorType in { 212 def : Property<"elementType", QualType> { 213 let Read = [{ node->getElementType() }]; 214 } 215 def : Property<"size", ExprRef> { 216 let Read = [{ node->getSizeExpr() }]; 217 } 218 def : Property<"attributeLoc", SourceLocation> { 219 let Read = [{ node->getAttributeLoc() }]; 220 } 221 222 def : Creator<[{ 223 return ctx.getDependentSizedExtVectorType(elementType, size, attributeLoc); 224 }]>; 225} 226 227let Class = MatrixType in { 228 def : Property<"elementType", QualType> { 229 let Read = [{ node->getElementType() }]; 230 } 231} 232 233let Class = ConstantMatrixType in { 234 def : Property<"numRows", UInt32> { 235 let Read = [{ node->getNumRows() }]; 236 } 237 def : Property<"numColumns", UInt32> { 238 let Read = [{ node->getNumColumns() }]; 239 } 240 241 def : Creator<[{ 242 return ctx.getConstantMatrixType(elementType, numRows, numColumns); 243 }]>; 244} 245 246let Class = DependentSizedMatrixType in { 247 def : Property<"rows", ExprRef> { 248 let Read = [{ node->getRowExpr() }]; 249 } 250 def : Property<"columns", ExprRef> { 251 let Read = [{ node->getColumnExpr() }]; 252 } 253 def : Property<"attributeLoc", SourceLocation> { 254 let Read = [{ node->getAttributeLoc() }]; 255 } 256 257 def : Creator<[{ 258 return ctx.getDependentSizedMatrixType(elementType, rows, columns, attributeLoc); 259 }]>; 260} 261 262let Class = FunctionType in { 263 def : Property<"returnType", QualType> { 264 let Read = [{ node->getReturnType() }]; 265 } 266 def : Property<"noReturn", Bool> { 267 let Read = [{ node->getExtInfo().getNoReturn() }]; 268 } 269 def : Property<"hasRegParm", Bool> { 270 let Read = [{ node->getExtInfo().getHasRegParm() }]; 271 } 272 def : Property<"regParm", UInt32> { 273 let Read = [{ node->getExtInfo().getRegParm() }]; 274 } 275 def : Property<"callingConvention", CallingConv> { 276 let Read = [{ node->getExtInfo().getCC() }]; 277 } 278 def : Property<"producesResult", Bool> { 279 let Read = [{ node->getExtInfo().getProducesResult() }]; 280 } 281 def : Property<"noCallerSavedRegs", Bool> { 282 let Read = [{ node->getExtInfo().getNoCallerSavedRegs() }]; 283 } 284 def : Property<"noCfCheck", Bool> { 285 let Read = [{ node->getExtInfo().getNoCfCheck() }]; 286 } 287 def : Property<"cmseNSCall", Bool> { 288 let Read = [{ node->getExtInfo().getCmseNSCall() }]; 289 } 290} 291 292let Class = FunctionNoProtoType in { 293 def : Creator<[{ 294 auto extInfo = FunctionType::ExtInfo(noReturn, hasRegParm, regParm, 295 callingConvention, producesResult, 296 noCallerSavedRegs, noCfCheck, 297 cmseNSCall); 298 return ctx.getFunctionNoProtoType(returnType, extInfo); 299 }]>; 300} 301 302let Class = FunctionProtoType in { 303 def : Property<"variadic", Bool> { 304 let Read = [{ node->isVariadic() }]; 305 } 306 def : Property<"trailingReturn", Bool> { 307 let Read = [{ node->hasTrailingReturn() }]; 308 } 309 def : Property<"methodQualifiers", Qualifiers> { 310 let Read = [{ node->getMethodQuals() }]; 311 } 312 def : Property<"refQualifier", RefQualifierKind> { 313 let Read = [{ node->getRefQualifier() }]; 314 } 315 def : Property<"exceptionSpecifier", ExceptionSpecInfo> { 316 let Read = [{ node->getExceptionSpecInfo() }]; 317 } 318 def : Property<"parameters", Array<QualType>> { 319 let Read = [{ node->getParamTypes() }]; 320 } 321 def : Property<"extParameterInfo", Array<ExtParameterInfo>> { 322 let Read = [{ node->hasExtParameterInfos() 323 ? node->getExtParameterInfos() 324 : llvm::ArrayRef<FunctionProtoType::ExtParameterInfo>() }]; 325 } 326 def : Property<"AArch64SMEAttributes", UInt32> { 327 let Read = [{ node->getAArch64SMEAttributes() }]; 328 } 329 330 def : Creator<[{ 331 auto extInfo = FunctionType::ExtInfo(noReturn, hasRegParm, regParm, 332 callingConvention, producesResult, 333 noCallerSavedRegs, noCfCheck, 334 cmseNSCall); 335 FunctionProtoType::ExtProtoInfo epi; 336 epi.ExtInfo = extInfo; 337 epi.Variadic = variadic; 338 epi.HasTrailingReturn = trailingReturn; 339 epi.TypeQuals = methodQualifiers; 340 epi.RefQualifier = refQualifier; 341 epi.ExceptionSpec = exceptionSpecifier; 342 epi.ExtParameterInfos = 343 extParameterInfo.empty() ? nullptr : extParameterInfo.data(); 344 epi.AArch64SMEAttributes = AArch64SMEAttributes; 345 return ctx.getFunctionType(returnType, parameters, epi); 346 }]>; 347} 348 349let Class = AtomicType in { 350 def : Property<"valueType", QualType> { 351 let Read = [{ node->getValueType() }]; 352 } 353 354 def : Creator<[{ 355 return ctx.getAtomicType(valueType); 356 }]>; 357} 358 359let Class = UnresolvedUsingType in { 360 def : Property<"declaration", DeclRef> { 361 let Read = [{ node->getDecl() }]; 362 } 363 364 def : Creator<[{ 365 return ctx.getUnresolvedUsingType(cast<UnresolvedUsingTypenameDecl>(declaration)); 366 }]>; 367} 368 369let Class = UsingType in { 370 def : Property<"foundDeclaration", UsingShadowDeclRef> { 371 let Read = [{ node->getFoundDecl() }]; 372 } 373 def : Property<"underlyingType", QualType> { 374 let Read = [{ node->getUnderlyingType() }]; 375 } 376 377 def : Creator<[{ 378 return ctx.getUsingType(foundDeclaration, underlyingType); 379 }]>; 380} 381 382let Class = TypedefType in { 383 def : Property<"declaration", DeclRef> { 384 let Read = [{ node->getDecl() }]; 385 } 386 def : Property<"underlyingType", QualType> { 387 let Read = [{ node->desugar() }]; 388 } 389 390 def : Creator<[{ 391 return ctx.getTypedefType(cast<TypedefNameDecl>(declaration), underlyingType); 392 }]>; 393} 394 395let Class = TypeOfExprType in { 396 def : Property<"expression", ExprRef> { 397 let Read = [{ node->getUnderlyingExpr() }]; 398 } 399 400 def : Property<"kind", TypeOfKind> { 401 let Read = [{ node->getKind() }]; 402 } 403 404 def : Creator<[{ 405 return ctx.getTypeOfExprType(expression, kind); 406 }]>; 407} 408 409let Class = TypeOfType in { 410 def : Property<"unmodifiedType", QualType> { 411 let Read = [{ node->getUnmodifiedType() }]; 412 } 413 414 def : Property<"kind", TypeOfKind> { 415 let Read = [{ node->getKind() }]; 416 } 417 418 def : Creator<[{ 419 return ctx.getTypeOfType(unmodifiedType, kind); 420 }]>; 421} 422 423let Class = DecltypeType in { 424 def : Property<"underlyingType", QualType> { 425 let Read = [{ node->getUnderlyingType() }]; 426 } 427 def : Property<"expression", ExprRef> { 428 let Read = [{ node->getUnderlyingExpr() }]; 429 } 430 431 def : Creator<[{ 432 return ctx.getDecltypeType(expression, underlyingType); 433 }]>; 434} 435 436let Class = UnaryTransformType in { 437 def : Property<"baseType", QualType> { 438 let Read = [{ node->getBaseType() }]; 439 } 440 def : Property<"underlyingType", QualType> { 441 let Read = [{ node->getUnderlyingType() }]; 442 } 443 def : Property<"transform", UnaryTypeTransformKind> { 444 let Read = [{ node->getUTTKind() }]; 445 } 446 447 def : Creator<[{ 448 return ctx.getUnaryTransformType(baseType, underlyingType, transform); 449 }]>; 450} 451 452let Class = AutoType in { 453 def : Property<"deducedType", Optional<QualType>> { 454 let Read = [{ makeOptionalFromNullable(node->getDeducedType()) }]; 455 } 456 def : Property<"keyword", AutoTypeKeyword> { 457 let Read = [{ node->getKeyword() }]; 458 } 459 def : Property<"typeConstraintConcept", Optional<ConceptDeclRef>> { 460 let Read = [{ makeOptionalFromPointer( 461 const_cast<const ConceptDecl*>(node->getTypeConstraintConcept())) }]; 462 } 463 def : Property<"typeConstraintArguments", Array<TemplateArgument>> { 464 let Read = [{ node->getTypeConstraintArguments() }]; 465 } 466 // FIXME: better enumerated value 467 // Only really required when the deduced type is null 468 def : Property<"dependence", UInt32> { 469 let Read = [{ !node->getDeducedType().isNull() ? 0 : 470 node->containsUnexpandedParameterPack() ? 2 : 471 node->isDependentType() ? 1 : 0 }]; 472 } 473 474 def : Creator<[{ 475 return ctx.getAutoType(makeNullableFromOptional(deducedType), keyword, 476 /*isDependentWithoutDeducedType*/ dependence > 0, 477 /*isPackWithoutDeducedType*/ dependence > 1, 478 makePointerFromOptional(typeConstraintConcept), 479 typeConstraintArguments); 480 }]>; 481} 482 483let Class = DeducedTemplateSpecializationType in { 484 def : Property<"templateName", Optional<TemplateName>> { 485 let Read = [{ makeOptionalFromNullable(node->getTemplateName()) }]; 486 } 487 def : Property<"deducedType", QualType> { 488 let Read = [{ node->getDeducedType() }]; 489 } 490 // Only really required when the deduced type is null 491 def : Property<"dependent", Bool> { 492 let Read = [{ !node->getDeducedType().isNull() 493 ? false : node->isDependentType() }]; 494 } 495 496 def : Creator<[{ 497 return ctx.getDeducedTemplateSpecializationType( 498 makeNullableFromOptional(templateName), 499 deducedType, dependent); 500 }]>; 501} 502 503let Class = TagType in { 504 def : Property<"dependent", Bool> { 505 let Read = [{ node->isDependentType() }]; 506 } 507 def : Property<"declaration", DeclRef> { 508 // We don't know which declaration was originally referenced here, and we 509 // cannot reference a declaration that follows the use (because that can 510 // introduce deserialization cycles), so conservatively generate a 511 // reference to the first declaration. 512 // FIXME: If this is a reference to a class template specialization, that 513 // can still introduce a deserialization cycle. 514 let Read = [{ node->getDecl()->getCanonicalDecl() }]; 515 } 516} 517 518let Class = EnumType in { 519 def : Creator<[{ 520 QualType result = ctx.getEnumType(cast<EnumDecl>(declaration)); 521 if (dependent) 522 const_cast<Type *>(result.getTypePtr()) 523 ->addDependence(TypeDependence::DependentInstantiation); 524 return result; 525 }]>; 526} 527 528let Class = RecordType in { 529 def : Creator<[{ 530 auto record = cast<RecordDecl>(declaration); 531 QualType result = ctx.getRecordType(record); 532 if (dependent) 533 const_cast<Type *>(result.getTypePtr()) 534 ->addDependence(TypeDependence::DependentInstantiation); 535 return result; 536 }]>; 537} 538 539let Class = ElaboratedType in { 540 def : Property<"keyword", ElaboratedTypeKeyword> { 541 let Read = [{ node->getKeyword() }]; 542 } 543 def : Property<"qualifier", NestedNameSpecifier> { 544 let Read = [{ node->getQualifier() }]; 545 } 546 def : Property<"namedType", QualType> { 547 let Read = [{ node->getNamedType() }]; 548 } 549 def : Property<"ownedTag", Optional<TagDeclRef>> { 550 let Read = [{ makeOptionalFromPointer( 551 const_cast<const TagDecl *>(node->getOwnedTagDecl())) }]; 552 } 553 554 def : Creator<[{ 555 return ctx.getElaboratedType(keyword, qualifier, namedType, 556 makePointerFromOptional(ownedTag)); 557 }]>; 558} 559 560let Class = InjectedClassNameType in { 561 def : Property<"declaration", DeclRef> { 562 // FIXME: drilling down to the canonical declaration is what the 563 // existing serialization code was doing, but it's not clear why. 564 let Read = [{ node->getDecl()->getCanonicalDecl() }]; 565 } 566 def : Property<"injectedSpecializationType", QualType> { 567 let Read = [{ node->getInjectedSpecializationType() }]; 568 } 569 570 def : Creator<[{ 571 // FIXME: ASTContext::getInjectedClassNameType is not currently suitable 572 // for AST reading, too much interdependencies. 573 const Type *T = nullptr; 574 auto typeDecl = cast<CXXRecordDecl>(declaration); 575 for (auto *DI = typeDecl; DI; DI = DI->getPreviousDecl()) { 576 if (const Type *existing = DI->getTypeForDecl()) { 577 T = existing; 578 break; 579 } 580 } 581 if (!T) { 582 T = new (ctx, TypeAlignment) 583 InjectedClassNameType(typeDecl, injectedSpecializationType); 584 for (auto *DI = typeDecl; DI; DI = DI->getPreviousDecl()) 585 DI->setTypeForDecl(T); 586 } 587 return QualType(T, 0); 588 }]>; 589} 590 591let Class = ParenType in { 592 def : Property<"innerType", QualType> { 593 let Read = [{ node->getInnerType() }]; 594 } 595 596 def : Creator<[{ 597 return ctx.getParenType(innerType); 598 }]>; 599} 600 601let Class = MacroQualifiedType in { 602 def : Property<"underlyingType", QualType> { 603 let Read = [{ node->getUnderlyingType() }]; 604 } 605 def : Property<"macroIdentifier", Identifier> { 606 let Read = [{ node->getMacroIdentifier() }]; 607 } 608 609 def : Creator<[{ 610 return ctx.getMacroQualifiedType(underlyingType, macroIdentifier); 611 }]>; 612} 613 614let Class = AttributedType in { 615 def : Property<"modifiedType", QualType> { 616 let Read = [{ node->getModifiedType() }]; 617 } 618 def : Property<"equivalentType", QualType> { 619 let Read = [{ node->getEquivalentType() }]; 620 } 621 def : Property<"attribute", AttrKind> { 622 let Read = [{ node->getAttrKind() }]; 623 } 624 625 def : Creator<[{ 626 return ctx.getAttributedType(attribute, modifiedType, equivalentType); 627 }]>; 628} 629 630let Class = BTFTagAttributedType in { 631 def : Property<"attr", BTFTypeTagAttr> { 632 let Read = [{ node->getAttr() }]; 633 } 634 def : Property<"wrappedType", QualType> { 635 let Read = [{ node->getWrappedType() }]; 636 } 637 638 def : Creator<[{ 639 return ctx.getBTFTagAttributedType(attr, wrappedType); 640 }]>; 641} 642 643let Class = DependentAddressSpaceType in { 644 def : Property<"pointeeType", QualType> { 645 let Read = [{ node->getPointeeType() }]; 646 } 647 def : Property<"addressSpace", ExprRef> { 648 let Read = [{ node->getAddrSpaceExpr() }]; 649 } 650 def : Property<"attributeLoc", SourceLocation> { 651 let Read = [{ node->getAttributeLoc() }]; 652 } 653 654 def : Creator<[{ 655 return ctx.getDependentAddressSpaceType(pointeeType, addressSpace, 656 attributeLoc); 657 }]>; 658} 659 660let Class = TemplateSpecializationType in { 661 def : Property<"dependent", Bool> { 662 let Read = [{ node->isDependentType() }]; 663 } 664 def : Property<"templateName", TemplateName> { 665 let Read = [{ node->getTemplateName() }]; 666 } 667 def : Property<"templateArguments", Array<TemplateArgument>> { 668 let Read = [{ node->template_arguments() }]; 669 } 670 def : Property<"underlyingType", Optional<QualType>> { 671 let Read = [{ 672 node->isTypeAlias() 673 ? std::optional<QualType>(node->getAliasedType()) 674 : node->isCanonicalUnqualified() 675 ? std::nullopt 676 : std::optional<QualType>(node->getCanonicalTypeInternal()) 677 }]; 678 } 679 680 def : Creator<[{ 681 QualType result; 682 if (!underlyingType) { 683 result = ctx.getCanonicalTemplateSpecializationType(templateName, 684 templateArguments); 685 } else { 686 result = ctx.getTemplateSpecializationType(templateName, 687 templateArguments, 688 *underlyingType); 689 } 690 if (dependent) 691 const_cast<Type *>(result.getTypePtr()) 692 ->addDependence(TypeDependence::DependentInstantiation); 693 return result; 694 }]>; 695} 696 697let Class = DependentTemplateSpecializationType in { 698 def : Property<"keyword", ElaboratedTypeKeyword> { 699 let Read = [{ node->getKeyword() }]; 700 } 701 def : Property<"qualifier", NestedNameSpecifier> { 702 let Read = [{ node->getQualifier() }]; 703 } 704 def : Property<"name", Identifier> { 705 let Read = [{ node->getIdentifier() }]; 706 } 707 def : Property<"templateArguments", Array<TemplateArgument>> { 708 let Read = [{ node->template_arguments() }]; 709 } 710 711 def : Creator<[{ 712 return ctx.getDependentTemplateSpecializationType(keyword, qualifier, 713 name, templateArguments); 714 }]>; 715} 716 717let Class = TemplateTypeParmType in { 718 def : Property<"depth", UInt32> { 719 let Read = [{ node->getDepth() }]; 720 } 721 def : Property<"index", UInt32> { 722 let Read = [{ node->getIndex() }]; 723 } 724 def : Property<"isParameterPack", Bool> { 725 let Read = [{ node->isParameterPack() }]; 726 } 727 def : Property<"declaration", Optional<TemplateTypeParmDeclRef>> { 728 let Read = [{ makeOptionalFromPointer( 729 const_cast<const TemplateTypeParmDecl*>(node->getDecl())) }]; 730 } 731 732 def : Creator<[{ 733 return ctx.getTemplateTypeParmType(depth, index, isParameterPack, 734 makePointerFromOptional(declaration)); 735 }]>; 736} 737 738let Class = SubstTemplateTypeParmType in { 739 def : Property<"replacementType", QualType> { 740 let Read = [{ node->getReplacementType() }]; 741 } 742 def : Property<"associatedDecl", DeclRef> { 743 let Read = [{ node->getAssociatedDecl() }]; 744 } 745 def : Property<"Index", UInt32> { 746 let Read = [{ node->getIndex() }]; 747 } 748 def : Property<"PackIndex", Optional<UInt32>> { 749 let Read = [{ node->getPackIndex() }]; 750 } 751 752 // The call to getCanonicalType here existed in ASTReader.cpp, too. 753 def : Creator<[{ 754 return ctx.getSubstTemplateTypeParmType( 755 replacementType, associatedDecl, Index, PackIndex); 756 }]>; 757} 758 759let Class = PackExpansionType in { 760 def : Property<"pattern", QualType> { 761 let Read = [{ node->getPattern() }]; 762 } 763 def : Property<"numExpansions", Optional<UInt32>> { 764 let Read = [{ node->getNumExpansions() }]; 765 } 766 767 def : Creator<[{ 768 return ctx.getPackExpansionType(pattern, numExpansions, 769 /*ExpectPackInType*/false); 770 }]>; 771} 772 773let Class = SubstTemplateTypeParmPackType in { 774 def : Property<"associatedDecl", DeclRef> { 775 let Read = [{ node->getAssociatedDecl() }]; 776 } 777 def : Property<"Index", UInt32> { 778 let Read = [{ node->getIndex() }]; 779 } 780 def : Property<"Final", Bool> { 781 let Read = [{ node->getFinal() }]; 782 } 783 def : Property<"replacementPack", TemplateArgument> { 784 let Read = [{ node->getArgumentPack() }]; 785 } 786 787 def : Creator<[{ 788 return ctx.getSubstTemplateTypeParmPackType( 789 associatedDecl, Index, Final, replacementPack); 790 }]>; 791} 792 793let Class = BuiltinType in { 794 def : Property<"kind", BuiltinTypeKind> { 795 let Read = [{ node->getKind() }]; 796 } 797 798 def : Creator<[{ 799 switch (kind) { 800#define IMAGE_TYPE(IMGTYPE, ID, SINGLETON_ID, ACCESS, SUFFIX) \ 801 case BuiltinType::ID: return ctx.SINGLETON_ID; 802#include "clang/Basic/OpenCLImageTypes.def" 803 804#define EXT_OPAQUE_TYPE(EXTTYPE, ID, EXT) \ 805 case BuiltinType::ID: return ctx.ID##Ty; 806#include "clang/Basic/OpenCLExtensionTypes.def" 807 808#define SVE_TYPE(NAME, ID, SINGLETON_ID) \ 809 case BuiltinType::ID: return ctx.SINGLETON_ID; 810#include "clang/Basic/AArch64SVEACLETypes.def" 811 812#define PPC_VECTOR_TYPE(NAME, ID, SIZE) \ 813 case BuiltinType::ID: return ctx.ID##Ty; 814#include "clang/Basic/PPCTypes.def" 815 816#define RVV_TYPE(NAME, ID, SINGLETON_ID) \ 817 case BuiltinType::ID: return ctx.SINGLETON_ID; 818#include "clang/Basic/RISCVVTypes.def" 819 820#define WASM_TYPE(NAME, ID, SINGLETON_ID) \ 821 case BuiltinType::ID: return ctx.SINGLETON_ID; 822#include "clang/Basic/WebAssemblyReferenceTypes.def" 823 824#define BUILTIN_TYPE(ID, SINGLETON_ID) \ 825 case BuiltinType::ID: return ctx.SINGLETON_ID; 826#include "clang/AST/BuiltinTypes.def" 827 } 828 llvm_unreachable("unreachable builtin case"); 829 }]>; 830} 831 832let Class = DependentNameType in { 833 def : Property<"keyword", ElaboratedTypeKeyword> { 834 let Read = [{ node->getKeyword() }]; 835 } 836 def : Property<"qualifier", NestedNameSpecifier> { 837 let Read = [{ node->getQualifier() }]; 838 } 839 def : Property<"name", Identifier> { 840 let Read = [{ node->getIdentifier() }]; 841 } 842 def : Property<"underlyingType", Optional<QualType>> { 843 let Read = [{ 844 node->isCanonicalUnqualified() 845 ? std::nullopt 846 : std::optional<QualType>(node->getCanonicalTypeInternal()) 847 }]; 848 } 849 850 def : Creator<[{ 851 QualType canon = (underlyingType 852 ? ctx.getCanonicalType(*underlyingType) 853 : QualType()); 854 return ctx.getDependentNameType(keyword, qualifier, name, canon); 855 }]>; 856} 857 858let Class = ObjCObjectType in { 859 def : Property<"baseType", QualType> { 860 let Read = [{ node->getBaseType() }]; 861 } 862 def : Property<"typeArgsAsWritten", Array<QualType>> { 863 let Read = [{ node->getTypeArgsAsWritten() }]; 864 } 865 def : Property<"qualifiers", Array<ObjCProtocolDeclRef>> { 866 let Read = [{ node->getProtocols() }]; 867 } 868 def : Property<"isKindOfTypeAsWritten", Bool> { 869 let Read = [{ node->isKindOfTypeAsWritten() }]; 870 } 871 872 def : Creator<[{ 873 return ctx.getObjCObjectType(baseType, typeArgsAsWritten, qualifiers, 874 isKindOfTypeAsWritten); 875 }]>; 876} 877 878let Class = ObjCInterfaceType in { 879 // We don't actually want any of the properties of the superclass. 880 def : Override { 881 let IgnoredProperties = [ "baseType", "typeArgsAsWritten", 882 "qualifiers", "isKindOfTypeAsWritten" ]; 883 } 884 885 def : Property<"declaration", DeclRef> { 886 // FIXME: drilling down to the canonical declaration is what the 887 // existing serialization code was doing, but it's not clear why. 888 let Read = [{ node->getDecl()->getCanonicalDecl() }]; 889 } 890 891 def : Creator<[{ 892 return ctx.getObjCInterfaceType( 893 cast<ObjCInterfaceDecl>(declaration->getCanonicalDecl())); 894 }]>; 895} 896 897let Class = ObjCTypeParamType in { 898 def : Property<"declaration", ObjCTypeParamDeclRef> { 899 let Read = [{ node->getDecl() }]; 900 } 901 def : Property<"qualifiers", Array<ObjCProtocolDeclRef>> { 902 let Read = [{ node->getProtocols() }]; 903 } 904 905 def : Creator<[{ 906 return ctx.getObjCTypeParamType(declaration, qualifiers); 907 }]>; 908} 909 910let Class = ObjCObjectPointerType in { 911 def : Property<"pointeeType", QualType> { 912 let Read = [{ node->getPointeeType() }]; 913 } 914 915 def : Creator<[{ 916 return ctx.getObjCObjectPointerType(pointeeType); 917 }]>; 918} 919 920let Class = PipeType in { 921 def : Property<"elementType", QualType> { 922 let Read = [{ node->getElementType() }]; 923 } 924 def : Property<"isReadOnly", Bool> { 925 let Read = [{ node->isReadOnly() }]; 926 } 927 928 def : Creator<[{ 929 return ctx.getPipeType(elementType, isReadOnly); 930 }]>; 931} 932 933let Class = BitIntType in { 934 def : Property<"isUnsigned", Bool> { 935 let Read = [{ node->isUnsigned() }]; 936 } 937 def : Property <"numBits", UInt32> { 938 let Read = [{ node->getNumBits() }]; 939 } 940 941 def : Creator<[{ 942 return ctx.getBitIntType(isUnsigned, numBits); 943 }]>; 944} 945 946let Class = DependentBitIntType in { 947 def : Property<"isUnsigned", Bool> { 948 let Read = [{ node->isUnsigned() }]; 949 } 950 def : Property <"numBitsExpr", ExprRef> { 951 let Read = [{ node->getNumBitsExpr() }]; 952 } 953 def : Creator<[{ 954 return ctx.getDependentBitIntType(isUnsigned, numBitsExpr); 955 }]>; 956} 957