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
b43ad96e
Commit
b43ad96e
authored
Jul 03, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- filed a bug w/ constant evaluation
SVN=125966
parent
add9c8cc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
251 additions
and
175 deletions
+251
-175
test/bugs/bug063.go
test/bugs/bug063.go
+8
-0
test/golden.out
test/golden.out
+14
-0
usr/gri/src/scanner.go
usr/gri/src/scanner.go
+229
-175
No files found.
test/bugs/bug063.go
0 → 100644
View file @
b43ad96e
// $G $D/$F.go
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
const
c
=
0
^
0
\ No newline at end of file
test/golden.out
View file @
b43ad96e
...
@@ -317,6 +317,20 @@ BUG: known to fail incorrectly
...
@@ -317,6 +317,20 @@ BUG: known to fail incorrectly
=========== bugs/bug062.go
=========== bugs/bug062.go
BUG: known to succeed incorrectly
BUG: known to succeed incorrectly
=========== bugs/bug063.go
bugs/bug063.go:4: illegal combination of literals XOR 7
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: expression must be a constant
bugs/bug063.go:4: fatal error: too many errors
BUG: should compile without problems
=========== fixedbugs/bug000.go
=========== fixedbugs/bug000.go
=========== fixedbugs/bug001.go
=========== fixedbugs/bug001.go
...
...
usr/gri/src/scanner.go
View file @
b43ad96e
...
@@ -69,6 +69,7 @@ const (
...
@@ -69,6 +69,7 @@ const (
COR
=
iota
;
COR
=
iota
;
// keywords
// keywords
KEYWORDS_BEG
=
iota
;
BREAK
=
iota
;
BREAK
=
iota
;
CASE
=
iota
;
CASE
=
iota
;
CONST
=
iota
;
CONST
=
iota
;
...
@@ -97,6 +98,7 @@ const (
...
@@ -97,6 +98,7 @@ const (
TRUE
=
iota
;
TRUE
=
iota
;
TYPE
=
iota
;
TYPE
=
iota
;
VAR
=
iota
;
VAR
=
iota
;
KEYWORDS_END
=
iota
;
)
)
...
@@ -108,96 +110,95 @@ var (
...
@@ -108,96 +110,95 @@ var (
export
TokenName
export
TokenName
func
TokenName
(
tok
int
)
string
{
func
TokenName
(
tok
int
)
string
{
switch
(
tok
)
{
switch
(
tok
)
{
case
ILLEGAL
:
return
"ILLEGAL"
;
case
ILLEGAL
:
return
"illegal"
;
case
EOF
:
return
"EOF"
;
case
EOF
:
return
"eof"
;
case
IDENT
:
return
"IDENT"
;
case
IDENT
:
return
"ident"
;
case
STRING
:
return
"STRING"
;
case
STRING
:
return
"string"
;
case
NUMBER
:
return
"NUMBER"
;
case
NUMBER
:
return
"number"
;
case
COMMA
:
return
"COMMA"
;
case
COMMA
:
return
","
;
case
COLON
:
return
"COLON"
;
case
COLON
:
return
":"
;
case
SEMICOLON
:
return
"SEMICOLON"
;
case
SEMICOLON
:
return
";"
;
case
PERIOD
:
return
"PERIOD"
;
case
PERIOD
:
return
"."
;
case
LPAREN
:
return
"LPAREN"
;
case
LPAREN
:
return
"("
;
case
RPAREN
:
return
"RPAREN"
;
case
RPAREN
:
return
")"
;
case
LBRACK
:
return
"LBRACK"
;
case
LBRACK
:
return
"["
;
case
RBRACK
:
return
"RBRACK"
;
case
RBRACK
:
return
"]"
;
case
LBRACE
:
return
"LBRACE"
;
case
LBRACE
:
return
"{"
;
case
RBRACE
:
return
"RBRACE"
;
case
RBRACE
:
return
"}"
;
case
ASSIGN
:
return
"ASSIGN"
;
case
ASSIGN
:
return
"="
;
case
DEFINE
:
return
"DEFINE"
;
case
DEFINE
:
return
":="
;
case
INC
:
return
"INC"
;
case
INC
:
return
"++"
;
case
DEC
:
return
"DEC"
;
case
DEC
:
return
"--"
;
case
NOT
:
return
"NOT"
;
case
NOT
:
return
"!"
;
case
AND
:
return
"AND"
;
case
AND
:
return
"&"
;
case
OR
:
return
"OR"
;
case
OR
:
return
"|"
;
case
XOR
:
return
"XOR"
;
case
XOR
:
return
"^"
;
case
ADD
:
return
"ADD"
;
case
ADD
:
return
"+"
;
case
SUB
:
return
"SUB"
;
case
SUB
:
return
"-"
;
case
MUL
:
return
"MUL"
;
case
MUL
:
return
"*"
;
case
REM
:
return
"REM"
;
case
QUO
:
return
"/"
;
case
QUO
:
return
"QUO"
;
case
REM
:
return
"%"
;
case
REM
:
return
"REM"
;
case
EQL
:
return
"=="
;
case
EQL
:
return
"EQL"
;
case
NEQ
:
return
"!="
;
case
NEQ
:
return
"NEQ"
;
case
LSS
:
return
"<"
;
case
LSS
:
return
"LSS"
;
case
LEQ
:
return
"<="
;
case
LEQ
:
return
"LEQ"
;
case
GTR
:
return
">"
;
case
GTR
:
return
"GTR"
;
case
GEQ
:
return
">="
;
case
GEQ
:
return
"GEQ"
;
case
SHL
:
return
"<<"
;
case
SHL
:
return
SHL
;
case
SHR
:
return
">>"
;
case
SHR
:
return
SHR
;
case
ADD_ASSIGN
:
return
"+="
;
case
ADD_ASSIGN
:
return
"ADD_ASSIGN"
;
case
SUB_ASSIGN
:
return
"-="
;
case
SUB_ASSIGN
:
return
"SUB_ASSIGN"
;
case
MUL_ASSIGN
:
return
"+="
;
case
MUL_ASSIGN
:
return
"MUL_ASSIGN"
;
case
QUO_ASSIGN
:
return
"/="
;
case
QUO_ASSIGN
:
return
"QUO_ASSIGN"
;
case
REM_ASSIGN
:
return
"%="
;
case
REM_ASSIGN
:
return
"REM_ASSIGN"
;
case
AND_ASSIGN
:
return
"&="
;
case
AND_ASSIGN
:
return
"AND_ASSIGN"
;
case
OR_ASSIGN
:
return
"|="
;
case
OR_ASSIGN
:
return
"OR_ASSIGN"
;
case
XOR_ASSIGN
:
return
"^="
;
case
XOR_ASSIGN
:
return
"XOR_ASSIGN"
;
case
SHL_ASSIGN
:
return
"<<="
;
case
SHL_ASSIGN
:
return
"SHL_ASSIGN"
;
case
SHR_ASSIGN
:
return
">>="
;
case
SHR_ASSIGN
:
return
"SHR_ASSIGN"
;
case
CAND
:
return
"&&"
;
case
CAND
:
return
"CAND"
;
case
COR
:
return
"||"
;
case
COR
:
return
"COR"
;
case
BREAK
:
return
"break"
;
case
BREAK
:
return
"BREAK"
;
case
CASE
:
return
"case"
;
case
CASE
:
return
"CASE"
;
case
CONST
:
return
"const"
;
case
CONST
:
return
"CONST"
;
case
CONTINUE
:
return
"continue"
;
case
CONTINUE
:
return
"CONTINUE"
;
case
DEFAULT
:
return
"default"
;
case
DEFAULT
:
return
"DEFAULT"
;
case
ELSE
:
return
"else"
;
case
ELSE
:
return
"ELSE"
;
case
EXPORT
:
return
"export"
;
case
EXPORT
:
return
"EXPORT"
;
case
FALLTHROUGH
:
return
"fallthrough"
;
case
FALLTHROUGH
:
return
"FALLTHROUGH"
;
case
FALSE
:
return
"false"
;
case
FALSE
:
return
"FALSE"
;
case
FOR
:
return
"for"
;
case
FOR
:
return
"FOR"
;
case
FUNC
:
return
"func"
;
case
FUNC
:
return
"FUNC"
;
case
GO
:
return
"go"
;
case
GO
:
return
"GO"
;
case
GOTO
:
return
"goto"
;
case
GOTO
:
return
"GOTO"
;
case
IF
:
return
"if"
;
case
IF
:
return
"IF"
;
case
IMPORT
:
return
"import"
;
case
IMPORT
:
return
"IMPORT"
;
case
INTERFACE
:
return
"interface"
;
case
INTERFACE
:
return
"INTERFACE"
;
case
MAP
:
return
"map"
;
case
MAP
:
return
"MAP"
;
case
NEW
:
return
"new"
;
case
NEW
:
return
"NEW"
;
case
NIL
:
return
"nil"
;
case
NIL
:
return
"NIL"
;
case
PACKAGE
:
return
"package"
;
case
PACKAGE
:
return
"PACKAGE"
;
case
RANGE
:
return
"range"
;
case
RANGE
:
return
"RANGE"
;
case
RETURN
:
return
"return"
;
case
RETURN
:
return
"RETURN"
;
case
SELECT
:
return
"select"
;
case
SELECT
:
return
"SELECT"
;
case
STRUCT
:
return
"struct"
;
case
STRUCT
:
return
"STRUCT"
;
case
SWITCH
:
return
"switch"
;
case
SWITCH
:
return
"SWITCH"
;
case
TRUE
:
return
"true"
;
case
TRUE
:
return
"TRUE"
;
case
TYPE
:
return
"type"
;
case
TYPE
:
return
"TYPE"
;
case
VAR
:
return
"var"
;
case
VAR
:
return
"VAR"
;
}
}
return
"???"
;
return
"???"
;
...
@@ -238,50 +239,104 @@ type Scanner struct {
...
@@ -238,50 +239,104 @@ type Scanner struct {
func
(
S
*
Scanner
)
Next
()
{
func
(
S
*
Scanner
)
Next
()
{
const
(
Bit1
=
7
;
Bitx
=
6
;
Bit2
=
5
;
Bit3
=
4
;
Bit4
=
3
;
T1
=
0x00
;
// (1 << (Bit1 + 1) - 1) ^ 0xFF; // 0000 0000
Tx
=
0x80
;
// (1 << (Bitx + 1) - 1) ^ 0xFF; // 1000 0000
T2
=
0xC0
;
// (1 << (Bit2 + 1) - 1) ^ 0xFF; // 1100 0000
T3
=
0xE0
;
// (1 << (Bit3 + 1) - 1) ^ 0xFF; // 1110 0000
T4
=
0xF0
;
// (1 << (Bit4 + 1) - 1) ^ 0xFF; // 1111 0000
Rune1
=
1
<<
(
Bit1
+
0
*
Bitx
)
-
1
;
// 0000 0000 0111 1111
Rune2
=
1
<<
(
Bit2
+
1
*
Bitx
)
-
1
;
// 0000 0111 1111 1111
Rune3
=
1
<<
(
Bit3
+
2
*
Bitx
)
-
1
;
// 1111 1111 1111 1111
Maskx
=
0x3F
;
// 1 << Bitx - 1; // 0011 1111
Testx
=
0xC0
;
// Maskx ^ 0xFF; // 1100 0000
Bad
=
0xFFFD
;
// Runeerror
);
src
:=
S
.
src
;
// TODO only needed because of 6g bug
src
:=
S
.
src
;
// TODO only needed because of 6g bug
if
S
.
pos
<
len
(
src
)
{
lim
:=
len
(
src
);
S
.
ch
=
int
(
S
.
src
[
S
.
pos
]);
pos
:=
S
.
pos
;
S
.
pos
++
;
if
(
S
.
ch
>=
128
)
{
// 1-byte sequence
panic
"UTF-8 not handled"
// 0000-007F => T1
if
pos
>=
lim
{
goto
eof
;
}
c0
:=
int
(
src
[
pos
+
0
]);
if
c0
<
Tx
{
S
.
ch
=
c0
;
S
.
pos
=
pos
+
1
;
return
;
}
}
}
else
{
S
.
ch
=
-
1
;
// 2-byte sequence
// 0080-07FF => T2 Tx
if
pos
+
1
>=
lim
{
goto
eof
;
}
c1
:=
int
(
src
[
pos
+
1
])
^
Tx
;
if
c1
&
Testx
!=
0
{
goto
bad
;
}
if
c0
<
T3
{
if
c0
<
T2
{
goto
bad
;
}
r
:=
(
c0
<<
Bitx
|
c1
)
&
Rune2
;
if
r
<=
Rune1
{
goto
bad
;
}
S
.
ch
=
r
;
S
.
pos
=
pos
+
2
;
return
;
}
// 3-byte encoding
// 0800-FFFF => T3 Tx Tx
if
pos
+
2
>=
lim
{
goto
eof
;
}
c2
:=
int
(
src
[
pos
+
2
])
^
Tx
;
if
c2
&
Testx
!=
0
{
goto
bad
;
}
if
c0
<
T4
{
r
:=
(((
c0
<<
Bitx
|
c1
)
<<
Bitx
)
|
c2
)
&
Rune3
;
if
r
<=
Rune2
{
goto
bad
;
}
S
.
ch
=
r
;
S
.
pos
=
pos
+
3
;
return
;
}
}
// bad encoding
bad
:
S
.
ch
=
Bad
;
S
.
pos
+=
1
;
return
;
// end of file
eof
:
S
.
ch
=
-
1
;
}
}
func
Init
()
{
func
Init
()
{
Keywords
=
new
(
map
[
string
]
int
);
Keywords
=
new
(
map
[
string
]
int
);
Keywords
[
"break"
]
=
BREAK
;
for
i
:=
KEYWORDS_BEG
;
i
<=
KEYWORDS_END
;
i
++
{
Keywords
[
"case"
]
=
CASE
;
Keywords
[
TokenName
(
i
)]
=
i
;
Keywords
[
"const"
]
=
CONST
;
}
Keywords
[
"continue"
]
=
CONTINUE
;
Keywords
[
"default"
]
=
DEFAULT
;
Keywords
[
"else"
]
=
ELSE
;
Keywords
[
"export"
]
=
EXPORT
;
Keywords
[
"fallthrough"
]
=
FALLTHROUGH
;
Keywords
[
"false"
]
=
FALSE
;
Keywords
[
"for"
]
=
FOR
;
Keywords
[
"func"
]
=
FUNC
;
Keywords
[
"go"
]
=
GO
;
Keywords
[
"goto"
]
=
GOTO
;
Keywords
[
"if"
]
=
IF
;
Keywords
[
"import"
]
=
IMPORT
;
Keywords
[
"interface"
]
=
INTERFACE
;
Keywords
[
"map"
]
=
MAP
;
Keywords
[
"new"
]
=
NEW
;
Keywords
[
"nil"
]
=
NIL
;
Keywords
[
"package"
]
=
PACKAGE
;
Keywords
[
"range"
]
=
RANGE
;
Keywords
[
"return"
]
=
RETURN
;
Keywords
[
"select"
]
=
SELECT
;
Keywords
[
"struct"
]
=
STRUCT
;
Keywords
[
"switch"
]
=
SWITCH
;
Keywords
[
"true"
]
=
TRUE
;
Keywords
[
"type"
]
=
TYPE
;
Keywords
[
"var"
]
=
VAR
;
}
}
...
@@ -552,7 +607,6 @@ func (S *Scanner) Scan () (tok, beg, end int) {
...
@@ -552,7 +607,6 @@ func (S *Scanner) Scan () (tok, beg, end int) {
case
'&'
:
tok
=
S
.
Select3
(
AND
,
AND_ASSIGN
,
'&'
,
CAND
);
case
'&'
:
tok
=
S
.
Select3
(
AND
,
AND_ASSIGN
,
'&'
,
CAND
);
case
'|'
:
tok
=
S
.
Select3
(
OR
,
OR_ASSIGN
,
'|'
,
COR
);
case
'|'
:
tok
=
S
.
Select3
(
OR
,
OR_ASSIGN
,
'|'
,
COR
);
default
:
tok
=
ILLEGAL
;
default
:
tok
=
ILLEGAL
;
}
}
}
}
...
...
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