[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] Generating #includes programatically
|
Hi,
I ended up using an InsertEdit to insert it before the first include
(getting the Node, and its offset, and then using that offset for
the InsertEdit). Thanks for the help!
Regards
Simon
Am 20.02.2015 um 08:30 schrieb Corbat
Thomas:
Hi
Simon
Since include directives don’t get visited in
the ASTVisitor (or preprocessor-related stuff in general,
because there is no inherent position in the tree
traversal), you cannot use ASTRewrite to place it after,
before or in place of another include directive. But you
could place if before another node actually represented in
the AST, like the first declaration of the translation unit.
To add the directive you need to create a
literal node (ASTRewrite.createLiteralNode() method), which
writes any string you like at the location of this node and
insert this node (ASTRewrite.insertBefore()).
Yet this location might not be correct for your
use case. For full flexibility you can create your own
TextFileChange, which allows you to add anything you like
anywhere you want. As Alena suggested you can check the
implementation of the include handling mechanisms. Perhaps
there is some infrastructure to simplify your task.
Regards
Thomas
From: cdt-dev-bounces@xxxxxxxxxxx
[mailto:cdt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Alena Laskavaia
Sent: Donnerstag, 19. Februar 2015 14:25
To: CDT General developers list.
Subject: Re: [cdt-dev] Generating #includes
programatically
Check Organize Includes/Add Include
feature of CDT, it must do something to insert includes ;)
On Thu, Feb 19, 2015 at 7:10 AM, Simon
Levermann <simon@xxxxxxxxxxxxx>
wrote:
Hello,
I'm currently looking into Code generation via the AST,
and I want to
generate an #include statement: #include
<utility>. This is needed for a
call to std::forward<T> which is used by some
other code that I
generate. However, the only implementation of
IASTPreprocessorIncludeStatement is
ASTInclusionStatement, which is a
package-private class inside ASTPreprocessorNode.java.
Thus, I cannot
instantiate it outside of the
org.eclipse.cdt.internal.core.parser.scanner package.
What is the intended way of generating #includes (or
other preprocessor
directives) and inserting them into the AST with an
ASTRewrite?
Kind regards
Simon
Levermann
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password,
or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev
|
Attachment:
signature.asc
Description: OpenPGP digital signature