diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-23 11:05:51 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-23 11:05:51 +0100 |
| commit | 14d1e424b6a582d021c73c88e1f0c5f0962ecc9d (patch) | |
| tree | 0fdc71b6e0de2576ae330f145a51f9c016ad81a2 /pkg/ast | |
| parent | de3e24c4b6cd0136618ce74eb025a15d4834c082 (diff) | |
pkg/compiler: allow use of empty strings
This comes up in several contexts in netfilter.
Diffstat (limited to 'pkg/ast')
| -rw-r--r-- | pkg/ast/ast.go | 9 | ||||
| -rw-r--r-- | pkg/ast/clone.go | 1 | ||||
| -rw-r--r-- | pkg/ast/format.go | 2 | ||||
| -rw-r--r-- | pkg/ast/parser.go | 1 | ||||
| -rw-r--r-- | pkg/ast/scanner.go | 6 | ||||
| -rw-r--r-- | pkg/ast/testdata/all.txt | 4 |
6 files changed, 10 insertions, 13 deletions
diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 08703ba33..f7d5b8b32 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -185,10 +185,11 @@ func (n *Int) Info() (Pos, string, string) { type Type struct { Pos Pos // Only one of Value, Ident, String is filled. - Value uint64 - ValueHex bool - Ident string - String string + Value uint64 + ValueHex bool + Ident string + String string + HasString bool // Part after COLON (for ranges and bitfields). HasColon bool Pos2 Pos diff --git a/pkg/ast/clone.go b/pkg/ast/clone.go index b915c1f33..b754b7650 100644 --- a/pkg/ast/clone.go +++ b/pkg/ast/clone.go @@ -182,6 +182,7 @@ func (n *Type) Clone() Node { ValueHex: n.ValueHex, Ident: n.Ident, String: n.String, + HasString: n.HasString, HasColon: n.HasColon, Pos2: n.Pos2, Value2: n.Value2, diff --git a/pkg/ast/format.go b/pkg/ast/format.go index c1dd3a624..a7e0f568f 100644 --- a/pkg/ast/format.go +++ b/pkg/ast/format.go @@ -152,7 +152,7 @@ func fmtType(t *Type) string { switch { case t.Ident != "": v = t.Ident - case t.String != "": + case t.HasString: v = fmt.Sprintf("\"%v\"", t.String) default: v = fmtIntValue(t.Value, t.ValueHex) diff --git a/pkg/ast/parser.go b/pkg/ast/parser.go index bd5650ad5..a7cfdbf02 100644 --- a/pkg/ast/parser.go +++ b/pkg/ast/parser.go @@ -419,6 +419,7 @@ func (p *parser) parseType() *Type { arg.Ident = p.lit case tokString: arg.String = p.lit + arg.HasString = true default: p.expect(tokInt, tokIdent, tokString) } diff --git a/pkg/ast/scanner.go b/pkg/ast/scanner.go index bd2171506..5ad5e5808 100644 --- a/pkg/ast/scanner.go +++ b/pkg/ast/scanner.go @@ -177,12 +177,6 @@ func (s *scanner) Scan() (tok token, lit string, pos Pos) { break } } - if lit == "" { - // Currently unsupported because with the current Type representation - // it would not be possible to understand if it is an empty string - // or a 0 integer. - s.Error(pos, "empty string literals are not supported") - } s.next() case s.ch >= '0' && s.ch <= '9': tok = tokInt diff --git a/pkg/ast/testdata/all.txt b/pkg/ast/testdata/all.txt index d4452b34f..ede11a88a 100644 --- a/pkg/ast/testdata/all.txt +++ b/pkg/ast/testdata/all.txt @@ -25,10 +25,10 @@ define FOO `bar ### C expression is not terminated foo(x int32[1:2:3, opt]) ### unexpected ':', expecting ']' s0 { - f0 string[""] ### empty string literals are not supported + f0 string[""] } -sf0 = "", "1" ### empty string literals are not supported +sf0 = "", "1" include <linux/foo.h> include "linux/foo.h" |
