0

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?

user694733
  • 13,861
  • 1
  • 40
  • 62

1 Answers1

1

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

albert
  • 5,966
  • 3
  • 13
  • 29
Mark Nunberg
  • 3,141
  • 13
  • 16
  • For this specific case, docs for the X-macros are not useful to me, I only needed the callgraphs. However when I tested your suggestion, I also found `ENABLE_PREPROCESSING` which, when disabled, seems to do the trick. This solution is not optimal, but best so far. Thanks for guiding me in right direction. If no one posts other alternatives, I'll choose this answer. – user694733 Feb 13 '15 at 14:02
  • Hrm. Indeed -- in your case you specifically _don't_ want the macros to be treated as macros, but rather as functions! – Mark Nunberg Feb 13 '15 at 14:21