Difference between revisions of "Code Completion Design"

From Code::Blocks
(Moved from user document)
 
(add images and debuglog description)
Line 1: Line 1:
 
[[Category:Developer Documentation]]
 
[[Category:Developer Documentation]]
==Get the source code==
+
==How to build==
 +
===Get the source code===
 
When you download the  svn source code of code::blocks,(see here [[Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_sources]] the source code of this plugin was already included. See a screenshot of these code opened in code::blocks under windows.
 
When you download the  svn source code of code::blocks,(see here [[Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_sources]] the source code of this plugin was already included. See a screenshot of these code opened in code::blocks under windows.
 
[[Image:Devcc1.png|frame|none| Code completion source tree opened in code::blocks]]
 
[[Image:Devcc1.png|frame|none| Code completion source tree opened in code::blocks]]
 +
===Build the code completion plug in===
 +
[[Image:Buildcc.PNG|frame|none| Code completion build target option in code::blocks]]
 +
Note, you should use "update.bat" to copy the new generated dll to the destination and strip the debug information. see [[Installing_Code::Blocks_from_source_on_Windows]]
 +
 
==Low level parser==
 
==Low level parser==
For someone havn't heard what does "Token" and "Tokenize" means, you should read the wikibooks article [http://en.wikibooks.org/wiki/C%2B%2B_Programming/Compiler#Compilation A brief explain of what does a parser do] and [http://en.wikipedia.org/wiki/Lexical_analysis Tokenize on wikipedia]. Shortly, a parser treats your C++ or C code as a large array of characters, then this big string was divided to small atom strings, meanwhile "spaces" and "comments" were ignored.
+
For someone haven't heard what does "Token" and "Tokenize" means, you should read the wikibooks article [http://en.wikibooks.org/wiki/C%2B%2B_Programming/Compiler#Compilation A brief explain of what does a parser do] and [http://en.wikipedia.org/wiki/Lexical_analysis Tokenize on wikipedia]. Shortly, a parser treats your C++ or C code as a large array of characters, then this big string was divided to small atom strings, meanwhile "spaces" and "comments" were ignored.
 
===Tokenizer class===
 
===Tokenizer class===
 
There are several steps to running the Tokenizer class
 
There are several steps to running the Tokenizer class
Line 12: Line 17:
 
*Nested Value was kept to indicate your are in the correct brace pair.
 
*Nested Value was kept to indicate your are in the correct brace pair.
 
==High level parser==
 
==High level parser==
 +
===Token===
 +
For boosting the speed of allocating Tokens, the "new" and "delete" operator were overloaded in it's base class say "class Token  : public BlockAllocated<Token, 10000>". In BlockAllocated class, there is only a static member say "static BlockAllocator<T, pool_size, debug> allocator;" to keep all the pre-allocated memorys for all derived class.'''10000''' means 10000 Tokens were allocated. 
 +
[[Image:Cb blockalloc.png|frame|none|  Operator new overloading for fast allocate in the heap]]
 +
 
Each identifier will be recorded and saved in the memory for later usage.
 
Each identifier will be recorded and saved in the memory for later usage.
 
==UI issue==
 
==UI issue==
 +
===Debug Log output===
 +
If you want to debug your plug-in, you may need to Logout the debug information. Mostly, here is the code
 +
'''
 +
Manager::Get()->GetLogManager()->DebugLog(_("XXXXX "));'''
 +
 +
Also, you need start the codeblocks with the command line argument. For example in windows.
 +
 +
'''codeblocks.exe --debug-log'''
 +
 +
then a Code::blocks debug panel will be shown to display the log.
 +
[[Image:CbDebugLog.png|frame|none|  Debug Log output panel]]

Revision as of 03:50, 22 February 2009

How to build

Get the source code

When you download the svn source code of code::blocks,(see here Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_sources the source code of this plugin was already included. See a screenshot of these code opened in code::blocks under windows.

Code completion source tree opened in code::blocks

Build the code completion plug in

Code completion build target option in code::blocks

Note, you should use "update.bat" to copy the new generated dll to the destination and strip the debug information. see Installing_Code::Blocks_from_source_on_Windows

Low level parser

For someone haven't heard what does "Token" and "Tokenize" means, you should read the wikibooks article A brief explain of what does a parser do and Tokenize on wikipedia. Shortly, a parser treats your C++ or C code as a large array of characters, then this big string was divided to small atom strings, meanwhile "spaces" and "comments" were ignored.

Tokenizer class

There are several steps to running the Tokenizer class

  • A thread must be created to parse a source file.
  • Open the source file and convert the file buff to Unicode mode.(since we are all using Unicode build of code::blocks, and ANSI mode is outdated).
  • The class contains a Pointer to the current position of the character, so, you can Get or Peek the current character.
  • Nested Value was kept to indicate your are in the correct brace pair.

High level parser

Token

For boosting the speed of allocating Tokens, the "new" and "delete" operator were overloaded in it's base class say "class Token : public BlockAllocated<Token, 10000>". In BlockAllocated class, there is only a static member say "static BlockAllocator<T, pool_size, debug> allocator;" to keep all the pre-allocated memorys for all derived class.10000 means 10000 Tokens were allocated.

Operator new overloading for fast allocate in the heap

Each identifier will be recorded and saved in the memory for later usage.

UI issue

Debug Log output

If you want to debug your plug-in, you may need to Logout the debug information. Mostly, here is the code Manager::Get()->GetLogManager()->DebugLog(_("XXXXX "));

Also, you need start the codeblocks with the command line argument. For example in windows.

codeblocks.exe --debug-log

then a Code::blocks debug panel will be shown to display the log.

Debug Log output panel