diff --git a/clang/include/clang/ExtractAPI/API.h b/clang/include/clang/ExtractAPI/API.h --- a/clang/include/clang/ExtractAPI/API.h +++ b/clang/include/clang/ExtractAPI/API.h @@ -134,7 +134,48 @@ bool empty() const { return Parameters.empty() && Constraints.empty(); } }; -/// DocComment is a vector of RawComment::CommentLine. +/// Slightly cut down version of PresumedLoc to suit the needs of +/// ExtractAPI. +class RecordLocation { + unsigned Line, Col; + std::string Filename; + +public: + RecordLocation(const unsigned Line, const unsigned Col, + std::string Filename = "") + : Line(Line), Col(Col), Filename(Filename) {} + RecordLocation(const PresumedLoc &Location) + : Line(Location.getLine()), Col(Location.getColumn()), + Filename(Location.getFilename()) {} + RecordLocation() = default; + + bool isInvalid() const { return Filename.empty(); } + bool isValid() const { return !isInvalid(); } + + const char *getFilename() const { return Filename.c_str(); } + + unsigned getLine() const { return Line; } + + unsigned getColumn() const { return Col; } +}; + +/// Store a documentation comment line of an APIRecord +/// +/// Similar to RawComment::CommentLine but use RecordLocation instead +/// of PresumedLoc. +struct CommentLine { + + std::string Text; + RecordLocation Begin; + RecordLocation End; + + CommentLine(llvm::StringRef Text, RecordLocation Begin, RecordLocation End) + : Text(Text), Begin(Begin), End(End) {} + CommentLine(const RawComment::CommentLine RComment) + : Text(RComment.Text), Begin(RComment.Begin), End(RComment.End) {} +}; + +/// DocComment is a vector of extractapi::CommentLine. /// /// Each line represents one line of striped documentation comment, /// with source range information. This simplifies calculating the source @@ -147,7 +188,7 @@ /// /// with multiple lines. /// ^~~~~~~~~~~~~~~~~~~~~~~' Second line. /// \endcode -using DocComment = std::vector; +using DocComment = std::vector; // Classes deriving from APIRecord need to have USR be the first constructor // argument. This is so that they are compatible with `addTopLevelRecord` @@ -223,7 +264,7 @@ StringRef USR; StringRef Name; - PresumedLoc Location; + RecordLocation Location; AvailabilitySet Availabilities; LinkageInfo Linkage; @@ -256,7 +297,7 @@ APIRecord() = delete; APIRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Location, AvailabilitySet Availabilities, + RecordLocation Location, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) @@ -273,7 +314,7 @@ }; struct NamespaceRecord : APIRecord { - NamespaceRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + NamespaceRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) @@ -290,19 +331,20 @@ struct GlobalFunctionRecord : APIRecord { FunctionSignature Signature; - GlobalFunctionRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + GlobalFunctionRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader) - : APIRecord(RK_GlobalFunction, USR, Name, Loc, std::move(Availabilities), - Linkage, Comment, Declaration, SubHeading, - IsFromSystemHeader), + : APIRecord(RK_GlobalFunction, USR, Name, RecordLocation, + std::move(Availabilities), Linkage, Comment, Declaration, + SubHeading, IsFromSystemHeader), Signature(Signature) {} GlobalFunctionRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, @@ -322,7 +364,8 @@ struct GlobalFunctionTemplateRecord : GlobalFunctionRecord { Template Templ; - GlobalFunctionTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + GlobalFunctionTemplateRecord(StringRef USR, StringRef Name, + RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -342,7 +385,7 @@ struct GlobalFunctionTemplateSpecializationRecord : GlobalFunctionRecord { GlobalFunctionTemplateSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -359,17 +402,18 @@ /// This holds information associated with global functions. struct GlobalVariableRecord : APIRecord { - GlobalVariableRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + GlobalVariableRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_GlobalVariable, USR, Name, Loc, std::move(Availabilities), - Linkage, Comment, Declaration, SubHeading, - IsFromSystemHeader) {} + : APIRecord(RK_GlobalVariable, USR, Name, RecordLocation, + std::move(Availabilities), Linkage, Comment, Declaration, + SubHeading, IsFromSystemHeader) {} GlobalVariableRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) @@ -387,7 +431,8 @@ struct GlobalVariableTemplateRecord : GlobalVariableRecord { Template Templ; - GlobalVariableTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + GlobalVariableTemplateRecord(StringRef USR, StringRef Name, + RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -405,7 +450,7 @@ struct GlobalVariableTemplateSpecializationRecord : GlobalVariableRecord { GlobalVariableTemplateSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) @@ -423,7 +468,7 @@ Template Templ; GlobalVariableTemplatePartialSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, class Template Template, @@ -441,13 +486,14 @@ /// This holds information associated with enum constants. struct EnumConstantRecord : APIRecord { - EnumConstantRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + EnumConstantRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_EnumConstant, USR, Name, Loc, std::move(Availabilities), - LinkageInfo::none(), Comment, Declaration, SubHeading, - IsFromSystemHeader) {} + : APIRecord(RK_EnumConstant, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo::none(), Comment, + Declaration, SubHeading, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { return Record->getKind() == RK_EnumConstant; @@ -461,11 +507,11 @@ struct EnumRecord : APIRecord { SmallVector> Constants; - EnumRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + EnumRecord(StringRef USR, StringRef Name, RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_Enum, USR, Name, Loc, std::move(Availabilities), + : APIRecord(RK_Enum, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader) {} @@ -479,13 +525,14 @@ /// This holds information associated with struct fields. struct StructFieldRecord : APIRecord { - StructFieldRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + StructFieldRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_StructField, USR, Name, Loc, std::move(Availabilities), - LinkageInfo::none(), Comment, Declaration, SubHeading, - IsFromSystemHeader) {} + : APIRecord(RK_StructField, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo::none(), Comment, + Declaration, SubHeading, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { return Record->getKind() == RK_StructField; @@ -499,13 +546,13 @@ struct StructRecord : APIRecord { SmallVector> Fields; - StructRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + StructRecord(StringRef USR, StringRef Name, RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_Struct, USR, Name, Loc, std::move(Availabilities), - LinkageInfo::none(), Comment, Declaration, SubHeading, - IsFromSystemHeader) {} + : APIRecord(RK_Struct, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo::none(), Comment, + Declaration, SubHeading, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { return Record->getKind() == RK_Struct; @@ -518,22 +565,22 @@ struct CXXFieldRecord : APIRecord { AccessControl Access; - CXXFieldRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXFieldRecord(StringRef USR, StringRef Name, RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) - : APIRecord(RK_CXXField, USR, Name, Loc, std::move(Availabilities), - LinkageInfo::none(), Comment, Declaration, SubHeading, - IsFromSystemHeader), + : APIRecord(RK_CXXField, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo::none(), Comment, + Declaration, SubHeading, IsFromSystemHeader), Access(Access) {} CXXFieldRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) - : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), + : APIRecord(Kind, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader), Access(Access) {} @@ -549,7 +596,7 @@ struct CXXFieldTemplateRecord : CXXFieldRecord { Template Templ; - CXXFieldTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXFieldTemplateRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -572,11 +619,11 @@ CXXMethodRecord() = delete; CXXMethodRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) - : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), + : APIRecord(Kind, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader), Signature(Signature), Access(Access) {} @@ -585,14 +632,15 @@ }; struct CXXConstructorRecord : CXXMethodRecord { - CXXConstructorRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXConstructorRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) - : CXXMethodRecord(RK_CXXConstructorMethod, USR, Name, Loc, + : CXXMethodRecord(RK_CXXConstructorMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, Access, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { @@ -604,13 +652,14 @@ }; struct CXXDestructorRecord : CXXMethodRecord { - CXXDestructorRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXDestructorRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) - : CXXMethodRecord(RK_CXXDestructorMethod, USR, Name, Loc, + : CXXMethodRecord(RK_CXXDestructorMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, Access, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { @@ -622,14 +671,15 @@ }; struct CXXStaticMethodRecord : CXXMethodRecord { - CXXStaticMethodRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXStaticMethodRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) - : CXXMethodRecord(RK_CXXStaticMethod, USR, Name, Loc, + : CXXMethodRecord(RK_CXXStaticMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, Access, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { @@ -641,14 +691,15 @@ }; struct CXXInstanceMethodRecord : CXXMethodRecord { - CXXInstanceMethodRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXInstanceMethodRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) - : CXXMethodRecord(RK_CXXInstanceMethod, USR, Name, Loc, + : CXXMethodRecord(RK_CXXInstanceMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, Access, IsFromSystemHeader) {} @@ -663,7 +714,7 @@ struct CXXMethodTemplateRecord : CXXMethodRecord { Template Templ; - CXXMethodTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXMethodTemplateRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -682,7 +733,7 @@ struct CXXMethodTemplateSpecializationRecord : CXXMethodRecord { CXXMethodTemplateSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, @@ -711,13 +762,13 @@ bool IsOptional; ObjCPropertyRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, - const DocComment &Comment, + RecordLocation RecordLocation, + AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AttributeKind Attributes, StringRef GetterName, StringRef SetterName, bool IsOptional, bool IsFromSystemHeader) - : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), + : APIRecord(Kind, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader), Attributes(Attributes), GetterName(GetterName), SetterName(SetterName), @@ -730,15 +781,13 @@ }; struct ObjCInstancePropertyRecord : ObjCPropertyRecord { - ObjCInstancePropertyRecord(StringRef USR, StringRef Name, PresumedLoc Loc, - AvailabilitySet Availabilities, - const DocComment &Comment, - DeclarationFragments Declaration, - DeclarationFragments SubHeading, - AttributeKind Attributes, StringRef GetterName, - StringRef SetterName, bool IsOptional, - bool IsFromSystemHeader) - : ObjCPropertyRecord(RK_ObjCInstanceProperty, USR, Name, Loc, + ObjCInstancePropertyRecord( + StringRef USR, StringRef Name, RecordLocation RecordLocation, + AvailabilitySet Availabilities, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading, + AttributeKind Attributes, StringRef GetterName, StringRef SetterName, + bool IsOptional, bool IsFromSystemHeader) + : ObjCPropertyRecord(RK_ObjCInstanceProperty, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Attributes, GetterName, SetterName, IsOptional, IsFromSystemHeader) {} @@ -752,15 +801,13 @@ }; struct ObjCClassPropertyRecord : ObjCPropertyRecord { - ObjCClassPropertyRecord(StringRef USR, StringRef Name, PresumedLoc Loc, - AvailabilitySet Availabilities, - const DocComment &Comment, - DeclarationFragments Declaration, - DeclarationFragments SubHeading, - AttributeKind Attributes, StringRef GetterName, - StringRef SetterName, bool IsOptional, - bool IsFromSystemHeader) - : ObjCPropertyRecord(RK_ObjCClassProperty, USR, Name, Loc, + ObjCClassPropertyRecord( + StringRef USR, StringRef Name, RecordLocation RecordLocation, + AvailabilitySet Availabilities, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading, + AttributeKind Attributes, StringRef GetterName, StringRef SetterName, + bool IsOptional, bool IsFromSystemHeader) + : ObjCPropertyRecord(RK_ObjCClassProperty, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Attributes, GetterName, SetterName, IsOptional, IsFromSystemHeader) {} @@ -778,15 +825,16 @@ using AccessControl = ObjCIvarDecl::AccessControl; AccessControl Access; - ObjCInstanceVariableRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCInstanceVariableRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) - : APIRecord(RK_ObjCIvar, USR, Name, Loc, std::move(Availabilities), - LinkageInfo::none(), Comment, Declaration, SubHeading, - IsFromSystemHeader), + : APIRecord(RK_ObjCIvar, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo::none(), Comment, + Declaration, SubHeading, IsFromSystemHeader), Access(Access) {} static bool classof(const APIRecord *Record) { @@ -804,11 +852,12 @@ ObjCMethodRecord() = delete; ObjCMethodRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, - const DocComment &Comment, DeclarationFragments Declaration, + RecordLocation RecordLocation, + AvailabilitySet Availabilities, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader) - : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), + : APIRecord(Kind, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader), Signature(Signature) {} @@ -817,13 +866,14 @@ }; struct ObjCInstanceMethodRecord : ObjCMethodRecord { - ObjCInstanceMethodRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCInstanceMethodRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader) - : ObjCMethodRecord(RK_ObjCInstanceMethod, USR, Name, Loc, + : ObjCMethodRecord(RK_ObjCInstanceMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { @@ -835,13 +885,14 @@ }; struct ObjCClassMethodRecord : ObjCMethodRecord { - ObjCClassMethodRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCClassMethodRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader) - : ObjCMethodRecord(RK_ObjCClassMethod, USR, Name, Loc, + : ObjCMethodRecord(RK_ObjCClassMethod, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Signature, IsFromSystemHeader) {} @@ -879,12 +930,13 @@ struct StaticFieldRecord : CXXFieldRecord { SymbolReference Context; - StaticFieldRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + StaticFieldRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Context, AccessControl Access, bool IsFromSystemHeader) - : CXXFieldRecord(RK_StaticField, USR, Name, Loc, + : CXXFieldRecord(RK_StaticField, USR, Name, RecordLocation, std::move(Availabilities), Comment, Declaration, SubHeading, Access, IsFromSystemHeader), Context(Context) {} @@ -905,12 +957,14 @@ ObjCContainerRecord() = delete; ObjCContainerRecord(RecordKind Kind, StringRef USR, StringRef Name, - PresumedLoc Loc, AvailabilitySet Availabilities, - LinkageInfo Linkage, const DocComment &Comment, + RecordLocation RecordLocation, + AvailabilitySet Availabilities, LinkageInfo Linkage, + const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), Linkage, - Comment, Declaration, SubHeading, IsFromSystemHeader) {} + : APIRecord(Kind, USR, Name, RecordLocation, std::move(Availabilities), + Linkage, Comment, Declaration, SubHeading, + IsFromSystemHeader) {} virtual ~ObjCContainerRecord() = 0; }; @@ -921,7 +975,7 @@ SmallVector Bases; AccessControl Access; - CXXClassRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + CXXClassRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, RecordKind Kind, @@ -942,7 +996,7 @@ struct ClassTemplateRecord : CXXClassRecord { Template Templ; - ClassTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ClassTemplateRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, @@ -959,7 +1013,7 @@ struct ClassTemplateSpecializationRecord : CXXClassRecord { ClassTemplateSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) @@ -975,7 +1029,7 @@ struct ClassTemplatePartialSpecializationRecord : CXXClassRecord { Template Templ; ClassTemplatePartialSpecializationRecord( - StringRef USR, StringRef Name, PresumedLoc Loc, + StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader) @@ -992,7 +1046,7 @@ struct ConceptRecord : APIRecord { Template Templ; - ConceptRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ConceptRecord(StringRef USR, StringRef Name, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, @@ -1009,12 +1063,13 @@ /// Determine whether the Category is derived from external class interface. bool IsFromExternalModule = false; - ObjCCategoryRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCCategoryRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Interface, bool IsFromSystemHeader) - : ObjCContainerRecord(RK_ObjCCategory, USR, Name, Loc, + : ObjCContainerRecord(RK_ObjCCategory, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader), @@ -1034,13 +1089,14 @@ // ObjCCategoryRecord%s are stored in and owned by APISet. SmallVector Categories; - ObjCInterfaceRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCInterfaceRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference SuperClass, bool IsFromSystemHeader) - : ObjCContainerRecord(RK_ObjCInterface, USR, Name, Loc, + : ObjCContainerRecord(RK_ObjCInterface, USR, Name, RecordLocation, std::move(Availabilities), Linkage, Comment, Declaration, SubHeading, IsFromSystemHeader), SuperClass(SuperClass) {} @@ -1055,11 +1111,12 @@ /// This holds information associated with Objective-C protocols. struct ObjCProtocolRecord : ObjCContainerRecord { - ObjCProtocolRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + ObjCProtocolRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : ObjCContainerRecord(RK_ObjCProtocol, USR, Name, Loc, + : ObjCContainerRecord(RK_ObjCProtocol, USR, Name, RecordLocation, std::move(Availabilities), LinkageInfo::none(), Comment, Declaration, SubHeading, IsFromSystemHeader) {} @@ -1074,12 +1131,13 @@ /// This holds information associated with macro definitions. struct MacroDefinitionRecord : APIRecord { - MacroDefinitionRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + MacroDefinitionRecord(StringRef USR, StringRef Name, + RecordLocation RecordLocation, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) - : APIRecord(RK_MacroDefinition, USR, Name, Loc, AvailabilitySet(), - LinkageInfo(), {}, Declaration, SubHeading, + : APIRecord(RK_MacroDefinition, USR, Name, RecordLocation, + AvailabilitySet(), LinkageInfo(), {}, Declaration, SubHeading, IsFromSystemHeader) {} static bool classof(const APIRecord *Record) { @@ -1098,14 +1156,14 @@ struct TypedefRecord : APIRecord { SymbolReference UnderlyingType; - TypedefRecord(StringRef USR, StringRef Name, PresumedLoc Loc, + TypedefRecord(StringRef USR, StringRef Name, RecordLocation RecordLocation, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference UnderlyingType, bool IsFromSystemHeader) - : APIRecord(RK_Typedef, USR, Name, Loc, std::move(Availabilities), - LinkageInfo(), Comment, Declaration, SubHeading, - IsFromSystemHeader), + : APIRecord(RK_Typedef, USR, Name, RecordLocation, + std::move(Availabilities), LinkageInfo(), Comment, + Declaration, SubHeading, IsFromSystemHeader), UnderlyingType(UnderlyingType) {} static bool classof(const APIRecord *Record) { @@ -1132,7 +1190,8 @@ template <> struct has_function_signature : public std::true_type {}; template <> -struct has_function_signature : public std::true_type {}; +struct has_function_signature : public std::true_type { +}; template <> struct has_function_signature : public std::true_type {}; template <> @@ -1190,7 +1249,7 @@ class APISet { public: NamespaceRecord *addNamespace(APIRecord *Parent, StringRef Name, - StringRef USR, PresumedLoc Loc, + StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -1203,13 +1262,13 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. GlobalVariableRecord * - addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc, + addGlobalVar(StringRef Name, StringRef USR, RecordLocation RecordLocation, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeadin, bool IsFromSystemHeaderg); GlobalVariableTemplateRecord * - addGlobalVariableTemplate(StringRef Name, StringRef USR, PresumedLoc Loc, + addGlobalVariableTemplate(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -1223,14 +1282,15 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. GlobalFunctionRecord * - addGlobalFunction(StringRef Name, StringRef USR, PresumedLoc Loc, - AvailabilitySet Availability, LinkageInfo Linkage, - const DocComment &Comment, DeclarationFragments Declaration, + addGlobalFunction(StringRef Name, StringRef USR, + RecordLocation RecordLocation, AvailabilitySet Availability, + LinkageInfo Linkage, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsFromSystemHeader); GlobalFunctionTemplateRecord *addGlobalFunctionTemplate( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -1238,7 +1298,7 @@ GlobalFunctionTemplateSpecializationRecord * addGlobalFunctionTemplateSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -1252,7 +1312,7 @@ /// to generate the USR for \c D and keep it alive in APISet. EnumConstantRecord * addEnumConstant(EnumRecord *Enum, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); @@ -1262,7 +1322,8 @@ /// \p USR alive. APISet::copyString provides a way to copy strings into /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. - EnumRecord *addEnum(StringRef Name, StringRef USR, PresumedLoc Loc, + EnumRecord *addEnum(StringRef Name, StringRef USR, + RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); @@ -1275,7 +1336,7 @@ /// to generate the USR for \c D and keep it alive in APISet. StructFieldRecord * addStructField(StructRecord *Struct, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); @@ -1285,22 +1346,21 @@ /// \p USR alive. APISet::copyString provides a way to copy strings into /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. - StructRecord *addStruct(StringRef Name, StringRef USR, PresumedLoc Loc, - AvailabilitySet Availability, - const DocComment &Comment, - DeclarationFragments Declaration, - DeclarationFragments SubHeading, - bool IsFromSystemHeader); + StructRecord * + addStruct(StringRef Name, StringRef USR, RecordLocation RecordLocation, + AvailabilitySet Availability, const DocComment &Comment, + DeclarationFragments Declaration, DeclarationFragments SubHeading, + bool IsFromSystemHeader); StaticFieldRecord * - addStaticField(StringRef Name, StringRef USR, PresumedLoc Loc, + addStaticField(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Context, AccessControl Access, bool IsFromSystemHeaderg); CXXFieldRecord *addCXXField(APIRecord *CXXClass, StringRef Name, - StringRef USR, PresumedLoc Loc, + StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -1308,13 +1368,13 @@ AccessControl Access, bool IsFromSystemHeader); CXXFieldTemplateRecord *addCXXFieldTemplate( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, Template Template, bool IsFromSystemHeader); CXXClassRecord *addCXXClass(APIRecord *Parent, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, @@ -1323,75 +1383,75 @@ ClassTemplateRecord * addClassTemplate(APIRecord *Parent, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader); ClassTemplateSpecializationRecord *addClassTemplateSpecialization( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader); ClassTemplatePartialSpecializationRecord * addClassTemplatePartialSpecialization( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader); GlobalVariableTemplateSpecializationRecord * addGlobalVariableTemplateSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); GlobalVariableTemplatePartialSpecializationRecord * addGlobalVariableTemplatePartialSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, bool IsFromSystemHeader); CXXMethodRecord *addCXXInstanceMethod( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader); CXXMethodRecord *addCXXStaticMethod( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader); CXXMethodRecord *addCXXSpecialMethod( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader); CXXMethodTemplateRecord *addCXXMethodTemplate( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, Template Template, bool IsFromSystemHeader); CXXMethodTemplateSpecializationRecord *addCXXMethodTemplateSpec( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader); - ConceptRecord *addConcept(StringRef Name, StringRef USR, PresumedLoc Loc, + ConceptRecord *addConcept(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, @@ -1405,7 +1465,7 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. ObjCCategoryRecord * - addObjCCategory(StringRef Name, StringRef USR, PresumedLoc Loc, + addObjCCategory(StringRef Name, StringRef USR, RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Interface, @@ -1418,7 +1478,7 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. ObjCInterfaceRecord * - addObjCInterface(StringRef Name, StringRef USR, PresumedLoc Loc, + addObjCInterface(StringRef Name, StringRef USR, RecordLocation RecordLocation, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference SuperClass, @@ -1432,7 +1492,7 @@ /// to generate the USR for \c D and keep it alive in APISet. ObjCMethodRecord * addObjCMethod(ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, bool IsInstanceMethod, bool IsFromSystemHeader); @@ -1445,7 +1505,7 @@ /// to generate the USR for \c D and keep it alive in APISet. ObjCPropertyRecord * addObjCProperty(ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, ObjCPropertyRecord::AttributeKind Attributes, @@ -1460,8 +1520,9 @@ /// to generate the USR for \c D and keep it alive in APISet. ObjCInstanceVariableRecord *addObjCInstanceVariable( ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, const DocComment &Comment, - DeclarationFragments Declaration, DeclarationFragments SubHeading, + RecordLocation RecordLocation, AvailabilitySet Availability, + const DocComment &Comment, DeclarationFragments Declaration, + DeclarationFragments SubHeading, ObjCInstanceVariableRecord::AccessControl Access, bool IsFromSystemHeader); @@ -1472,7 +1533,7 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. ObjCProtocolRecord * - addObjCProtocol(StringRef Name, StringRef USR, PresumedLoc Loc, + addObjCProtocol(StringRef Name, StringRef USR, RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); @@ -1485,7 +1546,7 @@ /// SourceLocation SL, const SourceManager &SM) is a helper method to generate /// the USR for the macro and keep it alive in APISet. MacroDefinitionRecord *addMacroDefinition(StringRef Name, StringRef USR, - PresumedLoc Loc, + RecordLocation RecordLocation, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader); @@ -1497,7 +1558,7 @@ /// APISet itself, and APISet::recordUSR(const Decl *D) is a helper method /// to generate the USR for \c D and keep it alive in APISet. TypedefRecord * - addTypedef(StringRef Name, StringRef USR, PresumedLoc Loc, + addTypedef(StringRef Name, StringRef USR, RecordLocation RecordLocation, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference UnderlyingType, bool IsFromSystemHeader); diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h --- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h +++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h @@ -29,6 +29,7 @@ #include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h" #include "clang/Index/USRGeneration.h" #include "llvm/ADT/StringRef.h" +#include #include namespace clang { @@ -123,6 +124,8 @@ const RawComment *fetchRawCommentForDecl(const Decl *Decl) const; protected: + DocComment FetchDocCommentFromDecl(const Decl *Decl); + /// Collect API information for the enum constants and associate with the /// parent enum. void recordEnumConstants(EnumRecord *EnumRecord, @@ -223,6 +226,19 @@ } } +template +DocComment ExtractAPIVisitorBase::FetchDocCommentFromDecl(const Decl *Decl) { + DocComment Comment; + if (auto *RawComment = + getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) { + auto RawCommentVec = RawComment->getFormattedLines( + Context.getSourceManager(), Context.getDiagnostics()); + std::copy(RawCommentVec.begin(), RawCommentVec.end(), + std::back_inserter(Comment)); + } + return Comment; +} + template bool ExtractAPIVisitorBase::VisitVarDecl(const VarDecl *Decl) { // skip function parameters. @@ -252,11 +268,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the variable. DeclarationFragments Declaration = @@ -320,11 +332,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments, sub-heading, and signature of the function. DeclarationFragments SubHeading = @@ -366,11 +374,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the enum. DeclarationFragments Declaration = @@ -482,11 +486,7 @@ LinkageInfo Linkage = Decl->getLinkageAndVisibility(); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the struct. DeclarationFragments Declaration = @@ -514,11 +514,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the struct. DeclarationFragments Declaration = @@ -548,11 +544,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments Declaration = DeclarationFragmentsBuilder::getFragmentsForCXXClass(Decl); DeclarationFragments SubHeading = @@ -604,11 +596,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments SubHeading = DeclarationFragmentsBuilder::getSubHeading(Decl); auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl); @@ -662,11 +650,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments, sub-heading, and signature for the method. DeclarationFragments Declaration = @@ -695,11 +679,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments, sub-heading, and signature for the method. DeclarationFragments Declaration = @@ -729,11 +709,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments Declaration = DeclarationFragmentsBuilder::getFragmentsForConcept(Decl); DeclarationFragments SubHeading = @@ -753,11 +729,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments Declaration = DeclarationFragmentsBuilder::getFragmentsForClassTemplateSpecialization( Decl); @@ -786,11 +758,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments Declaration = DeclarationFragmentsBuilder:: getFragmentsForClassTemplatePartialSpecialization(Decl); DeclarationFragments SubHeading = @@ -821,11 +789,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the variable. DeclarationFragments Declaration; @@ -866,11 +830,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the variable. DeclarationFragments Declaration = @@ -897,11 +857,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the variable. DeclarationFragments Declaration = DeclarationFragmentsBuilder:: @@ -929,11 +885,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); DeclarationFragments SubHeading = DeclarationFragmentsBuilder::getSubHeading(Decl); @@ -961,11 +913,7 @@ PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the interface. DeclarationFragments Declaration = @@ -1009,11 +957,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the protocol. DeclarationFragments Declaration = @@ -1067,11 +1011,7 @@ Context.getSourceManager().getPresumedLoc(Decl->getLocation()); StringRef Name = Decl->getName(); StringRef USR = API.recordUSR(Decl); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); QualType Type = Decl->getUnderlyingType(); SymbolReference SymRef = @@ -1096,11 +1036,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the category. DeclarationFragments Declaration = DeclarationFragmentsBuilder::getFragmentsForObjCCategory(Decl); @@ -1146,11 +1082,7 @@ StringRef USR = API.recordUSR(Constant); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Constant->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Constant)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Constant); // Build declaration fragments and sub-heading for the enum constant. DeclarationFragments Declaration = @@ -1175,11 +1107,7 @@ StringRef USR = API.recordUSR(Field); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Field->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Field)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Field); // Build declaration fragments and sub-heading for the struct field. DeclarationFragments Declaration = @@ -1204,11 +1132,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments and sub-heading for the struct field. DeclarationFragments Declaration = @@ -1233,11 +1157,7 @@ StringRef USR = API.recordUSR(Decl); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Decl->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Decl); // Build declaration fragments, sub-heading, and signature for the method. DeclarationFragments Declaration = @@ -1279,11 +1199,7 @@ StringRef USR = API.recordUSR(Method); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Method->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Method)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Method); // Build declaration fragments, sub-heading, and signature for the method. DeclarationFragments Declaration = @@ -1308,11 +1224,7 @@ StringRef USR = API.recordUSR(Property); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Property->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Property)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Property); // Build declaration fragments and sub-heading for the property. DeclarationFragments Declaration = @@ -1353,11 +1265,7 @@ StringRef USR = API.recordUSR(Ivar); PresumedLoc Loc = Context.getSourceManager().getPresumedLoc(Ivar->getLocation()); - DocComment Comment; - if (auto *RawComment = - getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Ivar)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + DocComment Comment = FetchDocCommentFromDecl(Ivar); // Build declaration fragments and sub-heading for the instance variable. DeclarationFragments Declaration = diff --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp --- a/clang/lib/ExtractAPI/API.cpp +++ b/clang/lib/ExtractAPI/API.cpp @@ -46,7 +46,7 @@ NamespaceRecord * APISet::addNamespace(APIRecord *Parent, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) { @@ -61,7 +61,7 @@ } GlobalVariableRecord * -APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc, +APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Fragments, DeclarationFragments SubHeading, bool IsFromSystemHeader) { @@ -71,7 +71,7 @@ } GlobalVariableTemplateRecord *APISet::addGlobalVariableTemplate( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, @@ -83,7 +83,7 @@ } GlobalFunctionRecord *APISet::addGlobalFunction( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Fragments, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -95,7 +95,7 @@ } GlobalFunctionTemplateRecord *APISet::addGlobalFunctionTemplate( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -108,7 +108,7 @@ GlobalFunctionTemplateSpecializationRecord * APISet::addGlobalFunctionTemplateSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, @@ -120,7 +120,7 @@ } EnumConstantRecord *APISet::addEnumConstant(EnumRecord *Enum, StringRef Name, - StringRef USR, PresumedLoc Loc, + StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -135,7 +135,7 @@ return Enum->Constants.emplace_back(std::move(Record)).get(); } -EnumRecord *APISet::addEnum(StringRef Name, StringRef USR, PresumedLoc Loc, +EnumRecord *APISet::addEnum(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -147,7 +147,7 @@ } StructFieldRecord *APISet::addStructField(StructRecord *Struct, StringRef Name, - StringRef USR, PresumedLoc Loc, + StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -162,19 +162,18 @@ return Struct->Fields.emplace_back(std::move(Record)).get(); } -StructRecord *APISet::addStruct(StringRef Name, StringRef USR, PresumedLoc Loc, - AvailabilitySet Availabilities, - const DocComment &Comment, - DeclarationFragments Declaration, - DeclarationFragments SubHeading, - bool IsFromSystemHeader) { +StructRecord * +APISet::addStruct(StringRef Name, StringRef USR, RecordLocation Loc, + AvailabilitySet Availabilities, const DocComment &Comment, + DeclarationFragments Declaration, + DeclarationFragments SubHeading, bool IsFromSystemHeader) { return addTopLevelRecord(USRBasedLookupTable, Structs, USR, Name, Loc, std::move(Availabilities), Comment, Declaration, SubHeading, IsFromSystemHeader); } StaticFieldRecord * -APISet::addStaticField(StringRef Name, StringRef USR, PresumedLoc Loc, +APISet::addStaticField(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -188,7 +187,7 @@ CXXFieldRecord * APISet::addCXXField(APIRecord *CXXClass, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) { @@ -201,7 +200,7 @@ } CXXFieldTemplateRecord *APISet::addCXXFieldTemplate( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, Template Template, bool IsFromSystemHeader) { @@ -217,7 +216,7 @@ CXXClassRecord * APISet::addCXXClass(APIRecord *Parent, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availabilities, + RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, APIRecord::RecordKind Kind, AccessControl Access, bool IsFromSystemHeader) { @@ -232,7 +231,7 @@ } ClassTemplateRecord *APISet::addClassTemplate( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader) { @@ -247,7 +246,7 @@ } ClassTemplateSpecializationRecord *APISet::addClassTemplateSpecialization( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, AccessControl Access, bool IsFromSystemHeader) { @@ -263,7 +262,7 @@ ClassTemplatePartialSpecializationRecord * APISet::addClassTemplatePartialSpecialization( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, AccessControl Access, bool IsFromSystemHeader) { @@ -279,7 +278,7 @@ GlobalVariableTemplateSpecializationRecord * APISet::addGlobalVariableTemplateSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) { @@ -291,7 +290,7 @@ GlobalVariableTemplatePartialSpecializationRecord * APISet::addGlobalVariableTemplatePartialSpecialization( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, Template Template, @@ -303,7 +302,8 @@ } ConceptRecord *APISet::addConcept(StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availability, + RecordLocation Loc, + AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, @@ -314,8 +314,8 @@ } CXXMethodRecord *APISet::addCXXInstanceMethod( - APIRecord *CXXClassRecord, StringRef Name, StringRef USR, PresumedLoc Loc, - AvailabilitySet Availability, const DocComment &Comment, + APIRecord *CXXClassRecord, StringRef Name, StringRef USR, + RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) { @@ -331,8 +331,8 @@ } CXXMethodRecord *APISet::addCXXStaticMethod( - APIRecord *CXXClassRecord, StringRef Name, StringRef USR, PresumedLoc Loc, - AvailabilitySet Availability, const DocComment &Comment, + APIRecord *CXXClassRecord, StringRef Name, StringRef USR, + RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, bool IsFromSystemHeader) { @@ -348,7 +348,7 @@ } CXXMethodTemplateRecord *APISet::addCXXMethodTemplate( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, Template Template, @@ -364,7 +364,7 @@ } CXXMethodTemplateSpecializationRecord *APISet::addCXXMethodTemplateSpec( - APIRecord *Parent, StringRef Name, StringRef USR, PresumedLoc Loc, + APIRecord *Parent, StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availability, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, FunctionSignature Signature, AccessControl Access, @@ -381,7 +381,7 @@ } ObjCCategoryRecord *APISet::addObjCCategory( - StringRef Name, StringRef USR, PresumedLoc Loc, + StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, SymbolReference Interface, bool IsFromSystemHeader, @@ -402,7 +402,7 @@ } ObjCInterfaceRecord * -APISet::addObjCInterface(StringRef Name, StringRef USR, PresumedLoc Loc, +APISet::addObjCInterface(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, LinkageInfo Linkage, const DocComment &Comment, DeclarationFragments Declaration, @@ -416,10 +416,10 @@ ObjCMethodRecord *APISet::addObjCMethod( ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availabilities, const DocComment &Comment, - DeclarationFragments Declaration, DeclarationFragments SubHeading, - FunctionSignature Signature, bool IsInstanceMethod, - bool IsFromSystemHeader) { + RecordLocation Loc, AvailabilitySet Availabilities, + const DocComment &Comment, DeclarationFragments Declaration, + DeclarationFragments SubHeading, FunctionSignature Signature, + bool IsInstanceMethod, bool IsFromSystemHeader) { std::unique_ptr Record; if (IsInstanceMethod) Record = std::make_unique( @@ -438,8 +438,9 @@ ObjCPropertyRecord *APISet::addObjCProperty( ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availabilities, const DocComment &Comment, - DeclarationFragments Declaration, DeclarationFragments SubHeading, + RecordLocation Loc, AvailabilitySet Availabilities, + const DocComment &Comment, DeclarationFragments Declaration, + DeclarationFragments SubHeading, ObjCPropertyRecord::AttributeKind Attributes, StringRef GetterName, StringRef SetterName, bool IsOptional, bool IsInstanceProperty, bool IsFromSystemHeader) { @@ -462,8 +463,9 @@ ObjCInstanceVariableRecord *APISet::addObjCInstanceVariable( ObjCContainerRecord *Container, StringRef Name, StringRef USR, - PresumedLoc Loc, AvailabilitySet Availabilities, const DocComment &Comment, - DeclarationFragments Declaration, DeclarationFragments SubHeading, + RecordLocation Loc, AvailabilitySet Availabilities, + const DocComment &Comment, DeclarationFragments Declaration, + DeclarationFragments SubHeading, ObjCInstanceVariableRecord::AccessControl Access, bool IsFromSystemHeader) { auto Record = std::make_unique( USR, Name, Loc, std::move(Availabilities), Comment, Declaration, @@ -475,7 +477,7 @@ } ObjCProtocolRecord *APISet::addObjCProtocol(StringRef Name, StringRef USR, - PresumedLoc Loc, + RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, @@ -487,7 +489,7 @@ } MacroDefinitionRecord * -APISet::addMacroDefinition(StringRef Name, StringRef USR, PresumedLoc Loc, +APISet::addMacroDefinition(StringRef Name, StringRef USR, RecordLocation Loc, DeclarationFragments Declaration, DeclarationFragments SubHeading, bool IsFromSystemHeader) { @@ -496,7 +498,7 @@ } TypedefRecord * -APISet::addTypedef(StringRef Name, StringRef USR, PresumedLoc Loc, +APISet::addTypedef(StringRef Name, StringRef USR, RecordLocation Loc, AvailabilitySet Availabilities, const DocComment &Comment, DeclarationFragments Declaration, DeclarationFragments SubHeading, diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp --- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp @@ -14,6 +14,7 @@ #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Version.h" +#include "clang/ExtractAPI/API.h" #include "clang/ExtractAPI/DeclarationFragments.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLFunctionalExtras.h" @@ -105,8 +106,7 @@ } /// Serialize a source position. -Object serializeSourcePosition(const PresumedLoc &Loc) { - assert(Loc.isValid() && "invalid source position"); +Object serializeSourcePosition(const RecordLocation &Loc) { Object SourcePosition; SourcePosition["line"] = Loc.getLine(); @@ -120,7 +120,7 @@ /// \param Loc The presumed location to serialize. /// \param IncludeFileURI If true, include the file path of \p Loc as a URI. /// Defaults to false. -Object serializeSourceLocation(const PresumedLoc &Loc, +Object serializeSourceLocation(const RecordLocation &Loc, bool IncludeFileURI = false) { Object SourceLocation; serializeObject(SourceLocation, "position", serializeSourcePosition(Loc)); @@ -136,8 +136,8 @@ } /// Serialize a source range with begin and end locations. -Object serializeSourceRange(const PresumedLoc &BeginLoc, - const PresumedLoc &EndLoc) { +Object serializeSourceRange(const RecordLocation &BeginLoc, + const RecordLocation &EndLoc) { Object SourceRange; serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc)); serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc)); diff --git a/clang/tools/libclang/CXExtractAPI.cpp b/clang/tools/libclang/CXExtractAPI.cpp --- a/clang/tools/libclang/CXExtractAPI.cpp +++ b/clang/tools/libclang/CXExtractAPI.cpp @@ -61,9 +61,12 @@ Context.getSourceManager().getPresumedLoc(Decl->getLocation()); LinkageInfo Linkage = Decl->getLinkageAndVisibility(); DocComment Comment; - if (auto *RawComment = fetchRawCommentForDecl(Interface)) - Comment = RawComment->getFormattedLines(Context.getSourceManager(), - Context.getDiagnostics()); + if (auto *RawComment = fetchRawCommentForDecl(Interface)) { + auto RawCommentVec = RawComment->getFormattedLines( + Context.getSourceManager(), Context.getDiagnostics()); + std::copy(RawCommentVec.begin(), RawCommentVec.end(), + std::back_inserter(Comment)); + } // Build declaration fragments and sub-heading by generating them for the // interface.