Skip to content

Commit

Permalink
Retain 'value' for property argument for all case conventions except …
Browse files Browse the repository at this point in the history
…keep
  • Loading branch information
sebaszm committed Oct 25, 2024
1 parent bc792f0 commit 5ccb76e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions JsonGenerator/source/header_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CaseConverter:
PARAMS = 2
MEMBERS = 3
ENUMS = 4
PROPERTY_PARAMS = 5

class Format(Enum):
LOWER = "lower" # lowercase
Expand All @@ -47,6 +48,8 @@ class Format(Enum):
CAMEL = "camel" # camelCase
PASCAL = "pascal" # PascalCase
KEEP = "keep" # ... keep as is
# keep has side effect that property parameter does not
# change the name to "value" but keeps original name

@staticmethod
def __to_pascal(string, uppercase=True):
Expand Down Expand Up @@ -124,14 +127,17 @@ def convention(self):
return self._convention

@property
def is_legacy(self):
return (self._convention == config.CaseConvention.LEGACY)
def is_keep(self):
return (self._convention == config.CaseConvention.KEEP)

def transform(self, input, attr):
assert input
return self.Format.transform(input, self.__format(attr))

def __format(self, attr):
if attr == self.PROPERTY_PARAMS:
attr = self.PARAMS

assert self.convention
return self._map[self.convention][attr]

Expand Down Expand Up @@ -204,13 +210,16 @@ def compute_name(obj, arg, relay=None):
if not relay:
relay = obj

_name = _case_converter.transform(relay.name, arg)
_orig_name = ("value" if ((arg == _case_converter.PROPERTY_PARAMS) and not _case_converter.is_keep) else relay.name)

_name = _case_converter.transform(_orig_name, arg)

if obj.meta.text == _name:
log.WarnLine(obj, "'%s': overriden name is same as default ('%s')" % (obj.meta.text, _name))

return (obj.meta.text if obj.meta.text else _name)


schema["@interfaceonly"] = True
schema["configuration"] = { "nodefault" : True }

Expand Down Expand Up @@ -594,7 +603,7 @@ def BuildParameters(obj, vars, rpc_format, is_property=False, test=False):
elif not var.meta.output:
log.WarnLine(var, "'%s': non-const parameter marked with @in tag (forgot 'const'?)" % var.name)

var_name = "value" if (is_property and _case_converter.is_legacy) else compute_name(var, _case_converter.PARAMS)
var_name = compute_name(var, (_case_converter.PROPERTY_PARAMS if is_property else _case_converter.PARAMS))

if var_name.startswith("__unnamed") and not test:
raise CppParseError(var, "unnamed parameter, can't deduce parameter name (*1)")
Expand Down Expand Up @@ -665,7 +674,7 @@ def BuildResult(vars, is_property=False):
var_type = ResolveTypedef(var.type)

if var.meta.output:
var_name = "value" if (is_property and _case_converter.is_legacy) else compute_name(var, _case_converter.PARAMS)
var_name = compute_name(var, (_case_converter.PROPERTY_PARAMS if is_property else _case_converter.PARAMS))

if var_name.startswith("__unnamed"):
raise CppParseError(var, "unnamed parameter, can't deduce parameter name (*2)")
Expand Down

0 comments on commit 5ccb76e

Please sign in to comment.