From f6cd6881cd93e853502f183de8054e54ac008148 Mon Sep 17 00:00:00 2001 From: RobertoRoos Date: Fri, 14 Feb 2025 10:17:55 +0100 Subject: [PATCH] Added merge of multiple sections in a GVL --- examples/docs/plc.rst | 10 ++++++++++ src/plcdoc/interpreter.py | 9 ++++++++- tests/roots/test-plc-autodoc/src_plc/AutoGVL.TcGVL | 12 ++++++++++++ tests/test_plc_autodoc.py | 3 +++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/examples/docs/plc.rst b/examples/docs/plc.rst index 53404af..b6d6e3f 100644 --- a/examples/docs/plc.rst +++ b/examples/docs/plc.rst @@ -108,3 +108,13 @@ Manually Typed PLC Structs .. plc:member:: \ FaceUp FaceDown + + +Manually Typed PLC GVLs +======================= + +.. plc:gvl:: GVL_MyGVL + + Global variable list with, well, global variables. + + :var UDINT tickInterval_us: PLC tick interval diff --git a/src/plcdoc/interpreter.py b/src/plcdoc/interpreter.py index 87b9fc4..8008680 100644 --- a/src/plcdoc/interpreter.py +++ b/src/plcdoc/interpreter.py @@ -307,7 +307,8 @@ def __init__(self, meta_model: TextXMetaClass, file=None): # GVL are annoying because no naming is present in source - we need to # extract it from the file name - self._model = meta_model.variable_lists[0] + self._model = meta_model + # ^ A GVL can contain multiple lists, store them all self._objtype = "gvl" if self._objtype is None: @@ -412,6 +413,12 @@ def get_args(self, skip_internal=True) -> List: var.kind = "var" args.append(var) + if hasattr(self._model, "variable_lists"): + for var_list in self._model.variable_lists: + for var in var_list.variables: + var.kind = "var" + args.append(var) + return args def add_child(self, child: "PlcDeclaration"): diff --git a/tests/roots/test-plc-autodoc/src_plc/AutoGVL.TcGVL b/tests/roots/test-plc-autodoc/src_plc/AutoGVL.TcGVL index 0111291..dcccbb6 100644 --- a/tests/roots/test-plc-autodoc/src_plc/AutoGVL.TcGVL +++ b/tests/roots/test-plc-autodoc/src_plc/AutoGVL.TcGVL @@ -7,6 +7,18 @@ VAR_GLOBAL counter : ULINT; cycleTime : LREAL := 0.001; // Time between PLC cycles END_VAR + +VAR_GLOBAL + otherSection : BOOL; +END_VAR + +VAR_GLOBAL CONSTANT + MY_CONST : INT := 420; +END_VAR + +VAR_GLOBAL PERSISTENT + runtime_sec : UDINT; +END_VAR ]]> \ No newline at end of file diff --git a/tests/test_plc_autodoc.py b/tests/test_plc_autodoc.py index 5d92aa7..73e5bec 100644 --- a/tests/test_plc_autodoc.py +++ b/tests/test_plc_autodoc.py @@ -156,3 +156,6 @@ def test_autodoc_gvl(app, status, warning): assert " :var BOOL flag: Flag for the system" == actual[4] assert " :var ULINT counter:" == actual[5] assert " :var LREAL cycleTime: Time between PLC cycles" == actual[6] + assert " :var BOOL otherSection:" == actual[7] + assert " :var INT MY_CONST:" == actual[8] + assert " :var UDINT runtime_sec:" == actual[9]