Skip to content

Commit 23e07f6

Browse files
committed
WIP class inheritance
1 parent 332f371 commit 23e07f6

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/symbols.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_hash::FxHashMap as HashMap;
2+
use rustc_hash::FxHashSet as HashSet;
23
use crate::lexer::{ParseError, SrcPos};
34
use crate::ast::*;
45

@@ -183,6 +184,48 @@ impl Program
183184
// Set the number of globals
184185
self.num_globals = env.next_global_idx;
185186

187+
188+
189+
190+
// Note: we need to make sure that there's no cycle
191+
// Might be simpler to do a DFS from each class?
192+
// We can keep track of which classes have already been processed
193+
194+
let mut processed = HashSet::<ClassId>::default();
195+
196+
197+
198+
199+
200+
201+
/*
202+
// Set of classes to be processed
203+
let mut classes: HashSet<ClassId> = self.classes.keys().cloned().collect();
204+
205+
// Until we've processed all classes for inheritance
206+
for class_id in &classes.clone() {
207+
208+
let class = &self.classes[class_id];
209+
210+
// If a class has no parent, skip it
211+
if class.parent_id == ClassId::default() {
212+
classes.remove(class_id);
213+
continue;
214+
}
215+
216+
// Wait until the parent of this class has been processed
217+
if classes.contains(&class.parent_id) {
218+
continue;
219+
}
220+
}
221+
*/
222+
223+
224+
225+
226+
227+
228+
186229
Ok(())
187230
}
188231
}

0 commit comments

Comments
 (0)