From 162bd26be4e47d89f305435f7a1917b023138ed6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 1 Apr 2019 12:46:10 +0200 Subject: pkg/compiler: make buffer alias to ptr[array[int8]] Ptr type has special handling of direction (pointers are always input). But buffer type missed this special case all the time. Make buffer less special by aliasing to the ptr[array[int8]] type. As the result buffer type can't have optional trailing "opt" attribute because we don't have such support for templates yet. Change such cases to use ptr type directly. Fixes #1097 --- pkg/compiler/testdata/all.txt | 2 ++ pkg/compiler/testdata/errors.txt | 6 +++--- pkg/compiler/types.go | 22 ++-------------------- 3 files changed, 7 insertions(+), 23 deletions(-) (limited to 'pkg') diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index 6863e5836..49cc1ffb9 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -10,6 +10,8 @@ foo$5(a int8['a':'z']) foo$6(a int8[-20:-10]) foo$7(a int8[-20:20]) foo$8(a ptr[in, strings]) +foo$9(a ptr[out, ptr[in, string]]) +foo$10(a ptr[out, buffer[in]]) resource r0[intptr] diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt index 55ec40901..e95c3be7d 100644 --- a/pkg/compiler/testdata/errors.txt +++ b/pkg/compiler/testdata/errors.txt @@ -71,9 +71,9 @@ resource r9["foo"] ### unexpected string "foo", expect type foo$7(a r0, a1 r2[opt]) foo$8(a fileoff[a, b, c]) ### wrong number of arguments for type fileoff, expect no arguments foo$9(a buffer[inout]) -foo$10(a buffer[intout]) ### unexpected value intout for direction argument of buffer type, expect [in out inout] -foo$11(a buffer["in"]) ### unexpected string "in" for direction argument of buffer type, expect [in out inout] -foo$12(a buffer[10]) ### unexpected int 10 for direction argument of buffer type, expect [in out inout] +foo$10(a buffer[intout]) ### unexpected value intout for direction argument of ptr type, expect [in out inout] +foo$11(a buffer["in"]) ### unexpected string "in" for direction argument of ptr type, expect [in out inout] +foo$12(a buffer[10]) ### unexpected int 10 for direction argument of ptr type, expect [in out inout] foo$13(a int32[2:3]) foo$14(a int32[2:2]) foo$16(a int32[3]) diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 8b10e2717..1a230458d 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -440,25 +440,6 @@ func genTextType(t *ast.Type) prog.TextKind { } } -var typeBuffer = &typeDesc{ - Names: []string{"buffer"}, - CanBeArgRet: canBeArg, - Args: []namedArg{{Name: "direction", Type: typeArgDir}}, - Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type { - base.TypeSize = comp.ptrSize - common := genCommon("", "", 0, genDir(args[0]), false) - // BufferBlobRand is always varlen. - common.IsVarlen = true - return &prog.PtrType{ - TypeCommon: base.TypeCommon, - Type: &prog.BufferType{ - TypeCommon: common, - Kind: prog.BufferBlobRand, - }, - } - }, -} - const ( stringnoz = "stringnoz" ) @@ -862,6 +843,8 @@ type boolptr intptr[0:1] type filename string[filename] filename = "", "." +type buffer[DIR] ptr[DIR, array[int8]] + type optional[T] [ val T void void @@ -882,7 +865,6 @@ func init() { typeCsum, typeProc, typeText, - typeBuffer, typeString, typeFmt, } -- cgit mrf-deployment