Hi,<div><br></div><div>I would like to modify class definitions that are part of a header file and generate another file (preferably overwrite the original header file). Essentially, I want to add a few fields to an existing class and change access specifiers of few other fields. For instance, transform something like:</div>
<div><br></div><div>/// Shape.h</div><div>class Shape {</div><div> public:</div><div> int x;</div><div> int y;</div><div> private:</div><div> float A;</div><div> float B;</div><div> float C;</div><div>
};</div><div><br></div><div><br></div><div>to</div><div><br></div><div>/// Shape.h</div><div>class Shape {</div><div> public:</div><div> int x; </div><div> int y;</div><div> int z; // Newly-added field</div>
<div> public: // Changed access specifier of A and B </div><div> float A;</div><div> float B;</div><div> private:</div><div> float C;</div><div>};</div><div><br></div><div>The information on the exact class on which the transformation is to be performed, and fields whose access specifiers have to be changed is available after semantic analysis (within the Sema object). I don't particularly care about the formatting of the output header file, as long as the transformations are done correctly. </div>
<div><br></div><div>What's the best way to achieve this within clang?</div><div><br></div><div>I took a look at RewriteObjC, and tried to write a ASTConsumer class based on it, but I was not able to apply it directly to header files: the output was a .gch file which is in binary and as it stands now, I am also not sure how to override HandleTagDecl() to make the necessary changes to the class in question. Is there a better/easier way than using either ASTConsumer/SemaConsumer ?</div>
<div><br></div><div>thanks,</div><div>Prakash</div>