mod display;
mod util;
#[macro_use]
mod any_design_unit;
#[macro_use]
pub mod search;
pub(crate) use self::util::*;
pub(crate) use any_design_unit::*;
use crate::data::*;
use crate::named_entity::{EntityId, Reference};
use crate::syntax::{Token, TokenAccess, TokenId};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum BaseSpecifier {
B,
O,
X,
UB,
UO,
UX,
SB,
SO,
SX,
D,
}
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
pub enum Operator {
And,
Or,
Nand,
Nor,
Xor,
Xnor,
Abs,
Not,
Minus,
Plus,
QueQue, EQ,
NE,
LT,
LTE,
GT,
GTE,
QueEQ,
QueNE,
QueLT,
QueLTE,
QueGT,
QueGTE,
SLL,
SRL,
SLA,
SRA,
ROL,
ROR,
Concat,
Times,
Div,
Mod,
Rem,
Pow,
}
#[derive(PartialEq, Debug, Clone)]
pub struct AttributeName {
pub name: WithPos<Name>,
pub signature: Option<WithPos<Signature>>,
pub attr: WithPos<AttributeDesignator>,
pub expr: Option<Box<WithPos<Expression>>>,
}
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
pub enum TypeAttribute {
Subtype,
Element,
}
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
pub enum RangeAttribute {
Range,
ReverseRange,
}
#[derive(PartialEq, Debug, Clone, Eq)]
pub enum AttributeDesignator {
Type(TypeAttribute),
Range(RangeAttribute),
Ident(WithRef<Symbol>),
Ascending,
Left,
Right,
High,
Low,
Length,
Image,
Value,
Pos,
Val,
Succ,
Pred,
LeftOf,
RightOf,
Signal(SignalAttribute),
SimpleName,
InstanceName,
PathName,
}
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
pub enum SignalAttribute {
Delayed,
Stable,
Quiet,
Transaction,
Event,
Active,
LastEvent,
LastActive,
LastValue,
Driving,
DrivingValue,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum ExternalObjectClass {
Constant,
Signal,
Variable,
}
impl From<ExternalObjectClass> for ObjectClass {
fn from(object: ExternalObjectClass) -> ObjectClass {
match object {
ExternalObjectClass::Constant => ObjectClass::Constant,
ExternalObjectClass::Variable => ObjectClass::Variable,
ExternalObjectClass::Signal => ObjectClass::Signal,
}
}
}
#[derive(PartialEq, Debug, Clone)]
pub enum ExternalPath {
Package(WithPos<Name>),
Absolute(WithPos<Name>),
Relative(WithPos<Name>, usize),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ExternalName {
pub class: ExternalObjectClass,
pub path: WithPos<ExternalPath>,
pub subtype: SubtypeIndication,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Name {
Designator(WithRef<Designator>),
Selected(Box<WithPos<Name>>, WithPos<WithRef<Designator>>),
SelectedAll(Box<WithPos<Name>>),
Slice(Box<WithPos<Name>>, Box<DiscreteRange>),
Attribute(Box<AttributeName>),
CallOrIndexed(Box<CallOrIndexed>),
External(Box<ExternalName>),
}
#[derive(PartialEq, Debug, Clone)]
pub struct CallOrIndexed {
pub name: WithPos<Name>,
pub parameters: Vec<AssociationElement>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Choice {
Expression(Expression),
DiscreteRange(DiscreteRange),
Others,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ElementAssociation {
Positional(WithPos<Expression>),
Named(Vec<WithPos<Choice>>, WithPos<Expression>),
}
#[derive(PartialEq, Debug, Clone)]
pub enum ActualPart {
Expression(Expression),
Open,
}
#[derive(PartialEq, Debug, Clone)]
pub struct AssociationElement {
pub formal: Option<WithPos<Name>>,
pub actual: WithPos<ActualPart>,
}
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum AbstractLiteral {
Integer(u64),
Real(f64),
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct BitString {
pub length: Option<u32>,
pub base: BaseSpecifier,
pub value: Latin1String,
}
#[derive(PartialEq, Debug, Clone)]
pub struct PhysicalLiteral {
pub value: AbstractLiteral,
pub unit: WithRef<Ident>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Literal {
String(Latin1String),
BitString(BitString),
Character(u8),
AbstractLiteral(AbstractLiteral),
Physical(PhysicalLiteral),
Null,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Allocator {
Qualified(QualifiedExpression),
Subtype(SubtypeIndication),
}
#[derive(PartialEq, Debug, Clone)]
pub struct QualifiedExpression {
pub type_mark: WithPos<TypeMark>,
pub expr: WithPos<Expression>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Expression {
Binary(
WithPos<WithRef<Operator>>,
Box<WithPos<Expression>>,
Box<WithPos<Expression>>,
),
Unary(WithPos<WithRef<Operator>>, Box<WithPos<Expression>>),
Aggregate(Vec<ElementAssociation>),
Qualified(Box<QualifiedExpression>),
Name(Box<Name>),
Literal(Literal),
New(Box<WithPos<Allocator>>),
}
pub type Ident = WithPos<Symbol>;
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum Direction {
Ascending,
Descending,
}
#[derive(PartialEq, Debug, Clone)]
pub enum DiscreteRange {
Discrete(WithPos<TypeMark>, Option<Range>),
Range(Range),
}
#[derive(PartialEq, Debug, Clone)]
pub struct RangeConstraint {
pub direction: Direction,
pub left_expr: Box<WithPos<Expression>>,
pub right_expr: Box<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Range {
Range(RangeConstraint),
Attribute(Box<AttributeName>),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ElementConstraint {
pub ident: Ident,
pub constraint: Box<WithPos<SubtypeConstraint>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum SubtypeConstraint {
Range(Range),
Array(Vec<DiscreteRange>, Option<Box<WithPos<SubtypeConstraint>>>),
Record(Vec<ElementConstraint>),
}
#[derive(PartialEq, Debug, Clone)]
pub struct RecordElementResolution {
pub ident: Ident,
pub resolution: Box<ResolutionIndication>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ResolutionIndication {
FunctionName(WithPos<Name>),
ArrayElement(WithPos<Name>),
Record(Vec<RecordElementResolution>),
Unresolved,
}
#[derive(PartialEq, Debug, Clone)]
pub struct TypeMark {
pub name: WithPos<Name>,
pub attr: Option<TypeAttribute>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct SubtypeIndication {
pub resolution: ResolutionIndication,
pub type_mark: WithPos<TypeMark>,
pub constraint: Option<WithPos<SubtypeConstraint>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ArrayIndex {
IndexSubtypeDefintion(WithPos<TypeMark>),
Discrete(DiscreteRange),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ElementDeclaration {
pub ident: WithDecl<Ident>,
pub subtype: SubtypeIndication,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ProtectedTypeDeclarativeItem {
Subprogram(SubprogramDeclaration),
}
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub enum Designator {
Identifier(Symbol),
OperatorSymbol(Operator),
Character(u8),
Anonymous(usize),
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct WithRef<T> {
pub item: T,
pub reference: Reference,
}
impl<T> WithRef<T> {
pub fn new(item: T) -> WithRef<T> {
WithRef {
item,
reference: Reference::undefined(),
}
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct WithDecl<T> {
pub tree: T,
pub decl: Reference,
}
impl<T> WithDecl<T> {
pub fn new(tree: T) -> WithDecl<T> {
WithDecl {
tree,
decl: Reference::undefined(),
}
}
}
impl<T> From<T> for WithDecl<T> {
fn from(value: T) -> Self {
WithDecl::new(value)
}
}
impl<T: AsRef<SrcPos>> AsRef<SrcPos> for WithDecl<T> {
fn as_ref(&self) -> &SrcPos {
self.tree.as_ref()
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct WithToken<T> {
item: T,
token: TokenId,
}
impl<T> WithToken<T> {
pub fn new(item: T, token: TokenId) -> WithToken<T> {
WithToken { item, token }
}
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct AliasDeclaration {
pub designator: WithDecl<WithPos<Designator>>,
pub subtype_indication: Option<SubtypeIndication>,
pub name: WithPos<Name>,
pub signature: Option<WithPos<Signature>>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct AttributeDeclaration {
pub ident: WithDecl<Ident>,
pub type_mark: WithPos<TypeMark>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct EntityTag {
pub designator: WithPos<WithRef<Designator>>,
pub signature: Option<WithPos<Signature>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum EntityName {
Name(EntityTag),
All,
Others,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum EntityClass {
Entity,
Architecture,
Configuration,
Procedure,
Function,
Package,
Type,
Subtype,
Constant,
Signal,
Variable,
Component,
Label,
Literal,
Units,
File,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct AttributeSpecification {
pub ident: WithRef<Ident>,
pub entity_name: EntityName,
pub entity_class: EntityClass,
pub expr: WithPos<Expression>,
}
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum Attribute {
Specification(AttributeSpecification),
Declaration(AttributeDeclaration),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ProtectedTypeDeclaration {
pub items: Vec<ProtectedTypeDeclarativeItem>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ProtectedTypeBody {
pub decl: Vec<Declaration>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct PhysicalTypeDeclaration {
pub range: Range,
pub primary_unit: WithDecl<Ident>,
pub secondary_units: Vec<(WithDecl<Ident>, PhysicalLiteral)>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum EnumerationLiteral {
Identifier(Symbol),
Character(u8),
}
#[derive(PartialEq, Debug, Clone)]
pub enum TypeDefinition {
Enumeration(Vec<WithDecl<WithPos<EnumerationLiteral>>>),
Numeric(Range),
Physical(PhysicalTypeDeclaration),
Array(Vec<ArrayIndex>, SubtypeIndication),
Record(Vec<ElementDeclaration>),
Access(SubtypeIndication),
Incomplete(Reference),
File(WithPos<TypeMark>),
Protected(ProtectedTypeDeclaration),
ProtectedBody(ProtectedTypeBody),
Subtype(SubtypeIndication),
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct TypeDeclaration {
pub ident: WithDecl<Ident>,
pub def: TypeDefinition,
pub end_ident_pos: Option<SrcPos>,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum ObjectClass {
Signal,
Constant,
Variable,
SharedVariable,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum InterfaceType {
Port,
Generic,
Parameter,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ObjectDeclaration {
pub class: ObjectClass,
pub ident: WithDecl<Ident>,
pub subtype_indication: SubtypeIndication,
pub expression: Option<WithPos<Expression>>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct FileDeclaration {
pub ident: WithDecl<Ident>,
pub subtype_indication: SubtypeIndication,
pub open_info: Option<WithPos<Expression>>,
pub file_name: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum SubprogramDesignator {
Identifier(Symbol),
OperatorSymbol(Operator),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ProcedureSpecification {
pub designator: WithDecl<WithPos<SubprogramDesignator>>,
pub header: Option<SubprogramHeader>,
pub param_tok: Option<TokenId>,
pub parameter_list: Vec<InterfaceDeclaration>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct FunctionSpecification {
pub pure: bool,
pub designator: WithDecl<WithPos<SubprogramDesignator>>,
pub header: Option<SubprogramHeader>,
pub param_tok: Option<TokenId>,
pub parameter_list: Vec<InterfaceDeclaration>,
pub return_type: WithPos<TypeMark>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct SubprogramBody {
pub specification: SubprogramSpecification,
pub declarations: Vec<Declaration>,
pub statements: Vec<LabeledSequentialStatement>,
pub end_ident_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct SubprogramHeader {
pub generic_tok: TokenId,
pub generic_list: Vec<InterfaceDeclaration>,
pub map_aspect: Option<MapAspect>,
}
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum SubprogramKind {
Function,
Procedure,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct SubprogramInstantiation {
pub kind: SubprogramKind,
pub ident: WithDecl<Ident>,
pub subprogram_name: WithPos<Name>,
pub signature: Option<WithPos<Signature>>,
pub generic_map: Option<MapAspect>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Signature {
Function(Vec<WithPos<TypeMark>>, WithPos<TypeMark>),
Procedure(Vec<WithPos<TypeMark>>),
}
#[derive(PartialEq, Debug, Clone)]
pub enum SubprogramSpecification {
Procedure(ProcedureSpecification),
Function(FunctionSpecification),
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct SubprogramDeclaration {
pub specification: SubprogramSpecification,
}
#[derive(PartialEq, Debug, Clone)]
pub struct InterfaceFileDeclaration {
pub ident: WithDecl<Ident>,
pub subtype_indication: SubtypeIndication,
}
#[derive(PartialEq, Debug, Clone)]
pub struct InterfaceObjectDeclaration {
pub list_type: InterfaceType,
pub class: ObjectClass,
pub ident: WithDecl<Ident>,
pub mode: Mode,
pub subtype_indication: SubtypeIndication,
pub expression: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum SubprogramDefault {
Name(WithPos<Name>),
Box,
}
#[derive(PartialEq, Debug, Clone)]
pub enum InterfacePackageGenericMapAspect {
Map(SeparatedList<AssociationElement>),
Box,
Default,
}
#[derive(PartialEq, Debug, Clone)]
pub struct InterfacePackageDeclaration {
pub ident: WithDecl<Ident>,
pub package_name: WithPos<Name>,
pub generic_map: InterfacePackageGenericMapAspect,
}
#[derive(PartialEq, Debug, Clone)]
pub enum InterfaceDeclaration {
Object(InterfaceObjectDeclaration),
File(InterfaceFileDeclaration),
Type(WithDecl<Ident>),
Subprogram(SubprogramSpecification, Option<SubprogramDefault>),
Package(InterfacePackageDeclaration),
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum Mode {
In,
Out,
InOut,
Buffer,
Linkage,
}
#[derive(PartialEq, Debug, Clone)]
pub struct PortClause {
pub port_list: Vec<InterfaceDeclaration>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ComponentDeclaration {
pub ident: WithDecl<Ident>,
pub generic_list: Vec<InterfaceDeclaration>,
pub port_list: Vec<InterfaceDeclaration>,
pub end_ident_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum Declaration {
Object(ObjectDeclaration),
File(FileDeclaration),
Type(TypeDeclaration),
Component(ComponentDeclaration),
Attribute(Attribute),
Alias(AliasDeclaration),
SubprogramDeclaration(SubprogramDeclaration),
SubprogramInstantiation(SubprogramInstantiation),
SubprogramBody(SubprogramBody),
Use(UseClause),
Package(PackageInstantiation),
Configuration(ConfigurationSpecification),
}
#[derive(PartialEq, Debug, Clone)]
pub struct WaitStatement {
pub sensitivity_clause: Vec<WithPos<Name>>,
pub condition_clause: Option<WithPos<Expression>>,
pub timeout_clause: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct AssertStatement {
pub condition: WithPos<Expression>,
pub report: Option<WithPos<Expression>>,
pub severity: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ReportStatement {
pub report: WithPos<Expression>,
pub severity: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Target {
Name(Name),
Aggregate(Vec<ElementAssociation>),
}
#[derive(PartialEq, Debug, Clone)]
pub struct WaveformElement {
pub value: WithPos<Expression>,
pub after: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum Waveform {
Elements(Vec<WaveformElement>),
Unaffected,
}
#[derive(PartialEq, Debug, Clone)]
pub enum DelayMechanism {
Transport,
Inertial { reject: Option<WithPos<Expression>> },
}
#[derive(PartialEq, Debug, Clone)]
pub struct SignalAssignment {
pub target: WithPos<Target>,
pub delay_mechanism: Option<DelayMechanism>,
pub rhs: AssignmentRightHand<Waveform>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum ForceMode {
In,
Out,
}
#[derive(PartialEq, Debug, Clone)]
pub struct SignalForceAssignment {
pub target: WithPos<Target>,
pub force_mode: Option<ForceMode>,
pub rhs: AssignmentRightHand<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct SignalReleaseAssignment {
pub target: WithPos<Target>,
pub force_mode: Option<ForceMode>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct VariableAssignment {
pub target: WithPos<Target>,
pub rhs: AssignmentRightHand<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum AssignmentRightHand<T> {
Simple(T),
Conditional(Conditionals<T>),
Selected(Selection<T>),
}
#[derive(PartialEq, Debug, Clone)]
pub struct Conditional<T> {
pub condition: WithPos<Expression>,
pub item: T,
}
#[derive(PartialEq, Debug, Clone)]
pub struct Conditionals<T> {
pub conditionals: Vec<Conditional<T>>,
pub else_item: Option<T>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct IfStatement {
pub conds: Conditionals<Vec<LabeledSequentialStatement>>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct Alternative<T> {
pub choices: Vec<WithPos<Choice>>,
pub item: T,
}
#[derive(PartialEq, Debug, Clone)]
pub struct Selection<T> {
pub expression: WithPos<Expression>,
pub alternatives: Vec<Alternative<T>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct CaseStatement {
pub is_matching: bool,
pub expression: WithPos<Expression>,
pub alternatives: Vec<Alternative<Vec<LabeledSequentialStatement>>>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum IterationScheme {
While(WithPos<Expression>),
For(WithDecl<Ident>, DiscreteRange),
}
#[derive(PartialEq, Debug, Clone)]
pub struct LoopStatement {
pub iteration_scheme: Option<IterationScheme>,
pub statements: Vec<LabeledSequentialStatement>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct NextStatement {
pub loop_label: Option<WithRef<Ident>>,
pub condition: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ExitStatement {
pub loop_label: Option<WithRef<Ident>>,
pub condition: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ReturnStatement {
pub expression: Option<WithPos<Expression>>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum SequentialStatement {
Wait(WaitStatement),
Assert(AssertStatement),
Report(ReportStatement),
VariableAssignment(VariableAssignment),
SignalAssignment(SignalAssignment),
SignalForceAssignment(SignalForceAssignment),
SignalReleaseAssignment(SignalReleaseAssignment),
ProcedureCall(WithPos<CallOrIndexed>),
If(IfStatement),
Case(CaseStatement),
Loop(LoopStatement),
Next(NextStatement),
Exit(ExitStatement),
Return(ReturnStatement),
Null,
}
#[derive(PartialEq, Debug, Clone)]
pub struct LabeledSequentialStatement {
pub label: WithDecl<Option<Ident>>,
pub statement: WithPos<SequentialStatement>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct BlockStatement {
pub guard_condition: Option<WithPos<Expression>>,
pub header: BlockHeader,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct BlockHeader {
pub generic_clause: Option<Vec<InterfaceDeclaration>>,
pub generic_map: Option<MapAspect>,
pub port_clause: Option<Vec<InterfaceDeclaration>>,
pub port_map: Option<MapAspect>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum SensitivityList {
Names(Vec<WithPos<Name>>),
All,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ProcessStatement {
pub postponed: bool,
pub sensitivity_list: Option<SensitivityList>,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledSequentialStatement>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ConcurrentProcedureCall {
pub postponed: bool,
pub call: WithPos<CallOrIndexed>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ConcurrentAssertStatement {
pub postponed: bool,
pub statement: AssertStatement,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ConcurrentSignalAssignment {
pub postponed: bool,
pub guarded: bool,
pub target: WithPos<Target>,
pub delay_mechanism: Option<DelayMechanism>,
pub rhs: AssignmentRightHand<Waveform>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum InstantiatedUnit {
Component(WithPos<Name>),
Entity(WithPos<Name>, Option<WithRef<Ident>>),
Configuration(WithPos<Name>),
}
impl InstantiatedUnit {
pub fn entity_reference(&self) -> Option<EntityId> {
match &self {
InstantiatedUnit::Entity(name, _) => name.item.get_suffix_reference(),
InstantiatedUnit::Configuration(name) => name.item.get_suffix_reference(),
InstantiatedUnit::Component(name) => name.item.get_suffix_reference(),
}
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct MapAspect {
pub start: TokenId,
pub list: SeparatedList<AssociationElement>,
pub closing_paren: TokenId,
}
impl MapAspect {
pub fn formals(&self) -> impl Iterator<Item = Option<EntityId>> + '_ {
self.list.formals()
}
pub fn span(&self, ctx: &dyn TokenAccess) -> SrcPos {
ctx.get_span(self.start, self.closing_paren)
}
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct InstantiationStatement {
pub unit: InstantiatedUnit,
pub generic_map: Option<MapAspect>,
pub port_map: Option<MapAspect>,
}
impl InstantiationStatement {
pub fn entity_reference(&self) -> Option<EntityId> {
self.unit.entity_reference()
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct GenerateBody {
pub alternative_label: Option<WithDecl<Ident>>,
pub decl: Option<Vec<Declaration>>,
pub statements: Vec<LabeledConcurrentStatement>,
pub end_label_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ForGenerateStatement {
pub index_name: WithDecl<Ident>,
pub discrete_range: DiscreteRange,
pub body: GenerateBody,
pub end_label_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct IfGenerateStatement {
pub conds: Conditionals<GenerateBody>,
pub end_label_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct CaseGenerateStatement {
pub sels: Selection<GenerateBody>,
pub end_label_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ConcurrentStatement {
ProcedureCall(ConcurrentProcedureCall),
Block(BlockStatement),
Process(ProcessStatement),
Assert(ConcurrentAssertStatement),
Assignment(ConcurrentSignalAssignment),
Instance(InstantiationStatement),
ForGenerate(ForGenerateStatement),
IfGenerate(IfGenerateStatement),
CaseGenerate(CaseGenerateStatement),
}
#[derive(PartialEq, Debug, Clone)]
pub struct LabeledConcurrentStatement {
pub label: WithDecl<Option<Ident>>,
pub statement: WithPos<ConcurrentStatement>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct LibraryClause {
pub name_list: IdentList,
}
#[derive(PartialEq, Debug, Clone)]
pub struct SeparatedList<T> {
pub items: Vec<T>,
pub tokens: Vec<TokenId>,
}
impl<T> Default for SeparatedList<T> {
fn default() -> Self {
SeparatedList {
items: Vec::default(),
tokens: Vec::default(),
}
}
}
impl SeparatedList<AssociationElement> {
pub fn formals(&self) -> impl Iterator<Item = Option<EntityId>> + '_ {
self.items.iter().filter_map(|el| match &el.formal {
None => None,
Some(name) => match &name.item {
Name::Designator(desi) => Some(desi.reference.get()),
_ => None,
},
})
}
}
pub type IdentList = SeparatedList<WithRef<Ident>>;
pub type NameList = SeparatedList<WithPos<Name>>;
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct UseClause {
pub name_list: NameList,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ContextReference {
pub name_list: NameList,
}
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum ContextItem {
Use(UseClause),
Library(LibraryClause),
Context(ContextReference),
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ContextDeclaration {
pub ident: WithDecl<Ident>,
pub items: ContextClause,
pub end_ident_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct PackageInstantiation {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub package_name: WithPos<Name>,
pub generic_map: Option<MapAspect>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum InstantiationList {
Labels(Vec<Ident>),
Others,
All,
}
#[derive(PartialEq, Debug, Clone)]
pub enum EntityAspect {
Entity(WithPos<Name>, Option<Ident>),
Configuration(WithPos<Name>),
Open,
}
#[derive(PartialEq, Debug, Clone)]
pub struct BindingIndication {
pub entity_aspect: Option<EntityAspect>,
pub generic_map: Option<MapAspect>,
pub port_map: Option<MapAspect>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct ComponentSpecification {
pub instantiation_list: InstantiationList,
pub component_name: WithPos<Name>,
}
#[derive(PartialEq, Debug, Clone)]
pub struct VUnitBindingIndication {
pub vunit_list: Vec<WithPos<Name>>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ConfigurationSpecification {
pub spec: ComponentSpecification,
pub bind_ind: BindingIndication,
pub vunit_bind_inds: Vec<VUnitBindingIndication>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ConfigurationDeclarativeItem {
Use(UseClause),
}
#[derive(PartialEq, Debug, Clone)]
pub struct ComponentConfiguration {
pub spec: ComponentSpecification,
pub bind_ind: Option<BindingIndication>,
pub vunit_bind_inds: Vec<VUnitBindingIndication>,
pub block_config: Option<BlockConfiguration>,
}
#[derive(PartialEq, Debug, Clone)]
pub enum ConfigurationItem {
Block(BlockConfiguration),
Component(ComponentConfiguration),
}
#[derive(PartialEq, Debug, Clone)]
pub struct BlockConfiguration {
pub block_spec: WithPos<Name>,
pub use_clauses: Vec<UseClause>,
pub items: Vec<ConfigurationItem>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ConfigurationDeclaration {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub entity_name: WithPos<Name>,
pub decl: Vec<ConfigurationDeclarativeItem>,
pub vunit_bind_inds: Vec<VUnitBindingIndication>,
pub block_config: BlockConfiguration,
pub end_ident_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct EntityDeclaration {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub generic_clause: Option<Vec<InterfaceDeclaration>>,
pub port_clause: Option<Vec<InterfaceDeclaration>>,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,
pub end_ident_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct ArchitectureBody {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub entity_name: WithRef<Ident>,
pub begin_token: TokenId,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,
pub end_ident_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct PackageDeclaration {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub generic_clause: Option<Vec<InterfaceDeclaration>>,
pub decl: Vec<Declaration>,
pub end_ident_pos: Option<SrcPos>,
}
#[with_token_span]
#[derive(PartialEq, Debug, Clone)]
pub struct PackageBody {
pub context_clause: ContextClause,
pub ident: WithDecl<Ident>,
pub decl: Vec<Declaration>,
pub end_ident_pos: Option<SrcPos>,
}
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum AnyPrimaryUnit {
Entity(EntityDeclaration),
Configuration(ConfigurationDeclaration),
Package(PackageDeclaration),
PackageInstance(PackageInstantiation),
Context(ContextDeclaration),
}
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum AnySecondaryUnit {
Architecture(ArchitectureBody),
PackageBody(PackageBody),
}
pub type ContextClause = Vec<ContextItem>;
#[derive(PartialEq, Debug, Clone, TokenSpan)]
pub enum AnyDesignUnit {
Primary(AnyPrimaryUnit),
Secondary(AnySecondaryUnit),
}
impl AnyDesignUnit {
pub fn is_entity(&self) -> bool {
matches!(self, AnyDesignUnit::Primary(AnyPrimaryUnit::Entity(_)))
}
}
#[derive(PartialEq, Debug, Clone, Default)]
pub struct DesignFile {
pub design_units: Vec<(Vec<Token>, AnyDesignUnit)>,
}