[cfe-dev] Source to source transformation : objc to c#

jahanian fjahanian at apple.com
Fri Jul 12 17:13:18 PDT 2013


Yes, it is doable. We already have a translation tool to rewrite Objective-C into c++.
See Frontend/RewriteModernObjC.cpp as an example of how it i done.
This tool has a limitation and a drawback. It only works on pre-processed files.
Also, coding style in this tool is dated. 

- Fariborz

On Jul 12, 2013, at 4:57 PM, Vincent R. <forumer at smartmobili.com> wrote:

> Hi,
> 
> Before spending some money I would like to know if what I want to do is possible or not.
> I would need a tool to transform some objc code into c#, for instance let's consider the following dummy objc class :
> 
> @interface BankAccount: NSObject
> {
>   NSString *_name;
>   NSString *_address;
> }
> 
> +(id) bankAccountWithName:(NSString*)name address:(NSString*)addr;
> 
> -(id) initWithName:(NSString*)name address:(NSString*)addr;
> 
> -(void) dummyMethodJustToExplain;
> 
> @end
> 
> implemented like that
> 
> +(id) bankAccountWithName:(NSString*)name address:(NSString*)addr
> {
>   return [[[BankAccount alloc] initWithName:name  address: addr] autorelease];
> }
> 
> -(id) initWithName:(NSString*)name address:(NSString*)addr
> {
>  self = [super init];
>  _name = name;
>  _address = addr;
> }
> 
> -(void) dummyMethodJustToExplain
> {
>   if (_name && _address != nil)
>   {
>     NSLog(@"Hello world");
>   }
> }
> 
> 
> 
> I would like to transform it in c# :
> 
> 
> public class BankAccount : NSObject
> {
>   new public static BankAccount alloc() { return new BankAccount (); }
> 
>   protected NSString _name;
>   protected NSString _address;
> 
>  public static id bankAccountWithName_address(NSString name, NSString addr)
>  {
>    return BankAccount.alloc().initWithName_address(name, addr);
>  }
> 
> 
>  public virtual id initWithName_address(NSString name, NSString addr)
>  {
>     id self = this;
> 
>     _name = name;
>     _addr = addr;
> 
>     return self;
>  }
> 
>  public virtual void dummyMethodJustToExplain()
>  {
>     if (_name != null && _address != null)
>     {
>       NS.Log(@"Hello world");
>     }
>  }
> }
> 
> 
> In the worst case I just need to transform the objc syntax into a C/# syntax ie instead of [myobj aMessage:10] I would like to get myObj.aMessage(10)
> and replace nil by null and YES:NO by true/false.
> 
> Do you think llvm/clang/rewrite is appropriate to do that or am I asking too much ?
> 
> 
> 
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list