Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- The server will no longer send an LSP warning if dml-builtins is not found, instead relying on the client to perform this task
- Fixed incorrect handling of explicit in-object constructs, correcting ranges of some error reports and detection of some linting errors
- Fixed an issue where the server would sometimes report `progress end` too early
- Fixed reference-matching for `extern` declarations, goto-functionality around these declarations will now work correctly

## 0.9.20
- Made GetKnownContexts custom request not wait for analysis results by default, reducing the chances of overfilling workpool capacity while analysises are running.
Expand Down
13 changes: 8 additions & 5 deletions src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ impl DeviceAnalysis {
self.symbol_info.method_symbols
.get(m.location())
.and_then(|m|m.get(&parent.key)),
DMLShallowObjectVariant::Extern(e) =>
self.symbol_info.variable_symbols.get(e.loc_span()),
DMLShallowObjectVariant::Session(s) |
DMLShallowObjectVariant::Saved(s) =>
self.symbol_info.variable_symbols.get(s.loc_span()),
Expand Down Expand Up @@ -1110,7 +1112,6 @@ impl DeviceAnalysis {
}
}
// TODO: types
// TODO: externs
}

fn lookup_global_from_ref(&self,
Expand Down Expand Up @@ -1187,8 +1188,6 @@ impl DeviceAnalysis {
},
// TODO: DMLType lookup
DMLSymbolKind::Typedef => Ok(vec![]),
// TODO: Extern lookup
DMLSymbolKind::Extern => Ok(vec![]),
e => {
Err(format!("Unexpected symbol kind of global symbol: {:?}", e))
},
Expand All @@ -1200,8 +1199,7 @@ impl DeviceAnalysis {
sym: &ContextedSymbol<'t>,
limitations: &mut HashSet<DLSLimitation>)
-> Result<Vec<SymbolRef>, String> {
if matches!(sym.symbol.kind, DMLSymbolKind::Template |
DMLSymbolKind::Typedef | DMLSymbolKind::Extern)
if matches!(sym.symbol.kind, DMLSymbolKind::Template | DMLSymbolKind::Typedef)
{
return self.lookup_global_sym(sym.symbol);
}
Expand Down Expand Up @@ -2059,6 +2057,10 @@ fn add_new_symbol_from_shallow(maker: &SymbolMaker,
(vec![*constant.loc_span()],
vec![*constant.loc_span()],
vec![*constant.loc_span()]),
DMLShallowObjectVariant::Extern(e) =>
(vec![*e.loc_span()],
vec![*e.loc_span()],
vec![*e.loc_span()]),
DMLShallowObjectVariant::Session(data) |
DMLShallowObjectVariant::Saved(data) =>
(vec![*data.declaration.loc_span()],
Expand Down Expand Up @@ -2094,6 +2096,7 @@ fn add_new_symbol_from_shallow(maker: &SymbolMaker,
DMLShallowObjectVariant::Method(method_ref) => {
internal_error!("Unreachable method_ref case reached, ignored. ({:?})", method_ref);
},
DMLShallowObjectVariant::Extern(_) |
DMLShallowObjectVariant::Constant(_) |
DMLShallowObjectVariant::Session(_) |
DMLShallowObjectVariant::Saved(_) |
Expand Down
43 changes: 29 additions & 14 deletions src/analysis/parsing/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,30 @@ pub fn parse_vardecl(context: &ParseContext, stream: &mut FileParser<'_>, file_i
}
}

// session, saved, and extern
#[derive(Debug, Clone, PartialEq)]
pub struct ExternContent {
pub kind: LeafToken,
pub cdecl: CDecl,
pub semi: LeafToken,
}

impl TreeElement for ExternContent {
fn range(&self) -> ZeroRange {
Range::combine(
self.kind.range(),
self.semi.range())
}
fn subs(&self) -> TreeElements<'_> {
create_subs!(&self.kind,
&self.cdecl,
&self.semi)
}
fn post_parse_sanity(&self, _file: &TextFile) -> Vec<LocalDMLError> {
self.cdecl.ensure_named()
}
}

// session, saved
#[derive(Debug, Clone, PartialEq)]
pub struct VariableContent {
pub kind: LeafToken,
Expand Down Expand Up @@ -544,19 +567,11 @@ impl Parse<DMLObjectContent> for VariableContent {
fn parse_extern(
externtok: LeafToken, context: &ParseContext, stream: &mut FileParser<'_>, file_info: &FileInfo)
-> DMLObject {
let (mut outer, mut inner) = object_contexts(context);
let cdecl = VarDecl::One(CDecl::parse(&inner, stream, file_info));
let initializer = match inner.peek_kind(stream) {
Some(TokenKind::Assign) => {
let assign = inner.next_leaf(stream);
let initializer = Initializer::parse(&inner, stream, file_info);
Some((assign, initializer))
},
_ => None,
};
let (mut outer, inner) = object_contexts(context);
let cdecl = CDecl::parse(&inner, stream, file_info);
let semi = outer.expect_next_kind(stream, TokenKind::SemiColon);
DMLObjectContent::Extern(VariableContent {
kind: externtok, cdecl, initializer, semi
DMLObjectContent::Extern(ExternContent {
kind: externtok, cdecl, semi
}).into()
}
Comment thread
JonatanWaern marked this conversation as resolved.
Resolved

Expand Down Expand Up @@ -1885,7 +1900,7 @@ pub enum DMLObjectContent {
DMLVersion(DMLVersionContent),
ErrorObject(ErrorObjectContent),
Export(ExportContent),
Extern(VariableContent),
Extern(ExternContent),
Event(CompositeObjectContent),
Field(FieldContent),
Footer(CBlockContent),
Expand Down
41 changes: 36 additions & 5 deletions src/analysis/structure/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ impl SymbolContainer for DMLStatement {
vec![con as &dyn StructureSymbol],
DMLStatement::Object(DMLObject::Parameter(param)) =>
vec![param as &dyn StructureSymbol],
DMLStatement::Object(DMLObject::Extern(ext)) =>
vec![ext as &dyn StructureSymbol],
DMLStatement::HashIf(hashif) => hashif.symbols(),
_ => vec![]
}
Expand Down Expand Up @@ -1343,6 +1345,38 @@ fn to_variable_decl_structure<'a>(content: &misc::CDecl,
})
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Extern {
pub var: VariableDecl,
pub span: ZeroSpan,
}

impl DMLNamed for Extern {
fn name(&self) -> &DMLString {
self.var.name()
}
}

impl DeclarationSpan for Extern {
fn span(&self) -> &ZeroSpan {
&self.span
}
}

impl StructureSymbol for Extern {
fn kind(&self) -> DMLSymbolKind {
DMLSymbolKind::Extern
}
}

pub fn to_extern_structure<'a>(extrn: &structure::ExternContent,
report: &mut Vec<LocalDMLError>,
file: FileSpec<'a>) -> Option<Extern> {
let var = to_variable_decl_structure(&extrn.cdecl, VariableDeclKind::Extern, report, file)?;
let span = ZeroSpan::from_range(extrn.range(), file.path);
Some(Extern { var, span })
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Variable {
pub vars: Vec<VariableDecl>,
Expand Down Expand Up @@ -1513,7 +1547,7 @@ pub enum DMLObject {
Device(Device),
Version(Version),
Export(Export),
Extern(Variable),
Extern(Extern),
Footer(CBlock),
Header(CBlock),
Hook(Hook),
Expand Down Expand Up @@ -1613,10 +1647,7 @@ fn to_objectstatement<'a>(content: &structure::DMLObjectContent,
Export::to_structure(con, report, file)?))),
structure::DMLObjectContent::Extern(con) =>
DMLStatementKind::Statement(DMLStatement::Object(DMLObject::Extern(
to_variable_structure(&con.cdecl,
con.initializer.as_ref().map(|(_,i)|i),
VariableDeclKind::Extern,
report, file)?))),
to_extern_structure(con, report, file)?))),
structure::DMLObjectContent::Event(con) =>
DMLStatementKind::Statement(DMLStatement::Object(
DMLObject::CompositeObject(
Expand Down
12 changes: 7 additions & 5 deletions src/analysis/structure/toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;
use crate::analysis::templating::evaluation::{Evaluatable, EvaluationContext};
use crate::logging::trace;

use crate::analysis::structure::objects::{Bitorder, CBlock, CompObjectKind, CompositeObject, Constant, DMLObject, DMLStatement, Device, Error, Export, Hook, Import, InEach, Instantiation, Loggroup, Method, MethodModifier, Parameter, Statements, Template, ToStructure, Typedef, Variable, Version, make_statements};
use crate::analysis::structure::objects::{Bitorder, CBlock, CompObjectKind, CompositeObject, Constant, DMLObject, DMLStatement, Device, Error, Export, Extern, Hook, Import, InEach, Instantiation, Loggroup, Method, MethodModifier, Parameter, Statements, Template, ToStructure, Typedef, Variable, Version, make_statements};
use crate::analysis::structure::expressions::{Expression};
use crate::analysis::{DMLError, FileSpec, LocationRange};
use crate::analysis::parsing::tree::{ZeroRange, ZeroSpan, TreeElement};
Expand Down Expand Up @@ -394,6 +394,7 @@ pub struct StatementSpec {
pub imports: Vec<ObjectDecl<Import>>,
pub errors: Vec<ObjectDecl<Error>>,
pub constants: Vec<ObjectDecl<Constant>>,
pub externs: Vec<Extern>,
}

impl SymbolContainer for StatementSpec {
Expand All @@ -405,6 +406,7 @@ impl SymbolContainer for StatementSpec {
symbols.append(&mut self.methods.to_symbols());
symbols.append(&mut self.constants.to_symbols());
symbols.append(&mut self.hooks.to_symbols());
symbols.append(&mut self.externs.to_symbols());
symbols
}
}
Expand Down Expand Up @@ -442,6 +444,7 @@ impl StatementSpec {
saveds: vec![],
params: vec![],
constants: vec![],
externs: vec![],
methods: vec![],
hooks: vec![],
instantiations: vec![],
Expand Down Expand Up @@ -550,7 +553,7 @@ fn flatten_hashif_branch(context: StatementContext,
DMLObject::Extern(ext) =>
report.push(LocalDMLError {
range:
ext.vars.first().unwrap().object.name.span.range,
ext.var.object.name.span.range,
description: format!(
"Extern declaration not allowed in {}",
context),
Expand Down Expand Up @@ -729,6 +732,7 @@ fn flatten_hashif_branch(context: StatementContext,
errors,
templates,
imports,
externs: vec![],
}
}

Expand All @@ -744,7 +748,6 @@ pub struct TopLevel {
pub bitorder: Option<Bitorder>,
pub loggroups: Vec<Loggroup>,
pub cblocks: Vec<CBlock>,
pub externs: Vec<Variable>,
pub typedefs: Vec<Typedef>,
pub references: Vec<Reference>,
pub spec: StatementSpec,
Expand Down Expand Up @@ -1007,7 +1010,7 @@ impl TopLevel {
let spec = StatementSpec {
objects, instantiations, ineachs, errors, imports,
saveds, sessions, params, constants, methods, exports, hooks,
templates,
templates, externs,
};
let mut references = vec![];
ast.references(&mut references, filespec);
Expand All @@ -1026,7 +1029,6 @@ impl TopLevel {
version,
device,
cblocks,
externs,
typedefs,
bitorder,
loggroups,
Expand Down
Loading
Loading