Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
New code completion remarks/issues
ollydbg:
--- Quote from: blueshake on October 20, 2009, 10:09:38 am ---what more I want to say is the logical error:
The only chance the variable m_LastWasPreprocessor becomes true is in these codes:
--- Code: --- if ((CurrentChar() == 'i' && NextChar() == 'n') || // in(clude)
(CurrentChar() == 'i' && NextChar() == 'f') || // if(|def|ndef)
(CurrentChar() == 'e' && NextChar() == 'l') || // el(se|if)
(CurrentChar() == 'e' && NextChar() == 'n') || // en(dif)
(m_TokenizerOptions.wantPreprocessor && CurrentChar() == 'd' && NextChar() == 'e')) // de(fine)
{
// ok, we have something like #in(clude)
m_LastWasPreprocessor = true;
m_LastPreprocessor.Clear();
m_TokenIndex = backupIdx; // keep #
skipPreprocessor = true;
break;
}
else
--- End code ---
at this time,str contain the string "#",and m_LastPreprocessor is empty.(see codes above)
so the three conditions in if:
m_LastWasPreprocessor------------------------true
!str.IsSameAs(_T("#"))-------------------------false
!m_LastPreprocessor.IsSameAs(_T("#"))-------true
see ,the three conditions can not all be true at the same time.It means the "if " condition can never be true.
--- End quote ---
Hi, blueshake, Thanks for the explanation. :D.
MortenMacFly:
--- Quote from: blueshake on October 20, 2009, 10:09:38 am ---m_LastWasPreprocessor------------------------true
!str.IsSameAs(_T("#"))-------------------------false
!m_LastPreprocessor.IsSameAs(_T("#"))-------true
--- End quote ---
Could it be that simply the "!str..." line should be removed as it is a relict of old times???
From what I read in the code it simplifies preprocessor handling in a way that it just gets rid of everything after the first preprocessor directive as it is unhandled anyways (except for #include and #if[[n]def], as stated in the comment)... which is good.
blueshake:
My another question :
what is the effort of m_LastPreprocessor .since when the variable m_LastWasPreprocessor is true,the m_LastPreprocessor is absoutely empty.see codes below.
--- Code: --- if ((CurrentChar() == 'i' && NextChar() == 'n') || // in(clude)
(CurrentChar() == 'i' && NextChar() == 'f') || // if(|def|ndef)
(CurrentChar() == 'e' && NextChar() == 'l') || // el(se|if)
(CurrentChar() == 'e' && NextChar() == 'n') || // en(dif)
(m_TokenizerOptions.wantPreprocessor && CurrentChar() == 'd' && NextChar() == 'e')) // de(fine)
{
// ok, we have something like #in(clude)
m_LastWasPreprocessor = true;
m_LastPreprocessor.Clear();
m_TokenIndex = backupIdx; // keep #
skipPreprocessor = true;
break;
}
else
--- End code ---
EDIT:
In the three conditions,
m_LastWasPreprocessor is true,!m_LastPreprocessor.IsSameAs(_T("#")) is absoutely true too.
ollydbg:
Hi,
I would like to say:
there is no use of "m_LastPreprocessor" and "m_LastWasPreprocessor".
Let me explain more, In the parserthread, see the code here:
--- Code: --- else if (token==ParserConsts::hash)
{
token = m_Tokenizer.GetToken();
if (token==ParserConsts::kw_include)
HandleIncludes();
else if (token==ParserConsts::kw_define)
HandleDefines();
else
HandlePreprocessorBlocks(token);
m_Str.Clear();
}
--- End code ---
and
--- Code: ---void ParserThread::HandlePreprocessorBlocks(const wxString& preproc)
{
if (preproc.StartsWith(ParserConsts::kw_if)) // #if, #ifdef, #ifndef
{
wxString token = preproc;
++m_PreprocessorIfCount;
token = m_Tokenizer.GetToken();
if (token.IsSameAs(_T("0")))
{
// TODO: handle special case "#if 0"
TRACE(_T("HandlePreprocessorBlocks() : Special case \"#if 0\" not skipped."));
}
m_Tokenizer.SkipToEOL();
}
else if (preproc==ParserConsts::kw_else || preproc==ParserConsts::kw_elif) // #else, #elif
{
TRACE(_T("HandlePreprocessorBlocks() : Saving nesting level: %d"), m_Tokenizer.GetNestingLevel());
m_Tokenizer.SaveNestingLevel();
wxString token = preproc;
while (!token.IsEmpty() && token != ParserConsts::kw_endif)
token = m_Tokenizer.GetToken();
--m_PreprocessorIfCount;
#if PARSERTHREAD_DEBUG_OUTPUT
int l = m_Tokenizer.GetNestingLevel();
#endif
m_Tokenizer.RestoreNestingLevel();
TRACE(_T("HandlePreprocessorBlocks() : Restoring nesting level: %d (was %d)"), m_Tokenizer.GetNestingLevel(), l);
}
else if (preproc==ParserConsts::kw_endif) // #endif
--m_PreprocessorIfCount;
}
--- End code ---
And In my working copy, I already delete the if statements, and works fine here.
We just want to skip the unnecessory preprocessor directive, and no string information should be kept in m_LastPreprocessor.
MortenMacFly:
--- Quote from: ollydbg on October 20, 2009, 04:14:58 pm ---
--- Code: --- else if (token==ParserConsts::hash)
{
token = m_Tokenizer.GetToken();
if (token==ParserConsts::kw_include)
HandleIncludes();
else if (token==ParserConsts::kw_define)
HandleDefines();
else
HandlePreprocessorBlocks(token);
m_Str.Clear();
}
--- End code ---
--- End quote ---
Notice that there is another call to HandlePreprocessorBlocks() in void ParserThread::SkipBlock() and ParserThread::HandleClass(EClassType ct).
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version