raising events appears to work. nondeterminism currently ignored
This commit is contained in:
parent
3f2db4457f
commit
09a87d3025
8 changed files with 243 additions and 194 deletions
|
|
@ -43,21 +43,25 @@ export type Statechart = {
|
|||
uid2State: Map<string, ConcreteState>;
|
||||
}
|
||||
|
||||
const emptyRoot: OrState = {
|
||||
uid: "root",
|
||||
kind: "or",
|
||||
depth: 0,
|
||||
initial: [],
|
||||
children:[],
|
||||
comments: [],
|
||||
entryActions: [],
|
||||
exitActions: [],
|
||||
};
|
||||
|
||||
export const emptyStatechart: Statechart = {
|
||||
root: {
|
||||
uid: "root",
|
||||
kind: "or",
|
||||
initial: [],
|
||||
children:[],
|
||||
comments: [],
|
||||
entryActions: [],
|
||||
exitActions: [],
|
||||
},
|
||||
root: emptyRoot,
|
||||
transitions: new Map(),
|
||||
variables: new Set(),
|
||||
inputEvents: new Set(),
|
||||
internalEvents: new Set(),
|
||||
outputEvents: new Set(),
|
||||
uid2State: new Map([["root", emptyRoot]]),
|
||||
};
|
||||
|
||||
// reflexive, transitive relation
|
||||
|
|
@ -72,10 +76,19 @@ export function isAncestorOf({ancestor, descendant}: {ancestor: ConcreteState, d
|
|||
return pathToParent && [...pathToParent, descendant];
|
||||
}
|
||||
|
||||
export function isOverlapping(a: ConcreteState, b: ConcreteState): boolean {
|
||||
if (a.depth < b.depth) {
|
||||
return Boolean(isAncestorOf({ancestor: a, descendant: b}));
|
||||
}
|
||||
else {
|
||||
return Boolean(isAncestorOf({ancestor: b, descendant: a}));
|
||||
}
|
||||
}
|
||||
|
||||
// the arena of a transition is the lowest common ancestor state that is an OR-state
|
||||
// see "Deconstructing the Semantics of Big-Step Modelling Languages" by Shahram Esmaeilsabzali, 2009
|
||||
export function computeArena({src, tgt}: {src: ConcreteState, tgt: ConcreteState}): {
|
||||
arena: ConcreteState,
|
||||
arena: OrState,
|
||||
srcPath: ConcreteState[],
|
||||
tgtPath: ConcreteState[],
|
||||
} {
|
||||
|
|
@ -95,5 +108,24 @@ export function computeArena({src, tgt}: {src: ConcreteState, tgt: ConcreteState
|
|||
const {arena, srcPath, tgtPath} = computeArena({src: tgt, tgt: src});
|
||||
return {arena, srcPath: tgtPath, tgtPath: srcPath};
|
||||
}
|
||||
throw new Error("should never reach here");
|
||||
}
|
||||
|
||||
export function getDescendants(state: ConcreteState): Set<string> {
|
||||
const result = new Set([state.uid]);
|
||||
for (const child of state.children) {
|
||||
for (const descendant of getDescendants(child)) {
|
||||
// will include child itself:
|
||||
result.add(descendant);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// the 'description' of a state is a human-readable string that (hopefully) identifies the state.
|
||||
// if the state contains a comment, we take the 'first' (= visually topmost) comment
|
||||
// otherwise we fall back to the state's UID.
|
||||
export function stateDescription(state: ConcreteState) {
|
||||
const description = state.comments.length > 0 ? state.comments[0][1] : state.uid;
|
||||
return description;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue