Re:GCC should warn about 2^16 and 2^32 and 2^64
by scatters on Monday June 17, 2019 @05:36AM
(#20201261)
By the time you write a linter, you've done more than half of the work of a compiler, at which point you might as well just ship it as a compiler. It's a bit different for clang, which is modular and provides libraries that tool writers can use, but gcc is intentionally monolithic.
[ Parent
| on HN ]
Re:GCC should warn about 2^16 and 2^32 and 2^64
by gchadwick on Monday June 17, 2019 @05:59AM
(#20201384)
> By the time you write a linter, you've done more than half of the work of a compiler, at which point you might as well just ship it as a compiler.
Does depend on what kind of lint you want to catch but something like this 'just' needs some lexing and parsing to give a usable AST that's reasonably clean so it's not too hard to write lint rules against it. (Not trivial for C & C++ hence 'just')
Building the full compiler is much more work, especially if you want a decent optimizing compiler.
Re:GCC should warn about 2^16 and 2^32 and 2^64
by antisemiotic on Monday June 17, 2019 @07:08AM
(#20201737)
It's not just nontrivial for C++, you need a full template engine just to properly parse it [1]. Same thing for languages with a lisp-like macro system. Or languages that allow dynamic redefinition od symbols [2].
[1] http://blog.reverberate.org/2013/08/parsing-c-is-literally-u...
Re:GCC should warn about 2^16 and 2^32 and 2^64
by barrkel on Monday June 17, 2019 @06:14AM
(#20201466)
The back end is a lot of work, but so is the front end in a language like C++.
In fact most of the essential complexity is in the front end; you make do with a simple back end, but the front end is irreducibly complex if you want it to actually compile the language to spec.
And you need the front end to lint, especially if you want to avoid false positives, the bane of linting tools.