Skip to content

Commit

Permalink
Bounded generic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Aug 28, 2024
1 parent 656eb70 commit 6db45a9
Show file tree
Hide file tree
Showing 45 changed files with 21,103 additions and 19,506 deletions.
13 changes: 2 additions & 11 deletions crates/analyzer/src/analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod check_variable_type;
use crate::analyzer::resource_table::PathId;
use crate::analyzer_error::AnalyzerError;
use crate::assign::{AssignPath, AssignPosition, AssignPositionTree, AssignPositionType};
Expand All @@ -13,7 +12,6 @@ use crate::symbol::{
};
use crate::symbol_table;
use crate::type_dag;
use check_variable_type::*;
use itertools::Itertools;
use std::path::Path;
use veryl_metadata::{Build, Lint, Metadata};
Expand Down Expand Up @@ -75,12 +73,6 @@ impl<'a> AnalyzerPass3<'a> {
}
}

pub fn check_variable_type(&self, input: &Veryl) -> Vec<AnalyzerError> {
let mut check_variable_type = CheckVariableType::new(self.text);
check_variable_type.veryl(input);
check_variable_type.errors
}

pub fn check_variables(&self) -> Vec<AnalyzerError> {
let mut ret = Vec::new();

Expand Down Expand Up @@ -245,13 +237,12 @@ impl Analyzer {
project_name: &str,
text: &str,
path: T,
input: &Veryl,
_input: &Veryl,
) -> Vec<AnalyzerError> {
let mut ret = Vec::new();

namespace_table::set_default(&[project_name.into()]);
let pass3 = AnalyzerPass3::new(path.as_ref(), text);
ret.append(&mut pass3.check_variable_type(input));
ret.append(&mut pass3.check_variables());
ret.append(&mut pass3.check_assignment());

Expand Down Expand Up @@ -386,7 +377,7 @@ fn traverse_assignable_symbol(id: SymbolId, path: &AssignPath) -> Vec<AssignPath

if let Some(symbol) = symbol_table::get(id) {
match &symbol.kind {
SymbolKind::Port(x) if is_assignable(&x.direction) => {
SymbolKind::Port(x) if is_assignable(&x.direction) && !x.is_proto => {
if let Some(ref x) = x.r#type {
if let TypeKind::UserDefined(ref x) = x.kind {
if let Ok(symbol) = symbol_table::resolve((x, &symbol.namespace)) {
Expand Down
191 changes: 0 additions & 191 deletions crates/analyzer/src/analyzer/check_variable_type.rs

This file was deleted.

33 changes: 33 additions & 0 deletions crates/analyzer/src/analyzer_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ pub enum AnalyzerError {
error_location: SourceSpan,
},

#[diagnostic(
severity(Error),
code(incompat_proto),
help(""),
url("https://doc.veryl-lang.org/book/07_appendix/02_semantic_error.html#incompat_proto")
)]
#[error("{identifier} is incompatible with {proto} because {cause}")]
IncompatProto {
identifier: String,
proto: String,
cause: String,
#[source_code]
input: NamedSource<String>,
#[label("Error location")]
error_location: SourceSpan,
},

#[diagnostic(
severity(Error),
code(missing_default_argument),
Expand Down Expand Up @@ -1195,6 +1212,22 @@ impl AnalyzerError {
}
}

pub fn incompat_proto(
identifier: &str,
proto: &str,
cause: &str,
source: &str,
token: &TokenRange,
) -> Self {
AnalyzerError::IncompatProto {
identifier: identifier.into(),
proto: proto.into(),
cause: cause.into(),
input: AnalyzerError::named_source(source, token),
error_location: token.into(),
}
}

pub fn missing_default_argument(identifier: &str, source: &str, token: &TokenRange) -> Self {
AnalyzerError::MissingDefaultArgument {
identifier: identifier.into(),
Expand Down
18 changes: 12 additions & 6 deletions crates/analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ pub mod check_enum;
pub mod check_expression;
pub mod check_function;
pub mod check_identifier;
pub mod check_instance;
pub mod check_modport;
pub mod check_msb_lsb;
pub mod check_number;
pub mod check_proto;
pub mod check_statement;
pub mod check_type;
pub mod check_unsafe;
pub mod create_reference;
pub mod create_symbol_table;
Expand All @@ -26,11 +27,12 @@ use check_enum::*;
use check_expression::*;
use check_function::*;
use check_identifier::*;
use check_instance::*;
use check_modport::*;
use check_msb_lsb::*;
use check_number::*;
use check_proto::*;
use check_statement::*;
use check_type::*;
use check_unsafe::*;
use create_reference::*;
use create_symbol_table::*;
Expand Down Expand Up @@ -97,14 +99,15 @@ pub struct Pass2Handlers<'a> {
check_enum: CheckEnum<'a>,
check_modport: CheckModport<'a>,
check_function: CheckFunction<'a>,
check_instance: CheckInstance<'a>,
check_type: CheckType<'a>,
check_msb_lsb: CheckMsbLsb<'a>,
check_assignment: CheckAssignment<'a>,
check_clock_reset: CheckClockReset<'a>,
create_reference: CreateReference<'a>,
create_type_dag: CreateTypeDag<'a>,
check_expression: CheckExpression<'a>,
check_clock_domain: CheckClockDomain<'a>,
check_proto: CheckProto<'a>,
}

impl<'a> Pass2Handlers<'a> {
Expand All @@ -113,14 +116,15 @@ impl<'a> Pass2Handlers<'a> {
check_enum: CheckEnum::new(text),
check_modport: CheckModport::new(text),
check_function: CheckFunction::new(text),
check_instance: CheckInstance::new(text),
check_type: CheckType::new(text),
check_msb_lsb: CheckMsbLsb::new(text),
check_assignment: CheckAssignment::new(text),
check_clock_reset: CheckClockReset::new(text),
create_reference: CreateReference::new(text),
create_type_dag: CreateTypeDag::new(text),
check_expression: CheckExpression::new(text),
check_clock_domain: CheckClockDomain::new(text),
check_proto: CheckProto::new(text),
}
}

Expand All @@ -129,14 +133,15 @@ impl<'a> Pass2Handlers<'a> {
&mut self.check_enum as &mut dyn Handler,
&mut self.check_modport as &mut dyn Handler,
&mut self.check_function as &mut dyn Handler,
&mut self.check_instance as &mut dyn Handler,
&mut self.check_type as &mut dyn Handler,
&mut self.check_msb_lsb as &mut dyn Handler,
&mut self.check_assignment as &mut dyn Handler,
&mut self.check_clock_reset as &mut dyn Handler,
&mut self.create_reference as &mut dyn Handler,
&mut self.create_type_dag as &mut dyn Handler,
&mut self.check_expression as &mut dyn Handler,
&mut self.check_clock_domain as &mut dyn Handler,
&mut self.check_proto as &mut dyn Handler,
]
}

Expand All @@ -145,14 +150,15 @@ impl<'a> Pass2Handlers<'a> {
ret.append(&mut self.check_enum.errors);
ret.append(&mut self.check_modport.errors);
ret.append(&mut self.check_function.errors);
ret.append(&mut self.check_instance.errors);
ret.append(&mut self.check_type.errors);
ret.append(&mut self.check_msb_lsb.errors);
ret.append(&mut self.check_assignment.errors);
ret.append(&mut self.check_clock_reset.errors);
ret.append(&mut self.create_reference.errors);
ret.append(&mut self.create_type_dag.errors);
ret.append(&mut self.check_expression.errors);
ret.append(&mut self.check_clock_domain.errors);
ret.append(&mut self.check_proto.errors);
ret
}
}
1 change: 1 addition & 0 deletions crates/analyzer/src/handlers/check_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl<'a> VerylGrammarTrait for CheckExpression<'a> {
}
}
SymbolKind::Module(_)
| SymbolKind::ProtoModule(_)
| SymbolKind::Interface(_)
| SymbolKind::Instance(_)
| SymbolKind::Block
Expand Down
Loading

0 comments on commit 6db45a9

Please sign in to comment.