News:

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

Main Menu

rev7176, potential bug

Started by ollydbg, May 30, 2011, 08:04:27 AM

Previous topic - Next topic

ollydbg

@loaden:
rev7176, you add a function call

                        // After add a variable token, we should skip to semicolon
                        SkipToOneOfChars(ParserConsts::semicolonclbrace, true);
                        m_Str.Clear();


But look at the DoParse() code:

case ParserConsts::semicolon_chr:
                {
                    m_Str.Clear();
                    m_PointerOrRef.Clear();
                    // Notice: clears the queue "m_EncounteredTypeNamespaces"
                    while (!m_EncounteredTypeNamespaces.empty())
                        m_EncounteredTypeNamespaces.pop();
                    m_TemplateArgument.Clear();
                }
                break;


So, if you Get(eat) the semicolon too earlier, you have no change to clear the context.
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.

ollydbg

BTW:
who can explain the logic to detect a "variable" in these code snippet:


                else if (   (peek == ParserConsts::semicolon)
                         || (   (   m_Options.useBuffer
                                 && (peek.GetChar(0) == ParserConsts::opbracket_chr) )
                             && (!m_Str.Contains(ParserConsts::dcolon)) ) )
                {
                    if (   !m_Str.IsEmpty()
                        && (    wxIsalpha(token.GetChar(0))
                            || (token.GetChar(0) == ParserConsts::underscore_chr) ) )
                    {
                        if (m_Options.handleVars)
                        {
                            Token* newToken = DoAddToken(tkVariable, token, m_Tokenizer.GetLineNumber());
                            if (newToken && !m_TemplateArgument.IsEmpty())
                                ResolveTemplateArgs(newToken);
                        }
                        // After add a variable token, we should skip to semicolon
                        SkipToOneOfChars(ParserConsts::semicolonclbrace, true);
                        m_Str.Clear();
                    }
                }

Too hard to understand the logic... :(
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.

MortenMacFly

Quote from: ollydbg on May 30, 2011, 08:04:27 AM
So, if you Get(eat) the semicolon too earlier, you have no change to clear the context.
I had another concern, but did not try (yet):
What about such constructs:
void main(void)
{
  int a,b,c;
  MyClass d,e,f;
}

... will b,c and e,f be skipped?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

Quote from: MortenMacFly on May 30, 2011, 09:10:14 AM
Quote from: ollydbg on May 30, 2011, 08:04:27 AM
So, if you Get(eat) the semicolon too earlier, you have no change to clear the context.
I had another concern, but did not try (yet):
What about such constructs:
void main(void)
{
  int a,b,c;
  MyClass d,e,f;
}

... will b,c and e,f be skipped?
I think no problem.
This can improve performance.

the a,b,c are local variable.
you can try:

  int a,b,c;
  MyClass d,e,f;



Loaden

Quote from: ollydbg on May 30, 2011, 08:04:27 AM
@loaden:
rev7176, you add a function call

                        // After add a variable token, we should skip to semicolon
                        SkipToOneOfChars(ParserConsts::semicolonclbrace, true);
                        m_Str.Clear();


But look at the DoParse() code:

case ParserConsts::semicolon_chr:
                {
                    m_Str.Clear();
                    m_PointerOrRef.Clear();
                    // Notice: clears the queue "m_EncounteredTypeNamespaces"
                    while (!m_EncounteredTypeNamespaces.empty())
                        m_EncounteredTypeNamespaces.pop();
                    m_TemplateArgument.Clear();
                }
                break;


So, if you Get(eat) the semicolon too earlier, you have no change to clear the context.
I see, you are right!
Thanks!