Skip to content

Commit ed8326c

Browse files
committed
refactor source files
1 parent c31f3e7 commit ed8326c

7 files changed

+226
-163
lines changed

source/lib/Corpus.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
//
1111

1212
#include "ast/FrontendAction.hpp"
13-
#include "ast/BitcodeReader.hpp"
14-
//#include "ast/BitcodeWriter.hpp"
13+
#include "ast/Bitcode.hpp"
1514
#include "ast/Serialize.hpp"
1615
#include "meta/Reduce.hpp"
1716
#include <mrdox/Corpus.hpp>
@@ -21,6 +20,7 @@
2120
#include <clang/Tooling/CommonOptionsParser.h>
2221
#include <llvm/Support/Mutex.h>
2322
#include <llvm/Support/ThreadPool.h>
23+
2424
#include <cassert>
2525

2626
namespace clang {

source/lib/ast/Bitcode.hpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// This is a derivative work. originally part of the LLVM Project.
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
//
9+
// Official repository: https://github.com/cppalliance/mrdox
10+
//
11+
12+
#ifndef MRDOX_SOURCE_AST_BITCODE_HPP
13+
#define MRDOX_SOURCE_AST_BITCODE_HPP
14+
15+
#include <mrdox/MetadataFwd.hpp>
16+
#include <mrdox/Reporter.hpp>
17+
#include <llvm/Support/Error.h>
18+
#include <llvm/Bitstream/BitstreamReader.h>
19+
#include <llvm/Bitstream/BitstreamWriter.h>
20+
#include <memory>
21+
#include <vector>
22+
23+
namespace clang {
24+
namespace mrdox {
25+
26+
/** Write an Info variant to the bitstream.
27+
*/
28+
void
29+
writeBitcode(
30+
Info const& I,
31+
llvm::BitstreamWriter& Stream);
32+
33+
/** Return an array of Info read from a bitstream.
34+
*/
35+
llvm::Expected<
36+
std::vector<std::unique_ptr<Info>>>
37+
readBitcode(
38+
llvm::BitstreamCursor& Stream,
39+
Reporter& R);
40+
41+
} // mrdox
42+
} // clang
43+
44+
#endif

source/lib/ast/BitcodeIDs.hpp

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
//
2+
// This is a derivative work. originally part of the LLVM Project.
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// Copyright (c) 2023 Vinnie Falco ([email protected])
8+
//
9+
// Official repository: https://github.com/cppalliance/mrdox
10+
//
11+
12+
#ifndef MRDOX_SOURCE_AST_BITCODEIDS_HPP
13+
#define MRDOX_SOURCE_AST_BITCODEIDS_HPP
14+
15+
#include <llvm/Bitstream/BitCodeEnums.h>
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
// Current version number of clang-doc bitcode.
21+
// Should be bumped when removing or changing BlockIds, RecordIds, or
22+
// BitCodeConstants, though they can be added without breaking it.
23+
static const unsigned VersionNumber = 3;
24+
25+
struct BitCodeConstants
26+
{
27+
static constexpr unsigned RecordSize = 32U;
28+
static constexpr unsigned SignatureBitSize = 8U;
29+
static constexpr unsigned SubblockIDSize = 4U;
30+
static constexpr unsigned BoolSize = 1U;
31+
static constexpr unsigned IntSize = 16U;
32+
static constexpr unsigned StringLengthSize = 16U;
33+
static constexpr unsigned FilenameLengthSize = 16U;
34+
static constexpr unsigned LineNumberSize = 32U;
35+
static constexpr unsigned ReferenceTypeSize = 8U;
36+
static constexpr unsigned USRLengthSize = 6U;
37+
static constexpr unsigned USRBitLengthSize = 8U;
38+
static constexpr unsigned USRHashSize = 20;
39+
static constexpr unsigned JavadocKindSize = 1U;
40+
static constexpr unsigned char Signature[4] = {'D', 'O', 'C', 'S'};
41+
};
42+
43+
/** List of block identifiers.
44+
45+
New IDs need to be added to both the enum
46+
here and the relevant IdNameMap in the
47+
implementation file.
48+
*/
49+
enum BlockId
50+
{
51+
BI_VERSION_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
52+
BI_NAMESPACE_BLOCK_ID,
53+
BI_ENUM_BLOCK_ID,
54+
BI_ENUM_VALUE_BLOCK_ID,
55+
BI_TYPE_BLOCK_ID,
56+
BI_FIELD_TYPE_BLOCK_ID,
57+
BI_MEMBER_TYPE_BLOCK_ID,
58+
BI_RECORD_BLOCK_ID,
59+
BI_BASE_RECORD_BLOCK_ID,
60+
BI_FUNCTION_BLOCK_ID,
61+
BI_JAVADOC_BLOCK_ID,
62+
BI_COMMENT_BLOCK_ID,
63+
BI_REFERENCE_BLOCK_ID,
64+
BI_TEMPLATE_BLOCK_ID,
65+
BI_TEMPLATE_SPECIALIZATION_BLOCK_ID,
66+
BI_TEMPLATE_PARAM_BLOCK_ID,
67+
BI_TYPEDEF_BLOCK_ID,
68+
BI_LAST,
69+
BI_FIRST = BI_VERSION_BLOCK_ID
70+
};
71+
72+
// New Ids need to be added to the enum here, and to the relevant IdNameMap and
73+
// initialization list in the implementation file.
74+
enum RecordId
75+
{
76+
VERSION = 1,
77+
FUNCTION_USR,
78+
FUNCTION_NAME,
79+
FUNCTION_DEFLOCATION,
80+
FUNCTION_LOCATION,
81+
FUNCTION_ACCESS,
82+
FUNCTION_IS_METHOD,
83+
JAVADOC_NODE_KIND,
84+
COMMENT_KIND,
85+
COMMENT_TEXT,
86+
COMMENT_NAME,
87+
COMMENT_DIRECTION,
88+
COMMENT_PARAMNAME,
89+
COMMENT_CLOSENAME,
90+
COMMENT_SELFCLOSING,
91+
COMMENT_EXPLICIT,
92+
COMMENT_ATTRKEY,
93+
COMMENT_ATTRVAL,
94+
COMMENT_ARG,
95+
FIELD_TYPE_NAME,
96+
FIELD_DEFAULT_VALUE,
97+
MEMBER_TYPE_NAME,
98+
MEMBER_TYPE_ACCESS,
99+
NAMESPACE_USR,
100+
NAMESPACE_NAME,
101+
NAMESPACE_PATH,
102+
ENUM_USR,
103+
ENUM_NAME,
104+
ENUM_DEFLOCATION,
105+
ENUM_LOCATION,
106+
ENUM_SCOPED,
107+
ENUM_VALUE_NAME,
108+
ENUM_VALUE_VALUE,
109+
ENUM_VALUE_EXPR,
110+
RECORD_USR,
111+
RECORD_NAME,
112+
RECORD_PATH,
113+
RECORD_DEFLOCATION,
114+
RECORD_LOCATION,
115+
RECORD_TAG_TYPE,
116+
RECORD_IS_TYPE_DEF,
117+
BASE_RECORD_USR,
118+
BASE_RECORD_NAME,
119+
BASE_RECORD_PATH,
120+
BASE_RECORD_TAG_TYPE,
121+
BASE_RECORD_IS_VIRTUAL,
122+
BASE_RECORD_ACCESS,
123+
BASE_RECORD_IS_PARENT,
124+
REFERENCE_USR,
125+
REFERENCE_NAME,
126+
REFERENCE_TYPE,
127+
REFERENCE_PATH,
128+
REFERENCE_FIELD,
129+
TEMPLATE_PARAM_CONTENTS,
130+
TEMPLATE_SPECIALIZATION_OF,
131+
TYPEDEF_USR,
132+
TYPEDEF_NAME,
133+
TYPEDEF_DEFLOCATION,
134+
TYPEDEF_IS_USING,
135+
RI_LAST,
136+
RI_FIRST = VERSION
137+
};
138+
139+
static constexpr unsigned BlockIdCount = BI_LAST - BI_FIRST;
140+
static constexpr unsigned RecordIdCount = RI_LAST - RI_FIRST;
141+
142+
// Identifiers for differentiating between subblocks
143+
enum class FieldId
144+
{
145+
F_default,
146+
F_namespace,
147+
F_parent,
148+
F_vparent,
149+
F_type,
150+
F_child_namespace,
151+
F_child_record,
152+
F_child_function
153+
};
154+
155+
} // mrdox
156+
} // clang
157+
158+
#endif

