summaryrefslogtreecommitdiff
path: root/src/compiler/GF
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2011-02-28 13:31:04 +0000
committeraarne <aarne@chalmers.se>2011-02-28 13:31:04 +0000
commit0dfbc9b73049ad810d04314b95729511863c3b51 (patch)
treea04bd82db982527f6ff9f45494dbdd4eef3cf9df /src/compiler/GF
parent66f95c2cb75248b663bbe67821a3fb8f9f12bf88 (diff)
the command show_operations to inspect opers in scope
Diffstat (limited to 'src/compiler/GF')
-rw-r--r--src/compiler/GF/Command/Commands.hs23
-rw-r--r--src/compiler/GF/Grammar/Lookup.hs40
-rw-r--r--src/compiler/GF/Grammar/Macros.hs1
3 files changed, 63 insertions, 1 deletions
diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs
index f7a34ee27..0161818f8 100644
--- a/src/compiler/GF/Command/Commands.hs
+++ b/src/compiler/GF/Command/Commands.hs
@@ -781,6 +781,29 @@ allCommands env@(pgf, mos) = Map.fromList [
"gt | l | sp -command=\"grep \\\"who\\\"\" | sp -command=\"wc\""
]
}),
+
+ ("so", emptyCommandInfo {
+ longname = "show_operations",
+ syntax = "so (-grep=STRING)* TYPE?",
+ synopsis = "show all operations in scope, possibly restricted to a value type",
+ explanation = unlines [
+ "Show the names and type signatures of all operations available in the current resource.",
+ "This command requires a source grammar to be in scope, imported with 'import -retain'.",
+ "The operations include the parameter constructors that are in scope.",
+ "The optional TYPE filters according to the value type.",
+ "The grep STRINGs filter according to other substrings of the type signatures.",
+ "This command must be a line of its own, and thus cannot be a part",
+ "of a pipe."
+ ],
+ flags = [
+ ("grep","substring used for filtering (the command can have many of these)")
+ ],
+ options = [
+ ("raw","show the types in computed forms (instead of category names)")
+ ],
+ needsTypeCheck = False
+ }),
+
("ut", emptyCommandInfo {
longname = "unicode_table",
synopsis = "show a transliteration table for a unicode character set",
diff --git a/src/compiler/GF/Grammar/Lookup.hs b/src/compiler/GF/Grammar/Lookup.hs
index 80dabef1b..b5959cf03 100644
--- a/src/compiler/GF/Grammar/Lookup.hs
+++ b/src/compiler/GF/Grammar/Lookup.hs
@@ -28,7 +28,8 @@ module GF.Grammar.Lookup (
lookupAbsDef,
lookupLincat,
lookupFunType,
- lookupCatContext
+ lookupCatContext,
+ allOpers, allOpersTo
) where
import GF.Data.Operations
@@ -43,6 +44,7 @@ import GF.Grammar.Lockfield
import Data.List (nub,sortBy)
import Control.Monad
import Text.PrettyPrint
+import qualified Data.Map as Map
-- whether lock fields are added in reuse
lock c = lockRecType c -- return
@@ -189,3 +191,39 @@ lookupCatContext gr m c = do
AbsCat (Just (L _ co)) -> return co
AnyInd _ n -> lookupCatContext gr n c
_ -> Bad (render (text "unknown category" <+> ppIdent c))
+
+
+-- this gives all opers and param constructors, also overloaded opers and funs, and the types, and locations
+-- notice that it only gives the modules that are reachable and the opers that are included
+
+allOpers :: SourceGrammar -> [((Ident,Ident),Type,(Int,Int))]
+allOpers gr =
+ [((mo,op),typ,loc) |
+ (mo,minc) <- reachable,
+ Ok minfo <- [lookupModule gr mo],
+ (op,info) <- Map.toList $ jments minfo,
+ isInherited minc op,
+ L loc typ <- typesIn info
+ ]
+ where
+ typesIn info = case info of
+ AbsFun (Just ltyp) _ _ _ -> [ltyp]
+ ResOper (Just ltyp) _ -> [ltyp]
+ ResValue ltyp -> [ltyp]
+ ResOverload _ tytrs -> [ltyp | (ltyp,_) <- tytrs]
+ _ -> []
+ reachable = case greatestResource gr of
+ Just r -> allExtendSpecs gr r
+ _ -> []
+
+--- not for dependent types
+allOpersTo :: SourceGrammar -> Type -> [((Ident,Ident),Type,(Int,Int))]
+allOpersTo gr ty = [op | op@(_,typ,_) <- allOpers gr, isProdTo ty typ] where
+ isProdTo t typ = eqProd typ t || case typ of
+ Prod _ _ a b -> isProdTo t b
+ _ -> False
+ eqProd f g = case (f,g) of
+ (Prod _ _ a1 b1, Prod _ _ a2 b2) -> eqProd a1 a2 && eqProd b1 b2
+ _ -> f == g
+
+
diff --git a/src/compiler/GF/Grammar/Macros.hs b/src/compiler/GF/Grammar/Macros.hs
index b40041e83..fb9979c31 100644
--- a/src/compiler/GF/Grammar/Macros.hs
+++ b/src/compiler/GF/Grammar/Macros.hs
@@ -621,6 +621,7 @@ allDependencies ism b =
opty _ = []
pts i = case i of
ResOper pty pt -> [pty,pt]
+--- ResOverload _ tyts -> concat [[Just ty, Just tr] | (ty,tr) <- tyts]
ResParam (Just ps) _ -> [Just (L loc t) | L loc (_,cont) <- ps, (_,_,t) <- cont]
CncCat pty _ _ -> [pty]
CncFun _ pt _ -> [pt] ---- (Maybe (Ident,(Context,Type))