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
9dbaab54
Commit
9dbaab54
authored
Sep 04, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewriting bugs
R=r OCL=14810 CL=14810
parent
4c9d84f0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
81 deletions
+137
-81
const.c
src/cmd/gc/const.c
+11
-0
go.h
src/cmd/gc/go.h
+3
-1
go.y
src/cmd/gc/go.y
+40
-36
subr.c
src/cmd/gc/subr.c
+0
-1
walk.c
src/cmd/gc/walk.c
+83
-43
No files found.
src/cmd/gc/const.c
View file @
9dbaab54
...
...
@@ -24,7 +24,18 @@ convlit(Node *n, Type *t)
n
->
type
=
n
->
left
->
type
;
return
;
}
et
=
t
->
etype
;
switch
(
et
)
{
case
TARRAY
:
case
TFUNC
:
case
TCHAN
:
case
TMAP
:
// case TPTR32:
// case TPTR64:
return
;
}
switch
(
whatis
(
n
))
{
default:
goto
bad1
;
...
...
src/cmd/gc/go.h
View file @
9dbaab54
...
...
@@ -258,7 +258,7 @@ enum
OLIST
,
OCMP
,
OPTR
,
OARRAY
,
ORETURN
,
OFOR
,
OIF
,
OSWITCH
,
OI2S
,
OS2I
,
OI2I
,
OAS
,
OASOP
,
OCASE
,
OXCASE
,
O
SCASE
,
O
FALL
,
OXFALL
,
OAS
,
OASOP
,
OCASE
,
OXCASE
,
OFALL
,
OXFALL
,
OGOTO
,
OPROC
,
ONEW
,
OEMPTY
,
OSELECT
,
OLEN
,
OCAP
,
OPANIC
,
OPRINT
,
OTYPEOF
,
...
...
@@ -661,7 +661,9 @@ void doimport8(Node*, Val*, Node*);
* walk.c
*/
void
walk
(
Node
*
);
void
walkstate
(
Node
*
);
void
walktype
(
Node
*
,
int
);
void
walkas
(
Node
*
);
void
walkbool
(
Node
*
);
Type
*
walkswitch
(
Node
*
,
Type
*
(
*
)(
Node
*
,
Type
*
));
int
casebody
(
Node
*
);
...
...
src/cmd/gc/go.y
View file @
9dbaab54
...
...
@@ -42,7 +42,7 @@
%
type
<
node
>
range_header
range_body
range_stmt
select_stmt
%
type
<
node
>
simple_stmt
osimple_stmt
semi_stmt
%
type
<
node
>
expr
uexpr
pexpr
expr_list
oexpr
oexpr_list
expr_list_r
%
type
<
node
>
name
name_name
onew_name
new_name
new_name_list_r
conexpr
%
type
<
node
>
name
name_name
onew_name
new_name
new_name_list_r
%
type
<
node
>
vardcl_list_r
vardcl
Avardcl
Bvardcl
%
type
<
node
>
interfacedcl_list_r
interfacedcl
%
type
<
node
>
structdcl_list_r
structdcl
...
...
@@ -182,7 +182,13 @@ Acommon_dcl:
{
$$
=
rev
($
3
);
}
|
LCONST
'('
constdcl_list_r
osemi
')'
|
LCONST
'('
constdcl
osemi
')'
{
iota
=
0
;
lastconst
=
N
;
$$
=
N
;
}
|
LCONST
'('
constdcl
';'
constdcl_list_r
osemi
')'
{
iota
=
0
;
lastconst
=
N
;
...
...
@@ -234,7 +240,7 @@ Bvardcl:
$$
=
nod
(
OAS
,
$$,
N
);
}
|
new_name_list_r
type
'='
o
expr_list
|
new_name_list_r
type
'='
expr_list
{
$$
=
rev
($
1
);
dodclvar
($$,
$
2
);
...
...
@@ -250,29 +256,43 @@ Bvardcl:
}
constdcl
:
new_name
con
expr
new_name
type
'='
expr
{
walktype
($
2
,
Erv
);
dodclconst
($
1
,
$
2
);
Node
*
c
=
treecopy
($
4
);
walktype
(
c
,
Erv
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
lastconst
=
$
4
;
iota
+=
1
;
}
|
new_name
type
con
expr
|
new_name
'='
expr
{
walktype
($
3
,
Erv
);
convlit
($
3
,
$
2
);
dodclconst
($
1
,
$
3
);
Node
*
c
=
treecopy
($
3
);
walktype
(
c
,
Erv
);
dodclconst
($
1
,
c
);
lastconst
=
$
3
;
iota
+=
1
;
}
conexpr
:
constdcl1
:
constdcl
|
new_name
type
{
if
(
lastconst
==
N
)
yyerror
(
"first constant must evaluate an expression"
);
$$
=
treecopy
(
lastconst
);
Node
*
c
=
treecopy
(
lastconst
);
walktype
(
c
,
Erv
);
convlit
(
c
,
$
2
);
dodclconst
($
1
,
c
);
iota
+=
1
;
}
|
'='
expr
|
new_name
{
lastconst
=
$
2
;
$$
=
treecopy
(
lastconst
);
Node
*
c
=
treecopy
(
lastconst
);
walktype
(
c
,
Erv
);
dodclconst
($
1
,
c
);
iota
+=
1
;
}
...
...
@@ -1041,14 +1061,6 @@ Afntypeh:
$$
=
functype
(
N
,
$
3
,
$
5
);
funcnam
($$,
nil
);
}
|
LFUNC
'('
oarg_type_list
')'
'.'
'('
oarg_type_list
')'
Afnres
/*
i
dont
believe
that
this
form
is
useful
for
anything
*/
{
if
($
3
==
N
||
$
3
->
op
==
OLIST
)
yyerror
(
"syntax error in method receiver"
);
$$
=
functype
($
3
,
$
7
,
$
9
);
funcnam
($$,
nil
);
}
Bfntypeh
:
LFUNC
'('
oarg_type_list
')'
Bfnres
...
...
@@ -1056,14 +1068,6 @@ Bfntypeh:
$$
=
functype
(
N
,
$
3
,
$
5
);
funcnam
($$,
nil
);
}
|
LFUNC
'('
oarg_type_list
')'
'.'
'('
oarg_type_list
')'
Bfnres
/*
i
dont
believe
that
this
form
is
useful
for
anything
*/
{
if
($
3
==
N
||
$
3
->
op
==
OLIST
)
yyerror
(
"syntax error in method receiver"
);
$$
=
functype
($
3
,
$
7
,
$
9
);
funcnam
($$,
nil
);
}
fntype
:
fntypeh
...
...
@@ -1168,8 +1172,8 @@ vardcl_list_r:
}
constdcl_list_r
:
constdcl
|
constdcl_list_r
';'
constdcl
constdcl
1
|
constdcl_list_r
';'
constdcl
1
typedcl_list_r
:
typedcl
...
...
@@ -1415,7 +1419,7 @@ keyexpr_list:
{
$$
=
rev
($
1
);
}
|
expr_list
|
o
expr_list
/*
*
the
one
compromise
of
a
...
...
src/cmd/gc/subr.c
View file @
9dbaab54
...
...
@@ -591,7 +591,6 @@ opnames[] =
[
OCALLINTER
]
=
"CALLINTER"
,
[
OCASE
]
=
"CASE"
,
[
OXCASE
]
=
"XCASE"
,
[
OSCASE
]
=
"SCASE"
,
[
OCMP
]
=
"CMP"
,
[
OFALL
]
=
"FALL"
,
[
OCONV
]
=
"CONV"
,
...
...
src/cmd/gc/walk.c
View file @
9dbaab54
...
...
@@ -16,13 +16,74 @@ walk(Node *fn)
if
(
debug
[
'W'
])
dump
(
"fn-before"
,
fn
->
nbody
);
curfn
=
fn
;
walk
type
(
fn
->
nbody
,
Etop
);
walk
state
(
fn
->
nbody
);
if
(
debug
[
'W'
])
dump
(
"fn"
,
fn
->
nbody
);
}
void
walktype1
(
Node
*
n
,
int
top
)
walkstate
(
Node
*
n
)
{
Node
*
l
,
*
more
;
loop:
if
(
n
==
N
)
return
;
more
=
N
;
switch
(
n
->
op
)
{
case
OLIST
:
walkstate
(
n
->
left
);
more
=
n
->
right
;
break
;
default:
yyerror
(
"walkstate: %O not a top level statement"
,
n
->
op
);
case
OASOP
:
case
OAS
:
case
OCALLMETH
:
case
OCALLINTER
:
case
OCALL
:
case
OSEND
:
case
ORECV
:
case
OPRINT
:
case
OPANIC
:
case
OFOR
:
case
OIF
:
case
OSWITCH
:
case
OSELECT
:
case
OEMPTY
:
case
OBREAK
:
case
OCONTINUE
:
case
OGOTO
:
case
OLABEL
:
case
OFALL
:
case
OXCASE
:
case
OCASE
:
case
OXFALL
:
case
ORETURN
:
case
OPROC
:
walktype
(
n
,
Etop
);
break
;
}
while
(
addtop
!=
N
)
{
l
=
addtop
;
addtop
=
N
;
walktype
(
l
,
Etop
);
n
->
ninit
=
list
(
n
->
ninit
,
l
);
}
if
(
more
!=
N
)
{
n
=
more
;
goto
loop
;
}
}
void
walktype
(
Node
*
n
,
int
top
)
{
Node
*
r
,
*
l
;
Type
*
t
;
...
...
@@ -108,11 +169,11 @@ loop:
case
OFOR
:
if
(
top
!=
Etop
)
goto
nottop
;
walk
type
(
n
->
ninit
,
Etop
);
walk
state
(
n
->
ninit
);
walkbool
(
n
->
ntest
);
walk
type
(
n
->
nincr
,
Etop
);
n
=
n
->
nbody
;
goto
loop
;
walk
state
(
n
->
nincr
);
walkstate
(
n
->
nbody
)
;
goto
ret
;
case
OSWITCH
:
if
(
top
!=
Etop
)
...
...
@@ -123,9 +184,9 @@ loop:
if
(
n
->
ntest
==
N
)
n
->
ntest
=
booltrue
;
walk
type
(
n
->
ninit
,
Etop
);
walk
state
(
n
->
ninit
);
walktype
(
n
->
ntest
,
Erv
);
walk
type
(
n
->
nbody
,
Etop
);
walk
state
(
n
->
nbody
);
// find common type
if
(
n
->
ntest
->
type
==
T
)
...
...
@@ -149,13 +210,6 @@ loop:
walkselect
(
n
);
goto
ret
;
case
OSCASE
:
if
(
top
!=
Etop
)
goto
nottop
;
// walktype(n->left, Erv); SPECIAL
n
=
n
->
right
;
goto
loop
;
case
OEMPTY
:
if
(
top
!=
Etop
)
goto
nottop
;
...
...
@@ -164,16 +218,16 @@ loop:
case
OIF
:
if
(
top
!=
Etop
)
goto
nottop
;
walk
type
(
n
->
ninit
,
Etop
);
walk
state
(
n
->
ninit
);
walkbool
(
n
->
ntest
);
walk
type
(
n
->
nelse
,
Etop
);
n
=
n
->
nbody
;
goto
loop
;
walk
state
(
n
->
nelse
);
walkstate
(
n
->
nbody
)
;
goto
ret
;
case
OPROC
:
if
(
top
!=
Etop
)
goto
nottop
;
walk
type
(
n
->
left
,
Etop
);
walk
state
(
n
->
left
);
goto
ret
;
case
OCALLMETH
:
...
...
@@ -345,8 +399,8 @@ loop:
if
(
top
!=
Etop
)
goto
nottop
;
walktype
(
n
->
left
,
Erv
);
n
=
n
->
right
;
goto
loop
;
walkstate
(
n
->
right
)
;
goto
ret
;
case
OXFALL
:
if
(
top
!=
Etop
)
...
...
@@ -480,7 +534,7 @@ loop:
if
(
!
isptrto
(
l
->
left
->
type
,
TMAP
))
goto
com
;
*
n
=
*
mapop
(
n
,
top
);
goto
loop
;
goto
ret
;
case
OLSH
:
case
ORSH
:
...
...
@@ -1179,8 +1233,8 @@ walkselect(Node *sel)
sel
->
nbody
=
rev
(
res
);
sel
->
left
=
N
;
walk
type
(
sel
->
ninit
,
Etop
);
walk
type
(
sel
->
nbody
,
Etop
);
walk
state
(
sel
->
ninit
);
walk
state
(
sel
->
nbody
);
//dump("sel", sel);
...
...
@@ -1476,7 +1530,7 @@ prcompat(Node *n)
loop:
if
(
l
==
N
)
{
walktype
(
r
,
E
top
);
walktype
(
r
,
E
rv
);
return
r
;
}
...
...
@@ -1538,7 +1592,7 @@ nodpanic(int32 lineno)
on
=
syslook
(
"panicl"
,
0
);
n
=
nodintconst
(
lineno
);
n
=
nod
(
OCALL
,
on
,
n
);
walktype
(
n
,
E
top
);
walktype
(
n
,
E
rv
);
return
n
;
}
...
...
@@ -2124,7 +2178,7 @@ chanop(Node *n, int top)
argtype
(
on
,
t
->
type
);
// any-1
argtype
(
on
,
t
->
type
);
// any-2
r
=
nod
(
OCALL
,
on
,
r
);
walktype
(
r
,
top
);
walktype
(
r
,
E
top
);
break
;
send2:
...
...
@@ -2142,7 +2196,7 @@ chanop(Node *n, int top)
argtype
(
on
,
t
->
type
);
// any-1
argtype
(
on
,
t
->
type
);
// any-2
r
=
nod
(
OCALL
,
on
,
r
);
walktype
(
r
,
top
);
walktype
(
r
,
E
top
);
break
;
}
return
r
;
...
...
@@ -2318,20 +2372,6 @@ arrayop(Node *n, int top)
return
r
;
}
void
walktype
(
Node
*
n
,
int
top
)
{
Node
*
r
;
walktype1
(
n
,
top
);
while
(
top
==
Etop
&&
addtop
!=
N
)
{
r
=
addtop
;
addtop
=
N
;
walktype1
(
r
,
top
);
n
->
ninit
=
list
(
n
->
ninit
,
r
);
}
}
void
diagnamed
(
Type
*
t
)
{
...
...
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