Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp =================================================================== --- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp +++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp @@ -510,6 +510,7 @@ emitBlock(N, FieldId::F_namespace); for (const auto &CI : I.Description) emitBlock(CI); + emitRecord(I.Access, FUNCTION_ACCESS); emitRecord(I.IsMethod, FUNCTION_IS_METHOD); if (I.DefLoc) emitRecord(I.DefLoc.getValue(), FUNCTION_DEFLOCATION); Index: clang-tools-extra/trunk/clang-doc/Representation.h =================================================================== --- clang-tools-extra/trunk/clang-doc/Representation.h +++ clang-tools-extra/trunk/clang-doc/Representation.h @@ -198,10 +198,11 @@ std::tie(Other.Type, Other.Name, Other.Access); } - AccessSpecifier Access = AccessSpecifier::AS_none; // Access level associated - // with this info (public, - // protected, private, - // none). + // Access level associated with this info (public, protected, private, none). + // AS_public is set as default because the bitcode writer requires the enum + // with value 0 to be used as the default. + // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3) + AccessSpecifier Access = AccessSpecifier::AS_public; }; struct Location { @@ -312,7 +313,10 @@ TypeInfo ReturnType; // Info about the return type of this function. llvm::SmallVector Params; // List of parameters. // Access level for this method (public, private, protected, none). - AccessSpecifier Access = AccessSpecifier::AS_none; + // AS_public is set as default because the bitcode writer requires the enum + // with value 0 to be used as the default. + // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3) + AccessSpecifier Access = AccessSpecifier::AS_public; }; // TODO: Expand to allow for documenting templating, inheritance access, Index: clang-tools-extra/trunk/clang-doc/Serialize.cpp =================================================================== --- clang-tools-extra/trunk/clang-doc/Serialize.cpp +++ clang-tools-extra/trunk/clang-doc/Serialize.cpp @@ -463,12 +463,11 @@ bool IsInAnonymousNamespace = false; populateFunctionInfo(Func, D, FC, LineNumber, File, IsFileInRootDir, IsInAnonymousNamespace); + Func.Access = clang::AccessSpecifier::AS_none; if (PublicOnly && ((IsInAnonymousNamespace || !isPublic(D->getAccess(), D->getLinkageInternal())))) return {}; - Func.Access = clang::AccessSpecifier::AS_none; - // Wrap in enclosing scope auto ParentI = std::make_unique(); if (!Func.Namespace.empty()) Index: clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp =================================================================== --- clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp +++ clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp @@ -174,6 +174,9 @@ template <> struct MappingTraits { static void mapping(IO &IO, MemberTypeInfo &I) { FieldTypeInfoMapping(IO, I); + // clang::AccessSpecifier::AS_none is used as the default here because it's + // the AS that shouldn't be part of the output. Even though AS_public is the + // default in the struct, it should be displayed in the YAML output. IO.mapOptional("Access", I.Access, clang::AccessSpecifier::AS_none); } }; @@ -218,6 +221,9 @@ IO.mapOptional("Parent", I.Parent, Reference()); IO.mapOptional("Params", I.Params); IO.mapOptional("ReturnType", I.ReturnType); + // clang::AccessSpecifier::AS_none is used as the default here because it's + // the AS that shouldn't be part of the output. Even though AS_public is the + // default in the struct, it should be displayed in the YAML output. IO.mapOptional("Access", I.Access, clang::AccessSpecifier::AS_none); } }; Index: clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp +++ clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp @@ -46,4 +46,5 @@ // CHECK-NEXT: ReturnType: // CHECK-NEXT: Type: // CHECK-NEXT: Name: 'void' +// CHECK-NEXT: Access: Public // CHECK-NEXT: ... Index: clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp @@ -106,6 +106,8 @@ I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); I.Params.emplace_back("int", "P"); + I.Access = AccessSpecifier::AS_none; + std::string WriteResult = writeInfo(&I); EXPECT_TRUE(WriteResult.size() > 0); std::vector> ReadResults = readInfo(WriteResult, 1); @@ -126,8 +128,7 @@ I.IsMethod = true; I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); - // TODO: fix access - // I.Access = AccessSpecifier::AS_private; + I.Access = AccessSpecifier::AS_public; std::string WriteResult = writeInfo(&I); EXPECT_TRUE(WriteResult.size() > 0); Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp @@ -43,6 +43,7 @@ I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record, "Namespace"); I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Access = AccessSpecifier::AS_none; I.ChildFunctions.back().Name = "OneFunction"; I.ChildEnums.emplace_back(); I.ChildEnums.back().Name = "OneEnum"; @@ -228,7 +229,7 @@

