Various refactors around symbol table
This commit is contained in:
parent
fd3a641c71
commit
69304de998
@ -90,7 +90,7 @@ impl Schala {
|
|||||||
// Typechecking
|
// Typechecking
|
||||||
// TODO typechecking not working
|
// TODO typechecking not working
|
||||||
let _overall_type = self.type_context.typecheck(&ast)
|
let _overall_type = self.type_context.typecheck(&ast)
|
||||||
.map_err(|err| SchalaError::from_type_error(err));
|
.map_err(SchalaError::from_type_error);
|
||||||
|
|
||||||
// Reduce AST - TODO this doesn't produce an error yet, but probably should
|
// Reduce AST - TODO this doesn't produce an error yet, but probably should
|
||||||
let symbol_table = self.symbol_table.borrow();
|
let symbol_table = self.symbol_table.borrow();
|
||||||
|
@ -23,8 +23,8 @@ macro_rules! fqsn {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mod source_map;
|
mod tables;
|
||||||
use source_map::SourceMap;
|
use tables::SourceMap;
|
||||||
mod symbol_trie;
|
mod symbol_trie;
|
||||||
use symbol_trie::SymbolTrie;
|
use symbol_trie::SymbolTrie;
|
||||||
mod test;
|
mod test;
|
||||||
@ -139,7 +139,7 @@ impl SymbolTable {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Symbol {
|
pub struct Symbol {
|
||||||
pub local_name: Rc<String>, //TODO does this need to be pub?
|
pub local_name: Rc<String>,
|
||||||
fully_qualified_name: FullyQualifiedSymbolName,
|
fully_qualified_name: FullyQualifiedSymbolName,
|
||||||
pub spec: SymbolSpec,
|
pub spec: SymbolSpec,
|
||||||
}
|
}
|
||||||
@ -204,12 +204,12 @@ impl SymbolTable {
|
|||||||
|
|
||||||
match decl {
|
match decl {
|
||||||
FuncSig(ref signature) => {
|
FuncSig(ref signature) => {
|
||||||
seen_identifiers.try_register(&signature.name, &id, &self.source_map)
|
seen_identifiers.try_register(&signature.name, id, &self.source_map)
|
||||||
.map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?;
|
.map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?;
|
||||||
self.add_function_signature(signature, scope_name_stack)?
|
self.add_function_signature(signature, scope_name_stack)?
|
||||||
}
|
}
|
||||||
FuncDecl(ref signature, ref body) => {
|
FuncDecl(ref signature, ref body) => {
|
||||||
seen_identifiers.try_register(&signature.name, &id, &self.source_map)
|
seen_identifiers.try_register(&signature.name, id, &self.source_map)
|
||||||
.map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?;
|
.map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?;
|
||||||
self.add_function_signature(signature, scope_name_stack)?;
|
self.add_function_signature(signature, scope_name_stack)?;
|
||||||
scope_name_stack.push(ScopeSegment{
|
scope_name_stack.push(ScopeSegment{
|
||||||
@ -234,7 +234,7 @@ impl SymbolTable {
|
|||||||
},
|
},
|
||||||
Statement { kind: StatementKind::Module(ModuleSpecifier { name, contents}), id, location } => {
|
Statement { kind: StatementKind::Module(ModuleSpecifier { name, contents}), id, location } => {
|
||||||
self.source_map.add_location(id, *location);
|
self.source_map.add_location(id, *location);
|
||||||
seen_modules.try_register(&name, &id, &self.source_map)
|
seen_modules.try_register(name, id, &self.source_map)
|
||||||
.map_err(|line| format!("Duplicate module definition: {}. It's already defined at {}", name, line))?;
|
.map_err(|line| format!("Duplicate module definition: {}. It's already defined at {}", name, line))?;
|
||||||
scope_name_stack.push(ScopeSegment { name: name.clone() });
|
scope_name_stack.push(ScopeSegment { name: name.clone() });
|
||||||
let output = self.add_symbols_from_scope(contents, scope_name_stack);
|
let output = self.add_symbols_from_scope(contents, scope_name_stack);
|
||||||
@ -248,7 +248,7 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn debug_symbol_table(&self) -> String {
|
pub fn debug_symbol_table(&self) -> String {
|
||||||
let mut output = format!("Symbol table\n");
|
let mut output = "Symbol table\n".to_string();
|
||||||
let mut sorted_symbols: Vec<(&FullyQualifiedSymbolName, &Symbol)> = self.symbol_path_to_symbol.iter().collect();
|
let mut sorted_symbols: Vec<(&FullyQualifiedSymbolName, &Symbol)> = self.symbol_path_to_symbol.iter().collect();
|
||||||
sorted_symbols.sort_by(|(fqsn, _), (other_fqsn, _)| fqsn.cmp(other_fqsn));
|
sorted_symbols.sort_by(|(fqsn, _), (other_fqsn, _)| fqsn.cmp(other_fqsn));
|
||||||
for (name, sym) in sorted_symbols.iter() {
|
for (name, sym) in sorted_symbols.iter() {
|
||||||
|
Loading…
Reference in New Issue
Block a user