How to use ASTRewrite insertBefore() properly

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

How to use ASTRewrite insertBefore() properly

Ming Cheng
Hi,

I have a .cpp content originally  like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

struct TestCPlImplMsgCopy {
};

and I want to refactor it eventually like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"
using namespace FT_ADP_LIBRARY;

struct TestCPlImplMsgCopy {
};

I think my code can find insert point before "struct TestCPlImplMsgCopy" correctly. But the actual result like this:

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"
using namespace FT_ADP_LIBRARY;

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

struct TestCPlImplMsgCopy {
};

Why I say my code can find the point correctly is bcos if I manually change the original .cpp file to be:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

using namespace FT_ADP_LIBRARY;

struct TestCPlImplMsgCopy {
};

Now the same code can happily change for me like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

using namespace FT_ADP_LIBRARY;

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"

struct TestCPlImplMsgCopy {
};

It seems to me that insertBefore() does not treat IASTComment like other normal IASTNode?

Thanks.

_______________________________________________
cdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to use ASTRewrite insertBefore() properly

Ming Cheng
Any suggestion is welcome.

thanks.


From: [hidden email] <[hidden email]> on behalf of Ming Cheng <[hidden email]>
Sent: Wednesday, March 11, 2020 7:26 AM
To: [hidden email] <[hidden email]>
Subject: [cdt-dev] How to use ASTRewrite insertBefore() properly
 
Hi,

I have a .cpp content originally  like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

struct TestCPlImplMsgCopy {
};

and I want to refactor it eventually like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"
using namespace FT_ADP_LIBRARY;

struct TestCPlImplMsgCopy {
};

I think my code can find insert point before "struct TestCPlImplMsgCopy" correctly. But the actual result like this:

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"
using namespace FT_ADP_LIBRARY;

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

struct TestCPlImplMsgCopy {
};

Why I say my code can find the point correctly is bcos if I manually change the original .cpp file to be:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

using namespace FT_ADP_LIBRARY;

struct TestCPlImplMsgCopy {
};

Now the same code can happily change for me like this:

/*
 * TestCPlImplMsgCopy.cpp
 *
 *  Created on: Mar 11, 2020
 *      Author: mcheng
 */

using namespace FT_ADP_LIBRARY;

#include "TC_UTGlobal.h"
#include "CPlImplMsgCopy.h"

struct TestCPlImplMsgCopy {
};

It seems to me that insertBefore() does not treat IASTComment like other normal IASTNode?

Thanks.

_______________________________________________
cdt-dev mailing list
[hidden email]
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev