4 ms·
There are really two reasons one would be analyzing the source code. One reason is to make sense of how to run it: to determine what instructions to emit. This
by victorNicollet 3y ago
There are really two reasons one would be analyzing the source code.
One reason is to make sense of how to run it: to determine what instructions to emit. This is the kind of analysis where you want to propagate constants (even if they're not flagged as compile-time), to drop dead code (if it can be can determined that it doesn't need to be executed), and so on. For this analysis, even if && evaluation isn't short-circuit, one can replace false && A with just false as long as you know A doesn't have side-effects, and at the very least one can replace:
if (CallA() && false)
{
CallB();
}
With just:
CallA();
The other reason to analyze your source code is to provide some level of static information to the user, such as detecting in advance situations that don't make sense. If there is never a situation where the expression `okeoefkepofke[3.141592]` is acceptable, then it's usually a good idea to report it as such even if the expression is 100% dead code as far as execution goes. I would even go one step further and say that static analysis should also register that expression as a (read-only) use of the variable `okeoefkepofke` for purposes of "find all references" or "rename symbol" tools.