Skip to content
Snippets Groups Projects
Commit eeee3df0 authored by Loïc Correnson's avatar Loïc Correnson Committed by David Bühler
Browse files

[ivette] display type informations

parent 6e670072
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ import { TitleBar } from 'ivette'; ...@@ -45,7 +45,7 @@ import { TitleBar } from 'ivette';
import Kind = AST.markerKind; import Kind = AST.markerKind;
import Var = AST.markerVar import Var = AST.markerVar
function getMarkerKind (props: AST.markerInfoData): [string, string] { function getMarkerKind(props: AST.markerInfoData): [string, string] {
switch (props.kind) { switch (props.kind) {
case Kind.declaration: case Kind.declaration:
switch (props.var) { switch (props.var) {
...@@ -70,7 +70,7 @@ function getMarkerKind (props: AST.markerInfoData): [string, string] { ...@@ -70,7 +70,7 @@ function getMarkerKind (props: AST.markerInfoData): [string, string] {
} }
} }
function markerKind (props: AST.markerInfoData): JSX.Element { function markerKind(props: AST.markerInfoData): JSX.Element {
const [label, title] = getMarkerKind(props); const [label, title] = getMarkerKind(props);
return <span className="astinfo-markerkind" title={title}>{label}</span>; return <span className="astinfo-markerkind" title={title}>{label}</span>;
} }
...@@ -83,16 +83,18 @@ interface InfoItemProps { ...@@ -83,16 +83,18 @@ interface InfoItemProps {
label: string; label: string;
title: string; title: string;
text: DATA.text; text: DATA.text;
onMarker: (m: AST.marker) => void;
} }
function InfoItem(props: InfoItemProps): JSX.Element { function InfoItem(props: InfoItemProps): JSX.Element {
const onMarker = (m: string) => void props.onMarker(AST.jMarker(m));
return ( return (
<div className="astinfo-infos"> <div className="astinfo-infos">
<div className="dome-text-label astinfo-kind" title={props.title}> <div className="dome-text-label astinfo-kind" title={props.title}>
{props.label} {props.label}
</div> </div>
<div className="dome-text-cell astinfo-data" title={props.title}> <div className="dome-text-cell astinfo-data" title={props.title}>
<Text text={props.text} /> <Text onMarker={onMarker} text={props.text} />
</div> </div>
</div> </div>
); );
...@@ -117,6 +119,7 @@ interface InfoSectionProps { ...@@ -117,6 +119,7 @@ interface InfoSectionProps {
onHover: (hover: boolean) => void; onHover: (hover: boolean) => void;
onSelect: () => void; onSelect: () => void;
onRemove: () => void; onRemove: () => void;
onMarker: (m: AST.marker) => void;
} }
function MarkInfos(props: InfoSectionProps): JSX.Element { function MarkInfos(props: InfoSectionProps): JSX.Element {
...@@ -129,21 +132,22 @@ function MarkInfos(props: InfoSectionProps): JSX.Element { ...@@ -129,21 +132,22 @@ function MarkInfos(props: InfoSectionProps): JSX.Element {
props.selected && 'selected', props.selected && 'selected',
props.hovered && 'hovered', props.hovered && 'hovered',
); );
const descr = markerInfo.descr ?? markerInfo.name;
const kind = markerKind(markerInfo); const kind = markerKind(markerInfo);
const name = markerInfo.name;
const descr = markerInfo.descr ?? `${kind} ${name}`;
const fs = props.filter.split(':'); const fs = props.filter.split(':');
const filtered = allInfos.filter((info) => !fs.some((m) => m === info.id)); const filtered = allInfos.filter((info) => !fs.some((m) => m === info.id));
const infos = more ? allInfos : filtered; const infos = more ? allInfos : filtered;
const hasMore = filtered.length < allInfos.length; const hasMore = filtered.length < allInfos.length;
const pinButton = const pinButton =
(!props.pinned || props.selected) ? (!props.pinned || props.selected) ?
{ {
icon: "PIN", selected: props.pinned, onClick: props.onPin, icon: "PIN", selected: props.pinned, onClick: props.onPin,
title: "Pin/unpin marker information" title: "Pin/unpin marker information"
} : { } : {
icon: "CIRC.CLOSE", onClick: props.onRemove, icon: "CIRC.CLOSE", onClick: props.onRemove,
title:"Remove marker information" title: "Remove marker information"
}; };
return ( return (
<div <div
className={`astinfo-section ${highlight}`} className={`astinfo-section ${highlight}`}
...@@ -165,7 +169,7 @@ function MarkInfos(props: InfoSectionProps): JSX.Element { ...@@ -165,7 +169,7 @@ function MarkInfos(props: InfoSectionProps): JSX.Element {
onClick={() => setUnfold(!unfold)} onClick={() => setUnfold(!unfold)}
/> />
<Code className="astinfo-markercode"> <Code className="astinfo-markercode">
{kind}{descr} {kind}{name}
</Code> </Code>
<IconButton <IconButton
style={{ display: hasMore ? undefined : 'none' }} style={{ display: hasMore ? undefined : 'none' }}
...@@ -184,7 +188,9 @@ function MarkInfos(props: InfoSectionProps): JSX.Element { ...@@ -184,7 +188,9 @@ function MarkInfos(props: InfoSectionProps): JSX.Element {
{...pinButton} {...pinButton}
/> />
</div> </div>
{unfold && infos.map((info) => <InfoItem key={info.id} {...info} />)} {unfold && infos.map((info) => (
<InfoItem key={info.id} onMarker={props.onMarker} {...info} />
))}
</div> </div>
); );
} }
...@@ -197,6 +203,13 @@ type Mark = { fct: string; marker: AST.marker }; ...@@ -197,6 +203,13 @@ type Mark = { fct: string; marker: AST.marker };
const reload = new Dome.Event('frama-c.astinfo'); const reload = new Dome.Event('frama-c.astinfo');
function addMarker(s: Mark[], marker: AST.marker, fct: string): Mark[] {
if (s.some((m) => m.marker === marker))
return s;
else
return s.concat({ marker, fct });
}
class InfoMarkers { class InfoMarkers {
private selection: Mark[] = []; private selection: Mark[] = [];
...@@ -219,13 +232,6 @@ class InfoMarkers { ...@@ -219,13 +232,6 @@ class InfoMarkers {
} }
} }
addMarker(s: Mark[], marker: AST.marker, fct: string): Mark[] {
if (s.some((m) => m.marker === marker))
return s;
else
return s.concat({ marker, fct });
}
setLocations( setLocations(
selected: States.Location | undefined, selected: States.Location | undefined,
hovered: States.Location | undefined hovered: States.Location | undefined
...@@ -240,8 +246,8 @@ class InfoMarkers { ...@@ -240,8 +246,8 @@ class InfoMarkers {
const m = mark.marker; const m = mark.marker;
return this.isPinned(m) || (m !== s0 && m !== h0); return this.isPinned(m) || (m !== s0 && m !== h0);
}); });
if (sm && sf) s = this.addMarker(s, sm, sf); if (sm && sf) s = addMarker(s, sm, sf);
if (hm && hf) s = this.addMarker(s, hm, hf); if (hm && hf) s = addMarker(s, hm, hf);
this.selection = s; this.selection = s;
this.mSelected = sm; this.mSelected = sm;
this.mHovered = hm; this.mHovered = hm;
...@@ -299,7 +305,7 @@ export default function ASTinfo(): JSX.Element { ...@@ -299,7 +305,7 @@ export default function ASTinfo(): JSX.Element {
Dome.useUpdate(reload); Dome.useUpdate(reload);
const markers = React.useMemo(() => new InfoMarkers(), []); const markers = React.useMemo(() => new InfoMarkers(), []);
const markerInfos = States.useSyncArray(AST.markerInfo, false); const markerInfos = States.useSyncArray(AST.markerInfo, false);
const [selection] = States.useSelection(); const [selection, setSelection] = States.useSelection();
const [hoveredLoc] = States.useHovered(); const [hoveredLoc] = States.useHovered();
const information = States.useRequest(AST.getInformation, null) ?? []; const information = States.useRequest(AST.getInformation, null) ?? [];
const [filter, setFilter] = const [filter, setFilter] =
...@@ -335,6 +341,14 @@ export default function ASTinfo(): JSX.Element { ...@@ -335,6 +341,14 @@ export default function ASTinfo(): JSX.Element {
const onSelect = () => void States.setSelection(mark); const onSelect = () => void States.setSelection(mark);
const onHover = const onHover =
(h: boolean): void => States.setHovered(h ? mark : undefined); (h: boolean): void => States.setHovered(h ? mark : undefined);
const onMarker =
(marker: AST.marker): void => {
const fct = selection?.current?.fct;
if (fct) {
markers.setPinned(marker, true);
setSelection({ location: { fct, marker } });
}
};
const ref = isHovered ? scrollTarget : undefined; const ref = isHovered ? scrollTarget : undefined;
const markInfo = const markInfo =
<MarkInfos <MarkInfos
...@@ -346,6 +360,7 @@ export default function ASTinfo(): JSX.Element { ...@@ -346,6 +360,7 @@ export default function ASTinfo(): JSX.Element {
filter={filter} filter={filter}
hovered={isHovered} hovered={isHovered}
onPin={onPin} onPin={onPin}
onMarker={onMarker}
onRemove={onRemove} onRemove={onRemove}
onHover={onHover} onHover={onHover}
onSelect={onSelect} onSelect={onSelect}
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
} }
.astinfo-section.hovered { .astinfo-section.hovered {
background: var(--code-hover); background: var(--highlighted-marker);
} }
.astinfo-section.selected.hovered { .astinfo-section.selected.hovered {
......
...@@ -725,6 +725,20 @@ let () = Information.register ...@@ -725,6 +725,20 @@ let () = Information.register
| _ -> raise Not_found | _ -> raise Not_found
end end
let () = Information.register
~id:"kernel.ast.typedef"
~label:"Typedef"
~descr:"Type Definition"
begin fun fmt loc ->
match loc with
| PGlobal
(( GType _
| GCompTag _ | GCompTagDecl _
| GEnumTag _ | GEnumTagDecl _
) as g) -> Printer.pp_global fmt g
| _ -> raise Not_found
end
let () = Information.register let () = Information.register
~id:"kernel.ast.typesizeof" ~id:"kernel.ast.typesizeof"
~label:"Sizeof" ~label:"Sizeof"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment