Macro expansion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro expansion

Vassil Vassilev via cfe-dev
Hello All,

I have a situation to expand a macro and I have succeeded by
extracting a constant value using clang::MacroInfo
getReplacementToken(0)
But if a user gives a expression then how can we evaluate the macro value?

ex:
#define S 16
#define O 4
#define C S/O

In the above example I need the evaluate S/O expression and use the
value for my processing.
Can someone point how can we do this?

Thanks in advance.

-Nagaraju
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Macro expansion

Vassil Vassilev via cfe-dev
Hi,

Unfortunately the pre processor amounts to not much more than text
manipulation and as such it won't evaluate expressions. In your example
`C` will hold the value `16/4`. If you want to have more than that,
then you will likely need to add a pre-build step to your build
process, Similar(but very different) to TableGen.

Regards,
Nathan James

On Sun, 2020-05-31 at 15:43 +0530, Nagaraju Mekala via cfe-dev wrote:

> Hello All,
>
> I have a situation to expand a macro and I have succeeded by
> extracting a constant value using clang::MacroInfo
> getReplacementToken(0)
> But if a user gives a expression then how can we evaluate the macro
> value?
>
> ex:
> #define S 16
> #define O 4
> #define C S/O
>
> In the above example I need the evaluate S/O expression and use the
> value for my processing.
> Can someone point how can we do this?
>
> Thanks in advance.
>
> -Nagaraju
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Macro expansion

Vassil Vassilev via cfe-dev
Hi Nathan James,

Thanks for the reply.
I just want 16/4. Is there any way to get that other than using
clang::MacroInfo getReplacementToken()

Thanks,
Nagaraju

On Sun, May 31, 2020 at 4:28 PM Nathan James <[hidden email]> wrote:

>
> Hi,
>
> Unfortunately the pre processor amounts to not much more than text
> manipulation and as such it won't evaluate expressions. In your example
> `C` will hold the value `16/4`. If you want to have more than that,
> then you will likely need to add a pre-build step to your build
> process, Similar(but very different) to TableGen.
>
> Regards,
> Nathan James
>
> On Sun, 2020-05-31 at 15:43 +0530, Nagaraju Mekala via cfe-dev wrote:
> > Hello All,
> >
> > I have a situation to expand a macro and I have succeeded by
> > extracting a constant value using clang::MacroInfo
> > getReplacementToken(0)
> > But if a user gives a expression then how can we evaluate the macro
> > value?
> >
> > ex:
> > #define S 16
> > #define O 4
> > #define C S/O
> >
> > In the above example I need the evaluate S/O expression and use the
> > value for my processing.
> > Can someone point how can we do this?
> >
> > Thanks in advance.
> >
> > -Nagaraju
> > _______________________________________________
> > cfe-dev mailing list
> > [hidden email]
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev