Skip to content

Commit d42444c

Browse files
committed
big refactor of scopes and records
1 parent 9128741 commit d42444c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+665
-356
lines changed

CMakeLists.txt

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ unset(CMAKE_FOLDER)
8989
#
9090
#-------------------------------------------------
9191

92-
configure_file(source/api/Version.hpp.in ${PROJECT_BINARY_DIR}/include/mrdox/Version.hpp)
92+
configure_file(source/lib/api/Version.hpp.in ${PROJECT_BINARY_DIR}/include/mrdox/Version.hpp)
9393

9494
file(GLOB_RECURSE LIB_INCLUDES CONFIGURE_DEPENDS include/*.hpp)
9595
file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS
96-
source/api/*.h
97-
source/api/*.hpp
98-
source/api/*.cpp
99-
source/api/*.natvis
96+
source/lib/*.h
97+
source/lib/*.hpp
98+
source/lib/*.cpp
99+
source/lib/*.natvis
100100
)
101101

102102
add_library(mrdox-api ${MRDOX_LINK_MODE} ${LIB_INCLUDES} ${LIB_SOURCES})
@@ -106,7 +106,7 @@ target_include_directories(mrdox-api
106106
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
107107
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
108108
PRIVATE
109-
"${PROJECT_SOURCE_DIR}/source/"
109+
"${PROJECT_SOURCE_DIR}/source/lib"
110110
${PROJECT_BINARY_DIR}/include
111111
)
112112
target_compile_definitions(
@@ -175,8 +175,8 @@ if (MRDOX_CLANG)
175175
endif ()
176176

177177
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
178-
source_group(TREE ${PROJECT_SOURCE_DIR}/include/mrdox PREFIX "include" FILES ${LIB_INCLUDES})
179-
source_group(TREE ${PROJECT_SOURCE_DIR}/source/api PREFIX "source" FILES ${LIB_SOURCES})
178+
source_group(TREE ${PROJECT_SOURCE_DIR}/include/mrdox PREFIX " include" FILES ${LIB_INCLUDES})
179+
source_group(TREE ${PROJECT_SOURCE_DIR}/source/lib/api PREFIX "api" FILES ${LIB_SOURCES})
180180

181181
#-------------------------------------------------
182182
#
@@ -189,13 +189,66 @@ add_executable(mrdox ${TOOL_SOURCES})
189189
target_link_libraries(mrdox PRIVATE mrdox-api)
190190
target_include_directories(mrdox
191191
PRIVATE
192-
${PROJECT_SOURCE_DIR}/source/
192+
${PROJECT_SOURCE_DIR}/source/lib
193193
${PROJECT_BINARY_DIR}/include/
194194
)
195195

196196
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
197197
source_group(TREE ${PROJECT_SOURCE_DIR}/source/tool PREFIX "source" FILES ${TOOL_SOURCES})
198198

199+
#-------------------------------------------------
200+
#
201+
# Tests
202+
#
203+
#-------------------------------------------------
204+
205+
if (BUILD_TESTING)
206+
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS source/test/*.cpp source/test/*.hpp)
207+
enable_testing()
208+
add_executable(mrdox-test ${TEST_SOURCES})
209+
target_link_libraries(mrdox-test PRIVATE mrdox-api ${llvm_libs})
210+
target_include_directories(mrdox-test
211+
PRIVATE
212+
${PROJECT_SOURCE_DIR}/source/lib)
213+
add_test(NAME mrdox-test COMMAND mrdox-test
214+
"${PROJECT_SOURCE_DIR}/test-files/old-tests"
215+
)
216+
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
217+
source_group(TREE ${PROJECT_SOURCE_DIR}/source/test PREFIX "source" FILES ${TEST_SOURCES})
218+
219+
if (CMAKE_EXPORT_COMPILE_COMMANDS)
220+
# test run
221+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
222+
include(mrdox.cmake)
223+
224+
mrdox(FORMAT adoc CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
225+
mrdox(FORMAT xml CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
226+
227+
add_custom_target(reference_adoc ALL DEPENDS reference.adoc)
228+
add_custom_target(reference_xml ALL DEPENDS reference.xml)
229+
endif()
230+
231+
find_package(LibXml2)
232+
if (LibXml2_FOUND)
233+
find_package(Java REQUIRED Runtime)
234+
# FindJava
235+
if (NOT Java_FOUND)
236+
message(FATAL_ERROR "Java is needed to run xml-lint")
237+
endif()
238+
239+
add_custom_target(mrdox.rng ALL DEPENDS mrdox.rnc
240+
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_CURRENT_SOURCE_DIR}/tools/trang.jar
241+
${CMAKE_CURRENT_SOURCE_DIR}/mrdox.rnc ${CMAKE_CURRENT_BINARY_DIR}/mrdox.rng)
242+
243+
244+
file(GLOB_RECURSE XML_SOURCES CONFIGURE_DEPENDS test-files/*.xml)
245+
add_test(NAME xml-lint
246+
COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --dropdtd --noout
247+
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdox.rng ${XML_SOURCES}
248+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
249+
endif()
250+
endif()
251+
199252
#-------------------------------------------------
200253
#
201254
# Install
@@ -250,7 +303,6 @@ if (MRDOX_INSTALL)
250303
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mrdox)
251304
endif ()
252305

253-
254306
#-------------------------------------------------
255307
#
256308
# Packages
@@ -279,58 +331,3 @@ if (MRDOX_INSTALL AND MRDOX_PACKAGE)
279331
# Always include CPack at last
280332
include(CPack)
281333
endif ()
282-
283-
#-------------------------------------------------
284-
#
285-
# Tests
286-
#
287-
#-------------------------------------------------
288-
289-
if (BUILD_TESTING)
290-
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS source/test/*.cpp source/test/*.hpp)
291-
enable_testing()
292-
add_executable(mrdox-test ${TEST_SOURCES})
293-
target_link_libraries(mrdox-test PRIVATE mrdox-api ${llvm_libs})
294-
target_include_directories(mrdox-test
295-
PRIVATE
296-
${PROJECT_SOURCE_DIR}/source)
297-
add_test(NAME mrdox-test COMMAND mrdox-test
298-
"${PROJECT_SOURCE_DIR}/test-files/old-tests"
299-
)
300-
source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
301-
source_group(TREE ${PROJECT_SOURCE_DIR}/source/test PREFIX "source" FILES ${TEST_SOURCES})
302-
303-
if (CMAKE_EXPORT_COMPILE_COMMANDS)
304-
# test run
305-
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
306-
include(mrdox.cmake)
307-
308-
mrdox(FORMAT adoc CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
309-
mrdox(FORMAT xml CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
310-
311-
add_custom_target(reference_adoc ALL DEPENDS reference.adoc)
312-
add_custom_target(reference_xml ALL DEPENDS reference.xml)
313-
endif()
314-
315-
find_package(LibXml2)
316-
if (LibXml2_FOUND)
317-
find_package(Java REQUIRED Runtime)
318-
# FindJava
319-
if (NOT Java_FOUND)
320-
message(FATAL_ERROR "Java is needed to run xml-lint")
321-
endif()
322-
323-
add_custom_target(mrdox.rng ALL DEPENDS mrdox.rnc
324-
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_CURRENT_SOURCE_DIR}/tools/trang.jar
325-
${CMAKE_CURRENT_SOURCE_DIR}/mrdox.rnc ${CMAKE_CURRENT_BINARY_DIR}/mrdox.rng)
326-
327-
328-
file(GLOB_RECURSE XML_SOURCES CONFIGURE_DEPENDS test-files/*.xml)
329-
add_test(NAME xml-lint
330-
COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --dropdtd --noout
331-
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdox.rng ${XML_SOURCES}
332-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
333-
endif()
334-
endif()
335-
336-
#-------------------------------------------------

include/mrdox/Corpus.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Config.hpp>
1717
#include <mrdox/MetadataFwd.hpp>
1818
#include <mrdox/Reporter.hpp>
19+
#include <mrdox/Metadata/Access.hpp>
1920
#include <mrdox/Metadata/Symbols.hpp>
2021
#include <clang/Tooling/Execution.h>
2122
#include <llvm/Support/Mutex.h>
@@ -99,9 +100,9 @@ class MRDOX_VISIBLE
99100
struct Visitor
100101
{
101102
MRDOX_DECL virtual ~Visitor() noexcept;
103+
102104
MRDOX_DECL virtual bool visit(NamespaceInfo const&);
103105
MRDOX_DECL virtual bool visit(RecordInfo const&);
104-
MRDOX_DECL virtual bool visit(Overloads const&);
105106
MRDOX_DECL virtual bool visit(FunctionInfo const&);
106107
MRDOX_DECL virtual bool visit(TypedefInfo const&);
107108
MRDOX_DECL virtual bool visit(EnumInfo const&);
@@ -111,12 +112,11 @@ class MRDOX_VISIBLE
111112
/** Visit the specified symbol ID or node.
112113
*/
113114
/** @{ */
114-
MRDOX_DECL bool visit(SymbolID id, Visitor& f) const;
115-
MRDOX_DECL bool visit(std::vector<Reference> const& R, Visitor& f) const;
116-
MRDOX_DECL bool visit(std::vector<SymbolID> const& R, Visitor& f) const;
117-
MRDOX_DECL bool visit(Scope const& I, Visitor& f) const;
118-
MRDOX_DECL bool visitWithOverloads(Scope const& I, Visitor& f) const;
119-
MRDOX_DECL bool visit(Info const& I, Visitor& f) const;
115+
MRDOX_DECL bool visit(Visitor& f, SymbolID id) const;
116+
MRDOX_DECL bool visit(Visitor& f, std::vector<Reference> const& R) const;
117+
MRDOX_DECL bool visit(Visitor& f, std::vector<SymbolID> const& R) const;
118+
MRDOX_DECL bool visit(Visitor& f, Scope const& I) const;
119+
MRDOX_DECL bool visit(Visitor& f, Info const& I) const;
120120
/** @} */
121121

122122
//--------------------------------------------

include/mrdox/Metadata/Access.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_METADATA_ACCESS_HPP
12+
#define MRDOX_METADATA_ACCESS_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Metadata/Symbols.hpp>
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
/** Access specifier.
21+
22+
Public is set to zero since it is the most
23+
frequently occurring access, and it is
24+
elided by the bitstream encoder because it
25+
has an all-zero bit pattern. This improves
26+
compression in the bitstream.
27+
28+
@note It is by design that there is no
29+
constant to represent "none."
30+
*/
31+
enum class Access
32+
{
33+
Public = 0,
34+
Protected,
35+
Private
36+
};
37+
38+
/** A reference to a symbol, and an access speciier.
39+
40+
This is used in records to refer to nested
41+
elements with access control.
42+
*/
43+
struct RefWithAccess
44+
{
45+
SymbolID id;
46+
Access access;
47+
};
48+
49+
} // mrdox
50+
} // clang
51+
52+
#endif

include/mrdox/Metadata/Interface.hpp

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,71 @@
1414

1515
#include <mrdox/Platform.hpp>
1616
#include <mrdox/MetadataFwd.hpp>
17+
#include <mrdox/Metadata/Access.hpp>
1718
#include <span>
1819
#include <utility>
1920
#include <vector>
2021

2122
namespace clang {
2223
namespace mrdox {
2324

24-
enum class Access
25+
struct RecordWithAccess
2526
{
26-
None = 0, // bitstream elides zeroes
27-
Public,
28-
Protected,
29-
Private
27+
RecordInfo const* I;
28+
RecordInfo const* From;
29+
Access access;
30+
};
31+
32+
struct FunctionWithAccess
33+
{
34+
FunctionInfo const* I;
35+
RecordInfo const* From;
36+
Access access;
37+
};
38+
39+
struct EnumWithAccess
40+
{
41+
EnumInfo const* I;
42+
RecordInfo const* From;
43+
Access access;
44+
};
45+
46+
struct TypeWithAccess
47+
{
48+
TypedefInfo const* I;
49+
RecordInfo const* From;
50+
Access access;
51+
};
52+
53+
struct VarWithAccess
54+
{
55+
VarInfo const* I;
56+
RecordInfo const* From;
57+
Access access;
58+
};
59+
60+
struct DataWithAccess
61+
{
62+
MemberTypeInfo const* I;
63+
RecordInfo const* From;
64+
Access access;
3065
};
3166

3267
/** The aggregated interface for a given struct, class, or union.
3368
*/
3469
class Interface
3570
{
3671
public:
37-
template<class Ty>
38-
struct Item
39-
{
40-
Ty const* I;
41-
RecordInfo const* From;
42-
Access access;
43-
};
44-
4572
/** A group of children that have the same access specifier.
4673
*/
4774
struct Tranche
4875
{
49-
std::span<Item<EnumInfo> const> Enums;
50-
std::span<Item<TypedefInfo> const> Types;
51-
std::span<Item<FunctionInfo> const> Functions;
52-
std::span<Item<MemberTypeInfo> const> Members;
53-
std::span<Item<VarInfo> const> Vars;
76+
std::span<RecordWithAccess const> Records;
77+
std::span<FunctionWithAccess const> Functions;
78+
std::span<EnumWithAccess const> Enums;
79+
std::span<TypeWithAccess const> Types;
80+
std::span<DataWithAccess const> Data;
81+
std::span<VarWithAccess const> Vars;
5482
};
5583

5684
/** The aggregated public interfaces.
@@ -76,11 +104,12 @@ class Interface
76104
private:
77105
class Build;
78106

79-
std::vector<Item<EnumInfo>> enums_;
80-
std::vector<Item<TypedefInfo>> types_;
81-
std::vector<Item<FunctionInfo>> functions_;
82-
std::vector<Item<MemberTypeInfo>> members_;
83-
std::vector<Item<VarInfo>> vars_;
107+
std::vector<RecordWithAccess> records_;
108+
std::vector<FunctionWithAccess> functions_;
109+
std::vector<EnumWithAccess> enums_;
110+
std::vector<TypeWithAccess> types_;
111+
std::vector<DataWithAccess> data_;
112+
std::vector<VarWithAccess> vars_;
84113
};
85114

86115
//------------------------------------------------

0 commit comments

Comments
 (0)