diff options
author | Michal Cmarada <mcmarada@cisco.com> | 2019-05-03 08:49:28 +0200 |
---|---|---|
committer | Michal Cmarada <mcmarada@cisco.com> | 2019-05-03 08:49:28 +0200 |
commit | 84e13a8718f480485123999539997dd22702a349 (patch) | |
tree | 301d8fb83b84b6bd9937fb09e1363cb07e407f86 /java | |
parent | 6fc28b0523978a6eca6d7d6ce12b6807bf6492c0 (diff) |
Fix enumset values for types other than u8(byte)
Usually enumsets use integer as its base type,
however to reduce memory usage in VPP less memory
consuming types can be used. This fixes enumset
generator so other types can be used (byte, short...)
Change-Id: I6c02153eecb879038f833491b0d7a4324d6ac102
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'java')
-rwxr-xr-x | java/jvpp/gen/jvppgen/enumsets_gen.py | 13 | ||||
-rwxr-xr-x | java/jvpp/gen/jvppgen/jni_type_handlers_gen.py | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/java/jvpp/gen/jvppgen/enumsets_gen.py b/java/jvpp/gen/jvppgen/enumsets_gen.py index e1f5c8d..4a04c07 100755 --- a/java/jvpp/gen/jvppgen/enumsets_gen.py +++ b/java/jvpp/gen/jvppgen/enumsets_gen.py @@ -32,7 +32,7 @@ def generate_enumsets(work_dir, model, logger): json_definition=t.doc, java_name=type_class_name, java_enum_name=type_class_name + "Options", - constants=_generate_constants(t.constants), + constants=_generate_constants(t.constants, t.value.type.java_name), value_type=t.value.type.java_name ) with open("%s/%s.java" % (work_dir, type_class_name), "w") as f: @@ -80,7 +80,7 @@ public final class $java_name { public $value_type getOptionsValue() { $value_type optionsValue = 0; for ($java_enum_name opts : options) { - optionsValue = optionsValue | opts.value; + optionsValue = ($value_type) (optionsValue | opts.value); } return optionsValue; } @@ -90,7 +90,7 @@ public final class $java_name { if (value == 0) { // if value is "0" set default value and exit - options.add($java_enum_name.forValue(0)); + options.add($java_enum_name.forValue(($value_type)0)); return; } @@ -168,8 +168,9 @@ $constants; """) -def _generate_constants(constants): - return ",\n".join(_CONSTANT_TEMPLATE.substitute(name=c['name'], value=c['value']) for c in constants) +def _generate_constants(constants, type_name): + return ",\n".join(_CONSTANT_TEMPLATE.substitute(name=c['name'], value=c['value'], + value_type=type_name) for c in constants) -_CONSTANT_TEMPLATE = Template(""" $name($value)""") +_CONSTANT_TEMPLATE = Template(""" $name(($value_type)$value)""") diff --git a/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py b/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py index d0d123a..90fc101 100755 --- a/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py +++ b/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py @@ -187,7 +187,7 @@ static inline jobject _net_to_host_${c_name}(JNIEnv * env, vl_api_${c_name}_t _n { jclass enumClass = (*env)->FindClass(env, "${class_FQN}"); jmethodID constructor = (*env)->GetMethodID(env, enumClass, "<init>", "(I)V"); - ${jni_type} value = (${jni_type}) $type_swap + ${jni_type} value = (${jni_type}) $type_swap; return (*env)->NewObject(env, enumClass, constructor, value); }""") |