I\'m generating C++ code, and it seems like it\'s going to get very messy, even my simple generating classes already have tons of special cases. Here is the code as it stan
I agree with S.Lott, that you should write out an example of what you want to generate.
Solving a problem with code generation should be less complicated than without.
This is because your total program has to deal with a lot of input information, and if a subset of that information changes very seldom, like once a week, the code generator only has to condition on that subset. The generated code conditions on the remaining input that changes more frequently. It's a divide-and-conquer strategy. Another name for it is "partial evaluation".
Generated code should also run a lot faster because it's less general.
In your specific case, there's no harm in doing the code generation in 2 (or more) passes. Like on pass 1 you generate declarations. On pass 2 you generate process code. Alternatively you could generate two output streams, and concatenate them at the end.
Hope that helps. Sorry if I'm just saying what's obvious.