Skip to content

Commit

Permalink
Add ShowUsedInfoClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Mar 31, 2019
1 parent a174995 commit 310eec5
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
30 changes: 30 additions & 0 deletions doc/ref/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ algorithms for the computation of a subgroup lattice.
Note that not all info classes defined in the ⪆ library are currently
documented. Many ⪆ packages define additional info classes, which are
typically documented in the corresponding package documentation.
The function <Ref Func="ShowInfoClasses"/> will show all info classes which
a GAP considers during execution.
<P/>
The amount of information to be displayed by each info class can be separately
specified by the user. This is done by selecting a non-negative integer
Expand Down Expand Up @@ -158,6 +160,34 @@ returns the info level of <A>infoclass</A>.
</Description>
</ManSection>
<P/>
<ManSection>
<Func Name="ShowInfoClasses" Arg='infoclass'/>

<Description>
Called with argument <C>true</C>, makes GAP print the InfoClass and level of
any executed Info statement. Call with the argument <C>false</C> stops this
printing.

Each level of each InfoClass is only printed once. The list of printed
InfoClasses and levels is reset whenever <C>true</C> is passed.
<P/>

<Example><![CDATA[
gap> ShowUsedInfoClasses(true);
gap> Intersection(Group((1,3,2,4,5,6)), Group((1,2,3,4,5,6)));
#I Would print info with SetInfoLevel(InfoOptions,1)
#I Would print info with SetInfoLevel(InfoBckt,1)
#I Would print info with SetInfoLevel(InfoBckt,3)
#I Would print info with SetInfoLevel(InfoBckt,5)
Group(())
gap> Intersection(Group((1,3,2,4,5,6)), Group((1,2,3,4,5,6)));
Group(())
]]></Example>

</Description>
</ManSection>
<P/>

<ManSection>
<Func Name="Info" Arg='infoclass, level, info[, moreinfo ...]'/>

Expand Down
2 changes: 2 additions & 0 deletions lib/info.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ DeclareOperation("InfoLevel", [IsInfoClass]);
DeclareGlobalFunction("SetInfoHandler");
DeclareGlobalFunction("DefaultInfoHandler");



#############################################################################
##
##
Expand Down
22 changes: 22 additions & 0 deletions lib/info.gi
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,27 @@ BIND_GLOBAL( "InfoDecision", function(selectors, level)
return ret;
end );

BIND_GLOBAL("SHOWN_USED_INFO_CLASSES", AtomicList());


BIND_GLOBAL("RESET_SHOW_USED_INFO_CLASSES", function()
while Length(SHOWN_USED_INFO_CLASSES) > 0 do
Remove(SHOWN_USED_INFO_CLASSES);
od;
end);

BIND_GLOBAL("SHOW_USED_INFO_CLASSES", function(selectors, level)
local selector;
# Handle selectors possibly being a list
selectors := Flat([selectors]);
for selector in selectors do
if not [selector, level] in SHOWN_USED_INFO_CLASSES then
Add(SHOWN_USED_INFO_CLASSES, [selector, level]);
Print("#I Would print info with SetInfoLevel(",
selector, ",", level, ")\n");
fi;
od;
end);

#############################################################################
##
Expand Down Expand Up @@ -436,3 +457,4 @@ end);
##
DeclareInfoClass( "InfoObsolete" );
SetInfoLevel(InfoObsolete,1);

