Add wuffs_foo__bar__initialize methods

This commit is contained in:
Nigel Tao committed 2019-02-09 12:54:02 +11:00
1 parent 10ead58e2e
commit 8794a586ac
10 files changed
+348 -103

No files matched your search

+3 -1
View File
@@ -138,7 +138,9 @@ func (c *Checker) parseBuiltInFuncs(ss []string, generic bool) (map[t.QQID]*a.Fu
}
}
}
file, err := parse.Parse(c.tm, filename, tokens, nil)
file, err := parse.Parse(c.tm, filename, tokens, &parse.Options{
AllowBuiltInNames: true,
})
if err != nil {
return nil, fmt.Errorf("check: parsing %q: could not parse built-in funcs: %v", s, err)
}
+1 -1
View File
@@ -90,7 +90,7 @@ func checkPackageName(s string) string {
// Blacklist certain package names.
switch s {
case "base", "base_private", "base_private_header", "base_public", "base_public_header",
"config", "implementation", "include_guard", "version":
"config", "implementation", "include_guard", "initialize", "version":
return ""
}
return s
+8
View File
@@ -24,6 +24,7 @@ import (
)
type Options struct {
AllowBuiltInNames bool
AllowDoubleUnderscoreNames bool
}
@@ -156,6 +157,13 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
if err != nil {
return nil, err
}
if !p.opts.AllowBuiltInNames {
switch id1 {
case t.IDInitialize, t.IDReset:
return nil, fmt.Errorf(`parse: cannot have a method named %q at %s:%d`,
id1.Str(p.tm), p.filename, p.line())
}
}
// TODO: should we require id0 != 0? In other words, always methods
// (attached to receivers) and never free standing functions?
if !p.opts.AllowDoubleUnderscoreNames && isDoubleUnderscore(p.tm.ByID(id1)) {
+8 -6
View File
@@ -578,9 +578,10 @@ const (
// -------- 0x200 block.
IDReset = ID(0x200)
IDSet = ID(0x201)
IDUnroll = ID(0x202)
IDInitialize = ID(0x200)
IDReset = ID(0x201)
IDSet = ID(0x202)
IDUnroll = ID(0x203)
// TODO: range/rect methods like intersection and contains?
@@ -906,9 +907,10 @@ var builtInsByID = [nBuiltInIDs]string{
// -------- 0x200 block.
IDReset: "reset",
IDSet: "set",
IDUnroll: "unroll",
IDInitialize: "initialize",
IDReset: "reset",
IDSet: "set",
IDUnroll: "unroll",
IDHighBits: "high_bits",
IDLowBits: "low_bits",