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

Vincent R. forumer at smartmobili.com
Fri Jul 12 16:57:59 PDT 2013


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 ?








More information about the cfe-dev mailing list