June 17, 2014
On 17/06/2014 07:25, Jacob Carlborg wrote:
> On 16/06/14 15:43, Bruno Medeiros wrote:
>
>> What's keeping us from having such a tool? It seems that after one has a
>> decent parser (that also keeps tracks of the source ranges of AST
>> nodes), it's easy to write code that does syntactic modifications and
>> then rewrites the source code. And there's several D parsers out there
>> already - so it should be too much effort to get there.
>> Even I am working on a tool that can be easily retrofitted for this
>> purpose.
>>
>> Or maybe I am misunderstanding the amount of semantic analysis that
>> would typically be required? Can someone give some examples of
>> modifications that would be useful for such a dfix tool? (I haven't yet
>> had the time to watch the full panel video, if that's relevant)
>
> * The parser haven't been available for that long (I think)
> * Can they handle whole language?

Dunno about DScanner, but if it's being used in DCD, I'd guess it can handle the whole language, or be fairly close to it.

Similarly, there is also DParser2 from MonoD and the DDT parser (for the tool I'm working on)

> * Semantic analysis is needed. Otherwise as soon as someone uses
> templates or mixins the tool won't properly work
>

I think there would be a lot of modifications that one can do without semantic analysis (or limited analysis). But that's why I asked for examples of dfix scenarios.

Adding "final" to every method in certain classes could be done without semantic analysis. Reworking certain constructs to different constructs possibly as well (for example change foreach_reverse to just foreach usage)

-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros
June 17, 2014
On 17/06/2014 16:45, Bruno Medeiros wrote:
> Dunno about DScanner, but if it's being used in DCD, I'd guess it can
> handle the whole language, or be fairly close to it.
>
> Similarly, there is also DParser2 from MonoD and the DDT parser (for the
> tool I'm working on)
>

And DDT is fairly complete, AFAIK, and well covered in tests. There might be some syntax I have missed if I misunderstood the grammar, but that should be fixable easily.

-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros
June 17, 2014
On 17/06/2014 16:45, Bruno Medeiros wrote:
> Similarly, there is also DParser2 from MonoD and the DDT parser (for the
> tool I'm working on)

And the DDT parser is fairly complete, AFAIK, and well covered in tests. There might be some syntax I have missed if I misunderstood the grammar spec, but that should be fixable easily.

-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros
June 17, 2014
On Tuesday, 17 June 2014 at 15:45:55 UTC, Bruno Medeiros wrote:

> Dunno about DScanner, but if it's being used in DCD, I'd guess it can handle the whole language, or be fairly close to it.
>
> Similarly, there is also DParser2 from MonoD and the DDT parser (for the tool I'm working on)
>

HAHAHAHAHAHA ! (The author of these actual tools will tell you the same).

>> * Semantic analysis is needed. Otherwise as soon as someone uses
>> templates or mixins the tool won't properly work
>>
>
> I think there would be a lot of modifications that one can do without semantic analysis (or limited analysis). But that's why I asked for examples of dfix scenarios.
>

Until you hit a static if. Which is always.

> Adding "final" to every method in certain classes could be done without semantic analysis. Reworking certain constructs to different constructs possibly as well (for example change foreach_reverse to just foreach usage)

ditto.
June 17, 2014
On Tuesday, 17 June 2014 at 15:45:55 UTC, Bruno Medeiros wrote:

> Adding "final" to every method in certain classes could be done without semantic analysis. Reworking certain constructs to different constructs possibly as well (for example change foreach_reverse to just foreach usage)

What about methods added via template and string mixins? You cannot add "final" to a method in a template, because you don't know if it will be mixed in into a class or struct (does the compiler allow "final" on struct methods?). There's no possible way to handle string mixins, a method can be built up by concatenating strings.

--
/Jacob Carlborg
June 17, 2014
On 17/06/2014 19:10, deadalnix wrote:
> On Tuesday, 17 June 2014 at 15:45:55 UTC, Bruno Medeiros wrote:
>
>> Dunno about DScanner, but if it's being used in DCD, I'd guess it can
>> handle the whole language, or be fairly close to it.
>>
>> Similarly, there is also DParser2 from MonoD and the DDT parser (for
>> the tool I'm working on)
>>
>
> HAHAHAHAHAHA ! (The author of these actual tools will tell you the same).
>

I don't understand what point is it you're trying to say here...
Are you saying it's ludicrous that people have written complete parsers for D?

>>> * Semantic analysis is needed. Otherwise as soon as someone uses
>>> templates or mixins the tool won't properly work
>>>
>>
>> I think there would be a lot of modifications that one can do without
>> semantic analysis (or limited analysis). But that's why I asked for
>> examples of dfix scenarios.
>>
>
> Until you hit a static if. Which is always.
>
>> Adding "final" to every method in certain classes could be done
>> without semantic analysis. Reworking certain constructs to different
>> constructs possibly as well (for example change foreach_reverse to
>> just foreach usage)
>
> ditto.

How would a static if prevent a tool from adding "final" to every method in a specified class?


-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros
June 17, 2014
On Tuesday, 17 June 2014 at 19:48:42 UTC, Bruno Medeiros wrote:
> On 17/06/2014 19:10, deadalnix wrote:
>> On Tuesday, 17 June 2014 at 15:45:55 UTC, Bruno Medeiros wrote:
>>
>>> Dunno about DScanner, but if it's being used in DCD, I'd guess it can
>>> handle the whole language, or be fairly close to it.
>>>
>>> Similarly, there is also DParser2 from MonoD and the DDT parser (for
>>> the tool I'm working on)
>>>
>>
>> HAHAHAHAHAHA ! (The author of these actual tools will tell you the same).
>>
>
> I don't understand what point is it you're trying to say here...
> Are you saying it's ludicrous that people have written complete parsers for D?

Parsing D is relatively simple but making any reliable changes without full (and mean _full_) semantic analysis is close to impossible because of code generation and interleaving semantic stages.
June 17, 2014
On 17/06/2014 20:12, Jacob Carlborg wrote:
> On Tuesday, 17 June 2014 at 15:45:55 UTC, Bruno Medeiros wrote:
>
>> Adding "final" to every method in certain classes could be done
>> without semantic analysis. Reworking certain constructs to different
>> constructs possibly as well (for example change foreach_reverse to
>> just foreach usage)
>
> What about methods added via template and string mixins? You cannot add
> "final" to a method in a template, because you don't know if it will be
> mixed in into a class or struct (does the compiler allow "final" on
> struct methods?). There's no possible way to handle string mixins, a
> method can be built up by concatenating strings.
>
> --
> /Jacob Carlborg

Methods added through string mixins would not work. Actually, any AST modification would probably not work through string mixins. That would be an incredibly difficult problem to solve - in many cases, impossible even.
And perhaps rightly so, one could make a case that string mixins should be used sparsely? We have to realize that string mixins are very useful, but are a dirty hack that is a replacement for AST macros.

As for methods added via templates, the tool would present the option to add "final" to those templates as well, or just the class. If doing do might break other classes that use the same template, well, that is a problem that transcends whether this transformation is done manually or by a tool. It would not be an issue with "dfix" itself then.

-- 
Bruno Medeiros
https://twitter.com/brunodomedeiros
June 18, 2014
On 17/06/14 22:00, Bruno Medeiros wrote:

> And perhaps rightly so, one could make a case that string mixins should
> be used sparsely? We have to realize that string mixins are very useful,
> but are a dirty hack that is a replacement for AST macros.

I fully agree, but that won't stop anyone from actually using string mixins ;)

-- 
/Jacob Carlborg
June 19, 2014
On Wednesday, 18 June 2014 at 06:43:32 UTC, Jacob Carlborg wrote:
> On 17/06/14 22:00, Bruno Medeiros wrote:
>
>> And perhaps rightly so, one could make a case that string mixins should
>> be used sparsely? We have to realize that string mixins are very useful,
>> but are a dirty hack that is a replacement for AST macros.
>
> I fully agree, but that won't stop anyone from actually using string mixins ;)

hmm well all string-mixins life at compile-time so one can print them out at runtime dump the source and but it into the ast same for the results of static if and the like