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
d915b961
Commit
d915b961
authored
Jul 03, 2008
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new iota
SVN=125984
parent
b43ad96e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
7 deletions
+58
-7
go.h
src/cmd/gc/go.h
+3
-0
go.y
src/cmd/gc/go.y
+21
-7
subr.c
src/cmd/gc/subr.c
+34
-0
No files found.
src/cmd/gc/go.h
View file @
d915b961
...
...
@@ -114,6 +114,7 @@ struct Node
uchar
etype
;
// op for OASOP, etype for OTYPE, exclam for export
uchar
class
;
// PPARAM, PAUTO, PEXTERN, PSTATIC
uchar
method
;
// OCALLMETH name
uchar
iota
;
// OLITERAL made from iota
// most nodes
Node
*
left
;
...
...
@@ -393,6 +394,7 @@ EXTERN int inimportsys;
EXTERN
Node
*
booltrue
;
EXTERN
Node
*
boolfalse
;
EXTERN
ulong
iota
;
EXTERN
Node
*
lastconst
;
EXTERN
long
vargen
;
EXTERN
long
exportgen
;
EXTERN
long
maxarg
;
...
...
@@ -479,6 +481,7 @@ void badtype(int, Type*, Type*);
Type
*
ptrto
(
Type
*
);
Node
*
cleanidlist
(
Node
*
);
Node
*
syslook
(
char
*
,
int
);
Node
*
treecopy
(
Node
*
);
Type
**
getthis
(
Type
*
);
Type
**
getoutarg
(
Type
*
);
...
...
src/cmd/gc/go.y
View file @
d915b961
...
...
@@ -40,7 +40,7 @@
%
type
<
node
>
range_header
range_body
range_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
new_name
new_name_list_r
%
type
<
node
>
name
name_name
new_name
new_name_list_r
conexpr
%
type
<
node
>
vardcl_list_r
vardcl
Avardcl
Bvardcl
%
type
<
node
>
interfacedcl_list_r
interfacedcl
%
type
<
node
>
structdcl_list_r
structdcl
...
...
@@ -166,6 +166,7 @@ Acommon_dcl:
{
$$
=
N
;
iota
=
0
;
lastconst
=
N
;
}
|
LTYPE
Atypedcl
{
...
...
@@ -185,6 +186,7 @@ Bcommon_dcl:
{
$$
=
N
;
iota
=
0
;
lastconst
=
N
;
}
|
LTYPE
Btypedcl
{
...
...
@@ -224,22 +226,33 @@ Bvardcl:
walktype
($
3
,
Erv
);
//
this
is
a
little
harry
defaultlit
($
3
);
dodclvar
($
1
,
$
3
->
type
);
$$
=
nod
(
OAS
,
$
1
,
$
3
);
}
constdcl
:
new_name
'='
expr
new_name
conexpr
{
walktype
($
2
,
Erv
);
dodclconst
($
1
,
$
2
);
}
|
new_name
type
conexpr
{
walktype
($
3
,
Erv
);
convlit
($
3
,
$
2
);
dodclconst
($
1
,
$
3
);
}
conexpr
:
{
if
(
lastconst
==
N
)
yyerror
(
"first constant must evaluate an expression"
);
$$
=
treecopy
(
lastconst
);
iota
+=
1
;
}
|
new_name
type
'='
expr
|
'='
expr
{
walktype
($
4
,
Erv
);
convlit
($
4
,
$
2
);
dodclconst
($
1
,
$
4
);
$$
=
$
2
;
lastconst
=
treecopy
($$);
iota
+=
1
;
}
...
...
@@ -653,6 +666,7 @@ pexpr:
|
LIOTA
{
$$
=
literal
(
iota
);
$$->
iota
=
1
;
//
flag
to
reevaluate
on
copy
}
|
name
|
'('
expr
')'
...
...
src/cmd/gc/subr.c
View file @
d915b961
...
...
@@ -1092,6 +1092,40 @@ out:
return
fmtstrcpy
(
fp
,
buf
);
}
Node
*
treecopy
(
Node
*
n
)
{
Node
*
m
;
if
(
n
==
N
)
return
N
;
switch
(
n
->
op
)
{
default:
m
=
nod
(
OXXX
,
N
,
N
);
*
m
=
*
n
;
m
->
left
=
treecopy
(
n
->
left
);
m
->
right
=
treecopy
(
n
->
right
);
break
;
case
OLITERAL
:
if
(
n
->
iota
)
{
m
=
literal
(
iota
);
m
->
iota
=
1
;
// flag to reevaluate on copy
break
;
}
m
=
nod
(
OXXX
,
N
,
N
);
*
m
=
*
n
;
break
;
case
ONAME
:
m
=
nod
(
OXXX
,
N
,
N
);
*
m
=
*
n
;
break
;
}
return
m
;
}
int
Zconv
(
Fmt
*
fp
)
{
...
...
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