aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/sym.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-04-04 17:54:02 -0700
committerRobert Griesemer <gri@golang.org>2017-04-07 03:04:00 +0000
commitf68f292820a3dc545aba0ee64a372635a64d5040 (patch)
treec61984f933df1783944c11c26df28594ed79c47a /src/cmd/compile/internal/types/sym.go
parent19bd145d0721a28658b15deb548f22a3405d83bd (diff)
downloadgo-f68f292820a3dc545aba0ee64a372635a64d5040.tar.gz
go-f68f292820a3dc545aba0ee64a372635a64d5040.zip
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types - moved Pkg, Sym, Type to new package - to break cycles, for now we need the (ugly) types/utils.go file which contains a handful of functions that must be installed early by the gc frontend - to break cycles, for now we need two functions to convert between *gc.Node and *types.Node (the latter is a dummy type) - adjusted the gc's code to use the new package and the conversion functions as needed - made several Pkg, Sym, and Type methods functions as needed - renamed constructors typ, typPtr, typArray, etc. to types.New, types.NewPtr, types.NewArray, etc. Passes toolstash-check -all. Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72 Reviewed-on: https://go-review.googlesource.com/39855 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/sym.go')
-rw-r--r--src/cmd/compile/internal/types/sym.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types/sym.go b/src/cmd/compile/internal/types/sym.go
new file mode 100644
index 0000000000..1086b99fdd
--- /dev/null
+++ b/src/cmd/compile/internal/types/sym.go
@@ -0,0 +1,62 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package types
+
+import (
+ "cmd/internal/obj"
+ "cmd/internal/src"
+)
+
+// Sym represents an object name. Most commonly, this is a Go identifier naming
+// an object declared within a package, but Syms are also used to name internal
+// synthesized objects.
+//
+// As an exception, field and method names that are exported use the Sym
+// associated with localpkg instead of the package that declared them. This
+// allows using Sym pointer equality to test for Go identifier uniqueness when
+// handling selector expressions.
+type Sym struct {
+ Link *Sym
+ Importdef *Pkg // where imported definition was found
+ Linkname string // link name
+
+ // saved and restored by dcopy
+ Pkg *Pkg
+ Name string // object name
+ Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
+ Lastlineno src.XPos // last declaration for diagnostic
+ Block int32 // blocknumber to catch redeclaration
+
+ flags bitset8
+ Label *Node // corresponding label (ephemeral)
+ Origpkg *Pkg // original package for . import
+ Lsym *obj.LSym
+}
+
+const (
+ symExport = 1 << iota // added to exportlist (no need to add again)
+ symPackage
+ symExported // already written out by export
+ symUniq
+ symSiggen
+ symAsm
+ symAlgGen
+)
+
+func (sym *Sym) Export() bool { return sym.flags&symExport != 0 }
+func (sym *Sym) Package() bool { return sym.flags&symPackage != 0 }
+func (sym *Sym) Exported() bool { return sym.flags&symExported != 0 }
+func (sym *Sym) Uniq() bool { return sym.flags&symUniq != 0 }
+func (sym *Sym) Siggen() bool { return sym.flags&symSiggen != 0 }
+func (sym *Sym) Asm() bool { return sym.flags&symAsm != 0 }
+func (sym *Sym) AlgGen() bool { return sym.flags&symAlgGen != 0 }
+
+func (sym *Sym) SetExport(b bool) { sym.flags.set(symExport, b) }
+func (sym *Sym) SetPackage(b bool) { sym.flags.set(symPackage, b) }
+func (sym *Sym) SetExported(b bool) { sym.flags.set(symExported, b) }
+func (sym *Sym) SetUniq(b bool) { sym.flags.set(symUniq, b) }
+func (sym *Sym) SetSiggen(b bool) { sym.flags.set(symSiggen, b) }
+func (sym *Sym) SetAsm(b bool) { sym.flags.set(symAsm, b) }
+func (sym *Sym) SetAlgGen(b bool) { sym.flags.set(symAlgGen, b) }