[cfe-dev] Rewriting question

Vincent R. forumer at smartmobili.com
Wed Aug 21 07:32:40 PDT 2013


Le 21.08.2013 11:00, Konstantin Tokarev a écrit :
> 20.08.2013, 20:34, "Vincent R." <forumer at smartmobili.com>:
>> Hi,
>>
>> to be able to rewrite objc code from [myObj someMsg:a 
>> withContext:ctx]
>> into a java/c# syntax myObj.someMsg_withContext(a, ctx)
>> do I need to change the "nature" of the ast node and transforms it 
>> from
>> an iVar into a c++ object that would have
>> a method named someMsg_withContext ?
>> IS there any sample code showing how to declare that kind of object 
>> ?
>> Inside RewriteModernObjC.cpp there is some code to synthetize a C
>> function (SynthMsgSendFunctionDecl) but do you have some
>> sample code to generate a c++ method it would help I think.
>
> Rewriter works the next way: you visit AST nodes which are
> interesting for you,
> take their SourceRanges's, and use Rewriter methods like ReplaceText 
> or
> RemoveText to replace _text_, corresponding to the node, with your 
> _text_,
> or remove it, respectively.
>
> So, you change not AST nodes but replace strings inside source whith
> other strings.

Ok I understand now instead of focusing on trying to return a different 
Stmt I should only
use the text replace functions.
So next question when I call the rewriter on a file, let's say 
NSButton.m how can I "ask" the rewriter
to find amongst all the imports the one that contains the class 
declaration.
For instance with the following lines :

#include "config.h"

#import <Foundation/NSCharacterSet.h>

#import "AppKit/NSApplication.h"
#import "AppKit/NSButton.h"
#import "AppKit/NSButtonCell.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSWindow.h"

//
// class variables
//
static id buttonCellClass = nil;

/**
    TODO Description
*/
@implementation NSButton

// ...

@end

it should find that the NSButton is declared inside AppKit/NSButton.h 
to be able to generate a single file with both
the declaration and definition. And while I am it how can I load the 
whole object hierarchy 
NSButton->NSControl->NSView->NSResponder->NSObject
to be able to know if an instance method "override" a method in a base 
class ?










More information about the cfe-dev mailing list