-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIFIntelSymbol.m
203 lines (147 loc) · 4.01 KB
/
IFIntelSymbol.m
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// IFIntelSymbol.m
// Inform
//
// Created by Andrew Hunter on 05/02/2005.
// Copyright 2005 Andrew Hunter. All rights reserved.
//
#import "IFIntelSymbol.h"
NSString* IFSectionSymbolType = @"IFSectionSymbolType";
@implementation IFIntelSymbol
// = Initialisation =
- (id) init {
self = [super init];
if (self) {
level = -1; // == Calculate
}
return self;
}
- (void) dealloc {
if (name) [name release];
if (type) [type release];
// ourFile releases us, not the other way around
//if (nextSymbol) [nextSymbol release];
// if (lastSymbol) [lastSymbol release]; -- not retained when set (ensures that we actually get released!)
[super dealloc];
}
// = Symbol data =
- (NSString*) name {
return name;
}
- (NSString*) type {
return type;
}
- (int) level {
if (level < 0) {
if (relation == IFSymbolOnLevel)
return levelDelta;
// Relative level
if (lastSymbol == nil)
return levelDelta<0?0:levelDelta;
int realLevel = [lastSymbol level] + levelDelta;
return realLevel<0?0:levelDelta;
}
return level;
}
- (enum IFSymbolRelation) relation {
return relation;
}
- (int) levelDelta {
return levelDelta;
}
- (void) setName: (NSString*) newName {
if (name) [name release];
name = [newName copy];
}
- (void) setType: (NSString*) newType {
if (type) [type release];
type = [newType copy];
}
- (void) setLevel: (int) newLevel {
level = newLevel;
}
- (void) setRelation: (enum IFSymbolRelation) newRelation {
relation = newRelation;
}
- (void) setLevelDelta: (int) newDelta {
levelDelta = newDelta;
}
// = Debug =
- (NSString*) description {
NSMutableString* res = [NSMutableString string];
[res appendFormat: @"IFIntelSymbol '%@' - delta %i", name, levelDelta];
return res;
}
// = Our relation to other symbols in the file =
- (IFIntelSymbol*) parent {
IFIntelSymbol* parent = lastSymbol;
int myLevel = [self level];
while (parent != nil && [parent level] >= myLevel) {
parent = parent->lastSymbol;
}
return parent;
}
- (IFIntelSymbol*) child {
IFIntelSymbol* child = nextSymbol;
if (child == nil) return nil;
if ([child level] > [self level]) return child;
return nil;
}
- (IFIntelSymbol*) sibling {
IFIntelSymbol* sibling = nextSymbol;
int myLevel = [self level];
while (sibling != nil && [sibling level] > myLevel) sibling = sibling->nextSymbol;
if (sibling == nil) return nil;
if ([sibling level] == myLevel) return sibling;
if ([sibling level] < myLevel) {
if ([sibling parent] == [self parent]) return sibling;
}
return nil;
}
- (IFIntelSymbol*) previousSibling {
IFIntelSymbol* sibling = lastSymbol;
int myLevel = [self level];
while (sibling != nil && [sibling level] > myLevel) sibling = sibling->lastSymbol;
if (sibling == nil) return nil;
if ([sibling level] == [self level]) return sibling;
return nil;
}
- (IFIntelSymbol*) nextSymbol {
return nextSymbol;
}
- (IFIntelSymbol*) lastSymbol {
return lastSymbol;
}
// = NSCoding =
// (This is required in order to use these objects in a menu, though is not especially useful in general)
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject: name
forKey: @"name"];
[encoder encodeObject: type
forKey: @"type"];
[encoder encodeInt: level
forKey: @"level"];
[encoder encodeInt: relation
forKey: @"relation"];
[encoder encodeInt: levelDelta
forKey: @"levelDelta"];
[encoder encodeObject: nextSymbol
forKey: @"nextSymbol"];
[encoder encodeObject: lastSymbol
forKey: @"lastSymbol"];
}
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (self) {
name = [[decoder decodeObjectForKey: @"name"] retain];
type = [[decoder decodeObjectForKey: @"type"] retain];
level = [decoder decodeIntForKey: @"level"];
relation = [decoder decodeIntForKey: @"relation"];
levelDelta = [decoder decodeIntForKey: @"levelDelta"];
// No point in loading these, as we can't retain them!
//nextSymbol = [decoder decodeObjectForKey: @"nextSymbol"];
//lastSymbol = [decoder decodeObjectForKey: @"lastSymbol"];
}
return self;
}
@end