News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Parse enumerator assignment

Started by Alpha, March 22, 2013, 01:39:48 PM

Previous topic - Next topic

Alpha

Testing parsing of enumerator assignments.  (Patch attached.)

oBFusCATed

Can you give example, what doesn't work and work works with the patch.
I'm not sure I understand the term enumerator assignments.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alpha

Given the following from src/plugins/codecompletion/parser/tokenizer.h

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:
TokenizerState::tsSkipQuestion=
With this patch, it becomes:
TokenizerState::tsSkipQuestion=0x0002
With this patch, the tool tip for tsTemplateArgument is:
TokenizerState::tsTemplateArgument=tsSkipUnWanted|tsSingleAngleBrace

Given the following code:

enum HexAssignment
{
    haFirst = 0x0001,
    haSecond,
    haThird
};

enum Colors
{
    clRed,
    clBlue,
    clGreen
};

enum TestEnum
{
    teFirst,
    teSecond = 5,
    teThird
};

haFirst is:
HexAssignment::haFirst=0x0001
haSecond is:
HexAssignment::haSecond=0x0002
haThird is:
HexAssignment::haThird=0x0003
clRed is:
Colors::clRed=0
clGreen is:
Colors::clGreen=2
teFirst is
TestEnum::teFirst=0
teThird is
TestEnum::teThird=6

Alpha


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:
TokenizerState::tsAnotherState=

oBFusCATed

Have tried to add a test to the test application (cctest or something like this)?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alpha

No, I have not added test cases yet; I will try to this weekend.

ollydbg

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:


        // 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:
enumerator->m_Args += peek; //emulator values were stored in m_Args field of the Token



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


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Alpha

Attached patch has better comments (functionality is the same).  I will write test cases, and then probably commit if no problems are identified.