Difference between revisions of "Talk:Code Completion Design"

From CodeBlocks
Jump to: navigation, search
(add document for parserthread)
 
(Handling class and typedef)
Line 83: Line 83:
 
e.g. MyClass MyClass ::fun() {}
 
e.g. MyClass MyClass ::fun() {}
 
6) ;
 
6) ;
 +
 +
 +
==Handling class example==
 +
The main routing of handling class was in
 +
ParserThread::HandleClass function
 +
If the parserThread meet these statement
 +
<pre>
 +
class AAA{
 +
    int m_a;
 +
    int m_b;
 +
} ;
 +
</pre>
 +
It will surely add a Token of "AAA", which has a type of "class".
 +
 +
What about these statements
 +
<pre>
 +
class AAA{
 +
    int m_a;
 +
    int m_b;
 +
} x,y,z;
 +
</pre>
 +
The parserThread should firstly add a Token "AAA", then it should regard "x", "y", "z" are three variables of type "AAA". This was done by "ReadVarNames()" function, it will read every comma separated variables after a class declaration
 +
 +
==Handling typedef==
 +
 +
Sometimes, you can see these code:
 +
<pre>
 +
typedef class AAA{
 +
    int m_a;
 +
    int m_b;
 +
} BBB,CCC;
 +
</pre>
 +
If the parser meet the keyword "typedef", firstly it set the "m_ParsingTypedef = ture" to indicate that we are parsing a typedef statement.
 +
 +
Next, it meets a keyword "class", which also indicate it is a class declaration. So, the HandleClass function will do the task. A Token of "class AAA" will be added to the TokensTree. Wait a minute, how can we deal with "BBB" and "CCC", this is not the same case as previous code, we can't regard "BBB","CCC" as variables. In this case, another function "ReadClsName()" will be called. For simplicity of TokensTree, we just regard "BBB" and "CCC" as derived class of "AAA".
 +
 +
How does the parser know between these two cases. Here is the code:
 +
 +
<pre>
 +
                if (m_ParsingTypedef)
 +
                {
 +
                    m_Str.Clear();
 +
                    ReadClsNames(newToken->m_Name);
 +
                    // m_ParsingTypedef = false;
 +
                    break;
 +
 +
                }
 +
                else
 +
                {
 +
                    m_Str = newToken->m_Name;
 +
                    ReadVarNames();
 +
                    m_Str.Clear();
 +
                    break;
 +
                }
 +
</pre>
 +
 +
That's the whole thing I would like to write about handling class and handling typedef.

Revision as of 14:51, 30 July 2009

Should be added to the article page soon

Parsethread

Three important functions should be introduced before we started .

  1. SkipToOneOfChars This function is used to skip any tokens until it meet any char in chars which is the parameter you pass.
  2. SkipBlock This function is used to skip block between two brances,for example ,{[()]}.If the block contain the proprocessor ,it will deal with it.
  3. SkipAngleBraces This function is used to skip the context between < and >.

the m_Str is used to stored the token can not be decided .

The three functions above are used to skip tokens we wantn't to parse.It can acclerate the speed of parser. In the function DoParse,it analyze the tokens it meet as follow:



clear m_Str

just clear the m_strbecause the parser believe the token has been recognized correctly . e.g. int a;

delete . ->

skip the tokens until it meet ; or } e.g. delete p; e.g. MyClass .fun(); e.g. MyClass->fun();

deal with {

skip the context between { and } if the usebuffer or the bufferskipblock is true in the option. e.g. int main() {cout <<endl;}

deal with }

clear the scope and relation it belong to .

:

set the scope .

while if do else for switch

skip the context until it meet ;or } if the usebuffer or the bufferskipblock is true in the option.

typedef

call HandleTypedef to deal with it if the option handletypedef is true. otherwise,it will skip the context until it meet ;or }

return :

skip the context until it meet the ; or }

const

just clear th e m_str

extern

call DoParse if the next token is "c",otherwise,skip the context until it meet ;

__asm

skip the context until it meet ;

static virtual inline

do nothing

#

handle include if the next token is include handle define if the next token is define otherwise handle the preprocessor block

using

skip the context until it meet ;or }

namespace

skip context between < and > if the next token is <

class

handle class if the option handleclass is true.otherwise skip it

struct

the same to class

enum

the same to class

untion

skip the context until it meet }or; call DoParse to analyze the context in the untion.

operator

eg. MyClass operator () (size_t param);

      MyClass operator += (MyClass param);

others

It means that the current token is not any one above . According to the next token ,it can be divided into several situation as followed . 1) the next one's fisrt char is (. eg. Macro(a, b) fun(int a , int b); eg. vector<int> fun(int a , int b); 2): and the current is not public /protected /private . eg. int x:1,y:1,z:1; 3), e.g. int x , y, z; 4)< e.g. someclass<void>::memberfunc; e.g. std::map<int, int> somevar; 5):: e.g. std::string e.g. MyClass MyClass ::fun() {} 6) ;


Handling class example

The main routing of handling class was in ParserThread::HandleClass function If the parserThread meet these statement

class AAA{
    int m_a;
    int m_b;
} ;

It will surely add a Token of "AAA", which has a type of "class".

What about these statements

class AAA{
    int m_a;
    int m_b;
} x,y,z;

The parserThread should firstly add a Token "AAA", then it should regard "x", "y", "z" are three variables of type "AAA". This was done by "ReadVarNames()" function, it will read every comma separated variables after a class declaration

Handling typedef

Sometimes, you can see these code:

typedef class AAA{
    int m_a;
    int m_b;
} BBB,CCC;

If the parser meet the keyword "typedef", firstly it set the "m_ParsingTypedef = ture" to indicate that we are parsing a typedef statement.

Next, it meets a keyword "class", which also indicate it is a class declaration. So, the HandleClass function will do the task. A Token of "class AAA" will be added to the TokensTree. Wait a minute, how can we deal with "BBB" and "CCC", this is not the same case as previous code, we can't regard "BBB","CCC" as variables. In this case, another function "ReadClsName()" will be called. For simplicity of TokensTree, we just regard "BBB" and "CCC" as derived class of "AAA".

How does the parser know between these two cases. Here is the code:

                if (m_ParsingTypedef)
                {
                    m_Str.Clear();
                    ReadClsNames(newToken->m_Name);
                    // m_ParsingTypedef = false;
                    break;

                }
                else
                {
                    m_Str = newToken->m_Name;
                    ReadVarNames();
                    m_Str.Clear();
                    break;
                }

That's the whole thing I would like to write about handling class and handling typedef.