Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
ed95d860
Commit
ed95d860
authored
Nov 14, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cdump: ignore __attribute__ (gcc extension).
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
3d6fe839
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
8 deletions
+132
-8
ccan/cdump/cdump.c
ccan/cdump/cdump.c
+64
-8
ccan/cdump/test/run-attributes.c
ccan/cdump/test/run-attributes.c
+68
-0
No files found.
ccan/cdump/cdump.c
View file @
ed95d860
...
...
@@ -390,6 +390,28 @@ static bool tok_maybe_take_cdump_note(const tal_t *ctx,
return
true
;
}
/* __attribute__((...)) */
static
bool
tok_ignore_attribute
(
struct
parse_state
*
ps
)
{
if
(
!
tok_take_if
(
&
ps
->
toks
,
"__attribute__"
))
return
true
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
"("
)
||
!
tok_take_if
(
&
ps
->
toks
,
"("
))
{
complain
(
ps
,
"Expected (( after __attribute__"
);
return
false
;
}
if
(
!
tok_take_expr
(
ps
,
")"
))
{
complain
(
ps
,
"Expected expression after __attribute__(("
);
return
false
;
}
if
(
!
tok_take_if
(
&
ps
->
toks
,
")"
))
{
complain
(
ps
,
"Expected )) __attribute__(("
);
return
false
;
}
return
true
;
}
/* struct|union ... */
static
bool
tok_take_conglom
(
struct
parse_state
*
ps
,
enum
cdump_type_kind
conglom_kind
)
...
...
@@ -415,6 +437,9 @@ static bool tok_take_conglom(struct parse_state *ps,
if
(
!
tok_maybe_take_cdump_note
(
e
,
ps
,
&
e
->
note
))
return
false
;
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
"{"
))
{
complain
(
ps
,
"Expected { for struct/union"
);
return
false
;
...
...
@@ -426,6 +451,9 @@ static bool tok_take_conglom(struct parse_state *ps,
const
struct
token
*
quals
;
unsigned
int
num_quals
=
0
;
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
/* Anything can have these prepended. */
quals
=
ps
->
toks
;
while
(
tok_take_if
(
&
ps
->
toks
,
"const"
)
...
...
@@ -455,6 +483,9 @@ static bool tok_take_conglom(struct parse_state *ps,
while
(
tok_take_if
(
&
ps
->
toks
,
"*"
))
m
->
type
=
ptr_of
(
ps
,
m
->
type
);
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
m
->
name
=
tok_take_ident
(
e
,
&
ps
->
toks
);
if
(
!
m
->
name
)
{
complain
(
ps
,
"Expected name for member"
);
...
...
@@ -471,6 +502,9 @@ static bool tok_take_conglom(struct parse_state *ps,
if
(
!
tok_maybe_take_cdump_note
(
e
->
u
.
members
,
ps
,
&
m
->
note
))
return
false
;
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
}
while
(
tok_take_if
(
&
ps
->
toks
,
","
));
if
(
!
tok_take_if
(
&
ps
->
toks
,
";"
))
{
...
...
@@ -479,10 +513,19 @@ static bool tok_take_conglom(struct parse_state *ps,
}
}
if
(
tok_take_if
(
&
ps
->
toks
,
"}"
)
&&
tok_take_if
(
&
ps
->
toks
,
";"
))
return
true
;
complain
(
ps
,
"Expected }; at end of struct/union"
);
return
false
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
"}"
))
{
complain
(
ps
,
"Expected } at end of struct/union"
);
return
false
;
}
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
";"
))
{
complain
(
ps
,
"Expected ; at end of struct/union"
);
return
false
;
}
return
true
;
}
/* enum ... */
...
...
@@ -510,6 +553,9 @@ static bool tok_take_enum(struct parse_state *ps)
if
(
!
tok_maybe_take_cdump_note
(
e
,
ps
,
&
e
->
note
))
return
false
;
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
"{"
))
{
complain
(
ps
,
"Expected { after enum name"
);
return
false
;
...
...
@@ -546,11 +592,19 @@ static bool tok_take_enum(struct parse_state *ps)
v
->
value
=
NULL
;
}
while
(
tok_take_if
(
&
ps
->
toks
,
","
));
if
(
tok_take_if
(
&
ps
->
toks
,
"}"
)
&&
tok_take_if
(
&
ps
->
toks
,
";"
))
return
true
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
"}"
))
{
complain
(
ps
,
"Expected } at end of enum"
);
return
false
;
}
complain
(
ps
,
"Expected }; at end of enum"
);
return
false
;
if
(
!
tok_ignore_attribute
(
ps
))
return
false
;
if
(
!
tok_take_if
(
&
ps
->
toks
,
";"
))
{
complain
(
ps
,
"Expected ; at end of enum"
);
return
false
;
}
return
true
;
}
static
bool
gather_undefines
(
const
char
*
name
,
...
...
@@ -608,6 +662,8 @@ struct cdump_definitions *cdump_extract(const tal_t *ctx, const char *code,
toks
=
ps
.
toks
=
tokenize
(
ps
.
defs
,
code
);
while
(
tok_peek
(
&
ps
.
toks
))
{
if
(
!
tok_ignore_attribute
(
&
ps
))
goto
fail
;
if
(
tok_take_if
(
&
ps
.
toks
,
"struct"
))
{
if
(
!
tok_take_conglom
(
&
ps
,
CDUMP_STRUCT
))
goto
fail
;
...
...
ccan/cdump/test/run-attributes.c
0 → 100644
View file @
ed95d860
#include <ccan/cdump/cdump.h>
/* Include the C files directly. */
#include <ccan/cdump/cdump.c>
#include <ccan/tap/tap.h>
int
main
(
void
)
{
struct
cdump_definitions
*
defs
;
const
struct
cdump_type
*
t
;
char
*
ctx
=
tal
(
NULL
,
char
),
*
problems
;
/* This is how many tests you plan to run */
plan_tests
(
37
);
defs
=
cdump_extract
(
ctx
,
"__attribute__((xxx)) enum foo __attribute__((xxx)) { BAR } __attribute__((xxx));"
,
NULL
);
ok1
(
defs
);
ok1
(
tal_parent
(
defs
)
==
ctx
);
ok1
(
strmap_empty
(
&
defs
->
structs
));
ok1
(
strmap_empty
(
&
defs
->
unions
));
t
=
strmap_get
(
&
defs
->
enums
,
"foo"
);
ok1
(
t
);
ok1
(
t
->
kind
==
CDUMP_ENUM
);
ok1
(
streq
(
t
->
name
,
"foo"
));
ok1
(
tal_count
(
t
->
u
.
enum_vals
)
==
1
);
ok1
(
streq
(
t
->
u
.
enum_vals
[
0
].
name
,
"BAR"
));
ok1
(
!
t
->
u
.
enum_vals
[
0
].
value
);
defs
=
cdump_extract
(
ctx
,
"__attribute__((xxx)) struct foo __attribute__((xxx)) { int __attribute__((xxx)) x __attribute__((xxx)); } __attribute__((xxx));"
,
&
problems
);
ok1
(
defs
);
ok1
(
tal_parent
(
defs
)
==
ctx
);
ok1
(
!
problems
);
ok1
(
strmap_empty
(
&
defs
->
enums
));
ok1
(
strmap_empty
(
&
defs
->
unions
));
t
=
strmap_get
(
&
defs
->
structs
,
"foo"
);
ok1
(
t
);
ok1
(
t
->
kind
==
CDUMP_STRUCT
);
ok1
(
streq
(
t
->
name
,
"foo"
));
ok1
(
tal_count
(
t
->
u
.
members
)
==
1
);
ok1
(
streq
(
t
->
u
.
members
[
0
].
name
,
"x"
));
ok1
(
t
->
u
.
members
[
0
].
type
->
kind
==
CDUMP_UNKNOWN
);
ok1
(
streq
(
t
->
u
.
members
[
0
].
type
->
name
,
"int"
));
defs
=
cdump_extract
(
ctx
,
"struct foo { int x, __attribute__((xxx)) y; };"
,
&
problems
);
ok1
(
defs
);
ok1
(
tal_parent
(
defs
)
==
ctx
);
ok1
(
!
problems
);
ok1
(
strmap_empty
(
&
defs
->
enums
));
ok1
(
strmap_empty
(
&
defs
->
unions
));
t
=
strmap_get
(
&
defs
->
structs
,
"foo"
);
ok1
(
t
);
ok1
(
t
->
kind
==
CDUMP_STRUCT
);
ok1
(
streq
(
t
->
name
,
"foo"
));
ok1
(
tal_count
(
t
->
u
.
members
)
==
2
);
ok1
(
streq
(
t
->
u
.
members
[
0
].
name
,
"x"
));
ok1
(
t
->
u
.
members
[
0
].
type
->
kind
==
CDUMP_UNKNOWN
);
ok1
(
streq
(
t
->
u
.
members
[
0
].
type
->
name
,
"int"
));
ok1
(
streq
(
t
->
u
.
members
[
1
].
name
,
"y"
));
ok1
(
t
->
u
.
members
[
1
].
type
->
kind
==
CDUMP_UNKNOWN
);
ok1
(
streq
(
t
->
u
.
members
[
1
].
type
->
name
,
"int"
));
/* This exits depending on whether all tests passed */
return
exit_status
();
}
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