Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: Alpha on March 22, 2013, 01:39:48 pm

Title: Parse enumerator assignment
Post by: Alpha on March 22, 2013, 01:39:48 pm
Testing parsing of enumerator assignments.  (Patch attached.)
Title: Re: Parse enumerator assignment
Post by: oBFusCATed on March 22, 2013, 07:08:43 pm
Can you give example, what doesn't work and work works with the patch.
I'm not sure I understand the term enumerator assignments.
Title: Re: Parse enumerator assignment
Post by: Alpha on March 22, 2013, 08:26:50 pm
Given the following from src/plugins/codecompletion/parser/tokenizer.h
Code
enum TokenizerState
{
    tsSkipEqual         = 0x0001,         /// Skip the assignment statement
    tsSkipQuestion      = 0x0002,         /// Skip the conditional evaluation statement
    tsSkipSubScrip      = 0x0004,         /// Skip the array-subscript notation statement

    tsSingleAngleBrace  = 0x0008,         /// Reserve angle braces
    tsReadRawExpression = 0x0010,         /// Reserve every chars

    tsSkipNone          = 0x1000,         /// Skip None
    // convenient masks
    tsSkipUnWanted      = tsSkipEqual    | tsSkipQuestion | tsSkipSubScrip,
    tsTemplateArgument  = tsSkipUnWanted | tsSingleAngleBrace
};
The tool tip for tsSkipQuestion is currently:
Code
TokenizerState::tsSkipQuestion=
With this patch, it becomes:
Code
TokenizerState::tsSkipQuestion=0x0002
With this patch, the tool tip for tsTemplateArgument is:
Code
TokenizerState::tsTemplateArgument=tsSkipUnWanted|tsSingleAngleBrace

Given the following code:
Code
enum HexAssignment
{
    haFirst = 0x0001,
    haSecond,
    haThird
};

enum Colors
{
    clRed,
    clBlue,
    clGreen
};

enum TestEnum
{
    teFirst,
    teSecond = 5,
    teThird
};
haFirst is:
Code
HexAssignment::haFirst=0x0001
haSecond is:
Code
HexAssignment::haSecond=0x0002
haThird is:
Code
HexAssignment::haThird=0x0003
clRed is:
Code
Colors::clRed=0
clGreen is:
Code
Colors::clGreen=2
teFirst is
Code
TestEnum::teFirst=0
teThird is
Code
TestEnum::teThird=6
Title: Re: Parse enumerator assignment
Post by: Alpha on March 22, 2013, 08:39:44 pm
Code
enum TokenizerState
{
    tsSkipEqual         = 0x0001,         /// Skip the assignment statement
    tsSkipQuestion      = 0x0002,         /// Skip the conditional evaluation statement
    tsSkipSubScrip      = 0x0004,         /// Skip the array-subscript notation statement

    tsSingleAngleBrace  = 0x0008,         /// Reserve angle braces
    tsReadRawExpression = 0x0010,         /// Reserve every chars

    tsSkipNone          = 0x1000,         /// Skip None
    // convenient masks
    tsSkipUnWanted      = tsSkipEqual    | tsSkipQuestion | tsSkipSubScrip,
    tsTemplateArgument  = tsSkipUnWanted | tsSingleAngleBrace,
    tsAnotherState
};
What does not work is that with this patch tsAnotherState will still have the tool tip:
Code
TokenizerState::tsAnotherState=
Title: Re: Parse enumerator assignment
Post by: oBFusCATed on March 22, 2013, 11:44:10 pm
Have tried to add a test to the test application (cctest or something like this)?
Title: Re: Parse enumerator assignment
Post by: Alpha on March 23, 2013, 03:52:41 am
No, I have not added test cases yet; I will try to this weekend.
Title: Re: Parse enumerator assignment
Post by: ollydbg on March 25, 2013, 04:07:12 pm
Just applied your patch (not test yet), and I see that the major part of your patch is handling the assignment.
Looks really nice.
So some suggestions:

Code
        // assignments (=xxx) are ignored by the tokenizer,
        // so we don't have to worry about them here ;)
These two comment lines should be removed.

Maybe, add comments like:
Code
enumerator->m_Args += peek; //emulator values were stored in m_Args field of the Token

Code

                        // emulator value string may have two types, hex value with prefix "0x" or decimal value
                        if (lastEnumerator->m_Args.StartsWith(wxT("0x")))

Title: Re: Parse enumerator assignment
Post by: Alpha on March 29, 2013, 08:39:50 pm
Attached patch has better comments (functionality is the same).  I will write test cases, and then probably commit if no problems are identified.