From 279decc8e4d04ac9291765805f0f55e3df16d88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Fri, 18 Dec 2020 11:18:33 +0100 Subject: [PATCH] [ivette/eva] refactor state into model --- ivette/src/frama-c/eva/cells.ts | 17 ++++++++++++++--- ivette/src/frama-c/eva/diffed.tsx | 6 +++--- ivette/src/frama-c/eva/model.ts | 4 ++-- ivette/src/frama-c/eva/probes.ts | 17 +++++++++-------- ivette/src/frama-c/eva/stacks.ts | 12 ++++++------ 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ivette/src/frama-c/eva/cells.ts b/ivette/src/frama-c/eva/cells.ts index a21b5d3b848..33e2a564703 100644 --- a/ivette/src/frama-c/eva/cells.ts +++ b/ivette/src/frama-c/eva/cells.ts @@ -13,7 +13,7 @@ import * as Values from 'frama-c/api/plugins/eva/values'; export type callback = () => void; -export interface StateCallbacks { +export interface ModelCallbacks { forceUpdate: callback; forceLayout: callback; } @@ -70,6 +70,7 @@ export function leq(a: Size, b: Size): boolean { export type EvaStatus = 'True' | 'False' | 'Unknown'; export type EvaAlarm = [EvaStatus, string]; +export type EvaState = 'Here' | 'After' | 'Then' | 'Else'; export interface EvaValues { errors?: string; @@ -81,19 +82,29 @@ export interface EvaValues { size: Size; } +export function valueAt(v: EvaValues, st: EvaState): string | undefined { + switch (st) { + case 'Here': return v.values; + case 'After': return v.v_after; + case 'Then': return v.v_then; + case 'Else': return v.v_else; + default: return undefined; + } +} + // -------------------------------------------------------------------------- // --- Value Cache // -------------------------------------------------------------------------- export class ValueCache { - private readonly state: StateCallbacks; + private readonly state: ModelCallbacks; private readonly probes = new Map<Ast.marker, Size>(); // Marker -> max in column private readonly stacks = new Map<string, Size>(); // Callstack -> max in row private readonly vcache = new Map<string, EvaValues>(); // '<Marker><@Callstack>?' -> value private smax = EMPTY; // max cell size - constructor(state: StateCallbacks) { + constructor(state: ModelCallbacks) { this.state = state; } diff --git a/ivette/src/frama-c/eva/diffed.tsx b/ivette/src/frama-c/eva/diffed.tsx index 27f4e681943..cef19297cff 100644 --- a/ivette/src/frama-c/eva/diffed.tsx +++ b/ivette/src/frama-c/eva/diffed.tsx @@ -27,11 +27,11 @@ export class DiffBuffer { const { value, added, removed, contents } = this; if (value) { if (added && removed) { - contents.push(<span className='eva-diff-modified'>{value}</span>); + contents.push(<span className="eva-diff-modified">{value}</span>); } else if (removed) { - contents.push(<span className='eva-diff-removed'>{value}</span>); + contents.push(<span className="eva-diff-removed">{value}</span>); } else if (added) { - contents.push(<span className='eva-diff-added' />); + contents.push(<span className="eva-diff-added" />); } else { contents.push(value); } diff --git a/ivette/src/frama-c/eva/model.ts b/ivette/src/frama-c/eva/model.ts index 6023adb04ac..1ee86bc301a 100644 --- a/ivette/src/frama-c/eva/model.ts +++ b/ivette/src/frama-c/eva/model.ts @@ -14,7 +14,7 @@ import * as Ast from 'frama-c/api/kernel/ast'; // Model import { Probe } from './probes'; import { StacksCache, Callsite } from './stacks'; -import { StateCallbacks, ValueCache } from './cells'; +import { ModelCallbacks, ValueCache } from './cells'; import { LayoutProps, LayoutEngine, Row } from './layout'; export interface ModelLayout extends LayoutProps { @@ -26,7 +26,7 @@ export interface ModelLayout extends LayoutProps { /* --- EVA Values Model ---*/ /* --------------------------------------------------------------------------*/ -export class Model implements StateCallbacks { +export class Model implements ModelCallbacks { constructor() { this.forceUpdate = this.forceUpdate.bind(this); diff --git a/ivette/src/frama-c/eva/probes.ts b/ivette/src/frama-c/eva/probes.ts index a77c9897711..77f6c695e77 100644 --- a/ivette/src/frama-c/eva/probes.ts +++ b/ivette/src/frama-c/eva/probes.ts @@ -8,7 +8,7 @@ import * as Values from 'frama-c/api/plugins/eva/values'; import * as Ast from 'frama-c/api/kernel/ast'; // Model -import { StateCallbacks } from './cells'; +import { ModelCallbacks, EvaState } from './cells'; /* --------------------------------------------------------------------------*/ /* --- Probe Labelling ---*/ @@ -45,7 +45,7 @@ export class Probe { // properties readonly fct: string; readonly marker: Ast.marker; - readonly state: StateCallbacks; + readonly model: ModelCallbacks; transient = true; loading = true; label?: string; @@ -57,11 +57,12 @@ export class Probe { byCallstacks = false; zoomed = false; zoomable = false; + vstate: EvaState = 'Here'; - constructor(state: StateCallbacks, fct: string, marker: Ast.marker) { + constructor(state: ModelCallbacks, fct: string, marker: Ast.marker) { this.fct = fct; this.marker = marker; - this.state = state; + this.model = state; this.requestProbeInfo = this.requestProbeInfo.bind(this); this.setTransient = this.setTransient.bind(this); } @@ -82,7 +83,7 @@ export class Probe { this.rank = undefined; this.loading = false; }) - .finally(this.state.forceLayout); + .finally(this.model.forceLayout); } // -------------------------------------------------------------------------- @@ -99,21 +100,21 @@ export class Probe { if (!tr && !this.label && this.code && this.code.length > LabelSize) { this.label = newLabel(); } - this.state.forceLayout(); + this.model.forceLayout(); } } setByCallstacks(byCS: boolean) { if (byCS !== this.byCallstacks) { this.byCallstacks = byCS; - this.state.forceLayout(); + this.model.forceLayout(); } } setZoomed(zoomed: boolean) { if (zoomed !== this.zoomed) { this.zoomed = zoomed; - this.state.forceLayout(); + this.model.forceLayout(); } } diff --git a/ivette/src/frama-c/eva/stacks.ts b/ivette/src/frama-c/eva/stacks.ts index c752b231650..013638a1630 100644 --- a/ivette/src/frama-c/eva/stacks.ts +++ b/ivette/src/frama-c/eva/stacks.ts @@ -5,7 +5,7 @@ import * as Server from 'frama-c/server'; import * as Values from 'frama-c/api/plugins/eva/values'; -import { StateCallbacks } from './cells'; +import { ModelCallbacks } from './cells'; // -------------------------------------------------------------------------- // --- Callstack infos @@ -25,7 +25,7 @@ export interface Callsite { export class StacksCache { - private readonly state: StateCallbacks; + private readonly model: ModelCallbacks; private readonly stacks = new Map<string, callstacks>(); private readonly calls = new Map<Values.callstack, Callsite[]>(); @@ -33,8 +33,8 @@ export class StacksCache { // --- LifeCycle // -------------------------------------------------------------------------- - constructor(state: StateCallbacks) { - this.state = state; + constructor(state: ModelCallbacks) { + this.model = state; } clear() { @@ -70,7 +70,7 @@ export class StacksCache { .send(Values.getCallstacks, stmt) .then((cs: callstacks) => { this.stacks.set(stmt, cs); - this.state.forceLayout(); + this.model.forceLayout(); }); } @@ -79,7 +79,7 @@ export class StacksCache { .send(Values.getCallstackInfo, cs) .then((calls) => { this.calls.set(cs, calls); - this.state.forceUpdate(); + this.model.forceUpdate(); }); } -- GitLab