Want to help DMD bugfixing? Write a simple utility.

Michel Fortin michel.fortin at michelf.com
Sat Mar 19 19:31:33 PDT 2011


On 2011-03-19 20:41:09 -0400, Jonathan M Davis <jmdavisProg at gmx.com> said:

> On Saturday 19 March 2011 17:11:56 Don wrote:
>> Here's the task:
>> Given a .d source file, strip out all of the unittest {} blocks,
>> including everything inside them.
>> Strip out all comments as well.
>> Print out the resulting file.
>> 
>> Motivation: Bug reports frequently come with very large test cases.
>> Even ones which look small often import from Phobos.
>> Reducing the test case is the first step in fixing the bug, and it's
>> frequently ~30% of the total time required. Stripping out the unit tests
>> is the most time-consuming and error-prone part of reducing the test case.
>> 
>> This should be a good task if you're relatively new to D but would like
>> to do something really useful.
> 
> Unfortunately, to do that 100% correctly, you need to actually have a working D
> lexer (and possibly parser). You might be able to get something close enough to
> work in most cases, but it doesn't take all that much to throw off a basic
> implementation of this sort of thing if you don't lex/parse it with something
> which properly understands D.

Well, I made simple lexer for D strings, comments, identifiers and a 
few other tokens which should be up to that task. It's what I use to 
parse files and detect dependencies in D for Xcode. Unfortunately, it's 
written in Objective-C++ (but half of it is plain C)...

<https://github.com/michelf/d-for-xcode/blob/master/Sources/DXBaseLexer.h>
<https://github.com/michelf/d-for-xcode/blob/master/Sources/DXBaseLexer.mm>
<https://github.com/michelf/d-for-xcode/blob/master/Sources/DXScannerTools.h>
<https://github.com/michelf/d-for-xcode/blob/master/Sources/DXScannerTools.m>

Very short unit test:
<https://github.com/michelf/d-for-xcode/blob/master/Unit%20Tests/DXBaseLexerTest.mm>

-- 


Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d-learn mailing list