Context operation for positive
This commit is contained in:
@ -1320,7 +1320,8 @@ where
|
||||
| Range::IterateOverSet(exp) => {
|
||||
let type_exp = typecheck_expression(exp, c)?;
|
||||
match type_exp {
|
||||
| AssertionTypes::Set => Ok(AssertionTypes::RangeSet),
|
||||
| AssertionTypes::Set =>
|
||||
Ok(AssertionTypes::RangeSet),
|
||||
| AssertionTypes::RangeNeighbours =>
|
||||
Ok(AssertionTypes::RangeNeighbours),
|
||||
| AssertionTypes::RangeContexts =>
|
||||
|
||||
@ -126,6 +126,25 @@ pub enum QualifierSystem {
|
||||
Context,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum QualifierContext {
|
||||
IsNill,
|
||||
IsIdentifier,
|
||||
IsSet,
|
||||
IsGuarded,
|
||||
IsRepeated,
|
||||
IsSummation,
|
||||
IsNondeterministicChoice,
|
||||
|
||||
GetSet,
|
||||
GetGuardReactants,
|
||||
GetGuardProducts,
|
||||
GetRepeatedCounter,
|
||||
GetRepeatedProcess,
|
||||
|
||||
GetNextProcesses,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum QualifierEdge {
|
||||
Source,
|
||||
@ -142,6 +161,7 @@ pub enum QualifierNode {
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Hash)]
|
||||
pub enum PositiveQualifier {
|
||||
System(QualifierSystem),
|
||||
Context(QualifierContext),
|
||||
Label(QualifierLabel),
|
||||
Restricted(QualifierRestricted),
|
||||
Edge(QualifierEdge),
|
||||
@ -187,6 +207,7 @@ pub(super) enum PositiveAssertionTypes {
|
||||
RangeInteger,
|
||||
RangeSet,
|
||||
RangeNeighbours,
|
||||
RangeContexts,
|
||||
|
||||
Node,
|
||||
Edge,
|
||||
@ -205,6 +226,7 @@ pub enum PositiveAssertReturnValue {
|
||||
Neighbours(petgraph::graph::NodeIndex),
|
||||
System(system::PositiveSystem),
|
||||
Context(process::PositiveProcess),
|
||||
RangeContext(process::PositiveProcess),
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -290,6 +312,105 @@ impl QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl QualifierContext {
|
||||
pub(super) fn get(&self, l: &process::PositiveProcess) -> PositiveAssertReturnValue {
|
||||
use process::PositiveProcess::*;
|
||||
match self {
|
||||
| Self::IsNill => PositiveAssertReturnValue::Boolean(matches!(l, Nill)),
|
||||
| Self::IsIdentifier =>
|
||||
PositiveAssertReturnValue::Boolean(matches!(l, RecursiveIdentifier {
|
||||
identifier: _,
|
||||
})),
|
||||
| Self::IsSet =>
|
||||
PositiveAssertReturnValue::Boolean(matches!(l, EntitySet {
|
||||
entities: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsGuarded =>
|
||||
PositiveAssertReturnValue::Boolean(matches!(l, Guarded {
|
||||
reaction: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsRepeated =>
|
||||
PositiveAssertReturnValue::Boolean(matches!(l, WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process: _,
|
||||
next_process: _,
|
||||
})),
|
||||
| Self::IsSummation =>
|
||||
PositiveAssertReturnValue::Boolean(matches!(l, Summation {
|
||||
children: _,
|
||||
})),
|
||||
| Self::IsNondeterministicChoice => PositiveAssertReturnValue::Boolean(
|
||||
matches!(l, NondeterministicChoice { children: _ }),
|
||||
),
|
||||
|
||||
| Self::GetSet => PositiveAssertReturnValue::Set(
|
||||
if let EntitySet {
|
||||
entities,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
entities.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetGuardReactants => PositiveAssertReturnValue::Set(
|
||||
if let Guarded {
|
||||
reaction,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
reaction.reactants.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetGuardProducts => PositiveAssertReturnValue::Set(
|
||||
if let Guarded {
|
||||
reaction,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
reaction.products.clone()
|
||||
} else {
|
||||
Default::default()
|
||||
},
|
||||
),
|
||||
| Self::GetRepeatedCounter => PositiveAssertReturnValue::Integer(
|
||||
if let WaitEntity {
|
||||
repeat,
|
||||
repeated_process: _,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
*repeat
|
||||
} else {
|
||||
0
|
||||
},
|
||||
),
|
||||
| Self::GetRepeatedProcess => {
|
||||
PositiveAssertReturnValue::Context(
|
||||
if let WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process,
|
||||
next_process: _,
|
||||
} = l
|
||||
{
|
||||
(**repeated_process).clone()
|
||||
} else {
|
||||
Default::default() // nill
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
| Self::GetNextProcesses =>
|
||||
PositiveAssertReturnValue::RangeContext(l.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PositiveUnary {
|
||||
pub(super) fn is_prefix(&self) -> bool {
|
||||
match self {
|
||||
@ -381,6 +502,78 @@ impl PositiveUnary {
|
||||
)),
|
||||
PositiveAssertionTypes::System,
|
||||
) => Ok(PositiveAssertionTypes::Context),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(QualifierContext::IsNill)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::IsIdentifier,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(QualifierContext::IsSet)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::IsGuarded,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::IsRepeated,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::IsSummation,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::IsNondeterministicChoice,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Boolean),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(QualifierContext::GetSet)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::GetGuardReactants,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::GetGuardProducts,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Set),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::GetRepeatedCounter,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Integer),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::GetRepeatedProcess,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::Context),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Context(
|
||||
QualifierContext::GetNextProcesses,
|
||||
)),
|
||||
PositiveAssertionTypes::Context,
|
||||
) => Ok(PositiveAssertionTypes::RangeContexts),
|
||||
| (
|
||||
Self::Qualifier(PositiveQualifier::Node(QualifierNode::System)),
|
||||
PositiveAssertionTypes::Node,
|
||||
@ -809,6 +1002,10 @@ impl TypeContext {
|
||||
self.data.insert(v.clone(), PositiveAssertionTypes::Edge);
|
||||
Ok(())
|
||||
},
|
||||
| PositiveAssertionTypes::RangeContexts => {
|
||||
self.data.insert(v.clone(), PositiveAssertionTypes::Context);
|
||||
Ok(())
|
||||
},
|
||||
| _ => Err(format!("Range has incorrect type {ty:?}.")),
|
||||
}
|
||||
}
|
||||
@ -1032,6 +1229,10 @@ impl PositiveAssertReturnValue {
|
||||
PositiveAssertReturnValue::System(sys),
|
||||
PositiveUnary::Qualifier(PositiveQualifier::System(q)),
|
||||
) => Ok(q.get(&sys)),
|
||||
| (
|
||||
PositiveAssertReturnValue::Context(c),
|
||||
PositiveUnary::Qualifier(PositiveQualifier::Context(q)),
|
||||
) => Ok(q.get(&c)),
|
||||
| (val, u) => Err(format!(
|
||||
"Incompatible unary operation {u:?} on value \
|
||||
{val:?}."
|
||||
@ -1290,6 +1491,8 @@ where
|
||||
Ok(PositiveAssertionTypes::RangeSet),
|
||||
| PositiveAssertionTypes::RangeNeighbours =>
|
||||
Ok(PositiveAssertionTypes::RangeNeighbours),
|
||||
| PositiveAssertionTypes::RangeContexts =>
|
||||
Ok(PositiveAssertionTypes::RangeContexts),
|
||||
| _ => Err(format!(
|
||||
"Expressions in range is not a set or \
|
||||
neighbours of a node, but is: {type_exp:?}."
|
||||
@ -1381,6 +1584,46 @@ where
|
||||
.map(|x| PositiveAssertReturnValue::Edge(x.id()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()),
|
||||
| PositiveAssertReturnValue::RangeContext(ctxs) => {
|
||||
use process::PositiveProcess::*;
|
||||
Ok(match ctxs {
|
||||
| Nill => vec![].into_iter(),
|
||||
| RecursiveIdentifier { identifier: _ } =>
|
||||
vec![].into_iter(),
|
||||
| EntitySet {
|
||||
entities: _,
|
||||
next_process,
|
||||
} => vec![PositiveAssertReturnValue::Context(
|
||||
(*next_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| Guarded {
|
||||
reaction: _,
|
||||
next_process,
|
||||
} => vec![PositiveAssertReturnValue::Context(
|
||||
(*next_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| WaitEntity {
|
||||
repeat: _,
|
||||
repeated_process,
|
||||
next_process: _,
|
||||
} => vec![PositiveAssertReturnValue::Context(
|
||||
(*repeated_process).clone(),
|
||||
)]
|
||||
.into_iter(),
|
||||
| Summation { children } => children
|
||||
.iter()
|
||||
.map(|c| PositiveAssertReturnValue::Context((**c).clone()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
| NondeterministicChoice { children } => children
|
||||
.iter()
|
||||
.map(|c| PositiveAssertReturnValue::Context((**c).clone()))
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
})
|
||||
}
|
||||
| _ => Err(format!("{val:?} is not a set in for cycle.")),
|
||||
}
|
||||
},
|
||||
|
||||
@ -176,6 +176,29 @@ impl fmt::Debug for QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for QualifierContext {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
| Self::IsNill => write!(f, "isNill"),
|
||||
| Self::IsIdentifier => write!(f, "isIdentifier"),
|
||||
| Self::IsSet => write!(f, "isSet"),
|
||||
| Self::IsGuarded => write!(f, "isGuarded"),
|
||||
| Self::IsRepeated => write!(f, "isRepeated"),
|
||||
| Self::IsSummation => write!(f, "isSummation"),
|
||||
| Self::IsNondeterministicChoice =>
|
||||
write!(f, "isNondeterministicChoice"),
|
||||
|
||||
| Self::GetSet => write!(f, "getSet"),
|
||||
| Self::GetGuardReactants => write!(f, "getGuardReactants"),
|
||||
| Self::GetGuardProducts => write!(f, "getGuardProducts"),
|
||||
| Self::GetRepeatedCounter => write!(f, "getRepeatedCounter"),
|
||||
| Self::GetRepeatedProcess => write!(f, "getRepeatedProcess"),
|
||||
|
||||
| Self::GetNextProcesses => write!(f, "getNextProcesses"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for QualifierEdge {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
@ -201,6 +224,7 @@ impl fmt::Debug for PositiveQualifier {
|
||||
| Self::Label(q) => write!(f, "{q:?}"),
|
||||
| Self::Restricted(q) => write!(f, "{q:?}"),
|
||||
| Self::System(q) => write!(f, "{q:?}"),
|
||||
| Self::Context(q) => write!(f, "{q:?}"),
|
||||
| Self::Edge(q) => write!(f, "{q:?}"),
|
||||
| Self::Node(q) => write!(f, "{q:?}"),
|
||||
}
|
||||
@ -250,6 +274,7 @@ impl fmt::Debug for PositiveAssertReturnValue {
|
||||
},
|
||||
| Self::System(sys) => write!(f, "{{debug: {sys:?}}}"),
|
||||
| Self::Context(ctx) => write!(f, "{{debug: {ctx:?}}}"),
|
||||
| Self::RangeContext(ctx) => write!(f, "{{debug: {ctx:?}}}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,6 +294,7 @@ impl fmt::Debug for PositiveAssertionTypes {
|
||||
| Self::RangeInteger => write!(f, "range of integers"),
|
||||
| Self::RangeSet => write!(f, "range of set"),
|
||||
| Self::RangeNeighbours => write!(f, "range of edges"),
|
||||
| Self::RangeContexts => write!(f, "range of contexts"),
|
||||
| Self::Edge => write!(f, "edge"),
|
||||
| Self::Node => write!(f, "node"),
|
||||
}
|
||||
@ -523,6 +549,16 @@ impl PrintableWithTranslator for QualifierSystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintableWithTranslator for QualifierContext {
|
||||
fn print(
|
||||
&self,
|
||||
f: &mut fmt::Formatter,
|
||||
_translator: &Translator,
|
||||
) -> fmt::Result {
|
||||
write!(f, "{self:?}")
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintableWithTranslator for QualifierEdge {
|
||||
fn print(
|
||||
&self,
|
||||
@ -557,6 +593,9 @@ impl PrintableWithTranslator for PositiveQualifier {
|
||||
| Self::System(q) => {
|
||||
write!(f, "{}", Formatter::from(translator, q))
|
||||
},
|
||||
| Self::Context(q) => {
|
||||
write!(f, "{}", Formatter::from(translator, q))
|
||||
},
|
||||
| Self::Edge(q) => write!(f, "{}", Formatter::from(translator, q)),
|
||||
| Self::Node(q) => write!(f, "{}", Formatter::from(translator, q)),
|
||||
}
|
||||
@ -601,6 +640,13 @@ impl PrintableWithTranslator for PositiveAssertReturnValue {
|
||||
| Self::Context(ctx) => {
|
||||
write!(f, "{}", Formatter::from(translator, ctx))
|
||||
},
|
||||
| Self::RangeContext(ctx) => {
|
||||
write!(
|
||||
f,
|
||||
"{{next processes of: {}}}",
|
||||
Formatter::from(translator, ctx)
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ pub mod useful_types_edge_relabeler {
|
||||
QualifierRestricted,
|
||||
QualifierLabel,
|
||||
QualifierSystem,
|
||||
QualifierContext,
|
||||
QualifierEdge,
|
||||
QualifierNode,
|
||||
Qualifier,
|
||||
@ -211,6 +212,7 @@ pub mod useful_types_node_relabeler {
|
||||
QualifierRestricted,
|
||||
QualifierLabel,
|
||||
QualifierSystem,
|
||||
QualifierContext,
|
||||
QualifierEdge,
|
||||
QualifierNode,
|
||||
Qualifier,
|
||||
@ -395,6 +397,7 @@ pub mod useful_types_positive_edge_relabeler {
|
||||
QualifierRestricted,
|
||||
QualifierLabel,
|
||||
QualifierSystem,
|
||||
QualifierContext,
|
||||
QualifierEdge,
|
||||
QualifierNode,
|
||||
PositiveQualifier,
|
||||
@ -510,6 +513,7 @@ impl positivedsl::PositiveAssert<PositiveEdgeRelablerInput> {
|
||||
.into()),
|
||||
| positivedsl::PositiveAssertionTypes::RangeInteger
|
||||
| positivedsl::PositiveAssertionTypes::RangeSet
|
||||
| positivedsl::PositiveAssertionTypes::RangeContexts
|
||||
| positivedsl::PositiveAssertionTypes::RangeNeighbours =>
|
||||
Err(format!("Returned type {ty:?} is not a valid return type.")),
|
||||
}
|
||||
@ -579,6 +583,7 @@ pub mod useful_types_positive_node_relabeler {
|
||||
QualifierRestricted,
|
||||
QualifierLabel,
|
||||
QualifierSystem,
|
||||
QualifierContext,
|
||||
QualifierEdge,
|
||||
QualifierNode,
|
||||
PositiveQualifier,
|
||||
@ -704,6 +709,7 @@ impl positivedsl::PositiveAssert<PositiveNodeRelablerInput> {
|
||||
.into()),
|
||||
| positivedsl::PositiveAssertionTypes::RangeInteger
|
||||
| positivedsl::PositiveAssertionTypes::RangeSet
|
||||
| positivedsl::PositiveAssertionTypes::RangeContexts
|
||||
| positivedsl::PositiveAssertionTypes::RangeNeighbours =>
|
||||
Err(format!("Returned type {ty:?} is not a valid return type.")),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user