Skip to content

Commit 5b869ff

Browse files
committed
FunctionKind work
1 parent 0f1f8fb commit 5b869ff

File tree

4 files changed

+109
-65
lines changed

4 files changed

+109
-65
lines changed

include/mrdox/Metadata/Function.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Metadata/BitField.hpp>
1717
#include <mrdox/Metadata/FieldType.hpp>
1818
#include <mrdox/Metadata/Function.hpp>
19+
#include <mrdox/Metadata/FunctionKind.hpp>
1920
#include <mrdox/Metadata/Symbol.hpp>
2021
#include <mrdox/Metadata/Symbols.hpp>
2122
#include <mrdox/Metadata/Template.hpp>
@@ -64,9 +65,10 @@ union FnFlags1
6465
BitFieldFullValue raw;
6566

6667
BitFlag<0> isNodiscard;
67-
BitField<1, 4, WarnUnusedResultAttr::Spelling> nodiscardSpelling;
68-
BitFlag<5> isExplicit;
69-
BitField<6, 7> functionKind;
68+
BitFlag<1> isExplicit;
69+
70+
BitField<2, 4, WarnUnusedResultAttr::Spelling> nodiscardSpelling;
71+
BitField<6, 7, FunctionKind> functionKind;
7072
};
7173

7274
// TODO: Expand to allow for documenting templating and default args.

source/lib/api/AST/ASTVisitor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "ASTVisitor.hpp"
1313
#include "Bitcode.hpp"
1414
#include "Commands.hpp"
15-
#include "api/ConfigImpl.hpp"
1615
#include "ParseJavadoc.hpp"
16+
#include "api/ConfigImpl.hpp"
17+
#include "api/Metadata/FunctionKind.hpp"
1718
#include "api/Support/Path.hpp"
1819
#include "api/Support/Debug.hpp"
1920
#include <mrdox/Metadata.hpp>
@@ -781,6 +782,14 @@ constructFunction(
781782
I.specs1.nodiscardSpelling = attr->getSemanticSpelling();
782783
}
783784

785+
{
786+
auto OOK = D->getOverloadedOperator();
787+
if(OOK != OverloadedOperatorKind::OO_None)
788+
{
789+
I.specs1.functionKind = getFunctionKind(OOK);
790+
}
791+
792+
}
784793
//
785794
// CXXMethodDecl
786795
//

