Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShowUsedInfoClasses #3387

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SOURCES += src/gap.c
SOURCES += gen/gap_version.c # generated source file
SOURCES += src/gvars.c
SOURCES += src/hookintrprtr.c
SOURCES += src/info.c
SOURCES += src/integer.c
SOURCES += src/intfuncs.c
SOURCES += src/intrprtr.c
Expand Down
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 info class 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
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 := [];
ChrisJefferson marked this conversation as resolved.
Show resolved Hide resolved

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
1 change: 1 addition & 0 deletions src/compiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern "C" {
#include "gapstate.h"
#include "gasman.h"
#include "gvars.h"
#include "info.h"
#include "integer.h"
#include "intrprtr.h"
#include "io.h"
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
170 changes: 170 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares the functions handling Info statements.
*/


#include "info.h"

#include "bool.h"
#include "calls.h"
#include "error.h"
#include "gapstate.h"
#include "gvars.h"
#include "modules.h"
#include "plist.h"

#ifdef HPCGAP
#include "hpc/aobjects.h"
#endif

enum {
INFODATA_NUM = 1,
INFODATA_CURRENTLEVEL,
INFODATA_CLASSNAME,
INFODATA_HANDLER,
INFODATA_OUTPUT,
};

static Obj InfoDecision;
static Obj IsInfoClassListRep;
static Obj DefaultInfoHandler;
static Obj ResetShowUsedInfoClassesHandler;
static Obj ShowUsedInfoClassesHandler;


Obj FuncShowUsedInfoClasses(Obj self, Obj choice)
{
RequireTrueOrFalse("ShowUsedInfoClasses", choice);

if (choice == True) {
STATE(ShowUsedInfoClassesActive) = 1;
CALL_0ARGS(ResetShowUsedInfoClassesHandler);
}
else {
STATE(ShowUsedInfoClassesActive) = 0;
}

return 0;
}

void InfoDoPrint(Obj cls, Obj lvl, Obj args)
{
if (IS_PLIST(cls))
cls = ELM_PLIST(cls, 1);
#if defined(HPCGAP)
Obj fun = Elm0AList(cls, INFODATA_HANDLER);
#else
Obj fun = ELM_PLIST(cls, INFODATA_HANDLER);
#endif
if (!fun)
fun = DefaultInfoHandler;

CALL_3ARGS(fun, cls, lvl, 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.
if (CALL_1ARGS(IsInfoClassListRep, selectors) == True) {
#if defined(HPCGAP)
Obj index = ElmAList(selectors, INFODATA_CURRENTLEVEL);
#else
Obj index = ELM_PLIST(selectors, INFODATA_CURRENTLEVEL);
#endif
if (IS_INTOBJ(index) && IS_INTOBJ(level)) {
// < on INTOBJs compares the represented integers.
if (index < level) {
return False;
}
}
}
return CALL_2ARGS(InfoDecision, selectors, 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;
}


/****************************************************************************
**
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
*/
static Int InitLibrary(StructInitInfo * module)
{

ChrisJefferson marked this conversation as resolved.
Show resolved Hide resolved
InitGVarFuncsFromTable(GVarFuncs);

ExportAsConstantGVar(INFODATA_CURRENTLEVEL);
ExportAsConstantGVar(INFODATA_CLASSNAME);
ExportAsConstantGVar(INFODATA_HANDLER);
ExportAsConstantGVar(INFODATA_OUTPUT);
ExportAsConstantGVar(INFODATA_NUM);

/* return success */
return 0;
}

/****************************************************************************
**
*F InitInfoInfo() . . . . . . . . . . . . . . . . . table of init functions
*/
static StructInitInfo module = {
// init struct using C99 designated initializers; for a full list of
// fields, please refer to the definition of StructInitInfo
.type = MODULE_BUILTIN,
.name = "info",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
};

StructInitInfo * InitInfoInfo(void)
{
return &module;
}
42 changes: 42 additions & 0 deletions src/info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares the functions handling Info statements.
*/

#ifndef GAP_INFO_H
#define GAP_INFO_H

#include "gap.h"
#include "system.h"

/****************************************************************************
**
*F InfoCheckLevel( <selectors>, <level> ) . . . check if Info should output
** InfoDoPrint( <selectors>, <level>, <args> ) . . . print an Info statement
*/

Obj InfoCheckLevel(Obj selectors, Obj level);

void InfoDoPrint(Obj cls, Obj lvl, Obj args);


/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
*/


/****************************************************************************
**
*F InitInfoInfo() . . . . . . . . . . . . . . . . . table of init functions
*/
StructInitInfo * InitInfoInfo(void);

#endif
Loading