[cfe-users] binary operator

2016-07-12 Thread folkert via cfe-users
Hi,

When iterating through the AST I encounter BinaryOperator-s, part of an
IfStmt.
My question now is: how can I find which operator it is? E.g. ==, >=,
etc. 
I'm using libclang.


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] binary operator

2016-07-12 Thread folkert via cfe-users
Hi,

> > When iterating through the AST I encounter BinaryOperator-s, part of an
> > IfStmt.
> > My question now is: how can I find which operator it is? E.g. ==, >=,
> > etc.
> > I'm using libclang.
> 
> You can call BinaryOperator::getOpcode, which will return an Opcode,
> which is a typedef of the BinaryOperatorKind enum.

That is part of the C++ api right? I'm using the one with the clang_
prefixes and I could not find any getOpcode call in there (I checked
Index.h).


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] binary operator

2016-07-13 Thread folkert via cfe-users
> > When iterating through the AST I encounter BinaryOperator-s, part of an
> > IfStmt.
> > My question now is: how can I find which operator it is? E.g. ==, >=,
> > etc.
> > I'm using libclang.
> >
> 
> You can call BinaryOperator::getOpcode, which will return an Opcode,
> which is a typedef of the BinaryOperatorKind enum.

This c++ version, is this from libtooling? Or which library?


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] link order for libtooling

2016-07-14 Thread folkert via cfe-users
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@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] link order for libtooling

2016-07-15 Thread folkert via cfe-users
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 :
> 
> > 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@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
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] parsing a windows source

2016-07-21 Thread folkert via cfe-users
Hi,

I would like to parse a windows source. Using clang/llvm and
preferably under Linux.

I'm using:

std::vector arguments;

arguments.push_back("-fms-compatibility");
arguments.push_back("-fms-extensions");
arguments.push_back("-Wno-error=invalid-token-paste");
arguments.push_back("-fdelayed-template-parsing");
arguments.push_back("-DWIN32");
arguments.push_back("-D_WIN32");
arguments.push_back("-D_WINDOWS");
arguments.push_back("-D_DEBUG");
arguments.push_back("-D_CRTDBG_MAP_ALLOC");
arguments.push_back("-D_UNICODE");
arguments.push_back("-DUNICODE");
arguments.push_back("-D_AFXDLL");
arguments.push_back("-D_DLL");
arguments.push_back("-fmsc-version=1600");
arguments.push_back("-fcxx-exceptions");
arguments.push_back("-fexceptions");
arguments.push_back("-D_M_AMD64=1");
arguments.push_back("-D_M_X64=1");
arguments.push_back("-I.");

