Difference between revisions of "Talk:Code Completion Design"

From CodeBlocks
Jump to: navigation, search
(add document for parserthread)
 
m (others)
 
(50 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
=Parsethread=
 
=Parsethread=
 
Three important  functions should be introduced before we started .
 
Three important  functions should be introduced before we started .
# SkipToOneOfChars This function is used to skip any tokens until it meet any char in chars which is the parameter you pass.
+
# '''SkipToOneOfChars''' This function is used to skip any tokens until it meet a char in chars which is the parameter you pass.
# SkipBlock This function is used to skip block between two brances,for example ,{[()]}.If the block contain the proprocessor ,it will deal with it.
+
# '''SkipBlock''' This function is used to skip block between two brances,for example ,{[()]}.If the block contain the proprocessor ,it will deal with it.
# SkipAngleBraces This function is used to skip the context between < and >.
+
# '''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 '''m_Str''' is used to store 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.
 
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:
+
 
 +
In the function DoParse,it analyze the tokens it meets as follow:
  
  
Line 15: Line 17:
  
 
==clear m_Str==
 
==clear m_Str==
just clear the m_strbecause the parser believe the token has been recognized correctly .
+
just clear the m_str,because the parser believe the token has been recognized correctly.
 
e.g. int a;
 
e.g. int a;
  
==delete . ->==
+
==deal with delete . ->==
skip the tokens until it meet ; or }
+
when parser meet these three tokens it will skip the next tokens until it meet token ; or }
e.g. delete p;
+
 
e.g. MyClass .fun();
+
e.g.  
e.g. MyClass->fun();
+
<source lang = "cpp">delete p;
 +
 
 +
MyClass.fun();
 +
 
 +
MyClass->fun();
 +
</source>
 +
 
 
==deal with { ==
 
==deal with { ==
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.
e.g. int main() {cout <<endl;}
+
<source lang = "cpp">
 +
int main() {cout <<endl;}
 +
</source>
 +
 
 
==deal with }==
 
==deal with }==
clear the scope and relation it belong to .
+
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 : ==
set the scope .
+
When parser meets this token.It will judge what the last token is. And set the related 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.
+
e.g.
== typedef==
+
<source lang = "cpp">
call HandleTypedef to deal with it if the option handletypedef is true.
+
class MyClass
otherwise,it will skip the context until it meet ;or }
+
{
== return :==
+
public :
skip the context until it meet the ; or }
+
    int x;
== const ==
+
    int y;
just clear th e m_str
+
};
== extern ==
+
</source>
 +
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.  
 +
<source lang = "cpp">
 +
if (a > b)
 +
 
 +
        c = a;
 +
 
 +
    else
 +
 
 +
        c = b;
 +
</source>
 +
 
 +
==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 }
 +
<source lang = "cpp">
 +
typedef int INT;
 +
</source>
 +
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.
 +
<source lang = "cpp">
 +
int add(int a, int b)
 +
 
 +
{
 +
 
 +
    return a+b;
 +
 
 +
}
 +
</source>
 +
==deal with  const ==
 +
just clear the m_str.It means that maybe a new variable or function is going to be defined.
 +
 
 +
e.g.
 +
 
 +
<source lang = "cpp">
 +
const int a = 3;
 +
 
 +
const int getVal(int a);
 +
</source>
 +
 
 +
==deal with  extern ==
 
call DoParse if the next token is "c",otherwise,skip the context until it meet ;
 
call DoParse if the next token is "c",otherwise,skip the context until it meet ;
== __asm ==
+
 
 +
==deal with  __asm ==
 
skip the context until it meet ;
 
skip the context until it meet ;
== static virtual inline ==
+
 
 +
==deal with  static virtual inline ==
 
do nothing
 
do nothing
== # ==
+
 
handle include if the next token is include
+
==deal with  # ==
handle define if the next token is define
+
Handle include if the next token is include.
otherwise handle the preprocessor block
+
 
== using ==
+
Handle define if the next token is define.
 +
 
 +
otherwise handle the preprocessor block.
 +
 
 +
e.g.
 +
<source lang = "cpp">
 +
#include <iostream>
 +
 
 +
#define MAXNUM 10
 +
 
 +
#if
 +
 
 +
#else
 +
 
 +
#endif
 +
</source>
 +
 
 +
==deal with using ==
 
skip the context until it meet ;or }
 
skip the context until it meet ;or }
== namespace ==
+
 
 +
e.g.
 +
<source lang = "cpp">
 +
using namespace std;
 +
</source>
 +
 
 +
==deal with namespace ==
 
skip context between < and > if the next token is <
 
skip context between < and > if the next token is <
== class ==
+
 
handle class if the option handleclass is true.otherwise skip it
+
==deal with class ==
== struct ==
+
handle class if handleclass in the option is true.Otherwise skip context until the parser meet } or ;
 +
 +
e.g.
 +
<source lang = "cpp">
 +
class Myclass
 +
{
 +
 
 +
    int x;
 +
    int y;
 +
 
 +
};
 +
</source>
 +
 
 +
==deal with struct ==
 
the same to class
 
the same to class
== enum ==
+
 
 +
==deal with enum ==
 
the same to class
 
the same to class
== untion ==
+
 
 +
==deal with untion ==
 
skip the context until it meet }or;
 
skip the context until it meet }or;
 
call DoParse to analyze the context in the untion.
 
call DoParse to analyze the context in the untion.
== operator ==
+
 
eg.  MyClass operator () (size_t param);
+
==deal with operator ==
 +
eg.   
 +
<source lang = "cpp">
 +
      MyClass operator () (size_t param);
 
       MyClass operator += (MyClass param);
 
       MyClass operator += (MyClass param);
 +
</source>
 
== others ==
 
== others ==
It means that the current token is not any one above .
+
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 (.
+
According to the next token ,it can be divided into several situation as followed.
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 .
+
1) the next one's fisrt char is (
eg.  int x:1,y:1,z:1;
+
<source lang = "cpp">
 +
Macro(a, b) fun(int a , int b);
 +
vector<int>  fun(int a , int b);
 +
</source>
 +
 
 +
2) : and the current is not public /protected /private  
 +
 
 +
eg.   
 +
<source lang = "cpp">int x:1,y:1,z:1;</source>
 +
 
 
3),
 
3),
e.g. int  x , y, z;
+
 
 +
e.g.  
 +
<source lang = "cpp">int  x , y, z;</source>
 +
 
 
4)<
 
4)<
e.g. someclass<void>::memberfunc;
+
 
e.g. std::map<int, int> somevar;
+
e.g.  
 +
<source lang = "cpp">
 +
someclass<void>::memberfunc;
 +
 
 +
std::map<int, int> somevar;
 +
</source>
 
5)::
 
5)::
e.g. std::string
+
 
e.g. MyClass MyClass ::fun() {}
+
e.g.
 +
<source lang = "cpp">
 +
std::string
 +
 
 +
MyClass MyClass ::fun() {}
 +
</source>
 
6) ;
 
6) ;

Latest revision as of 16:21, 17 December 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 a 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 store 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 the m_str.It means that maybe a new variable or function is going to be defined.

e.g.

const int a = 3;
 
const int getVal(int a);

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
 
#else 
 
#endif

deal with using

skip the context until it meet ;or }

e.g.

 
using namespace std;

deal with namespace

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

deal with class

handle class if handleclass in the option 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;
 
std::map<int, int> somevar;

5)::

e.g.

std::string
 
MyClass MyClass ::fun() {}

6) ;