-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClassScope.zu
130 lines (111 loc) · 3.24 KB
/
ClassScope.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# The Zimbu compiler written in Zimbu
#
# ClassScope class.
#
# A Scope used for the toplevel of a class and interface. The SHARED section
# is in a SharedScope.
#
# 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"
IMPORT "Template.zu"
CLASS ClassScope EXTENDS Scope @items=public
# Object members defined in a class. These symbols are part of every object.
# The SHARED members are in $declDict.
multiDict<string, Declaration> $objectMembers
# Template with the types used in this class.
Template $template
# Return TRUE when at the toplevel class scope, not in SHARED section inside
# a class or in a method.
FUNC $isTopClassScope() bool @define
RETURN TRUE
}
# Can symbols be used before defined?
FUNC $isForwardDeclare() bool @define
RETURN TRUE
}
# Are variables initialized when declared?
# FALSE when a method does the initialization.
FUNC $isInitVar() bool @define
RETURN FALSE
}
# Can there be non-declaration statements in this Scope?
FUNC $hasStatements() bool @define
RETURN FALSE
}
# Get the list of object declarations.
FUNC $getObjectDeclDict() multiDict<string, Declaration> @replace
RETURN $objectMembers
}
# Add an object member.
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(TRUE)
}
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)
}
# Remove object member |decl| from the class.
PROC $removeObjectMember(Declaration decl)
IF $objectMembers != NIL
list<Declaration> l = $objectMembers.get(decl.name)
FOR i IN 0 UNTIL l.Size()
IF l[i] IS decl
l.remove(i)
IF l.Size() == 0
$objectMembers.removeAll(decl.name)
}
BREAK
}
}
}
}
PROC $initPass(Scope outer)
$fillFromOuter(outer)
# Don't copy the return symbol from the outer scope.
$returnType = NIL
}
# If this class has templates, add them to the scope.
# E.g. <Titem> adds the actual type for Titem.
PROC $addTemplateTypes()
IF $template != NIL
FOR decl IN $template.decls
IF decl != NIL
$addMember(decl)
}
}
}
}
# If this class has templates, remove them from the scope.
# This undoes $addTemplateTypes()
PROC $removeTemplateTypes()
IF $template != NIL
FOR decl IN $template.decls
IF decl != NIL
$removeMember(decl)
}
}
}
}
}