Author Topic: Parse enumerator assignment  (Read 13371 times)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Parse enumerator assignment
« on: March 22, 2013, 01:39:48 pm »
Testing parsing of enumerator assignments.  (Patch attached.)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: Parse enumerator assignment
« Reply #1 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.
(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!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Parse enumerator assignment
« Reply #2 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

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Parse enumerator assignment
« Reply #3 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=

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: Parse enumerator assignment
« Reply #4 on: March 22, 2013, 11:44:10 pm »
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!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Parse enumerator assignment
« Reply #5 on: March 23, 2013, 03:52:41 am »
No, I have not added test cases yet; I will try to this weekend.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5377
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Parse enumerator assignment
« Reply #6 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")))

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.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Parse enumerator assignment
« Reply #7 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.