report.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
class REPORTER
class REPORTER is
-- This class is provided to report errors, warnings, etc to a program
-- user. Where appropriate errors and warnings are also sent to a throw-back
-- channel for use by other applications known to the underlying operating
-- system. A fatal error may be 'reported' by raising an exception as
-- required. This is always done as a string exception, created for the
-- purpose by this object.
-- Version 1.1 Oct 98. Copyright University of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 7 Feb 98 kh Original for portability.
-- 26 Oct 98 kh Added pre/post conditions.
private attr lib : LIBCHARS ;
-- The following three attributes are provided for use with operating
-- systems which provide error file/line data to some editor facility. Where
-- this is not possible then this feature is ignored.
private attr throw_back_possible : BOOL ;
readonly attr throw_back_active : BOOL ;
private attr throw_back_channel : REFERENCE ;
-- The following two attributes indicate the action to be taken in
-- respect of warnings (the default is that a warning does not count as
-- an error!). The second one instructs the reporter that every error
-- reported is to cause a raising of an exception for the error string
-- created by this reporter.
readonly attr warning_not_error : BOOL ;
readonly attr raise_error : BOOL ;
private attr error_count : CARD ;
private attr warning_count : CARD ;
private attr messages : ARRAY{STR} ;
readonly attr max_index : CARD ;
private attr source : FILE_PATH ;
private attr line_no : CARD ;
-- This component is the path of the file about which warnings/errors are currently being reported (if any).
create(format_strings : ARRAY{STR},library : LIBCHARS,do_throwback : BOOL) : SAME
pre ~void(library) and (format_strings.size > 0)
post ~void(result)
is
--This routine is the sole creation routine for reporter objects. It
-- sets the attributes from the parameters.
me : SAME := new ;
me.lib := library ;
me.messages := format_strings ;
me.max_index := me.messages.size ;
me.warning_not_error := true ;
me.raise_error := false ;
me.error_count := 0 ;
me.warning_count := 0 ;
me.line_no := 0 ;
if do_throwback then
me.throw_back_channel := FILE_SYS::open_throw_back ;
me.throw_back_possible := ~void(me.throw_back_channel)
else
me.throw_back_possible := false
end ;
me.throw_back_active := false ;
me.source := void ;
return me
end ;
create(format_strings : ARRAY{STR},library : LIBCHARS) : SAME
pre ~void(library) and (format_strings.size > 0)
post ~void(result)
is
--This routine is the sole creation routine for reporter objects. It
-- sets the attributes from the parameters.
return create(format_strings,library,false)
end ;
create(format_strings : ARRAY{STR}) : SAME
pre (format_strings.size > 0)
post ~void(result)
is
--This routine is the sole creation routine for reporter objects. It
-- sets the attributes from the parameters.
return create(format_strings,LIBCHARS::default,false)
end ;
can_throw : BOOL is
-- This predicate returns true if and only if throw-back is possible,
-- otherwise false.
return throw_back_possible
end ;
start_throw(fyle_ident : FILE_PATH) : BOOL
pre ~void(self) and ~void(fyle_ident)
post throw_back_active or ~throw_back_possible
is
-- This routine sets up the current source file corresponding to which
-- errors are thrown, sets throw-back active if possible and returns true if
-- and only if throw back is both possible and active.
if throw_back_possible then
source := fyle_ident ;
throw_back_active := true
end ;
return throw_back_active
end ;
private throw(msg : STR,only_warning : BOOL)
pre ~void(self) and (msg.size > 0)
post true
is
--This private routine does the actual throwback operation for both
-- warnings and errors.
if throw_back_active then
FILE_SYS::throw(throw_back_channel,source.str,msg,only_warning)
end
end ;
done_throwing
pre ~void(self)
post ~throw_back_active
is
--This routine 'closes' throwing for this reporter.
if throw_back_active then
FILE_SYS::close_throw_back(throw_back_channel) ;
throw_back_active := false
end
end ;
fatal
pre ~void(self)
post raise_error
is
--This routine sets the reporter to raise exceptions rather than send
-- error messages!
raise_error := true
end ;
non_fatal
pre ~void(self)
post ~raise_error
is
--This routine sets the reporter to send error messages rather than
-- raise exceptions!
raise_error := false
end ;
clear_errors
pre ~void(self)
post error_count = 0
is
--This routine permits an exception catching routine to clear any
-- errors if appropriate during recovery.
error_count := 0
end ;
errors : CARD
pre ~void(self)
post result = error_count
is
--This routine merely returns the number of errors since
-- error_count was last cleared.
return error_count
end ;
error_free : BOOL is
--This predicate returns true if and only if there are currently no
-- errors reported.
return void(self)
or (error_count = 0)
end ;
warn_only
pre ~void(self)
post warning_not_error
is
--This routine sets the reporter to treat further warnings as not being
-- errors.
warning_not_error := true
end ;
warn_as_errors
pre ~void(self)
post ~warning_not_error
is
--This routine sets the reporter to treat warnings as if they were
-- errors - which may be either fatal or non-fatal dependent on the error
-- reporting regime in force.
warning_not_error := false
end ;
clear_warnings
pre ~void(self)
post warning_count = 0
is
--This routine resets the warning count to zero.
warning_count := 0
end ;
warnings : CARD
pre ~void(self)
post result = warning_count
is
--This routine merely returns the number of warnings since
-- warning_count was last cleared.
return warning_count
end ;
private do_warn(line_err : CARD,msg : STR)
pre ~void(self)
and (msg.size > 0)
post (warning_not_err
and (warning_count = (initial(warning_count) + 1)))
or true
is
--This routine is the one which actually emits warning messages or
-- passes them to the error channel depending on the state of the
-- warning_not_error flag.
if warning_not_error then
line_no := line_err ;
throw(msg,true) ;
warning_count := warning_count + 1 ;
#ERR + msg + lib.Line_Mark.str
else
do_error(line_err,msg)
end ;
end ;
warn(index : CARD)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel.
do_warn(0,messages[index])
end ;
warn(index : CARD,arg : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel.
do_warn(0,FMT::create(messages[index],arg).str)
end ;
warn(index : CARD,arg1,arg2 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel.
do_warn(0,FMT::create(messages[index],arg1,arg2).str)
end ;
warn(index : CARD,arg1,arg2,arg3 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel.
do_warn(0,FMT::create(messages[index],| arg1,arg2,arg3 |).str)
end ;
line_warn(index : CARD,line : CARD)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel. The line number
-- argument is expected to form part of the message itself.
do_warn(line,FMT::create(messages[index],line.str).str)
end ;
line_warn(index : CARD,line : CARD,arg : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel. The line number
-- argument is expected to form part of the message itself.
do_warn(line,FMT::create(messages[index],arg,line.str).str)
end ;
line_warn(index : CARD,line : CARD,arg1,arg2 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel. The line number
-- argument is expected to form part of the message itself.
do_warn(line,FMT::create(messages[index],| arg1,arg2,line.str |).str)
end ;
line_warn(index : CARD,line : CARD,arg1,arg2,arg3 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the warning channel
-- or, if warning_not_error is false, to the error channel. The line number
-- argument is expected to form part of the message itself.
do_warn(line,FMT::create(messages[index],| arg1,arg2,arg3,line.str |).str)
end ;
private do_error(line_err : CARD,msg : STR)
pre ~void(self)
post true
is
--This routine is the one which actually emits messages or raises
-- exceptions.
error_count := error_count + 1 ;
line_no := line_err ;
throw(msg,false) ;
if raise_error then
raise msg + lib.Line_Mark.tgt_str
else
#ERR + msg + lib.Line_Mark.tgt_str
end
end ;
error(index : CARD)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(0,messages[index])
end ;
error(index : CARD, arg : $FMT)
pre ~void(self) and (index < messages.size)
post true
is
-- This routine sends the indicated message either to the error channel
-- or as a raised exception.
#OUT+"report.sa error index:"+index.str+",massage size:"+messages.size.str+"\n";
do_error(0,FMT::create(messages[index],arg).str)
end ;
error(index : CARD,arg1,arg2 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(0,FMT::create(messages[index],arg1,arg2).str)
end ;
error(index : CARD,arg1,arg2,arg3 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(0,FMT::create(messages[index],| arg1,arg2,arg3 |).str)
end ;
line_error(index : CARD,line : CARD)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(line,FMT::create(messages[index],line.str).str)
end ;
line_error(index : CARD,line : CARD,arg : $FMT)
pre ~void(self)
and (index < messages.size)
and ~void(arg)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(line,FMT::create(messages[index],arg,line.str).str)
end ;
line_error(index : CARD,line : CARD,arg1,arg2 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(line,FMT::create(messages[index],| arg1,arg2,line.str |).str)
end ;
line_error(index : CARD,line : CARD,arg1,arg2,arg3 : $FMT)
pre ~void(self)
and (index < messages.size)
post true
is
--This routine sends the indicated message either to the error channel
-- or as a raised exception.
do_error(line,FMT::create(messages[index],| arg1,arg2,arg3,line.str |).str)
end ;
-- NOTE This class is open for further expansion when a windowing system
-- library is available!
end ; -- REPORTER