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
96c20204
Commit
96c20204
authored
Jan 20, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- updated pretty (removed "export")
R=r OCL=23134 CL=23134
parent
839a6846
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
113 deletions
+33
-113
ast.go
usr/gri/pretty/ast.go
+3
-4
compilation.go
usr/gri/pretty/compilation.go
+1
-2
parser.go
usr/gri/pretty/parser.go
+22
-89
pretty.go
usr/gri/pretty/pretty.go
+1
-2
printer.go
usr/gri/pretty/printer.go
+0
-8
scanner.go
usr/gri/pretty/scanner.go
+3
-5
test.sh
usr/gri/pretty/test.sh
+3
-2
typechecker.go
usr/gri/pretty/typechecker.go
+0
-1
No files found.
usr/gri/pretty/ast.go
View file @
96c20204
...
...
@@ -387,7 +387,6 @@ var BadStat = NewStat(0, Scanner.ILLEGAL);
type
Decl
struct
{
Node
;
Exported
bool
;
Ident
*
Expr
;
// nil for ()-style declarations
Typ
*
Type
;
Val
*
Expr
;
...
...
@@ -397,14 +396,14 @@ type Decl struct {
}
func
NewDecl
(
pos
,
tok
int
,
exported
bool
)
*
Decl
{
func
NewDecl
(
pos
,
tok
int
)
*
Decl
{
d
:=
new
(
Decl
);
d
.
Pos
,
d
.
Tok
,
d
.
Exported
=
pos
,
tok
,
exported
;
d
.
Pos
,
d
.
Tok
=
pos
,
tok
;
return
d
;
}
var
BadDecl
=
NewDecl
(
0
,
Scanner
.
ILLEGAL
,
false
);
var
BadDecl
=
NewDecl
(
0
,
Scanner
.
ILLEGAL
);
// ----------------------------------------------------------------------------
...
...
usr/gri/pretty/compilation.go
View file @
96c20204
...
...
@@ -30,7 +30,6 @@ type Flags struct {
Columns
bool
;
Testmode
bool
;
Tokenchan
bool
;
Naming
bool
;
}
...
...
@@ -136,7 +135,7 @@ func Compile(src_file string, flags *Flags) (*AST.Program, int) {
}
var
parser
Parser
.
Parser
;
parser
.
Open
(
flags
.
Verbose
,
flags
.
Sixg
,
flags
.
Deps
,
flags
.
Naming
,
&
scanner
,
tstream
);
parser
.
Open
(
flags
.
Verbose
,
flags
.
Sixg
,
flags
.
Deps
,
&
scanner
,
tstream
);
prog
:=
parser
.
ParseProgram
();
...
...
usr/gri/pretty/parser.go
View file @
96c20204
...
...
@@ -13,7 +13,7 @@ import (
type
Parser
struct
{
// Tracing/debugging
verbose
,
sixg
,
deps
,
naming
bool
;
verbose
,
sixg
,
deps
bool
;
indent
uint
;
// Scanner
...
...
@@ -109,11 +109,10 @@ func (P *Parser) Next() {
}
func
(
P
*
Parser
)
Open
(
verbose
,
sixg
,
deps
,
naming
bool
,
scanner
*
Scanner
.
Scanner
,
tokchan
<-
chan
*
Scanner
.
Token
)
{
func
(
P
*
Parser
)
Open
(
verbose
,
sixg
,
deps
bool
,
scanner
*
Scanner
.
Scanner
,
tokchan
<-
chan
*
Scanner
.
Token
)
{
P
.
verbose
=
verbose
;
P
.
sixg
=
sixg
;
P
.
deps
=
deps
;
P
.
naming
=
naming
;
P
.
indent
=
0
;
P
.
scanner
=
scanner
;
...
...
@@ -192,33 +191,6 @@ func (P *Parser) Declare(p *AST.Expr, kind int) {
}
func
(
P
*
Parser
)
VerifyExport1
(
p
*
AST
.
Expr
,
exported
bool
)
{
obj
:=
p
.
Obj
;
if
exported
{
if
!
obj
.
IsExported
()
{
P
.
Error
(
obj
.
Pos
,
`"`
+
obj
.
Ident
+
`" should be uppercase`
);
}
}
else
if
P
.
scope_lev
==
0
{
if
obj
.
IsExported
()
{
P
.
Error
(
obj
.
Pos
,
`"`
+
obj
.
Ident
+
`" should be lowercase`
);
}
}
}
func
(
P
*
Parser
)
VerifyExport
(
p
*
AST
.
Expr
,
exported
bool
)
{
if
!
P
.
naming
{
return
;
}
for
p
.
Tok
==
Scanner
.
COMMA
{
P
.
VerifyExport1
(
p
.
X
,
exported
);
p
=
p
.
Y
;
}
P
.
VerifyExport1
(
p
,
exported
);
}
// ----------------------------------------------------------------------------
// AST support
...
...
@@ -1500,7 +1472,7 @@ func (P *Parser) ParseStatement() *AST.Stat {
func
(
P
*
Parser
)
ParseImportSpec
(
pos
int
)
*
AST
.
Decl
{
P
.
Trace
(
"ImportSpec"
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
IMPORT
,
false
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
IMPORT
);
if
P
.
tok
==
Scanner
.
PERIOD
{
P
.
Error
(
P
.
pos
,
`"import ." not yet handled properly`
);
P
.
Next
();
...
...
@@ -1526,10 +1498,10 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
}
func
(
P
*
Parser
)
ParseConstSpec
(
exported
bool
,
pos
int
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseConstSpec
(
pos
int
)
*
AST
.
Decl
{
P
.
Trace
(
"ConstSpec"
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
CONST
,
exported
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
CONST
);
d
.
Ident
=
P
.
ParseIdentList
();
d
.
Typ
=
P
.
TryType
();
if
P
.
tok
==
Scanner
.
ASSIGN
{
...
...
@@ -1538,32 +1510,29 @@ func (P *Parser) ParseConstSpec(exported bool, pos int) *AST.Decl {
}
P
.
Declare
(
d
.
Ident
,
AST
.
CONST
);
P
.
VerifyExport
(
d
.
Ident
,
exported
);
P
.
Ecart
();
return
d
;
}
func
(
P
*
Parser
)
ParseTypeSpec
(
exported
bool
,
pos
int
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseTypeSpec
(
pos
int
)
*
AST
.
Decl
{
P
.
Trace
(
"TypeSpec"
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
TYPE
,
exported
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
TYPE
);
d
.
Ident
=
P
.
ParseIdent
(
nil
);
d
.
Typ
=
P
.
ParseType
();
P
.
opt_semi
=
true
;
P
.
VerifyExport
(
d
.
Ident
,
exported
);
P
.
Ecart
();
return
d
;
}
func
(
P
*
Parser
)
ParseVarSpec
(
exported
bool
,
pos
int
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseVarSpec
(
pos
int
)
*
AST
.
Decl
{
P
.
Trace
(
"VarSpec"
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
VAR
,
exported
);
d
:=
AST
.
NewDecl
(
pos
,
Scanner
.
VAR
);
d
.
Ident
=
P
.
ParseIdentList
();
if
P
.
tok
==
Scanner
.
ASSIGN
{
P
.
Next
();
...
...
@@ -1577,7 +1546,6 @@ func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl {
}
P
.
Declare
(
d
.
Ident
,
AST
.
VAR
);
P
.
VerifyExport
(
d
.
Ident
,
exported
);
P
.
Ecart
();
return
d
;
...
...
@@ -1585,19 +1553,19 @@ func (P *Parser) ParseVarSpec(exported bool, pos int) *AST.Decl {
// TODO replace this by using function pointers derived from methods
func
(
P
*
Parser
)
ParseSpec
(
exported
bool
,
pos
int
,
keyword
int
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseSpec
(
pos
int
,
keyword
int
)
*
AST
.
Decl
{
switch
keyword
{
case
Scanner
.
IMPORT
:
return
P
.
ParseImportSpec
(
pos
);
case
Scanner
.
CONST
:
return
P
.
ParseConstSpec
(
exported
,
pos
);
case
Scanner
.
TYPE
:
return
P
.
ParseTypeSpec
(
exported
,
pos
);
case
Scanner
.
VAR
:
return
P
.
ParseVarSpec
(
exported
,
pos
);
case
Scanner
.
CONST
:
return
P
.
ParseConstSpec
(
pos
);
case
Scanner
.
TYPE
:
return
P
.
ParseTypeSpec
(
pos
);
case
Scanner
.
VAR
:
return
P
.
ParseVarSpec
(
pos
);
}
panic
(
"UNREACHABLE"
);
return
nil
;
}
func
(
P
*
Parser
)
ParseDecl
(
exported
bool
,
keyword
int
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseDecl
(
keyword
int
)
*
AST
.
Decl
{
P
.
Trace
(
"Decl"
);
d
:=
AST
.
BadDecl
;
...
...
@@ -1605,10 +1573,10 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
P
.
Expect
(
keyword
);
if
P
.
tok
==
Scanner
.
LPAREN
{
P
.
Next
();
d
=
AST
.
NewDecl
(
pos
,
keyword
,
exported
);
d
=
AST
.
NewDecl
(
pos
,
keyword
);
d
.
List
=
array
.
New
(
0
);
for
P
.
tok
!=
Scanner
.
RPAREN
&&
P
.
tok
!=
Scanner
.
EOF
{
d
.
List
.
Push
(
P
.
ParseSpec
(
exported
,
pos
,
keyword
));
d
.
List
.
Push
(
P
.
ParseSpec
(
pos
,
keyword
));
if
P
.
tok
==
Scanner
.
SEMICOLON
{
P
.
Next
();
}
else
{
...
...
@@ -1620,7 +1588,7 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
P
.
opt_semi
=
true
;
}
else
{
d
=
P
.
ParseSpec
(
exported
,
pos
,
keyword
);
d
=
P
.
ParseSpec
(
pos
,
keyword
);
}
P
.
Ecart
();
...
...
@@ -1637,10 +1605,10 @@ func (P *Parser) ParseDecl(exported bool, keyword int) *AST.Decl {
// func (recv) ident (params) type
// func (recv) ident (params) (results)
func
(
P
*
Parser
)
ParseFunctionDecl
(
exported
bool
)
*
AST
.
Decl
{
func
(
P
*
Parser
)
ParseFunctionDecl
()
*
AST
.
Decl
{
P
.
Trace
(
"FunctionDecl"
);
d
:=
AST
.
NewDecl
(
P
.
pos
,
Scanner
.
FUNC
,
exported
);
d
:=
AST
.
NewDecl
(
P
.
pos
,
Scanner
.
FUNC
);
P
.
Expect
(
Scanner
.
FUNC
);
var
recv
*
AST
.
Type
;
...
...
@@ -1662,21 +1630,6 @@ func (P *Parser) ParseFunctionDecl(exported bool) *AST.Decl {
P
.
scope_lev
--
;
}
if
recv
==
nil
||
exported
{
P
.
VerifyExport
(
d
.
Ident
,
exported
);
}
P
.
Ecart
();
return
d
;
}
func
(
P
*
Parser
)
ParseExportDecl
()
*
AST
.
Decl
{
P
.
Trace
(
"ExportDecl"
);
d
:=
AST
.
NewDecl
(
P
.
pos
,
Scanner
.
EXPORT
,
false
);
d
.
Ident
=
P
.
ParseIdentList
();
P
.
Ecart
();
return
d
;
}
...
...
@@ -1687,36 +1640,16 @@ func (P *Parser) ParseDeclaration() *AST.Decl {
indent
:=
P
.
indent
;
d
:=
AST
.
BadDecl
;
exported
:=
false
;
// TODO don't use bool flag for export
if
P
.
tok
==
Scanner
.
EXPORT
||
P
.
tok
==
Scanner
.
PACKAGE
{
if
P
.
scope_lev
==
0
{
exported
=
true
;
}
else
{
P
.
Error
(
P
.
pos
,
"local declarations cannot be exported"
);
}
P
.
Next
();
}
switch
P
.
tok
{
case
Scanner
.
CONST
,
Scanner
.
TYPE
,
Scanner
.
VAR
:
d
=
P
.
ParseDecl
(
exported
,
P
.
tok
);
d
=
P
.
ParseDecl
(
P
.
tok
);
case
Scanner
.
FUNC
:
d
=
P
.
ParseFunctionDecl
(
exported
);
case
Scanner
.
EXPORT
:
if
exported
{
P
.
Error
(
P
.
pos
,
"cannot mark export declaration for export"
);
}
P
.
Next
();
d
=
P
.
ParseExportDecl
();
d
=
P
.
ParseFunctionDecl
();
default
:
if
exported
&&
(
P
.
tok
==
Scanner
.
IDENT
||
P
.
tok
==
Scanner
.
LPAREN
)
{
d
=
P
.
ParseExportDecl
();
}
else
{
P
.
Error
(
P
.
pos
,
"declaration expected"
);
P
.
Next
();
// make progress
}
}
if
indent
!=
P
.
indent
{
panic
(
"imbalanced tracing code (Declaration)"
);
...
...
@@ -1741,7 +1674,7 @@ func (P *Parser) ParseProgram() *AST.Program {
{
P
.
OpenScope
();
p
.
Decls
=
array
.
New
(
0
);
for
P
.
tok
==
Scanner
.
IMPORT
{
p
.
Decls
.
Push
(
P
.
ParseDecl
(
false
,
Scanner
.
IMPORT
));
p
.
Decls
.
Push
(
P
.
ParseDecl
(
Scanner
.
IMPORT
));
P
.
OptSemicolon
();
}
if
!
P
.
deps
{
...
...
usr/gri/pretty/pretty.go
View file @
96c20204
...
...
@@ -25,7 +25,6 @@ func init() {
Flag
.
BoolVar
(
&
flags
.
Columns
,
"columns"
,
Platform
.
USER
==
"gri"
,
"print column info in error messages"
);
Flag
.
BoolVar
(
&
flags
.
Testmode
,
"t"
,
false
,
"test mode: interprets /* ERROR */ and /* SYNC */ comments"
);
Flag
.
BoolVar
(
&
flags
.
Tokenchan
,
"token_chan"
,
false
,
"use token channel for scanner-parser connection"
);
Flag
.
BoolVar
(
&
flags
.
Naming
,
"naming"
,
false
,
"verify export naming scheme"
);
}
...
...
@@ -55,7 +54,7 @@ func main() {
if
nerrors
>
0
{
return
;
}
if
!
flags
.
Naming
&&
!
*
silent
&&
!
flags
.
Testmode
{
if
!*
silent
&&
!
flags
.
Testmode
{
Printer
.
Print
(
prog
);
}
}
...
...
usr/gri/pretty/printer.go
View file @
96c20204
...
...
@@ -791,10 +791,6 @@ func (P *Printer) Stat(s *AST.Stat) {
func
(
P
*
Printer
)
Declaration
(
d
*
AST
.
Decl
,
parenthesized
bool
)
{
if
!
parenthesized
{
if
d
.
Exported
{
P
.
String
(
d
.
Pos
,
"export"
);
P
.
separator
=
blank
;
}
P
.
Token
(
d
.
Pos
,
d
.
Tok
);
P
.
separator
=
blank
;
}
...
...
@@ -827,10 +823,6 @@ func (P *Printer) Declaration(d *AST.Decl, parenthesized bool) {
P
.
Expr
(
d
.
Val
);
P
.
separator
=
semicolon
;
case
Scanner
.
EXPORT
:
P
.
Expr
(
d
.
Ident
);
P
.
separator
=
semicolon
;
case
Scanner
.
TYPE
:
P
.
Expr
(
d
.
Ident
);
P
.
separator
=
blank
;
// TODO switch to tab? (but indentation problem with structs)
...
...
usr/gri/pretty/scanner.go
View file @
96c20204
...
...
@@ -76,7 +76,7 @@ const (
PERIOD
;
// keywords
Keywords_beg
;
// do not export eventually
keywords_beg
;
BREAK
;
CASE
;
CHAN
;
...
...
@@ -85,7 +85,6 @@ const (
DEFAULT
;
ELSE
;
EXPORT
;
FALLTHROUGH
;
FOR
;
...
...
@@ -106,7 +105,7 @@ const (
SWITCH
;
TYPE
;
VAR
;
Keywords_end
;
// do not export eventually
keywords_end
;
// AST use only
EXPRSTAT
;
...
...
@@ -187,7 +186,6 @@ func TokenString(tok int) string {
case
DEFAULT
:
return
"default"
;
case
ELSE
:
return
"else"
;
case
EXPORT
:
return
"export"
;
case
FALLTHROUGH
:
return
"fallthrough"
;
case
FOR
:
return
"for"
;
...
...
@@ -249,7 +247,7 @@ var keywords map [string] int;
func
init
()
{
keywords
=
make
(
map
[
string
]
int
);
for
i
:=
Keywords_beg
+
1
;
i
<
K
eywords_end
;
i
++
{
for
i
:=
keywords_beg
+
1
;
i
<
k
eywords_end
;
i
++
{
keywords
[
TokenString
(
i
)]
=
i
;
}
}
...
...
usr/gri/pretty/test.sh
View file @
96c20204
...
...
@@ -24,8 +24,9 @@ apply1() {
#echo $1 $2
case
`
basename
$F
`
in
# files with errors (skip them)
method1.go
|
selftest1.go
|
func3.go
|
bug014.go
|
bug029.go
|
bug032.go
|
bug050.go
|
\
bug068.go
|
bug088.go
|
bug083.go
|
bug106.go
|
bug125.go
|
bug126.go
)
;;
method1.go
|
selftest1.go
|
func3.go
|
\
bug014.go
|
bug025.go
|
bug029.go
|
bug032.go
|
bug050.go
|
bug068.go
|
\
bug088.go
|
bug083.go
|
bug106.go
|
bug125.go
|
bug126.go
)
;;
*
)
$1
$2
;
count
$F
;;
esac
}
...
...
usr/gri/pretty/typechecker.go
View file @
96c20204
...
...
@@ -64,7 +64,6 @@ func (s *state) CheckDeclaration(d *AST.Decl) {
// single declaration
switch
d
.
Tok
{
case
Scanner
.
IMPORT
:
case
Scanner
.
EXPORT
:
case
Scanner
.
CONST
:
case
Scanner
.
VAR
:
case
Scanner
.
TYPE
:
...
...
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