From 8d52a6eab62c38d433428506228da10420920f4e Mon Sep 17 00:00:00 2001 From: chai2010 Date: Sun, 6 May 2018 22:21:41 +0800 Subject: [PATCH] cmd/asm: allow methods implemented in assembly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. allow methods implemented in assembly, identifier name support "main.(*SomeType).method" format 2. if the symbol starts with type··x, rewrite it as type·""·x fixes #4978 --- src/cmd/asm/internal/lex/lex.go | 9 ++++++++- src/cmd/asm/internal/lex/tokenizer.go | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cmd/asm/internal/lex/lex.go b/src/cmd/asm/internal/lex/lex.go index f1f7da79112e35..4483f1a1f3439d 100644 --- a/src/cmd/asm/internal/lex/lex.go +++ b/src/cmd/asm/internal/lex/lex.go @@ -107,9 +107,16 @@ func Make(token ScanToken, text string) Token { if token == scanner.Ident && strings.HasPrefix(text, "\u00B7") { text = `""` + text } - // Substitute the substitutes for . and /. + // If the symbol starts with type··x, rewrite it as type·""·x + if token == scanner.Ident && strings.HasPrefix(text, "type\u00B7\u00B7") { + text = "type\u00B7" + `""` + text[len("type\u00B7"):] + } + // Substitute the substitutes for '.', '/', '*', '(' and ')'. text = strings.Replace(text, "\u00B7", ".", -1) text = strings.Replace(text, "\u2215", "/", -1) + text = strings.Replace(text, "\u2217", "*", -1) + text = strings.Replace(text, "\uFF08", "(", -1) + text = strings.Replace(text, "\uFF09", ")", -1) return Token{ScanToken: token, text: text} } diff --git a/src/cmd/asm/internal/lex/tokenizer.go b/src/cmd/asm/internal/lex/tokenizer.go index aef9ea8636844a..05effbea4988a0 100644 --- a/src/cmd/asm/internal/lex/tokenizer.go +++ b/src/cmd/asm/internal/lex/tokenizer.go @@ -61,6 +61,12 @@ func isIdentRune(ch rune, i int) bool { return true case '\u2215': // Represents the slash in runtime/debug.setGCPercent. U+2215 '∕' division slash return true + case '\u2217': // Represents the asterisk in main.(*SomeType).method. U+2217 '∗' asterisk + return true + case '\uFF08': // Represents the left parentheses in main.(*SomeType).method. U+FF08 '(' left parentheses + return true + case '\uFF09': // Represents the right parentheses in main.(*SomeType).method. U+FF09 ')' right parentheses + return true } // Digits are OK only after the first character. return i > 0 && unicode.IsDigit(ch)