From f659aefff279c829856505d17765a3302a19709c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Tue, 1 Dec 2020 16:57:56 +0100
Subject: [PATCH] [ivette] 'main' flag in function data

---
 ivette/api/generated/kernel/ast/index.ts | 6 +++++-
 ivette/src/renderer/Globals.tsx          | 3 +--
 src/plugins/server/kernel_ast.ml         | 5 +++++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/ivette/api/generated/kernel/ast/index.ts b/ivette/api/generated/kernel/ast/index.ts
index 36a793feea8..319a69f78ed 100644
--- a/ivette/api/generated/kernel/ast/index.ts
+++ b/ivette/api/generated/kernel/ast/index.ts
@@ -280,6 +280,8 @@ export interface functionsData {
   name: string;
   /** Signature */
   signature: string;
+  /** Is the function the main entry point */
+  main: boolean;
   /** Is the function defined? */
   defined: boolean;
   /** Is the function from the Frama-C stdlib? */
@@ -297,6 +299,7 @@ export const jFunctionsData: Json.Loose<functionsData> =
            '#functions expected'),
     name: Json.jFail(Json.jString,'String expected'),
     signature: Json.jFail(Json.jString,'String expected'),
+    main: Json.jFail(Json.jBoolean,'Boolean expected'),
     defined: Json.jFail(Json.jBoolean,'Boolean expected'),
     stdlib: Json.jFail(Json.jBoolean,'Boolean expected'),
     builtin: Json.jFail(Json.jBoolean,'Boolean expected'),
@@ -311,11 +314,12 @@ export const jFunctionsDataSafe: Json.Safe<functionsData> =
 export const byFunctionsData: Compare.Order<functionsData> =
   Compare.byFields
     <{ key: Json.key<'#functions'>, name: string, signature: string,
-       defined: boolean, stdlib: boolean, builtin: boolean,
+       main: boolean, defined: boolean, stdlib: boolean, builtin: boolean,
        eva_analyzed?: boolean }>({
     key: Compare.string,
     name: Compare.alpha,
     signature: Compare.string,
+    main: Compare.boolean,
     defined: Compare.boolean,
     stdlib: Compare.boolean,
     builtin: Compare.boolean,
diff --git a/ivette/src/renderer/Globals.tsx b/ivette/src/renderer/Globals.tsx
index 24f734a46be..6c20dab7b6e 100644
--- a/ivette/src/renderer/Globals.tsx
+++ b/ivette/src/renderer/Globals.tsx
@@ -119,8 +119,7 @@ export default () => {
   // Items
   const current: undefined | string = selection?.current?.function;
   const makeFctItem = (fct: functionsData) => {
-    const { name, signature } = fct;
-    const isMain = 0 < signature.indexOf('/* main */');
+    const { name, signature, main: isMain } = fct;
     return (
       <Item
         className={isMain ? 'fct-main' : undefined}
diff --git a/src/plugins/server/kernel_ast.ml b/src/plugins/server/kernel_ast.ml
index c69abdd308a..cb1c7032413 100644
--- a/src/plugins/server/kernel_ast.ml
+++ b/src/plugins/server/kernel_ast.ml
@@ -393,6 +393,11 @@ struct
         ~descr:(Md.plain "Signature")
         ~data:(module Data.Jstring)
         ~get:signature ;
+      States.column model
+        ~name:"main"
+        ~descr:(Md.plain "Is the function the main entry point")
+        ~data:(module Data.Jbool)
+        ~get:Kernel_function.is_entry_point;
       States.column model
         ~name:"defined"
         ~descr:(Md.plain "Is the function defined?")
-- 
GitLab