In a large C project there are many struct
s that have other struct
s, or pointers to them, as fields. I want to create a directed graph to show the dependencies between the "types". An example would be
typedef struct javaStat {
int idNo;
struct idIdentList *className;
struct typeModifiers *thisType;
struct symbol thisClass;
} ...
From this I would like to generate a DOT structure, which would look like
digraph {
javaStat -> idIdentList
javaStat -> typeModifiers
javaStat -> symbol
}
or, using a DOT short-hand:
digraph {
javaStat -> {idIdentList typeModifiers symbol}
}
Of course the first and last lines can be added by hand, so the primary problem is converting the struct references to the graph "pointer" lines.
At this point I'm content with a first level solution, meaning that deeper nesting could be ignored.
I first tried a simple grep struct *.h
which produced something workable:
typedef struct javaStat {
struct idIdentList *className;
struct typeModifiers *thisType;
struct symbol thisClass;
typedef struct <next struct> {
This is a simple problem which a few lines of Python would solve, but are there other handy solutions, perhaps using sed
, grep
, awk
and their brethren?
EDIT: I've realized that the reason I want to do this is because I need to find one or more structures that are at the base of the "struct tree".
typedef
). – Devriespycparser
. – Knottspycparser
has helped me a couple of times. – Knottsc
. So I guess we're more or less in sync here. (But do check out libclang. The documentation sucks, but the interface is simple enough for simple things.) – Devries