Rewriting question

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

Rewriting question

Vincent R.
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.

Thanks


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

Re: Rewriting question

jahanian
Modern rewriter translates objective-c syntax  for messaging into c function APIs which
implement the messaging. ASTs are those for a c function call. It does not introduce any
new AST. If you want to translate into other languages not
supported (in AST) by clang, your only choice is to rewriter the messaging syntax 
directly into their c# representation.

- Fariborz

On Aug 20, 2013, at 8:38 AM, Vincent R. <[hidden email]> wrote:

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.

Thanks


_______________________________________________
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: Rewriting question

Vincent R.
Le 20.08.2013 21:06, jahanian a écrit :
> Modern rewriter translates objective-c syntax for messaging into c
> function APIs which
> implement the messaging. ASTs are those for a c function call. It
> does
> not introduce any
> new AST. If you want to translate into other languages not
> supported (in AST) by clang, your only choice is to rewriter the
> messaging syntax
> directly into their c# representation.

Yes and how do I rewrite the messaging syntax directly ? What file or
function is involved to do it ?

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

Re: Rewriting question

Konstantin Tokarev
In reply to this post by Vincent R.


20.08.2013, 20:34, "Vincent R." <[hidden email]>:

> 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.

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

Re: Rewriting question

Vincent R.
Le 21.08.2013 11:00, Konstantin Tokarev a écrit :

> 20.08.2013, 20:34, "Vincent R." <[hidden email]>:
>> 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 ?







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

Re: Rewriting question

jahanian
In reply to this post by Vincent R.
As an example, you can look at RewriteObjCMethodDecl which builds a c function declaration and the caller,
then replaces the method declaration with this string; as in:

RewriteObjCMethodDecl(OMD->getClassInterface(), OMD, ResultStr);
    SourceLocation LocStart = OMD->getLocStart();
    SourceLocation LocEnd = OMD->getCompoundBody()->getLocStart();

    const char *startBuf = SM->getCharacterData(LocStart);
    const char *endBuf = SM->getCharacterData(LocEnd);
    ReplaceText(LocStart, endBuf-startBuf, ResultStr);

- fariborz

On Aug 21, 2013, at 1:23 AM, Vincent R. <[hidden email]> wrote:

> Le 20.08.2013 21:06, jahanian a écrit :
>> Modern rewriter translates objective-c syntax for messaging into c
>> function APIs which
>> implement the messaging. ASTs are those for a c function call. It does
>> not introduce any
>> new AST. If you want to translate into other languages not
>> supported (in AST) by clang, your only choice is to rewriter the
>> messaging syntax
>> directly into their c# representation.
>
> Yes and how do I rewrite the messaging syntax directly ? What file or function is involved to do it ?
>


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