Uh oh!
There was an error while loading. Please reload this page.
make sure the language for a Token/TokenList is always determined - #5853
Conversation
firewave
commented
Jan 6, 2024
Requires #5848 to be merged first and is a prerequisite for #5724 and #5725. Several of the test Clang AST dumps have no filename specified which causes the language not be be determined. I wonder if we actually encounter such dumps in real world examples or if these are just in the tests. If the latter is the case we need some heuristic to be able to detect the language. I could default to C++ for the time being though. |
The ambiguity of headers is also exposed by this causing |
390bdfa to
c743df5CompareTokenList is always determinedToken/TokenList is always determined3a34536 to
4e809caComparefirewave
commented
Jan 13, 2024
It turns out there is actually a valid state where we have no language - when we process markup files (i.e. |
e1ec95b to
91f442dCompared1a0384 to
48758bbComparefirewave
commented
Jan 19, 2024
Requires #5896 to be merged first. |
cc2d9c9 to
2835d3bComparefirewave
commented
Jan 20, 2024
I am not too happy about the multiple asserts but it is possible to create a |
danmar
commented
Jan 28, 2024
For your information we have in the Cppcheck Premium backlog a task to look at improving clang AST import.. it's way in the future we will at least not work on this for the next year.. I have the feeling it might be a good idea to fork clang and update the dump output so it's more parser-friendly. I believe we just need to tweak the dumping code which should be relatively limited in scope. I envision it will be a big job to maintain it.. but it would probably be worth it. |
firewave
commented
Feb 8, 2024
#5961 is another step in improving things. |
firewave
commented
Feb 8, 2024
And yet another step with #5963. |
5f9bf44 to
60c27feComparefirewave
commented
Feb 12, 2024
With the adjustments the asserts are now limited to I hope to make further improvements that make the asserts unnecessary. |
| bool TokenList::createTokens(std::istream &code, const std::string& file0) | ||
| { | ||
| #ifdef ASSERT_LANG |
There was a problem hiding this comment.
sorry it's not so nice to have such ifdefs over and over. Is the idea that I will undefine ASSERT_LANG in release builds somehow? How about this code:
#ifdef N_ASSERT_LANG
#define ASSERT_LANG(cond) throw InternalError(nullptr, __FILE__ ": assertion error: " #cond);
#else
#include <cassert>
#define ASSERT_LANG(cond) assert(cond)
#endif
.. and I build with -DN_ASSERT_LANG in release builds?
There was a problem hiding this comment.
This is temporary and the intention is to simply disable the define in source. I can already provide a PR so it will not be missed. In case I am able to make the appropriate improvements the asserts will one by one go away. In case I am not they will not be enabled at all. Not pretty but it quite local and does not spill into other code.
I do not want an I do not want an InternalError for this as this is nothing the user should ever see. We will also not be able to generate the appropriate information the user needs to provide so we can figure out the location in case the source cannot be provided. Also this would require modifications in daca so I get the desired information. That would cause a ripple effect I want to avoid.
There was a problem hiding this comment.
at least I'd suggest that we avoid ifdefs over and over.. for instance:
#ifndef N_ASSERT_LANG
#include <cassert>
#define ASSERT_LANG(cond) assert(cond)
#endif
7bfcce6 to
ad01507Comparefirewave
commented
Feb 20, 2024
Any more feedback on this? Otherwise I am going to merge this tomorrow so I can hopefully finish up the task during this dev cycle. |
firewave
commented
Feb 20, 2024
Still needs a bit of work. Files without any extension have no language set. Those need to default to C++ by default as per the existing code. But we treat headers as C by default - that is inconsistent. That should be aligned to be C by default. Extension-less files are most likely C++ anyways but those should be identified by the Emacs marker (see https://trac.cppcheck.net/ticket/10692). I will address this in a different PR. |
firewave
commented
Feb 20, 2024
Ugh. Turns out to get this done properly we need to move towards only using |
7533b82 to
92858b5Comparefirewave
commented
Feb 20, 2024
I addressed this with another fallback for now. |
No description provided.