Clang as a scripted refactoring tool

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang as a scripted refactoring tool

Joseph Garvin
The mozilla folks have two complementary tools, Dehydra/Treehydra,
that let them add new static checking features to C++ via javascript.
They write how an annotation should work in javascript and then the
tools enforce it. I'd like to see an extended version of that idea --
using a high level language like javascript or python to be able to
describe refactorings specific to the task at hand. Beyond simple
class renaming I'd like to be able to say, refactor classes that use a
visitor pattern to use signals, or write a simple script to find
classes that have virtual functions and update them to have a virtual
destructor if they don't already. I asked the mozilla guys about this
on IRC and they suggested Clang is already part way there. What's the
state of using Clang for refactoring and what parts of the code base
should I be looking at if I'm interested in trying to build something
like this?
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang as a scripted refactoring tool

Sebastian Redl

On Aug 31, 2010, at 9:56 AM, Joseph Garvin wrote:
> I asked the mozilla guys about this
> on IRC and they suggested Clang is already part way there. What's the
> state of using Clang for refactoring and what parts of the code base
> should I be looking at if I'm interested in trying to build something
> like this?

Hi,

Clang is designed to be usable as the basis for a refactoring tool. Your best bet is to look at the Rewriter component. It allows you to create edits of the source code, based on location information stored in the AST. For an example, look at the Obj-C rewriter, a tool that rewrites Obj-C into pure C.

Sebastian
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang as a scripted refactoring tool

jahanian

On Aug 31, 2010, at 10:09 AM, Sebastian Redl wrote:

>
> On Aug 31, 2010, at 9:56 AM, Joseph Garvin wrote:
>> I asked the mozilla guys about this
>> on IRC and they suggested Clang is already part way there. What's the
>> state of using Clang for refactoring and what parts of the code base
>> should I be looking at if I'm interested in trying to build something
>> like this?
>
> Hi,
>
> Clang is designed to be usable as the basis for a refactoring tool.  
> Your best bet is to look at the Rewriter component. It allows you to  
> create edits of the source code, based on location information  
> stored in the AST. For an example, look at the Obj-C rewriter, a  
> tool that rewrites Obj-C into pure C.
Minor note. It rewrites into C++.

- Fariborz

>
>
> Sebastian
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang as a scripted refactoring tool

Joseph Garvin
Thanks guys I'll take a look :)

On Wed, Sep 1, 2010 at 1:17 PM, Fariborz Jahanian <[hidden email]> wrote:

>
> On Aug 31, 2010, at 10:09 AM, Sebastian Redl wrote:
>
>>
>> On Aug 31, 2010, at 9:56 AM, Joseph Garvin wrote:
>>>
>>> I asked the mozilla guys about this
>>> on IRC and they suggested Clang is already part way there. What's the
>>> state of using Clang for refactoring and what parts of the code base
>>> should I be looking at if I'm interested in trying to build something
>>> like this?
>>
>> Hi,
>>
>> Clang is designed to be usable as the basis for a refactoring tool. Your
>> best bet is to look at the Rewriter component. It allows you to create edits
>> of the source code, based on location information stored in the AST. For an
>> example, look at the Obj-C rewriter, a tool that rewrites Obj-C into pure C.
>
> Minor note. It rewrites into C++.
>
> - Fariborz
>
>>
>>
>> Sebastian
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev