Skip to content

Commit

Permalink
Started refactoring semantic resolution code
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Oct 26, 2024
1 parent 2f3e57a commit 605be09
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 307 deletions.
26 changes: 26 additions & 0 deletions src/resolve/ctx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::{function_search_ctx::FunctionSearchCtx, job::FuncJob};
use crate::{resolved, workspace::fs::FsNodeId};
use indexmap::IndexMap;
use std::collections::{HashMap, VecDeque};

pub struct ResolveCtx {
pub jobs: VecDeque<FuncJob>,
pub function_search_ctxs: IndexMap<FsNodeId, FunctionSearchCtx>,
pub public_functions: HashMap<FsNodeId, HashMap<String, Vec<resolved::FunctionRef>>>,
pub types_in_modules: HashMap<FsNodeId, HashMap<String, resolved::TypeDecl>>,
pub globals_in_modules: HashMap<FsNodeId, HashMap<String, resolved::GlobalVarDecl>>,
pub helper_exprs_in_modules: HashMap<FsNodeId, HashMap<String, resolved::HelperExprDecl>>,
}

impl ResolveCtx {
pub fn new() -> Self {
Self {
jobs: Default::default(),
function_search_ctxs: Default::default(),
public_functions: HashMap::new(),
types_in_modules: HashMap::new(),
globals_in_modules: HashMap::new(),
helper_exprs_in_modules: HashMap::new(),
}
}
}
20 changes: 19 additions & 1 deletion src/resolve/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::{
self, CInteger, CIntegerAssumptions, ConformBehavior, Language, Settings, UnaryOperator,
},
resolve::{
ensure_initialized,
error::ResolveErrorKind,
expr::{
call::resolve_call_expr, conditional::resolve_conditional_expr,
Expand Down Expand Up @@ -425,3 +424,22 @@ pub fn resolve_expr(

Ok(resolved_expr)
}

fn ensure_initialized(
subject: &ast::Expr,
resolved_subject: &TypedExpr,
) -> Result<(), ResolveError> {
if resolved_subject.is_initialized {
Ok(())
} else {
Err(match &subject.kind {
ast::ExprKind::Variable(variable_name) => {
ResolveErrorKind::CannotUseUninitializedVariable {
variable_name: variable_name.to_string(),
}
}
_ => ResolveErrorKind::CannotUseUninitializedValue,
}
.at(subject.source))
}
}
5 changes: 5 additions & 0 deletions src/resolve/initialized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Copy, Clone, Debug)]
pub enum Initialized {
Require,
AllowUninitialized,
}
16 changes: 16 additions & 0 deletions src/resolve/job.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::{
resolved::{self, EnumRef, StructureRef, TypeAliasRef},
workspace::fs::FsNodeId,
};

pub enum FuncJob {
Regular(FsNodeId, usize, resolved::FunctionRef),
}

#[derive(Clone, Debug)]
pub struct TypeJob {
pub physical_file_id: FsNodeId,
pub type_aliases: Vec<TypeAliasRef>,
pub structures: Vec<StructureRef>,
pub enums: Vec<EnumRef>,
}
Loading

0 comments on commit 605be09

Please sign in to comment.