mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Add a genlinenum flag
This commit is contained in:
1 parent
dd94ad3821
commit
20c474b32a
4 files changed
+24
-13
No files matched your search
@@ -98,6 +98,7 @@ const (
|
||||
func Do(args []string) error {
|
||||
flags := flag.FlagSet{}
|
||||
cformatterFlag := flags.String("cformatter", cf.CformatterDefault, cf.CformatterUsage)
|
||||
genlinenumFlag := flags.Bool("genlinenum", cf.GenlinenumDefault, cf.GenlinenumUsage)
|
||||
|
||||
return generate.Do(&flags, args, func(pkgName string, tm *t.Map, c *check.Checker, files []*a.File) ([]byte, error) {
|
||||
if !cf.IsAlphaNumericIsh(*cformatterFlag) {
|
||||
@@ -139,11 +140,12 @@ func Do(args []string) error {
|
||||
|
||||
} else {
|
||||
g := &gen{
|
||||
pkgPrefix: "wuffs_" + pkgName + "__",
|
||||
pkgName: pkgName,
|
||||
tm: tm,
|
||||
checker: c,
|
||||
files: files,
|
||||
pkgPrefix: "wuffs_" + pkgName + "__",
|
||||
pkgName: pkgName,
|
||||
tm: tm,
|
||||
checker: c,
|
||||
files: files,
|
||||
genlinenum: *genlinenumFlag,
|
||||
}
|
||||
var err error
|
||||
unformatted, err = g.generate()
|
||||
@@ -310,6 +312,12 @@ type gen struct {
|
||||
checker *check.Checker
|
||||
files []*a.File
|
||||
|
||||
// genlinenum is whether to print "// foo.wuffs:123" comments in the
|
||||
// generated C code. This can be useful for debugging, although it is not
|
||||
// enabled by default as it can lead to many spurious changes in the
|
||||
// generated C code (due to line numbers changing) when editing Wuffs code.
|
||||
genlinenum bool
|
||||
|
||||
statusList []status
|
||||
statusMap map[t.QID]status
|
||||
structList []*a.Struct
|
||||
|
||||
@@ -22,12 +22,6 @@ import (
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
// genFilenameLineComments is whether to print "// foo.wuffs:123\n" comments in
|
||||
// the generated code. This can be useful for debugging, although it is not
|
||||
// enabled by default as it can lead to many spurious changes in the generated
|
||||
// C code (due to line numbers changing) when editing Wuffs code.
|
||||
const genFilenameLineComments = false
|
||||
|
||||
func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
if depth > a.MaxBodyDepth {
|
||||
return fmt.Errorf("body recursion depth too large")
|
||||
@@ -48,7 +42,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
defer b.writes("}\n")
|
||||
}
|
||||
|
||||
if genFilenameLineComments {
|
||||
if g.genlinenum {
|
||||
filename, line := n.AsRaw().FilenameLine()
|
||||
if i := strings.LastIndexByte(filename, '/'); i >= 0 {
|
||||
filename = filename[i+1:]
|
||||
|
||||
Reference in new issue
Block a user