Functions

OneFunction

-

OneFunction()

+

public OneFunction()

Enums

@@ -248,6 +249,8 @@ I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); + I.Access = AccessSpecifier::AS_none; + SmallString<16> PathTo; llvm::sys::path::native("path/to", PathTo); I.ReturnType = TypeInfo(EmptySID, "float", InfoType::IT_default, PathTo); @@ -331,6 +334,7 @@ I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); I.Params.emplace_back("int", "I"); I.Params.emplace_back("int", "J"); + I.Access = AccessSpecifier::AS_none; CommentInfo Top; Top.Kind = "FullComment"; Index: clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp @@ -31,6 +31,7 @@ I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); I.ChildFunctions.emplace_back(); I.ChildFunctions.back().Name = "OneFunction"; + I.ChildFunctions.back().Access = AccessSpecifier::AS_none; I.ChildEnums.emplace_back(); I.ChildEnums.back().Name = "OneEnum"; @@ -127,7 +128,7 @@ ### OneFunction -* OneFunction()* +*public OneFunction()* @@ -153,6 +154,8 @@ I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); + I.Access = AccessSpecifier::AS_none; + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); I.Params.emplace_back("int", "P"); I.IsMethod = true; @@ -213,6 +216,7 @@ I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); I.Params.emplace_back("int", "I"); I.Params.emplace_back("int", "J"); + I.Access = AccessSpecifier::AS_none; CommentInfo Top; Top.Kind = "FullComment"; Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp @@ -103,6 +103,7 @@ F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); F.Namespace.emplace_back(EmptySID, "B", InfoType::IT_namespace); F.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction); } @@ -299,6 +300,7 @@ F.Name = "F"; F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); + F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction); } @@ -314,6 +316,7 @@ F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"}); F.Params.emplace_back("int", "I"); + F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction); } @@ -379,6 +382,7 @@ F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default); F.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); F.Params.emplace_back("int", "x"); + F.Access = AccessSpecifier::AS_none; ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F)); CheckNamespaceInfo(&ExpectedBWithFunction, BWithFunction); @@ -389,6 +393,7 @@ ExportedF.ReturnType = TypeInfo(EmptySID, "double", InfoType::IT_default); ExportedF.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"}); ExportedF.Params.emplace_back("double", "y"); + ExportedF.Access = AccessSpecifier::AS_none; ExpectedBWithExportedFunction.ChildFunctions.emplace_back( std::move(ExportedF)); CheckNamespaceInfo(&ExpectedBWithExportedFunction, BWithExportedFunction); Index: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp @@ -34,6 +34,7 @@ "path/to/A/Namespace"); I.ChildFunctions.emplace_back(); I.ChildFunctions.back().Name = "OneFunction"; + I.ChildFunctions.back().Access = AccessSpecifier::AS_none; I.ChildEnums.emplace_back(); I.ChildEnums.back().Name = "OneEnum"; @@ -138,6 +139,7 @@ - USR: '0000000000000000000000000000000000000000' Name: 'OneFunction' ReturnType: {} + Access: Public ChildEnums: - USR: '0000000000000000000000000000000000000000' Name: 'OneEnum' @@ -154,6 +156,8 @@ I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}); I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"}); + I.Access = AccessSpecifier::AS_none; + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void"); I.Params.emplace_back("int", "path/to/int", "P"); @@ -242,6 +246,7 @@ I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); I.Params.emplace_back("int", "I"); I.Params.emplace_back("int", "J"); + I.Access = AccessSpecifier::AS_none; CommentInfo Top; Top.Kind = "FullComment";