From fa2e82becde527ff86d237a97fc43778822d57c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Mon, 16 Aug 2021 15:29:42 -0700 Subject: [PATCH] edtlib: emit pinctrl names as tokens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be necessary to going back and forth between indexes and names in C. Signed-off-by: Martí Bolívar --- .../python-devicetree/src/devicetree/edtlib.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/dts/python-devicetree/src/devicetree/edtlib.py b/scripts/dts/python-devicetree/src/devicetree/edtlib.py index 0abeb6fa804..905ebaad28d 100644 --- a/scripts/dts/python-devicetree/src/devicetree/edtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/edtlib.py @@ -1381,12 +1381,21 @@ class PinCtrl: The name of the configuration, as given in pinctrl-names, or None if there is no pinctrl-names property + name_as_token: + Like 'name', but with non-alphanumeric characters converted to underscores. + conf_nodes: A list of Node instances for the pin configuration nodes, e.g. the nodes pointed at by &state_1 and &state_2 in pinctrl-0 = <&state_1 &state_2>; """ + + @property + def name_as_token(self): + "See the class docstring" + return _val_as_token(self.name) if self.name is not None else None + def __repr__(self): fields = [] @@ -1478,7 +1487,7 @@ class Property: @property def val_as_token(self): "See the class docstring" - return re.sub(_NOT_ALPHANUM_OR_UNDERSCORE, '_', self.val) + return _val_as_token(self.val) @property def enum_index(self): @@ -2746,6 +2755,11 @@ _LOG = logging.getLogger(__name__) # Regular expression for non-alphanumeric-or-underscore characters. _NOT_ALPHANUM_OR_UNDERSCORE = re.compile(r'\W', re.ASCII) + +def _val_as_token(val): + return re.sub(_NOT_ALPHANUM_OR_UNDERSCORE, '_', val) + + # Custom PyYAML binding loader class to avoid modifying yaml.Loader directly, # which could interfere with YAML loading in clients class _BindingLoader(Loader):