News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

CC scope

Started by Alpha, October 29, 2011, 08:41:33 PM

Previous topic - Next topic

Alpha

Quote from: ollydbg on November 19, 2012, 11:39:54 AM
1, if you remove the whole "{" block, you will remove all the EOL characters "\n", so after parsing the buffer, you variable location (line information) may be changed.
I never thought of that... I will see what I can do.

Quote from: ollydbg on November 19, 2012, 11:39:54 AM
2, if you remove the "{" block directly, which means:
The posted patch already deals with this.
+            buffer.Prepend(searchData->control->GetTextRange(i, scanPos));
+            scanPos = scopeStart + 1;

i is the position of a "}" brace, and the + 1 includes the matching "{" brace in scanPos, so

for (...)
{
     int a;
}

currently becomes

for (...)
{}


Quote from: MortenMacFly on November 19, 2012, 02:43:25 PM
Quote from: ollydbg on November 19, 2012, 02:09:49 PM
Yes, this patch did conflict with the one for parsing of for loops. But sorry those days I'm a little busy, so I have no time to deeply test and merge those two patches. :(
...maybe ALPHA can do it - what I meant is this:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=3345&group_id=5358
Have not looked at that patch yet, but if it is not too complicated, I will merge them.

Alpha

Quote from: Alpha on November 19, 2012, 11:08:27 PM
Quote from: ollydbg on November 19, 2012, 11:39:54 AM
1, if you remove the whole "{" block, you will remove all the EOL characters "\n", so after parsing the buffer, you variable location (line information) may be changed.
I never thought of that... I will see what I can do.
This should deal with it:

Index: src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 8585)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -1857,7 +1857,33 @@
         if (blockStart >= blockEnd)
             blockStart = blockEnd;

-        wxString buffer = searchData->control->GetTextRange(blockStart, blockEnd);
+        wxString buffer; // = searchData->control->GetTextRange(blockStart, blockEnd);
+        // condense out-of-scope braces {...}
+        int scanPos = blockEnd;
+        for (int curPos = pos; curPos > blockStart; --curPos)
+        {
+            if (searchData->control->GetCharAt(curPos) != wxT('}'))
+                continue;
+            const int style = searchData->control->GetStyleAt(curPos);
+            if (   searchData->control->IsString(style)
+                || searchData->control->IsCharacter(style)
+                || searchData->control->IsComment(style))
+            {
+                continue;
+            }
+            const int scopeStart = searchData->control->BraceMatch(curPos);
+            if (scopeStart < blockStart)
+                break;
+            buffer.Prepend(searchData->control->GetTextRange(curPos, scanPos));
+            const int startLn = searchData->control->LineFromPosition(scopeStart);
+            const int endLn   = searchData->control->LineFromPosition(curPos);
+            if (startLn < endLn) // maintain correct line numbers for parsed tokens
+                buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
+            scanPos = scopeStart + 1;
+            curPos  = scopeStart;
+        }
+        buffer.Prepend(searchData->control->GetTextRange(blockStart, scanPos));
+
         buffer.Trim();
         if (   !buffer.IsEmpty()
             && !m_Parser->ParseBuffer(buffer, false, false, true, searchData->file, m_LastFuncTokenIdx, initLine) )


Quote from: Alpha on November 19, 2012, 11:08:27 PM
Quote from: MortenMacFly on November 19, 2012, 02:43:25 PM
Quote from: ollydbg on November 19, 2012, 02:09:49 PM
Yes, this patch did conflict with the one for parsing of for loops. But sorry those days I'm a little busy, so I have no time to deeply test and merge those two patches. :(
...maybe ALPHA can do it - what I meant is this:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=3345&group_id=5358
Have not looked at that patch yet, but if it is not too complicated, I will merge them.
The only conflict I can see (are there other conflicts I have missed?) is that:

int main()
{
    for (int var_it = 0; var_it < 5; ++var_it)
    {
        int fooBar = var_it;
    }
    // "fooBar" correctly does not exist here (with the above patch)
    // but "var_it" does exist (from loop declaration patch)
    return 0;
}

When modifying buffer, I think the proper way to condense for loop arguments is:

for (int var_it = 0; var_it < 5; ++var_it)
{
    // stuff...
}

to:

for (;;)
{

}

However, I am not certain about the other cases that the loop declaration patch handles; any suggestions?

Alpha

Submitted patch 3375.  It should address all issues discussed here.