Skip to content

Commit

Permalink
Add ShowDeclarationsOfOperation helper
Browse files Browse the repository at this point in the history
When debugging issues with method installations for operations (including
attributes and properties), it can be helpful to find out what all
declarations of a given operation are. This helper function does just that.
  • Loading branch information
fingolfin committed May 17, 2019
1 parent f30c1e4 commit 82aa61e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/ref/create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ See also Section <Ref Sect="More About Global Variables"/>.
<#Include Label="DeclareSynonym">
<#Include Label="FlushCaches">
<#Include Label="FilterByName">
<#Include Label="ShowDeclarationsOfOperation">

</Section>

Expand Down
43 changes: 43 additions & 0 deletions lib/methwhy.g
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,49 @@ BIND_GLOBAL("ShowImpliedFilters",function(filter)
fi;
end);


#############################################################################
##
#F ShowDeclarationsOfOperation( <oper> )
##
## <#GAPDoc Label="ShowDeclarationsOfOperation">
## <ManSection>
## <Func Name="ShowDeclarationsOfOperation" Arg='oper'/>
##
## <Description>
## Displays information about all declarations of the operation <A>oper</A>,
## including the location of each declaration and the argument filters.
## <Log><![CDATA[
## gap> ShowDeclarationsOfOperation(IsFinite);
## Available declarations for operation <Property "IsFinite">:
## 1: GAPROOT/lib/coll.gd:1451 with 1 arguments, and filters [ IsListOrCollection ]
## 2: GAPROOT/lib/float.gd:212 with 1 arguments, and filters [ IsFloat ]
## 3: GAPROOT/lib/ctbl.gd:1195 with 1 arguments, and filters [ IsNearlyCharacterTable ]
## ]]></Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BIND_GLOBAL("ShowDeclarationsOfOperation",function(oper)
local locs, reqs, i, r;
if not IsOperation(oper) then
Error("<oper> must be an operation");
fi;
Print("Available declarations for operation ", oper, ":\n");
locs := GET_DECLARATION_LOCATIONS(oper);
reqs := GET_OPER_FLAGS(oper);
for i in [1.. Length(locs)] do
r := List(reqs[i], r -> JoinStringsWithSeparator(NamesFilter(r), " and "));
Print(String(i, 3), ": ", locs[i][1], ":", locs[i][2],
" with ", Length(reqs[i]),
" arguments, and filters [ ",
JoinStringsWithSeparator(r, ", "),
" ]\n"
);
od;
end);


#############################################################################
##
#F PageSource( func ) . . . . . . . . . . . . . . . show source code in pager
Expand Down

0 comments on commit 82aa61e

Please sign in to comment.