Rewriting question about renaming type

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

Rewriting question about renaming type

Vincent R.
Hi,

When working with rewriting I would like to transform the variable
declaration and convert them into .net types :

let's consider the following declaration:

@interface GSNamedColor : NSColor
{
   NSString* _catalog_name;
   NSString *_color_name;
   NSString *_cached_name_space;
   NSColor *_cached_color;
   BOOL _aBoolVar;
   NSInteger _anIntVar;
}

I am transforming it into this for now :

public class GSNamedColor : NSColor
{
    protected NSString *_catalog_name;
    protected NSString *_color_name;
    protected NSString *_cached_name_space;
    protected NSColor *_cached_color;
    protected BOOL _aBoolVar;
    protected NSInteger _anIntVar;
}

But of course what I would like to obtain is

public class GSNamedColor : NSColor
{
    protected NSString _catalog_name;
    protected NSString _color_name;
    protected NSString _cached_name_space;
    protected NSColor _cached_color;
    protected bool _aBoolVar;
    protected int _anIntVar;
}

It means that I have to remove * when it's an object and replace some
type by corresponding ones

The code used for this transformation is :

void RewriteModernObjC::RewriteObjCFieldDecl(FieldDecl *fieldDecl,
                                              std::string &Result) {
   QualType Type = fieldDecl->getType();
   std::string Name = fieldDecl->getNameAsString();

   Result += "protected ";
   bool EleboratedType = RewriteObjCFieldDeclType(Type, Result);
   if (!EleboratedType)
     Type.getAsStringInternal(Name, Context->getPrintingPolicy());

   Result += Name;
  ...
}


so now my problem is to know what is the best option to modify the way
variable are written, I have a simple option
that consists in parsing the result of Type.getAsStringInternal and I
have already done something like that
when there is a call to getAsString

std::string
RewriteModernObjC::ConvertObjcStringTypeIntoCsharp(std::string ObjcType)
{
        std::string CSType = ObjcType;

     //convert objc types into .net ones
     if (ObjcType == "BOOL")
                CSType = "bool";
     else if (ObjcType == "NSInteger")
                CSType = "int";
        else if (ObjcType == "NSUInteger")
                CSType = "unsigned int";
        else if (ObjcType == "CGFloat")
                CSType = "double";
     else if (*ObjcType.rbegin() == '*')
                CSType = ObjcType.substr(0, ObjcType.size()-1);

        return CSType;
}

but in the case of getAsStringInternal the method doesn't work because
it returns the type followed by the name so it would mean I had to write
another
method that almost do the same but that use a startWith algorithm
instead of ==, and that split in function of space to check if there is
a * just after
the type and remove it, ...

SO I suppose another option would be to modify the getAsString and
getAsStringInternal but I don't know exactly how to do it.
There seem to be a printing policy but that's all I know for the
moment.


My question is : what is the best approach and how would you 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 about renaming type

Richard-2

In article <[hidden email]>,
    "Vincent R." <[hidden email]> writes:

> My question is : what is the best approach and how would you do it ?

I would study/emulate the cpp11-migrate tool.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://computergraphicsmuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev