Skip to content

How to add a prefix to function names ? #537

@mingodad

Description

@mingodad

I'm looking for a way to add a prefix to function names and then pretty print it -ast-print but I'm not sure how to do it, at first it seems that I would use ASTRewriter to do it, I would expect that I'll only need to change the FunctionDefinitionAST::declarator and then everywhere it's used will have the prefix.

#include <stdio.h>
#include <stdlib.h>

int i1(int n);

int i1(int n)
{
    if (n < 2) return 1;
    return i1(n-2) + i1(n-1);
}

int main(int argc, char **argv)
{
    int xt = 32;
    if(argc > 1)
    {
	xt = atoi(argv[1]);
    }
    int result = i1(xt);
    printf("Result of %d = %d\n", xt, result);
    return 0;
}

I would like to add a prefix fn_ to function names and have this output:

...
int fn_i1(int n);

int fn_i1(int n)
{
    if (n < 2) return 1;
    return fn_i1(n-2) + fn_i1(n-1);
}

int main(int argc, char **argv)
{
    int xt = 32;
    if(argc > 1)
    {
	xt = atoi(argv[1]);
    }
    int result = fn_i1(xt);
    printf("Result of %d = %d\n", xt, result);
    return 0;
}

How could I achieve it ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions