J
Jens Schweikhardt
hello, world\n
consider a small project of 100 C source and 100 header files.
The coding rules require that only C files include headers,
headers are not allowed to include other headers (not sure if
this is 100% the "IWYU - Include What You Use" paradigma).
The headers contain only what headers should contain:
prototypes, typedefs, declarations, macro definitions.
The problem: given a set of headers, determine a sequence of
#include directives that avoids syntax errors due to undeclared
identifiers. I.e. if "foo.h" declares type foo_t and "bar.h" uses
foo_t in a prototype, "bar.h" must be included before "foo.h".
I'm not a computer scientist, but it sounds as if this requires a
topological sort of all the '"foo.h" needs "bar.h"' relations. Now the
interesting part is: how to automate this, i.e. how to determine "this
header declares identifiers A, B, C and requires X, Y, Z"? I looked
at IWYU by google, but it requires a clang source tree plus some more
hoop jumping and that's way too elephantine, so I gave up not knowing
whether it would provide a solution.
Can you think of a lightweight way to solve this? Maybe using perl, the
unix tool box, make, gmake, gcc, a C lexer?
Regards,
Jens
consider a small project of 100 C source and 100 header files.
The coding rules require that only C files include headers,
headers are not allowed to include other headers (not sure if
this is 100% the "IWYU - Include What You Use" paradigma).
The headers contain only what headers should contain:
prototypes, typedefs, declarations, macro definitions.
The problem: given a set of headers, determine a sequence of
#include directives that avoids syntax errors due to undeclared
identifiers. I.e. if "foo.h" declares type foo_t and "bar.h" uses
foo_t in a prototype, "bar.h" must be included before "foo.h".
I'm not a computer scientist, but it sounds as if this requires a
topological sort of all the '"foo.h" needs "bar.h"' relations. Now the
interesting part is: how to automate this, i.e. how to determine "this
header declares identifiers A, B, C and requires X, Y, Z"? I looked
at IWYU by google, but it requires a clang source tree plus some more
hoop jumping and that's way too elephantine, so I gave up not knowing
whether it would provide a solution.
Can you think of a lightweight way to solve this? Maybe using perl, the
unix tool box, make, gmake, gcc, a C lexer?
Regards,
Jens