Search code examples
cdoxygenx-macros

X-macro breaks doxygen callgraph


I have 3 files:

test.c

int table[] = {
    #define X(val)    val,
    #include "test.x"
    #undef X
};
void level2(void) {
    level3();
    level4();
}
void level3(void) {
    level4();
}

test2.c

void level1(void) {
    level2();
    level3();
    level4();
}
void level4(void) {
}

test.x

X(1)
X(2)
X(3)

I use doxygen to create callgraphs for these functions. Here's what I expected:

  • level1:
    • References level2(), level3(), and level4().
  • level2:
    • References level3(), and level4().
    • Referenced by level1().
  • level3:
    • References level4().
    • Referenced by level1(), and level2().
  • level4:
    • Referenced by level1(), level2(), and level3().

But here is what I got:

  • level1:
    • References level2(), level3(), and level4().
  • level2:
    • Referenced by level1().
  • level3:
    • Referenced by level1().
  • level4:
    • Referenced by level1().

It seems X-macro on test.c is the culprit. I managed to make it work by doing 2 things (either will do):

  1. Renaming test.x so doxygen doesn't find it. It will show warning, but callgraph is correct.
  2. Adding trailing newline at the end of test.x. Normally file would end immediately after X(3).

Question:

How can I get reliable callgraph out of doxygen without editing the files? Is there a setting I need to change or is this plain bug?


Solution

  • I've had varying experience with xmacros. In general Doxygen will treat macros as proper declarations and not actually preprocess them. In order to get macros working (and this includes x-macros). In general:

    1. Set MACRO_EXPANSION=yes
    2. Either set EXPAND_ONLY_PREDEF=yes (which will make Doxygen expand all macros) or
    3. Add the name of your macro to EXPAND_AS_DEFINED.

    Additionally, take note of this: http://www.doxygen.nl/manual/config.html#cfg_skip_function_macros

    To give you an idea about what's possible with xmacros and Doxygen, I can generate proper documentation from this: https://github.com/couchbase/libcouchbase/blob/master/include/libcouchbase/error.h#L95