On Tue, Aug 23, 2011 at 9:25 AM, Simon <[email protected]> wrote:
> Couldn't find the env.sh using locate but I got the following to sort of
env.sh is at the root of the pfff project. git clone
git://github.com/facebook/pfff.git
and you should find it.
> work (see below) thanks to your tip about PFFF_HOME. I have some more
> questions:
> 1. How can I get pfff to include the file line and character position info
> in the dump?
I've just added a -dump_cpp_full option to pfff that does that.
> 2. pfff seems to like the #define but doesn't like the #ifdef. How can I fix
> this?
pfff recognize only certain cpp idioms (just like coccinelle). This
idiom is not yet
supported.
> 3. How can I get pfff to dump the comment too?
the new -dump_cpp_full option does that.
> Thanks,
> Simon
>
> $ cat example.c
> #define ANYDEFINE 1
> enum myenum {
> enum_a,
> #ifdef OPTIONAL_ENUM_A2
> enum_a2,
> #endif
> enum_b,
> enum_c
> };
> long myfunc(int arg1, int arg2)
> {
> /* example comment */
> return arg1 + arg2;
> }
> $ PFFF_HOME=/usr/local/share/pfff pfff -dump_cpp example.c
> Using /usr/local/share/pfff//data/cpp_stdlib/macros.h macro file
> parse error
> = File "example.c", line 4, column 0, charpos = 46
> around = '#ifdef OPTIONAL_ENUM_A2', whole content = #ifdef
> OPTIONAL_ENUM_A2
> ERROR-RECOV: found sync '}' at line 9
> ERROR-RECOV: found sync bis, eating } and ;
> badcount: 8
> bad: #define ANYDEFINE 1
> bad: enum myenum {
> bad: enum_a,
> BAD:!!!!! #ifdef OPTIONAL_ENUM_A2
> bad: enum_a2,
> bad: #endif
> bad: enum_b,
> bad: enum_c
> bad: };
> [CppTop(
> Define((), ("ANYDEFINE", ()), DefineVar, DefineExpr((C(Int("1")),
> [()]))));
> NotParsedCorrectly(
> [(); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
> (); (); (); (); (); (); (); (); ()]);
> Func(
> FunctionOrMethod(
> {f_name: (None, [], IdIdent(("myfunc", ()))); f_type:
> {ft_ret: ((), (BaseType(IntType(Si((Signed, CLong)))), [()]));
> ft_params:
> [{p_name: Some(("arg1", ())); p_type:
> ((), (BaseType(IntType(Si((Signed, CInt)))), [()])); p_register:
> None; p_val: None; };
> {p_name: Some(("arg2", ())); p_type:
> ((), (BaseType(IntType(Si((Signed, CInt)))), [()])); p_register:
> None; p_val: None; }];
> ft_dots: None; ft_const: None; ft_throw: None; };
> f_storage: ((NoSto, false), []); f_body:
> [StmtElem(
> (Jump(
> ReturnExpr(
> (Binary(
> (Ident((None, [], IdIdent(("arg1", ()))),
> {i_scope: NoScope; }),
> []), Arith(Plus),
> (Ident((None, [], IdIdent(("arg2", ()))),
> {i_scope: NoScope; }),
> [])),
> [()]))),
> [(); ()]))];
> })); FinalDef(())]
>
> On Mon, Aug 22, 2011 at 4:14 PM, yoann padioleau <[email protected]>
> wrote:
>>
>> Have you done the source env.sh that set PFFF_HOME so that pfff knows
>> where
>> to find its configuration files?
>>
>>
>> On Mon, Aug 22, 2011 at 3:26 PM, Simon <[email protected]> wrote:
>> > Thanks, I following the install instructions. Everything went well.
>> > How can invoke pfff without it complaining (see below)?
>> > $ cat example.c
>> > int
>> > myfunc(int arg1, int arg2)
>> > {
>> > return arg1 + arg2;
>> > }
>> > $ pfff -dump_cpp example.c
>> > Using /home/pad/pfff//data/cpp_stdlib/macros.h macro file
>> > exn Unix_error: No such file or directory stat
>> > /home/pad/pfff//data/cpp_stdlib/macros.h
>> > Fatal error: exception Unix.Unix_error(20, "stat",
>> > "/home/pad/pfff//data/cpp_stdlib/macros.h")
>> > Thanks,
>> > Simon
>> > On Mon, Aug 22, 2011 at 2:52 PM, yoann padioleau
>> > <[email protected]>
>> > wrote:
>> >>
>> >> You need ocaml 3.12. The pattern at this line use a feature introduced
>> >> in
>> >> 3.12.
>> >>
>> >> On Mon, Aug 22, 2011 at 2:39 PM, Simon <[email protected]> wrote:
>> >> > On Mon, Aug 22, 2011 at 1:58 PM, yoann padioleau
>> >> > <[email protected]>
>> >> > wrote:
>> >> >>
>> >> >> it's in the repository of pfff, in the lang_cpp/parsing
>> >> >> subdirectory.
>> >> >> https://github.com/facebook/pfff
>> >> >> (it can also parse lots of C++ code).
>> >> >> There is a -dump_cpp option to pfff that may do what you want.
>> >> >
>> >> > Thanks. I tried to compile pfff so that I can try out the -dump_cpp
>> >> > option
>> >> > but I get an error at the 'make depend' stage:
>> >> > $ /usr/bin/ocaml -version
>> >> > The Objective Caml toplevel, version 3.11.2
>> >> > $ make depend
>> >> > ...
>> >> > make[1]: Entering directory
>> >> > `/tmp/facebook-pfff-446e09a/h_visualization'
>> >> > ocamldep -I ../commons -I ../commons/lib-json *.mli *.ml > .depend
>> >> > File "treemap.ml", line 133, characters 23-24:
>> >> > Error: Syntax error
>> >> > make[1]: *** [depend] Error 2
>> >> > make[1]: Leaving directory
>> >> > `/tmp/facebook-pfff-446e09a/h_visualization'
>> >> > make: *** [depend] Error 2
>> >> > Any ideas?
>> >> > Thanks,
>> >> > Simon
>> >> >
>> >> >>
>> >> >> On Mon, Aug 22, 2011 at 1:49 PM, Julia Lawall <[email protected]> wrote:
>> >> >> > On Mon, 22 Aug 2011, Simon wrote:
>> >> >> >
>> >> >> >> On Mon, Aug 22, 2011 at 12:43 PM, Julia Lawall <[email protected]>
>> >> >> >> wrote:
>> >> >> >>
>> >> >> >> > On Mon, 22 Aug 2011, Simon wrote:
>> >> >> >> >
>> >> >> >> > > On Mon, Aug 22, 2011 at 11:11 AM, SF Markus Elfring <
>> >> >> >> > > [email protected]> wrote:
>> >> >> >> > >
>> >> >> >> > > > > Ideally I'd like at least enough info to be able to
>> >> >> >> > > > > reconstruct
>> >> >> >> > > > > the
>> >> >> >> > > > source
>> >> >> >> > > > > file exactly from the pretty-printed C tree. And have yet
>> >> >> >> > > > > more
>> >> >> >> > > > > info
>> >> >> >> > > > > which identifies individual C statements and their parts.
>> >> >> >> > > >
>> >> >> >> > > > Would you like to perform any data processing on
>> >> >> >> > > > abstraction
>> >> >> >> > > > levels
>> >> >> >> > like
>> >> >> >> > > > the
>> >> >> >> > > > following?
>> >> >> >> > > > - control flow graph (CFG)
>> >> >> >> > > > - abstract sematic graph (ASG)
>> >> >> >> > > > - abstract syntax tree (AST)
>> >> >> >> > > >
>> >> >> >> > >
>> >> >> >> > > If there was a way to pretty print Coccinelle's abstract
>> >> >> >> > > syntax
>> >> >> >> > > tree, and
>> >> >> >> > it
>> >> >> >> > > also contained file, line, and position info, then this would
>> >> >> >> > > probably
>> >> >> >> > allow
>> >> >> >> > > me to do the type of data processing that I'm interested in.
>> >> >> >> > > Is
>> >> >> >> > > there a
>> >> >> >> > way
>> >> >> >> > > to pretty print Coccinelle's abstract syntax tree? Thanks,
>> >> >> >> > > Simon
>> >> >> >> >
>> >> >> >> > Not really. But it would seem ike you would rather not use
>> >> >> >> > Coccinelle, ie
>> >> >> >> > the SmPL language, and instead just use its parser. You could
>> >> >> >> > then
>> >> >> >> > modify
>> >> >> >> > its pretty printer to generate the information you want.
>> >> >> >> >
>> >> >> >>
>> >> >> >> Thanks. Can you please point me towards the parser and its code
>> >> >> >> and
>> >> >> >> if
>> >> >> >> it
>> >> >> >> has a limited pretty printer already, how can I invoke it?
>> >> >> >
>> >> >> > All of the C-related code is in the parsing_c subdirectory. You
>> >> >> > would
>> >> >> > want to use the code for implementing the -type_c option as a
>> >> >> > model,
>> >> >> > I
>> >> >> > think. The entry point for the -type_c option would be found in
>> >> >> > that
>> >> >> > directory as well.
>> >> >> >
>> >> >> > It may be easier to just get the yacfe parser from Yoann
>> >> >> > Padioleau.
>> >> >> > Then
>> >> >> > you wouldn't have to extract the parser from the Coccinelle source
>> >> >> > code.
>> >> >> > Unfortunately, I'm not really finding the most recent version, so
>> >> >> > perhaps
>> >> >> > Yoann will see this and let you know where it is.
>> >> >> >
>> >> >> > julia
>> >> >> > _______________________________________________
>> >> >> > Cocci mailing list
>> >> >> > [email protected]
>> >> >> > http://lists.diku.dk/mailman/listinfo/cocci
>> >> >> > (Web access from inside DIKUs LAN only)
>> >> >> >
>> >> >
>> >> >
>> >
>> >
>
>
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)