Fix error by linter

This commit is contained in:
Masaaki Goshima 2021-11-28 02:48:01 +09:00
parent b5e1478450
commit ea19d1161a
No known key found for this signature in database
GPG Key ID: 6A53785055537153
3 changed files with 77 additions and 79 deletions

View File

@ -109,10 +109,9 @@ func (c *UintCode) ToOpcode(ctx *compileContext) Opcodes {
} }
type FloatCode struct { type FloatCode struct {
typ *runtime.Type typ *runtime.Type
bitSize uint8 bitSize uint8
isString bool isPtr bool
isPtr bool
} }
func (c *FloatCode) Kind() CodeKind { func (c *FloatCode) Kind() CodeKind {
@ -142,9 +141,8 @@ func (c *FloatCode) ToOpcode(ctx *compileContext) Opcodes {
} }
type StringCode struct { type StringCode struct {
typ *runtime.Type typ *runtime.Type
isString bool isPtr bool
isPtr bool
} }
func (c *StringCode) Kind() CodeKind { func (c *StringCode) Kind() CodeKind {
@ -152,16 +150,16 @@ func (c *StringCode) Kind() CodeKind {
} }
func (c *StringCode) ToOpcode(ctx *compileContext) Opcodes { func (c *StringCode) ToOpcode(ctx *compileContext) Opcodes {
isJsonNumberType := c.typ == runtime.Type2RType(jsonNumberType) isJSONNumberType := c.typ == runtime.Type2RType(jsonNumberType)
var code *Opcode var code *Opcode
if c.isPtr { if c.isPtr {
if isJsonNumberType { if isJSONNumberType {
code = newOpCode(ctx, c.typ, OpNumberPtr) code = newOpCode(ctx, c.typ, OpNumberPtr)
} else { } else {
code = newOpCode(ctx, c.typ, OpStringPtr) code = newOpCode(ctx, c.typ, OpStringPtr)
} }
} else { } else {
if isJsonNumberType { if isJSONNumberType {
code = newOpCode(ctx, c.typ, OpNumber) code = newOpCode(ctx, c.typ, OpNumber)
} else { } else {
code = newOpCode(ctx, c.typ, OpString) code = newOpCode(ctx, c.typ, OpString)
@ -172,9 +170,8 @@ func (c *StringCode) ToOpcode(ctx *compileContext) Opcodes {
} }
type BoolCode struct { type BoolCode struct {
typ *runtime.Type typ *runtime.Type
isString bool isPtr bool
isPtr bool
} }
func (c *BoolCode) Kind() CodeKind { func (c *BoolCode) Kind() CodeKind {
@ -337,12 +334,11 @@ func (c *MapCode) ToOpcode(ctx *compileContext) Opcodes {
type StructCode struct { type StructCode struct {
typ *runtime.Type typ *runtime.Type
isPtr bool
fields []*StructFieldCode fields []*StructFieldCode
isPtr bool
disableIndirectConversion bool disableIndirectConversion bool
isIndirect bool isIndirect bool
isRecursive bool isRecursive bool
recursiveCodes Opcodes
} }
func (c *StructCode) Kind() CodeKind { func (c *StructCode) Kind() CodeKind {
@ -362,7 +358,7 @@ func (c *StructCode) lastFieldCode(field *StructFieldCode, firstField *Opcode) *
func (c *StructCode) lastAnonymousFieldCode(firstField *Opcode) *Opcode { func (c *StructCode) lastAnonymousFieldCode(firstField *Opcode) *Opcode {
// firstField is special StructHead operation for anonymous structure. // firstField is special StructHead operation for anonymous structure.
// So, StructHead's next operation is truely struct head operation. // So, StructHead's next operation is truly struct head operation.
lastField := firstField.Next lastField := firstField.Next
for lastField.NextField != nil { for lastField.NextField != nil {
lastField = lastField.NextField lastField = lastField.NextField

View File

@ -248,102 +248,167 @@ func (c *Compiler) typeToCodeWithPtr(typ *runtime.Type, isPtr bool) (Code, error
const intSize = 32 << (^uint(0) >> 63) const intSize = 32 << (^uint(0) >> 63)
//nolint:unparam
func (c *Compiler) intCode(typ *runtime.Type, isPtr bool) (*IntCode, error) { func (c *Compiler) intCode(typ *runtime.Type, isPtr bool) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: intSize, isPtr: isPtr}, nil return &IntCode{typ: typ, bitSize: intSize, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) int8Code(typ *runtime.Type, isPtr bool) (*IntCode, error) { func (c *Compiler) int8Code(typ *runtime.Type, isPtr bool) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 8, isPtr: isPtr}, nil return &IntCode{typ: typ, bitSize: 8, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) int16Code(typ *runtime.Type, isPtr bool) (*IntCode, error) { func (c *Compiler) int16Code(typ *runtime.Type, isPtr bool) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 16, isPtr: isPtr}, nil return &IntCode{typ: typ, bitSize: 16, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) int32Code(typ *runtime.Type, isPtr bool) (*IntCode, error) { func (c *Compiler) int32Code(typ *runtime.Type, isPtr bool) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil return &IntCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) int64Code(typ *runtime.Type, isPtr bool) (*IntCode, error) { func (c *Compiler) int64Code(typ *runtime.Type, isPtr bool) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil return &IntCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) uintCode(typ *runtime.Type, isPtr bool) (*UintCode, error) { func (c *Compiler) uintCode(typ *runtime.Type, isPtr bool) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: intSize, isPtr: isPtr}, nil return &UintCode{typ: typ, bitSize: intSize, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) uint8Code(typ *runtime.Type, isPtr bool) (*UintCode, error) { func (c *Compiler) uint8Code(typ *runtime.Type, isPtr bool) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 8, isPtr: isPtr}, nil return &UintCode{typ: typ, bitSize: 8, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) uint16Code(typ *runtime.Type, isPtr bool) (*UintCode, error) { func (c *Compiler) uint16Code(typ *runtime.Type, isPtr bool) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 16, isPtr: isPtr}, nil return &UintCode{typ: typ, bitSize: 16, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) uint32Code(typ *runtime.Type, isPtr bool) (*UintCode, error) { func (c *Compiler) uint32Code(typ *runtime.Type, isPtr bool) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil return &UintCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) uint64Code(typ *runtime.Type, isPtr bool) (*UintCode, error) { func (c *Compiler) uint64Code(typ *runtime.Type, isPtr bool) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil return &UintCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) float32Code(typ *runtime.Type, isPtr bool) (*FloatCode, error) { func (c *Compiler) float32Code(typ *runtime.Type, isPtr bool) (*FloatCode, error) {
return &FloatCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil return &FloatCode{typ: typ, bitSize: 32, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) float64Code(typ *runtime.Type, isPtr bool) (*FloatCode, error) { func (c *Compiler) float64Code(typ *runtime.Type, isPtr bool) (*FloatCode, error) {
return &FloatCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil return &FloatCode{typ: typ, bitSize: 64, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) stringCode(typ *runtime.Type, isPtr bool) (*StringCode, error) { func (c *Compiler) stringCode(typ *runtime.Type, isPtr bool) (*StringCode, error) {
return &StringCode{typ: typ, isPtr: isPtr}, nil return &StringCode{typ: typ, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) boolCode(typ *runtime.Type, isPtr bool) (*BoolCode, error) { func (c *Compiler) boolCode(typ *runtime.Type, isPtr bool) (*BoolCode, error) {
return &BoolCode{typ: typ, isPtr: isPtr}, nil return &BoolCode{typ: typ, isPtr: isPtr}, nil
} }
//nolint:unparam
func (c *Compiler) intStringCode(typ *runtime.Type) (*IntCode, error) { func (c *Compiler) intStringCode(typ *runtime.Type) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: intSize, isString: true}, nil return &IntCode{typ: typ, bitSize: intSize, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) int8StringCode(typ *runtime.Type) (*IntCode, error) { func (c *Compiler) int8StringCode(typ *runtime.Type) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 8, isString: true}, nil return &IntCode{typ: typ, bitSize: 8, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) int16StringCode(typ *runtime.Type) (*IntCode, error) { func (c *Compiler) int16StringCode(typ *runtime.Type) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 16, isString: true}, nil return &IntCode{typ: typ, bitSize: 16, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) int32StringCode(typ *runtime.Type) (*IntCode, error) { func (c *Compiler) int32StringCode(typ *runtime.Type) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 32, isString: true}, nil return &IntCode{typ: typ, bitSize: 32, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) int64StringCode(typ *runtime.Type) (*IntCode, error) { func (c *Compiler) int64StringCode(typ *runtime.Type) (*IntCode, error) {
return &IntCode{typ: typ, bitSize: 64, isString: true}, nil return &IntCode{typ: typ, bitSize: 64, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) uintStringCode(typ *runtime.Type) (*UintCode, error) { func (c *Compiler) uintStringCode(typ *runtime.Type) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: intSize, isString: true}, nil return &UintCode{typ: typ, bitSize: intSize, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) uint8StringCode(typ *runtime.Type) (*UintCode, error) { func (c *Compiler) uint8StringCode(typ *runtime.Type) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 8, isString: true}, nil return &UintCode{typ: typ, bitSize: 8, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) uint16StringCode(typ *runtime.Type) (*UintCode, error) { func (c *Compiler) uint16StringCode(typ *runtime.Type) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 16, isString: true}, nil return &UintCode{typ: typ, bitSize: 16, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) uint32StringCode(typ *runtime.Type) (*UintCode, error) { func (c *Compiler) uint32StringCode(typ *runtime.Type) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 32, isString: true}, nil return &UintCode{typ: typ, bitSize: 32, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) uint64StringCode(typ *runtime.Type) (*UintCode, error) { func (c *Compiler) uint64StringCode(typ *runtime.Type) (*UintCode, error) {
return &UintCode{typ: typ, bitSize: 64, isString: true}, nil return &UintCode{typ: typ, bitSize: 64, isString: true}, nil
} }
//nolint:unparam
func (c *Compiler) bytesCode(typ *runtime.Type, isPtr bool) (*BytesCode, error) {
return &BytesCode{typ: typ, isPtr: isPtr}, nil
}
//nolint:unparam
func (c *Compiler) interfaceCode(typ *runtime.Type, isPtr bool) (*InterfaceCode, error) {
return &InterfaceCode{typ: typ, isPtr: isPtr}, nil
}
//nolint:unparam
func (c *Compiler) marshalJSONCode(typ *runtime.Type) (*MarshalJSONCode, error) {
return &MarshalJSONCode{
typ: typ,
isAddrForMarshaler: c.isPtrMarshalJSONType(typ),
isNilableType: c.isNilableType(typ),
isMarshalerContext: typ.Implements(marshalJSONContextType) || runtime.PtrTo(typ).Implements(marshalJSONContextType),
}, nil
}
//nolint:unparam
func (c *Compiler) marshalTextCode(typ *runtime.Type) (*MarshalTextCode, error) {
return &MarshalTextCode{
typ: typ,
isAddrForMarshaler: c.isPtrMarshalTextType(typ),
isNilableType: c.isNilableType(typ),
}, nil
}
func (c *Compiler) ptrCode(typ *runtime.Type) (*PtrCode, error) {
code, err := c.typeToCodeWithPtr(typ.Elem(), true)
if err != nil {
return nil, err
}
ptr, ok := code.(*PtrCode)
if ok {
return &PtrCode{typ: typ, value: ptr.value, ptrNum: ptr.ptrNum + 1}, nil
}
return &PtrCode{typ: typ, value: code, ptrNum: 1}, nil
}
func (c *Compiler) sliceCode(typ *runtime.Type) (*SliceCode, error) { func (c *Compiler) sliceCode(typ *runtime.Type) (*SliceCode, error) {
elem := typ.Elem() elem := typ.Elem()
code, err := c.listElemCode(elem) code, err := c.listElemCode(elem)
@ -386,43 +451,6 @@ func (c *Compiler) mapCode(typ *runtime.Type) (*MapCode, error) {
return &MapCode{typ: typ, key: keyCode, value: valueCode}, nil return &MapCode{typ: typ, key: keyCode, value: valueCode}, nil
} }
func (c *Compiler) bytesCode(typ *runtime.Type, isPtr bool) (*BytesCode, error) {
return &BytesCode{typ: typ, isPtr: isPtr}, nil
}
func (c *Compiler) interfaceCode(typ *runtime.Type, isPtr bool) (*InterfaceCode, error) {
return &InterfaceCode{typ: typ, isPtr: isPtr}, nil
}
func (c *Compiler) marshalJSONCode(typ *runtime.Type) (*MarshalJSONCode, error) {
return &MarshalJSONCode{
typ: typ,
isAddrForMarshaler: c.isPtrMarshalJSONType(typ),
isNilableType: c.isNilableType(typ),
isMarshalerContext: typ.Implements(marshalJSONContextType) || runtime.PtrTo(typ).Implements(marshalJSONContextType),
}, nil
}
func (c *Compiler) marshalTextCode(typ *runtime.Type) (*MarshalTextCode, error) {
return &MarshalTextCode{
typ: typ,
isAddrForMarshaler: c.isPtrMarshalTextType(typ),
isNilableType: c.isNilableType(typ),
}, nil
}
func (c *Compiler) ptrCode(typ *runtime.Type) (*PtrCode, error) {
code, err := c.typeToCodeWithPtr(typ.Elem(), true)
if err != nil {
return nil, err
}
ptr, ok := code.(*PtrCode)
if ok {
return &PtrCode{typ: typ, value: ptr.value, ptrNum: ptr.ptrNum + 1}, nil
}
return &PtrCode{typ: typ, value: code, ptrNum: 1}, nil
}
func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) { func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) {
switch { switch {
case c.isPtrMarshalJSONType(typ): case c.isPtrMarshalJSONType(typ):

View File

@ -428,32 +428,6 @@ func (c *Opcode) TotalLength() int {
return idx + 1 return idx + 1
} }
func (c *Opcode) decOpcodeIndex() {
for code := c; !code.IsEnd(); {
code.DisplayIdx--
if code.Idx > 0 {
code.Idx -= uintptrSize
}
if code.ElemIdx > 0 {
code.ElemIdx -= uintptrSize
}
if code.MapIter > 0 {
code.MapIter -= uintptrSize
}
if code.Length > 0 && code.Op.CodeType() != CodeArrayHead && code.Op.CodeType() != CodeArrayElem {
code.Length -= uintptrSize
}
code = code.IterNext()
}
}
func (c *Opcode) decIndent() {
for code := c; !code.IsEnd(); {
code.Indent--
code = code.IterNext()
}
}
func (c *Opcode) dumpHead(code *Opcode) string { func (c *Opcode) dumpHead(code *Opcode) string {
var length uint32 var length uint32
if code.Op.CodeType() == CodeArrayHead { if code.Op.CodeType() == CodeArrayHead {