[cfe-users] link order for libtooling

Mikhail Ramalho via cfe-users cfe-users at lists.llvm.org
Fri Jul 15 07:08:41 PDT 2016


Hi Folkert,

getName() should work for namedDecl only; to get type names, you need to
work differently.

I suggest you have a look at:

http://clang.llvm.org/doxygen/TypePrinter_8cpp_source.html
http://clang.llvm.org/doxygen/ASTDumper_8cpp_source.html
http://clang.llvm.org/doxygen/StmtDumper_8cpp_source.html

They print/dump the AST. I would say it's the best place to look (and
reimplement) to print a xml.

Thanks,


2016-07-15 10:06 GMT+01:00 folkert <folkert at vanheusden.com>:

> Mikhail,
>
> Thanks.
> Problem with getName() is that it does not exist for too many types.
> For example when I have a QualType that I would like to get as a string,
> then the doxygen says there's a getAstString static function but in
> reality it is not there. There's also no getName() for QualType. Then
> there's the split() method but the object that comes out of it also has
> no tostring or something that emits an enum or something.
>
> What I'm trying to do is create a tool which emits an xml of the ast.
> A bit like the one which was included.
>
> On Thu, Jul 14, 2016 at 03:38:41PM +0100, Mikhail Ramalho wrote:
> > In ESBMC [0], we use:
> >
> > -lclangTooling -lclangDriver -lclangFrontend -lclangParse
> > -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangLex
> > -lclangAST -lclangBasic -lLLVMBitReader -lLLVMCore -lLLVMOption
> > -lLLVMMCParser -lLLVMMC -lLLVMSupport -lrt -ldl -lpthread -lz -lm
> >
> > For clang, we have to manually write the libs, but for llvm we simply use
> > llvm-config, you can check the scripts for clang's libs [1] and llvm [2].
> >
> > ~
> >
> > But as a suggestion, I would not rely on getNameAsString, as it is
> > deprecated for quite a while. Try changing to *getName().str()* and it
> > should work for any C declaration (I'm not completely sure about that,
> > though). For C++ declarations (specially constructors and destructors), I
> > use the following method:
> >
> > std::string clang_c_convertert::get_decl_name(
> >   const clang::NamedDecl &decl)
> > {
> >   if(const clang::IdentifierInfo *identifier = decl.getIdentifier())
> >     return identifier->getName().str();
> >
> >   std::string name;
> >   llvm::raw_string_ostream rso(name);
> >   decl.printName(rso);
> >   return rso.str();
> > }
> >
> > It shoudl work for any C or C++ declaration.
> >
> > Thank you,
> >
> > [0] https://github.com/esbmc/esbmc
> > [1]
> >
> https://github.com/esbmc/esbmc/blob/master/scripts/build-aux/m4/ax_clang.m4
> > [2]
> >
> https://github.com/esbmc/esbmc/blob/master/scripts/build-aux/m4/ax_llvm.m4
> >
> >
> > 2016-07-14 15:12 GMT+01:00 folkert via cfe-users <
> cfe-users at lists.llvm.org>:
> >
> > > Hi,
> > >
> > > What is the order of the clang libraries when linking?
> > >
> > > Currently I'm doing:
> > >
> > > clang++ -fno-rtti `llvm-config --cxxflags` \
> > >         iterate.cpp \
> > >         `llvm-config --ldflags --libs --system-libs` \
> > >         -I/usr/lib/llvm-3.8/include -ggdb3 -std=c++11
> > > -I/usr/include/llvm-3.8/llvm/Support -L/usr/lib/llvm-3.8/lib/
> > > -L/usr/lib/gcc/x86_64-linux-gnu/5/ -I/usr/include/c++/5/
> > > -I/usr/include/x86_64-linux-gnu/c++/5/ -I/usr/lib/llvm-3.8/include/ \
> > >         -lclangTooling -lclangFrontend -lclangDriver
> -lclangSerialization
> > > -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST
> -lclangLex
> > > -lclangBasic -lLLVM -ldl
> > >
> > > but this gives me:
> > >
> > > /tmp/iterate-66d196.o: In function `getNameAsString':
> > > /usr/lib/llvm-3.8/include/clang/AST/Decl.h:184: undefined reference to
> > > `clang::DeclarationName::getAsString() const'
> > >
> > > Thanks in advance.
> > >
> > >
> > > Folkert van Heusden
> > >
> > > --
> > > ----------------------------------------------------------------------
> > > Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> > > _______________________________________________
> > > cfe-users mailing list
> > > cfe-users at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
> > >
> >
> >
> >
> > --
> >
> > Mikhail Ramalho.
>
>
> Folkert van Heusden
>
> --
> MultiTail รจ uno flexible tool per seguire di logfiles e effettuazione
> di commissioni. Feltrare, provedere da colore, merge, 'diff-view',
> etc. http://www.vanheusden.com/multitail/
> ----------------------------------------------------------------------
> Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
>



-- 

Mikhail Ramalho.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20160715/00620d98/attachment.html>


More information about the cfe-users mailing list