Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Preprocessor

pad edited this page Oct 19, 2010 · 8 revisions

A recurring problem with the C/C++ parser included in pfff is the failure of the parser on code using certain cpp idioms. For instance with:

$ cat class.cpp
#define SLOT
class A {
        public SLOT:
          void foo(int);
};
int main() {}

The parser will choke with:

$ /pfff -dump_cpp_ml class.cpp > /dev/null
parse error
 = File "class.cpp", line 3, column 8,  charpos = 31
    around = 'SLOT', whole content =    public SLOT:
ERROR-RECOV: found sync '}' at line 5
ERROR-RECOV: found sync bis, eating } and ;
badcount: 4
bad: #define SLOT
bad: class A {
BAD:!!!!!       public SLOT:
bad:      void foo(int);
bad: };

This is "normal". The C/C++ parser in pfff try to parse as-is the source code, without calling first cpp, The C preprocessor. The reason is that in a refactoring context, you can not call cpp because cpp then expand all the macros and ifdefs which is a representation of the original source code that is not convenient to work on. Indeed modifying the expanded code with a refactoring would not easily back propagate to the original source (before expansion). To still be usable, the C++ parser recognize a few macros idioms such as FOR_EACH, attributes, etc. This is documented here: http://padator.org/papers/yacfe-cc09.pdf

TODO Use -D or -macro_file.

TODO

TODO

[1] Yoann Padioleau, Parsing C/C++ Code without Pre-processing, CC'2009
http://padator.org/papers/yacfe-cc09.pdf
Clone this wiki locally