Skip to content

Commit 0bd9adf

Browse files
committed
tidy xml, add FunctionKind
1 parent 9fe79c9 commit 0bd9adf

File tree

10 files changed

+279
-13
lines changed

10 files changed

+279
-13
lines changed

include/mrdox/Metadata/Function.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <mrdox/Metadata/FieldType.hpp>
1818
#include <mrdox/Metadata/Function.hpp>
1919
#include <mrdox/Metadata/Symbol.hpp>
20-
#include <mrdox/Metadata/Template.hpp>
2120
#include <mrdox/Metadata/Symbols.hpp>
21+
#include <mrdox/Metadata/Template.hpp>
2222
#include <clang/Basic/Specifiers.h>
2323
#include <llvm/ADT/Optional.h>
2424
#include <llvm/ADT/SmallString.h>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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_METADATA_FUNCTIONKIND_HPP
13+
#define MRDOX_METADATA_FUNCTIONKIND_HPP
14+
15+
#include <mrdox/Platform.hpp>
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
/** An enumeration of the different kinds of functions.
21+
*/
22+
enum class FunctionKind
23+
{
24+
// VFALCO The most frequent function kind should be
25+
// here, since the bitstream writer does not emit zeroes.
26+
Plain = 0,
27+
28+
// The operator kind values have to match the clang enumeration
29+
OpNew /* = clang::OverloadedOperatorKind::OO_New */,
30+
OpDelete,
31+
OpArray_New,
32+
OpArray_Delete,
33+
OpPlus,
34+
OpMinus,
35+
OpStar,
36+
OpSlash,
37+
OpPercent,
38+
OpCaret,
39+
OpAmp,
40+
OpPipe,
41+
OpTilde,
42+
OpExclaim,
43+
OpEqual,
44+
OpLess,
45+
OpGreater,
46+
OpPlusEqual,
47+
OpMinusEqual,
48+
OpStarEqual,
49+
OpSlashEqual,
50+
OpPercentEqual,
51+
OpCaretEqual,
52+
OpAmpEqual,
53+
OpPipeEqual,
54+
OpLessLess,
55+
OpGreaterGreater,
56+
OpLessLessEqual,
57+
OpGreaterGreaterEqual,
58+
OpEqualEqual,
59+
OpExclaimEqual,
60+
OpLessEqual,
61+
OpGreaterEqual,
62+
OpSpaceship,
63+
OpAmpAmp,
64+
OpPipePipe,
65+
OpPlusPlus,
66+
OpMinusMinus,
67+
OpComma,
68+
OpArrowStar,
69+
OpArrow,
70+
OpCall,
71+
OpSubscript,
72+
OpConditional,
73+
OpCoawait,
74+
NUM_OVERLOADED_OPERATORS /* = clang::OverloadedOperatorKind::NUM_OVERLOADED_OPERATORS */,
75+
76+
Destructor = NUM_OVERLOADED_OPERATORS,
77+
Constructor,
78+
Conversion
79+
};
80+
81+
} // mrdox
82+
} // clang
83+
84+
#endif

