summaryrefslogtreecommitdiff
path: root/libgo/go/exp/eval/compiler.go
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/go/exp/eval/compiler.go
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libgo/go/exp/eval/compiler.go')
-rw-r--r--libgo/go/exp/eval/compiler.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/libgo/go/exp/eval/compiler.go b/libgo/go/exp/eval/compiler.go
new file mode 100644
index 000000000..9d2923bfc
--- /dev/null
+++ b/libgo/go/exp/eval/compiler.go
@@ -0,0 +1,92 @@
+// Copyright 2009 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 eval
+
+import (
+ "fmt"
+ "go/scanner"
+ "go/token"
+)
+
+
+// A compiler captures information used throughout an entire
+// compilation. Currently it includes only the error handler.
+//
+// TODO(austin) This might actually represent package level, in which
+// case it should be package compiler.
+type compiler struct {
+ fset *token.FileSet
+ errors scanner.ErrorHandler
+ numErrors int
+ silentErrors int
+}
+
+func (a *compiler) diagAt(pos token.Pos, format string, args ...interface{}) {
+ a.errors.Error(a.fset.Position(pos), fmt.Sprintf(format, args...))
+ a.numErrors++
+}
+
+func (a *compiler) numError() int { return a.numErrors + a.silentErrors }
+
+// The universal scope
+func newUniverse() *Scope {
+ sc := &Scope{nil, 0}
+ sc.block = &block{
+ offset: 0,
+ scope: sc,
+ global: true,
+ defs: make(map[string]Def),
+ }
+ return sc
+}
+
+var universe *Scope = newUniverse()
+
+
+// TODO(austin) These can all go in stmt.go now
+type label struct {
+ name string
+ desc string
+ // The PC goto statements should jump to, or nil if this label
+ // cannot be goto'd (such as an anonymous for loop label).
+ gotoPC *uint
+ // The PC break statements should jump to, or nil if a break
+ // statement is invalid.
+ breakPC *uint
+ // The PC continue statements should jump to, or nil if a
+ // continue statement is invalid.
+ continuePC *uint
+ // The position where this label was resolved. If it has not
+ // been resolved yet, an invalid position.
+ resolved token.Pos
+ // The position where this label was first jumped to.
+ used token.Pos
+}
+
+// A funcCompiler captures information used throughout the compilation
+// of a single function body.
+type funcCompiler struct {
+ *compiler
+ fnType *FuncType
+ // Whether the out variables are named. This affects what
+ // kinds of return statements are legal.
+ outVarsNamed bool
+ *codeBuf
+ flow *flowBuf
+ labels map[string]*label
+}
+
+// A blockCompiler captures information used throughout the compilation
+// of a single block within a function.
+type blockCompiler struct {
+ *funcCompiler
+ block *block
+ // The label of this block, used for finding break and
+ // continue labels.
+ label *label
+ // The blockCompiler for the block enclosing this one, or nil
+ // for a function-level block.
+ parent *blockCompiler
+}