Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
003f0ad6
Commit
003f0ad6
authored
Dec 17, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added missing file
R=r OCL=21384 CL=21384
parent
b8635907
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
typechecker.go
usr/gri/pretty/typechecker.go
+100
-0
No files found.
usr/gri/pretty/typechecker.go
0 → 100644
View file @
003f0ad6
// 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
TypeChecker
import
(
AST
"ast"
;
Universe
"universe"
;
Globals
"globals"
;
Object
"object"
;
Type
"type"
;
)
type
State
struct
{
level
int
;
top_scope
*
Globals
.
Scope
;
}
// ----------------------------------------------------------------------------
// Support
func
(
s
*
State
)
Error
(
pos
int
,
msg
string
)
{
panicln
(
"error:"
+
msg
);
}
// ----------------------------------------------------------------------------
// Scopes
func
(
s
*
State
)
OpenScope
()
{
s
.
top_scope
=
Globals
.
NewScope
(
s
.
top_scope
);
}
func
(
s
*
State
)
CloseScope
()
{
s
.
top_scope
=
s
.
top_scope
.
parent
;
}
func
(
s
*
State
)
Lookup
(
ident
string
)
*
Globals
.
Object
{
for
scope
:=
s
.
top_scope
;
scope
!=
nil
;
scope
=
scope
.
parent
{
obj
:=
scope
.
Lookup
(
ident
);
if
obj
!=
nil
{
return
obj
;
}
}
return
nil
;
}
func
(
s
*
State
)
DeclareInScope
(
scope
*
Globals
.
Scope
,
obj
*
Globals
.
Object
)
{
if
s
.
level
>
0
{
panic
(
"cannot declare objects in other packages"
);
}
obj
.
pnolev
=
s
.
level
;
if
scope
.
Lookup
(
obj
.
ident
)
!=
nil
{
s
.
Error
(
obj
.
pos
,
`"`
+
obj
.
ident
+
`" is declared already`
);
return
;
// don't insert it into the scope
}
scope
.
Insert
(
obj
);
}
func
(
s
*
State
)
Declare
(
obj
*
Globals
.
Object
)
{
s
.
DeclareInScope
(
s
.
top_scope
,
obj
);
}
// ----------------------------------------------------------------------------
// Common productions
func
(
s
*
State
)
DeclareIdent
(
kind
int
)
{
obj
:=
Globals
.
NewObject
(
0
,
kind
,
""
);
s
.
Declare
(
obj
);
}
// ----------------------------------------------------------------------------
func
(
s
*
State
)
CheckProgram
(
p
*
AST
.
Program
)
{
s
.
OpenScope
();
{
s
.
OpenScope
();
s
.
CloseScope
();
}
s
.
CloseScope
();
}
// ----------------------------------------------------------------------------
export
func
CheckProgram
(
p
*
AST
.
Program
)
{
var
s
State
;
s
.
CheckProgram
(
p
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment