Interrogate should be able to parse any constexpr as enum value, including one that references a different enum value

This commit is contained in:
rdb 2014-12-03 21:51:58 +01:00
parent ba702c9ef3
commit b3fd8b94ad
2 changed files with 26 additions and 5 deletions

View File

@ -12,11 +12,11 @@
//
////////////////////////////////////////////////////////////////////
#include "cppEnumType.h"
#include "cppTypedef.h"
#include "cppExpression.h"
#include "cppSimpleType.h"
#include "cppConstType.h"
#include "cppScope.h"
#include "cppParser.h"
#include "indent.h"
@ -29,7 +29,8 @@
CPPEnumType::
CPPEnumType(CPPIdentifier *ident, CPPScope *current_scope,
const CPPFile &file) :
CPPExtensionType(T_enum, ident, current_scope, file)
CPPExtensionType(T_enum, ident, current_scope, file),
_last_value(NULL)
{
}
@ -41,12 +42,31 @@ CPPEnumType(CPPIdentifier *ident, CPPScope *current_scope,
CPPInstance *CPPEnumType::
add_element(const string &name, CPPExpression *value) {
CPPType *type =
CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
CPPSimpleType::F_unsigned));
CPPType::new_type(new CPPConstType(new CPPSimpleType(
CPPSimpleType::T_int, CPPSimpleType::F_unsigned)));
CPPIdentifier *ident = new CPPIdentifier(name);
CPPInstance *inst = new CPPInstance(type, ident);
inst->_initializer = value;
_elements.push_back(inst);
if (value == (CPPExpression *)NULL) {
if (_last_value == (CPPExpression *)NULL) {
// This is the first value, and should therefore be 0.
static CPPExpression *const zero = new CPPExpression(0);
value = zero;
} else if (_last_value->_type == CPPExpression::T_integer) {
value = new CPPExpression(_last_value->_u._integer + 1);
} else {
// We may not be able to determine the value just yet. No
// problem; we'll just define it as another expression.
static CPPExpression *const one = new CPPExpression(1);
value = new CPPExpression('+', _last_value, one);
}
}
inst->_initializer = value;
_last_value = value;
return inst;
}

View File

@ -52,6 +52,7 @@ public:
typedef vector<CPPInstance *> Elements;
Elements _elements;
CPPExpression *_last_value;
};