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

CC scope

<< < (4/4)

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.

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

--- End quote ---
The posted patch already deals with this.

--- Code: ---+            buffer.Prepend(searchData->control->GetTextRange(i, scanPos));
+            scanPos = scopeStart + 1;
--- End code ---
i is the position of a "}" brace, and the + 1 includes the matching "{" brace in scanPos, so

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

--- End code ---
currently becomes

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

--- End code ---


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

--- 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

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

--- End quote ---
I never thought of that... I will see what I can do.

--- End quote ---
This should deal with it:

--- Code: ---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) )

--- End code ---


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

--- 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

--- End quote ---
Have not looked at that patch yet, but if it is not too complicated, I will merge them.

--- End quote ---
The only conflict I can see (are there other conflicts I have missed?) is that:

--- Code: ---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;
}

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

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

--- End code ---
to:

--- Code: ---for (;;)
{

}

--- End code ---
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.

Navigation

[0] Message Index

[*] Previous page

Go to full version