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
4539ced7
Commit
4539ced7
authored
Sep 03, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
array literals
R=r OCL=14756 CL=14756
parent
0976e34d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
54 deletions
+89
-54
go.h
src/cmd/gc/go.h
+2
-0
go.y
src/cmd/gc/go.y
+30
-27
subr.c
src/cmd/gc/subr.c
+6
-27
walk.c
src/cmd/gc/walk.c
+51
-0
No files found.
src/cmd/gc/go.h
View file @
4539ced7
...
@@ -690,6 +690,8 @@ Node* reorder2(Node*);
...
@@ -690,6 +690,8 @@ Node* reorder2(Node*);
Node
*
reorder3
(
Node
*
);
Node
*
reorder3
(
Node
*
);
Node
*
reorder4
(
Node
*
);
Node
*
reorder4
(
Node
*
);
Node
*
structlit
(
Node
*
);
Node
*
structlit
(
Node
*
);
Node
*
arraylit
(
Node
*
);
Node
*
chantlit
(
Node
*
);
/*
/*
* const.c
* const.c
...
...
src/cmd/gc/go.y
View file @
4539ced7
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
%
token
LLSH
LRSH
LINC
LDEC
LSEND
LRECV
%
token
LLSH
LRSH
LINC
LDEC
LSEND
LRECV
%
token
LIGNORE
%
token
LIGNORE
%
type
<
sym
>
sym
sym1
sym2
key
laconst
lname
latype
%
type
<
sym
>
sym
sym1
sym2
key
word
laconst
lname
latype
%
type
<
lint
>
chandir
%
type
<
lint
>
chandir
%
type
<
node
>
xdcl
xdcl_list_r
oxdcl_list
%
type
<
node
>
xdcl
xdcl_list_r
oxdcl_list
%
type
<
node
>
common_dcl
Acommon_dcl
Bcommon_dcl
%
type
<
node
>
common_dcl
Acommon_dcl
Bcommon_dcl
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
%
type
<
node
>
hidden_importsym_list_r
ohidden_importsym_list
hidden_importsym
isym
%
type
<
node
>
hidden_importsym_list_r
ohidden_importsym_list
hidden_importsym
isym
%
type
<
node
>
hidden_importfield_list_r
ohidden_importfield_list
hidden_importfield
%
type
<
node
>
hidden_importfield_list_r
ohidden_importfield_list
hidden_importfield
%
type
<
node
>
fnres
Afnres
Bfnres
fnliteral
xfndcl
fndcl
fnbody
%
type
<
node
>
fnres
Afnres
Bfnres
fnliteral
xfndcl
fndcl
fnbody
%
type
<
node
>
keyval_list_r
keyval
%
type
<
node
>
key
expr_list
key
val_list_r
keyval
%
type
<
node
>
typedcl
Atypedcl
Btypedcl
%
type
<
node
>
typedcl
Atypedcl
Btypedcl
%
type
<
type
>
fntype
fnlitdcl
intype
new_type
typeconv
%
type
<
type
>
fntype
fnlitdcl
intype
new_type
typeconv
...
@@ -753,23 +753,13 @@ pexpr:
...
@@ -753,23 +753,13 @@ pexpr:
$$->
type
=
ptrto
($
3
);
$$->
type
=
ptrto
($
3
);
}
}
|
fnliteral
|
fnliteral
|
'['
expr_list
']'
|
typeconv
'('
keyexpr_list
')'
{
//
array
literal
$$
=
N
;
}
|
'['
keyval_list_r
']'
{
//
map
literal
$$
=
N
;
}
|
typeconv
'('
oexpr_list
')'
{
{
//
struct
literal
and
conversions
//
struct
literal
and
conversions
$$
=
nod
(
OCONV
,
$
3
,
N
);
$$
=
nod
(
OCONV
,
rev
($
3
)
,
N
);
$$->
type
=
$
1
;
$$->
type
=
$
1
;
}
}
|
LCONVERT
'('
type
','
expr
')'
|
LCONVERT
'('
type
','
keyexpr_list
')'
{
{
$$
=
nod
(
OCONV
,
$
5
,
N
);
$$
=
nod
(
OCONV
,
$
5
,
N
);
$$->
type
=
$
3
;
$$->
type
=
$
3
;
...
@@ -846,17 +836,17 @@ sym:
...
@@ -846,17 +836,17 @@ sym:
sym1
:
sym1
:
sym
sym
|
key
|
key
word
sym2
:
sym2
:
sym
sym
|
key
|
key
word
/*
/*
*
keywords
that
we
can
*
keywords
that
we
can
*
use
as
variable
/
type
names
*
use
as
variable
/
type
names
*/
*/
key
:
key
word
:
LNIL
LNIL
|
LTRUE
|
LTRUE
|
LFALSE
|
LFALSE
...
@@ -881,22 +871,28 @@ typeconv:
...
@@ -881,22 +871,28 @@ typeconv:
{
{
$$
=
oldtype
($
1
);
$$
=
oldtype
($
1
);
}
}
|
'['
']'
typeconv
|
'['
oexpr
']'
type
{
{
$$
=
aindex
(
N
,
$
3
);
//
array
literal
}
$$
=
aindex
($
2
,
$
4
);
|
LCHAN
chandir
typeconv
{
$$
=
typ
(
TCHAN
);
$$->
type
=
$
3
;
$$->
chan
=
$
2
;
}
}
|
LMAP
'['
type
conv
']'
typeconv
|
LMAP
'['
type
']'
type
{
{
//
map
literal
$$
=
typ
(
TMAP
);
$$
=
typ
(
TMAP
);
$$->
down
=
$
3
;
$$->
down
=
$
3
;
$$->
type
=
$
5
;
$$->
type
=
$
5
;
}
}
|
LSTRUCT
'{'
structdcl_list_r
osemi
'}'
{
//
struct
literal
$$
=
dostruct
(
rev
($
3
),
TSTRUCT
);
}
|
LSTRUCT
'{'
'}'
{
//
struct
literal
$$
=
dostruct
(
N
,
TSTRUCT
);
}
type
:
type
:
Atype
Atype
...
@@ -1414,6 +1410,13 @@ keyval_list_r:
...
@@ -1414,6 +1410,13 @@ keyval_list_r:
$$
=
nod
(
OLIST
,
$
1
,
$
3
);
$$
=
nod
(
OLIST
,
$
1
,
$
3
);
}
}
keyexpr_list
:
keyval_list_r
{
$$
=
rev
($
1
);
}
|
expr_list
/*
/*
*
the
one
compromise
of
a
*
the
one
compromise
of
a
*
non
-
reversed
list
*
non
-
reversed
list
...
...
src/cmd/gc/subr.c
View file @
4539ced7
...
@@ -425,33 +425,6 @@ loop:
...
@@ -425,33 +425,6 @@ loop:
dodump
(
n
->
left
,
dep
);
dodump
(
n
->
left
,
dep
);
n
=
n
->
right
;
n
=
n
->
right
;
goto
loop
;
goto
loop
;
// case ODCLFUNC:
// dodump(n->nname, dep);
// if(n->this) {
// indent(dep);
// print("%O-this\n", n->op);
// dodump(n->this, dep+1);
// }
// if(n->argout) {
// indent(dep);
// print("%O-outarg\n", n->op);
// dodump(n->argout, dep+1);
// }
// if(n->argin) {
// indent(dep);
// print("%O-inarg\n", n->op);
// dodump(n->argin, dep+1);
// }
// n = n->nbody;
// goto loop;
case
OIF
:
case
OSWITCH
:
case
OFOR
:
case
OSELECT
:
dodump
(
n
->
ninit
,
dep
);
break
;
}
}
indent
(
dep
);
indent
(
dep
);
...
@@ -460,6 +433,12 @@ loop:
...
@@ -460,6 +433,12 @@ loop:
return
;
return
;
}
}
if
(
n
->
ninit
!=
N
)
{
print
(
"%O-init
\n
"
,
n
->
op
);
dodump
(
n
->
ninit
,
dep
+
1
);
indent
(
dep
);
}
switch
(
n
->
op
)
{
switch
(
n
->
op
)
{
default:
default:
print
(
"%N
\n
"
,
n
);
print
(
"%N
\n
"
,
n
);
...
...
src/cmd/gc/walk.c
View file @
4539ced7
...
@@ -427,6 +427,13 @@ loop:
...
@@ -427,6 +427,13 @@ loop:
goto
ret
;
goto
ret
;
}
}
// structure literal
if
(
t
->
etype
==
TARRAY
)
{
r
=
arraylit
(
n
);
*
n
=
*
r
;
goto
ret
;
}
badtype
(
n
->
op
,
l
->
type
,
t
);
badtype
(
n
->
op
,
l
->
type
,
t
);
goto
ret
;
goto
ret
;
...
@@ -2835,3 +2842,47 @@ loop:
...
@@ -2835,3 +2842,47 @@ loop:
r
=
listnext
(
&
saver
);
r
=
listnext
(
&
saver
);
goto
loop
;
goto
loop
;
}
}
Node
*
arraylit
(
Node
*
n
)
{
Iter
saver
;
Type
*
t
;
Node
*
var
,
*
r
,
*
a
;
int
idx
;
t
=
n
->
type
;
if
(
t
->
etype
!=
TARRAY
)
fatal
(
"arraylit: not array"
);
if
(
t
->
bound
<
0
)
{
// make it a closed array
// should there be a type copy here?
r
=
listfirst
(
&
saver
,
&
n
->
left
);
for
(
idx
=
0
;
r
!=
N
;
idx
++
)
r
=
listnext
(
&
saver
);
t
->
bound
=
idx
;
}
var
=
nod
(
OXXX
,
N
,
N
);
tempname
(
var
,
t
);
idx
=
0
;
r
=
listfirst
(
&
saver
,
&
n
->
left
);
loop:
if
(
r
==
N
)
{
return
var
;
}
// build list of var[c] = expr
a
=
nodintconst
(
idx
);
a
=
nod
(
OINDEX
,
var
,
a
);
a
=
nod
(
OAS
,
a
,
r
);
addtop
=
list
(
addtop
,
a
);
idx
++
;
r
=
listnext
(
&
saver
);
goto
loop
;
}
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