Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

CC scope

<< < (3/4) > >>

ollydbg:

--- Quote from: Alpha on November 17, 2012, 11:21:28 pm ---Here is a possible scope optimizer for CC.  If anyone has time to test, let me know how well it works.

--- Code: ---Index: src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 8571)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -1826,7 +1826,7 @@
     if (blockStart != -1)
     {
         ++blockStart; // skip {
-        const int pos = caretPos == -1 ? searchData->control->GetCurrentPos() : caretPos;
+        const int pos = (caretPos == -1 ? searchData->control->GetCurrentPos() : caretPos);
         const int line = searchData->control->LineFromPosition(pos);
         const int blockEnd = searchData->control->GetLineEndPosition(line);
         if (blockEnd < 0 || blockEnd > searchData->control->GetLength())
@@ -1842,7 +1842,29 @@
         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 i = pos; i > blockStart; --i)
+        {
+            if (searchData->control->GetCharAt(i) != wxT('}'))
+                continue;
+            const int style = searchData->control->GetStyleAt(i);
+            if (   searchData->control->IsString(style)
+                || searchData->control->IsCharacter(style)
+                || searchData->control->IsComment(style))
+            {
+                continue;
+            }
+            const int scopeStart = searchData->control->BraceMatch(i);
+            if (scopeStart < blockStart)
+                break;
+            buffer.Prepend(searchData->control->GetTextRange(i, scanPos));
+            scanPos = scopeStart + 1;
+            i       = 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) )

--- End code ---

--- End quote ---

The logic seems good to me.

So, for a simple code:

--- Code: ---void ffff()
{
    int a;
    {
        int b;
        {
            int c;
        }
    }
   
    for (....)
    {
        int d;     
        {
            int e;
            ////////// caret here;       
        }
    }
}


--- End code ---

It should have only variable statement "e, d, a" in the buffer.

I'm going to test it in tonight. :)

ollydbg:
Two issue:
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.

2, if you remove the "{" block directly, which means:


--- Code: ---for (...)
{
     int a;
}

--- End code ---

will become

--- Code: ---for (...)

--- End code ---
This becomes a invalid statement. What I think is right method is to convert to this:

--- Code: ---for (...)
{
     
}

--- End code ---
Keep the "{" and "}" and all the EOL characters, and remove all others. :)

MortenMacFly:

--- Quote from: ollydbg on November 19, 2012, 11:39:54 am ---
--- Code: ---for (...)

--- End code ---
This becomes a invalid statement. What I think is right method is to convert to this:

--- Code: ---for (...)
{
}

--- End code ---

--- End quote ---
True. Otherwise our parser may get hick-ups. ;-)

Also, (ollydbg): Do you have applied that other patch concerning variable parsing of for loops and stuff in parallel? This could conflict.

ollydbg:

--- Quote from: MortenMacFly on November 19, 2012, 12:13:57 pm ---Also, (ollydbg): Do you have applied that other patch concerning variable parsing of for loops and stuff in parallel? This could conflict.

--- End quote ---
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. :(

MortenMacFly:

--- 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. :(

--- End quote ---
...maybe ALPHA can do it - what I meant is this:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=3345&group_id=5358

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version