[aspectc-user] Replace CPP-Makro with the Puma-Manipulator in the scanning phase
Olaf Spinczyk
os at aspectc.org
Mon Mar 24 19:36:55 CET 2014
Hello Stefan!
It seems to me that you are using the ManipCommander is the wrong way. The idea
of it is that you perform many code manipulations with kill, copy, move,
replace, etc. and call commit() once when you're done. As a consequence the
pointers between the token objects remain unmodified while you iterate over your
program text/syntax tree.
In cases where you need to create new tokens, you create a new CUnit object on
the heap (with new and not locally) and register it at the ManipCommander with
addBuffer() for cleanup after commit().
I don't know if this is really the problem in your concrete case, but you asked
for "wrong use". It might help to rewrite the code.
Best regards,
Olaf Spinczyk
On 03/24/2014 05:44 PM, Stefan Hengelein wrote:
> Hello there,
>
> we're using the Puma-Tool for parsing .c files within our Project (
> https://www4.cs.fau.de/Research/VAMOS/ ) at the University in
> Erlangen.
>
> I've now encountered a problem and i'm not quite sure what i did wrong
> and if i did something wrong when using Puma.
>
> what i want to do:
>
> Replace
> #if IS_ENABLED(CONFIG_FOO)
> with
> #if (defined(CONFIG_FOO) || defined(CONFIG_FOO_MODULE))
>
> we thought, the easiest way to implement the replacement would be
> after the scanning phase.
>
> how i implemented it:
>
> Puma::ManipCommander mc;
> Puma::Token *s, *e, *prev;
> [...]
> if (!strcmp(s->text(), "IS_ENABLED")) {
> prev = unit->prev(unit->prev(s));
>
> Puma::Token *symbol = unit->next(unit->next(s));
> e = unit->next(symbol);
>
> std::string modsymboltext(symbol->text());
> modsymboltext += "_MODULE";
> Puma::Token *modsymbol = new
> Puma::Token(Puma::TOK_ID, Puma::Token::pre_id, modsymboltext.c_str());
>
> Puma::ErrorStream err;
> Puma::CUnit enabled(err);
>
> enabled << "(defined(" << *symbol << ") ||
> defined(" << *modsymbol << "))" << Puma::endu;
> mc.replace(s, e, enabled.first(), enabled.last());
> mc.commit();
>
> s = prev ? prev : unit->first();
> }
>
> s is the pointer to iterate over the Puma::Token s in the Puma::Unit
> e points to the Token containing the closing brace of "IS_ENABLED(CONFIG_FOO)"
>
> when i run "print_tokens(unit)" after the transformation, the code i
> get is the code i wanted to have, but after parsing there is something
> wrong with the token structure, i guess. At least i don't get the
> right text after the "#if"s when i use the CPP-Syntax tree, to be
> clear, it is empty. But just the part i inserted is missing,
> everything after that directive seems to be there.
>
> Did i use the ManipCommander wrong or do you have a clue what could
> have gone wrong?
>
> Thanks in advance,
> Stefan
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at aspectc.org
> http://www.aspectc.org/mailman/listinfo/aspectc-user
>
More information about the aspectc-user
mailing list