Menu

#210 "&" and "*" are differently parsed in the CC's parser

Undefined
fixed
ollydbg
Undefined
2015-09-05
2015-09-05
ollydbg
No

While hunting the bug: Re: The 01 September 2015 build (10474) is out., I see this issue.

I create a simple cctest project(ccc_read_parenthese.cpp), and paste such code:

class AAA
{
    int* f1(wxCommandEvent & event);
    float& f2(wxCommandEvent & event);
};

You see the log:

000002. -----------I-n-t-e-r-i-m--L-o-g-----------
000003. InitTokenizer() : m_Filename='F:\cb_sf_git\trunk\src\plugins\codecompletion\testing\ccc_read_parenthese.cpp', m_FileSize=94.
000004. Init() : m_Filename='F:\cb_sf_git\trunk\src\plugins\codecompletion\testing\ccc_read_parenthese.cpp'
000005. F:\cb_sf_git\trunk\src\plugins\codecompletion\testing\ccc_read_parenthese.cpp
000006. Parse() : Parsing 'F:\cb_sf_git\trunk\src\plugins\codecompletion\testing\ccc_read_parenthese.cpp'
000007. DoParse() : Loop:m_Str='', token='class'
000008. HandleClass() : Found class 'AAA', next='{'
000009. DoAddToken() : Created token='AAA', file_idx=1, line=1, ticket=259
000010. GetTokenBaseType() : Searching within m_Str=''
000011. GetTokenBaseType() : Compensated m_Str=''
000012. GetTokenBaseType() : Returning ''
000013. DoAddToken() : Prepending ''
000014. DoAddToken() : Added/updated token 'AAA' (0), kind 'class', type '', actual ''. Parent is  (-1)
000015. DoParse() : Loop:m_Str='', token='int'
000016. DoParse() : Loop:m_Str='int ', token='*'
000017. DoParse() : Loop:m_Str='int ', token='f1'
000018. HandleFunction() : Adding function 'f1': m_Str='int '
000019. HandleFunction() : name='f1', args='(wxCommandEvent& event)', peek=';'
000020. HandleFunction() : !(Ctor/Dtor) 'f1', m_Str='int ', localParent='<none>'
000021. HandleFunction() : Adding function 'f1', ': m_Str='int ', enc_ns='nil'.
000022. HandleFunction() : Add token name='f1', args='(wxCommandEvent& event)', return type='int '
000023. GetBaseArgs() : args='(wxCommandEvent& event)'.
000024. GetBaseArgs() : baseArgs='(wxCommandEvent&)'.
000025. DoAddToken() : Created token='f1', file_idx=1, line=3, ticket=260
000026. GetTokenBaseType() : Searching within m_Str='int'
000027. GetTokenBaseType() : Compensated m_Str='int'
000028. GetTokenBaseType() : Found 'int'
000029. DoAddToken() : Prepending ''
000030. DoAddToken() : Added/updated token 'f1' (1), kind 'function', type 'int*', actual 'int'. Parent is AAA (0)
000031. DoParse() : Loop:m_Str='', token=';'
000032. DoParse() : Loop:m_Str='', token='float'
000033. DoParse() : Loop:m_Str='float ', token='&'
000034. DoParse() : Loop:m_Str='float & ', token='f2'
000035. HandleFunction() : Adding function 'f2': m_Str='float & '
000036. HandleFunction() : name='f2', args='(wxCommandEvent& event)', peek=';'
000037. HandleFunction() : !(Ctor/Dtor) 'f2', m_Str='float & ', localParent='<none>'
000038. HandleFunction() : Adding function 'f2', ': m_Str='float & ', enc_ns='nil'.
000039. HandleFunction() : Add token name='f2', args='(wxCommandEvent& event)', return type='float & '
000040. GetBaseArgs() : args='(wxCommandEvent& event)'.
000041. GetBaseArgs() : baseArgs='(wxCommandEvent&)'.
000042. DoAddToken() : Created token='f2', file_idx=1, line=4, ticket=261
000043. GetTokenBaseType() : Searching within m_Str='float &'
000044. GetTokenBaseType() : Compensated m_Str='float &'
000045. GetTokenBaseType() : Found 'float'
000046. DoAddToken() : Prepending ''
000047. DoAddToken() : Added/updated token 'f2' (2), kind 'function', type 'float &', actual 'float'. Parent is AAA (0)
000048. DoParse() : Loop:m_Str='', token=';'
000049. DoParse() : Loop:m_Str='', token='}'

You see the m_Str are different

Discussion

  • ollydbg

    ollydbg - 2015-09-05
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     While hunting the bug: [Re: The 01 September 2015 build (10474) is out.](http://forums.codeblocks.org/index.php/topic,20557.msg139856.html#msg139856), I see this issue.
    
    -I create a simple cctest project(ccc_parse_error.cpp), and paste such code:
    +I create a simple cctest project(ccc_read_parenthese.cpp), and paste such code:
    
         class AAA
         {
    
     
  • ollydbg

    ollydbg - 2015-09-05

    Well, I see that in the DoParse(), only * is handled, but not &, so this patch should fix the issue:

    src/plugins/codecompletion/parser/parserthread.cpp | 1 +
    1 file changed, 1 insertion(+)

    diff --git a/src/plugins/codecompletion/parser/parserthread.cpp b/src/plugins/codecompletion/parser/parserthread.cpp
    index 1e4b9f9..7cfcd9d 100644
    --- a/src/plugins/codecompletion/parser/parserthread.cpp
    +++ b/src/plugins/codecompletion/parser/parserthread.cpp
    @@ -657,6 +657,7 @@ void ParserThread::DoParse()
                     break;
    
                 case ParserConsts::ptr_chr:
    +            case ParserConsts::ref_chr:
                     {
                         m_PointerOrRef << token;
                     }
    
     
  • ollydbg

    ollydbg - 2015-09-05

    Fixed in rev10483

     
  • ollydbg

    ollydbg - 2015-09-05
    • status: open --> fixed
     
  • Teodor Petrov

    Teodor Petrov - 2015-09-05

    I see no test added to the test suite. Can you add one?

     
  • ollydbg

    ollydbg - 2015-09-05

    Well, the file(ccc_read_parenthese.cpp) I used for testing has no "test case for code suggestion list", I just run it under GDB to see whether it works OK.

    Our cctest frame can only test whether the suggestion list is correct or not, but the internal parsing logic is not tested yet.

    Some idea: maybe, we can add hook to DoAddToken() function, and see whether an expected Token is added correctly, but it is hard for a large file, because it may have thousands of Tokens.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.