Skip to content

Commit

Permalink
Can now concretize templates
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jun 23, 2024
1 parent f78e092 commit 3f68461
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/dev_aid/lsp/hover_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn hover(info: LocationInfo, linker: &Linker, file_data: &FileData) -> Vec<M
hover.gather_hover_infos(md, decl_id, decl.identifier_type.is_generative());
}
LocationInfo::InModule(_, md, _, InModule::NamedSubmodule(submod)) => {
let submodule = &linker.modules[submod.module_uuid];
let submodule = &linker.modules[submod.module_ref.id];

// Declaration's documentation
hover.documentation(&submod.documentation);
Expand Down
18 changes: 9 additions & 9 deletions src/dev_aid/lsp/tree_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl<'linker> From<LocationInfo<'linker>> for RefersTo {
result.global = Some(name_elem);
}
LocationInfo::Port(sm, md, p_id) => {
result.local = Some((sm.module_uuid, md.ports[p_id].declaration_instruction));
result.port = Some((sm.module_uuid, p_id))
result.local = Some((sm.module_ref.id, md.ports[p_id].declaration_instruction));
result.port = Some((sm.module_ref.id, p_id))
}
LocationInfo::Interface(md_id, _md, i_id, _interface) => {
result.interface = Some((md_id, i_id))
Expand All @@ -77,7 +77,7 @@ impl RefersTo {
LocationInfo::InModule(md_id, _, obj, _) => self.local == Some((md_id, obj)),
LocationInfo::Type(_) => false,
LocationInfo::Global(ne) => self.global == Some(ne),
LocationInfo::Port(sm, _, p_id) => self.port == Some((sm.module_uuid, p_id)),
LocationInfo::Port(sm, _, p_id) => self.port == Some((sm.module_ref.id, p_id)),
LocationInfo::Interface(md_id, _, i_id, _) => self.interface == Some((md_id, i_id))
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'linker, Visitor : FnMut(Span, LocationInfo<'linker>), Pruner : Fn(Span) ->
WireReferenceRoot::SubModulePort(port) => {
if let Some(span) = port.port_name_span {
let sm_instruction = md.instructions[port.submodule_decl].unwrap_submodule();
let submodule = &self.linker.modules[sm_instruction.module_uuid];
let submodule = &self.linker.modules[sm_instruction.module_ref.id];
self.visit(span, LocationInfo::Port(sm_instruction, submodule, port.port));

// port_name_span being enabled means submodule_name_span is for sure
Expand All @@ -177,8 +177,8 @@ impl<'linker, Visitor : FnMut(Span, LocationInfo<'linker>), Pruner : Fn(Span) ->
(self.visitor)(typ_expr_span, LocationInfo::Type(typ_expr));
match typ_expr {
WrittenType::Error(_) => {}
WrittenType::Named(span, name_id) => {
self.visit(*span, LocationInfo::Global(NameElem::Type(*name_id)));
WrittenType::Named(named_type) => {
self.visit(named_type.span, LocationInfo::Global(NameElem::Type(named_type.id)));
}
WrittenType::Array(_, arr_box) => {
let (arr_content_typ, _size_id, _br_span) = arr_box.deref();
Expand All @@ -195,9 +195,9 @@ impl<'linker, Visitor : FnMut(Span, LocationInfo<'linker>), Pruner : Fn(Span) ->
let submodule = md.instructions[submodule_instruction].unwrap_submodule();
self.visit(submod_name_span, LocationInfo::InModule(md_id, md, submodule_instruction, InModule::NamedSubmodule(submodule)));
if iref.interface_span != submod_name_span {
let submod_md = &self.linker.modules[submodule.module_uuid];
let submod_md = &self.linker.modules[submodule.module_ref.id];
let interface = &submod_md.interfaces[iref.submodule_interface];
self.visit(iref.interface_span, LocationInfo::Interface(submodule.module_uuid, submod_md, iref.submodule_interface, interface));
self.visit(iref.interface_span, LocationInfo::Interface(submodule.module_ref.id, submod_md, iref.submodule_interface, interface));
}
}
}
Expand All @@ -217,7 +217,7 @@ impl<'linker, Visitor : FnMut(Span, LocationInfo<'linker>), Pruner : Fn(Span) ->
for (id, inst) in &md.instructions {
match inst {
Instruction::SubModule(sm) => {
self.visit(sm.module_name_span, LocationInfo::Global(NameElem::Module(sm.module_uuid)));
self.visit(sm.module_ref.span, LocationInfo::Global(NameElem::Module(sm.module_ref.id)));
if let Some((_sm_name, sm_name_span)) = &sm.name {
self.visit(*sm_name_span, LocationInfo::InModule(md_id, md, id, InModule::NamedSubmodule(sm)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl ErrorInfoObject for SubModuleInstance {
if let Some((name, span)) = &self.name {
(*span, format!("{name} declared here"))
} else {
(self.module_name_span, "Used here".to_owned())
(self.module_ref.span, "Used here".to_owned())
}
}
}
Expand Down
38 changes: 24 additions & 14 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Module {

pub fn get_instruction_span(&self, instr_id : FlatID) -> Span {
match &self.instructions[instr_id] {
Instruction::SubModule(sm) => sm.module_name_span,
Instruction::SubModule(sm) => sm.module_ref.span,
Instruction::FuncCall(fc) => fc.whole_func_span,
Instruction::Declaration(decl) => decl.decl_span,
Instruction::Wire(w) => w.span,
Expand Down Expand Up @@ -413,24 +413,32 @@ impl WireSource {
}
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct GlobalReference<ID> {
pub span: Span,
pub id: ID,
pub template_args: FlatAlloc<Option<TemplateArg>, TemplateIDMarker>,
pub template_span: Option<BracketSpan>
}

#[derive(Debug)]
pub enum WrittenType {
Error(Span),
Named(Span, TypeUUID),
Named(GlobalReference<TypeUUID>),
Array(Span, Box<(WrittenType, FlatID, BracketSpan)>)
}

impl WrittenType {
pub fn get_span(&self) -> Span {
match self {
WrittenType::Error(span) | WrittenType::Named(span, _) | WrittenType::Array(span, _) => *span
WrittenType::Error(span) | WrittenType::Named(GlobalReference { span, ..}) | WrittenType::Array(span, _) => *span
}
}

pub fn to_type(&self) -> AbstractType {
match self {
WrittenType::Error(_) => AbstractType::Error,
WrittenType::Named(_, id) => AbstractType::Named(*id),
WrittenType::Named(named_type) => AbstractType::Named(named_type.id),
WrittenType::Array(_, arr_box) => {
let (elem_typ, _arr_idx, _br_span) = arr_box.deref();
AbstractType::Array(Box::new(elem_typ.to_type()))
Expand All @@ -440,7 +448,7 @@ impl WrittenType {

pub fn for_each_generative_input<F : FnMut(FlatID)>(&self, mut f : F) {
match self {
WrittenType::Error(_) | WrittenType::Named(_, _) => {}
WrittenType::Error(_) | WrittenType::Named(_) => {}
WrittenType::Array(_span, arr_box) => {
f(arr_box.deref().1)
}
Expand All @@ -452,8 +460,8 @@ impl WrittenType {
WrittenType::Error(_) => {
"{error}".to_owned()
}
WrittenType::Named(_, id) => {
linker_types[*id].get_full_name()
WrittenType::Named(named_type) => {
linker_types[named_type.id].get_full_name()
}
WrittenType::Array(_, sub) => sub.deref().0.to_string(linker_types) + "[]",
}
Expand Down Expand Up @@ -522,22 +530,24 @@ pub enum TemplateInputKind {
Generative{decl_span : Span, declaration_instruction : FlatID}
}


#[derive(Debug)]
pub struct TemplateArg {
pub name_specification : Option<Span>,
pub whole_span : Span,
pub typ : TemplateArgType
pub kind : TemplateArgKind
}

pub enum TemplateArgType {
#[derive(Debug)]
pub enum TemplateArgKind {
Type(WrittenType),
Value(FlatID)
}


#[derive(Debug)]
pub struct SubModuleInstance {
pub module_uuid : ModuleUUID,
pub module_name_span : Span,
pub module_ref : GlobalReference<ModuleUUID>,
/// Name is not always present in source code. Such as in inline function call syntax: my_mod(a, b, c)
pub name : Option<(String, Span)>,
pub declaration_runtime_depth : usize,
Expand Down Expand Up @@ -641,8 +651,8 @@ impl Instruction {
}


#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum ModuleOrWrittenType {
WrittenType(WrittenType),
Module(Span, ModuleUUID)
Module(GlobalReference<ModuleUUID>)
}
Loading

0 comments on commit 3f68461

Please sign in to comment.