1/*  $Id$
2
3    Part of CHR (Constraint Handling Rules)
4
5    Author:        Tom Schrijvers
6    E-mail:        Tom.Schrijvers@cs.kuleuven.be
7    WWW:           http://www.swi-prolog.org
8    Copyright (C): 2005, K.U. Leuven
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License
12    as published by the Free Software Foundation; either version 2
13    of the License, or (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24    As a special exception, if you link this library with other files,
25    compiled with a Free Software compiler, to produce an executable, this
26    library does not by itself cause the resulting executable to be covered
27    by the GNU General Public License. This exception does not however
28    invalidate any other reasons why the executable file might be covered by
29    the GNU General Public License.
30*/
31:- module(chr_compiler_errors,
32		[
33			chr_info/3,
34			chr_warning/3,
35			chr_error/3,
36			print_chr_error/1
37		]).
38
39:- use_module(chr_compiler_options).
40
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42% chr_info(+Type,+FormattedMessage,+MessageParameters)
43
44chr_info(_,Message,Params) :-
45	( \+verbosity_on ->
46		true
47	;
48		long_line_with_equality_signs,
49		format(user_error,'CHR compiler:\n',[]),
50		format(user_error,Message,Params),
51		long_line_with_equality_signs
52	).
53
54
55%% SWI begin
56verbosity_on :-
57	current_prolog_flag(verbose,V), V \== silent,
58	current_prolog_flag(verbose_load,true).
59%% SWI end
60
61%% SICStus begin
62%% verbosity_on.  % at the moment
63%% SICStus end
64
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66% chr_warning(+Type,+FormattedMessage,+MessageParameters)
67
68chr_warning(deprecated(Term),Message,Params) :- !,
69	long_line_with_equality_signs,
70	format(user_error,'CHR compiler WARNING: deprecated syntax      ~w.\n',[Term]),
71	format(user_error,'    `--> ',[]),
72	format(user_error,Message,Params),
73        format(user_error,'    Support for deprecated syntax will be discontinued in the near future!\n',[]),
74	long_line_with_equality_signs.
75
76chr_warning(internal,Message,Params) :- !,
77	long_line_with_equality_signs,
78	format(user_error,'CHR compiler WARNING: something unexpected happened in the CHR compiler.\n',[]),
79	format(user_error,'    `--> ',[]),
80	format(user_error,Message,Params),
81        format(user_error,'    Your program may not have been compiled correctly!\n',[]),
82        format(user_error,'    Please contact tom.schrijvers@cs.kuleuven.be.\n',[]),
83	long_line_with_equality_signs.
84
85chr_warning(unsupported_pragma(Pragma,Rule),Message,Params) :- !,
86	long_line_with_equality_signs,
87	format(user_error,'CHR compiler WARNING: unsupported pragma ~w in ~@.\n',[Pragma,format_rule(Rule)]),
88	format(user_error,'    `--> ',[]),
89	format(user_error,Message,Params),
90        format(user_error,'    Pragma is ignored!\n',[]),
91	long_line_with_equality_signs.
92chr_warning(problem_pragma(Pragma,Rule),Message,Params) :- !,
93	long_line_with_equality_signs,
94	format(user_error,'CHR compiler WARNING: unsupported pragma ~w in ~@.\n',[Pragma,format_rule(Rule)]),
95	format(user_error,'    `--> ',[]),
96	format(user_error,Message,Params),
97	long_line_with_equality_signs.
98
99chr_warning(_,Message,Params) :-
100	( chr_pp_flag(verbosity,on) ->
101		long_line_with_equality_signs,
102		format(user_error,'CHR compiler WARNING:\n',[]),
103		format(user_error,'    `--> ',[]),
104		format(user_error,Message,Params),
105		long_line_with_equality_signs
106	;
107		true
108	).
109
110%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111% chr_error(+Type,+FormattedMessage,+MessageParameters)
112
113chr_error(Type,Message,Params) :-
114	throw(chr_error(error(Type,Message,Params))).
115
116print_chr_error(error(Type,Message,Params)) :-
117	print_chr_error(Type,Message,Params).
118
119print_chr_error(syntax(Term),Message,Params) :- !,
120	long_line_with_equality_signs,
121	format(user_error,'CHR compiler ERROR: invalid syntax "~w".\n',[Term]),
122	format(user_error,'    `--> ',[]),
123	format(user_error,Message,Params),
124	long_line_with_equality_signs.
125
126print_chr_error(type_error,Message,Params) :- !,
127	long_line_with_equality_signs,
128	format(user_error,'CHR compiler TYPE ERROR:\n',[]),
129	format(user_error,'    `--> ',[]),
130	format(user_error,Message,Params),
131	long_line_with_equality_signs.
132
133print_chr_error(internal,Message,Params) :- !,
134	long_line_with_equality_signs,
135	format(user_error,'CHR compiler ERROR: something unexpected happened in the CHR compiler.\n',[]),
136	format(user_error,'    `--> ',[]),
137	format(user_error,Message,Params),
138        format(user_error,'    Please contact tom.schrijvers@cs.kuleuven.be.\n',[]),
139	long_line_with_equality_signs.
140
141print_chr_error(cyclic_alias(Alias),_Message,_Params) :- !,
142	long_line_with_equality_signs,
143	format(user_error,'CHR compiler ERROR: cyclic alias "~w".\n',[Alias]),
144	format(user_error,'    `--> Aborting compilation.\n',[]),
145	long_line_with_equality_signs.
146
147print_chr_error(_,Message,Params) :-
148	long_line_with_equality_signs,
149	format(user_error,'CHR compiler ERROR:\n',[]),
150	format(user_error,'    `--> ',[]),
151	format(user_error,Message,Params),
152	long_line_with_equality_signs.
153
154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155
156
157format_rule(PragmaRule) :-
158	PragmaRule = pragma(_,_,Pragmas,MaybeName,N),
159	( MaybeName = yes(Name) ->
160		write('rule '), write(Name)
161	;
162		write('rule number '), write(N)
163	),
164	( memberchk(line_number(LineNumber),Pragmas) ->
165		write(' (line '),
166		write(LineNumber),
167		write(')')
168	;
169		true
170	).
171
172long_line_with_equality_signs :-
173	format(user_error,'================================================================================\n',[]).
174