CppAst.CodeGen
CppAst.CodeGen copied to clipboard
fails to generate enum value based on macro definition
When attempting to generate an enum using a macro definition the code generated does not compile.
Current
c++
/*! Macro to set a the prefix bytes of an API specific Result code. */
#define RESULT_PREFIX(val) (val << 16)
enum {
/*! Defines the prefix for global Result codes. */
ResultAPIPrefix_Global = RESULT_PREFIX(0),
};
enum {
/*! Defines the prefix for AudioResult codes. */
ResultAPIPrefix_Audio = RESULT_PREFIX(0x9e11)
};
C#
public enum __AnonymousCppEnum_api_3920AnonymousEnum : int
{
/// <summary>
/// Defines the prefix for global Result codes.
/// </summary>
ResultAPIPrefix_Global = unchecked((int)(0 16)enum{/*! Defines the prefix for global Result codes. */ResultAPIPrefix_Global=RESULT_PREFIX(0))),
}
public enum __AnonymousCppEnum_audio_8721AnonymousEnum : int
{
/// <summary>
/// Defines the prefix for AudioResult codes.
/// </summary>
ResultAPIPrefix_Audio = unchecked((int)(0x9e11 )), // Note this value should have also been computed using the macro.
}
Expected
public enum __AnonymousCppEnum_api_3920AnonymousEnum : int
{
/// <summary>
/// Defines the prefix for global Result codes.
/// </summary>
ResultAPIPrefix_Global = unchecked((int)0 << (int)16),
}
public enum __AnonymousCppEnum_audio_8721AnonymousEnum : int
{
/// <summary>
/// Defines the prefix for AudioResult codes.
/// </summary>
ResultAPIPrefix_Audio = unchecked((int)0x9e11 << (int)16),
}
I'm not entirely sure what the result of this should look like, but probably a calculated value for the enum?
It should print the characters, don't know why it is not working.
PR much welcome for the various issues, as I don't have any time left dedicated for this project these days...
PR much welcome for the various issues, as I don't have any time left dedicated for this project these days...
No worries, I understand. I will do my best, but I'm def not sure about this one in particular. The others I was planning on opening PRs if I solved them.
@xoofx this actually seems to be a problem in the CppAst project, as the cpp macro isn't properly applied to the CppEnumItem.ValueExpression
.
I'm trying to track down exactly what's going on but a bit slow going.
@xoofx where exactly are the macros applied to the expressions?
you mean this?
No, I've already fixed that in https://github.com/xoofx/CppAst.CodeGen/pull/8
I'm talking about more lower level in the CppAst model builder, where we're gathering all the enum expression values.
https://github.com/xoofx/CppAst/blob/b27338c68fae3ab189ad58573b27a7e3547f98a9/src/CppAst/CppModelBuilder.cs#L192-L205
Correct. That's where I'm currently looking.
So after stepping through each of this I was able to figure out that the clang tokenizer is returning back invalid tokens.
Seems to be fixed. Thanks!
Nope, I was mistaken, I must have updated my headers with the precomputed values