mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Add a lang/builtin package.
This commit is contained in:
1 parent
010c4db54f
commit
2efdf5fab6
5 files changed
+80
-67
No files matched your search
+2
-14
@@ -11,6 +11,7 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/google/puffs/lang/base38"
|
||||
"github.com/google/puffs/lang/builtin"
|
||||
|
||||
a "github.com/google/puffs/lang/ast"
|
||||
t "github.com/google/puffs/lang/token"
|
||||
@@ -47,13 +48,6 @@ func (e *Error) Error() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func trimQuotes(s string) string {
|
||||
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
|
||||
return s[1 : len(s)-1]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// typeExprFoo is an *ast.Node MType (implicit type).
|
||||
var (
|
||||
typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
|
||||
@@ -95,12 +89,6 @@ type Struct struct {
|
||||
Struct *a.Struct
|
||||
}
|
||||
|
||||
var builtInStatuses = map[string]t.ID{
|
||||
// TODO: fill in the rest of the built in statuses.
|
||||
"short read": t.IDSuspension,
|
||||
"short write": t.IDSuspension,
|
||||
}
|
||||
|
||||
func Check(tm *t.Map, files ...*a.File) (*Checker, error) {
|
||||
for _, f := range files {
|
||||
if f == nil {
|
||||
@@ -242,7 +230,7 @@ func (c *Checker) checkStatus(node *a.Node) error {
|
||||
id := n.Message()
|
||||
if other, ok := c.statuses[id]; ok {
|
||||
return &Error{
|
||||
Err: fmt.Errorf("check: duplicate status %q", trimQuotes(id.String(c.tm))),
|
||||
Err: fmt.Errorf("check: duplicate status %q", builtin.TrimQuotes(id.String(c.tm))),
|
||||
Filename: n.Filename(),
|
||||
Line: n.Line(),
|
||||
OtherFilename: other.Status.Filename(),
|
||||
|
||||
+5
-2
@@ -7,6 +7,8 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/google/puffs/lang/builtin"
|
||||
|
||||
a "github.com/google/puffs/lang/ast"
|
||||
t "github.com/google/puffs/lang/token"
|
||||
)
|
||||
@@ -124,11 +126,12 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
if s, ok := q.c.statuses[n.Message()]; ok {
|
||||
sk = s.Status.Keyword()
|
||||
} else {
|
||||
msg := trimQuotes(n.Message().String(q.tm))
|
||||
sk, ok = builtInStatuses[msg]
|
||||
msg := builtin.TrimQuotes(n.Message().String(q.tm))
|
||||
z, ok := builtin.StatusMap[msg]
|
||||
if !ok {
|
||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||
}
|
||||
sk = z.Keyword
|
||||
}
|
||||
if nk != sk {
|
||||
return fmt.Errorf("check: return statement says %q but declaration says %q",
|
||||
|
||||
Reference in new issue
Block a user