include/mrdox/Metadata/Record.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace mrdox {
3030

3131
struct BaseRecordInfo;
3232

33-
/** Bit constants used with function specifiers.
33+
/** Bit constants used with Record metadata
3434
*/
3535
enum class RecFlags0 : std::uint32_t
3636
{
@@ -40,6 +40,7 @@ enum class RecFlags0 : std::uint32_t
4040

4141
struct RecordInfo : SymbolInfo
4242
{
43+
// VFALCO Use our own enumeration for this
4344
// Type of this record (struct, class, union, interface).
4445
TagTypeKind TagType = TagTypeKind::TTK_Struct;
4546

include/mrdox/Platform.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef MRDOX_PLATFORM_HPP
1212
#define MRDOX_PLATFORM_HPP
1313

14+
#include <type_traits>
15+
1416
/*
1517
Platform-specific things, and stuff
1618
that is dependent on the toolchain.
@@ -53,14 +55,6 @@ namespace mrdox {
5355
# error unknown platform for dynamic linking
5456
#endif
5557

56-
//------------------------------------------------
57-
58-
template<class T>
59-
T&& _access(T&& t) noexcept
60-
{
61-
return static_cast<T&&>(t);
62-
}
63-
6458
} // mrdox
6559
} // clang
6660

source/api/Metadata/FunctionKind.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
#include "FunctionKind.hpp"
12+
#include "Support/TypeTraits.hpp"
13+
#include <mrdox/Debug.hpp>
14+
#include <clang/Basic/OperatorKinds.h>
15+
#include <utility>
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
static_assert(
21+
to_underlying(FunctionKind::NUM_OVERLOADED_OPERATORS) ==
22+
to_underlying(OverloadedOperatorKind::NUM_OVERLOADED_OPERATORS));
23+
24+
llvm::StringRef
25+
getFunctionKindString(
26+
FunctionKind kind)
27+
{
28+
struct Item
29+
{
30+
char const* token;
31+
char const* name;
32+
FunctionKind kind;
33+
};
34+
using FK = FunctionKind;
35+
static constinit Item const tab[] = {
36+
{ "new", "new", FK::Plain },
37+
{ "delete", "del", FK::OpDelete },
38+
{ "new[]", "arr_new", FK::OpArray_New },
39+
{ "delete[]", "arr_del", FK::OpArray_Delete },
40+
{ "+", "plus", FK::OpPlus },
41+
{ "-", "minus", FK::OpMinus },
42+
{ "*", "star", FK::OpStar },
43+
{ "/", "slash", FK::OpSlash },
44+
{ "%", "mod", FK::OpPercent },
45+
{ "^", "xor", FK::OpCaret },
46+
{ "&", "bitand", FK::OpAmp },
47+
{ "|", "bitor", FK::OpPipe },
48+
{ "~", "bitnot", FK::OpTilde },
49+
{ "!", "not", FK::OpExclaim },
50+
{ "=", "assign", FK::OpEqual },
51+
{ "<", "lt", FK::OpLess },
52+
{ ">", "gt", FK::OpGreater },
53+
{ "+=", "plus_eq", FK::OpPlusEqual },
54+
{ "-=", "minus_eq", FK::OpMinusEqual },
55+
{ "*=", "star_eq", FK::OpStarEqual },
56+
{ "/=", "slash_eq", FK::OpSlashEqual },
57+
{ "%=", "mod_eq", FK::OpPercentEqual },
58+
{ "^=", "xor_eq", FK::OpCaretEqual },
59+
{ "&=", "and_eq", FK::OpAmpEqual },
60+
{ "|=", "or_eq", FK::OpPipeEqual },
61+
{ "<<", "lt_lt", FK::OpLessLess },
62+
{ ">>", "gt_gt", FK::OpGreaterGreater },
63+
{ "<<=", "lt_lt_eq", FK::OpLessLessEqual },
64+
{ ">>=", "gt_gt_eq", FK::OpGreaterGreaterEqual },
65+
{ "==", "eq", FK::OpEqualEqual },
66+
{ "!=", "not_eq", FK::OpExclaimEqual },
67+
{ "<=", "le", FK::OpLessEqual },
68+
{ ">=", "ge", FK::OpGreaterEqual },
69+
{ "<=>", "3way", FK::OpSpaceship },
70+
{ "&&", "and", FK::OpAmpAmp },
71+
{ "||", "or", FK::OpPipePipe },
72+
{ "++", "inc", FK::OpPlusPlus },
73+
{ "--", "dec", FK::OpMinusMinus },
74+
{ ",", "comma", FK::OpComma },
75+
{ "->*", "ptrmem", FK::OpArrowStar },
76+
{ "->", "ptr", FK::OpArrow },
77+
{ "()", "call", FK::OpCall },
78+
{ "[]", "subs", FK::OpSubscript },
79+
{ "?", "ternary", FK::OpConditional },
80+
{ "co_await", "coawait", FK::OpCoawait }
81+
};
82+
Assert(tab[to_underlying(kind)].kind == kind);
83+
return tab[to_underlying(kind)].name;
84+
}
85+
86+
} // mrdox
87+
} // clang
88+

source/api/Metadata/FunctionKind.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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_API_METADATA_FUNCTIONKIND_HPP
12+
#define MRDOX_API_METADATA_FUNCTIONKIND_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Metadata/FunctionKind.hpp>
16+
#include <llvm/ADT/StringRef.h>
17+
18+
namespace clang {
19+
namespace mrdox {
20+
21+
/** Return a unique string constant for the kind.
22+
*/
23+
llvm::StringRef
24+
getFunctionKindString(
25+
FunctionKind kind);
26+
27+
} // mrdox
28+
} // clang
29+
30+
#endif

source/api/Support/TypeTraits.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_API_SUPPORT_TYPE_TRAITS_HPP
12+
#define MRDOX_API_SUPPORT_TYPE_TRAITS_HPP
13+
14+
#include <type_traits>
15+
16+
namespace clang {
17+
namespace mrdox {
18+
19+
/** Return the value as its underlying type.
20+
*/
21+
template<class Enum>
22+
requires std::is_enum_v<Enum>
23+
constexpr auto
24+
to_underlying(
25+
Enum value) noexcept ->
26+
std::underlying_type_t<Enum>
27+
{
28+
return static_cast<
29+
std::underlying_type_t<Enum>>(value);
30+
}
31+
32+
} // mrdox
33+
} // clang
34+
35+
#endif

source/api/_XML/CXXTags.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ inline void write(Bits<FnFlags1> const& bits, XMLTags& tags)
264264

265265
inline void write(Bits<VarFlags0> const& bits, XMLTags& tags)
266266
{
267-
WriteBits(bits).write<VarFlags0::storageClass>(tags);
267+
WriteBits(bits).write<VarFlags0::storageClass, StorageClass>(tags);
268268
}
269269

270270
inline void writeReturnType(TypeInfo const& I, XMLTags& tags)

source/api/_XML/XMLWriter.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,43 @@ writeAllSymbols()
8888
tags_.open("symbols");
8989
for(auto I : corpus_.allSymbols())
9090
{
91+
llvm::StringRef tag;
92+
switch(I->IT)
93+
{
94+
case InfoType::IT_namespace:
95+
tag = "namespace";
96+
break;
97+
case InfoType::IT_record:
98+
switch(static_cast<RecordInfo const*>(I)->TagType)
99+
{
100+
case TagTypeKind::TTK_Class: tag = "class"; break;
101+
case TagTypeKind::TTK_Struct: tag = "struct"; break;
102+
case TagTypeKind::TTK_Union: tag = "struct"; break;
103+
default:
104+
Assert(false);
105+
}
106+
break;
107+
case InfoType::IT_function:
108+
tag = "function";
109+
break;
110+
case InfoType::IT_typedef:
111+
if(static_cast<TypedefInfo const*>(I)->IsUsing)
112+
tag = "using";
113+
else
114+
tag = "typedef";
115+
break;
116+
case InfoType::IT_enum:
117+
tag = "enum";
118+
break;
119+
case InfoType::IT_variable:
120+
tag = "variable";
121+
break;
122+
default:
123+
Assert(false);
124+
}
91125
tags_.write("symbol", {}, {
92126
{ "name", I->getFullyQualifiedName(temp) },
93-
{ "tag", toString(I->IT)},
127+
{ "tag", tag },
94128
{ I->id } });
95129
}
96130
tags_.close("symbols");

test-files/old-tests/ns-variables.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</variable>
1616
<variable name="t" id="eFAdMVIx9F2Zyx0LmK/nCDOhmhA=">
1717
<file path="ns-variables.cpp" line="9"/>
18-
<attr id="storage-class" value="1"/>
18+
<attr id="storage-class" name="extern" value="1"/>
1919
<type name="T" id="CgGNdHpW5mG/i5741WPYQDw28OQ="/>
2020
</variable>
2121
</namespace>

0 commit comments

Comments
 (0)