Fix warnings

This commit is contained in:
Greg Shuflin 2021-10-19 13:54:32 -07:00
parent 8b724cf0ff
commit 3060afd752
5 changed files with 14 additions and 27 deletions

View File

@ -17,7 +17,7 @@ use std::str::FromStr;
use std::convert::TryFrom;
use crate::ast::*;
use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable, FullyQualifiedSymbolName};
use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable};
use crate::builtin::Builtin;
use crate::util::deref_optional_box;

View File

@ -4,7 +4,7 @@ use std::rc::Rc;
use std::fmt;
use std::fmt::Write;
use crate::tokenizing::{Location, LineNumber};
use crate::tokenizing::Location;
use crate::ast;
use crate::ast::{ItemId, TypeBody, Variant, TypeSingletonName, Signature, Declaration, Statement, StatementKind, ModuleSpecifier};
use crate::typechecking::TypeName;
@ -32,12 +32,6 @@ impl FQSN {
v.push(Scope::Name(new_name));
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
@ -47,12 +41,14 @@ enum Scope {
Name(String)
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
struct DuplicateName {
prev_name: FQSN,
location: Location
}
#[allow(dead_code)]
#[derive(Debug)]
struct NameSpec<K> {
location: Location,
@ -256,7 +252,8 @@ impl SymbolTable {
//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> {
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;
match kind {
StatementKind::Declaration(Declaration::FuncSig(signature)) => {
@ -290,7 +287,7 @@ impl SymbolTable {
StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => {
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 } )?;
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());
}
},
@ -318,7 +315,7 @@ impl SymbolTable {
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 register = |fqsn: FQSN, spec: SymbolSpec| {

View File

@ -1,6 +1,6 @@
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::util::ScopeStack;
@ -65,11 +65,9 @@ impl<'a> ASTVisitor for Resolver<'a> {
};
let members = self.symbol_table.symbol_trie.get_children(&prefix);
for member in members.into_iter() {
let local_name = match member.scopes.last().unwrap() {
Scope::Name(n) => Rc::new(n.clone()),
_ => panic!("LOL bad"),
};
self.name_scope_stack.insert(local_name.clone(), member.scopes);
let Scope::Name(n) = member.scopes.last().unwrap();
let local_name = Rc::new(n.clone());
self.name_scope_stack.insert(local_name, member.scopes);
}
},
ImportedNames::LastOfPath => {

View File

@ -11,9 +11,8 @@ impl TrieKey for FQSN {
let mut hasher = DefaultHasher::new();
let mut output = vec![];
for segment in self.scopes.iter() {
if let Scope::Name(s) = segment {
s.as_bytes().hash(&mut hasher);
}
let Scope::Name(s) = segment;
s.as_bytes().hash(&mut hasher);
output.extend_from_slice(&hasher.finish().to_be_bytes());
}
output

View File

@ -18,11 +18,4 @@ impl DeclLocations {
pub(crate) fn add_location(&mut self, id: &ItemId, loc: Location) {
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
}
}
}