From e39b3d4f9b0666e822381c258ad3a1373a790fce Mon Sep 17 00:00:00 2001 From: Markus Pfeiffer Date: Thu, 13 Apr 2017 00:10:08 +0100 Subject: [PATCH] Add function LocationOfDeclaration This function returns the location of the declaration of the passed object if it is known. --- lib/type.gd | 18 ++++++++++++++++++ lib/type.gi | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/type.gd b/lib/type.gd index cd2634dfb8..072a245578 100644 --- a/lib/type.gd +++ b/lib/type.gd @@ -72,3 +72,21 @@ DeclareGlobalFunction( "IsCategory" ); ## ## <#/GAPDoc> DeclareGlobalFunction( "CategoryByName" ); + + +############################################################################# +## +#F LocationOfDeclaration( ) +## +## Find the location of the declaration of . +## +## <#GAPDoc Label="LocationOfDeclaration"> +## +## +## +## +## returns the location of the declaration of object if it is known. +## +## +## <#/GAPDoc> +DeclareGlobalFunction( "LocationOfDeclaration" ); diff --git a/lib/type.gi b/lib/type.gi index fa8c53af2b..dc88738167 100644 --- a/lib/type.gi +++ b/lib/type.gi @@ -171,3 +171,21 @@ function(name) return fail; end); +InstallGlobalFunction( LocationOfDeclaration, +function(object) + local fid; + if IsFilter(object) then + fid := IdOfFilter(object); + if fid <> fail then + if IsBound(FILTERS_LOCATIONS[fid]) then + return FILTERS_LOCATIONS[fid]; + fi; + fi; + elif IsOperation(object) then + fid := Position(OPERATIONS, object); + if IsBound(OPERATIONS_LOCATIONS[fid + 1]) then + return OPERATIONS_LOCATIONS[fid + 1]; + fi; + fi; + return fail; +end);