1 | % (c) 2009-2014 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
2 | % Heinrich Heine Universitaet Duesseldorf | |
3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
4 | ||
5 | :- module(ast_inspector,[tcltk_get_node_info/6]). | |
6 | ||
7 | :- use_module(library(codesio)). | |
8 | :- use_module(library(lists)). | |
9 | :- use_module(bmachine). | |
10 | :- use_module(bsyntaxtree). | |
11 | ||
12 | :- use_module(module_information,[module_info/2]). | |
13 | :- module_info(group,visualization). | |
14 | :- module_info(description,'This module provides the logic behind the AST inspector debugging view in Tcl'). | |
15 | ||
16 | % first argument is a path : top-level root is empty path [], afterwards we have numbers representing the number of the child chosen | |
17 | tcltk_get_node_info([],'','','','',NSubs) :- | |
18 | !,top_level_astnodes(Nodes),length(Nodes,NSubs). | |
19 | tcltk_get_node_info([TopIndex|RIndex],write(Text),write(Type),write(Infos),write(Quant),NSubs) :- | |
20 | top_level_astnodes(Tops), | |
21 | nth0(TopIndex,Tops,Top), | |
22 | lookup_astnode(Top,RIndex,info(Text,Type,Infos,Quant),NSubs),!. | |
23 | tcltk_get_node_info(_Index,'Failure when trying to get node info','','','',0). | |
24 | ||
25 | top_level_astnodes(Tops) :- findall(T,top_level(T),Tops). | |
26 | ||
27 | top_level(properties) :- b_get_properties_from_machine(P),\+ is_truth(P). | |
28 | top_level(static_assertions) :- b_get_static_assertions_from_machine([_|_]). | |
29 | top_level(dynamic_assertions) :- b_get_dynamic_assertions_from_machine([_|_]). | |
30 | top_level(invariant). | |
31 | top_level(operations). | |
32 | ||
33 | astnode_info(properties,Info,[P]) :- | |
34 | !,text_info('Properties',Info),b_get_properties_from_machine(P). | |
35 | astnode_info(invariant,Info,[I]) :- | |
36 | !,text_info('Invariant',Info),b_get_invariant_from_machine(I). | |
37 | astnode_info(operations,Info,Ops) :- | |
38 | !,text_info('Operations',Info), | |
39 | findall(op(Name),b_is_operation_name(Name),Ops). | |
40 | astnode_info(op(Name),Info,Result) :- | |
41 | !,b_get_machine_operation(Name,Returns,Parameters,_), | |
42 | ( Returns =[] -> Result=PRes; Result=[returns(Name) |PRes]), | |
43 | ( Parameters=[] -> PRes =Subs; PRes =[parameters(Name)|Subs]), | |
44 | Subs = [subst(Name)],text_info(Name,Info). | |
45 | astnode_info(returns(Name),info('Returns','','',Ids),TIds) :- | |
46 | !,b_get_machine_operation(Name,TIds,_,_),get_texpr_ids(TIds,Ids). | |
47 | astnode_info(parameters(Name),info('Parameters','','',Ids),TIds) :- | |
48 | !,b_get_machine_operation(Name,_,TIds,_),get_texpr_ids(TIds,Ids). | |
49 | astnode_info(subst(Name),Info,[Subst]) :- | |
50 | !,text_info('Substitution',Info), b_get_machine_operation(Name,_,_,Subst). | |
51 | astnode_info(static_assertions,Info,Ass) :- | |
52 | !,text_info('Static Assertions',Info),b_get_static_assertions_from_machine(Ass). | |
53 | astnode_info(dynamic_assertions,Info,Ass) :- | |
54 | !,text_info('Dynamic Assertions',Info),b_get_dynamic_assertions_from_machine(Ass). | |
55 | astnode_info(TExpr,info(Node,Type,Infos,Ids),Subs) :- | |
56 | create_texpr(Expr,Type,Infos,TExpr),!, | |
57 | safe_syntaxelement(Expr,Subs,Names,_,Constant), | |
58 | ( Names = [] -> Ids='' | |
59 | ; otherwise -> get_texpr_ids(Names,Ids)), | |
60 | functor(Expr,Functor,_), | |
61 | ( Constant=[] -> | |
62 | Node=Functor | |
63 | ; otherwise -> | |
64 | functor(Node,Functor,1), | |
65 | arg(1,Node,Constant) | |
66 | ). | |
67 | astnode_info(TExpr,info('INVALID NODE','',TExpr,''),[]). | |
68 | ||
69 | text_info(Text,info(Text,'','','')). | |
70 | ||
71 | lookup_astnode(Top,Index,Info,N) :- | |
72 | astnode_info(Top,TopInfo,Subs), | |
73 | lookup_subnode(Index,Subs,TopInfo,Info,N). | |
74 | ||
75 | lookup_subnode([],Subs,Info,Info,N) :- | |
76 | length(Subs,N). | |
77 | lookup_subnode([H|T],Subs,_TopInfo,Info,N) :- | |
78 | nth0(H,Subs,Sub), | |
79 | lookup_astnode(Sub,T,Info,N). |