D Compiler as a Library

Roman D. Boiko rb at d-coding.com
Thu Apr 19 04:25:46 PDT 2012


On Thursday, 19 April 2012 at 11:04:20 UTC, Ary Manzana wrote:
> On 4/19/12 12:48 AM, Jacob Carlborg wrote:
>> On 2012-04-18 14:49, Marco Leise wrote:
>>
>>> I want refactoring to be as simple as 
>>> Foo.renameSymbol("std.path.sep",
>>> "std.path.dirSeperator"); if the connection between module- 
>>> and
>>> filename allows "std.path" to be traced back to the original 
>>> file.
>>
>> I'm not sure but I don't think that is enough. In Clang you do 
>> something
>> like this:
>>
>> 1. Get cursor of source location
>> 2. Get a unique global ID of the cursor the corresponds to the 
>> symbol
>> (unified symbol resolution)
>> 3. Walk the AST to find all matches of this ID
>> 4. Get the source location of the cursors which match
>> 5. Rename the symbol at the source location
>>
>
> Unfortunately rename can't be perfect in D because you can't 
> apply it inside templates.

In general, there is nothing preventing renaming in templates or
mixins, if you do renaming after semantic analysis. However,
there can be some troubles, e.g., if mixin string is generated on
the fly from some function. Compiler error should suffice in this
case, or even better, refactoring tool should give a warning.


More information about the Digitalmars-d mailing list