-
Notifications
You must be signed in to change notification settings - Fork 4
/
NameManager.mpl
114 lines (92 loc) · 2.68 KB
/
NameManager.mpl
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
# Copyright (C) 2021 Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"Array" use
"HashTable" use
"String" use
"control" use
NameManager: [{
virtual itemSchema: Ref; # Should have a field named "file", which is used as opaque pointer by NameManager
createName: [
text:;
result: text textNameIds.find;
result.success [result.value new] [
string: text String same [@text] [text toString] uif;
nameId: names.size;
nameId 1 + @names.enlarge
string.getStringView nameId @textNameIds.insertUnsafe # Make StringView using the source String object, reference should remain valid when we move String
@string @names.last.@text set
0 @names.last.!overloadCount
0 @names.last.!localCount
nameId
] if
];
addItem: [
item: nameId:;;
current: nameId @names.at;
item.file nil? [current.overloadCount 1 + @current.!overloadCount] when
item.isLocal [current.localCount 1 + @current.!localCount] when
@item @current.@items.append
];
findItem: [
index: file: nameId:;; new;
items: nameId names.at.items;
index -1 = [items.size !index] when
[
index 1 - !index
index -1 = [
itemFile: index items.at.file;
itemFile nil? [file nil?] || [itemFile file is] ||
] || ~
] loop
index
];
findItemStrong: [
index: file: nameId:;; new;
items: nameId names.at.items;
index -1 = [items.size !index] when
[
index 1 - !index
index -1 = [
itemFile: index items.at.file;
file nil? [itemFile file is] ||
] || ~
] loop
index
];
hasOverload: [
nameId: new;
nameId @names.at.overloadCount 0 >
];
hasLocalDefinition: [
nameId: new;
nameId @names.at.localCount 0 >
];
getItem: [
index: nameId:;;
index nameId @names.at.@items.at
];
getText: [
nameId:;
nameId names.at.text.getStringView
];
removeItem: [
nameId:;
current: nameId @names.at;
current.items.last.file nil? [current.overloadCount 1 - @current.!overloadCount] when
current.items.last.isLocal [current.localCount 1 - @current.!localCount] when
@current.@items.popBack
];
# Private
Name: [{
text: String;
items: @itemSchema Array;
overloadCount: Int32;
localCount: Int32;
}];
names: Name Array;
textNameIds: StringView Int32 HashTable;
}];