CC: [huki] parser - fixed handling of assignment within for loop.
I'm OK with this commit.
With this patch, we can handle the pattern:
for(int i = 0; ...; ...)...
And correctly recognize "i" as a variable.
I will commit soon. This is an enhancement on the original patch, see revision 8700, and the related patch page:
Patch 3345 - Code::Blocks HistoryBut I see in the function void ParserThread::HandleForLoopArguments()'s body:
...
if (peek == ParserConsts::comma)
{
smallTokenizer.GetToken(); // eat comma
createNewToken = true;
}
else if (peek == ParserConsts::colon
|| peek == ParserConsts::semicolon
|| peek.empty())
{
createNewToken = true;
finished = true; // after this point there will be no further declarations
}
...
It looks like handling colon is not quite correct. For example:
for ( SomeNamespace::SomeClass i = 0; ...)
In this case, it should add a token "i", which the type "SomeNamespace::SomeClass".
The current method is try to construct a small buffer(smallTokenizer), which contains:
( SomeNamespace::SomeClass i = 0; ...)
and run some parsing method on it.
My idea could be:
1, Make the buffer "( SomeNamespace::SomeClass i = 0; ...)", and construct a new Parserthread object
2, call DoParse() function recursively on the buffer, which is quite similar with how we parse the class definitions
class AAA
{
// body of the class definition, we recursively to call the DoParse() function.
// So that all tokens are marked as the child token of the Token "AAA".
// once the "}" is met, the Doparse() will returned to its high level DoParse().
}
3, if possible, we can let the Token "i" be a child Token of the current Token(ideally the Token "for"), although all the tokens are temporary tokens.
In the main loop of the DoParse(), the "SomeNamespace::SomeClass i = 0;" will be correctly recognized as a Token "i".
This is the way we can handle function parameters, or the catch(xxx) clause, as we have already discussed.