[aspectc-user] Replace CPP-Makro with the Puma-Manipulator in the scanning phase

Stefan Hengelein stefan.hengelein at fau.de
Mon Mar 24 17:44:33 CET 2014

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

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:

#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());

                    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,

More information about the aspectc-user mailing list