Commit e3fdcdfe authored by Robert Griesemer's avatar Robert Griesemer

- Ident node now takes a string Value instead of a []bytes

(this removes a lot of string() conversions down the road)
- a few minor adjustments

R=rsc
DELTA=11  (0 added, 0 deleted, 11 changed)
OCL=27029
CL=27038
parent 2d543d0c
...@@ -129,7 +129,7 @@ type ( ...@@ -129,7 +129,7 @@ type (
// An Ident node represents an identifier. // An Ident node represents an identifier.
Ident struct { Ident struct {
token.Position; // identifier position token.Position; // identifier position
Lit []byte; // identifier string (e.g. foobar) Value string; // identifier string (e.g. foobar)
}; };
// An Ellipsis node stands for the "..." type in a // An Ellipsis node stands for the "..." type in a
...@@ -142,25 +142,25 @@ type ( ...@@ -142,25 +142,25 @@ type (
// An IntLit node represents an integer literal. // An IntLit node represents an integer literal.
IntLit struct { IntLit struct {
token.Position; // int literal position token.Position; // int literal position
Lit []byte; // literal string; e.g. 42 or 0x7f Value []byte; // literal string; e.g. 42 or 0x7f
}; };
// A FloatLit node represents a floating-point literal. // A FloatLit node represents a floating-point literal.
FloatLit struct { FloatLit struct {
token.Position; // float literal position token.Position; // float literal position
Lit []byte; // literal string; e.g. 3.14 or 1e-9 Value []byte; // literal string; e.g. 3.14 or 1e-9
}; };
// A CharLit node represents a character literal. // A CharLit node represents a character literal.
CharLit struct { CharLit struct {
token.Position; // char literal position token.Position; // char literal position
Lit []byte; // literal string, including quotes; e.g. 'a' or '\x7f' Value []byte; // literal string, including quotes; e.g. 'a' or '\x7f'
}; };
// A StringLit node represents a string literal. // A StringLit node represents a string literal.
StringLit struct { StringLit struct {
token.Position; // string literal position token.Position; // string literal position
Lit []byte; // literal string, including quotes; e.g. "foo" or `\m\n\o` Value []byte; // literal string, including quotes; e.g. "foo" or `\m\n\o`
}; };
// A StringList node represents a sequence of adjacent string literals. // A StringList node represents a sequence of adjacent string literals.
...@@ -236,7 +236,7 @@ type ( ...@@ -236,7 +236,7 @@ type (
}; };
// A UnaryExpr node represents a unary expression. // A UnaryExpr node represents a unary expression.
// Unary "*" expressions are represented via DerefExpr nodes. // Unary "*" expressions are represented via StarExpr nodes.
// //
UnaryExpr struct { UnaryExpr struct {
token.Position; // position of Op token.Position; // position of Op
......
...@@ -229,12 +229,12 @@ func (p *parser) parseDeclaration() ast.Decl; ...@@ -229,12 +229,12 @@ func (p *parser) parseDeclaration() ast.Decl;
func (p *parser) parseIdent() *ast.Ident { func (p *parser) parseIdent() *ast.Ident {
if p.tok == token.IDENT { if p.tok == token.IDENT {
x := &ast.Ident{p.pos, p.lit}; x := &ast.Ident{p.pos, string(p.lit)};
p.next(); p.next();
return x; return x;
} }
p.expect(token.IDENT); // use expect() error handling p.expect(token.IDENT); // use expect() error handling
return &ast.Ident{p.pos, [0]byte{}}; return &ast.Ident{p.pos, ""};
} }
...@@ -360,7 +360,7 @@ func (p *parser) makeIdentList(list *vector.Vector) []*ast.Ident { ...@@ -360,7 +360,7 @@ func (p *parser) makeIdentList(list *vector.Vector) []*ast.Ident {
if !is_ident { if !is_ident {
pos := list.At(i).(ast.Expr).Pos(); pos := list.At(i).(ast.Expr).Pos();
p.error_expected(pos, "identifier"); p.error_expected(pos, "identifier");
idents[i] = &ast.Ident{pos, []byte{}}; idents[i] = &ast.Ident{pos, ""};
} }
idents[i] = ident; idents[i] = ident;
} }
...@@ -907,7 +907,7 @@ func (p *parser) parseSelectorOrTypeAssertion(x ast.Expr) ast.Expr { ...@@ -907,7 +907,7 @@ func (p *parser) parseSelectorOrTypeAssertion(x ast.Expr) ast.Expr {
var typ ast.Expr; var typ ast.Expr;
if p.tok == token.TYPE { if p.tok == token.TYPE {
// special case for type switch // special case for type switch
typ = &ast.Ident{p.pos, p.lit}; typ = &ast.Ident{p.pos, "type"};
p.next(); p.next();
} else { } else {
typ = p.parseType(); typ = p.parseType();
...@@ -1654,7 +1654,7 @@ func parseImportSpec(p *parser, doc ast.Comments) ast.Spec { ...@@ -1654,7 +1654,7 @@ func parseImportSpec(p *parser, doc ast.Comments) ast.Spec {
var ident *ast.Ident; var ident *ast.Ident;
if p.tok == token.PERIOD { if p.tok == token.PERIOD {
ident = &ast.Ident{p.pos, []byte{'.'}}; ident = &ast.Ident{p.pos, "."};
p.next(); p.next();
} else if p.tok == token.IDENT { } else if p.tok == token.IDENT {
ident = p.parseIdent(); ident = p.parseIdent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment