<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style>body { line-height: 1.5; }body { font-size: 10.5pt; font-family: ????; color: rgb(0, 0, 0); line-height: 1.5; }</style>
</head>
<body>
<div><span></span>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
Dear Clang users: </div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
I have a class named classA in a.h and a.cpp file. it have some methods, I want to add a new method definition to a.h and add new method body after last method use clang . How to do it ? </div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
I know the RecursiveASTVisitor::VisitCXXRecordDecl(...) can visit CXXRecordDecl and CXXMethodDecl , Rewriter be used to write code . but how to create new method definition and body to a.h and a.cpp?</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
//a.h file</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
classA {</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
protected:</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
int filed;</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
public:</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
void method1();</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
void method2();</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
//insert a new method</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<span style="font-size: 12pt;">}</span><br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
//a.cpp file</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
void classA::method1()</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
{</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
..........</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
}</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
void classA::method2()</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
{</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
...........</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
}</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
// inset new method body</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
Yours truly<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
<br>
</div>
<div style="line-height: normal; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;">
Robert</div>
</div>
<div><br>
</div>
<hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span>
<div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt">
<div>licux6@hotmail.com</div>
</div>
</span></div>
</body>
</html>