pkg,service/dap: use switch instead of ifs (#3576)

This commit is contained in:
Oleksandr Redko 2023-11-22 19:07:08 +02:00 committed by GitHub
parent 60a9014dcf
commit f1daaeb1b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 15 deletions

@ -47,11 +47,12 @@ func SplitQuotedFields(in string, quote rune) []string {
}
case inQuote:
if ch == quote {
switch ch {
case quote:
state = inField
} else if ch == '\\' {
case '\\':
state = inQuoteEscaped
} else {
default:
buf.WriteRune(ch)
}

@ -280,11 +280,12 @@ func readNote(r io.ReadSeeker, machineType elf.Machine) (*note, error) {
descReader := bytes.NewReader(desc)
switch note.Type {
case elf.NT_PRSTATUS:
if machineType == _EM_X86_64 {
switch machineType {
case _EM_X86_64:
note.Desc = &linuxPrStatusAMD64{}
} else if machineType == _EM_AARCH64 {
case _EM_AARCH64:
note.Desc = &linuxPrStatusARM64{}
} else {
default:
return nil, fmt.Errorf("unsupported machine type")
}
if err := binary.Read(descReader, binary.LittleEndian, note.Desc); err != nil {

@ -2416,17 +2416,18 @@ func (s *Session) childrenToDAPVariables(v *fullyQualifiedVariable) []dap.Variab
c := &v.Children[i]
cfqname := fmt.Sprintf("%s.%s", v.fullyQualifiedNameOrExpr, c.Name)
if strings.HasPrefix(c.Name, "~") || strings.HasPrefix(c.Name, ".") {
switch {
case strings.HasPrefix(c.Name, "~") || strings.HasPrefix(c.Name, "."):
cfqname = ""
} else if v.isScope && v.fullyQualifiedNameOrExpr == "" {
case v.isScope && v.fullyQualifiedNameOrExpr == "":
cfqname = c.Name
} else if v.fullyQualifiedNameOrExpr == "" {
case v.fullyQualifiedNameOrExpr == "":
cfqname = ""
} else if v.Kind == reflect.Interface {
case v.Kind == reflect.Interface:
cfqname = fmt.Sprintf("%s.(%s)", v.fullyQualifiedNameOrExpr, c.Name) // c is data
} else if v.Kind == reflect.Ptr {
case v.Kind == reflect.Ptr:
cfqname = fmt.Sprintf("(*%v)", v.fullyQualifiedNameOrExpr) // c is the nameless pointer value
} else if v.Kind == reflect.Complex64 || v.Kind == reflect.Complex128 {
case v.Kind == reflect.Complex64 || v.Kind == reflect.Complex128:
cfqname = "" // complex children are not struct fields and can't be accessed directly
}
cvalue, cvarref := s.convertVariable(c, cfqname)

@ -5210,11 +5210,12 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
cmdRequest()
client.ExpectInitializedEvent(t)
if cmd == "launch" {
switch cmd {
case "launch":
client.ExpectLaunchResponse(t)
} else if cmd == "attach" {
case "attach":
client.ExpectAttachResponse(t)
} else {
default:
panic("expected launch or attach command")
}