1/*  Part of CHR (Constraint Handling Rules)
2
3    Author:        Tom Schrijvers
4    E-mail:        Tom.Schrijvers@cs.kuleuven.be
5    WWW:           http://www.swi-prolog.org
6    Copyright (c)  2005-2011, K.U. Leuven
7    All rights reserved.
8
9    Redistribution and use in source and binary forms, with or without
10    modification, are permitted provided that the following conditions
11    are met:
12
13    1. Redistributions of source code must retain the above copyright
14       notice, this list of conditions and the following disclaimer.
15
16    2. Redistributions in binary form must reproduce the above copyright
17       notice, this list of conditions and the following disclaimer in
18       the documentation and/or other materials provided with the
19       distribution.
20
21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32    POSSIBILITY OF SUCH DAMAGE.
33*/
34
35:- module(chr_compiler_errors,
36		[
37			chr_info/3,
38			chr_warning/3,
39			chr_error/3,
40			print_chr_error/1
41		]).
42
43:- use_module(chr_compiler_options).
44
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46% chr_info(+Type,+FormattedMessage,+MessageParameters)
47
48chr_info(_,Message,Params) :-
49	( \+verbosity_on ->
50		true
51	;
52		long_line_with_equality_signs,
53		format(user_error,'CHR compiler:\n',[]),
54		format(user_error,Message,Params),
55		long_line_with_equality_signs
56	).
57
58
59%% SWI begin
60verbosity_on :-
61	current_prolog_flag(verbose,V), V \== silent,
62	current_prolog_flag(verbose_load,true).
63%% SWI end
64
65%% SICStus begin
66%% verbosity_on.  % at the moment
67%% SICStus end
68
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70% chr_warning(+Type,+FormattedMessage,+MessageParameters)
71
72chr_warning(deprecated(Term),Message,Params) :- !,
73	long_line_with_equality_signs,
74	format(user_error,'CHR compiler WARNING: deprecated syntax      ~w.\n',[Term]),
75	format(user_error,'    `--> ',[]),
76	format(user_error,Message,Params),
77        format(user_error,'    Support for deprecated syntax will be discontinued in the near future!\n',[]),
78	long_line_with_equality_signs.
79
80chr_warning(internal,Message,Params) :- !,
81	long_line_with_equality_signs,
82	format(user_error,'CHR compiler WARNING: something unexpected happened in the CHR compiler.\n',[]),
83	format(user_error,'    `--> ',[]),
84	format(user_error,Message,Params),
85        format(user_error,'    Your program may not have been compiled correctly!\n',[]),
86        format(user_error,'    Please contact tom.schrijvers@cs.kuleuven.be.\n',[]),
87	long_line_with_equality_signs.
88
89chr_warning(unsupported_pragma(Pragma,Rule),Message,Params) :- !,
90	long_line_with_equality_signs,
91	format(user_error,'CHR compiler WARNING: unsupported pragma ~w in ~@.\n',[Pragma,format_rule(Rule)]),
92	format(user_error,'    `--> ',[]),
93	format(user_error,Message,Params),
94        format(user_error,'    Pragma is ignored!\n',[]),
95	long_line_with_equality_signs.
96chr_warning(problem_pragma(Pragma,Rule),Message,Params) :- !,
97	long_line_with_equality_signs,
98	format(user_error,'CHR compiler WARNING: unsupported pragma ~w in ~@.\n',[Pragma,format_rule(Rule)]),
99	format(user_error,'    `--> ',[]),
100	format(user_error,Message,Params),
101	long_line_with_equality_signs.
102
103chr_warning(_,Message,Params) :-
104	( chr_pp_flag(verbosity,on) ->
105		long_line_with_equality_signs,
106		format(user_error,'CHR compiler WARNING:\n',[]),
107		format(user_error,'    `--> ',[]),
108		format(user_error,Message,Params),
109		long_line_with_equality_signs
110	;
111		true
112	).
113
114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115% chr_error(+Type,+FormattedMessage,+MessageParameters)
116
117chr_error(Type,Message,Params) :-
118	throw(chr_error(error(Type,Message,Params))).
119
120print_chr_error(error(Type,Message,Params)) :-
121	print_chr_error(Type,Message,Params).
122
123print_chr_error(syntax(Term),Message,Params) :- !,
124	long_line_with_equality_signs,
125	format(user_error,'CHR compiler ERROR: invalid syntax "~w".\n',[Term]),
126	format(user_error,'    `--> ',[]),
127	format(user_error,Message,Params),
128	long_line_with_equality_signs.
129
130print_chr_error(type_error,Message,Params) :- !,
131	long_line_with_equality_signs,
132	format(user_error,'CHR compiler TYPE ERROR:\n',[]),
133	format(user_error,'    `--> ',[]),
134	format(user_error,Message,Params),
135	long_line_with_equality_signs.
136
137print_chr_error(internal,Message,Params) :- !,
138	long_line_with_equality_signs,
139	format(user_error,'CHR compiler ERROR: something unexpected happened in the CHR compiler.\n',[]),
140	format(user_error,'    `--> ',[]),
141	format(user_error,Message,Params),
142        format(user_error,'    Please contact tom.schrijvers@cs.kuleuven.be.\n',[]),
143	long_line_with_equality_signs.
144
145print_chr_error(cyclic_alias(Alias),_Message,_Params) :- !,
146	long_line_with_equality_signs,
147	format(user_error,'CHR compiler ERROR: cyclic alias "~w".\n',[Alias]),
148	format(user_error,'    `--> Aborting compilation.\n',[]),
149	long_line_with_equality_signs.
150
151print_chr_error(_,Message,Params) :-
152	long_line_with_equality_signs,
153	format(user_error,'CHR compiler ERROR:\n',[]),
154	format(user_error,'    `--> ',[]),
155	format(user_error,Message,Params),
156	long_line_with_equality_signs.
157
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
160
161:- public
162	format_rule/1.			% called using format/3 `@'
163
164format_rule(PragmaRule) :-
165	PragmaRule = pragma(_,_,Pragmas,MaybeName,N),
166	( MaybeName = yes(Name) ->
167		write('rule '), write(Name)
168	;
169		write('rule number '), write(N)
170	),
171	( memberchk(source_location(SourceLocation),Pragmas) ->
172		write(' at '),
173		write(SourceLocation)
174	;
175		true
176	).
177
178long_line_with_equality_signs :-
179	format(user_error,'================================================================================\n',[]).
180