]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: fix EOF message on operand parsing errors.
authorTal Shprecher <tshprecher@gmail.com>
Sat, 20 Feb 2016 00:02:54 +0000 (16:02 -0800)
committerRob Pike <r@golang.org>
Thu, 25 Feb 2016 00:21:14 +0000 (00:21 +0000)
If the parsing of an operand completes but the parser thinks there
is more to read, return an "expected end of operand" error message
instead of "expected EOF." This also removes extra "asm: " prefixes
in error strings since "asm: " is already set as the global log
prefix.

Fixes #14071

Change-Id: I7d621c1aea529a0eca3bcba032359bd25b3e1080
Reviewed-on: https://go-review.googlesource.com/19731
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/asm/internal/asm/parse.go
src/cmd/asm/internal/asm/pseudo_test.go
src/cmd/asm/internal/lex/input.go
src/cmd/asm/internal/lex/lex.go
src/cmd/asm/main.go

index 4258c5ce263f0f58ed9d9035410b24343bdae40e..6c324ce3af7ed568d42a428c53b5ff0fc255ad6f 100644 (file)
@@ -297,7 +297,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
                        p.errorf("illegal use of register list")
                }
                p.registerList(a)
-               p.expect(scanner.EOF)
+               p.expectOperandEnd()
                return true
        }
 
@@ -331,7 +331,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
                        }
                }
                // fmt.Printf("REG %s\n", obj.Dconv(&emptyProg, 0, a))
-               p.expect(scanner.EOF)
+               p.expectOperandEnd()
                return true
        }
 
@@ -363,7 +363,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
                        a.Type = obj.TYPE_FCONST
                        a.Val = p.floatExpr()
                        // fmt.Printf("FCONST %s\n", obj.Dconv(&emptyProg, 0, a))
-                       p.expect(scanner.EOF)
+                       p.expectOperandEnd()
                        return true
                }
                if p.have(scanner.String) {
@@ -378,7 +378,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
                        a.Type = obj.TYPE_SCONST
                        a.Val = str
                        // fmt.Printf("SCONST %s\n", obj.Dconv(&emptyProg, 0, a))
-                       p.expect(scanner.EOF)
+                       p.expectOperandEnd()
                        return true
                }
                a.Offset = int64(p.expr())
@@ -392,7 +392,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
                                a.Type = obj.TYPE_MEM
                        }
                        // fmt.Printf("CONST %d %s\n", a.Offset, obj.Dconv(&emptyProg, 0, a))
-                       p.expect(scanner.EOF)
+                       p.expectOperandEnd()
                        return true
                }
                // fmt.Printf("offset %d \n", a.Offset)
@@ -402,7 +402,7 @@ func (p *Parser) operand(a *obj.Addr) bool {
        p.registerIndirect(a, prefix)
        // fmt.Printf("DONE %s\n", p.arch.Dconv(&emptyProg, 0, a))
 
-       p.expect(scanner.EOF)
+       p.expectOperandEnd()
        return true
 }
 
@@ -983,14 +983,19 @@ func (p *Parser) more() bool {
 
 // get verifies that the next item has the expected type and returns it.
 func (p *Parser) get(expected lex.ScanToken) lex.Token {
-       p.expect(expected)
+       p.expect(expected, expected.String())
        return p.next()
 }
 
+// expectOperandEnd verifies that the parsing state is properly at the end of an operand.
+func (p *Parser) expectOperandEnd() {
+       p.expect(scanner.EOF, "end of operand")
+}
+
 // expect verifies that the next item has the expected type. It does not consume it.
-func (p *Parser) expect(expected lex.ScanToken) {
-       if p.peek() != expected {
-               p.errorf("expected %s, found %s", expected, p.next())
+func (p *Parser) expect(expectedToken lex.ScanToken, expectedMessage string) {
+       if p.peek() != expectedToken {
+               p.errorf("expected %s, found %s", expectedMessage, p.next())
        }
 }
 
index ee13b724ebecfe34567287d0204dfea2895a306d..2e6d6c8154f327225cceb9610945102ac671cfef 100644 (file)
@@ -35,8 +35,8 @@ func TestErroneous(t *testing.T) {
                {"TEXT", "%", "expect two or three operands for TEXT"},
                {"TEXT", "1, 1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
                {"TEXT", "$\"foo\", 0, $1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
-               {"TEXT", "$0É:0, 0, $1", "expected EOF, found É"},   // Issue #12467.
-               {"TEXT", "$:0:(SB, 0, $1", "expected '(', found 0"}, // Issue 12468.
+               {"TEXT", "$0É:0, 0, $1", "expected end of operand, found É"}, // Issue #12467.
+               {"TEXT", "$:0:(SB, 0, $1", "expected '(', found 0"},          // Issue 12468.
                {"FUNCDATA", "", "expect two operands for FUNCDATA"},
                {"FUNCDATA", "(SB ", "expect two operands for FUNCDATA"},
                {"DATA", "", "expect two operands for DATA"},
index 33b9d8adeaf439c009bcd4689e887ceb914241c3..4855daa892ff72b88e3e835ba22e1154865d2e4c 100644 (file)
@@ -30,7 +30,7 @@ type Input struct {
        peekText        string
 }
 
-// NewInput returns a
+// NewInput returns an Input from the given path.
 func NewInput(name string) *Input {
        return &Input{
                // include directories: look in source dir, then -I directories.
index 6fce55f7f4041f4349b71b0d57533be5f71f7d3e..81339059b197654a333d198a438c8522e2d2f12e 100644 (file)
@@ -77,7 +77,7 @@ func NewLexer(name string, ctxt *obj.Link) TokenReader {
        input := NewInput(name)
        fd, err := os.Open(name)
        if err != nil {
-               log.Fatalf("asm: %s\n", err)
+               log.Fatalf("%s\n", err)
        }
        input.Push(NewTokenizer(name, fd, fd))
        return input
index f48050c137871c7e73afab908a182dcad5d846fc..4e450bec9893cfcb5b5fcb831d3d428bf65e8796 100644 (file)
@@ -26,7 +26,7 @@ func main() {
 
        architecture := arch.Set(GOARCH)
        if architecture == nil {
-               log.Fatalf("asm: unrecognized architecture %s", GOARCH)
+               log.Fatalf("unrecognized architecture %s", GOARCH)
        }
 
        flags.Parse()
@@ -66,7 +66,7 @@ func main() {
                obj.Writeobjdirect(ctxt, output)
        }
        if !ok || diag {
-               log.Printf("asm: assembly of %s failed", flag.Arg(0))
+               log.Printf("assembly of %s failed", flag.Arg(0))
                os.Remove(*flags.OutputFile)
                os.Exit(1)
        }