Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
go
Commits
c597845e
Commit
c597845e
authored
Dec 04, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
const/var/iota declarations as discussed
R=r OCL=20506 CL=20506
parent
afa64240
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
38 deletions
+100
-38
src/cmd/gc/dcl.c
src/cmd/gc/dcl.c
+83
-0
src/cmd/gc/go.h
src/cmd/gc/go.h
+2
-0
src/cmd/gc/go.y
src/cmd/gc/go.y
+15
-38
No files found.
src/cmd/gc/dcl.c
View file @
c597845e
...
...
@@ -1212,3 +1212,86 @@ embedded(Sym *s)
yyerror
(
"embedded type cannot be a pointer"
);
return
n
;
}
/*
* declare variables from grammar
* new_name_list [type] = expr_list
*/
Node
*
variter
(
Node
*
vv
,
Type
*
t
,
Node
*
ee
)
{
Iter
viter
,
eiter
;
Node
*
v
,
*
e
,
*
r
,
*
a
;
vv
=
rev
(
vv
);
ee
=
rev
(
ee
);
v
=
listfirst
(
&
viter
,
&
vv
);
e
=
listfirst
(
&
eiter
,
&
ee
);
r
=
N
;
loop:
if
(
v
==
N
&&
e
==
N
)
return
rev
(
r
);
if
(
v
==
N
||
e
==
N
)
{
yyerror
(
"shape error in var dcl"
);
return
rev
(
r
);
}
a
=
nod
(
OAS
,
v
,
N
);
if
(
t
==
T
)
{
gettype
(
e
,
a
);
defaultlit
(
e
);
dodclvar
(
v
,
e
->
type
);
}
else
dodclvar
(
v
,
t
);
a
->
right
=
e
;
r
=
list
(
r
,
a
);
v
=
listnext
(
&
viter
);
e
=
listnext
(
&
eiter
);
goto
loop
;
}
/*
* declare constants from grammar
* new_name_list [type] [= expr_list]
*/
void
constiter
(
Node
*
vv
,
Type
*
t
,
Node
*
cc
)
{
Iter
viter
,
citer
;
Node
*
v
,
*
c
,
*
a
;
if
(
cc
==
N
)
cc
=
lastconst
;
lastconst
=
cc
;
vv
=
rev
(
vv
);
cc
=
rev
(
treecopy
(
cc
));
v
=
listfirst
(
&
viter
,
&
vv
);
c
=
listfirst
(
&
citer
,
&
cc
);
loop:
if
(
v
==
N
&&
c
==
N
)
{
iota
+=
1
;
return
;
}
if
(
v
==
N
||
c
==
N
)
{
yyerror
(
"shape error in var dcl"
);
iota
+=
1
;
return
;
}
gettype
(
c
,
N
);
if
(
t
!=
T
)
convlit
(
c
,
t
);
dodclconst
(
v
,
c
);
v
=
listnext
(
&
viter
);
c
=
listnext
(
&
citer
);
goto
loop
;
}
src/cmd/gc/go.h
View file @
c597845e
...
...
@@ -713,6 +713,8 @@ void checkwidth(Type*);
void
defercheckwidth
(
void
);
void
resumecheckwidth
(
void
);
Node
*
embedded
(
Sym
*
);
Node
*
variter
(
Node
*
,
Type
*
,
Node
*
);
void
constiter
(
Node
*
,
Type
*
,
Node
*
);
/*
* export.c
...
...
src/cmd/gc/go.y
View file @
c597845e
...
...
@@ -318,60 +318,37 @@ Bvardcl:
if
(
addtop
!= N)
fatal
(
"new_name_list_r type '=' expr_list"
);
$$
=
rev
($
1
);
dodclvar
($$,
$
2
);
$$
=
nod
(
OAS
,
$$,
$
4
);
$$
=
variter
($
1
,
$
2
,
$
4
);
addtotop
($$);
}
|
new_name
'='
expr
|
new_name
_list_r
'='
expr_list
{
$$
=
nod
(
OAS
,
$
1
,
N
);
gettype
($
3
,
$$
);
defaultlit
($
3
);
dodclvar
($
1
,
$
3
->
type
);
$$->
right
=
$
3
;
if
(
addtop
!= N)
fatal
(
"new_name_list_r '=' expr_list"
);
$$
=
variter
($
1
,
T
,
$
3
);
addtotop
($$)
;
}
constdcl
:
new_name
type
'='
expr
new_name
_list_r
type
'='
expr_list
{
Node
*
c
=
treecopy
($
4
);
gettype
(
c
,
N
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
lastconst
=
$
4
;
iota
+=
1
;
constiter
($
1
,
$
2
,
$
4
);
}
|
new_name
'='
expr
|
new_name
_list_r
'='
expr_list
{
Node
*
c
=
treecopy
($
3
);
gettype
(
c
,
N
);
dodclconst
($
1
,
c
);
lastconst
=
$
3
;
iota
+=
1
;
constiter
($
1
,
T
,
$
3
);
}
constdcl1
:
constdcl
|
new_name
type
|
new_name
_list_r
type
{
Node
*
c
=
treecopy
(
lastconst
);
gettype
(
c
,
N
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
iota
+=
1
;
constiter
($
1
,
$
2
,
N
);
}
|
new_name
|
new_name
_list_r
{
Node
*
c
=
treecopy
(
lastconst
);
gettype
(
c
,
N
);
dodclconst
($
1
,
c
);
iota
+=
1
;
constiter
($
1
,
T
,
N
);
}
typedclname
:
...
...
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