use constant names

This commit is contained in:
Dan Markham 2020-02-23 15:24:20 -08:00
parent 56342fda5f
commit 9793e421ce
No known key found for this signature in database
GPG Key ID: 80673ED3335C219F
2 changed files with 10 additions and 8 deletions

View File

@ -61,7 +61,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh
g.Printf("\nvar _%sValues = []%s{", typeName, typeName)
for _, values := range runs {
for _, value := range values {
g.Printf("\t%s, ", value.str)
g.Printf("\t%s, ", value.originalName)
}
}
g.Printf("}\n\n")
@ -98,8 +98,8 @@ func (g *Generator) printValueMap(runs [][]Value, typeName string, runsThreshold
}
for _, value := range values {
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
n += len(value.name)
}
}

View File

@ -508,6 +508,7 @@ func (g *Generator) format() []byte {
// Value represents a declared constant.
type Value struct {
originalName string // The name of the constant before transformation
name string // The name of the constant after transformation (i.e. camel case => snake case)
// The value is stored as a bit pattern alone. The boolean tells us
// whether to interpret it as an int64 or a uint64; the only place
@ -602,6 +603,7 @@ func (f *File) genDecl(node ast.Node) bool {
u64 = uint64(i64)
}
v := Value{
originalName: n.Name,
name: n.Name,
value: u64,
signed: info&types.IsUnsigned == 0,