3

I'm just curious if anybody could help with finding good tool for the task. I have large program in C/C++ which needs to be ported from Win32 to Linux. As "wrapping" (i.e. the most OS-sensitive) part was successfully isolated from insides of the program this task only involves going through its "internals". Some things works, some cause small compile time problems but there is one HUGE inconvenient part - macro usage.

Basically most of the internals look like this:

START_MAIN( ... )
  SOME_MACRO( ... )
  ANOTHER_MACRO( ... )
  WRITE_SOMETHING()
END_MAIN()

This makes C/C++ look like Pascal but gives also lots of terrible pain while trying to figure out "what's wrong".

Are there ANY tools to help with parsing this kind of sources to get to the root of problems?

I'm slowly (manually) approaching "compilability" of this program but anything what could help me see through this (artificially structured) mess would be really appreciated.

yatsek
  • 855
  • 1
  • 10
  • 19

2 Answers2

1

If you need to manually adjust the compiling, output and stuff (i.e. looking for a customizable C++ parser), clang is a good tool to start with.

In case you just want to see the preprocessed code (with macros expanded), you can use compiler flags:
MSVC: add /P to C++ compiler flags (Project -> Properties -> C/C++ -> Command Line)
GCC, Clang: Add the -E compiler flag

This question about preprocessing C++ code contains some answers you might find useful.

Community
  • 1
  • 1
Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
  • And if the preprocessed code is too unreadable, try running it through [GNU Indent](http://www.gnu.org/software/indent/). – Greg Hewgill Aug 23 '11 at 23:48
  • Yes - I know about compiler flags but those are not very helpful. In result (after preprocessing) I get tones of code which is again very difficult to read. I was thinking that the best tool would be something (vim plugin ?) which would expand/collapse specific macro (in real time) so I could jump between program logic (this Pascal-like language) and internals causing problems – yatsek Aug 23 '11 at 23:48
  • I guess you can't do much about it - if the information what the code does is not there, an automated tool won't help you. Preprocessing and using some code beautifier might help uncovering some things but I'm afraid only the heuristics built into your brain can process that big ball of mud. – Karel Petranek Aug 23 '11 at 23:55
0

Eclipse CDT will expand macros and even show you how many macro-evaluations were required to reach the final code that would be emitted by the preprocessor.

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_whatsnew.htm

Look at the "Macro Exploration" section.

lnqhien
  • 59
  • 3
  • I'll go with that solution. Probably using some more advanced ctags/cscope-kung-fu would give more extensive information but I need to quickly fix that pile of c..ode. And this is enough - although I'm still hoping that there is some holy grail of (easy) parsing. Thanks for sharing! :) – yatsek Aug 24 '11 at 22:08