Hi, all, with the help of ollydbg, I have enhanced the CC by solving the #if XXX expression value.
As of now, the parser in CC only parse all the #if XXX branch, and ignore all the #else branch. That's not so satisfied for me, So, my implementation of the new CC is that I have resolved all the expression after the #if . Here is the test code:
Test code one:
#include <iostream>
using namespace std;
//#define TEST_
#ifdef TEST_ //Here, you can change the #ifdef to ifndef, if defined or if !defined. all should works.
int iIfdef1;
int iIfdef2;
int iIfdef3;
int iIfdef4;
int iIfdef5;
int iIfdef6;
#else
int iElse1;
int iElse2;
int iElse3;
int iElse4;
int iElse5;
int iElse6;
#endif
int main()
{
return 0;
}
Test code two:
#include <windows.h> // I have tested under MinGW
int main()
{
CreateFile // Well, this function can be showned in autocompletion list, (you need the add #include <winbase.h> before.
return 0;
}
A belief description of parsing windows.h by now:
code snippet in windows.h
#ifdef RC_INVOKED
/* winresrc.h includes the necessary headers */
#include <winresrc.h>
#else
#include <stdarg.h>
#include <windef.h>
#include <wincon.h>
#include <winbase.h>
My implementation of CC is that #ifdef RC_INVOKED get false, then, the #else branch was parsed, then winbase.h file was automatically included.
Test code three:
#if 0
#define Expression_1
#elif 0
#define Expression_2
#elif 0
#define Expression_3
#elif 0
#define Expression_4
#if 0
#define Expression_4_if
#else
#define Expression_4_else
#endif
#elif 0
#define Expression_5
#else
#define Expression_1_else
#if 0
#define Expression_1_else_if
#elif 0
#define Expression_1_else_elif
#else
#define Expression_1_else_else
#if 0
#define Expression_1_else_else_if
#elif 0
#define Expression_1_else_else_elif_1
#elif 0
#define Expression_1_else_else_elif_2
#else
#define Expression_1_else_else_else
#if 1
#define Expression_1_else_else_else_if
#endif
#if 1
#define Expression_1_else_if2
#else
#define Expression_1_else_else2
#endif
#endif
#endif
#endif
int main()
{
Exp
return 0;
}
My implemenatation of CC can correctly parse arbitrary level of the predefined conditional derective. You can tested by your self.
Comments are welcome. thanks.
By the way, in rare cases, when the expression resolving precession failed, I have a "fall back" method, which is still parse the #if branch by default( the same way as the current CC's parser) Beta 2 changed:Rewrote ParserThread::SkipToNextPreprocessorBlock() and ParserThread::SkipToEndPreprocessorBlock(), make it clear.
AND FIX a bug!Version 2 Change Log:1. Move condition preprocessor handle from ParserThread to Tokenizer class
2. Support parse like this demo:
#define AAA
void test(int testInt1 // some comment
#ifdef AAA // test
, int testInt2)
#else
)
#endif
{
tes|
};
3. Rewrote SkipXXX functions.
4. Make argument support default value, like
(int i, bool b = true)5. Fixed some bugs.
Another test demo:
class A
{
public:
void AFunc()
{
}
};
class B
{
public:
void BFunc()
{
}
};
class C
#ifndef AAA
: public A
#else
: public B
#endif
{
public:
void CFunc()
{
}
};
C c;
c.
V2 - Beta 2 Change Log:1. Fixed some bugs.
2. Add #undef handle
3. Refactoring Expression
V2 - Beta 3 Change Log:1. Replace from 'GetArgument' to 'ReadBlock'.
2. Fix bugs.
NOTE: Once officially accepted this patch, all attachment will be deleted.Welcome for test!
[attachment deleted by admin]