loadmode_string.go 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package packages
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. var allModes = []LoadMode{
  10. NeedName,
  11. NeedFiles,
  12. NeedCompiledGoFiles,
  13. NeedImports,
  14. NeedDeps,
  15. NeedExportFile,
  16. NeedTypes,
  17. NeedSyntax,
  18. NeedTypesInfo,
  19. NeedTypesSizes,
  20. }
  21. var modeStrings = []string{
  22. "NeedName",
  23. "NeedFiles",
  24. "NeedCompiledGoFiles",
  25. "NeedImports",
  26. "NeedDeps",
  27. "NeedExportFile",
  28. "NeedTypes",
  29. "NeedSyntax",
  30. "NeedTypesInfo",
  31. "NeedTypesSizes",
  32. }
  33. func (mod LoadMode) String() string {
  34. m := mod
  35. if m == 0 {
  36. return "LoadMode(0)"
  37. }
  38. var out []string
  39. for i, x := range allModes {
  40. if x > m {
  41. break
  42. }
  43. if (m & x) != 0 {
  44. out = append(out, modeStrings[i])
  45. m = m ^ x
  46. }
  47. }
  48. if m != 0 {
  49. out = append(out, "Unknown")
  50. }
  51. return fmt.Sprintf("LoadMode(%s)", strings.Join(out, "|"))
  52. }