Use C++17 nested declarations and add CppParser support, closes #5234#5235
Use C++17 nested declarations and add CppParser support, closes #5234#5235mikomikotaishi wants to merge 8 commits intopocoproject:mainfrom
Conversation
52b7231 to
47fbbd2
Compare
47fbbd2 to
57d3f32
Compare
|
This is a change that doesn't actually change the usage of the library at the consumer end, so could we merge this one before 1.16.0? I think it falls under code tidiness and would probably be better suited to be merged sooner rather than later. |
|
The CodeQL errors seem to not be caused by anything made by this PR, as the affected errors are not mentioning changes made in this PR, so I won't address those in this PR. |
|
This change will also require someone to add support for nested namespace declarations to CppParser, otherwise PocoDoc will fail to generate the reference documentation. |
23cd29b to
3ba6402
Compare
|
@obiltschnig I have added nested namespace support and a test case now |
Great, thank you! |
CppParser/src/Parser.cpp
Outdated
| pNS->setInline(inlineFlags[i]); | ||
| } | ||
| // Only add the first (outermost) namespace to the global symbol table, | ||
| // and only if it's not already there |
There was a problem hiding this comment.
The addToGST logic has subtly changed from the old behavior.
Old code set addGST = undefined (true when the namespace was newly created, false when found via lookup).
New code checks _gst.find(namespaceNames[i]) == _gst.end(), which looks up the simple name in the flat global symbol table.
Since _gst is a multimap, find() will match any symbol with that name (not just namespaces), which could give false negatives if a non-namespace symbol happens to share the name. Consider using the original approach:
pushNameSpace(pNS, -1, (i == 0 && undefined));This preserves the old semantic: add to GST only when the outermost namespace was newly created.
There was a problem hiding this comment.
OK, I'll apply this
| [[nodiscard]] | ||
| Symbol::Kind kind() const; | ||
| std::string toString() const; | ||
|
|
There was a problem hiding this comment.
Nit: [[nodiscard]] was added to isInline() and kind() but not to toString() on the next line. Consider adding it for consistency, or removing from kind() since the existing codebase doesn't use [[nodiscard]] elsewhere in this class.
There was a problem hiding this comment.
I probably would have had it added in my other pull request for [[nodiscard]], #5156. If you want I could just move ahead with adding it here, rather than waiting for #5156.
Edit: I think it's a good idea if we move ahead with it here, rather than waiting for #5156, seeing as it's a related functionality that touches this class.
| } | ||
|
|
||
|
|
||
| void CppParserTest::setUp() |
There was a problem hiding this comment.
Good test coverage for the basic cases. Consider adding tests for:
- Repeated declaration of the same nested namespace (e.g.,
namespace A::B { class X; }followed bynamespace A::B { class Y; }) to ensure both symbols end up in the same namespace - Single (non-nested) namespace as a regression test for the refactored code
- Deeply nested (4+ levels) to verify the pop loop works correctly
There was a problem hiding this comment.
OK, added these.
|
Hi @mikomikotaishi, I opened new issues for CodeQL issues to be analysed separately. Please take a look at the comment for CppParser. Thank you for your contributions. |
0147bc1 to
2cb49b6
Compare
2cb49b6 to
e5b887d
Compare
| @@ -117,7 +115,7 @@ const T& clamp(const T& v, const T& lo, const T& hi) { | |||
| } | |||
|
|
|||
| template <typename T, typename U> | |||
| static T numeric_cast(U value, | |||
| T numeric_cast(U value, | |||
There was a problem hiding this comment.
This file lives under dependencies/tessil/ and should not be modified as part of POCO changes — it's a bundled third-party library. If this static removal is needed, it should be done upstream or tracked as a separate dependency patch. Please revert this change.
There was a problem hiding this comment.
Non-Poco files were extracted to dependencies on main and this change can't be applied directly.
There was a problem hiding this comment.
This is the only way I can get modules to work, since apparently something calls these internally linked symbols.
I'm not actually sure what to do instead here
There was a problem hiding this comment.
My proposal:
- modify ordered_hash.h in dependencies, Write a note to dependencies/README.md about the change and the reason for the change.
- Then open PR in https://github.com/Tessil/ordered-map for the same change to get it included upstream.
There was a problem hiding this comment.
OK, I submitted a similar pull request at Tessil/ordered-map#54.
Do note that the repo has a few stale PRs, the most recent one being in May of last year, which haven't been responded to at all, though the last commit to the repo was from the author 4 months ago.
There was a problem hiding this comment.
Some stable products change very slowly. We'll see what happens.
1694d69 to
59d9112
Compare
43c3784 to
8c0f57a
Compare
|
@mikomikotaishi, please do not force push because the track of changes is then lost. We will squash merge in the end after all of the changes are done. |
| @@ -19,8 +19,7 @@ | |||
| #include <vector> | |||
|
|
|||
| CPPTRACE_BEGIN_NAMESPACE | |||
| namespace detail { | |||
| namespace libdwarf { | |||
| namespace detail::libdwarf { | |||
There was a problem hiding this comment.
Revert all changes in cpptrace. We use it unchanges from upstream.
| namespace double_conversion { | ||
|
|
||
| namespace PowersOfTenCache { | ||
| namespace double_conversion::PowersOfTenCache { |
There was a problem hiding this comment.
Revert all changes in v8_double_conversion. We use it unchanged from upstream.
|
I only use force pushes when it's a small amendment, such as a typo or a minor fix to a broken push. However that being said I will avoid doing this in the future. |
|
Sorry for the delay in the response, I didn't see it until now. I've reverted all changes made in |
| } | ||
|
|
||
| if (isOperator(pNext, OperatorToken::OP_ASSIGN)) | ||
| { |
There was a problem hiding this comment.
I just want to ensure I am not misunderstanding: should this not permit re-defining/re-opening namespaces? In the tests, I re-open namespaces by re-using them, and am not sure if this is the intended behaviour or not.
| // update the inline flag | ||
| pNS->setInline(inlineFlags[i]); | ||
| } | ||
| pushNameSpace(pNS, -1, i == 0); |
There was a problem hiding this comment.
I think that here it should be:
pushNameSpace(pNS, -1, (i == 0 && undefined))
There was a problem hiding this comment.
I just want to ensure I am not misunderstanding: should this not permit re-defining/re-opening namespaces? In the tests, I re-open namespaces by re-using them, and am not sure if this is the intended behaviour or not. You mentioned earlier that you made a mistake in the comment you left, but this was on line 257. Could you give clarity on what the intended behaviour should be, and whether my tests should reuse namespaces?
There was a problem hiding this comment.
Re-opening namespaces is perfectly fine and must keep working — that is not the concern here.
The issue is about duplicate entries in _gst (the global symbol table, a std::multimap), not about preventing namespace re-opening.
Old code (before this PR):
NameSpace* pNS = dynamic_cast<NameSpace*>(currentNameSpace()->lookup(fullName));
bool undefined = (pNS == nullptr);
if (undefined) pNS = new NameSpace(name, currentNameSpace());
pushNameSpace(pNS, -1, undefined); // addGST = true ONLY when newly createdWhen namespace Poco appeared a second time in the same file, undefined was false, so the existing Poco namespace was not inserted into _gst again.
Current code:
bool undefined = (pNS == nullptr);
// ...
pushNameSpace(pNS, -1, i == 0); // addGST = true ALWAYS for outermostNow every time namespace Poco::Net appears (even the 2nd, 3rd time in the same file), the outermost namespace Poco is re-inserted into _gst. Since _gst is a multimap, this creates duplicate entries.
The fix (i == 0 && undefined) restores the original semantic: add to _gst only when the namespace is seen for the first time. Re-opening still works exactly as before — lookup() finds the existing namespace, symbols get added to it — we just skip the redundant _gst insert.
There was a problem hiding this comment.
OK, I'll apply the change then.
There was a problem hiding this comment.
Making this change seemed to cause the unit tests to fail, particularly at the line st.find("A") != st.end(). Any ideas on what to do?
There was a problem hiding this comment.
My suggestion was actually wrong and should be reverted.
It does not work because there is a global root() singleton which is shared across runs in tests.
A apologise.
There was a problem hiding this comment.
OK, I've gone ahead and undid the edit.
Should we wait for the tests to finish before merging, or could we just go ahead and do it knowing that two commits ago the tests all passed?
|
There is potentially one change in CppParser. Please take a look. Rebase (or merge) from latest main in Poco repository to resolve conflicts. Then we are ready for merge. |
This pull request closes #5234, and replaces the repeated namespace declarations with the new C++17 nested namespace declarations for a concise declaration of multiple nested namespaces. (The library is C++20, and thus should not be broken by this change.)
This was done using a Python script (and a small part by hand for more complex files), and the CI tests don't report any build errors so I assume it was done correctly, but as always if something is incorrect please bring it to my attention.
As
CppParserrequires nested namespace support as well to generate the new docs, I have updated it to support nested namespaces as well as a small test case to the testing suite.