FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppparser/cppparser/src/cppparser.cpp at master · satya-das/cppparser · GitHub
satya-das
/
cppparser
Public
Notifications
You must be signed in to change notification settings
Fork
47
Star
379
Code
Issues
4
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cppparser
/
cppparser
/
src
/
cppparser.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
130 lines (105 loc) · 3.28 KB
Breadcrumbs
cppparser
/
cppparser
/
src
/
cppparser.cpp
Copy path
File metadata and controls
130 lines (105 loc) · 3.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
Copyright (C) 2022 Satya Das and CppParser contributors
//
SPDX-License-Identifier: MIT
#
include
"
cppparser/cppparser.h
"
#
include
"
cppast/cppast.h
"
#
include
"
parser.h
"
#
include
"
utils.h
"
#
include
<
algorithm
>
#
include
<
map
>
#
include
<
set
>
#
include
<
stdexcept
>
#
include
<
string
>
#
include
<
vector
>
//
Unfortunately parser is not reentrant and has no way as of now to inject parameters.
//
So, we need globals.
//
Globals to help parse when preprocessors are used
std::set<std::string>
gMacroNames
;
std::set<std::string>
gKnownApiDecorNames
;
std::map<std::string,
int
>
gDefinedNames
;
std::set<std::string>
gUndefinedNames
;
std::set<std::string>
gIgnorableMacroNames
;
std::map<std::string,
int
>
gRenamedKeywords
;
bool
gParseEnumBodyAsBlob
=
false
;
bool
gParseFunctionBodyAsBlob
=
false
;
extern
int
GetKeywordId
(
const
std::string& keyword);
namespace
cppparser
{
void
CppParser::addKnownMacro
(std::string knownMacro)
{
gMacroNames
.
insert
(
std::move
(knownMacro));
}
void
CppParser::addKnownMacros
(
const
std::vector<std::string>& knownMacros)
{
for
(
auto
& macro : knownMacros)
gMacroNames
.
insert
(macro);
}
void
CppParser::addDefinedName
(std::string definedName,
int
value)
{
gDefinedNames
[
std::move
(definedName)] = value;
}
void
CppParser::addUndefinedName
(std::string undefinedName)
{
gUndefinedNames
.
insert
(
std::move
(undefinedName));
}
void
CppParser::addUndefinedNames
(
const
std::vector<std::string>& undefinedNames)
{
for
(
auto
& macro : undefinedNames)
gUndefinedNames
.
insert
(macro);
}
void
CppParser::addIgnorableMacro
(std::string ignorableMacro)
{
gIgnorableMacroNames
.
insert
(
std::move
(ignorableMacro));
}
void
CppParser::addIgnorableMacros
(
const
std::vector<std::string>& ignorableMacros)
{
for
(
auto
& macro : ignorableMacros)
gIgnorableMacroNames
.
insert
(macro);
}
void
CppParser::addKnownApiDecor
(std::string knownApiDecor)
{
gKnownApiDecorNames
.
insert
(
std::move
(knownApiDecor));
}
void
CppParser::addKnownApiDecors
(
const
std::vector<std::string>& knownApiDecor)
{
for
(
auto
& apiDecor : knownApiDecor)
gKnownApiDecorNames
.
insert
(apiDecor);
}
bool
CppParser::addRenamedKeyword
(
const
std::string& keyword, std::string renamedKeyword)
{
auto
id =
GetKeywordId
(keyword);
if
(id == -
1
)
return
false
;
gRenamedKeywords
.
emplace
(
std::make_pair
(
std::move
(renamedKeyword), id));
return
true
;
}
void
CppParser::parseEnumBodyAsBlob
()
{
gParseEnumBodyAsBlob
=
true
;
}
void
CppParser::parseFunctionBodyAsBlob
(
bool
asBlob)
{
gParseFunctionBodyAsBlob
= asBlob;
}
std::unique_ptr<cppast::CppCompound>
CppParser::parseFile
(
const
std::string& filename)
{
auto
stm =
ReadFile
(filename);
auto
cppCompound =
ParseStream
(stm.
data
(), stm.
size
());
if
(!cppCompound)
return
cppCompound;
cppCompound->
name
(filename);
return
cppCompound;
}
std::unique_ptr<cppast::CppCompound>
CppParser::parseStream
(
char
* stm,
size_t
stmSize)
{
if
((stm ==
nullptr
) || (stmSize <
2
) || (stm[stmSize -
1
] !=
'
\0
'
) || (stm[stmSize -
2
] !=
'
\0
'
))
throw
std::invalid_argument
(
"
Stream must be valid and it must terminate with double null characters
"
);
return
::
ParseStream
(stm, stmSize);
}
void
CppParser::setErrorHandler
(ErrorHandler errorHandler)
{
::SetErrorHandler
(errorHandler);
}
void
CppParser::resetErrorHandler
()
{
::ResetErrorHandler
();
}
}
//
namespace cppparser
Back
|
FazBrowse Home
|
New Git URL