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
5package packages
6
7import (
8	"fmt"
9	"strings"
10)
11
12var allModes = []LoadMode{
13	NeedName,
14	NeedFiles,
15	NeedCompiledGoFiles,
16	NeedImports,
17	NeedDeps,
18	NeedExportsFile,
19	NeedTypes,
20	NeedSyntax,
21	NeedTypesInfo,
22	NeedTypesSizes,
23}
24
25var modeStrings = []string{
26	"NeedName",
27	"NeedFiles",
28	"NeedCompiledGoFiles",
29	"NeedImports",
30	"NeedDeps",
31	"NeedExportsFile",
32	"NeedTypes",
33	"NeedSyntax",
34	"NeedTypesInfo",
35	"NeedTypesSizes",
36}
37
38func (mod LoadMode) String() string {
39	m := mod
40	if m == 0 {
41		return "LoadMode(0)"
42	}
43	var out []string
44	for i, x := range allModes {
45		if x > m {
46			break
47		}
48		if (m & x) != 0 {
49			out = append(out, modeStrings[i])
50			m = m ^ x
51		}
52	}
53	if m != 0 {
54		out = append(out, "Unknown")
55	}
56	return fmt.Sprintf("LoadMode(%s)", strings.Join(out, "|"))
57}
58