Skip to content

Commit

Permalink
Add token span to AnyEnt and to symbols documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Schottkyc137 committed Feb 24, 2024
1 parent 924ab79 commit 2700f66
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 124 deletions.
5 changes: 4 additions & 1 deletion vhdl_lang/src/analysis/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl<'a> AnalyzeContext<'a> {
parent,
AnyEntKind::Concurrent(statement.statement.item.label_typ()),
Some(label.pos()),
None,
);
statement.label.decl.set(ent.id());
scope.add(ent, diagnostics);
Expand All @@ -60,6 +61,7 @@ impl<'a> AnalyzeContext<'a> {
Related::None,
AnyEntKind::Concurrent(statement.statement.item.label_typ()),
None,
None,
);
statement.label.decl.set(ent.id());
}
Expand Down Expand Up @@ -136,7 +138,7 @@ impl<'a> AnalyzeContext<'a> {
let typ = as_fatal(self.drange_type(scope, discrete_range, diagnostics))?;
let nested = scope.nested();
nested.add(
index_name.define(self.arena, parent, AnyEntKind::LoopParameter(typ)),
index_name.define(self.arena, parent, AnyEntKind::LoopParameter(typ), None),
diagnostics,
);
self.analyze_generate_body(&nested, parent, body, diagnostics)?;
Expand Down Expand Up @@ -239,6 +241,7 @@ impl<'a> AnalyzeContext<'a> {
self.arena,
parent,
AnyEntKind::Concurrent(Some(Concurrent::Generate)),
None,
);
scope.add(ent, diagnostics);
inner_parent = ent;
Expand Down
33 changes: 24 additions & 9 deletions vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,21 @@ impl<'a> AnalyzeContext<'a> {
let full_definiton =
find_full_type_definition(type_decl.ident.name(), remaining);

let decl_pos = match full_definiton {
Some(full_decl) => full_decl.ident.pos(),
let (decl_pos, span) = match full_definiton {
Some(full_decl) => {
(full_decl.ident.pos(), Some(full_decl.span))
}
None => {
let mut error = Diagnostic::error(
type_decl.ident.pos(),
format!(
"Missing full type declaration of incomplete type '{}'",
type_decl.ident.name()
),
"Missing full type declaration of incomplete type '{}'",
type_decl.ident.name()
),
);
error.add_related(type_decl.ident.pos(), "The full type declaration shall occur immediately within the same declarative part");
diagnostics.push(error);
type_decl.ident.pos()
(type_decl.ident.pos(), None)
}
};

Expand All @@ -155,6 +157,7 @@ impl<'a> AnalyzeContext<'a> {
parent,
AnyEntKind::Type(Type::Incomplete),
Some(decl_pos),
span,
);
reference.set_unique_reference(ent);

Expand Down Expand Up @@ -213,7 +216,7 @@ impl<'a> AnalyzeContext<'a> {
name,
subtype_indication,
signature,
span: _,
span,
} = alias;

let resolved_name = self.name_resolve(scope, &name.pos, &mut name.item, diagnostics);
Expand Down Expand Up @@ -298,7 +301,7 @@ impl<'a> AnalyzeContext<'a> {
}
};

Ok(designator.define(self.arena, parent, kind))
Ok(designator.define(self.arena, parent, kind, Some(*span)))
}

pub(crate) fn analyze_declaration(
Expand All @@ -308,6 +311,7 @@ impl<'a> AnalyzeContext<'a> {
decl: &mut Declaration,
diagnostics: &mut dyn DiagnosticHandler,
) -> FatalResult {
let src_span = decl.span();
match decl {
Declaration::Alias(alias) => {
if let Some(ent) =
Expand All @@ -323,6 +327,7 @@ impl<'a> AnalyzeContext<'a> {
implicit.designator().clone(),
AnyEntKind::Overloaded(Overloaded::Alias(implicit)),
ent.decl_pos(),
ent.src_span,
);
scope.add(impicit_alias, diagnostics);
}
Expand Down Expand Up @@ -389,6 +394,7 @@ impl<'a> AnalyzeContext<'a> {
},
kind,
Some(object_decl.ident.tree.pos().clone()),
Some(src_span),
);
object_decl.ident.decl.set(object_ent.id());

Expand Down Expand Up @@ -419,7 +425,8 @@ impl<'a> AnalyzeContext<'a> {

if let Some(subtype) = subtype {
scope.add(
self.arena.define(ident, parent, AnyEntKind::File(subtype)),
self.arena
.define(ident, parent, AnyEntKind::File(subtype), Some(src_span)),
diagnostics,
);
}
Expand All @@ -430,6 +437,7 @@ impl<'a> AnalyzeContext<'a> {
&mut component.ident,
parent,
AnyEntKind::Component(Region::default()),
Some(src_span),
);
self.analyze_interface_list(
&nested,
Expand Down Expand Up @@ -458,6 +466,7 @@ impl<'a> AnalyzeContext<'a> {
&mut attr_decl.ident,
parent,
AnyEntKind::Attribute(typ),
Some(src_span),
),
diagnostics,
);
Expand Down Expand Up @@ -527,6 +536,7 @@ impl<'a> AnalyzeContext<'a> {
FormalRegion::new_params(),
None,
))),
Some(src_span),
);
let referenced_name = &mut instance.subprogram_name;
if let Some(name) = as_fatal(self.name_resolve(
Expand Down Expand Up @@ -559,6 +569,7 @@ impl<'a> AnalyzeContext<'a> {
&mut instance.ident,
parent,
AnyEntKind::Design(Design::PackageInstance(Region::default())),
Some(src_span),
);

if let Some(pkg_region) =
Expand Down Expand Up @@ -769,6 +780,7 @@ impl<'a> AnalyzeContext<'a> {
&mut file_decl.ident,
parent,
AnyEntKind::InterfaceFile(file_type.type_mark().to_owned()),
None,
)
}
InterfaceDeclaration::Object(ref mut object_decl) => {
Expand Down Expand Up @@ -805,13 +817,15 @@ impl<'a> AnalyzeContext<'a> {
subtype,
has_default: object_decl.expression.is_some(),
}),
None,
)
}
InterfaceDeclaration::Type(ref mut ident) => {
let typ = TypeEnt::from_any(self.arena.define(
ident,
parent,
AnyEntKind::Type(Type::Interface),
None,
))
.unwrap();

Expand Down Expand Up @@ -851,6 +865,7 @@ impl<'a> AnalyzeContext<'a> {
&mut instance.ident,
parent,
AnyEntKind::Design(Design::InterfacePackageInstance(package_region)),
None,
)
}
};
Expand Down
11 changes: 11 additions & 0 deletions vhdl_lang/src/analysis/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::analysis::names::ResolvedName;
use crate::ast::*;
use crate::data::*;
use crate::named_entity::*;
use crate::HasTokenSpan;
use analyze::*;

