D Compiler as a Library

Tobias Pankrath tobias at pankrath.net
Thu Apr 19 05:31:22 PDT 2012


On Thursday, 19 April 2012 at 12:16:05 UTC, Ary Manzana wrote:
> On 4/19/12 7:25 PM, Roman D. Boiko wrote:
>> 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.
>
> T foo(T)(T x) {
>   return x.something();
> }
>
> int something(int x) {
>   return 1;
> }
>
> float something(float x) {
>   return 1.0;
> }
>
> Now... go and rename the first function named "something". What 
> do you do with "x.something()" inside the template... rename it 
> or not?

1. Ask the user or
2. Check if there is an instance of foo!int which refers to 
something. If so
and there is no other instance, that refers to another something: 
rename it.
3. If there in another instance: Ask the user to rename one, all, 
none.


More information about the Digitalmars-d mailing list