Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
use PPToken for preprocessor in native CC
ollydbg:
I have some code improvement about the preprocessor in our legacy Code completion plugin, see
https://github.com/asmwarrior/codeblocks_sfmirror/tree/master
What I want is that I would like to use "id compare" instead of "string compare" for the high level parser.
Comments are welcome, thanks.
Miguel Gimenez:
I have been looking at this commit (the exact location of the changes was not specified).
PPToken looks to me just a way to pack token information, so I assume the real benefit is using the deque afterwards.
I just suggest changing
--- Code: ---if (m_PPTokenStream.size() > 0)
--- End code ---
to this
--- Code: ---if (!m_PPTokenStream.empty())
--- End code ---
and removing this part
--- Code: --- else
;// peekToken.Clear();
--- End code ---
ollydbg:
--- Quote from: Miguel Gimenez on September 17, 2024, 05:58:45 pm ---I have been looking at this commit (the exact location of the changes was not specified).
PPToken looks to me just a way to pack token information, so I assume the real benefit is using the deque afterwards.
--- End quote ---
Thanks for the comment.
The "deque" here is used to move the token cursor forward or backward, because we have some interface to "peek token" (look ahead) or "undo token"(move the cursor backward), so I think a "deque" is a good structure to use.
--- Quote ---
I just suggest changing
--- Code: ---if (m_PPTokenStream.size() > 0)
--- End code ---
to this
--- Code: ---if (!m_PPTokenStream.empty())
--- End code ---
--- End quote ---
Thanks, but what's the difference? Maybe the "empty()" function runs much faster?
--- Quote ---and removing this part
--- Code: --- else
;// peekToken.Clear();
--- End code ---
--- End quote ---
I will read this part of the code later.
Thanks.
blauzahn:
I very briefly glanced across the commit pointed to by the link.
findings:
* class PToken: data-member m_Kind is left uninitialized when PToken is default initialized and when initialized via the ctor with 4 args (while having 5 data-member).
The call to the latter one is also a little errorprone. It might easily be used incorrectly because it has 3 int args. I'd consider member-initializer for the 4 integral data
member and delete the default-ctor.
* The cctor of PToken is unecessary and breaks the rule-of-0 without need. It might also copy m_Kind from
an uninitialized data-member. That is undefined behaviour. IMHO the cctor should be removed.
* The compound statement after if (IsEOF()) is repeated. It sets 2 data-members of PToken and should be delegated to PToken. Cheers
ollydbg:
--- Quote from: blauzahn on September 18, 2024, 09:08:10 am ---I very briefly glanced across the commit pointed to by the link.
findings:
--- End quote ---
Thanks for the comment.
--- Quote ---class PToken: data-member m_Kind is left uninitialized when PToken is default initialized and when initialized via the ctor with 4 args (while having 5 data-member).
The call to the latter one is also a little errorprone. It might easily be used incorrectly because it has 3 int args. I'd consider member-initializer for the 4 integral data
member and delete the default-ctor.
--- End quote ---
Oh, yes, I should initialize the m_Kind member variable in the default constructor and other constructors.
About the argument: "PPToken(wxString lexeme, int charIndex, int lineIndex, int nestLevel)", I really don't know where does the "charIndex" come from, I will looked into it.
--- Quote ---The cctor of PToken is unecessary and breaks the rule-of-0 without need. It might also copy m_Kind from
an uninitialized data-member. That is undefined behaviour. IMHO the cctor should be removed.
--- End quote ---
My initial though is that PPToken's copy constructor is used because I think it need to construct the element in the deque, in some cases, the PPToken get copied to the deque. Am I wrong?
Oh, you are correct,
--- Quote ---In C++, the "Rule of Zero" is a guideline that suggests avoiding writing custom constructors, destructors, or copy/move assignment operators if the default compiler-generated versions will suffice. The rule states that if a class does not need custom resource management (like dynamic memory allocation), it can rely on the compiler-generated special member functions.
--- End quote ---
So, the copy constructor is not needed here, because the compiler will generate the same one if I remove it.
--- Quote ---The compound statement after if (IsEOF()) is repeated. It sets 2 data-members of PToken and should be delegated to PToken.
--- End quote ---
Do you mean that the
--- Code: --- /** Check whether the Tokenizer reaches the end of the buffer (file) */
bool IsEOF() const
{
return m_TokenIndex >= m_BufferLen;
}
--- End code ---
should be removed from the high level parser, but we can return a PPToken which has m_Kind field set as "EOF"?
Thanks.
Navigation
[0] Message Index
[#] Next page
Go to full version