impl<'a> AnalyzeContext<'a> {
Expand Down Expand Up @@ -50,6 +51,7 @@ impl<'a> AnalyzeContext<'a> {
self.work_library(),
AnyEntKind::Design(Design::Entity(Visibility::default(), Region::default())),
Some(unit.pos()),
Some(unit.span()),
);

unit.ident.decl.set(ent.id());
Expand Down Expand Up @@ -89,6 +91,7 @@ impl<'a> AnalyzeContext<'a> {
unit: &mut ConfigurationDeclaration,
diagnostics: &mut dyn DiagnosticHandler,
) -> FatalResult {
let src_span = unit.span();
let root_region = Scope::default();
self.add_implicit_context_clause(&root_region)?;
self.analyze_context_clause(&root_region, &mut unit.context_clause, diagnostics)?;
Expand Down Expand Up @@ -117,6 +120,7 @@ impl<'a> AnalyzeContext<'a> {
&mut unit.ident,
self.work_library(),
AnyEntKind::Design(Design::Configuration),
Some(src_span),
);

Ok(())
Expand All @@ -132,6 +136,7 @@ impl<'a> AnalyzeContext<'a> {
self.work_library(),
AnyEntKind::Design(Design::Package(Visibility::default(), Region::default())),
Some(unit.pos()),
Some(unit.span()),
);

unit.ident.decl.set(ent.id());
Expand Down Expand Up @@ -178,6 +183,7 @@ impl<'a> AnalyzeContext<'a> {
self.work_library(),
AnyEntKind::Design(Design::PackageInstance(Region::default())),
Some(unit.pos()),
Some(unit.span()),
);

unit.ident.decl.set(ent.id());
Expand Down Expand Up @@ -207,12 +213,14 @@ impl<'a> AnalyzeContext<'a> {
let root_scope = Scope::default();
self.add_implicit_context_clause(&root_scope)?;
let scope = root_scope.nested();
let src_span = unit.span();
self.analyze_context_clause(&scope, &mut unit.items, diagnostics)?;

self.arena.define(
&mut unit.ident,
self.work_library(),
AnyEntKind::Design(Design::Context(scope.into_region())),
Some(src_span),
);

Ok(())
Expand All @@ -223,6 +231,7 @@ impl<'a> AnalyzeContext<'a> {
unit: &mut ArchitectureBody,
diagnostics: &mut dyn DiagnosticHandler,
) -> FatalResult {
let src_span = unit.span();
let primary = match self.lookup_in_library(
self.work_library_name(),
&unit.entity_name.item.pos,
Expand Down Expand Up @@ -257,6 +266,7 @@ impl<'a> AnalyzeContext<'a> {
&mut unit.ident,
primary.into(),
AnyEntKind::Design(Design::Architecture(primary)),
Some(src_span),
);

root_scope.add(arch, diagnostics);
Expand Down Expand Up @@ -310,6 +320,7 @@ impl<'a> AnalyzeContext<'a> {
Related::DeclaredBy(primary.into()),
AnyEntKind::Design(Design::PackageBody),
Some(unit.ident.tree.pos.clone()),
Some(unit.span()),
);
unit.ident.decl.set(body.id());

Expand Down
8 changes: 4 additions & 4 deletions vhdl_lang/src/analysis/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'a> ResolvedName<'a> {
AnyEntKind::Overloaded(_) => {
return Err(
"Internal error. Unreachable as overloaded is handled outside".to_owned(),
)
);
}
AnyEntKind::File(_)
| AnyEntKind::InterfaceFile(_)
Expand All @@ -177,7 +177,7 @@ impl<'a> ResolvedName<'a> {
return Err(format!(
"{} cannot be selected from design unit",
ent.kind().describe()
))
));
}
};

Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'a> ResolvedName<'a> {
return Err(
"Internal error. Unreachable as overloded is handled outside this function"
.to_string(),
)
);
}
AnyEntKind::File(_)
| AnyEntKind::InterfaceFile(_)
Expand All @@ -230,7 +230,7 @@ impl<'a> ResolvedName<'a> {
return Err(format!(
"{} should never be looked up from the current scope",
ent.kind().describe()
))
));
}
};

Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/analysis/package_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ impl<'a> AnalyzeContext<'a> {
Related::InstanceOf(uninst),
AnyEntKind::Library, // Will be immediately overwritten below
decl_pos,
uninst.src_span,
);
let kind = self.map_kind(Some(inst), mapping, uninst.kind())?;
unsafe {
Expand Down
Loading

0 comments on commit 2700f66

Please sign in to comment.