Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
017ceae4
Commit
017ceae4
authored
Aug 05, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clang parser: Add support for unions
parent
61690d65
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
+35
-2
src/clang_parser.cpp
src/clang_parser.cpp
+2
-1
src/lexer.l
src/lexer.l
+1
-1
tests/clang_parser.cpp
tests/clang_parser.cpp
+32
-0
No files found.
src/clang_parser.cpp
View file @
017ceae4
...
@@ -116,7 +116,8 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
...
@@ -116,7 +116,8 @@ void ClangParser::parse(ast::Program *program, StructMap &structs)
{
{
auto
&
structs
=
*
static_cast
<
StructMap
*>
(
client_data
);
auto
&
structs
=
*
static_cast
<
StructMap
*>
(
client_data
);
if
(
clang_getCursorKind
(
parent
)
!=
CXCursor_StructDecl
)
// TODO CXCursor_UnionDecl
if
(
clang_getCursorKind
(
parent
)
!=
CXCursor_StructDecl
&&
clang_getCursorKind
(
parent
)
!=
CXCursor_UnionDecl
)
return
CXChildVisit_Recurse
;
return
CXChildVisit_Recurse
;
if
(
clang_getCursorKind
(
c
)
==
CXCursor_FieldDecl
)
if
(
clang_getCursorKind
(
c
)
==
CXCursor_FieldDecl
)
...
...
src/lexer.l
View file @
017ceae4
...
@@ -92,7 +92,7 @@ pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func {
...
@@ -92,7 +92,7 @@ pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func {
<STR>. { driver.error(loc, std::string("invalid character '") +
<STR>. { driver.error(loc, std::string("invalid character '") +
std::string(yytext) + std::string("'")); }
std::string(yytext) + std::string("'")); }
struct
{ BEGIN(STRUCT); buffer = std::string(yytext); open_brackets = 0; }
struct
|union
{ BEGIN(STRUCT); buffer = std::string(yytext); open_brackets = 0; }
<STRUCT>"{" { BEGIN(STRUCT); buffer += std::string(yytext); open_brackets++; }
<STRUCT>"{" { BEGIN(STRUCT); buffer += std::string(yytext); open_brackets++; }
<STRUCT>"}" { buffer += std::string(yytext);
<STRUCT>"}" { buffer += std::string(yytext);
if (open_brackets == 1)
if (open_brackets == 1)
...
...
tests/clang_parser.cpp
View file @
017ceae4
...
@@ -43,6 +43,38 @@ TEST(clang_parser, integers)
...
@@ -43,6 +43,38 @@ TEST(clang_parser, integers)
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
offset
,
8
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"z"
].
offset
,
8
);
}
}
TEST
(
clang_parser
,
c_union
)
{
StructMap
structs
;
parse
(
"union Foo { char c; short s; int i; long l; }"
,
structs
);
ASSERT_EQ
(
structs
.
size
(),
1
);
ASSERT_EQ
(
structs
.
count
(
"Foo"
),
1
);
EXPECT_EQ
(
structs
[
"Foo"
].
size
,
8
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
size
(),
4
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
count
(
"c"
),
1
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
count
(
"s"
),
1
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
count
(
"i"
),
1
);
ASSERT_EQ
(
structs
[
"Foo"
].
fields
.
count
(
"l"
),
1
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"c"
].
type
.
type
,
Type
::
integer
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"c"
].
type
.
size
,
1
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"c"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"s"
].
type
.
type
,
Type
::
integer
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"s"
].
type
.
size
,
2
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"s"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"i"
].
type
.
type
,
Type
::
integer
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"i"
].
type
.
size
,
4
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"i"
].
offset
,
0
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"l"
].
type
.
type
,
Type
::
integer
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"l"
].
type
.
size
,
8
);
EXPECT_EQ
(
structs
[
"Foo"
].
fields
[
"l"
].
offset
,
0
);
}
TEST
(
clang_parser
,
integer_ptr
)
TEST
(
clang_parser
,
integer_ptr
)
{
{
StructMap
structs
;
StructMap
structs
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment