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
9c5669bd
Commit
9c5669bd
authored
Sep 02, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug in conv(string, bytearray)
R=r OCL=14732 CL=14732
parent
b5eddae5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
55 deletions
+93
-55
src/cmd/gc/go.h
src/cmd/gc/go.h
+2
-1
src/cmd/gc/subr.c
src/cmd/gc/subr.c
+7
-5
src/cmd/gc/walk.c
src/cmd/gc/walk.c
+84
-49
No files found.
src/cmd/gc/go.h
View file @
9c5669bd
...
@@ -559,7 +559,7 @@ int isptrto(Type*, int);
...
@@ -559,7 +559,7 @@ int isptrto(Type*, int);
int
isptrarray
(
Type
*
);
int
isptrarray
(
Type
*
);
int
isptrdarray
(
Type
*
);
int
isptrdarray
(
Type
*
);
int
isinter
(
Type
*
);
int
isinter
(
Type
*
);
int
isbytearray
(
Type
*
);
int
bytearraysz
(
Type
*
);
int
eqtype
(
Type
*
,
Type
*
,
int
);
int
eqtype
(
Type
*
,
Type
*
,
int
);
void
argtype
(
Node
*
,
Type
*
);
void
argtype
(
Node
*
,
Type
*
);
int
eqargs
(
Type
*
,
Type
*
);
int
eqargs
(
Type
*
,
Type
*
);
...
@@ -689,6 +689,7 @@ Node* reorder1(Node*);
...
@@ -689,6 +689,7 @@ Node* reorder1(Node*);
Node
*
reorder2
(
Node
*
);
Node
*
reorder2
(
Node
*
);
Node
*
reorder3
(
Node
*
);
Node
*
reorder3
(
Node
*
);
Node
*
reorder4
(
Node
*
);
Node
*
reorder4
(
Node
*
);
Node
*
structlit
(
Node
*
);
/*
/*
* const.c
* const.c
...
...
src/cmd/gc/subr.c
View file @
9c5669bd
...
@@ -1229,18 +1229,20 @@ isinter(Type *t)
...
@@ -1229,18 +1229,20 @@ isinter(Type *t)
}
}
int
int
isbytearray
(
Type
*
t
)
bytearraysz
(
Type
*
t
)
{
{
if
(
t
==
T
)
if
(
t
==
T
)
return
0
;
return
-
2
;
if
(
isptr
[
t
->
etype
])
{
if
(
isptr
[
t
->
etype
])
{
t
=
t
->
type
;
t
=
t
->
type
;
if
(
t
==
T
)
if
(
t
==
T
)
return
0
;
return
-
2
;
}
}
if
(
t
->
etype
!=
TARRAY
)
if
(
t
->
etype
!=
TARRAY
)
return
0
;
return
-
2
;
return
t
->
bound
+
1
;
if
(
!
eqtype
(
t
->
type
,
types
[
TUINT8
],
0
))
return
-
2
;
return
t
->
bound
;
// -1 is dyn, >=0 is fixed
}
}
int
int
...
...
src/cmd/gc/walk.c
View file @
9c5669bd
...
@@ -8,6 +8,7 @@ static Type* sw1(Node*, Type*);
...
@@ -8,6 +8,7 @@ static Type* sw1(Node*, Type*);
static
Type
*
sw2
(
Node
*
,
Type
*
);
static
Type
*
sw2
(
Node
*
,
Type
*
);
static
Type
*
sw3
(
Node
*
,
Type
*
);
static
Type
*
sw3
(
Node
*
,
Type
*
);
static
Node
*
curfn
;
static
Node
*
curfn
;
static
Node
*
addtop
;
void
void
walk
(
Node
*
fn
)
walk
(
Node
*
fn
)
...
@@ -38,7 +39,7 @@ isselect(Node *n)
...
@@ -38,7 +39,7 @@ isselect(Node *n)
}
}
void
void
walktype
(
Node
*
n
,
int
top
)
walktype
1
(
Node
*
n
,
int
top
)
{
{
Node
*
r
,
*
l
;
Node
*
r
,
*
l
;
Type
*
t
;
Type
*
t
;
...
@@ -54,11 +55,6 @@ walktype(Node *n, int top)
...
@@ -54,11 +55,6 @@ walktype(Node *n, int top)
* compile-time constants are evaluated.
* compile-time constants are evaluated.
*/
*/
if
(
top
==
Exxx
||
top
==
Eyyy
)
{
dump
(
""
,
n
);
fatal
(
"walktype: bad top=%d"
,
top
);
}
loop:
loop:
if
(
n
==
N
)
if
(
n
==
N
)
goto
ret
;
goto
ret
;
...
@@ -76,6 +72,11 @@ loop:
...
@@ -76,6 +72,11 @@ loop:
fatal
(
"walktype: switch 1 unknown op %N"
,
n
);
fatal
(
"walktype: switch 1 unknown op %N"
,
n
);
goto
ret
;
goto
ret
;
case
OLIST
:
walktype
(
n
->
left
,
top
);
n
=
n
->
right
;
goto
loop
;
case
OPRINT
:
case
OPRINT
:
if
(
top
!=
Etop
)
if
(
top
!=
Etop
)
goto
nottop
;
goto
nottop
;
...
@@ -120,11 +121,6 @@ loop:
...
@@ -120,11 +121,6 @@ loop:
}
}
goto
ret
;
goto
ret
;
case
OLIST
:
walktype
(
n
->
left
,
top
);
n
=
n
->
right
;
goto
loop
;
case
OFOR
:
case
OFOR
:
if
(
top
!=
Etop
)
if
(
top
!=
Etop
)
goto
nottop
;
goto
nottop
;
...
@@ -400,6 +396,8 @@ loop:
...
@@ -400,6 +396,8 @@ loop:
goto
ret
;
goto
ret
;
convlit
(
l
,
t
);
convlit
(
l
,
t
);
if
(
l
->
type
==
T
)
goto
ret
;
// nil conversion
// nil conversion
if
(
eqtype
(
t
,
l
->
type
,
0
))
{
if
(
eqtype
(
t
,
l
->
type
,
0
))
{
...
@@ -422,7 +420,7 @@ loop:
...
@@ -422,7 +420,7 @@ loop:
*
n
=
*
stringop
(
n
,
top
);
*
n
=
*
stringop
(
n
,
top
);
goto
ret
;
goto
ret
;
}
}
if
(
isbytearray
(
l
->
type
)
!=
0
)
{
if
(
bytearraysz
(
l
->
type
)
!=
-
2
)
{
n
->
op
=
OARRAY
;
n
->
op
=
OARRAY
;
*
n
=
*
stringop
(
n
,
top
);
*
n
=
*
stringop
(
n
,
top
);
goto
ret
;
goto
ret
;
...
@@ -433,16 +431,20 @@ loop:
...
@@ -433,16 +431,20 @@ loop:
if
(
isptrarray
(
t
)
&&
isptrdarray
(
l
->
type
))
if
(
isptrarray
(
t
)
&&
isptrdarray
(
l
->
type
))
goto
ret
;
goto
ret
;
// if(t->etype == TARRAY) {
// interface and structure
// arrayconv(t, l);
// goto ret;
// }
r
=
isandss
(
n
->
type
,
l
);
r
=
isandss
(
n
->
type
,
l
);
if
(
r
!=
N
)
{
if
(
r
!=
N
)
{
*
n
=
*
r
;
*
n
=
*
r
;
goto
ret
;
goto
ret
;
}
}
// structure literal
if
(
t
->
etype
==
TSTRUCT
)
{
r
=
structlit
(
n
);
*
n
=
*
r
;
goto
ret
;
}
badtype
(
n
->
op
,
l
->
type
,
t
);
badtype
(
n
->
op
,
l
->
type
,
t
);
goto
ret
;
goto
ret
;
...
@@ -1591,6 +1593,7 @@ Node*
...
@@ -1591,6 +1593,7 @@ Node*
stringop
(
Node
*
n
,
int
top
)
stringop
(
Node
*
n
,
int
top
)
{
{
Node
*
r
,
*
c
,
*
on
;
Node
*
r
,
*
c
,
*
on
;
Type
*
t
;
int32
l
;
int32
l
;
switch
(
n
->
op
)
{
switch
(
n
->
op
)
{
...
@@ -1674,15 +1677,24 @@ stringop(Node *n, int top)
...
@@ -1674,15 +1677,24 @@ stringop(Node *n, int top)
break
;
break
;
case
OARRAY
:
case
OARRAY
:
// byteastring(a, l)
// byteastring(*byte, int32) string;
t
=
n
->
left
->
type
;
l
=
bytearraysz
(
t
);
// &a[0]
c
=
nodintconst
(
0
);
c
=
nodintconst
(
0
);
r
=
nod
(
OINDEX
,
n
->
left
,
c
);
r
=
nod
(
OINDEX
,
n
->
left
,
c
);
r
=
nod
(
OADDR
,
r
,
N
);
r
=
nod
(
OADDR
,
r
,
N
);
l
=
isbytearray
(
n
->
left
->
type
);
if
(
l
>=
0
)
{
c
=
nodintconst
(
l
-
1
);
// static size
c
=
nodintconst
(
l
);
}
else
{
// dynamic size
c
=
nod
(
OLEN
,
n
->
left
,
N
);
}
r
=
list
(
r
,
c
);
r
=
list
(
r
,
c
);
on
=
syslook
(
"byteastring"
,
0
);
on
=
syslook
(
"byteastring"
,
0
);
r
=
nod
(
OCALL
,
on
,
r
);
r
=
nod
(
OCALL
,
on
,
r
);
break
;
break
;
...
@@ -2309,6 +2321,20 @@ arrayop(Node *n, int top)
...
@@ -2309,6 +2321,20 @@ arrayop(Node *n, int top)
return
r
;
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
(
r
,
n
->
ninit
);
}
}
void
void
diagnamed
(
Type
*
t
)
diagnamed
(
Type
*
t
)
{
{
...
@@ -2420,34 +2446,6 @@ bad:
...
@@ -2420,34 +2446,6 @@ bad:
return
n
;
return
n
;
}
}
//void
//arrayconv(Type *t, Node *n)
//{
// int c;
// Iter save;
// Node *l;
//
// l = listfirst(&save, &n);
// c = 0;
//
//loop:
// if(l == N) {
// if(t->bound == 0)
// t->bound = c;
// if(t->bound == 0 || t->bound < c)
// yyerror("error with array convert bounds");
// return;
// }
//
// c++;
// walktype(l, Erv);
// convlit(l, t->type);
// if(!ascompat(l->type, t->type))
// badtype(OARRAY, l->type, t->type);
// l = listnext(&save);
// goto loop;
//}
Node
*
Node
*
old2new
(
Node
*
n
,
Type
*
t
)
old2new
(
Node
*
n
,
Type
*
t
)
{
{
...
@@ -2818,3 +2816,40 @@ reorder4(Node *n)
...
@@ -2818,3 +2816,40 @@ reorder4(Node *n)
*/
*/
return
n
;
return
n
;
}
}
Node
*
structlit
(
Node
*
n
)
{
Iter
savel
,
saver
;
Type
*
l
,
*
t
;
Node
*
var
,
*
r
,
*
a
;
t
=
n
->
type
;
if
(
t
->
etype
!=
TSTRUCT
)
fatal
(
"structlit: not struct"
);
print
(
"
\n
struct lit %lT
\n
"
,
t
);
var
=
nod
(
OXXX
,
N
,
N
);
tempname
(
var
,
t
);
l
=
structfirst
(
&
savel
,
&
n
->
type
);
r
=
listfirst
(
&
saver
,
&
n
->
left
);
loop:
if
(
l
==
T
||
r
==
N
)
{
if
(
l
!=
T
||
r
!=
N
)
yyerror
(
"error in shape struct literal"
);
return
var
;
}
// build list of var.field = expr
a
=
nod
(
ODOT
,
var
,
newname
(
l
->
sym
));
a
=
nod
(
OAS
,
a
,
r
);
addtop
=
list
(
addtop
,
a
);
l
=
structnext
(
&
savel
);
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