Skip to content

Commit 69efdb9

Browse files
committed
extract variables
1 parent 9d61625 commit 69efdb9

15 files changed

+558
-433
lines changed

Diff for: CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ file(GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS
9292
source/api/*.h
9393
source/api/*.hpp
9494
source/api/*.cpp
95-
source/api/*.natvis)
95+
#source/api/*.natvis
96+
)
9697

9798
add_library(mrdox-api ${MRDOX_LINK_MODE} ${LIB_INCLUDES} ${LIB_SOURCES})
9899
target_compile_features(mrdox-api PUBLIC cxx_std_20)

Diff for: include/mrdox/Metadata.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@
3636
#include <mrdox/Metadata/TemplateParam.hpp>
3737
#include <mrdox/Metadata/Type.hpp>
3838
#include <mrdox/Metadata/Typedef.hpp>
39+
#include <mrdox/Metadata/Variable.hpp>
3940

4041
#endif

Diff for: include/mrdox/Metadata/Scope.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct Scope
3939
std::vector<Reference> Functions;
4040
std::vector<TypedefInfo> Typedefs;
4141
std::vector<EnumInfo> Enums;
42+
std::vector<Reference> Variables;
4243

4344
explicit
4445
Scope(

Diff for: include/mrdox/Metadata/Symbols.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum class InfoType
4747
IT_record,
4848
IT_function,
4949
IT_enum,
50-
IT_typedef
50+
IT_typedef,
51+
IT_variable
5152
};
5253

5354
/** Return the result of comparing s0 to s1.

Diff for: include/mrdox/Metadata/Variable.hpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_VARIABLE_HPP
12+
#define MRDOX_METADATA_VARIABLE_HPP
13+
14+
#include <mrdox/Platform.hpp>
15+
#include <mrdox/Metadata/Symbol.hpp>
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
/** A variable.
21+
22+
This includes variables at namespace
23+
scope, and static variables at class scope.
24+
*/
25+
struct VariableInfo : SymbolInfo
26+
{
27+
TypeInfo Type;
28+
29+
explicit
30+
VariableInfo(
31+
SymbolID ID = SymbolID(),
32+
llvm::StringRef Name = llvm::StringRef())
33+
: SymbolInfo(InfoType::IT_variable, ID, Name)
34+
{
35+
}
36+
};
37+
38+
} // mrdox
39+
} // clang
40+
41+
#endif

Diff for: include/mrdox/MetadataFwd.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct TemplateParamInfo;
4444
struct TemplateSpecializationInfo;
4545
struct TypeInfo;
4646
struct TypedefInfo;
47+
struct VariableInfo;
4748
struct VerbatimBlock;
4849

4950
} // mrdox

Diff for: source/api/AST/ASTVisitor.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ WalkUpFromEnumDecl(
268268
return true;
269269
}
270270

271+
bool
272+
ASTVisitor::
273+
WalkUpFromVarDecl(
274+
VarDecl* D)
275+
{
276+
mapDecl(D);
277+
return true;
278+
}
279+
271280
int
272281
ASTVisitor::
273282
getLine(

Diff for: source/api/AST/ASTVisitor.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class ASTVisitor
7979
bool WalkUpFromTypeAliasDecl(TypeAliasDecl* D);
8080
bool WalkUpFromTypedefDecl(TypedefDecl* D);
8181
bool WalkUpFromEnumDecl(EnumDecl* D);
82+
bool WalkUpFromVarDecl(VarDecl* D);
8283

8384
private:
8485
template <typename T>

Diff for: source/api/AST/BitcodeIDs.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum BlockId
6767
BI_TEMPLATE_SPECIALIZATION_BLOCK_ID,
6868
BI_TYPE_BLOCK_ID,
6969
BI_TYPEDEF_BLOCK_ID,
70+
BI_VARIABLE_BLOCK_ID,
7071
BI_LAST,
7172
BI_FIRST = BI_VERSION_BLOCK_ID
7273
};
@@ -126,6 +127,10 @@ enum RecordId
126127
TYPEDEF_NAME,
127128
TYPEDEF_DEFLOCATION,
128129
TYPEDEF_IS_USING,
130+
VARIABLE_USR,
131+
VARIABLE_NAME,
132+
VARIABLE_DEFLOCATION,
133+
VARIABLE_LOCATION,
129134
RI_LAST,
130135
RI_FIRST = VERSION
131136
};

Diff for: source/api/AST/BitcodeReader.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ decodeRecord(
201201
case InfoType::IT_function:
202202
case InfoType::IT_enum:
203203
case InfoType::IT_typedef:
204-
case InfoType::IT_default:
204+
case InfoType::IT_variable:
205205
Field = IT;
206206
return llvm::Error::success();
207+
default:
208+
Field = InfoType::IT_default;
209+
return makeError("invalid value for InfoType");
207210
}
208-
Field = InfoType::IT_default;
209-
return makeError("invalid value for InfoType");
210211
}
211212

212213
static

0 commit comments

Comments
 (0)