13
14:- module(literal_parser, [parse_bodies/0]). 15
16:- use_module('analyzer/metafile_referencer'). 17:- use_module(library(lists)). 18:- ensure_loaded(parse_util). 19
29parse_bodies:- 30 pos_and_vars(ClauseId,BodyPos,VarNames),
31 termT(ClauseId,ClauseTerm),
32 ( ( ClauseTerm = (_Head :- Body),
33 clauseT(ClauseId,_,Module,_,_)
34 )
35 ; ( ClauseTerm = (:- Body),
36 directiveT(ClauseId,_,Module)
37 )
38 ),
39 parse_body_literals(Body, BodyPos, ClauseId, ClauseId, Module, VarNames),
40 retract(pos_and_vars(ClauseId,BodyPos,VarNames)),
41 fail.
42parse_bodies.
43
44
45parse_body_literals(Module:Literal, Pos, _ParentId, ClauseId, _OrigModule, VarNames) :-
46 !,
47 Pos = term_position(From, To, _FFrom, _FTo, SubPos),
48 SubPos = [ModuleFrom-ModuleTo, LiteralPos],
49 assert_new_node(Module:Literal,From,To,Id), 50 assert_new_node(Module,ModuleFrom,ModuleTo,_MId),
51 parse_body_literals(Literal, LiteralPos, Id, ClauseId, Module, VarNames). 55
56parse_body_literals([A|B], Pos, _ParentId, _ClauseId, _Module, _VarNames) :-
57 !,
58 Pos = list_position(From, To, _ElemPos, _TailPos),
59 assert_new_node([A|B],From,To,_Id).
60
64
68parse_body_literals('$VAR'(_A), _Pos, _ParentId, _ClauseId, _Module, _VarNames) :-
69 !.
75
84
85
86parse_body_literals(Body, Pos, ParentId, ClauseId, Module, VarNames) :-
87 88 catch(
89 metafile_referencer:is_metaterm(Module, Body, MetaArguments),
90 _,
91 true
92 ),
93 !,
94 Pos = term_position(From, To, _FFrom, _FTo, SubPos),
95 assert_new_node(Body,From,To,Id), 96 functor(Body,Functor,Arity),
97 assert(literalT(Id,ParentId,ClauseId,Module,Functor,Arity)),
98 assert(metaT(Id,ParentId,ClauseId,Module,Functor,Arity)),
99 forall( member(Meta, MetaArguments),
100 process_meta_argument(Meta, SubPos, Id, ClauseId, Module, VarNames)
101 ).
102
103parse_body_literals(Literal, Pos, ParentId, ClauseId, Module, _VarNames) :-
104 105 106 ( Pos = term_position(From, To, _FFrom, _FTo, _SubPos)
107 ; Pos = From - To
108 ),
109 assert_new_node(Literal,From,To,Id), 110 functor(Literal,Functor,Arity),
111 assert(literalT(Id,ParentId,ClauseId,Module,Functor,Arity)),
112 assert(lirteralT_ri(Functor,Arity,Module,Id)).
113 114
115process_meta_argument( (Nr,MetaTerm), Pos, ParentId, ClauseId, Module, VarNames) :-
116 nth1(Nr,Pos,TermPos),
117 parse_body_literals(MetaTerm, TermPos, ParentId, ClauseId, Module, VarNames)