From 4761976f7a1add8911f289c42a3f8609b70fdf82 Mon Sep 17 00:00:00 2001
From: Maxime Jacquemin <maxime.jacquemin@cea.fr>
Date: Wed, 13 Oct 2021 15:56:44 +0200
Subject: [PATCH] [ivette] Better statement identification in the Eva component

---
 ivette/src/frama-c/plugins/eva/probeinfos.tsx |  4 ++--
 ivette/src/frama-c/plugins/eva/valueinfos.tsx | 21 +++++++++++++++----
 ivette/src/frama-c/plugins/eva/valuetable.tsx |  6 +++---
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/ivette/src/frama-c/plugins/eva/probeinfos.tsx b/ivette/src/frama-c/plugins/eva/probeinfos.tsx
index 8bfd82fa0db..54fe12b1dea 100644
--- a/ivette/src/frama-c/plugins/eva/probeinfos.tsx
+++ b/ivette/src/frama-c/plugins/eva/probeinfos.tsx
@@ -50,7 +50,7 @@ function ProbeEditor() {
   if (!probe || !probe.code) return null;
   const { label } = probe;
   const { code } = probe;
-  const { stmt } = probe;
+  const { stmt, fct, marker } = probe;
   const { rank } = probe;
   const byCS = probe.byCallstacks;
   const stacks = model.getStacks(probe);
@@ -65,7 +65,7 @@ function ProbeEditor() {
       <div className="eva-probeinfo-code">
         <SizedArea cols={cols} rows={rows}>{code}</SizedArea>
       </div>
-      <Code><Stmt stmt={stmt} rank={rank} /></Code>
+      <Code><Stmt stmt={stmt} rank={rank} fct={fct} marker={marker} /></Code>
       <IconButton
         icon="ITEMS.LIST"
         className="eva-probeinfo-button"
diff --git a/ivette/src/frama-c/plugins/eva/valueinfos.tsx b/ivette/src/frama-c/plugins/eva/valueinfos.tsx
index 1b1bdecd08e..8644eb31361 100644
--- a/ivette/src/frama-c/plugins/eva/valueinfos.tsx
+++ b/ivette/src/frama-c/plugins/eva/valueinfos.tsx
@@ -30,6 +30,9 @@ import { classes } from 'dome/misc/utils';
 import { Hpack, Vpack } from 'dome/layout/boxes';
 import { Code, Cell } from 'dome/controls/labels';
 import * as States from 'frama-c/states';
+import * as Ast from 'frama-c/api/kernel/ast';
+import { readFile } from 'dome/system';
+import * as Dome from 'dome';
 
 // Locals
 import { EvaAlarm } from './cells';
@@ -43,15 +46,25 @@ import { useModel } from './model';
 interface StmtProps {
   stmt?: string;
   rank?: number;
+  fct: string;
+  marker: Ast.marker;
 }
 
 export function Stmt(props: StmtProps) {
-  const { rank, stmt } = props;
+  const { rank, stmt, fct, marker } = props;
+  const markersInfo = States.useSyncArray(Ast.markerInfo);
+  const line = markersInfo.getData(marker)?.sloc?.line;
+  const file = markersInfo.getData(marker)?.sloc?.file;
+  const read = () => file ? readFile(file) : Promise.reject();
+  const text = React.useMemo(read, [file]);
+  const { result } = Dome.usePromise(text);
+  const allLines = result?.split(/\r\n|\n/);
+  const title = allLines ? (line ? `Stmt: ${allLines[line - 1]}` : '') : '' ;
   if (rank === undefined || !stmt) return null;
-  const title = `Stmt at global rank ${rank} (internal id: ${stmt})`;
+  // const title = `Stmt at global rank ${rank} (internal id: ${stmt})`;
   return (
     <span className="dome-text-cell eva-stmt" title={title}>
-      @S{rank}
+      @{fct}:{line}
     </span>
   );
 }
@@ -125,7 +138,7 @@ export function StackInfos() {
         onDoubleClick={onDoubleClick}
       >
         {caller}
-        <Stmt stmt={stmt} rank={rank} />
+        <Stmt stmt={stmt} rank={rank} fct={caller} marker={stmt} />
       </Cell>
     );
   };
diff --git a/ivette/src/frama-c/plugins/eva/valuetable.tsx b/ivette/src/frama-c/plugins/eva/valuetable.tsx
index 9b60287b841..50377b7977f 100644
--- a/ivette/src/frama-c/plugins/eva/valuetable.tsx
+++ b/ivette/src/frama-c/plugins/eva/valuetable.tsx
@@ -107,7 +107,7 @@ function TableCell(props: TableCellProps) {
   const maxWidth = CELLPADDING + WSIZER.dimension(probe.maxCols);
   const style = { width: minWidth, maxWidth };
   let contents: React.ReactNode = props.probe.marker;
-  const { transient } = probe;
+  const { transient, marker } = probe;
   const focused = model.getFocused();
   const isFocused = focused === probe;
 
@@ -118,12 +118,12 @@ function TableCell(props: TableCellProps) {
       if (transient) {
         contents = <span className="dome-text-label">« Probe »</span>;
       } else {
-        const { stmt, rank, code, label } = probe;
+        const { stmt, rank, code, label, fct } = probe;
         const textClass = label ? 'dome-text-label' : 'dome-text-cell';
         contents = (
           <>
             <span className={textClass}>{label ?? code}</span>
-            <Stmt stmt={stmt} rank={rank} />
+            <Stmt stmt={stmt} rank={rank} fct={fct} marker={marker} />
           </>
         );
       }
-- 
GitLab