source/lib/api/Metadata/FunctionKind.cpp

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,99 @@
1717
namespace clang {
1818
namespace mrdox {
1919

20+
namespace {
21+
2022
static_assert(
2123
to_underlying(FunctionKind::NUM_OVERLOADED_OPERATORS) ==
2224
to_underlying(OverloadedOperatorKind::NUM_OVERLOADED_OPERATORS));
2325

26+
struct Item
27+
{
28+
char const* token;
29+
char const* name;
30+
FunctionKind kind;
31+
OverloadedOperatorKind ook;
32+
};
33+
34+
// short operator names from:
35+
// http://www.int0x80.gr/papers/name_mangling.pdf
36+
using FK = FunctionKind;
37+
using OOK = OverloadedOperatorKind;
38+
static constinit Item const Table[] = {
39+
/*
40+
::= ps # + (unary)
41+
::= ng # - (unary)
42+
::= ad # & (unary)
43+
::= de # * (unary)
44+
*/
45+
{ "", "", FK::Plain, OOK::OO_None },
46+
{ "new", "nw", FK::OpNew, OOK::OO_New },
47+
{ "delete", "dl", FK::OpDelete, OOK::OO_Delete },
48+
{ "new[]", "na", FK::OpArray_New, OOK::OO_Array_New },
49+
{ "delete[]", "da", FK::OpArray_Delete, OOK::OO_Array_Delete },
50+
{ "+", "pl", FK::OpPlus, OOK::OO_Plus },
51+
{ "-", "mi", FK::OpMinus, OOK::OO_Minus },
52+
{ "*", "ml", FK::OpStar, OOK::OO_Star },
53+
{ "/", "dv", FK::OpSlash, OOK::OO_Slash },
54+
{ "%", "rm", FK::OpPercent, OOK::OO_Percent },
55+
{ "^", "eo", FK::OpCaret, OOK::OO_Caret },
56+
{ "&", "an", FK::OpAmp, OOK::OO_Amp },
57+
{ "|", "or", FK::OpPipe, OOK::OO_Pipe },
58+
{ "~", "co", FK::OpTilde, OOK::OO_Tilde },
59+
{ "!", "nt", FK::OpExclaim, OOK::OO_Exclaim },
60+
{ "=", "as", FK::OpEqual, OOK::OO_Equal },
61+
{ "<", "lt", FK::OpLess, OOK::OO_Less },
62+
{ ">", "gt", FK::OpGreater, OOK::OO_Greater },
63+
{ "+=", "ple", FK::OpPlusEqual, OOK::OO_PlusEqual },
64+
{ "-=", "mie", FK::OpMinusEqual, OOK::OO_MinusEqual },
65+
{ "*=", "mle", FK::OpStarEqual, OOK::OO_StarEqual },
66+
{ "/=", "dve", FK::OpSlashEqual, OOK::OO_SlashEqual },
67+
{ "%=", "rme", FK::OpPercentEqual, OOK::OO_PercentEqual },
68+
{ "^=", "eoe", FK::OpCaretEqual, OOK::OO_CaretEqual },
69+
{ "&=", "ane", FK::OpAmpEqual, OOK::OO_AmpEqual },
70+
{ "|=", "ore", FK::OpPipeEqual, OOK::OO_PipeEqual },
71+
{ "<<", "ls", FK::OpLessLess, OOK::OO_LessLess },
72+
{ ">>", "rs", FK::OpGreaterGreater, OOK::OO_GreaterGreater },
73+
{ "<<=", "lse", FK::OpLessLessEqual, OOK::OO_LessLessEqual },
74+
{ ">>=", "rse", FK::OpGreaterGreaterEqual, OOK::OO_GreaterGreaterEqual },
75+
{ "==", "eq", FK::OpEqualEqual, OOK::OO_EqualEqual },
76+
{ "!=", "ne", FK::OpExclaimEqual, OOK::OO_ExclaimEqual },
77+
{ "<=", "le", FK::OpLessEqual, OOK::OO_LessEqual },
78+
{ ">=", "ge", FK::OpGreaterEqual, OOK::OO_GreaterEqual },
79+
{ "<=>", "ss", FK::OpSpaceship, OOK::OO_Spaceship },
80+
{ "&&", "aa", FK::OpAmpAmp, OOK::OO_AmpAmp },
81+
{ "||", "oo", FK::OpPipePipe, OOK::OO_PipePipe },
82+
{ "++", "pp", FK::OpPlusPlus, OOK::OO_PlusPlus },
83+
{ "--", "mm", FK::OpMinusMinus, OOK::OO_MinusMinus },
84+
{ ",", "cm", FK::OpComma, OOK::OO_Comma },
85+
{ "->*", "pm", FK::OpArrowStar, OOK::OO_ArrowStar },
86+
{ "->", "pt", FK::OpArrow, OOK::OO_Arrow },
87+
{ "()", "cl", FK::OpCall, OOK::OO_Call },
88+
{ "[]", "ix", FK::OpSubscript, OOK::OO_Subscript },
89+
{ "?", "qu", FK::OpConditional, OOK::OO_Conditional },
90+
{ "co_await", "ca", FK::OpCoawait, OOK::OO_Coawait },
91+
{ "~", "dt", FK::Destructor, OOK::OO_None },
92+
{ "", "ct", FK::Constructor, OOK::OO_None },
93+
{ "", "cv", FK::Conversion, OOK::OO_None }
94+
};
95+
96+
} // (anon)
97+
98+
FunctionKind
99+
getFunctionKind(
100+
OverloadedOperatorKind OOK) noexcept
101+
{
102+
Assert(OOK < OverloadedOperatorKind::NUM_OVERLOADED_OPERATORS);
103+
Assert(Table[to_underlying(OOK)].ook == OOK);
104+
return Table[to_underlying(OOK)].kind;
105+
}
106+
24107
llvm::StringRef
25108
getFunctionKindString(
26-
FunctionKind kind)
109+
FunctionKind kind) noexcept
27110
{
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-
{ "~", "dtor", FK::Destructor },
82-
{ "", "ctor", FK::Constructor },
83-
{ "", "conv", FK::Conversion }
84-
};
85-
Assert(tab[to_underlying(kind)].kind == kind);
86-
return tab[to_underlying(kind)].name;
111+
Assert(Table[to_underlying(kind)].kind == kind);
112+
return Table[to_underlying(kind)].name;
87113
}
88114

89115
} // mrdox

source/lib/api/Metadata/FunctionKind.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414
#include <mrdox/Platform.hpp>
1515
#include <mrdox/Metadata/FunctionKind.hpp>
1616
#include <llvm/ADT/StringRef.h>
17+
#include <clang/Basic/OperatorKinds.h>
1718

1819
namespace clang {
1920
namespace mrdox {
2021

22+
/** Return the function kind corresponding to clang's enum
23+
*/
24+
FunctionKind
25+
getFunctionKind(
26+
OverloadedOperatorKind OOK) noexcept;
27+
2128
/** Return a unique string constant for the kind.
2229
*/
2330
llvm::StringRef
2431
getFunctionKindString(
25-
FunctionKind kind);
32+
FunctionKind kind) noexcept;
2633

2734
} // mrdox
2835
} // clang

0 commit comments

Comments
 (0)