Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chibicc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
邓家琪
Chibicc
Commits
f0a018a7
Commit
f0a018a7
authored
4 years ago
by
Rui Ueyama
Browse files
Options
Downloads
Patches
Plain Diff
Add -> operator
parent
e1e831ea
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
parse.c
+9
-1
9 additions, 1 deletion
parse.c
test/struct.c
+3
-0
3 additions, 0 deletions
test/struct.c
tokenize.c
+5
-3
5 additions, 3 deletions
tokenize.c
with
17 additions
and
4 deletions
parse.c
+
9
−
1
View file @
f0a018a7
...
...
@@ -672,7 +672,7 @@ static Node *struct_ref(Node *lhs, Token *tok) {
return
node
;
}
// postfix = primary ("[" expr "]" | "." ident)*
// postfix = primary ("[" expr "]" | "."
ident | "->"
ident)*
static
Node
*
postfix
(
Token
**
rest
,
Token
*
tok
)
{
Node
*
node
=
primary
(
&
tok
,
tok
);
...
...
@@ -692,6 +692,14 @@ static Node *postfix(Token **rest, Token *tok) {
continue
;
}
if
(
equal
(
tok
,
"->"
))
{
// x->y is short for (*x).y
node
=
new_unary
(
ND_DEREF
,
node
,
tok
);
node
=
struct_ref
(
node
,
tok
->
next
);
tok
=
tok
->
next
->
next
;
continue
;
}
*
rest
=
tok
;
return
node
;
}
...
...
This diff is collapsed.
Click to expand it.
test/struct.c
+
3
−
0
View file @
f0a018a7
...
...
@@ -33,6 +33,9 @@ int main() {
ASSERT
(
2
,
({
struct
t
{
char
a
[
2
];};
{
struct
t
{
char
a
[
4
];};
}
struct
t
y
;
sizeof
(
y
);
}));
ASSERT
(
3
,
({
struct
t
{
int
x
;};
int
t
=
1
;
struct
t
y
;
y
.
x
=
2
;
t
+
y
.
x
;
}));
ASSERT
(
3
,
({
struct
t
{
char
a
;}
x
;
struct
t
*
y
=
&
x
;
x
.
a
=
3
;
y
->
a
;
}));
ASSERT
(
3
,
({
struct
t
{
char
a
;}
x
;
struct
t
*
y
=
&
x
;
y
->
a
=
3
;
x
.
a
;
}));
printf
(
"OK
\n
"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
tokenize.c
+
5
−
3
View file @
f0a018a7
...
...
@@ -114,9 +114,11 @@ static int from_hex(char c) {
// Read a punctuator token from p and returns its length.
static
int
read_punct
(
char
*
p
)
{
if
(
startswith
(
p
,
"=="
)
||
startswith
(
p
,
"!="
)
||
startswith
(
p
,
"<="
)
||
startswith
(
p
,
">="
))
return
2
;
static
char
*
kw
[]
=
{
"=="
,
"!="
,
"<="
,
">="
,
"->"
};
for
(
int
i
=
0
;
i
<
sizeof
(
kw
)
/
sizeof
(
*
kw
);
i
++
)
if
(
startswith
(
p
,
kw
[
i
]))
return
strlen
(
kw
[
i
]);
return
ispunct
(
*
p
)
?
1
:
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment