diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-04-02 14:21:45 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-04-02 20:10:07 +0200 |
| commit | 3e679c51c03ac13a5b4b601873689925eda3cc16 (patch) | |
| tree | cc4d32d731ff4eca66ae2af36d3bd229b8f08a4d /pkg | |
| parent | 374050e90404a9eeea577d7c97fbc6ef0dacd478 (diff) | |
pkg/compiler: support non-zero terminated filenames
Now file names become:
string[filename]
with a possibility of using other string features:
stringnoz[filename]
string[filename, CONST_SIZE]
and filename is left as type alias as it is commonly used:
type filename string[filename]
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/compiler/check.go | 4 | ||||
| -rw-r--r-- | pkg/compiler/compiler.go | 7 | ||||
| -rw-r--r-- | pkg/compiler/types.go | 39 |
3 files changed, 27 insertions, 23 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 6d304d26b..906d7e0de 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -110,6 +110,10 @@ func (comp *compiler) checkNames() { comp.error(n.Pos, "string flags uses reserved name %v", name) continue } + if builtinStrFlags[name] != nil { + comp.error(n.Pos, "string flags conflicts with builtin flags", name) + continue + } if prev := comp.strFlags[name]; prev != nil { comp.error(n.Pos, "string flags %v redeclared, previously declared at %v", name, prev.Pos) diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index f1e39b269..809de5bd5 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -64,8 +64,11 @@ func Compile(desc *ast.Description, consts map[string]uint64, target *targets.Ta structNodes: make(map[*prog.StructDesc]*ast.Struct), structVarlen: make(map[string]bool), } - for name, typedef := range builtinTypedefs { - comp.typedefs[name] = typedef + for name, n := range builtinTypedefs { + comp.typedefs[name] = n + } + for name, n := range builtinStrFlags { + comp.strFlags[name] = n } comp.typecheck() // The subsequent, more complex, checks expect basic validity of the tree, diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 019b734dd..c6be0d8f6 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -261,26 +261,6 @@ var typeArgFlags = &typeArg{ }, } -var typeFilename = &typeDesc{ - Names: []string{"filename"}, - CantBeOpt: true, - OptArgs: 1, - Args: []namedArg{{"size", typeArgInt}}, - Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool { - return len(args) == 0 - }, - Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type { - base.TypeSize = 0 - if len(args) >= 1 { - base.TypeSize = args[0].Value - } - return &prog.BufferType{ - TypeCommon: base.TypeCommon, - Kind: prog.BufferFilename, - } - }, -} - var typeFileoff = &typeDesc{ Names: []string{"fileoff"}, CanBeArgRet: canBeArg, @@ -478,6 +458,18 @@ var typeString = &typeDesc{ return comp.stringSize(t, args) == 0 }, Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type { + if len(args) > 0 && args[0].Ident == "filename" { + base.TypeName = "filename" + base.TypeSize = 0 + if len(args) >= 2 { + base.TypeSize = args[1].Value + } + return &prog.BufferType{ + TypeCommon: base.TypeCommon, + Kind: prog.BufferFilename, + NoZ: t.Ident == stringnoz, + } + } subkind := "" if len(args) > 0 && args[0].Ident != "" { subkind = args[0].Ident @@ -729,6 +721,7 @@ var typeArgBase = namedArg{ var ( builtinTypes = make(map[string]*typeDesc) builtinTypedefs = make(map[string]*ast.TypeDef) + builtinStrFlags = make(map[string]*ast.StrFlags) // To avoid weird cases like ptr[in, in] and ptr[out, opt]. reservedName = map[string]bool{ @@ -745,6 +738,9 @@ type bool16 int16[0:1] type bool32 int32[0:1] type bool64 int64[0:1] type boolptr intptr[0:1] + +type filename string[filename] +filename = "", "." ` func init() { @@ -756,7 +752,6 @@ func init() { typeLen, typeConst, typeFlags, - typeFilename, typeFileoff, typeVMA, typeCsum, @@ -780,6 +775,8 @@ func init() { switch n := decl.(type) { case *ast.TypeDef: builtinTypedefs[n.Name.Name] = n + case *ast.StrFlags: + builtinStrFlags[n.Name.Name] = n case *ast.NewLine: default: panic(fmt.Sprintf("unexpected node in builtins: %#v", n)) |
