Skip to content

Commit

Permalink
Add ShowUsedInfoClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Apr 7, 2019
1 parent cd25afc commit dfb8333
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
31 changes: 31 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="ShowUsedInfoClasses"/> will show all info classes which
&GAP; considers while executing code.
<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,35 @@ returns the info level of <A>infoclass</A>.
</Description>
</ManSection>
<P/>
<ManSection>
<Func Name="ShowUsedInfoClasses" Arg='infoclass'/>

<Description>
Called with argument <K>true</K>, this makes &GAP; print the info class and level of
any executed <Ref Func="Info"/> statement. Calling with the argument <K>false</K> stops this
printing.

Each level of each InfoClass is only printed once. The history of printed
info classes and levels is reset whenever <K>true</K> 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(())
gap> ShowUsedInfoClasses(false);
]]></Example>

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

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

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


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


#############################################################################
##
## The following functions are used by ShowUsedInfoClasses
##
## SHOWN_USED_INFO_CLASSES contains the InfoClasses which have been printed
## out by ShowUsedInfoClasses.
## RESET_SHOW_USED_INFO_CLASSES and SHOW_USED_INFO_CLASSES are called from
## the kernel.

SHOWN_USED_INFO_CLASSES := [];

if IsHPCGAP then
ShareInternalObj(INFO_CLASSES);
fi;


BIND_GLOBAL("RESET_SHOW_USED_INFO_CLASSES", function()
atomic readwrite SHOWN_USED_INFO_CLASSES do
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]);
atomic readwrite SHOWN_USED_INFO_CLASSES do
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;
od;
end);

#############################################################################
##
#V InfoDebug
Expand Down
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
41 changes: 41 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,17 +100,32 @@ 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 }
};


/****************************************************************************
**
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
*/
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 @@ -100,6 +138,9 @@ static Int InitKernel(StructInitInfo * module)
*/
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 dfb8333

Please sign in to comment.