@@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field,
92
92
case InfoType::IT_default:
93
93
case InfoType::IT_enum:
94
94
case InfoType::IT_typedef:
95
+ case InfoType::IT_concept:
95
96
Field = IT;
96
97
return llvm::Error::success ();
97
98
}
@@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field,
108
109
case FieldId::F_type:
109
110
case FieldId::F_child_namespace:
110
111
case FieldId::F_child_record:
112
+ case FieldId::F_concept:
111
113
case FieldId::F_default:
112
114
Field = F;
113
115
return llvm::Error::success ();
@@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID,
391
393
" invalid field for TemplateParamInfo" );
392
394
}
393
395
396
+ static llvm::Error parseRecord (const Record &R, unsigned ID,
397
+ llvm::StringRef Blob, ConceptInfo *I) {
398
+ switch (ID) {
399
+ case CONCEPT_USR:
400
+ return decodeRecord (R, I->USR , Blob);
401
+ case CONCEPT_NAME:
402
+ return decodeRecord (R, I->Name , Blob);
403
+ case CONCEPT_IS_TYPE:
404
+ return decodeRecord (R, I->IsType , Blob);
405
+ case CONCEPT_CONSTRAINT_EXPRESSION:
406
+ return decodeRecord (R, I->ConstraintExpression , Blob);
407
+ }
408
+ llvm_unreachable (" invalid field for ConceptInfo" );
409
+ }
410
+
411
+ static llvm::Error parseRecord (const Record &R, unsigned ID,
412
+ llvm::StringRef Blob, ConstraintInfo *I) {
413
+ if (ID == CONSTRAINT_EXPRESSION)
414
+ return decodeRecord (R, I->ConstraintExpr , Blob);
415
+ return llvm::createStringError (llvm::inconvertibleErrorCode (),
416
+ " invalid field for ConstraintInfo" );
417
+ }
418
+
394
419
template <typename T> static llvm::Expected<CommentInfo *> getCommentInfo (T I) {
395
420
return llvm::createStringError (llvm::inconvertibleErrorCode (),
396
421
" invalid type cannot contain CommentInfo" );
@@ -429,6 +454,10 @@ template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) {
429
454
return I->Children .back ().get ();
430
455
}
431
456
457
+ template <> llvm::Expected<CommentInfo *> getCommentInfo (ConceptInfo *I) {
458
+ return &I->Description .emplace_back ();
459
+ }
460
+
432
461
// When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on
433
462
// the parent block to set it. The template specializations define what to do
434
463
// for each supported parent block.
@@ -584,6 +613,17 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) {
584
613
}
585
614
}
586
615
616
+ template <>
617
+ llvm::Error addReference (ConstraintInfo *I, Reference &&R, FieldId F) {
618
+ if (F == FieldId::F_concept) {
619
+ I->ConceptRef = std::move (R);
620
+ return llvm::Error::success ();
621
+ }
622
+ return llvm::createStringError (
623
+ llvm::inconvertibleErrorCode (),
624
+ " ConstraintInfo cannot contain this Reference" );
625
+ }
626
+
587
627
template <typename T, typename ChildInfoType>
588
628
static void addChild (T I, ChildInfoType &&R) {
589
629
llvm::errs () << " invalid child type for info" ;
@@ -600,6 +640,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) {
600
640
template <> void addChild (NamespaceInfo *I, TypedefInfo &&R) {
601
641
I->Children .Typedefs .emplace_back (std::move (R));
602
642
}
643
+ template <> void addChild (NamespaceInfo *I, ConceptInfo &&R) {
644
+ I->Children .Concepts .emplace_back (std::move (R));
645
+ }
603
646
604
647
// Record children:
605
648
template <> void addChild (RecordInfo *I, FunctionInfo &&R) {
@@ -649,6 +692,9 @@ template <> void addTemplate(RecordInfo *I, TemplateInfo &&P) {
649
692
template <> void addTemplate (FunctionInfo *I, TemplateInfo &&P) {
650
693
I->Template .emplace (std::move (P));
651
694
}
695
+ template <> void addTemplate (ConceptInfo *I, TemplateInfo &&P) {
696
+ I->Template = std::move (P);
697
+ }
652
698
653
699
// Template specializations go only into template records.
654
700
template <typename T>
@@ -662,6 +708,14 @@ void addTemplateSpecialization(TemplateInfo *I,
662
708
I->Specialization .emplace (std::move (TSI));
663
709
}
664
710
711
+ template <typename T> static void addConstraint (T I, ConstraintInfo &&C) {
712
+ llvm::errs () << " invalid container for constraint info" ;
713
+ exit (1 );
714
+ }
715
+ template <> void addConstraint (TemplateInfo *I, ConstraintInfo &&C) {
716
+ I->Constraints .emplace_back (std::move (C));
717
+ }
718
+
665
719
// Read records from bitcode into a given info.
666
720
template <typename T>
667
721
llvm::Error ClangDocBitcodeReader::readRecord (unsigned ID, T I) {
@@ -716,6 +770,8 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
716
770
}
717
771
}
718
772
773
+ // TODO: Create a helper that can receive a function to reduce repetition for
774
+ // most blocks.
719
775
template <typename T>
720
776
llvm::Error ClangDocBitcodeReader::readSubBlock (unsigned ID, T I) {
721
777
llvm::TimeTraceScope (" Reducing infos" , " readSubBlock" );
@@ -817,6 +873,20 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
817
873
addChild (I, std::move (TI));
818
874
return llvm::Error::success ();
819
875
}
876
+ case BI_CONSTRAINT_BLOCK_ID: {
877
+ ConstraintInfo CI;
878
+ if (auto Err = readBlock (ID, &CI))
879
+ return Err;
880
+ addConstraint (I, std::move (CI));
881
+ return llvm::Error::success ();
882
+ }
883
+ case BI_CONCEPT_BLOCK_ID: {
884
+ ConceptInfo CI;
885
+ if (auto Err = readBlock (ID, &CI))
886
+ return Err;
887
+ addChild (I, std::move (CI));
888
+ return llvm::Error::success ();
889
+ }
820
890
default :
821
891
return llvm::createStringError (llvm::inconvertibleErrorCode (),
822
892
" invalid subblock type" );
@@ -922,6 +992,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
922
992
return createInfo<EnumInfo>(ID);
923
993
case BI_TYPEDEF_BLOCK_ID:
924
994
return createInfo<TypedefInfo>(ID);
995
+ case BI_CONCEPT_BLOCK_ID:
996
+ return createInfo<ConceptInfo>(ID);
925
997
case BI_FUNCTION_BLOCK_ID:
926
998
return createInfo<FunctionInfo>(ID);
927
999
default :
@@ -962,6 +1034,7 @@ ClangDocBitcodeReader::readBitcode() {
962
1034
case BI_RECORD_BLOCK_ID:
963
1035
case BI_ENUM_BLOCK_ID:
964
1036
case BI_TYPEDEF_BLOCK_ID:
1037
+ case BI_CONCEPT_BLOCK_ID:
965
1038
case BI_FUNCTION_BLOCK_ID: {
966
1039
auto InfoOrErr = readBlockToInfo (ID);
967
1040
if (!InfoOrErr)
0 commit comments