Currently i found some strange behaviors using the new CC Branch of Code::Blocks:
1) if i enter
Code:
while ()
and then press "." it will be autocompleted as
Code:
while ().while
this problem can be solved by this patch.
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5744)
+++ nativeparser.cpp (working copy)
@@ -1214,8 +1214,8 @@
case '(': --nest; break;
}
}
- if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
- --x;
+ //if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
+ // --x;
}
}
}
Can you explain a little about this modify on the function:
unsigned int NativeParser::FindCCTokenStart(const wxString& line)
{
......
return x;
}
Thanks!
The function is list below:
unsigned int NativeParser::FindCCTokenStart(const wxString& line)
{
int x = line.Length() - 1;
int nest = 0;
bool repeat = true;
while (repeat)
{
repeat = false;
while ((x >= 0) && (wxIsalnum(line.GetChar(x)) || line.GetChar(x) == '_'))
--x;
if ( (x > 0) &&
( (line.GetChar(x) == '>' && line.GetChar(x - 1) == '-') ||
(line.GetChar(x) == ':' && line.GetChar(x - 1) == ':') ) )
{
x -= 2;
repeat = true;
}
else if ((x >= 0) && (line.GetChar(x) == '.'))
{
--x;
repeat = true;
}
if (repeat)
{
// now we 're just before the "." or "->" or "::"
// skip any whitespace
while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
--x;
// check for function/array/cast ()
if ((x >= 0) && (line.GetChar(x) == ')' || line.GetChar(x) == ']'))
{
++nest;
while (--x >= 0 && nest != 0)
{
#if wxCHECK_VERSION(2, 9, 0)
switch (line.GetChar(x).GetValue())
#else
switch (line.GetChar(x))
#endif
{
case ']':
case ')': ++nest; break;
case '[':
case '(': --nest; break;
}
}
if ((x > 0) && (wxIsalnum(line.GetChar(x - 1)) || line.GetChar(x - 1) == '_'))
--x;
}
}
}
++x;
if (x < 0)
x = 0;
while (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')
++x;
//Manager::Get()->GetLogManager()->DebugLog("Starting at %d \"%s\"", x, line.Mid(x).c_str());
return x;
}
I think we need to "skip any whitespace" after we find the "[" in the following line
That is what I think is right :D:
while (--x >= 0 && nest != 0)
{
#if wxCHECK_VERSION(2, 9, 0)
switch (line.GetChar(x).GetValue())
#else
switch (line.GetChar(x))
#endif
{
case ']':
case ')': ++nest; break;
case '[':
case '(': --nest; break;
}
}
//***************ADD code here:
// skip any whitespace
while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
--x;
//**************
......
so should we add the codes
while ((x >= 0) && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t'))
--x;
to the function or others?
i think the problem can be solved by this patch too.
which one is better, still need to further discussed.
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5744)
+++ nativeparser.cpp (working copy)
@@ -1248,21 +1247,20 @@
++startAt;
}
}
-
-// Manager::Get()->GetLogManager()->DebugLog(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str());
- while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_'))
+ //Manager::Get()->GetLogManager()->DebugLog(F(_T("at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
+ while ((startAt < line.Length()) && (wxIsalnum(line.GetChar(startAt)) || line.GetChar(startAt) == '_' || line.GetChar(startAt) == ' ' || line.GetChar(startAt) == '\t'))
{
res << line.GetChar(startAt);
++startAt;
}
-
+ res.Trim();
while ((nest > 0) && (startAt < line.Length()))
{
if (line.GetChar(startAt) == ')')
--nest;
++startAt;
}
- //Manager::Get()->GetLogManager()->DebugLog("Done nest: at %d (%c): res=%s", startAt, line.GetChar(startAt), res.c_str());
+ //Manager::Get()->GetLogManager()->DebugLog(F(_T("Done nest: at %d (%c): res=%s"), startAt, line.GetChar(startAt), res.c_str()));
if ((startAt < line.Length()) && (line.GetChar(startAt) == '(' || line.GetChar(startAt) == '['))
{
wxString NativeParser::GetCCToken(wxString& line, ParserTokenType& tokenType)
{
// line contains a string on the following form:
// " char* mychar = SomeNamespace::m_SomeVar.SomeMeth"
// first we locate the first non-space char starting from the *end*:
//
// " char* mychar = SomeNamespace::m_SomeVar.SomeMeth"
// ^
// then we remove everything before it.
// after it, what we do here, is (by this example) return "SomeNamespace"
// *and* modify line to become:
// m_SomeVar.SomeMeth
// so that if we 're called again with the (modified) line,
// we 'll return "m_SomeVar" and modify line (again) to become:
// SomeMeth
// and so on and so forth until we return an empty string...
// NOTE: if we find () args or [] arrays in our way, we skip them (done in GetNextCCToken)...
The last comment says:
// NOTE: if we find () args or [] arrays in our way, we skip them (done in GetNextCCToken)...
So, it is better to change the function "GetNextCCToken" I think.