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
ba556a88
Commit
ba556a88
authored
Jan 12, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- removed an unnecessary field from AST.Expr nodes
R=r OCL=22601 CL=22601
parent
0a0ee89f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
38 deletions
+38
-38
usr/gri/pretty/ast.go
usr/gri/pretty/ast.go
+8
-9
usr/gri/pretty/parser.go
usr/gri/pretty/parser.go
+22
-21
usr/gri/pretty/printer.go
usr/gri/pretty/printer.go
+8
-8
No files found.
usr/gri/pretty/ast.go
View file @
ba556a88
...
...
@@ -170,9 +170,6 @@ export type Expr struct {
Node
;
x
,
y
*
Expr
;
// binary (x, y) and unary (y) expressions
obj
*
Object
;
// TODO this one should go as well
t
*
Type
;
// type expressions, function literal types
}
...
...
@@ -198,9 +195,10 @@ export func NewExpr(pos, tok int, x, y *Expr) *Expr {
}
export
func
NewLit
(
pos
,
tok
int
,
obj
*
Object
)
*
Expr
{
// TODO probably don't need the tok parameter eventually
export
func
NewLit
(
tok
int
,
obj
*
Object
)
*
Expr
{
e
:=
new
(
Expr
);
e
.
pos
,
e
.
tok
,
e
.
obj
=
pos
,
tok
,
obj
;
e
.
pos
,
e
.
tok
,
e
.
obj
=
obj
.
pos
,
tok
,
obj
;
return
e
;
}
...
...
@@ -302,6 +300,7 @@ export type Type struct {
key
*
Type
;
// receiver type or map key
elt
*
Type
;
// array, map, channel or pointer element type, function result type
list
*
array
.
Array
;
end
int
;
// struct fields, interface methods, function parameters
scope
*
Scope
;
// struct fields, methods
}
...
...
@@ -340,10 +339,10 @@ func (t *Type) nfields() int {
// requires complete Type.pos access
export
func
NewTypeExpr
(
t
*
Type
)
*
Expr
{
e
:=
new
(
Expr
);
e
.
pos
,
e
.
tok
,
e
.
t
=
t
.
pos
,
Scanner
.
TYPE
,
t
;
return
e
;
export
func
NewTypeExpr
(
t
yp
*
Type
)
*
Expr
{
obj
:=
NewObject
(
typ
.
pos
,
TYPE
,
""
);
obj
.
typ
=
typ
;
return
NewLit
(
Scanner
.
TYPE
,
obj
)
;
}
...
...
usr/gri/pretty/parser.go
View file @
ba556a88
...
...
@@ -195,7 +195,7 @@ func (P *Parser) Declare(p *AST.Expr, kind int) {
func
ExprType
(
x
*
AST
.
Expr
)
*
AST
.
Type
{
var
t
*
AST
.
Type
;
if
x
.
tok
==
Scanner
.
TYPE
{
t
=
x
.
t
;
t
=
x
.
obj
.
typ
;
}
else
if
x
.
tok
==
Scanner
.
IDENT
{
// assume a type name
t
=
AST
.
NewType
(
x
.
pos
,
AST
.
TYPENAME
);
...
...
@@ -213,7 +213,7 @@ func (P *Parser) NoType(x *AST.Expr) *AST.Expr {
if
x
!=
nil
&&
x
.
tok
==
Scanner
.
TYPE
{
P
.
Error
(
x
.
pos
,
"expected expression, found type"
);
val
:=
AST
.
NewObject
(
x
.
pos
,
AST
.
NONE
,
"0"
);
x
=
AST
.
NewLit
(
x
.
pos
,
Scanner
.
INT
,
val
);
x
=
AST
.
NewLit
(
Scanner
.
INT
,
val
);
}
return
x
;
}
...
...
@@ -248,7 +248,8 @@ func (P *Parser) ParseIdent(scope *AST.Scope) *AST.Expr {
}
else
{
assert
(
obj
.
kind
!=
AST
.
NONE
);
}
x
=
AST
.
NewLit
(
P
.
pos
,
Scanner
.
IDENT
,
obj
);
x
=
AST
.
NewLit
(
Scanner
.
IDENT
,
obj
);
x
.
pos
=
P
.
pos
;
// override obj.pos (incorrect if object was looked up!)
if
P
.
verbose
{
P
.
PrintIndent
();
print
(
"Ident =
\"
"
,
P
.
val
,
"
\"\n
"
);
...
...
@@ -382,10 +383,7 @@ func (P *Parser) ParseChannelType() *AST.Type {
}
// TODO: The code below (ParseVarDecl, ParseVarDeclList) is all too
// complicated. There must be a better way to do this.
func
(
P
*
Parser
)
ParseVarDecl
(
expect_ident
bool
)
*
AST
.
Type
{
func
(
P
*
Parser
)
ParseVar
(
expect_ident
bool
)
*
AST
.
Type
{
t
:=
AST
.
BadType
;
if
expect_ident
{
x
:=
P
.
ParseIdent
(
nil
);
...
...
@@ -401,13 +399,14 @@ func (P *Parser) ParseVarDecl(expect_ident bool) *AST.Type {
}
func
(
P
*
Parser
)
ParseVar
Decl
List
(
list
*
array
.
Array
,
ellipsis_ok
bool
)
{
P
.
Trace
(
"Var
Decl
List"
);
func
(
P
*
Parser
)
ParseVarList
(
list
*
array
.
Array
,
ellipsis_ok
bool
)
{
P
.
Trace
(
"VarList"
);
// parse a list of types
// assume a list of types
// (a list of identifiers looks like a list of type names)
i0
:=
list
.
Len
();
for
{
list
.
Push
(
P
.
ParseVar
Decl
(
ellipsis_ok
/* param list */
&&
i0
>
0
));
list
.
Push
(
P
.
ParseVar
(
ellipsis_ok
/* param list */
&&
i0
>
0
));
if
P
.
tok
==
Scanner
.
COMMA
{
P
.
Next
();
}
else
{
...
...
@@ -415,6 +414,7 @@ func (P *Parser) ParseVarDeclList(list *array.Array, ellipsis_ok bool) {
}
}
// if we had a list of identifiers, it must be followed by a type
typ
:=
P
.
TryType
();
if
typ
==
nil
&&
P
.
tok
==
Scanner
.
ELLIPSIS
{
typ
=
AST
.
NewType
(
P
.
pos
,
AST
.
ELLIPSIS
);
...
...
@@ -460,10 +460,10 @@ func (P *Parser) ParseParameterList(ellipsis_ok bool) *array.Array {
P
.
Trace
(
"ParameterList"
);
list
:=
array
.
New
(
0
);
P
.
ParseVar
Decl
List
(
list
,
ellipsis_ok
);
P
.
ParseVarList
(
list
,
ellipsis_ok
);
for
P
.
tok
==
Scanner
.
COMMA
{
P
.
Next
();
P
.
ParseVar
Decl
List
(
list
,
ellipsis_ok
);
P
.
ParseVarList
(
list
,
ellipsis_ok
);
}
P
.
Ecart
();
...
...
@@ -623,7 +623,7 @@ func (P *Parser) ParseStructType() *AST.Type {
t
.
list
=
array
.
New
(
0
);
for
P
.
tok
!=
Scanner
.
RBRACE
&&
P
.
tok
!=
Scanner
.
EOF
{
P
.
ParseVar
Decl
List
(
t
.
list
,
false
);
P
.
ParseVarList
(
t
.
list
,
false
);
if
P
.
tok
==
Scanner
.
STRING
{
// ParseOperand takes care of string concatenation
t
.
list
.
Push
(
P
.
ParseOperand
());
...
...
@@ -758,9 +758,9 @@ func (P *Parser) ParseFunctionLit() *AST.Expr {
P
.
Trace
(
"FunctionLit"
);
val
:=
AST
.
NewObject
(
P
.
pos
,
AST
.
NONE
,
""
);
x
:=
AST
.
NewLit
(
P
.
pos
,
Scanner
.
FUNC
,
val
);
x
:=
AST
.
NewLit
(
Scanner
.
FUNC
,
val
);
P
.
Expect
(
Scanner
.
FUNC
);
x
.
t
=
P
.
ParseFunctionType
();
val
.
typ
=
P
.
ParseFunctionType
();
P
.
expr_lev
++
;
P
.
scope_lev
++
;
val
.
block
,
val
.
end
=
P
.
ParseBlock
();
...
...
@@ -813,7 +813,7 @@ func (P *Parser) ParseOperand() *AST.Expr {
case
Scanner
.
INT
,
Scanner
.
FLOAT
,
Scanner
.
STRING
:
val
:=
AST
.
NewObject
(
P
.
pos
,
AST
.
NONE
,
P
.
val
);
x
=
AST
.
NewLit
(
P
.
pos
,
P
.
tok
,
val
);
x
=
AST
.
NewLit
(
P
.
tok
,
val
);
P
.
Next
();
if
x
.
tok
==
Scanner
.
STRING
{
// TODO should remember the list instead of
...
...
@@ -852,7 +852,7 @@ func (P *Parser) ParseSelectorOrTypeGuard(x *AST.Expr) *AST.Expr {
}
else
{
P
.
Expect
(
Scanner
.
LPAREN
);
x
.
t
=
P
.
ParseType
(
);
x
.
y
=
AST
.
NewTypeExpr
(
P
.
ParseType
()
);
P
.
Expect
(
Scanner
.
RPAREN
);
}
...
...
@@ -966,7 +966,8 @@ func (P *Parser) ParseCompositeLit(t *AST.Type) *AST.Expr {
P
.
Trace
(
"CompositeLit"
);
x
:=
P
.
NewExpr
(
P
.
pos
,
Scanner
.
LBRACE
,
nil
,
nil
);
x
.
t
=
t
;
x
.
obj
=
AST
.
NewObject
(
t
.
pos
,
AST
.
TYPE
,
""
);
x
.
obj
.
typ
=
t
;
P
.
Expect
(
Scanner
.
LBRACE
);
if
P
.
tok
!=
Scanner
.
RBRACE
{
x
.
y
=
P
.
ParseCompositeElements
();
...
...
@@ -1022,7 +1023,7 @@ func (P *Parser) ParseUnaryExpr() *AST.Expr {
if
tok
==
Scanner
.
MUL
&&
y
.
tok
==
Scanner
.
TYPE
{
// pointer type
t
:=
AST
.
NewType
(
pos
,
AST
.
POINTER
);
t
.
elt
=
y
.
t
;
t
.
elt
=
y
.
obj
.
typ
;
x
=
AST
.
NewTypeExpr
(
t
);
}
else
{
x
=
P
.
NewExpr
(
pos
,
tok
,
nil
,
y
);
...
...
@@ -1480,7 +1481,7 @@ func (P *Parser) ParseImportSpec(pos int) *AST.Decl {
if
P
.
tok
==
Scanner
.
STRING
{
// TODO eventually the scanner should strip the quotes
val
:=
AST
.
NewObject
(
P
.
pos
,
AST
.
NONE
,
P
.
val
);
d
.
val
=
AST
.
NewLit
(
P
.
pos
,
Scanner
.
STRING
,
val
);
d
.
val
=
AST
.
NewLit
(
Scanner
.
STRING
,
val
);
P
.
Next
();
}
else
{
P
.
Expect
(
Scanner
.
STRING
);
// use Expect() error handling
...
...
usr/gri/pretty/printer.go
View file @
ba556a88
...
...
@@ -547,7 +547,7 @@ func (P *Printer) Expr1(x *AST.Expr, prec1 int) {
switch
x
.
tok
{
case
Scanner
.
TYPE
:
// type expr
P
.
Type
(
x
.
t
);
P
.
Type
(
x
.
obj
.
typ
);
case
Scanner
.
IDENT
:
P
.
HtmlIdentifier
(
x
);
...
...
@@ -559,7 +559,7 @@ func (P *Printer) Expr1(x *AST.Expr, prec1 int) {
case
Scanner
.
FUNC
:
// function literal
P
.
String
(
x
.
pos
,
"func"
);
P
.
Type
(
x
.
t
);
P
.
Type
(
x
.
obj
.
typ
);
P
.
Block
(
0
,
x
.
obj
.
block
,
x
.
obj
.
end
,
true
);
P
.
newlines
=
0
;
...
...
@@ -576,12 +576,12 @@ func (P *Printer) Expr1(x *AST.Expr, prec1 int) {
// selector or type guard
P
.
Expr1
(
x
.
x
,
Scanner
.
HighestPrec
);
P
.
String
(
x
.
pos
,
"."
);
if
x
.
y
!=
nil
{
P
.
Expr1
(
x
.
y
,
Scanner
.
HighestPrec
);
}
else
{
if
x
.
y
.
tok
==
Scanner
.
TYPE
{
P
.
String
(
0
,
"("
);
P
.
Type
(
x
.
t
);
P
.
Expr
(
x
.
y
);
P
.
String
(
0
,
")"
);
}
else
{
P
.
Expr1
(
x
.
y
,
Scanner
.
HighestPrec
);
}
case
Scanner
.
LBRACK
:
...
...
@@ -599,8 +599,8 @@ func (P *Printer) Expr1(x *AST.Expr, prec1 int) {
P
.
String
(
0
,
")"
);
case
Scanner
.
LBRACE
:
// composite
P
.
Type
(
x
.
t
);
// composite
literal
P
.
Type
(
x
.
obj
.
typ
);
P
.
String
(
x
.
pos
,
"{"
);
P
.
Expr
(
x
.
y
);
P
.
String
(
0
,
"}"
);
...
...
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