mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 08:32:50 -06:00
dependency graph can be restricted to some modules; added help dg
This commit is contained in:
@@ -208,6 +208,31 @@ allCommands cod env@(pgf, mos) = Map.fromList [
|
|||||||
],
|
],
|
||||||
needsTypeCheck = False
|
needsTypeCheck = False
|
||||||
}),
|
}),
|
||||||
|
("dg", emptyCommandInfo {
|
||||||
|
longname = "dependency_graph",
|
||||||
|
syntax = "dg (-only=MODULES)?",
|
||||||
|
synopsis = "print module dependency graph",
|
||||||
|
explanation = unlines [
|
||||||
|
"Prints the dependency graph of source modules.",
|
||||||
|
"Requires that import has been done with the -retain flag.",
|
||||||
|
"The graph is written in the file _gfdepgraph.dot",
|
||||||
|
"which can be further processed by Graphviz (the system command 'dot').",
|
||||||
|
"By default, all modules are shown, but the -only flag restricts them",
|
||||||
|
"by a comma-separated list of patterns, where 'name*' matches modules",
|
||||||
|
"whose name has prefix 'name', and other patterns match modules with",
|
||||||
|
"exactly the same name. The graphical conventions are:",
|
||||||
|
" solid box = abstract, solid ellipse = concrete, dashed ellipse = other",
|
||||||
|
" solid arrow empty head = of, solid arrow = **, dashed arrow = open",
|
||||||
|
" dotted arrow = other dependency"
|
||||||
|
],
|
||||||
|
flags = [
|
||||||
|
("only","list of modules included (default: all), literally or by prefix*")
|
||||||
|
],
|
||||||
|
examples = [
|
||||||
|
"dg -only=SyntaxEng,Food* -- shows only SyntaxEng, and those with prefix Food"
|
||||||
|
],
|
||||||
|
needsTypeCheck = False
|
||||||
|
}),
|
||||||
("dt", emptyCommandInfo {
|
("dt", emptyCommandInfo {
|
||||||
longname = "define_tree",
|
longname = "define_tree",
|
||||||
syntax = "dt IDENT (TREE | STRING | \"<\" COMMANDLINE)",
|
syntax = "dt IDENT (TREE | STRING | \"<\" COMMANDLINE)",
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import GF.Grammar.Grammar
|
|||||||
import GF.Infra.Modules
|
import GF.Infra.Modules
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
|
|
||||||
depGraph :: SourceGrammar -> String
|
import Data.List (nub,isPrefixOf)
|
||||||
depGraph = prDepGraph . grammar2moddeps
|
|
||||||
|
-- the list gives the only modules to show, e.g. to hide the library details
|
||||||
|
depGraph :: Maybe [String] -> SourceGrammar -> String
|
||||||
|
depGraph only = prDepGraph . grammar2moddeps only
|
||||||
|
|
||||||
prDepGraph :: [(Ident,ModDeps)] -> String
|
prDepGraph :: [(Ident,ModDeps)] -> String
|
||||||
prDepGraph deps = unlines $ [
|
prDepGraph deps = unlines $ [
|
||||||
@@ -47,15 +50,25 @@ data ModDeps = ModDeps {
|
|||||||
|
|
||||||
noModDeps = ModDeps MTAbstract [] [] [] [] [] [] []
|
noModDeps = ModDeps MTAbstract [] [] [] [] [] [] []
|
||||||
|
|
||||||
grammar2moddeps :: SourceGrammar -> [(Ident,ModDeps)]
|
grammar2moddeps :: Maybe [String] -> SourceGrammar -> [(Ident,ModDeps)]
|
||||||
grammar2moddeps gr = [(i,depMod m) | (i,m) <- modules gr] where
|
grammar2moddeps monly gr = [(i,depMod i m) | (i,m) <- modules gr, yes i]
|
||||||
depMod m = noModDeps{
|
where
|
||||||
modtype = mtype m,
|
depMod i m =
|
||||||
ofs = case mtype m of
|
noModDeps{
|
||||||
MTConcrete i -> [i]
|
modtype = mtype m,
|
||||||
MTInstance i -> [i]
|
ofs = case mtype m of
|
||||||
_ -> [],
|
MTConcrete i -> [i | yes i]
|
||||||
extendeds = map fst (extend m),
|
MTInstance i -> [i | yes i]
|
||||||
openeds = map openedModule (opens m),
|
_ -> [],
|
||||||
extrads = mexdeps m
|
extendeds = nub $ filter yes $ map fst (extend m),
|
||||||
}
|
openeds = nub $ filter yes $ map openedModule (opens m),
|
||||||
|
extrads = nub $ filter yes $ mexdeps m
|
||||||
|
}
|
||||||
|
yes i = case monly of
|
||||||
|
Just only -> match (showIdent i) only
|
||||||
|
_ -> True
|
||||||
|
match s os = any (\x -> doMatch x s) os
|
||||||
|
doMatch x s = case last x of
|
||||||
|
'*' -> isPrefixOf (init x) s
|
||||||
|
_ -> x == s
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import GF.Command.Commands
|
|||||||
import GF.Command.Abstract
|
import GF.Command.Abstract
|
||||||
import GF.Command.Parse
|
import GF.Command.Parse
|
||||||
import GF.Data.ErrM
|
import GF.Data.ErrM
|
||||||
|
import GF.Data.Operations (chunks)
|
||||||
import GF.Grammar hiding (Ident)
|
import GF.Grammar hiding (Ident)
|
||||||
import GF.Grammar.Parser (runP, pExp)
|
import GF.Grammar.Parser (runP, pExp)
|
||||||
import GF.Grammar.ShowTerm
|
import GF.Grammar.ShowTerm
|
||||||
@@ -133,7 +134,10 @@ loop opts gfenv0 = do
|
|||||||
Bad s -> putStrLn $ enc s
|
Bad s -> putStrLn $ enc s
|
||||||
loopNewCPU gfenv
|
loopNewCPU gfenv
|
||||||
"dg":ws -> do
|
"dg":ws -> do
|
||||||
writeFile "_gfdepgraph.dot" (depGraph sgr)
|
let stop = case ws of
|
||||||
|
('-':'o':'n':'l':'y':'=':fs):_ -> Just $ chunks ',' fs
|
||||||
|
_ -> Nothing
|
||||||
|
writeFile "_gfdepgraph.dot" (depGraph stop sgr)
|
||||||
putStrLn "wrote graph in file _gfdepgraph.dot"
|
putStrLn "wrote graph in file _gfdepgraph.dot"
|
||||||
loopNewCPU gfenv
|
loopNewCPU gfenv
|
||||||
"eh":w:_ -> do
|
"eh":w:_ -> do
|
||||||
|
|||||||
Reference in New Issue
Block a user