Refactor generated code

This commit is contained in:
Masaaki Goshima 2020-12-30 16:09:12 +09:00
parent 1bb6fd5c21
commit a2f709e756
2 changed files with 57 additions and 29797 deletions

View File

@ -106,8 +106,12 @@ const (
) )
func (t opType) String() string { func (t opType) String() string {
if int(t) >= {{ .OpLen }} {
return t.toNotIndent().String() + "Indent"
}
switch t { switch t {
{{- range $type := .OpTypes }} {{- range $type := .OpNotIndentTypes }}
case op{{ $type.Op }}: case op{{ $type.Op }}:
return "{{ $type.Op }}" return "{{ $type.Op }}"
{{- end }} {{- end }}
@ -116,8 +120,12 @@ func (t opType) String() string {
} }
func (t opType) codeType() codeType { func (t opType) codeType() codeType {
if int(t) >= {{ .OpLen }} {
return t.toNotIndent().codeType()
}
switch t { switch t {
{{- range $type := .OpTypes }} {{- range $type := .OpNotIndentTypes }}
case op{{ $type.Op }}: case op{{ $type.Op }}:
return code{{ $type.Code }} return code{{ $type.Code }}
{{- end }} {{- end }}
@ -125,19 +133,27 @@ func (t opType) codeType() codeType {
return codeOp return codeOp
} }
func (t opType) toIndent() opType { func (t opType) toNotIndent() opType {
switch t { if int(t) >= {{ .OpLen }} {
{{- range $type := .OpTypes }} return opType(int(t) - {{ .OpLen }})
case op{{ $type.Op }}:
return op{{ call $type.Indent }}
{{- end }}
} }
return t return t
} }
func (t opType) toIndent() opType {
if int(t) >= {{ .OpLen }} {
return t
}
return opType(int(t) + {{ .OpLen }})
}
func (t opType) toEscaped() opType { func (t opType) toEscaped() opType {
if int(t) >= {{ .OpLen }} {
return opType(int(t.toNotIndent().toEscaped()) + {{ .OpLen }})
}
switch t { switch t {
{{- range $type := .OpTypes }} {{- range $type := .OpNotIndentTypes }}
{{- if $type.IsEscaped }} {{- if $type.IsEscaped }}
case op{{ $type.Op }}: case op{{ $type.Op }}:
return op{{ call $type.Escaped }} return op{{ call $type.Escaped }}
@ -581,11 +597,17 @@ func (t opType) fieldToStringTagField() opType {
} }
var b bytes.Buffer var b bytes.Buffer
if err := tmpl.Execute(&b, struct { if err := tmpl.Execute(&b, struct {
CodeTypes []string CodeTypes []string
OpTypes []opType OpTypes []opType
OpNotIndentTypes []opType
OpLen int
OpIndentLen int
}{ }{
CodeTypes: codeTypes, CodeTypes: codeTypes,
OpTypes: append(opTypes, indentOpTypes...), OpTypes: append(opTypes, indentOpTypes...),
OpNotIndentTypes: opTypes,
OpLen: len(opTypes),
OpIndentLen: len(indentOpTypes),
}); err != nil { }); err != nil {
return err return err
} }

File diff suppressed because it is too large Load Diff