Fix warnings
This commit is contained in:
parent
8b724cf0ff
commit
3060afd752
@ -17,7 +17,7 @@ use std::str::FromStr;
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable, FullyQualifiedSymbolName};
|
use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable};
|
||||||
use crate::builtin::Builtin;
|
use crate::builtin::Builtin;
|
||||||
use crate::util::deref_optional_box;
|
use crate::util::deref_optional_box;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use std::rc::Rc;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use crate::tokenizing::{Location, LineNumber};
|
use crate::tokenizing::Location;
|
||||||
use crate::ast;
|
use crate::ast;
|
||||||
use crate::ast::{ItemId, TypeBody, Variant, TypeSingletonName, Signature, Declaration, Statement, StatementKind, ModuleSpecifier};
|
use crate::ast::{ItemId, TypeBody, Variant, TypeSingletonName, Signature, Declaration, Statement, StatementKind, ModuleSpecifier};
|
||||||
use crate::typechecking::TypeName;
|
use crate::typechecking::TypeName;
|
||||||
@ -32,12 +32,6 @@ impl FQSN {
|
|||||||
v.push(Scope::Name(new_name));
|
v.push(Scope::Name(new_name));
|
||||||
FQSN { scopes: v }
|
FQSN { scopes: v }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extend(&self, new_name: String) -> Self {
|
|
||||||
let mut existing = self.scopes.clone();
|
|
||||||
existing.push(Scope::Name(new_name));
|
|
||||||
FQSN { scopes: existing }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO eventually this should use ItemId's to avoid String-cloning
|
//TODO eventually this should use ItemId's to avoid String-cloning
|
||||||
@ -47,12 +41,14 @@ enum Scope {
|
|||||||
Name(String)
|
Name(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct DuplicateName {
|
struct DuplicateName {
|
||||||
prev_name: FQSN,
|
prev_name: FQSN,
|
||||||
location: Location
|
location: Location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct NameSpec<K> {
|
struct NameSpec<K> {
|
||||||
location: Location,
|
location: Location,
|
||||||
@ -256,7 +252,8 @@ impl SymbolTable {
|
|||||||
//TODO this should probably return a vector of duplicate name errors
|
//TODO this should probably return a vector of duplicate name errors
|
||||||
fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec<Scope>) -> Result<(), DuplicateName> {
|
fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec<Scope>) -> Result<(), DuplicateName> {
|
||||||
for statement in statements {
|
for statement in statements {
|
||||||
let Statement { id, kind, location } = statement;
|
//TODO I'm not sure if I need to do anything with this ID
|
||||||
|
let Statement { id: _, kind, location } = statement;
|
||||||
let location = *location;
|
let location = *location;
|
||||||
match kind {
|
match kind {
|
||||||
StatementKind::Declaration(Declaration::FuncSig(signature)) => {
|
StatementKind::Declaration(Declaration::FuncSig(signature)) => {
|
||||||
@ -290,7 +287,7 @@ impl SymbolTable {
|
|||||||
StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => {
|
StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => {
|
||||||
let fq_type = FQSN::from_scope_stack(scope_stack.as_ref(), name.name.as_ref().to_owned());
|
let fq_type = FQSN::from_scope_stack(scope_stack.as_ref(), name.name.as_ref().to_owned());
|
||||||
self.types.register(fq_type, NameSpec { location, kind: TypeKind } )?;
|
self.types.register(fq_type, NameSpec { location, kind: TypeKind } )?;
|
||||||
if let Err(errors) = self.add_type_members(id, name, body, mutable, location, scope_stack) {
|
if let Err(errors) = self.add_type_members(name, body, mutable, location, scope_stack) {
|
||||||
return Err(errors[0].clone());
|
return Err(errors[0].clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -318,7 +315,7 @@ impl SymbolTable {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_type_members(&mut self, id: &ItemId, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec<Scope>) -> Result<(), Vec<DuplicateName>> {
|
fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec<Scope>) -> Result<(), Vec<DuplicateName>> {
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
|
|
||||||
let mut register = |fqsn: FQSN, spec: SymbolSpec| {
|
let mut register = |fqsn: FQSN, spec: SymbolSpec| {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::symbol_table::{SymbolTable, ScopeSegment, FullyQualifiedSymbolName, FQSN, Scope};
|
use crate::symbol_table::{SymbolTable, FQSN, Scope};
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::util::ScopeStack;
|
use crate::util::ScopeStack;
|
||||||
|
|
||||||
@ -65,11 +65,9 @@ impl<'a> ASTVisitor for Resolver<'a> {
|
|||||||
};
|
};
|
||||||
let members = self.symbol_table.symbol_trie.get_children(&prefix);
|
let members = self.symbol_table.symbol_trie.get_children(&prefix);
|
||||||
for member in members.into_iter() {
|
for member in members.into_iter() {
|
||||||
let local_name = match member.scopes.last().unwrap() {
|
let Scope::Name(n) = member.scopes.last().unwrap();
|
||||||
Scope::Name(n) => Rc::new(n.clone()),
|
let local_name = Rc::new(n.clone());
|
||||||
_ => panic!("LOL bad"),
|
self.name_scope_stack.insert(local_name, member.scopes);
|
||||||
};
|
|
||||||
self.name_scope_stack.insert(local_name.clone(), member.scopes);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ImportedNames::LastOfPath => {
|
ImportedNames::LastOfPath => {
|
||||||
|
@ -11,9 +11,8 @@ impl TrieKey for FQSN {
|
|||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for segment in self.scopes.iter() {
|
for segment in self.scopes.iter() {
|
||||||
if let Scope::Name(s) = segment {
|
let Scope::Name(s) = segment;
|
||||||
s.as_bytes().hash(&mut hasher);
|
s.as_bytes().hash(&mut hasher);
|
||||||
}
|
|
||||||
output.extend_from_slice(&hasher.finish().to_be_bytes());
|
output.extend_from_slice(&hasher.finish().to_be_bytes());
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
|
@ -18,11 +18,4 @@ impl DeclLocations {
|
|||||||
pub(crate) fn add_location(&mut self, id: &ItemId, loc: Location) {
|
pub(crate) fn add_location(&mut self, id: &ItemId, loc: Location) {
|
||||||
self.map.insert(id.clone(), loc);
|
self.map.insert(id.clone(), loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lookup(&self, id: &ItemId) -> Option<Location> {
|
|
||||||
match self.map.get(id) {
|
|
||||||
Some(loc) => Some(loc.clone()),
|
|
||||||
None => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user