User forums > Help

Codecompletion parser bug on treating comments

(1/3) > >>

ollydbg:
I found that the parser stopped parsing in the comment blocks, and only two variables( int a, int b) were recognized.

--- Code: ---int a;
int b;

///remove "//" or "/*" blocks

int c;
int d;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

--- End code ---


thanks :D

MortenMacFly:

--- Quote from: ollydbg on March 09, 2009, 08:49:58 am ---I found that the parser stopped parsing in the comment blocks, and only two variables( int a, int b) were recognized.

--- End quote ---
That is correct. C::B recognises the /* as beginning of a multi-line comment which never ends.

If you find a way how to *fast* determine whether you are inside a string or not I am pleased to apply that. I believe there is no way to handle such without a certain slowdown.

BTW: Are you aware that a compiler will issue a warning in such cases about a multi-line comment inside a comment? There is a good reason it will do... ;-)

Jenna:

--- Quote from: MortenMacFly on March 09, 2009, 12:25:36 pm ---
--- Quote from: ollydbg on March 09, 2009, 08:49:58 am ---I found that the parser stopped parsing in the comment blocks, and only two variables( int a, int b) were recognized.

--- End quote ---
That is correct. C::B recognises the /* as beginning of a multi-line comment which never ends.

--- End quote ---

Why do we search for nested braces or other comments, while we are skipping to EndOfLine indside a comment ?.

As far as I know, there are only two things that can end a c++-style comment: a newline or EOF.

In other words, what about just "eating" all chars until EOL or EOF?

A patch can look like this:

--- Code: ---Index: src/plugins/codecompletion/parser/tokenizer.cpp
===================================================================
--- src/plugins/codecompletion/parser/tokenizer.cpp (Revision 5482)
+++ src/plugins/codecompletion/parser/tokenizer.cpp (Arbeitskopie)
@@ -279,18 +279,21 @@
     {
         while (NotEOF() && CurrentChar() != '\n')
         {
-            if (CurrentChar() == '/' && NextChar() == '*')
+            if(!skippingComment)
             {
-                SkipComment(false); // don't skip whitespace after the comment
-                if (skippingComment && CurrentChar() == '\n')
+                if (CurrentChar() == '/' && NextChar() == '*')
                 {
-                    continue; // early exit from the loop
+                    SkipComment(false); // don't skip whitespace after the comment
+                    if (skippingComment && CurrentChar() == '\n')
+                    {
+                        continue; // early exit from the loop
+                    }
                 }
+                if (nestBraces && CurrentChar() == _T('{'))
+                    ++m_NestLevel;
+                else if (nestBraces && CurrentChar() == _T('}'))
+                    --m_NestLevel;
             }
-            if (nestBraces && CurrentChar() == _T('{'))
-                ++m_NestLevel;
-            else if (nestBraces && CurrentChar() == _T('}'))
-                --m_NestLevel;
             MoveToNextChar();
         }
         wxChar last = PreviousChar();

--- End code ---

The patch looks a little bit "unclear", but this is how TortoiseSVN handles changed indendation, at least on my XP.
In fact I only added one if-clause with two braces.

If I have overseen or totally missing something, please correct me.

dje:
Shouldn't it be

--- Code: ---while (NotEOF() && CurrentChar() != '\n' && CurrentChar() != '\r')
--- End code ---
for Mac users ?

Dje

MortenMacFly:

--- Quote from: jens on March 09, 2009, 05:13:07 pm ---In other words, what about just "eating" all chars until EOL or EOF?

--- End quote ---
Nope - won't work. Consider this:

--- Code: ---void MyFun(bool myParam /* = true */, int MyOtherParam /* = 0 */)
{
  int a /* could be b */ = 1; /* probably 0 */
  int b; /* Descr:
           * Nice!
           */ return;
  string "hello
            world";
}

--- End code ---
...unless I am missing something...
(Will try the patch though...)

Navigation

[0] Message Index

[#] Next page

Go to full version