arguments.push_back("-isystem=/C/Program Files (x86)/Microsoft Visual 
Studio 10.0/VC/include");
arguments.push_back("-I/C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include");
arguments.push_back("-isystem=/C/Program Files (x86)/Microsoft Visual 
Studio 10.0/VC/crt/src");
arguments.push_back("-I/C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/crt/src");
arguments.push_back("-I/C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/atlmfc/include");
arguments.push_back("-isystem=/C/Program Files (x86)/Microsoft 
SDKs/Windows/v7.0A/Include");
arguments.push_back("-I/C/Program Files (x86)/Microsoft 
SDKs/Windows/v7.0A/Include");

// buf contains source to parse
llvm::Twine code(buf);

FindNamedClassAction *fnca = new FindNamedClassAction(root);

clang::tooling::runToolOnCodeWithArgs(fnca, code, arguments, 
llvm::Twine(fname));

This gives:

In file included from /C/Source.cpp:12:
In file included from /C/StdAfx.h:2:
In file included from /C/01StdAfx.h:47:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/atlmfc/include/afx.h:54:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/new.h:22:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/new:6:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/exception:7:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/xstddef:6:
In file included from /C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/yvals.h:6:
/C/Program Files (x86)/Microsoft Visual Studio 
10.0/VC/include/crtdefs.h:402:29: error: typedef redefinition with
different types ('unsigned int' vs 'unsigned long')
typedef _W64 unsigned int   size_t;
^
/C/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/crtdefs.h:543:2: 
warning: __declspec attribute
'dllimport' is not supported [-Wignored-attributes]
 _CRTIMP void __cdecl _invalid_parameter(_In_opt_z_ const wchar_t *,
_In_opt_z_ const wchar_t *, _In_opt_z_ const wchar_t *, unsigned int,
uintptr_t);
 ^
/C/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/crtdefs.h:18:28: 
note: expanded from macro '_CRTIMP'
#define _CRTIMP __declspec(dllimport)
   ^
[skipped a bit]

/C/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Include/winnt.h:455:9: 
error: unknown type name
'PNZWCH'
typedef PNZWCH PNZTCH;
^


How can I fix this? Is it a missing compile-flag?


Folkert van Heusden

-- 
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] Expr objects and Evaluate*

2016-08-01 Thread folkert via cfe-users
Hi,

I have an Expr object. How can I know if I can invoke
EvaluateAsBooleanCondition, EvaluateAsRValue, EvaluateAsInt and
EvaluateAsFloat ?
Because if I just call them on any Expr object, I get assertions like:

llvm/tools/clang/include/clang/AST/Type.h:612: const 
clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion 
`!isNull() && "Cannot retrieve a NULL type pointer"' failed

#3  0x7f65aa2111b2 in __GI___assert_fail (assertion=0x11e6450 "!isNull() && 
\"Cannot retrieve a NULL type pointer\"", file=0x11e61d0 
"/home/folkert/llvm/tools/clang/include/clang/AST/Type.h", line=612,
function=0x1780040 
<_ZZNK5clang8QualType12getCommonPtrEvE19__PRETTY_FUNCTION__> "const 
clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const") at 
assert.c:101
#4  0x00ea5713 in clang::QualType::getCommonPtr() const [clone 
.part.1700] ()
#5  0x00ec3727 in clang::Expr::EvaluateAsInt(llvm::APSInt&, 
clang::ASTContext const&, clang::Expr::SideEffectsKind) const ()


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] traversing the ast using libtooling

2016-08-04 Thread folkert via cfe-users
Hi,

When I want to walk over the complete ast and visit each node (by using
a RecursiveASTVisitor<...>), do I need to implement all of TraverseDecl,
TraverseStmt and TraverseType? Because with all of those it looks like
some code is processed twice.

Second question: there are other Traverse...-methods as well:
TraverseAttr for example. Shouldn't I implement that one as well to get
all data?


Folkert van Heusden

-- 
---
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] uniquely identifying names

2016-08-26 Thread folkert via cfe-users
Hi,

The Sun java compiler allows you to (from java) walk the AST and
investigate it. Each token is stored in an object. Each object has a
hash() method which uniquely identifies it.

Now I was wondering: can I do so with the LLVM tooling as well? I could
of course if I want to identify e.g. a function name just pick the line-
and column number and maybe include the function name itself as well but
that would constantly change when lines are added and/or removed.

Any suggestions?


regards,

Folkert van Heusden

-- 
-
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] uniquely identifying names

2016-08-30 Thread folkert via cfe-users
Maybe I could expand a name into its full name and use that.
e.g.:

namespace bla { class myclass { void mymethod() { } } }

then the full name of mymethod would be bla::myclass::mymethod would be
unique enough to me (including filename).
Can I somehow get this out of it?

On Fri, Aug 26, 2016 at 03:33:20PM +, David Blaikie wrote:
> There's no structural identity of code in Clang that I know of - I know
> someone's building a tool for doing structural similarity for things like
> plagiarism detection (I think there are some patches on the clang mailing
> list).
> 
> But if you only need identity within a single process, the pointer value of
> the pointer to any AST construct is a unique identity you can use.
> 
> (line/file/column isn't sufficiently unique - you could have a file that is
> included under different macro situations and each time it defines a
> different function, but all those functions would appear to be defined on
> the same line/file of that included file - or a macro that defines multiple
> functions - both can be resolved by looking at the more complete location
> information (including macro locations, etc))
> 
> On Fri, Aug 26, 2016 at 5:11 AM folkert via cfe-users <
> cfe-users@lists.llvm.org> wrote:
> 
> > Hi,
> >
> > The Sun java compiler allows you to (from java) walk the AST and
> > investigate it. Each token is stored in an object. Each object has a
> > hash() method which uniquely identifies it.
> >
> > Now I was wondering: can I do so with the LLVM tooling as well? I could
> > of course if I want to identify e.g. a function name just pick the line-
> > and column number and maybe include the function name itself as well but
> > that would constantly change when lines are added and/or removed.
> >
> > Any suggestions?
> >
> >
> > regards,
> >
> > Folkert van Heusden
> >
> > --
> > -
> > Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> > ___
> > cfe-users mailing list
> > cfe-users@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
> >


Folkert van Heusden

-- 
Always wondered what the latency of your webserver is? Or how much more
latency you get when you go through a proxy server/tor? The numbers
tell the tale and with HTTPing you know them!
 http://www.vanheusden.com/httping/
---
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] uniquely identifying names

2016-08-31 Thread folkert via cfe-users
Oh right, indeed.
Parser error (my brain) on my side: I looked for "fully q...".
Mea culpa.

On Tue, Aug 30, 2016 at 08:52:25PM +0200, Lucas Soltic wrote:
> I don't know which API you're using, but 
> clang::NamedDecl::getQualifiedNameAsString seems to do what you want.
> 
> > Le 30 août 2016 à 17:40, David Blaikie via cfe-users 
> >  a écrit :
> > 
> > Do you want to identify the same entity across a valid program's various 
> > source files? Across changes to that program? (what changes?)
> > 
> > If you want to do the former, then producing the mangled name of the entity 
> > is probably what you want. (some part of the ABI code in Clang could give 
> > you that, I would assume - but not sure exactly where)
> > 
> >> On Tue, Aug 30, 2016 at 2:33 AM folkert  wrote:
> >> Maybe I could expand a name into its full name and use that.
> >> e.g.:
> >> 
> >> namespace bla { class myclass { void mymethod() { } } }
> >> 
> >> then the full name of mymethod would be bla::myclass::mymethod would be
> >> unique enough to me (including filename).
> >> Can I somehow get this out of it?
> >> 
> >> On Fri, Aug 26, 2016 at 03:33:20PM +, David Blaikie wrote:
> >> > There's no structural identity of code in Clang that I know of - I know
> >> > someone's building a tool for doing structural similarity for things like
> >> > plagiarism detection (I think there are some patches on the clang mailing
> >> > list).
> >> >
> >> > But if you only need identity within a single process, the pointer value 
> >> > of
> >> > the pointer to any AST construct is a unique identity you can use.
> >> >
> >> > (line/file/column isn't sufficiently unique - you could have a file that 
> >> > is
> >> > included under different macro situations and each time it defines a
> >> > different function, but all those functions would appear to be defined on
> >> > the same line/file of that included file - or a macro that defines 
> >> > multiple
> >> > functions - both can be resolved by looking at the more complete location
> >> > information (including macro locations, etc))
> >> >
> >> > On Fri, Aug 26, 2016 at 5:11 AM folkert via cfe-users <
> >> > cfe-users@lists.llvm.org> wrote:
> >> >
> >> > > Hi,
> >> > >
> >> > > The Sun java compiler allows you to (from java) walk the AST and
> >> > > investigate it. Each token is stored in an object. Each object has a
> >> > > hash() method which uniquely identifies it.
> >> > >
> >> > > Now I was wondering: can I do so with the LLVM tooling as well? I could
> >> > > of course if I want to identify e.g. a function name just pick the 
> >> > > line-
> >> > > and column number and maybe include the function name itself as well 
> >> > > but
> >> > > that would constantly change when lines are added and/or removed.
> >> > >
> >> > > Any suggestions?
> >> > >
> >> > >
> >> > > regards,
> >> > >
> >> > > Folkert van Heusden
> >> > >
> >> > > --
> >> > > -
> >> > > Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> >> > > ___
> >> > > cfe-users mailing list
> >> > > cfe-users@lists.llvm.org
> >> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
> >> > >
> >> 
> >> 
> >> Folkert van Heusden
> >> 
> >> --
> >> Always wondered what the latency of your webserver is? Or how much more
> >> latency you get when you go through a proxy server/tor? The numbers
> >> tell the tale and with HTTPing you know them!
> >>  http://www.vanheusden.com/httping/
> >> ---
> >> Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> > ___
> > cfe-users mailing list
> > cfe-users@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Folkert van Heusden

-- 
Multi tail barnamaj mowahib li mora9abat attasjilat wa nataij awamir
al 7asoub. damj, talwin, mora9abat attarchi7 wa ila akhirih.
http://www.vanheusden.com/multitail/
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] diagnostics

2016-08-31 Thread folkert via cfe-users
Hi,

Something strange is happening while parsing using 

std::unique_ptr au = clang::tooling::buildASTFromCodeWithArgs(code, 
arguments, llvm::Twine(argv[i]));

I get a lot of errors and warning written to stderr (how can I stop that
apart from redirecting fd 2 to /dev/null?) but the following does not
return anything:

for(ASTUnit::stored_diag_const_iterator iterator = au -> stored_diag_begin(); 
iterator != au -> stored_diag_end(); iterator++) {
 // etc
}


Folkert van Heusden

-- 
MultiTail cok yonlu kullanimli bir program, loglari okumak, verilen
kommandolari yerine getirebilen. Filter, renk verme, merge, 'diff-
view', vs.  http://www.vanheusden.com/multitail/
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] splitting a type

2016-09-08 Thread folkert via cfe-users
Hi,

When I retrieve CastExpr::getType().getAsString() then I can get
something like:

const mytype_t *const **

Can I also somehow retrieve this tokenized?


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] finding the source position (range) of a variable name

2016-09-13 Thread folkert via cfe-users
Hi,

Finding the name and position of a function/method is easy:

DeclarationNameInfo dni = fd -> getNameInfo();
SourceRange dniSr = dni.getSourceRange(); // dniSr is position and length of 
name in source file
std::string name = dni.getName().getAsString(); // name of function/method


But how can I get this information for variables? Both the name and
sourcerange.
I looked in getQualifier +Loc of DeclaratorDecl but they're always
missing it seems?



Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] finding the source position (range) of a variable name

2016-09-14 Thread folkert via cfe-users

> DeclarationNameInfo dni = fd -> getNameInfo();
> SourceRange dniSr = dni.getSourceRange(); // dniSr is position and length of 
> name in source file
> std::string name = dni.getName().getAsString(); // name of function/method
> 
> But how can I get this information for variables? Both the name and
> sourcerange.
> I looked in getQualifier +Loc of DeclaratorDecl but they're always
> missing it seems?

What I mean is:
DeclaratorDecl::getQualifierLoc().getNestedNameSpecifier() always
returns NULL while I expect a NestedNameSpecifier object.



Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] finding the source position (range) of a variable name

2016-09-14 Thread folkert via cfe-users
The problem can be reproduced with this small example code:
http://files.slimwinnen.nl/n-nns.tgz

Just run make and then ./parse and you'll see it saying that "! NO
NestedNameSpecifier".
The test-code is test.cpp and the file it parses is example.cpp.

> > DeclarationNameInfo dni = fd -> getNameInfo();
> > SourceRange dniSr = dni.getSourceRange(); // dniSr is position and length 
> > of name in source file
> > std::string name = dni.getName().getAsString(); // name of function/method
> > 
> > But how can I get this information for variables? Both the name and
> > sourcerange.
> > I looked in getQualifier +Loc of DeclaratorDecl but they're always
> > missing it seems?
> 
> What I mean is:
> DeclaratorDecl::getQualifierLoc().getNestedNameSpecifier() always
> returns NULL while I expect a NestedNameSpecifier object.


Folkert van Heusden

-- 
MultiTail ist eine flexible Applikation um Logfiles und Kommando
Eingaben zu überprüfen. Inkl. Filter, Farben, Zusammenführen,
Ansichten etc. http://www.vanheusden.com/multitail/
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] dissecting the type of a VarDecl

2016-09-16 Thread folkert via cfe-users
Hi,

I have a VarDecl instance for which I want to dissect the type.
E.g. a const int a would be a const, an int and the name a /
std::vector would be namespace std, vector and so on.

The first one is easy but the second one: I have no idea where to begin.

Sofar I have the following:

#include 
#include 
#include 

using namespace clang;

void printQT(ASTContext *const Context, const QualType x)
{
if (x.isNull())
return;

QualType type = x.getNonReferenceType();

for(;!type.isNull();) {
if (type.hasQualifiers()) {
Qualifiers q = type.getQualifiers();

if (q.hasConst())
printf("const ");

if (q.hasVolatile())
printf("volatile ");

if (q.hasRestrict())
printf("restrict ");
}

const Type *t = type.getTypePtr();

if (!t) {
printf("null?\n");
break;
}
else if (t -> isPointerType())
printf("* ");
else if (t -> isFundamentalType()) {
std::string curType = 
type.getUnqualifiedType().getAsString();

printf("[F]%s ", curType.c_str());
break; // should be last entry in this chain
}
else {
std::string curType = 
type.getUnqualifiedType().getAsString();
// dissect

printf("%s ", curType.c_str());
break; // should be last entry in this chain
}

type = type->getPointeeType();
}

printf("\n");
}

int main(int argc, char **argv)
{
FILE *fh = fopen("example.cpp", "r");

fseek(fh, 0, SEEK_END);
size_t len = ftell(fh);
fseek(fh, 0, SEEK_SET);
char *buf = (char *)malloc(len + 1);
fread(buf, 1, len, fh);
buf[len] = 0x00;
fclose(fh);

llvm::Twine code(buf);

std::vector arguments;
arguments.push_back("-resource-dir=/usr/local/llvm/lib/clang/4.0.0");

std::unique_ptr au = 
clang::tooling::buildASTFromCodeWithArgs(code, arguments, 
llvm::Twine("example.cpp"));

for(clang::ASTUnit::top_level_iterator dit = au -> top_level_begin(); 
dit != au -> top_level_end(); dit++)
{
if (isa(*dit)) {
const VarDecl *vd = static_cast(*dit);
printQT(&au -> getASTContext(), vd -> getType());
}
}

return 0;
}



Folkert van Heusden
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] finding source-range of a macro-parameter name

2016-10-17 Thread folkert via cfe-users
Hi,

Given:

#define W(A) while(A)

void myfunc()
{
W(1) {
}
}

I would like retrieve a string for the "1" parameter of the while-macro.

Usually I would use:

Lexer::getSourceText(CharSourceRange::getCharRange(sr), sm, 
LangOptions(), 0);

(with 'sr' being a SourceRange and sm a SourceManager object).

to retrieve part of the original source-code. This works fine for e.g.
int a = 1; but fails for #defines.

I tried getLocStart, getLocation, tried using Lexer::getLocForEndOfToken
and sm.getSpellingLoc but everything ends up with an empty string ("").

Any suggestions?


regards
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] the case of the missing label in the switch/case

2016-11-09 Thread folkert via cfe-users
Hi,

I maybe very well not understanding something but it looks like a label
targetted by a goto, in a switch statement, gets missing: if I iterate
through the ast and emit all the stmt/expr/decls, then no label-type is
emitted.

#include 
 
void myfunc(int a)
{
switch(a) {
case 1:
printf("1\n");
goto my_label;
 
case 2:
break;
 
case 3:
my_label: // this label does not appear in the ast
printf("Hello, world!\n");
}
}


any ideas?


Folkert van Heusden

-- 
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] the case of the missing label in the switch/case

2016-11-09 Thread folkert via cfe-users
The problem is that you were using CaseStmt::getRHS instead of
CaseStmt::getSubStmt.
No idea what getRHS is supposed to return then.

On Wed, Nov 09, 2016 at 09:53:28AM +0100, folkert via cfe-users wrote:
> Hi,
> 
> I maybe very well not understanding something but it looks like a label
> targetted by a goto, in a switch statement, gets missing: if I iterate
> through the ast and emit all the stmt/expr/decls, then no label-type is
> emitted.
> 
> #include 
>  
> void myfunc(int a)
> {
> switch(a) {
> case 1:
> printf("1\n");
> goto my_label;
>  
> case 2:
> break;
>  
> case 3:
> my_label: // this label does not appear in the ast
> printf("Hello, world!\n");
> }
> }
> 
> 
> any ideas?
> 
> 
> Folkert van Heusden
> 
> -- 
> --
> Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Folkert van Heusden

-- 
To MultiTail einai ena polymorfiko ergaleio gia ta logfiles kai tin
eksodo twn entolwn. Prosferei: filtrarisma, xrwmatismo, sygxwneysi,
diaforetikes provoles. http://www.vanheusden.com/multitail/
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] finding in which function/method/scope a Decl is in, the parent so to say

2016-11-11 Thread folkert via cfe-users
Hi,

How can I find the parent of a VarDecl? The scope it is in. E.g.
function/method or a global.


Folkert van Heusden
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users