Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
38 deletions
+100
-38
dcl.c
src/cmd/gc/dcl.c
+83
-0
go.h
src/cmd/gc/go.h
+2
-0
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)
...
@@ -1212,3 +1212,86 @@ embedded(Sym *s)
yyerror
(
"embedded type cannot be a pointer"
);
yyerror
(
"embedded type cannot be a pointer"
);
return
n
;
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*);
...
@@ -713,6 +713,8 @@ void checkwidth(Type*);
void
defercheckwidth
(
void
);
void
defercheckwidth
(
void
);
void
resumecheckwidth
(
void
);
void
resumecheckwidth
(
void
);
Node
*
embedded
(
Sym
*
);
Node
*
embedded
(
Sym
*
);
Node
*
variter
(
Node
*
,
Type
*
,
Node
*
);
void
constiter
(
Node
*
,
Type
*
,
Node
*
);
/*
/*
* export.c
* export.c
...
...
src/cmd/gc/go.y
View file @
c597845e
...
@@ -318,60 +318,37 @@ Bvardcl:
...
@@ -318,60 +318,37 @@ Bvardcl:
if
(
addtop
!= N)
if
(
addtop
!= N)
fatal
(
"new_name_list_r type '=' expr_list"
);
fatal
(
"new_name_list_r type '=' expr_list"
);
$$
=
rev
($
1
);
$$
=
variter
($
1
,
$
2
,
$
4
);
dodclvar
($$,
$
2
);
$$
=
nod
(
OAS
,
$$,
$
4
);
addtotop
($$);
addtotop
($$);
}
}
|
new_name
'='
expr
|
new_name
_list_r
'='
expr_list
{
{
$$
=
nod
(
OAS
,
$
1
,
N
);
if
(
addtop
!= N)
gettype
($
3
,
$$
);
fatal
(
"new_name_list_r '=' expr_list"
);
defaultlit
($
3
);
dodclvar
($
1
,
$
3
->
type
);
$$
=
variter
($
1
,
T
,
$
3
);
$$->
right
=
$
3
;
addtotop
($$)
;
}
}
constdcl
:
constdcl
:
new_name
type
'='
expr
new_name
_list_r
type
'='
expr_list
{
{
Node
*
c
=
treecopy
($
4
);
constiter
($
1
,
$
2
,
$
4
);
gettype
(
c
,
N
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
lastconst
=
$
4
;
iota
+=
1
;
}
}
|
new_name
'='
expr
|
new_name
_list_r
'='
expr_list
{
{
Node
*
c
=
treecopy
($
3
);
constiter
($
1
,
T
,
$
3
);
gettype
(
c
,
N
);
dodclconst
($
1
,
c
);
lastconst
=
$
3
;
iota
+=
1
;
}
}
constdcl1
:
constdcl1
:
constdcl
constdcl
|
new_name
type
|
new_name
_list_r
type
{
{
Node
*
c
=
treecopy
(
lastconst
);
constiter
($
1
,
$
2
,
N
);
gettype
(
c
,
N
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
iota
+=
1
;
}
}
|
new_name
|
new_name
_list_r
{
{
Node
*
c
=
treecopy
(
lastconst
);
constiter
($
1
,
T
,
N
);
gettype
(
c
,
N
);
dodclconst
($
1
,
c
);
iota
+=
1
;
}
}
typedclname
:
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