mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Re-introduce type/bounds checking to "puffs gen".
This rolls back some of:
f23a808 Remove some redundant cmd/puffs/gen.go code.
3258c1e Remove check.FlagsOnlyTypeCheck.
The language-specific code generators, such as puffs-gen-c, have to do
type and bounds checking anyway, to generate the right types and
function calls. Accordingly, I thought that the type and bounds checking
in the language-agnostic cmd/puffs/gen.go was redundant, and removed it.
However, puffs-gen-c just works with stdin and stdout, and the comments
have been stripped from its input, so it cannot print either the right
filename or right line number for any errors.
We therefore need to do type and bounds checking in cmd/puffs/gen.go
too, in order to produce actionable errors.
This commit is contained in:
1 parent
524d323992
commit
dc71a93dcf
1 file changed
+9
-3
+9
-3
@@ -14,6 +14,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/google/puffs/lang/ast"
|
||||
"github.com/google/puffs/lang/check"
|
||||
"github.com/google/puffs/lang/parse"
|
||||
"github.com/google/puffs/lang/render"
|
||||
"github.com/google/puffs/lang/token"
|
||||
@@ -71,6 +73,7 @@ func genDir(puffsRoot string, dirname string, filenames []string, langs []string
|
||||
// mtime is newer than all inputs and the puffs-gen-foo command.
|
||||
|
||||
tm := &token.Map{}
|
||||
files := []*ast.File(nil)
|
||||
buf := &bytes.Buffer{}
|
||||
for _, filename := range filenames {
|
||||
filename = filepath.Join(puffsRoot, filepath.FromSlash(dirname), filename)
|
||||
@@ -82,15 +85,18 @@ func genDir(puffsRoot string, dirname string, filenames []string, langs []string
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// We don't need the AST node to pretty-print, but it's worth rejecting
|
||||
// syntax errors early. This is just a parse, not a full type check.
|
||||
if _, err := parse.Parse(tm, filename, tokens); err != nil {
|
||||
if f, err := parse.Parse(tm, filename, tokens); err != nil {
|
||||
return err
|
||||
} else {
|
||||
files = append(files, f)
|
||||
}
|
||||
if err := render.Render(buf, tm, tokens, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := check.Check(tm, files...); err != nil {
|
||||
return err
|
||||
}
|
||||
combinedSrc := buf.Bytes()
|
||||
|
||||
packageName := path.Base(dirname)
|
||||
|
||||
Reference in new issue
Block a user