3 changes: 3 additions & 0 deletions src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ typedef struct GAPState {
Int PrintObjIndex;
Int PrintObjDepth;

/* From info.c */
Int ShowUsedInfoClassesActive;

UInt1 StateSlots[STATE_SLOTS_SIZE];

/* Allocation */
Expand Down
42 changes: 42 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "bool.h"
#include "calls.h"
#include "error.h"
#include "gapstate.h"
#include "gvars.h"
#include "modules.h"
#include "plist.h"
Expand All @@ -34,6 +36,24 @@ enum {
static Obj InfoDecision;
static Obj IsInfoClassListRep;
static Obj DefaultInfoHandler;
static Obj ResetShowUsedInfoClassesHandler;
static Obj ShowUsedInfoClassesHandler;


Obj FuncShowUsedInfoClasses(Obj self, Obj choice)
{
if(choice == True) {
STATE(ShowUsedInfoClassesActive) = 1;
CALL_0ARGS(ResetShowUsedInfoClassesHandler);
}
else if(choice == False) {
STATE(ShowUsedInfoClassesActive) = 0;
}
else {
ErrorMayQuit("<setting> should be true or false", 0, 0);
}
return 0;
}

void InfoDoPrint(Obj cls, Obj lvl, Obj args)
{
Expand All @@ -53,6 +73,9 @@ void InfoDoPrint(Obj cls, Obj lvl, Obj args)

Obj InfoCheckLevel(Obj selectors, Obj level)
{
if(STATE(ShowUsedInfoClassesActive)) {
CALL_2ARGS(ShowUsedInfoClassesHandler, selectors, level);
}
// Fast-path the most common failing case.
// The fast-path only deals with the case where all arguments are of the
// correct type, and were False is returned.
Expand All @@ -77,6 +100,15 @@ Obj InfoCheckLevel(Obj selectors, Obj level)
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/

/****************************************************************************
**
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
*/
static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC(ShowUsedInfoClasses, 1, "choice"),
{ 0, 0, 0, 0, 0 }
};


/****************************************************************************
**
Expand All @@ -85,10 +117,17 @@ Obj InfoCheckLevel(Obj selectors, Obj level)
static Int InitKernel (
StructInitInfo * module )
{
/* init filters and functions */
InitHdlrFuncsFromTable( GVarFuncs );

/* The work of handling Info messages is delegated to the GAP level */
ImportFuncFromLibrary("InfoDecision", &InfoDecision);
ImportFuncFromLibrary("DefaultInfoHandler", &DefaultInfoHandler);
ImportFuncFromLibrary("IsInfoClassListRep", &IsInfoClassListRep);
ImportFuncFromLibrary("RESET_SHOW_USED_INFO_CLASSES",
&ResetShowUsedInfoClassesHandler);
ImportFuncFromLibrary("SHOW_USED_INFO_CLASSES",
&ShowUsedInfoClassesHandler);

/* return success */
return 0;
Expand All @@ -102,6 +141,9 @@ static Int InitKernel (
static Int InitLibrary (
StructInitInfo * module )
{

InitGVarFuncsFromTable( GVarFuncs );

ExportAsConstantGVar(INFODATA_CURRENTLEVEL);
ExportAsConstantGVar(INFODATA_CLASSNAME);
ExportAsConstantGVar(INFODATA_HANDLER);
Expand Down
14 changes: 14 additions & 0 deletions tst/testinstall/info.tst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ gap> Info(InfoTest1 + InfoTest2, 0);
Error, level 0 Info messages are not allowed
gap> Info(InfoTest1 + InfoTest2, "apple");
Error, usage : Info(<selectors>, <level>, ...)
gap> ShowUsedInfoClasses(true);
gap> Info(InfoTest2, 2, "apple");
#I Would print info with SetInfoLevel(InfoTest2,2)
#I Would print info with SetInfoLevel(InfoGlobal,3)
#I apple
gap> Info(InfoTest1 + InfoTest2, 2, "apple");
#I Would print info with SetInfoLevel(InfoTest1,2)
#I apple
gap> Info(InfoTest1 + InfoTest2, 2, "apple");
#I apple
gap> Info(InfoTest1 + InfoTest2, 3, "apple");
#I Would print info with SetInfoLevel(InfoTest1,3)
#I Would print info with SetInfoLevel(InfoTest2,3)
gap> ShowUsedInfoClasses(false);
gap> str := "";;
gap> str2 := "";;
gap> SetDefaultInfoOutput(OutputTextString(str, false));
Expand Down

0 comments on commit 310eec5

Please sign in to comment.