• Advertisement
Sign in to follow this  

I need a better precompiler for C++

This topic is 2098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to use a code generator as a custom precompiler for Visual Studio so that I don't have to copy and paste the result from an external code generator?
I want my macro to be a real function with loops, type safety and complex datatypes that returns a string of IDL or C++ code directly to the compiler.
With the standard C precompiler, I have to type the number of arguments in the name and write 26 versions of each macro to handle overloading.

Example of bloated precompiler code for the Interface Definition Language

#define SUBMACRO_DISPATCHMAP_0(DISPID,OT,FNAME) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_Void)
#define SUBMACRO_DISPATCHMAP_1(DISPID,OT,FNAME,AN1,AT1) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1)
#define SUBMACRO_DISPATCHMAP_2(DISPID,OT,FNAME,AN1,AT1,AN2,AT2) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2)
#define SUBMACRO_DISPATCHMAP_3(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3)
#define SUBMACRO_DISPATCHMAP_4(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4)
#define SUBMACRO_DISPATCHMAP_5(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5)
#define SUBMACRO_DISPATCHMAP_6(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6)
#define SUBMACRO_DISPATCHMAP_7(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7)
#define SUBMACRO_DISPATCHMAP_8(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8)
#define SUBMACRO_DISPATCHMAP_9(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9)
#define SUBMACRO_DISPATCHMAP_10(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10)
#define SUBMACRO_DISPATCHMAP_11(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11)
#define SUBMACRO_DISPATCHMAP_12(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12)
#define SUBMACRO_DISPATCHMAP_13(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13)
#define SUBMACRO_DISPATCHMAP_14(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14)
#define SUBMACRO_DISPATCHMAP_15(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15)
#define SUBMACRO_DISPATCHMAP_16(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16)
#define SUBMACRO_DISPATCHMAP_17(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17)
#define SUBMACRO_DISPATCHMAP_18(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18)
#define SUBMACRO_DISPATCHMAP_19(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19)
#define SUBMACRO_DISPATCHMAP_20(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20)
#define SUBMACRO_DISPATCHMAP_21(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20,AN21,AT21) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20 In_##AT21)
#define SUBMACRO_DISPATCHMAP_22(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20,AN21,AT21,AN22,AT22) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20 In_##AT21 In_##AT22)
#define SUBMACRO_DISPATCHMAP_23(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20,AN21,AT21,AN22,AT22,AN23,AT23) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20 In_##AT21 In_##AT22 In_##AT23)
#define SUBMACRO_DISPATCHMAP_24(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20,AN21,AT21,AN22,AT22,AN23,AT23,AN24,AT24) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20 In_##AT21 In_##AT22 In_##AT23 In_##AT24)
#define SUBMACRO_DISPATCHMAP_25(DISPID,OT,FNAME,AN1,AT1,AN2,AT2,AN3,AT3,AN4,AT4,AN5,AT5,AN6,AT6,AN7,AT7,AN8,AT8,AN9,AT9,AN10,AT10,AN11,AT11,AN12,AT12,AN13,AT13,AN14,AT14,AN15,AT15,AN16,AT16,AN17,AT17,AN18,AT18,AN19,AT19,AN20,AT20,AN21,AT21,AN22,AT22,AN23,AT23,AN24,AT24,AN25,AT25) \
DISP_FUNCTION_ID(CCtrl, #FNAME, DISPID, FNAME, Out_##OT, In_##AT1 In_##AT2 In_##AT3 In_##AT4 In_##AT5 In_##AT6 In_##AT7 In_##AT8 In_##AT9 In_##AT10 In_##AT11 In_##AT12 In_##AT13 In_##AT14 In_##AT15 In_##AT16 In_##AT17 In_##AT18 In_##AT19 In_##AT20 In_##AT21 In_##AT22 In_##AT23 In_##AT24 In_##AT25)
Edited by Dawoodoz

Share this post


Link to post
Share on other sites
Advertisement
>> [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]I want my macro to be a real function with loops, type safety and complex datatypes ... [/background]

[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]26 versions of each macro[/background]

[/font]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]For the love of all that is holy, don't abuse macros like that if you value your sanity.[/background]

[/font]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Learn to use templates to handle arbitrary data types. Templates have type safety. Use an array to pass all those values to a constructor. Templates are much easier to debug and use than macros. Break your work up into smaller functions that you can easily edit and debug. [/background]

[/font]

Share this post


Link to post
Share on other sites
Instead of copy-pasting, can't you use pre-build events or custom build events to achieve whatever you are trying to do here? I mean, you can setup VS to take a .y file and generate a .c file (using Bison) and then compile it using the C/C++ compiler.

Share this post


Link to post
Share on other sites

Whoa there... let's take a step back.

What exactly are you trying to do here?


I am making an MFC ActiveX component in Visual C++ 2005.
I am generating function declarations for IDL, a header and C++ at the same time and if any copy is different from the other, it will not work.

Share this post


Link to post
Share on other sites

Instead of copy-pasting, can't you use pre-build events or custom build events to achieve whatever you are trying to do here? I mean, you can setup VS to take a .y file and generate a .c file (using Bison) and then compile it using the C/C++ compiler.


Thanks, that might solve it.

Share this post


Link to post
Share on other sites

>>

[background=rgb(250, 251, 252)]I want my macro to be a real function with loops, type safety and complex datatypes ... [/background]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]26 versions of each macro[/background][/font]



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]For the love of all that is holy, don't abuse macros like that if you value your sanity.[/background][/font]



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Learn to use templates to handle arbitrary data types. Templates have type safety. Use an array to pass all those values to a constructor. Templates are much easier to debug and use than macros. Break your work up into smaller functions that you can easily edit and debug. [/background][/font]





I am generating the ActiveX interface definitions that was made for small graphical components but now I have about 500 methods to forward declare in 3 different ways.
I have no sanity left since the macro that is calling these macros concatunate the macro names before calling them. :D

Share this post


Link to post
Share on other sites
Try Boost.Preprocessor:
http://www.boost.org/libs/preprocessor
http://www.boostpro.com/mplbook/preprocessor.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement