mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-14 13:42:50 -06:00
restore graphvizParseTree
This commit is contained in:
@@ -561,12 +561,8 @@ pgfCommands = Map.fromList [
|
|||||||
nodeEdgeStyle = valStrOpts "nodeedgestyle" "solid" opts,
|
nodeEdgeStyle = valStrOpts "nodeedgestyle" "solid" opts,
|
||||||
leafEdgeStyle = valStrOpts "leafedgestyle" "dashed" opts
|
leafEdgeStyle = valStrOpts "leafedgestyle" "dashed" opts
|
||||||
}
|
}
|
||||||
let depfile = valStrOpts "file" "" opts
|
|
||||||
concr <- optLang pgf opts
|
concr <- optLang pgf opts
|
||||||
mlab <- case depfile of
|
let grphs = map (graphvizParseTree concr gvOptions) es
|
||||||
"" -> return Nothing
|
|
||||||
_ -> (Just . getDepLabels) `fmap` restricted (readFile depfile)
|
|
||||||
let grphs = map (graphvizDependencyTree "dot" False mlab Nothing concr) es
|
|
||||||
if isFlag "view" opts || isFlag "format" opts
|
if isFlag "view" opts || isFlag "format" opts
|
||||||
then do
|
then do
|
||||||
let view = optViewGraph opts
|
let view = optViewGraph opts
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ libpgf_la_SOURCES = \
|
|||||||
pgf/typechecker.h \
|
pgf/typechecker.h \
|
||||||
pgf/linearizer.cxx \
|
pgf/linearizer.cxx \
|
||||||
pgf/linearizer.h \
|
pgf/linearizer.h \
|
||||||
|
pgf/graphviz.cxx \
|
||||||
|
pgf/graphviz.h \
|
||||||
pgf/data.cxx \
|
pgf/data.cxx \
|
||||||
pgf/data.h \
|
pgf/data.h \
|
||||||
pgf/expr.cxx \
|
pgf/expr.cxx \
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
#include "typechecker.h"
|
#include "typechecker.h"
|
||||||
#include "linearizer.h"
|
#include "linearizer.h"
|
||||||
|
#include "graphviz.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgf_exn_clear(PgfExn* err)
|
pgf_exn_clear(PgfExn* err)
|
||||||
@@ -2065,3 +2066,27 @@ void pgf_set_concrete_flag(PgfDB *db, PgfConcrRevision revision,
|
|||||||
concr->cflags = cflags;
|
concr->cflags = cflags;
|
||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API PgfText *
|
||||||
|
pgf_graphviz_parse_tree(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfMarshaller *m,
|
||||||
|
PgfGraphvizOptions* opts,
|
||||||
|
PgfExn *err)
|
||||||
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
|
DB_scope scope(db, READER_SCOPE);
|
||||||
|
|
||||||
|
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||||
|
|
||||||
|
PgfLinearizationGraphvizOutput out;
|
||||||
|
PgfLinearizer linearizer(concr, m);
|
||||||
|
m->match_expr(&linearizer, expr);
|
||||||
|
linearizer.reverse_and_label();
|
||||||
|
if (linearizer.resolve()) {
|
||||||
|
linearizer.linearize(&out);
|
||||||
|
return out.generate_graphviz(opts);
|
||||||
|
}
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -672,4 +672,23 @@ void pgf_set_concrete_flag(PgfDB *db, PgfConcrRevision revision,
|
|||||||
PgfMarshaller *m,
|
PgfMarshaller *m,
|
||||||
PgfExn *err);
|
PgfExn *err);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int noLeaves;
|
||||||
|
int noFun;
|
||||||
|
int noCat;
|
||||||
|
int noDep;
|
||||||
|
const char *nodeFont;
|
||||||
|
const char *leafFont;
|
||||||
|
const char *nodeColor;
|
||||||
|
const char *leafColor;
|
||||||
|
const char *nodeEdgeStyle;
|
||||||
|
const char *leafEdgeStyle;
|
||||||
|
} PgfGraphvizOptions;
|
||||||
|
|
||||||
|
PGF_API PgfText *
|
||||||
|
pgf_graphviz_parse_tree(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfMarshaller *m,
|
||||||
|
PgfGraphvizOptions* opts,
|
||||||
|
PgfExn *err);
|
||||||
|
|
||||||
#endif // PGF_H_
|
#endif // PGF_H_
|
||||||
|
|||||||
@@ -858,12 +858,40 @@ data GraphvizOptions = GraphvizOptions {noLeaves :: Bool,
|
|||||||
|
|
||||||
graphvizDefaults = GraphvizOptions False False False True "" "" "" "" "" ""
|
graphvizDefaults = GraphvizOptions False False False True "" "" "" "" "" ""
|
||||||
|
|
||||||
|
withGraphvizOptions :: GraphvizOptions -> (Ptr PgfGraphvizOptions -> IO a) -> IO a
|
||||||
|
withGraphvizOptions opts f =
|
||||||
|
allocaBytes (#size PgfGraphvizOptions) $ \c_opts ->
|
||||||
|
withCString (nodeFont opts) $ \c_nodeFont ->
|
||||||
|
withCString (leafFont opts) $ \c_leafFont ->
|
||||||
|
withCString (nodeColor opts) $ \c_nodeColor ->
|
||||||
|
withCString (leafColor opts) $ \c_leafColor ->
|
||||||
|
withCString (nodeEdgeStyle opts) $ \c_nodeEdgeStyle ->
|
||||||
|
withCString (leafEdgeStyle opts) $ \c_leafEdgeStyle -> do
|
||||||
|
(#poke PgfGraphvizOptions, noLeaves) c_opts (if noLeaves opts then 1 else 0 :: CInt)
|
||||||
|
(#poke PgfGraphvizOptions, noFun) c_opts (if noFun opts then 1 else 0 :: CInt)
|
||||||
|
(#poke PgfGraphvizOptions, noCat) c_opts (if noCat opts then 1 else 0 :: CInt)
|
||||||
|
(#poke PgfGraphvizOptions, noDep) c_opts (if noDep opts then 1 else 0 :: CInt)
|
||||||
|
(#poke PgfGraphvizOptions, nodeFont) c_opts c_nodeFont
|
||||||
|
(#poke PgfGraphvizOptions, leafFont) c_opts c_leafFont
|
||||||
|
(#poke PgfGraphvizOptions, nodeColor) c_opts c_nodeColor
|
||||||
|
(#poke PgfGraphvizOptions, leafColor) c_opts c_leafColor
|
||||||
|
(#poke PgfGraphvizOptions, nodeEdgeStyle) c_opts c_nodeEdgeStyle
|
||||||
|
(#poke PgfGraphvizOptions, leafEdgeStyle) c_opts c_leafEdgeStyle
|
||||||
|
f c_opts
|
||||||
|
|
||||||
-- | Renders an abstract syntax tree in a Graphviz format.
|
-- | Renders an abstract syntax tree in a Graphviz format.
|
||||||
graphvizAbstractTree :: PGF -> GraphvizOptions -> Expr -> String
|
graphvizAbstractTree :: PGF -> GraphvizOptions -> Expr -> String
|
||||||
graphvizAbstractTree p opts e = error "TODO: graphvizAbstractTree"
|
graphvizAbstractTree p opts e = error "TODO: graphvizAbstractTree"
|
||||||
|
|
||||||
graphvizParseTree :: Concr -> GraphvizOptions -> Expr -> String
|
graphvizParseTree :: Concr -> GraphvizOptions -> Expr -> String
|
||||||
graphvizParseTree c opts e = error "TODO: graphvizParseTree"
|
graphvizParseTree c opts e =
|
||||||
|
unsafePerformIO $
|
||||||
|
withForeignPtr (c_revision c) $ \c_revision ->
|
||||||
|
bracket (newStablePtr e) freeStablePtr $ \c_e ->
|
||||||
|
withForeignPtr marshaller $ \m ->
|
||||||
|
withGraphvizOptions opts $ \c_opts ->
|
||||||
|
bracket (withPgfExn "graphvizParseTree" (pgf_graphviz_parse_tree (c_db c) c_revision c_e m c_opts)) free $ \c_text ->
|
||||||
|
peekText c_text
|
||||||
|
|
||||||
graphvizWordAlignment :: [Concr] -> GraphvizOptions -> Expr -> String
|
graphvizWordAlignment :: [Concr] -> GraphvizOptions -> Expr -> String
|
||||||
graphvizWordAlignment cs opts e = error "TODO: graphvizWordAlignment"
|
graphvizWordAlignment cs opts e = error "TODO: graphvizWordAlignment"
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ data PgfUnmarshaller
|
|||||||
data PgfBuildLinIface
|
data PgfBuildLinIface
|
||||||
data PgfLinBuilderIface
|
data PgfLinBuilderIface
|
||||||
data PgfLinearizationOutputIface
|
data PgfLinearizationOutputIface
|
||||||
|
data PgfGraphvizOptions
|
||||||
|
|
||||||
type Wrapper a = a -> IO (FunPtr a)
|
type Wrapper a = a -> IO (FunPtr a)
|
||||||
type Dynamic a = FunPtr a -> a
|
type Dynamic a = FunPtr a -> a
|
||||||
@@ -226,6 +227,9 @@ foreign import ccall pgf_get_concrete_flag :: Ptr PgfDB -> Ptr Concr -> Ptr PgfT
|
|||||||
|
|
||||||
foreign import ccall pgf_set_concrete_flag :: Ptr PgfDB -> Ptr Concr -> Ptr PgfText -> StablePtr Literal -> Ptr PgfMarshaller -> Ptr PgfExn -> IO ()
|
foreign import ccall pgf_set_concrete_flag :: Ptr PgfDB -> Ptr Concr -> Ptr PgfText -> StablePtr Literal -> Ptr PgfMarshaller -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
|
foreign import ccall pgf_graphviz_parse_tree :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfMarshaller -> Ptr PgfGraphvizOptions -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- Texts
|
-- Texts
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user