mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Interrogate should be able to parse any constexpr as enum value, including one that references a different enum value
This commit is contained in:
parent
ba702c9ef3
commit
b3fd8b94ad
@ -12,11 +12,11 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#include "cppEnumType.h"
|
#include "cppEnumType.h"
|
||||||
#include "cppTypedef.h"
|
#include "cppTypedef.h"
|
||||||
#include "cppExpression.h"
|
#include "cppExpression.h"
|
||||||
#include "cppSimpleType.h"
|
#include "cppSimpleType.h"
|
||||||
|
#include "cppConstType.h"
|
||||||
#include "cppScope.h"
|
#include "cppScope.h"
|
||||||
#include "cppParser.h"
|
#include "cppParser.h"
|
||||||
#include "indent.h"
|
#include "indent.h"
|
||||||
@ -29,7 +29,8 @@
|
|||||||
CPPEnumType::
|
CPPEnumType::
|
||||||
CPPEnumType(CPPIdentifier *ident, CPPScope *current_scope,
|
CPPEnumType(CPPIdentifier *ident, CPPScope *current_scope,
|
||||||
const CPPFile &file) :
|
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::
|
CPPInstance *CPPEnumType::
|
||||||
add_element(const string &name, CPPExpression *value) {
|
add_element(const string &name, CPPExpression *value) {
|
||||||
CPPType *type =
|
CPPType *type =
|
||||||
CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
|
CPPType::new_type(new CPPConstType(new CPPSimpleType(
|
||||||
CPPSimpleType::F_unsigned));
|
CPPSimpleType::T_int, CPPSimpleType::F_unsigned)));
|
||||||
|
|
||||||
CPPIdentifier *ident = new CPPIdentifier(name);
|
CPPIdentifier *ident = new CPPIdentifier(name);
|
||||||
CPPInstance *inst = new CPPInstance(type, ident);
|
CPPInstance *inst = new CPPInstance(type, ident);
|
||||||
inst->_initializer = value;
|
|
||||||
_elements.push_back(inst);
|
_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;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
typedef vector<CPPInstance *> Elements;
|
typedef vector<CPPInstance *> Elements;
|
||||||
Elements _elements;
|
Elements _elements;
|
||||||
|
CPPExpression *_last_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user