@@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field,
9292  case  InfoType::IT_default:
9393  case  InfoType::IT_enum:
9494  case  InfoType::IT_typedef:
95+   case  InfoType::IT_concept:
9596    Field = IT;
9697    return  llvm::Error::success ();
9798  }
@@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field,
108109  case  FieldId::F_type:
109110  case  FieldId::F_child_namespace:
110111  case  FieldId::F_child_record:
112+   case  FieldId::F_concept:
111113  case  FieldId::F_default:
112114    Field = F;
113115    return  llvm::Error::success ();
@@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID,
391393                                 " invalid field for TemplateParamInfo"  );
392394}
393395
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+ 
394419template  <typename  T> static  llvm::Expected<CommentInfo *> getCommentInfo (T I) {
395420  return  llvm::createStringError (llvm::inconvertibleErrorCode (),
396421                                 " invalid type cannot contain CommentInfo"  );
@@ -429,6 +454,10 @@ template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) {
429454  return  I->Children .back ().get ();
430455}
431456
457+ template  <> llvm::Expected<CommentInfo *> getCommentInfo (ConceptInfo *I) {
458+   return  &I->Description .emplace_back ();
459+ }
460+ 
432461//  When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on
433462//  the parent block to set it. The template specializations define what to do
434463//  for each supported parent block.
@@ -584,6 +613,17 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) {
584613  }
585614}
586615
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+ 
587627template  <typename  T, typename  ChildInfoType>
588628static  void  addChild (T I, ChildInfoType &&R) {
589629  llvm::errs () << " invalid child type for info"  ;
@@ -600,6 +640,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) {
600640template  <> void  addChild (NamespaceInfo *I, TypedefInfo &&R) {
601641  I->Children .Typedefs .emplace_back (std::move (R));
602642}
643+ template  <> void  addChild (NamespaceInfo *I, ConceptInfo &&R) {
644+   I->Children .Concepts .emplace_back (std::move (R));
645+ }
603646
604647//  Record children:
605648template  <> void  addChild (RecordInfo *I, FunctionInfo &&R) {
@@ -649,6 +692,9 @@ template <> void addTemplate(RecordInfo *I, TemplateInfo &&P) {
649692template  <> void  addTemplate (FunctionInfo *I, TemplateInfo &&P) {
650693  I->Template .emplace (std::move (P));
651694}
695+ template  <> void  addTemplate (ConceptInfo *I, TemplateInfo &&P) {
696+   I->Template  = std::move (P);
697+ }
652698
653699//  Template specializations go only into template records.
654700template  <typename  T>
@@ -662,6 +708,14 @@ void addTemplateSpecialization(TemplateInfo *I,
662708  I->Specialization .emplace (std::move (TSI));
663709}
664710
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+ 
665719//  Read records from bitcode into a given info.
666720template  <typename  T>
667721llvm::Error ClangDocBitcodeReader::readRecord (unsigned  ID, T I) {
@@ -716,6 +770,8 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
716770  }
717771}
718772
773+ //  TODO: Create a helper that can receive a function to reduce repetition for
774+ //  most blocks.
719775template  <typename  T>
720776llvm::Error ClangDocBitcodeReader::readSubBlock (unsigned  ID, T I) {
721777  llvm::TimeTraceScope (" Reducing infos"  , " readSubBlock"  );
@@ -817,6 +873,20 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
817873    addChild (I, std::move (TI));
818874    return  llvm::Error::success ();
819875  }
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+   }
820890  default :
821891    return  llvm::createStringError (llvm::inconvertibleErrorCode (),
822892                                   " invalid subblock type"  );
@@ -922,6 +992,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) {
922992    return  createInfo<EnumInfo>(ID);
923993  case  BI_TYPEDEF_BLOCK_ID:
924994    return  createInfo<TypedefInfo>(ID);
995+   case  BI_CONCEPT_BLOCK_ID:
996+     return  createInfo<ConceptInfo>(ID);
925997  case  BI_FUNCTION_BLOCK_ID:
926998    return  createInfo<FunctionInfo>(ID);
927999  default :
@@ -962,6 +1034,7 @@ ClangDocBitcodeReader::readBitcode() {
9621034    case  BI_RECORD_BLOCK_ID:
9631035    case  BI_ENUM_BLOCK_ID:
9641036    case  BI_TYPEDEF_BLOCK_ID:
1037+     case  BI_CONCEPT_BLOCK_ID:
9651038    case  BI_FUNCTION_BLOCK_ID: {
9661039      auto  InfoOrErr = readBlockToInfo (ID);
9671040      if  (!InfoOrErr)
0 commit comments