Difference between revisions of "Talk:Code Completion Design"

From CodeBlocks
Jump to: navigation, search
m (deal with :: add code tag)
(add more code fields)
Line 23: Line 23:
 
when parser meet these three tokens it will skip the next tokens until it meet token ; or }
 
when parser meet these three tokens it will skip the next tokens until it meet token ; or }
  
e.g. delete p;
+
e.g.  
 +
<pre>delete p;
  
e.g. MyClass.fun();
+
MyClass.fun();
  
e.g. MyClass->fun();
+
MyClass->fun();
 +
</pre>
  
 
==deal with { ==
 
==deal with { ==
The parser will skip the context between { and } if the usebuffer or the bufferskipblock is true in the option.
+
The parser will skip the context between { and } if the usebuffer or the bufferskipblock is true in the option.eg.
 
+
<pre>
e.g. int main() {cout <<endl;}
+
int main() {cout <<endl;}
 +
</pre>
  
 
==deal with }==
 
==deal with }==
Line 53: Line 56:
  
 
==deal with  while if  do else for switch==
 
==deal with  while if  do else for switch==
skip the context until it meet ;or } if the usebuffer or the bufferskipblock is true in the option.
+
skip the context until it meet ;or } if the usebuffer or the bufferskipblock is true in the option.e.g.  
 
+
<pre>
e.g.  
+
 
+
 
if (a > b)
 
if (a > b)
  
Line 64: Line 65:
  
 
         c = b;
 
         c = b;
 +
</pre>
  
 
==deal with  typedef==
 
==deal with  typedef==
 
When parser meet this token ,it calls HandleTypedef function to deal with it if the option handletypedef is true.
 
When parser meet this token ,it calls HandleTypedef function to deal with it if the option handletypedef is true.
 
Otherwise,it will skip the next context until it meet ;or }
 
Otherwise,it will skip the next context until it meet ;or }
 
+
<pre>
 
typedef int INT;
 
typedef int INT;
 
+
</pre>
 
More Information, see below.
 
More Information, see below.
  
Line 76: Line 78:
 
The parser skips the context until it meet the ; or }
 
The parser skips the context until it meet the ; or }
  
Because the parser believe that there is no chance for variab definition here.
+
Because the parser believe that there is no chance for variab definition here. e.g.  
 
+
<pre>
e.g. int add(int a, int b)
+
int add(int a, int b)
  
 
{
 
{
Line 85: Line 87:
  
 
}
 
}
 
+
</pre>
 
==deal with  const ==
 
==deal with  const ==
 
just clear th e m_str
 
just clear th e m_str
Line 105: Line 107:
 
otherwise handle the preprocessor block.
 
otherwise handle the preprocessor block.
  
e.g. #include <iostream>
+
e.g.  
 +
<pre>
 +
#include <iostream>
  
e.g. #define MAXNUM 10
+
#define MAXNUM 10
  
e.g. #if
+
#if
 +
</pre>
  
 
==deal with using ==
 
==deal with using ==
 
skip the context until it meet ;or }
 
skip the context until it meet ;or }
 
+
<pre>
e.g.
+
 
+
 
using namespace std;
 
using namespace std;
 +
</pre>
  
 
==deal with namespace ==
 
==deal with namespace ==
Line 123: Line 127:
 
==deal with class ==
 
==deal with class ==
 
handle class if the option handleclass is true.otherwise skip context until the  
 
handle class if the option handleclass is true.otherwise skip context until the  
parser meet } or ;
+
parser meet } or ; e.g.
 
+
<pre>
e.g.
+
 
+
 
class Myclass
 
class Myclass
 
 
{
 
{
  
Line 135: Line 136:
  
 
};
 
};
 +
</pre>
  
 
==deal with struct ==
 
==deal with struct ==
Line 148: Line 150:
 
==deal with operator ==
 
==deal with operator ==
 
eg.   
 
eg.   
 
+
<pre>
 
       MyClass operator () (size_t param);
 
       MyClass operator () (size_t param);
 
       MyClass operator += (MyClass param);
 
       MyClass operator += (MyClass param);
 
+
</pre>
 
== others ==
 
== others ==
 
It means that the current token is not any one above.So the next token should be judged.
 
It means that the current token is not any one above.So the next token should be judged.
Line 159: Line 161:
  
 
1) the next one's fisrt char is (
 
1) the next one's fisrt char is (
 
+
<pre>
eg.  Macro(a, b) fun(int a , int b);
+
Macro(a, b) fun(int a , int b);
 
+
vector<int>  fun(int a , int b);
eg.  vector<int>  fun(int a , int b);
+
</pre>
  
 
2): and the current is not public /protected /private  
 
2): and the current is not public /protected /private  
  
eg.  int x:1,y:1,z:1;
+
eg.   
 +
<pre>int x:1,y:1,z:1;</pre>
  
 
3),
 
3),
  
e.g. int  x , y, z;
+
e.g.  
 +
<pre>int  x , y, z;</pre>
  
 
4)<
 
4)<
 
+
<pre>
 
e.g. someclass<void>::memberfunc;
 
e.g. someclass<void>::memberfunc;
  
 
e.g. std::map<int, int> somevar;
 
e.g. std::map<int, int> somevar;
 
+
</pre>
 
5)::
 
5)::
 +
e.g.
 +
<pre>
 +
std::string
  
e.g. std::string
+
MyClass MyClass ::fun() {}
 
+
</pre>
e.g. MyClass MyClass ::fun() {}
+
 
+
 
6) ;
 
6) ;
  

Revision as of 07:45, 31 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 meets as follow:



clear m_Str

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

deal with delete . ->

when parser meet these three tokens it will skip the next tokens until it meet token ; or }

e.g.

delete p;

MyClass.fun();

MyClass->fun();

deal with {

The parser will skip the context between { and } if the usebuffer or the bufferskipblock is true in the option.eg.

int main() {cout <<endl;}

deal with }

The parser clears the scope and domain.So it means it's a new begin. By the way,it also clear m_Str.

deal with :

When parser meets this token.It will judge what the last token is. And set the related scope.

e.g.

class MyClass 
{
 public :
    int x;
    int y;
};

Here the scope is public.

deal with while if do else for switch

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

if (a > b)

         c = a;

     else

         c = b;

deal with typedef

When parser meet this token ,it calls HandleTypedef function to deal with it if the option handletypedef is true. Otherwise,it will skip the next context until it meet ;or }

typedef int INT;

More Information, see below.

deal with return :

The parser skips the context until it meet the ; or }

Because the parser believe that there is no chance for variab definition here. e.g.

int add(int a, int b)

{

    return a+b;

}

deal with const

just clear th e m_str

deal with extern

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

deal with __asm

skip the context until it meet ;

deal with static virtual inline

do nothing

deal with #

Handle include if the next token is include.

Handle define if the next token is define.

otherwise handle the preprocessor block.

e.g.

#include <iostream>

#define MAXNUM 10

#if

deal with using

skip the context until it meet ;or }

 
using namespace std;

deal with namespace

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

deal with class

handle class if the option handleclass is true.otherwise skip context until the parser meet } or ; e.g.

class Myclass
{

    int x; 
    int y;

};

deal with struct

the same to class

deal with enum

the same to class

deal with untion

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

deal with operator

eg.

       MyClass operator () (size_t param);
       MyClass operator += (MyClass param);

others

It means that the current token is not any one above.So the next token should be judged.

According to the next token ,it can be divided into several situation as followed.


1) the next one's fisrt char is (

Macro(a, b) fun(int a , int b);
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

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.