source/lib/ast/BitcodeReader.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

12-
#include "BitcodeReader.hpp"
13-
#include "BitcodeWriter.hpp"
12+
#include "BitcodeIDs.hpp"
1413
#include <mrdox/Error.hpp>
1514
#include <mrdox/Metadata.hpp>
15+
#include <mrdox/Reporter.hpp>
1616
#include <clang/AST/AST.h>
1717
#include <llvm/ADT/IndexedMap.h>
1818
#include <llvm/ADT/Optional.h>
1919
#include <llvm/ADT/SmallVector.h>
20+
#include <llvm/Bitstream/BitstreamReader.h>
2021

2122
namespace clang {
2223
namespace mrdox {

source/lib/ast/BitcodeReader.hpp

-15
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,9 @@
1818
#ifndef MRDOX_SOURCE_AST_BITCODEREADER_HPP
1919
#define MRDOX_SOURCE_AST_BITCODEREADER_HPP
2020

21-
#include <mrdox/MetadataFwd.hpp>
22-
#include <mrdox/Reporter.hpp>
23-
#include <llvm/Support/Error.h>
24-
#include <llvm/Bitstream/BitstreamReader.h>
25-
#include <memory>
26-
#include <vector>
27-
2821
namespace clang {
2922
namespace mrdox {
3023

31-
/** Return an array of Info read from a Bitstream.
32-
*/
33-
llvm::Expected<
34-
std::vector<std::unique_ptr<Info>>>
35-
readBitcode(
36-
llvm::BitstreamCursor& Stream,
37-
Reporter& R);
38-
3924
} // mrdox
4025
} // clang
4126

source/lib/ast/BitcodeWriter.cpp

+17-6
Original file line numberDiff line numberDiff line change
@@ -953,24 +953,24 @@ emitBlock(
953953

954954
bool
955955
BitcodeWriter::
956-
dispatchInfoForWrite(Info* I)
956+
dispatchInfoForWrite(Info const* I)
957957
{
958958
switch (I->IT)
959959
{
960960
case InfoType::IT_namespace:
961-
emitBlock(*static_cast<clang::mrdox::NamespaceInfo*>(I));
961+
emitBlock(*static_cast<NamespaceInfo const*>(I));
962962
break;
963963
case InfoType::IT_record:
964-
emitBlock(*static_cast<clang::mrdox::RecordInfo*>(I));
964+
emitBlock(*static_cast<RecordInfo const*>(I));
965965
break;
966966
case InfoType::IT_function:
967-
emitBlock(*static_cast<clang::mrdox::FunctionInfo*>(I));
967+
emitBlock(*static_cast<FunctionInfo const*>(I));
968968
break;
969969
case InfoType::IT_enum:
970-
emitBlock(*static_cast<clang::mrdox::EnumInfo*>(I));
970+
emitBlock(*static_cast<EnumInfo const*>(I));
971971
break;
972972
case InfoType::IT_typedef:
973-
emitBlock(*static_cast<clang::mrdox::TypedefInfo*>(I));
973+
emitBlock(*static_cast<TypedefInfo const*>(I));
974974
break;
975975
default:
976976
llvm::errs() << "Unexpected info, unable to write.\n";
@@ -979,5 +979,16 @@ dispatchInfoForWrite(Info* I)
979979
return false;
980980
}
981981

982+
/** Write an Info variant to the bitstream.
983+
*/
984+
void
985+
writeBitcode(
986+
Info const& I,
987+
llvm::BitstreamWriter& Stream)
988+
{
989+
BitcodeWriter writer(Stream);
990+
writer.dispatchInfoForWrite(&I);
991+
}
992+
982993
} // mrdox
983994
} // clang

0 commit comments

Comments
 (0)