diff options
author | Russ Cox <rsc@golang.org> | 2020-12-23 00:08:03 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2020-12-23 06:38:01 +0000 |
commit | 9ee309255a94499c6f4e6d3ac7653b5eeb4ae7b7 (patch) | |
tree | 3a166c8ebba0ca3a374fb126fd58e7b74758ed3a /src/cmd/compile/internal/gc/main.go | |
parent | ead4957892bc1975d9cc9c32777733c67e5a885e (diff) | |
download | go-9ee309255a94499c6f4e6d3ac7653b5eeb4ae7b7.tar.gz go-9ee309255a94499c6f4e6d3ac7653b5eeb4ae7b7.zip |
[dev.regabi] cmd/compile: move helpers into package types [generated]
[git-generate]
cd src/cmd/compile/internal/gc
rf '
# Type hash (formatting).
mv typehash TypeHash
mv TypeHash fmt.go
# Method sorting.
mv methcmp MethodsByName
mv MethodsByName MethodsByName.Len MethodsByName.Swap \
MethodsByName.Less sort.go
# Move version check into types.
# A little surprising, but its keyed off the types.Pkg.
ex {
import "cmd/compile/internal/types"
var p *types.Pkg
var major, minor int
langSupported(major, minor, p) -> AllowsGoVersion(p, major, minor)
}
rm langSupported
mv checkLang ParseLangFlag
mv lang langWant AllowsGoVersion ParseLangFlag \
parseLang currentLang goVersionRE goversion.go
mv testdclstack CheckDclstack
mv CheckDclstack scope.go
mv algtype1 AlgType
mv isComplex IsComplex
mv isFloat IsFloat
mv isInt IsInt
mv issimple IsSimple
mv okforcmp IsOrdered
mv floatForComplex FloatForComplex
mv complexForFloat ComplexForFloat
mv isdirectiface IsDirectIface
mv isifacemethod IsInterfaceMethod
mv isMethodApplicable IsMethodApplicable
mv ispaddedfield IsPaddedField
mv isRuntimePkg IsRuntimePkg
mv isReflectPkg IsReflectPkg
mv methtype ReceiverBaseType
mv typesymname TypeSymName
mv typesym TypeSym
mv typeLookup TypeSymLookup
mv IsAlias IsDotAlias
mv isreflexive IsReflexive
mv simtype SimType
# The type1.go here is to avoid an undiagnosed bug in rf
# that does not get the follow-up typechecking right if we
# move directly to type.go during the mv into package types below.
mv \
IsInt IsOrdered IsReflexive \
IsDirectIface IsInterfaceMethod IsMethodApplicable IsPaddedField \
IsRuntimePkg IsReflectPkg ReceiverBaseType \
FloatForComplex ComplexForFloat \
TypeSym TypeSymLookup TypeSymName \
typepkg SimType \
type1.go
# The alg1.go here is because we are only moving part of alg.go.
mv typeHasNoAlg TypeHasNoAlg
mv AlgKind ANOEQ AlgType TypeHasNoAlg IsComparable IncomparableField IsPaddedField alg1.go
mv IsDotAlias pkg.go
mv alg1.go algkind_string.go fmt.go goversion.go pkg.go \
CheckDclstack \ # scope.go
sort.go type1.go \
cmd/compile/internal/types
'
cd ../types
rf '
mv IsDclstackValid isDclstackValid
mv alg1.go alg.go
mv type1.go type.go
'
Change-Id: I8bd53b21c7bdd1770e1b525de32f136833e84c9d
Reviewed-on: https://go-review.googlesource.com/c/go/+/279307
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 93 |
1 files changed, 2 insertions, 91 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index feded3f9b2..15646ff8c7 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -23,13 +23,11 @@ import ( "flag" "fmt" "go/constant" - "internal/goversion" "io" "io/ioutil" "log" "os" "path" - "regexp" "runtime" "sort" "strconv" @@ -153,7 +151,7 @@ func Main(archInit func(*Arch)) { log.Fatalf("location lists requested but register mapping not available on %v", base.Ctxt.Arch.Name) } - checkLang() + types.ParseLangFlag() if base.Flag.SymABIs != "" { readSymABIs(base.Flag.SymABIs, base.Ctxt.Pkgpath) @@ -858,7 +856,7 @@ func clearImports() { s.Def = nil continue } - if IsAlias(s) { + if types.IsDotAlias(s) { // throw away top-level name left over // from previous import . "x" // We'll report errors after type checking in checkDotImports. @@ -873,10 +871,6 @@ func clearImports() { } } -func IsAlias(sym *types.Sym) bool { - return sym.Def != nil && sym.Def.Sym() != sym -} - // recordFlags records the specified command-line flags to be placed // in the DWARF info. func recordFlags(flags ...string) { @@ -944,89 +938,6 @@ func recordPackageName() { s.P = []byte(types.LocalPkg.Name) } -// currentLang returns the current language version. -func currentLang() string { - return fmt.Sprintf("go1.%d", goversion.Version) -} - -// goVersionRE is a regular expression that matches the valid -// arguments to the -lang flag. -var goVersionRE = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`) - -// A lang is a language version broken into major and minor numbers. -type lang struct { - major, minor int -} - -// langWant is the desired language version set by the -lang flag. -// If the -lang flag is not set, this is the zero value, meaning that -// any language version is supported. -var langWant lang - -// AllowsGoVersion reports whether a particular package -// is allowed to use Go version major.minor. -// We assume the imported packages have all been checked, -// so we only have to check the local package against the -lang flag. -func AllowsGoVersion(pkg *types.Pkg, major, minor int) bool { - if pkg == nil { - // TODO(mdempsky): Set Pkg for local types earlier. - pkg = types.LocalPkg - } - if pkg != types.LocalPkg { - // Assume imported packages passed type-checking. - return true - } - if langWant.major == 0 && langWant.minor == 0 { - return true - } - return langWant.major > major || (langWant.major == major && langWant.minor >= minor) -} - -func langSupported(major, minor int, pkg *types.Pkg) bool { - return AllowsGoVersion(pkg, major, minor) -} - -// checkLang verifies that the -lang flag holds a valid value, and -// exits if not. It initializes data used by langSupported. -func checkLang() { - if base.Flag.Lang == "" { - return - } - - var err error - langWant, err = parseLang(base.Flag.Lang) - if err != nil { - log.Fatalf("invalid value %q for -lang: %v", base.Flag.Lang, err) - } - - if def := currentLang(); base.Flag.Lang != def { - defVers, err := parseLang(def) - if err != nil { - log.Fatalf("internal error parsing default lang %q: %v", def, err) - } - if langWant.major > defVers.major || (langWant.major == defVers.major && langWant.minor > defVers.minor) { - log.Fatalf("invalid value %q for -lang: max known version is %q", base.Flag.Lang, def) - } - } -} - -// parseLang parses a -lang option into a langVer. -func parseLang(s string) (lang, error) { - matches := goVersionRE.FindStringSubmatch(s) - if matches == nil { - return lang{}, fmt.Errorf(`should be something like "go1.12"`) - } - major, err := strconv.Atoi(matches[1]) - if err != nil { - return lang{}, err - } - minor, err := strconv.Atoi(matches[2]) - if err != nil { - return lang{}, err - } - return lang{major: major, minor: minor}, nil -} - // useNewABIWrapGen returns TRUE if the compiler should generate an // ABI wrapper for the function 'f'. func useABIWrapGen(f *ir.Func) bool { |