[dev.cc] cmd/asm: fix macro definition bug in the lexer

Because text/scanner hides the spaces, the lexer treated
	#define A(x)
and
	#define A (x)
the same, but they are not: the first is an argument with macros, the
second is a simple one-word macro whose definition contains parentheses.
Fix this by noticing the relative column number as we move from A to (.
Hacky but simple.

Also add a helper to recognize the peculiar ARM shifted register operators.

Change-Id: I2cad22f5f1e11d8dad40ad13955793d178afb3ae
Reviewed-on: https://go-review.googlesource.com/4872
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Rob Pike 2015-02-13 16:55:33 -08:00
parent 7fbfbca2c4
commit ae2b145da2
6 changed files with 40 additions and 1 deletions

View file

@ -203,12 +203,21 @@ func (in *Input) defineMacro(name string, args []string, tokens []Token) {
// The argument list is nil for no parens on the definition; otherwise a list of
// formal argument names.
func (in *Input) macroDefinition(name string) ([]string, []Token) {
prevCol := in.Stack.Col()
tok := in.Stack.Next()
if tok == '\n' || tok == scanner.EOF {
in.Error("no definition for macro:", name)
}
var args []string
if tok == '(' {
// The C preprocessor treats
// #define A(x)
// and
// #define A (x)
// distinctly: the first is a macro with arguments, the second without.
// Distinguish these cases using the column number, since we don't
// see the space itself. Note that text/scanner reports the position at the
// end of the token. It's where you are now, and you just read this token.
if tok == '(' && in.Stack.Col() == prevCol+1 {
// Macro has arguments. Scan list of formals.
acceptArg := true
args = []string{} // Zero length but not nil.