Author Topic: The parsing flow explanation by a simple example  (Read 10274 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
The parsing flow explanation by a simple example
« on: July 24, 2013, 07:32:48 am »
If we have a foo.cbp (located in e:/foo/), which contains 5 files below:

foo.cbp has custom compiler include search path: c:/wx/include
foo.cbp has custom macro definition __GNUWIN32__ and __WXMSW__

we have prioirty file setting in CodeCompletion dialog:
"prep.h",<wxprep.h>, "stdafx.h"

We use mingw compiler which is located in d:/mingw463/

Now, we are going to parse this project.

1, Parser's include paths:
   add project common folder to Parser object: e:/foo
   add project setting search path c:/wx/include
2, Compiler's buildin include paths
    add d:/mingw463/include
   add d:/mingw463/lib/gcc/i686-w64-mingw32/4.6.3/include

3, Compiler's buildin Preprocessor macros:
   run GCC -dM command, get a buffer like:
   #define __DBL_MIN_EXP__ (-1021)
   #define __UINT_LEAST16_MAX__ 65535
   #define __FLT_MIN__ 1.17549435082228750797e-38F
   #define __UINT_LEAST8_TYPE__ unsigned char
   #define _WIN32 1
4,  Project's preprocessor macros:
   #define __GNUWIN32__
   #define __WXMSW__
5,   Search all the setting priority files in the above include paths
   "prep.h" was found under e:/foo/ -> it is a local priority header
   <wxprep.h> was found under c:/wx/include -> it is a global priority header
   "stdafx.h" not find in any paths, skip
6,  Create a ParserThreadTask thread, waiting for ThreadDone event.

7, in ParserThreadTask executing, did the following:
   7.1 parse preprocessor macros gothered from step3 and step4
   7.2 parse priority headers, in our example, it is c:/wx/include/wxprep.h and e:/foo/prep.h
   7.3 parse a.h and b.h
   7.4 parse a.cpp and b.cpp
   7.5 parse system priority header again, which is c:/wx/include/wxprep.h in our case
   7.6 mark a.h b.h a.cpp b.cpp as local parsed files
8, Done

BTW: it looks like the step7 is quite complex, it involve a lot of Timer tick and Thread creation.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.