-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMethodScope.zu
98 lines (78 loc) · 2.6 KB
/
MethodScope.zu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
# The Zimbu compiler written in Zimbu
#
# MethodScope class.
#
# A Scope used for the toplevel of a method. Declares the arguments and
# return type.
#
# Copyright 2011 Bram Moolenaar All Rights Reserved.
# Licensed under the Apache License, Version 2.0. See the LICENSE file or
# obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0
#
IMPORT.PROTO "zui.proto"
IMPORT "Declaration.zu"
IMPORT "Scope.zu"
CLASS MethodScope EXTENDS Scope @items=public
Declaration $reference # For a closure: reference to the method.
# Variables with reference type, possibly tracked for garbage collection.
# This is an ordered dict, items are kept in the order they are added.
dict<string, Declaration> $refVars
# Variables used temporarily. The $temp field says whether it is currently
# being used.
list<Declaration.C> $tempVars
# For USE arguments with $: "USE $var".
multiDict<string, Declaration> $objectMembers
bool $hasDefer # TRUE when DEFER encountered
# Return TRUE when at the toplevel class scope, not in SHARED section inside
# a class or in a method.
FUNC $isTopClassScope() bool @define
RETURN FALSE
}
# Can symbols be used before defined?
FUNC $isForwardDeclare() bool @define
RETURN FALSE
}
# Are variables initialized when declared?
# FALSE when a method does the initialization.
FUNC $isInitVar() bool @define
RETURN TRUE
}
# Can there be statements in this Scope?
FUNC $hasStatements() bool @define
RETURN TRUE
}
PROC $initPass(Scope outer)
$fillFromOuter(outer)
# The declarations are newly created each pass.
$declDict = NIL
}
# Get the list of object declarations.
FUNC $getObjectDeclDict() multiDict<string, Declaration> @replace
RETURN $objectMembers
}
# Add an object member. Only for "USE $var"
PROC $addObjectMember(Declaration decl) @replace
$addObjectDecl(decl.name, decl.zuiDecl, decl)
}
# Inner part of Scope.addObjectDecl() for object members.
PROC $addObjectDecl(string name, Zui.Declaration zuiDecl,
Declaration decl) @replace
IF $objectMembers == NIL
$objectMembers = NEW()
}
IF $objectMembers.has(name)
# If a symbol was already added for this zuiDecl, remove it.
list<Declaration> l = $objectMembers.get(name)
FOR i IN 0 UNTIL l.Size()
IF l[i].zuiDecl IS zuiDecl
l.remove(i)
BREAK
}
}
}
# The last added symbol must be first in the list for generateMethod()
# to work for overloaded methods
$objectMembers.insert(name, decl)
}
}