summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2011-09-21 08:12:14 +0000
committeraarne <aarne@chalmers.se>2011-09-21 08:12:14 +0000
commit958e81126d9bee7d190e738102836918f37b756b (patch)
treef3f6dd26e28b2738741f85befe2f268d6a59c729 /src/compiler/GF/Grammar
parent33a42b1c7ca74fd4484fd143b5396d61fa924eb7 (diff)
commands ss to show source, and sd to show the dependencies of a constant
Diffstat (limited to 'src/compiler/GF/Grammar')
-rw-r--r--src/compiler/GF/Grammar/Analyse.hs41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/compiler/GF/Grammar/Analyse.hs b/src/compiler/GF/Grammar/Analyse.hs
index ad538de87..9946c7812 100644
--- a/src/compiler/GF/Grammar/Analyse.hs
+++ b/src/compiler/GF/Grammar/Analyse.hs
@@ -1,16 +1,20 @@
module GF.Grammar.Analyse (
- stripSourceGrammar
+ stripSourceGrammar,
+ constantDepsTerm
) where
import GF.Grammar.Grammar
import GF.Infra.Ident
import GF.Infra.Option ---
import GF.Infra.Modules
+import GF.Grammar.Macros
+import GF.Grammar.Lookup
import GF.Data.Operations
import qualified Data.Map as Map
-
+import Data.List (nub)
+import Debug.Trace
stripSourceGrammar :: SourceGrammar -> SourceGrammar
stripSourceGrammar sgr = mGrammar [(i, m{jments = Map.map stripInfo (jments m)}) | (i,m) <- modules sgr]
@@ -27,3 +31,36 @@ stripInfo i = case i of
CncFun mict mte mtf -> CncFun mict Nothing Nothing
AnyInd b f -> i
+constantsInTerm :: Term -> [Term]
+constantsInTerm = nub . consts where
+ consts t = case t of
+ Q _ -> [t]
+ QC _ -> [t]
+ _ -> collectOp consts t
+
+constantDeps :: SourceGrammar -> QIdent -> Err [Term]
+constantDeps sgr f = do
+ ts <- deps f
+ let cs = [i | t <- ts, i <- getId t]
+ ds <- mapM deps cs
+ return $ nub $ concat $ ts:ds
+ where
+ deps c = case lookupOverload sgr c of
+ Ok tts ->
+ return $ concat [constantsInTerm ty ++ constantsInTerm tr | (_,(ty,tr)) <- tts]
+ _ -> do
+ ty <- lookupResType sgr c
+ tr <- lookupResDef sgr c
+ return $ constantsInTerm ty ++ constantsInTerm tr
+ getId t = case t of
+ Q i -> [i]
+ QC i -> [i]
+ _ -> []
+
+constantDepsTerm :: SourceGrammar -> Term -> Err [Term]
+constantDepsTerm sgr t = case t of
+ Q i -> constantDeps sgr i
+ QC i -> constantDeps sgr i
+ P (Vr r) l -> constantDeps sgr $ (r,label2ident l) ---
+ _ -> Bad ("expected qualified constant, not " ++ show t)
+