Help with clang AST matchers: find semicolon after a decl statement

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

Help with clang AST matchers: find semicolon after a decl statement

Frederico Araujo
Dear list,

I'm implementing a small source-to-source rewriter using clang tooling and AST matchers.
I'd like to ask if there is a way to use clang's API to find the source location after a semicolon of a matched declaration statement?

Looking in the documentation, I found the "findLocationAfterSemi" function which seems to be exactly what I want. However, I'm not being able to use it. Searching my llvm sources, I see its corresponding header file Transforms.h in <llvm_src_dir>/tools/clang/lib/ARCMigrate/ but not inside any sub-directory inside the directory I compiled clang (using cmake).

The function I mentioned can be found here:
http://clang.llvm.org/doxygen/Transforms_8h.html

Any help will be much appreciated!

Thanks,
Fred

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help with clang AST matchers: find semicolon after a decl statement

Frederico Araujo
I found the problem!

I forgot to update my make file to link against the ARCMigrate library.
I realized that after adding -I$(LLVM_SRC_PATH)/tools/clang/lib/ARCMigrate to my CLANG_INCLUDES, I also had to add -lclangARCMigrate to my CLANG_LIBS, which solved the problem.
I wonder why Transforms.h isn't included in clang's tools build directory?

So, in conclusion, answering my first question, the following code can be used to find the location just after the semicolon:

SourceLocation SemiLoc = clang::arcmt::trans::findSemiAfterLocation(D->getLocEnd(), D->getASTContext());

Regards,
Fred


On Wed, Jul 30, 2014 at 5:18 PM, Frederico Araujo <[hidden email]> wrote:
Dear list,

I'm implementing a small source-to-source rewriter using clang tooling and AST matchers.
I'd like to ask if there is a way to use clang's API to find the source location after a semicolon of a matched declaration statement?

Looking in the documentation, I found the "findLocationAfterSemi" function which seems to be exactly what I want. However, I'm not being able to use it. Searching my llvm sources, I see its corresponding header file Transforms.h in <llvm_src_dir>/tools/clang/lib/ARCMigrate/ but not inside any sub-directory inside the directory I compiled clang (using cmake).

The function I mentioned can be found here:
http://clang.llvm.org/doxygen/Transforms_8h.html

Any help will be much appreciated!

Thanks,
Fred


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help with clang AST matchers: find semicolon after a decl statement

Manuel Klimek
On Thu, Jul 31, 2014 at 12:37 AM, Frederico Araujo <[hidden email]> wrote:
I found the problem!

I forgot to update my make file to link against the ARCMigrate library.
I realized that after adding -I$(LLVM_SRC_PATH)/tools/clang/lib/ARCMigrate to my CLANG_INCLUDES, I also had to add -lclangARCMigrate to my CLANG_LIBS, which solved the problem.
I wonder why Transforms.h isn't included in clang's tools build directory?

I didn't even know the transforms stuff has such nice reusable functions. Generally, I'd say "arcmigrate" is the wrong layer of abstraction for those functions. We might want to put them next to clang's Lexer.

Generally, so far everybody has just rolled their own version of the findSemiAfterLocation function, which is admittedly very unfortunate.
 
So, in conclusion, answering my first question, the following code can be used to find the location just after the semicolon:

SourceLocation SemiLoc = clang::arcmt::trans::findSemiAfterLocation(D->getLocEnd(), D->getASTContext()); 


Regards,
Fred


On Wed, Jul 30, 2014 at 5:18 PM, Frederico Araujo <[hidden email]> wrote:
Dear list,

I'm implementing a small source-to-source rewriter using clang tooling and AST matchers.
I'd like to ask if there is a way to use clang's API to find the source location after a semicolon of a matched declaration statement?

Looking in the documentation, I found the "findLocationAfterSemi" function which seems to be exactly what I want. However, I'm not being able to use it. Searching my llvm sources, I see its corresponding header file Transforms.h in <llvm_src_dir>/tools/clang/lib/ARCMigrate/ but not inside any sub-directory inside the directory I compiled clang (using cmake).

The function I mentioned can be found here:
http://clang.llvm.org/doxygen/Transforms_8h.html

Any help will be much appreciated!

Thanks,
Fred


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev