[patch] DFA rewritten
Original Reporter info from Mantis: Gorelkin
-
Reporter name: Sergei Gorelkin
Original Reporter info from Mantis: Gorelkin
- Reporter name: Sergei Gorelkin
Description:
I probably should ask for a SVN branch to work on this kind of things. Nevertheless, this patch is a logically completed piece ready to be merged.
It is a new data flow analyzer, based on the ideas and data model borrowed from Mono C# compiler (mcs). Since one of mcs licenses is GPL, I assume it's legal to do so.
Its highlights:
* Does definite assignment analysis (not live variable analysis as the existing DFA does). Definite assignment analysis is known as a better technique to detect uninitialized variable usage, while live variable analysis is better suited for detecting 'dead' assignments.
* Handles try/except and try/finally flows.
* Processes nodes in their natural order.
* Needs only one pass, except some (rare) cases with backwards goto's.
* Reports correct source positions, unlike current implementation which reports everything at function start location.
* Detects semantic errors like break/continue outside of a loop, which are currently handled at the codegeneration stage.
* Also detects unreachable code.
* The initial testing shows better results than Delphi 7, which gets lost on cases with nested exception handling blocks.
Its drawbacks/unimplemented features:
* Can possibly break loop strength reduction, although I tried to preserve the compatiblity in this respect. This must be retested.
* The exact message wording and/or severity is also subject for review. E.g. I added all messages into 'symtable' category - without having an idea if it's correct.
The archive contains 4 files:
- dfa_compiler.patch is to apply to trunk/compiler
- dfa_tests.patch is to apply to trunk/tests
- dfautils.pas is a new unit to add to compiler
- optdfa.pas is a replacement for trunk/compiler/optdfa.pas, not included into patch because of too many changes.
Enjoy :-)
Mantis conversion info:
- Mantis ID: 15523
- Platform: all
- Monitored by: » crossbuilder (Burkhard Carstens), » Hixie (Ian Hickson), » PaulIsh (Paul Ishenin), » etrusco (Flávio Etrusco), » alexvins (Alexander Shishkin), » Vincent (Vincent Snijders), » @MageSlayer (Denis Golovan), » @PascalDragon (Sven Barth)