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
179af0bb
Commit
179af0bb
authored
Jan 07, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clear automatic arrays created with literals
R=r OCL=22215 CL=22215
parent
a577ea31
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
57 deletions
+71
-57
walk.c
src/cmd/gc/walk.c
+71
-57
No files found.
src/cmd/gc/walk.c
View file @
179af0bb
...
@@ -3499,63 +3499,63 @@ loop:
...
@@ -3499,63 +3499,63 @@ loop:
goto
loop
;
goto
loop
;
}
}
Node
*
//
Node*
oldarraylit
(
Node
*
n
)
//
oldarraylit(Node *n)
{
//
{
Iter
saver
;
//
Iter saver;
Type
*
t
;
//
Type *t;
Node
*
var
,
*
r
,
*
a
;
//
Node *var, *r, *a;
int
idx
;
//
int idx;
//
t
=
n
->
type
;
//
t = n->type;
if
(
t
->
etype
!=
TARRAY
)
//
if(t->etype != TARRAY)
fatal
(
"arraylit: not array"
);
//
fatal("arraylit: not array");
//
if
(
t
->
bound
<
0
)
{
//
if(t->bound < 0) {
// make a shallow copy
//
// make a shallow copy
t
=
typ
(
0
);
//
t = typ(0);
*
t
=
*
n
->
type
;
//
*t = *n->type;
n
->
type
=
t
;
//
n->type = t;
//
// make it a closed array
//
// make it a closed array
r
=
listfirst
(
&
saver
,
&
n
->
left
);
//
r = listfirst(&saver, &n->left);
if
(
r
!=
N
&&
r
->
op
==
OEMPTY
)
//
if(r != N && r->op == OEMPTY)
r
=
N
;
//
r = N;
for
(
idx
=
0
;
r
!=
N
;
idx
++
)
//
for(idx=0; r!=N; idx++)
r
=
listnext
(
&
saver
);
//
r = listnext(&saver);
t
->
bound
=
idx
;
//
t->bound = idx;
}
//
}
//
var
=
nod
(
OXXX
,
N
,
N
);
//
var = nod(OXXX, N, N);
tempname
(
var
,
t
);
//
tempname(var, t);
//
idx
=
0
;
//
idx = 0;
r
=
listfirst
(
&
saver
,
&
n
->
left
);
//
r = listfirst(&saver, &n->left);
if
(
r
!=
N
&&
r
->
op
==
OEMPTY
)
//
if(r != N && r->op == OEMPTY)
r
=
N
;
//
r = N;
//
loop:
//
loop:
if
(
r
==
N
)
//
if(r == N)
return
var
;
//
return var;
//
// build list of var[c] = expr
//
// build list of var[c] = expr
//
a
=
nodintconst
(
idx
);
//
a = nodintconst(idx);
a
=
nod
(
OINDEX
,
var
,
a
);
//
a = nod(OINDEX, var, a);
a
=
nod
(
OAS
,
a
,
r
);
//
a = nod(OAS, a, r);
addtop
=
list
(
addtop
,
a
);
//
addtop = list(addtop, a);
idx
++
;
//
idx++;
//
r
=
listnext
(
&
saver
);
//
r = listnext(&saver);
goto
loop
;
//
goto loop;
}
//
}
Node
*
Node
*
arraylit
(
Node
*
n
)
arraylit
(
Node
*
n
)
{
{
Iter
saver
;
Iter
saver
;
Type
*
t
;
Type
*
t
;
Node
*
var
,
*
r
,
*
a
,
*
n
as
,
*
n
new
;
Node
*
var
,
*
r
,
*
a
,
*
nnew
;
int
idx
,
b
;
int
idx
,
b
;
t
=
n
->
type
;
t
=
n
->
type
;
...
@@ -3571,8 +3571,26 @@ arraylit(Node *n)
...
@@ -3571,8 +3571,26 @@ arraylit(Node *n)
nnew
=
nod
(
OMAKE
,
N
,
N
);
nnew
=
nod
(
OMAKE
,
N
,
N
);
nnew
->
type
=
t
;
nnew
->
type
=
t
;
nas
=
nod
(
OAS
,
var
,
nnew
);
a
=
nod
(
OAS
,
var
,
nnew
);
addtop
=
list
(
addtop
,
nas
);
addtop
=
list
(
addtop
,
a
);
}
if
(
b
>=
0
)
{
idx
=
0
;
r
=
listfirst
(
&
saver
,
&
n
->
left
);
if
(
r
!=
N
&&
r
->
op
==
OEMPTY
)
r
=
N
;
while
(
r
!=
N
)
{
// count initializers
idx
++
;
r
=
listnext
(
&
saver
);
}
// if entire array isnt initialized,
// then clear the array
if
(
idx
<
b
)
{
a
=
nod
(
OAS
,
var
,
N
);
addtop
=
list
(
addtop
,
a
);
}
}
}
idx
=
0
;
idx
=
0
;
...
@@ -3581,10 +3599,6 @@ arraylit(Node *n)
...
@@ -3581,10 +3599,6 @@ arraylit(Node *n)
r
=
N
;
r
=
N
;
while
(
r
!=
N
)
{
while
(
r
!=
N
)
{
// build list of var[c] = expr
// build list of var[c] = expr
if
(
b
>=
0
&&
idx
>=
b
)
{
yyerror
(
"literal array initializer out of bounds"
);
break
;
}
a
=
nodintconst
(
idx
);
a
=
nodintconst
(
idx
);
a
=
nod
(
OINDEX
,
var
,
a
);
a
=
nod
(
OINDEX
,
var
,
a
);
a
=
nod
(
OAS
,
a
,
r
);
a
=
nod
(
OAS
,
a
,
r
);
...
...
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