Skip to content

Commit

Permalink
Extend obsolete to support multiple levels
Browse files Browse the repository at this point in the history
Obsolete warnings of level 1 will be displayed by default,
level 2 warnings are enabled with the -O command line option.
  • Loading branch information
ChrisJefferson committed Oct 15, 2018
1 parent 930776f commit 0b9c72c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
13 changes: 8 additions & 5 deletions doc/ref/obsolete.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,16 @@ Note that <C>MultRowVector</C> was also renamed to <C>MultVectorLeft</C>.
<InfoClass Name="InfoObsolete"/>
<Description>
is an info class to display warnings when an obsolete variable is used.
By default, these warnings are switched off since the info level for
this class is 0. Setting it to 1 will trigger warnings if &GAP; will
detect that an obsolete variable is used at runtime.
By default, the info level for this class is set to 1, which will only
show variables which will be removed in the next major version of GAP.
Setting it to 2 will trigger further warnings, for variables which have
alternative names, or may be removed in future.

This class can be set to 0 to disable all obsolete warnings.
<P/>
To check that the &GAP; code does not use obsolete variables at the
To check that the &GAP; code does not use any obsolete variables at the
parsing time, and not at a runtime, use <C>-O</C> command line option,
see <Ref Sect="Command Line Options"/>.
see <Ref Sect="Command Line Options"/>.
</Description>
</ManSection>

Expand Down
7 changes: 4 additions & 3 deletions lib/info.gi
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,9 @@ end);
##
#V InfoObsolete
##
## This info class has a default level of 0.
## Warnings can be switched on by setting its level to one.
## This info class has a default level of 1.
## Warnings can be disabled entirely by setting its level to 0, and further
## warnings can be switched on by setting its level to 2.
##
DeclareInfoClass( "InfoObsolete" );
SetInfoLevel(InfoObsolete,0);
SetInfoLevel(InfoObsolete,1);
20 changes: 15 additions & 5 deletions lib/obsolete.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,29 @@
## <#/GAPDoc>
##

BIND_GLOBAL( "DeclareObsoleteSynonym", function( name_obsolete, name_current )
local value, orig_value;
BIND_GLOBAL( "DeclareObsoleteSynonym", function( name_obsolete, name_current, level_arg... )
local value, orig_value, printed_warning, level;
if not ForAll( [ name_obsolete, name_current ], IsString ) then
Error("Each argument of DeclareObsoleteSynonym must be a string\n");
fi;
if Length(level_arg) = 0 then
level := 2;
else
level := level_arg[1];
fi;

value := EvalString( name_current );
if IsFunction( value ) then
orig_value := value;
printed_warning := false;
value := function (arg)
local res;
Info( InfoObsolete, 1, "'", name_obsolete, "' is obsolete.",
"\n#I It may be removed in a future release of GAP.",
"\n#I Use ", name_current, " instead.");
if not printed_warning then
Info( InfoObsolete, level, "'", name_obsolete, "' is obsolete.",
"\n#I It may be removed in a future release of GAP.",
"\n#I Use ", name_current, " instead.");
printed_warning := true;
fi;
# TODO: This will error out if orig_value is a function which returns nothing.
#return CallFuncList(orig_value, arg);
res := CallFuncListWrap(orig_value, arg);
Expand Down
2 changes: 1 addition & 1 deletion tst/testbugfix/2013-06-14-t00300.tst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gap> foo:=function() return 42; end;
function( ) ... end
gap> DeclareObsoleteSynonym("bar","foo");
gap> oldLevel := InfoLevel(InfoObsolete);;
gap> SetInfoLevel(InfoObsolete,1);
gap> SetInfoLevel(InfoObsolete,2);
gap> bar();
#I 'bar' is obsolete.
#I It may be removed in a future release of GAP.
Expand Down

0 comments on commit 0b9c72c

Please sign in to comment.