View previous topic :: View next topic |
Author |
Message |
MaKo
Joined: 12 Jul 2008 Posts: 5
|
Posted: Sat Jul 12, 2008 2:29 pm Post subject: Lint for D |
|
|
Hi,
there was discussion about generating warnings in D in general in the digitalmars newsgroups, and I realized that at least DMD probably never includes more checkings. IMO that's a little bit sad. I haven't realized this until now, although I have occasionally wondered that if I'm using "-w" switch or not.
I started to think about writing some sort of checker against simple potential bugs (like not using return values, unused vars and such). Now I have seen that there exists at least some similar efforts, so I ask here for getting some links to them, and their status.
At first, I really would not like to do that kind of static checker with C or C++, instead I would like to use D. Is there D parser for D code? Or wrapper for Bright's C-files to D?
The second question is mainly for LLVMDC and GDC developers; I would not like to duplicate the parsing things, IMO I would try to use some open source front end as starting point. Assuming that I would try to use LLVMDC parsing, how large effort it would be use it without code generation, and having a wrapper to D (to be able to write the checker with D)?
Basically, I would like to include the checker after compilation:
$ dmd/gdc/llvmdc <options> <sources> && check <options> <sources> && <run that software>
...Because I would not like to check sources that have errors that prevent code generation. Similarly, I would like to try to use the same flags than compiler uses, that is, having some kind of integration between checker and compiler.
Currently I'm looking towards LLVMDC, since I have a 64-bit machine and I don't have working D compiler for that (instead I have installed a Linux inside Linux to be able to use 32-bit D compiler).
Any ideas & suggestions are welcome |
|
Back to top |
|
|
MaKo
Joined: 12 Jul 2008 Posts: 5
|
Posted: Tue Jul 15, 2008 2:54 pm Post subject: |
|
|
Well, I hacked something; not a dlint, but somewhat general purpose AST walking class for DParser, and some source code checkers. Sources (including binary for i386-linux) are available:
http://reaaliaika.net/showarea.php/download/dwalk
dwalk.tar.ge opens to directory named dwalk. dwalk/dparser should contain link to DParser sources (you may also upload them to dwalk/ directory with svn etc).
Package contains:
- Sources: dwalk/src/
- Test files: dwalk/testfiles
About sources: You probably first take a look to main.d. Then you may want to look at the scanners (ScanXXXModule.d). Finally, you might want to take a look at the ASTWalk (ASTWalking.d).
If you get the thing compiled, you should have executable named dwalk, which can:
- Detect unused things; there may still be some false reporting, as well as it can surely undetect some unused things. imports are not checked at all. Nor templates (or they may be, if they go with the defaults).
- Detect expression result discarding, i.e. unused return values. There are some pecularities with "void main(...)" functions, which cause false alarms.
- Detect constant conditions, in for/while/do and if/switch; take a look at the testfiles/TestInfLoop1.d for seeing, which kind of infinite or dead loops are scanned.
Some notes: Packet compiles with DMD1.0 and phobos. If compiling to linux, you may need to hack (current) DParser sources a little; if I remember correctly, change memicmp -> memcmp somewhere (changes things case sensitive, bu so what), and somewhere else there was function like DebugOutputA, change it to writefln.
Any reports, comments & suggestions are welcome |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|