scilab: fix scilab_enums test: enum returned as double, and enum value computing
This commit is contained in:
parent
423192a9f0
commit
9a8b1207ca
2 changed files with 34 additions and 21 deletions
|
|
@ -370,8 +370,8 @@
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(int)) enum SWIGTYPE
|
%typemap(scilabconstcode, fragment=SWIG_CreateScilabVariable_frag(double)) enum SWIGTYPE
|
||||||
%{
|
%{
|
||||||
if (SWIG_CreateScilabVariable_int(pvApiCtx, "$result", $value) != SWIG_OK)
|
if (SWIG_CreateScilabVariable_double(pvApiCtx, "$result", $value) != SWIG_OK)
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ protected:
|
||||||
List *sourceFileList;
|
List *sourceFileList;
|
||||||
List *cflags;
|
List *cflags;
|
||||||
List *ldflags;
|
List *ldflags;
|
||||||
|
|
||||||
String *verboseBuildLevel;
|
String *verboseBuildLevel;
|
||||||
String *buildFlagsScript;
|
String *buildFlagsScript;
|
||||||
|
|
||||||
|
|
@ -579,14 +579,17 @@ public:
|
||||||
bool isEnum = (Cmp(nodeType(node), "enumitem") == 0);
|
bool isEnum = (Cmp(nodeType(node), "enumitem") == 0);
|
||||||
|
|
||||||
if (isConstant || isEnum) {
|
if (isConstant || isEnum) {
|
||||||
|
if (isEnum) {
|
||||||
|
Setattr(node, "type", "double");
|
||||||
|
constantValue = Getattr(node, "enumvalue");
|
||||||
|
}
|
||||||
|
|
||||||
constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0);
|
constantTypemap = Swig_typemap_lookup("scilabconstcode", node, nodeName, 0);
|
||||||
if (constantTypemap != NULL) {
|
if (constantTypemap != NULL) {
|
||||||
Setattr(node, "wrap:name", constantName);
|
Setattr(node, "wrap:name", constantName);
|
||||||
Replaceall(constantTypemap, "$result", constantName);
|
Replaceall(constantTypemap, "$result", constantName);
|
||||||
if (isEnum) {
|
|
||||||
constantValue = Getattr(node, "enumvalue");
|
|
||||||
}
|
|
||||||
Replaceall(constantTypemap, "$value", constantValue);
|
Replaceall(constantTypemap, "$value", constantValue);
|
||||||
|
|
||||||
emit_action_code(node, variablesCode, constantTypemap);
|
emit_action_code(node, variablesCode, constantTypemap);
|
||||||
Delete(constantTypemap);
|
Delete(constantTypemap);
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
@ -646,23 +649,33 @@ public:
|
||||||
// Compute the "absolute" value of enum if needed
|
// Compute the "absolute" value of enum if needed
|
||||||
// (most of time enum values are a linked list of relative values)
|
// (most of time enum values are a linked list of relative values)
|
||||||
String *enumValue = Getattr(node, "enumvalue");
|
String *enumValue = Getattr(node, "enumvalue");
|
||||||
if (!enumValue) {
|
String *enumValueEx = Getattr(node, "enumvalueex");
|
||||||
String *enumValueEx = Getattr(node, "enumvalueex");
|
|
||||||
if (enumValueEx) {
|
// First enum value ?
|
||||||
String *firstenumitem = Getattr(node, "firstenumitem");
|
String *firstenumitem = Getattr(node, "firstenumitem");
|
||||||
if (firstenumitem) {
|
if (firstenumitem) {
|
||||||
// First node, value is in enumValueEx
|
if (enumValue) {
|
||||||
Setattr(node, "enumvalue", enumValueEx);
|
// Value is in 'enumvalue'
|
||||||
iPreviousEnumValue = atoi(Char(enumValueEx));
|
iPreviousEnumValue = atoi(Char(enumValue));
|
||||||
}
|
}
|
||||||
else {
|
else if (enumValueEx) {
|
||||||
enumValue = NewString("");
|
// Or value is in 'enumValueEx'
|
||||||
iPreviousEnumValue = iPreviousEnumValue + 1;
|
iPreviousEnumValue = atoi(Char(enumValueEx));
|
||||||
Printf(enumValue, "%d", iPreviousEnumValue);
|
|
||||||
Setattr(node, "enumvalue", enumValue);
|
enumValue = NewString("");
|
||||||
}
|
Printf(enumValue, "%d", iPreviousEnumValue);
|
||||||
|
Setattr(node, "enumvalue", enumValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!enumValue && enumValueEx) {
|
||||||
|
// Value is not specified, set it by incrementing last value
|
||||||
|
enumValue = NewString("");
|
||||||
|
Printf(enumValue, "%d", ++iPreviousEnumValue);
|
||||||
|
Setattr(node, "enumvalue", enumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enums in Scilab are mapped to double
|
||||||
|
Setattr(node, "type", "double");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Language::enumvalueDeclaration(node);
|
return Language::enumvalueDeclaration(node);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue