mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Remove packageid
This commit is contained in:
1 parent
82a19afd4a
commit
6236e7205f
14 files changed
+87
-209
No files matched your search
@@ -250,25 +250,9 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pkgIDNode := (*a.PackageID)(nil)
|
||||
for _, f := range files {
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
if n.Kind() == a.KPackageID {
|
||||
pkgIDNode = n.AsPackageID()
|
||||
}
|
||||
}
|
||||
}
|
||||
if pkgIDNode == nil {
|
||||
return fmt.Errorf("missing packageid declaration")
|
||||
}
|
||||
pkgIDStr, ok := t.Unescape(pkgIDNode.ID().Str(&h.tm))
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid packageid declaration")
|
||||
}
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
fmt.Fprintf(out, "// Code generated by running \"wuffs gen\". DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(out, "packageid %q\n\n", pkgIDStr)
|
||||
|
||||
for _, f := range files {
|
||||
for _, n := range f.TopLevelDecls() {
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
- Changed the string messages for built-in status codes.
|
||||
- Changed `error "foo"` to `status "?foo"`.
|
||||
- Made the status type a `const char *`, not an `int32_t`.
|
||||
- Made a packageid declaration mandatory.
|
||||
- Disallowed certain packageid's like `base` or `config`.
|
||||
- Disallowed `__double_underscore` prefixed names.
|
||||
- Moved the base38 package from `lang/base38` to `lib/base38`.
|
||||
- Added a stand-alone `lib/interval` package.
|
||||
|
||||
+40
-62
@@ -47,7 +47,6 @@ const (
|
||||
KIf
|
||||
KIterate
|
||||
KJump
|
||||
KPackageID
|
||||
KRet
|
||||
KStatus
|
||||
KStruct
|
||||
@@ -67,26 +66,25 @@ func (k Kind) String() string {
|
||||
var kindStrings = [...]string{
|
||||
KInvalid: "KInvalid",
|
||||
|
||||
KArg: "KArg",
|
||||
KAssert: "KAssert",
|
||||
KAssign: "KAssign",
|
||||
KConst: "KConst",
|
||||
KExpr: "KExpr",
|
||||
KField: "KField",
|
||||
KFile: "KFile",
|
||||
KFunc: "KFunc",
|
||||
KIOBind: "KIOBind",
|
||||
KIf: "KIf",
|
||||
KIterate: "KIterate",
|
||||
KJump: "KJump",
|
||||
KPackageID: "KPackageID",
|
||||
KRet: "KRet",
|
||||
KStatus: "KStatus",
|
||||
KStruct: "KStruct",
|
||||
KTypeExpr: "KTypeExpr",
|
||||
KUse: "KUse",
|
||||
KVar: "KVar",
|
||||
KWhile: "KWhile",
|
||||
KArg: "KArg",
|
||||
KAssert: "KAssert",
|
||||
KAssign: "KAssign",
|
||||
KConst: "KConst",
|
||||
KExpr: "KExpr",
|
||||
KField: "KField",
|
||||
KFile: "KFile",
|
||||
KFunc: "KFunc",
|
||||
KIOBind: "KIOBind",
|
||||
KIf: "KIf",
|
||||
KIterate: "KIterate",
|
||||
KJump: "KJump",
|
||||
KRet: "KRet",
|
||||
KStatus: "KStatus",
|
||||
KStruct: "KStruct",
|
||||
KTypeExpr: "KTypeExpr",
|
||||
KUse: "KUse",
|
||||
KVar: "KVar",
|
||||
KWhile: "KWhile",
|
||||
}
|
||||
|
||||
type Flags uint32
|
||||
@@ -176,7 +174,6 @@ type Node struct {
|
||||
// If . . . If
|
||||
// Iterate unroll label length Iterate
|
||||
// Jump keyword label . Jump
|
||||
// PackageID . . lit(pkgID) PackageID
|
||||
// Ret keyword . . Ret
|
||||
// Status keyword pkg lit(message) Status
|
||||
// Struct . pkg name Struct
|
||||
@@ -203,27 +200,26 @@ func (n *Node) MType() *TypeExpr { return n.mType }
|
||||
func (n *Node) SetMBounds(x Bounds) { n.mBounds = x }
|
||||
func (n *Node) SetMType(x *TypeExpr) { n.mType = x }
|
||||
|
||||
func (n *Node) AsArg() *Arg { return (*Arg)(n) }
|
||||
func (n *Node) AsAssert() *Assert { return (*Assert)(n) }
|
||||
func (n *Node) AsAssign() *Assign { return (*Assign)(n) }
|
||||
func (n *Node) AsConst() *Const { return (*Const)(n) }
|
||||
func (n *Node) AsExpr() *Expr { return (*Expr)(n) }
|
||||
func (n *Node) AsField() *Field { return (*Field)(n) }
|
||||
func (n *Node) AsFile() *File { return (*File)(n) }
|
||||
func (n *Node) AsFunc() *Func { return (*Func)(n) }
|
||||
func (n *Node) AsIOBind() *IOBind { return (*IOBind)(n) }
|
||||
func (n *Node) AsIf() *If { return (*If)(n) }
|
||||
func (n *Node) AsIterate() *Iterate { return (*Iterate)(n) }
|
||||
func (n *Node) AsJump() *Jump { return (*Jump)(n) }
|
||||
func (n *Node) AsPackageID() *PackageID { return (*PackageID)(n) }
|
||||
func (n *Node) AsRaw() *Raw { return (*Raw)(n) }
|
||||
func (n *Node) AsRet() *Ret { return (*Ret)(n) }
|
||||
func (n *Node) AsStatus() *Status { return (*Status)(n) }
|
||||
func (n *Node) AsStruct() *Struct { return (*Struct)(n) }
|
||||
func (n *Node) AsTypeExpr() *TypeExpr { return (*TypeExpr)(n) }
|
||||
func (n *Node) AsUse() *Use { return (*Use)(n) }
|
||||
func (n *Node) AsVar() *Var { return (*Var)(n) }
|
||||
func (n *Node) AsWhile() *While { return (*While)(n) }
|
||||
func (n *Node) AsArg() *Arg { return (*Arg)(n) }
|
||||
func (n *Node) AsAssert() *Assert { return (*Assert)(n) }
|
||||
func (n *Node) AsAssign() *Assign { return (*Assign)(n) }
|
||||
func (n *Node) AsConst() *Const { return (*Const)(n) }
|
||||
func (n *Node) AsExpr() *Expr { return (*Expr)(n) }
|
||||
func (n *Node) AsField() *Field { return (*Field)(n) }
|
||||
func (n *Node) AsFile() *File { return (*File)(n) }
|
||||
func (n *Node) AsFunc() *Func { return (*Func)(n) }
|
||||
func (n *Node) AsIOBind() *IOBind { return (*IOBind)(n) }
|
||||
func (n *Node) AsIf() *If { return (*If)(n) }
|
||||
func (n *Node) AsIterate() *Iterate { return (*Iterate)(n) }
|
||||
func (n *Node) AsJump() *Jump { return (*Jump)(n) }
|
||||
func (n *Node) AsRaw() *Raw { return (*Raw)(n) }
|
||||
func (n *Node) AsRet() *Ret { return (*Ret)(n) }
|
||||
func (n *Node) AsStatus() *Status { return (*Status)(n) }
|
||||
func (n *Node) AsStruct() *Struct { return (*Struct)(n) }
|
||||
func (n *Node) AsTypeExpr() *TypeExpr { return (*TypeExpr)(n) }
|
||||
func (n *Node) AsUse() *Use { return (*Use)(n) }
|
||||
func (n *Node) AsVar() *Var { return (*Var)(n) }
|
||||
func (n *Node) AsWhile() *While { return (*While)(n) }
|
||||
|
||||
func (n *Node) Walk(f func(*Node) error) error {
|
||||
if n != nil {
|
||||
@@ -921,24 +917,6 @@ func NewStruct(flags Flags, filename string, line uint32, name t.ID, fields []*N
|
||||
}
|
||||
}
|
||||
|
||||
// PackageID is "packageid ID2":
|
||||
// - ID2: <string literal> package ID
|
||||
type PackageID Node
|
||||
|
||||
func (n *PackageID) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *PackageID) Filename() string { return n.filename }
|
||||
func (n *PackageID) Line() uint32 { return n.line }
|
||||
func (n *PackageID) ID() t.ID { return n.id2 }
|
||||
|
||||
func NewPackageID(filename string, line uint32, id t.ID) *PackageID {
|
||||
return &PackageID{
|
||||
kind: KPackageID,
|
||||
filename: filename,
|
||||
line: line,
|
||||
id2: id,
|
||||
}
|
||||
}
|
||||
|
||||
// Use is "use ID2":
|
||||
// - ID2: <string literal> package path
|
||||
type Use Node
|
||||
@@ -958,7 +936,7 @@ func NewUse(filename string, line uint32, path t.ID) *Use {
|
||||
}
|
||||
|
||||
// File is a file of source code:
|
||||
// - List0: <Const|Func|PackageID|Status|Struct|Use> top-level declarations
|
||||
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
|
||||
type File Node
|
||||
|
||||
func (n *File) AsNode() *Node { return (*Node)(n) }
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/google/wuffs/lang/builtin"
|
||||
"github.com/google/wuffs/lang/parse"
|
||||
"github.com/google/wuffs/lib/base38"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
@@ -87,7 +86,6 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
|
||||
tm: tm,
|
||||
resolveUse: resolveUse,
|
||||
reasonMap: rMap,
|
||||
packageID: base38.Max + 1,
|
||||
consts: map[t.QID]*a.Const{},
|
||||
funcs: map[t.QQID]*a.Func{},
|
||||
localVars: map[t.QQID]typeMap{},
|
||||
@@ -136,8 +134,6 @@ var phases = [...]struct {
|
||||
kind a.Kind
|
||||
check func(*Checker, *a.Node) error
|
||||
}{
|
||||
{a.KPackageID, (*Checker).checkPackageID},
|
||||
{a.KInvalid, (*Checker).checkPackageIDExists},
|
||||
{a.KUse, (*Checker).checkUse},
|
||||
{a.KStatus, (*Checker).checkStatus},
|
||||
{a.KConst, (*Checker).checkConst},
|
||||
@@ -161,9 +157,6 @@ type Checker struct {
|
||||
resolveUse func(usePath string) ([]byte, error)
|
||||
reasonMap reasonMap
|
||||
|
||||
packageID uint32
|
||||
otherPackageID *a.PackageID
|
||||
|
||||
consts map[t.QID]*a.Const
|
||||
funcs map[t.QQID]*a.Func
|
||||
localVars map[t.QQID]typeMap
|
||||
@@ -179,49 +172,6 @@ type Checker struct {
|
||||
unsortedStructs []*a.Struct
|
||||
}
|
||||
|
||||
func (c *Checker) PackageID() uint32 { return c.packageID }
|
||||
|
||||
func (c *Checker) checkPackageID(node *a.Node) error {
|
||||
n := node.AsPackageID()
|
||||
if c.otherPackageID != nil {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: multiple packageid declarations"),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
OtherFilename: c.otherPackageID.Filename(),
|
||||
OtherLine: c.otherPackageID.Line(),
|
||||
}
|
||||
}
|
||||
raw := n.ID().Str(c.tm)
|
||||
s, ok := t.Unescape(raw)
|
||||
if !ok {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: %q is not a valid packageid", raw),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
}
|
||||
u, ok := base38.Encode(s)
|
||||
if !ok || u == 0 {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: %q is not a valid packageid", s),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
}
|
||||
}
|
||||
c.packageID = u
|
||||
c.otherPackageID = n
|
||||
setPlaceholderMBoundsMType(n.AsNode())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checker) checkPackageIDExists(node *a.Node) error {
|
||||
if c.otherPackageID == nil {
|
||||
return fmt.Errorf("check: missing packageid declaration")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checker) checkUse(node *a.Node) error {
|
||||
usePath := node.AsUse().Path()
|
||||
filename, ok := t.Unescape(usePath.Str(c.tm))
|
||||
|
||||
@@ -59,8 +59,6 @@ func compareToWuffsfmt(tm *t.Map, tokens []t.Token, comments []string, src strin
|
||||
func TestCheck(tt *testing.T) {
|
||||
const filename = "test.wuffs"
|
||||
src := strings.TrimSpace(`
|
||||
packageid "test"
|
||||
|
||||
pri struct foo(
|
||||
i base.i32,
|
||||
)
|
||||
@@ -205,7 +203,7 @@ func TestConstValues(tt *testing.T) {
|
||||
|
||||
tm := &t.Map{}
|
||||
for s, wantInt64 := range testCases {
|
||||
src := "packageid \"test\"\npri func foo() {\n\t" + s + "\n}\n"
|
||||
src := "pri func foo() {\n\t" + s + "\n}\n"
|
||||
|
||||
tokens, _, err := t.Tokenize(tm, filename, []byte(src))
|
||||
if err != nil {
|
||||
|
||||
+2
-16
@@ -19,8 +19,6 @@ package parse
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/wuffs/lib/base38"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
@@ -102,7 +100,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
flags := a.Flags(0)
|
||||
line := p.src[0].Line
|
||||
switch k := p.peek1(); k {
|
||||
case t.IDPackageID, t.IDUse:
|
||||
case t.IDUse:
|
||||
p.src = p.src[1:]
|
||||
path := p.peek1()
|
||||
if !path.IsStrLiteral(p.tm) {
|
||||
@@ -115,19 +113,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
return nil, fmt.Errorf(`parse: expected (implicit) ";", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if k == t.IDPackageID {
|
||||
raw := path.Str(p.tm)
|
||||
s, ok := t.Unescape(raw)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`parse: %q is not a valid packageid`, raw)
|
||||
}
|
||||
if u, ok := base38.Encode(s); !ok || u == 0 {
|
||||
return nil, fmt.Errorf(`parse: %q is not a valid packageid`, s)
|
||||
}
|
||||
return a.NewPackageID(p.filename, line, path).AsNode(), nil
|
||||
} else {
|
||||
return a.NewUse(p.filename, line, path).AsNode(), nil
|
||||
}
|
||||
return a.NewUse(p.filename, line, path).AsNode(), nil
|
||||
|
||||
case t.IDPub:
|
||||
flags |= a.FlagsPublic
|
||||
|
||||
+44
-46
@@ -331,29 +331,28 @@ const (
|
||||
maxKeyword = 0x9F
|
||||
|
||||
// TODO: sort these by name, when the list has stabilized.
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDPackageID = ID(0x91)
|
||||
IDConst = ID(0x92)
|
||||
IDTry = ID(0x93)
|
||||
IDIterate = ID(0x94)
|
||||
IDYield = ID(0x95)
|
||||
IDIOBind = ID(0x96)
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDConst = ID(0x91)
|
||||
IDTry = ID(0x92)
|
||||
IDIterate = ID(0x93)
|
||||
IDYield = ID(0x94)
|
||||
IDIOBind = ID(0x95)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -619,29 +618,28 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDRef: "ref",
|
||||
IDDeref: "deref",
|
||||
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
|
||||
IDArray: "array",
|
||||
IDNptr: "nptr",
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "adl3"
|
||||
|
||||
// TODO: drop the '?' but still generate wuffs_adler32__hasher__initialize?
|
||||
pub struct hasher?(
|
||||
state base.u32,
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "crc3"
|
||||
|
||||
// TODO: drop the '?' but still generate wuffs_crc32__ieee_hasher__initialize?
|
||||
pub struct ieee_hasher?(
|
||||
state base.u32,
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "dflt"
|
||||
|
||||
pub status "?bad Huffman code (over-subscribed)"
|
||||
pub status "?bad Huffman code (under-subscribed)"
|
||||
pub status "?bad Huffman code length count"
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "gif "
|
||||
|
||||
use "std/lzw"
|
||||
|
||||
pub status "?bad block"
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "gzip"
|
||||
|
||||
use "std/crc32"
|
||||
use "std/deflate"
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "lzw "
|
||||
|
||||
pub status "?bad code"
|
||||
pub status "?cyclical prefix chain"
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
packageid "zlib"
|
||||
|
||||
use "std/adler32"
|
||||
use "std/deflate"
|
||||
|
||||
|
||||
Reference in new issue
Block a user