From 85cedd3fdb1de746c23805f2347b394546a27219 Mon Sep 17 00:00:00 2001 From: Jenny Cao Date: Wed, 1 May 2024 10:32:19 -0400 Subject: [PATCH 01/63] Update readme for yang adms and non-ION DTNMA C agent --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e36505c..cb0083f 100644 --- a/README.md +++ b/README.md @@ -38,23 +38,22 @@ It is part of the larger Asynchronous Network Managment System (ANMS) managed fo `'(_ )_)(_)_)' -This tool uses the JSON representation of an Application Data Model (ADM) to +This tool uses the YANG representation of an Application Data Model (ADM) to generate code for various purposes. CAmp generates: -- C code for usage in NASA ION (Interplanetary Overlay Network) +- C code for usage in a C-implemented DTNMA agent - This generation can also carry over custom functions in existing C files for the ADM, if indicated appropriately in the existing code (see the Round-tripping Section). -- SQL code, also for usage in NASA ION +- SQL code for usage by the ANMS manager - ACE input files, for usage with the ARI CBOR Encoder (ACE) Tool -Additional generators may be added to account for use cases outside of ION/ACE. Please contact the developers for more information or suggestions. The Architecture Section also provides some explanation of the components of CAmp, and how to incorporate additional generators. **NOTE** -CAmp largely assumes that the ADM JSON input can be trusted (i.e., CAmp does not +CAmp largely assumes that the ADM YANG input can be trusted (i.e., CAmp does not go to great lengths to fully sanitize all strings found within the ADM). CAmp does properly escape necessary sequences found in the ADMs tested during development (e.g., apostrophes in object descriptions). @@ -79,17 +78,18 @@ pip3 install . ### Basic Usage -The camp tool takes a JSON representation of an ADM for a network protocol as +The camp tool takes a YANG representation of an ADM for a network protocol as input and calls each of the included generators to generate files for the ADM. -> The included `template.json` provides an example of how a JSON ADM should be -> formatted. For more information on this data model, please consult the AMA -> Application Data Model IETF draft. + +>For information on how to format a YANG ADM, please consult the Application Management Model IETF draft. -Given the JSON representation of the ADM, run camp with: +Given the YANG representation of the ADM, run camp with: ``` - camp + camp ``` ### Name Registry @@ -170,7 +170,7 @@ and will create the directories listed above within . Custom Code and Round-tripping ------------------------------ -The `adm__impl.c` and `adm__impl.h` files generated for NASA ION +The `adm__impl.c` and `adm__impl.h` files generated for the DTNMA agent contain functions whose bodies cannot be automatically generated with knowledge of the ADM alone. When generated, these fuctions are marked with tags similar to the following: @@ -230,11 +230,11 @@ copied over to the correct area of the new file. - create_agent.py - Generates agent file (C code) for usage in NASA ION - create_gen_h.py - Generates the shared header file needed for NASA ION - create_impl_c.py - Generates the implementation file (C code) for usage in - NASA ION + DTNMA C agent - create_impl_h.py - Generates the header file for the implementation file created by create_impl_c.py - - create_mgr_c.py - Generates the manager file for usage in NASA ION - - create_mysql.py - Generates an SQL file for usage with NASA ION stored + - create_mgr_c.py - Generates the manager file for usage in DTNMA C agent + - create_mysql.py - Generates an SQL file for usage with DTNMA C agent stored procedures - lib/ - Library functions for generating commonly-used patterns and accessing portions of the ADM. From d90b6740fd3498915135e41f908c5b6ec0a0cf9a Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 13 Aug 2024 11:13:04 -0400 Subject: [PATCH 02/63] change AdmFile to AdmModule --- src/camp/generators/lib/campch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 7c0aa58..87c3f0a 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -653,7 +653,7 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): # # Writes the init function to c_file # -def write_init_function(c_file, adm: ace.models.AdmFile, g_var_idx: str, mgr: bool): +def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: bool): enum_name = cu.make_enum_name_from_str(adm.norm_namespace) vdb_adds = "\tadm_add_adm_info(\"" + adm.norm_namespace + "\", " + enum_name + ");\n" From 87b0006197c6ad767c923ab76de5e539a04b1080 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 13 Aug 2024 11:16:05 -0400 Subject: [PATCH 03/63] use most up-to-date ace branch in CI --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 11cd519..e1cae13 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -24,7 +24,7 @@ name: Build and run tests on: [push] env: - ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@aa879be" + ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git" jobs: build: From 496d9fd22d180ec98cb7a4b79b1972edfafed7a7 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 13 Aug 2024 11:24:40 -0400 Subject: [PATCH 04/63] change Mdat to MetadataItem --- src/camp/generators/create_sql.py | 10 +++++----- src/camp/tools/camp.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index db55bd1..6396e49 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -345,11 +345,11 @@ def val_or_none(obj, attr='value'): return '' return getattr(obj, attr) - name = val_or_none(self.admset.get_child(self.adm, models.Mdat, 'name')) - ns = val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace')) - version = val_or_none(self.admset.get_child(self.adm, models.Mdat, 'version')) - org = val_or_none(self.admset.get_child(self.adm, models.Mdat, 'organization')) - desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) + name = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'name')) + ns = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'namespace')) + version = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'version')) + org = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'organization')) + desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) diff --git a/src/camp/tools/camp.py b/src/camp/tools/camp.py index c4b4d5d..b3f7b9d 100644 --- a/src/camp/tools/camp.py +++ b/src/camp/tools/camp.py @@ -123,7 +123,7 @@ def run(args: argparse.Namespace): return 2 for mdat in ('name', 'namespace', 'enum'): - if admset.get_child(adm, ace.models.Mdat, mdat) is None: + if admset.get_child(adm, ace.models.MetadataItem, mdat) is None: LOGGER.error('The ADM is missing an "%s" metadata item', mdat) return 2 From a69e7fdc628b696961e531be281fd84054ff4cc8 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 13 Aug 2024 11:36:42 -0400 Subject: [PATCH 05/63] try AdmObjMixin instead --- src/camp/generators/create_sql.py | 10 +++++----- src/camp/tools/camp.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 6396e49..39ea786 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -345,11 +345,11 @@ def val_or_none(obj, attr='value'): return '' return getattr(obj, attr) - name = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'name')) - ns = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'namespace')) - version = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'version')) - org = val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'organization')) - desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.MetadataItem, 'namespace'), 'description')) + name = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'name')) + ns = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'namespace')) + version = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'version')) + org = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'organization')) + desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) diff --git a/src/camp/tools/camp.py b/src/camp/tools/camp.py index b3f7b9d..23acfcc 100644 --- a/src/camp/tools/camp.py +++ b/src/camp/tools/camp.py @@ -123,7 +123,7 @@ def run(args: argparse.Namespace): return 2 for mdat in ('name', 'namespace', 'enum'): - if admset.get_child(adm, ace.models.MetadataItem, mdat) is None: + if admset.get_child(adm, ace.models.AdmObjMixin, mdat) is None: LOGGER.error('The ADM is missing an "%s" metadata item', mdat) return 2 From 9ed099ad72b652c7f0f338733addb3f906843766 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 12:47:50 -0400 Subject: [PATCH 06/63] fix Mdat => Ident --- src/camp/generators/create_sql.py | 10 +++++----- src/camp/tools/camp.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 39ea786..7f4b11e 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -345,11 +345,11 @@ def val_or_none(obj, attr='value'): return '' return getattr(obj, attr) - name = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'name')) - ns = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'namespace')) - version = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'version')) - org = val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'organization')) - desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.AdmObjMixin, 'namespace'), 'description')) + name = val_or_none(self.admset.get_child(self.adm, models.Ident, 'name')) + ns = val_or_none(self.admset.get_child(self.adm, models.Ident, 'namespace')) + version = val_or_none(self.admset.get_child(self.adm, models.Ident, 'version')) + org = val_or_none(self.admset.get_child(self.adm, models.Ident, 'organization')) + desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.Ident, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) diff --git a/src/camp/tools/camp.py b/src/camp/tools/camp.py index 23acfcc..13daebe 100644 --- a/src/camp/tools/camp.py +++ b/src/camp/tools/camp.py @@ -123,7 +123,7 @@ def run(args: argparse.Namespace): return 2 for mdat in ('name', 'namespace', 'enum'): - if admset.get_child(adm, ace.models.AdmObjMixin, mdat) is None: + if admset.get_child(adm, ace.models.Ident, mdat) is None: LOGGER.error('The ADM is missing an "%s" metadata item', mdat) return 2 From b90cbfeb4de0ad6ddff551cf1c77b7a14ec287f1 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 12:48:03 -0400 Subject: [PATCH 07/63] use other branch for ace test env --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index e1cae13..3f78e9c 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -24,7 +24,7 @@ name: Build and run tests on: [push] env: - ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git" + ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@haining-ace-yang-updates" jobs: build: From a6fce0ed3f0dbb1b458e63bc601c92f7fe579390 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 12:56:14 -0400 Subject: [PATCH 08/63] update tests to use yang files instead of json --- tests/integration_test/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_test/util.py b/tests/integration_test/util.py index c935e70..dae902e 100644 --- a/tests/integration_test/util.py +++ b/tests/integration_test/util.py @@ -22,7 +22,7 @@ def _good_file(name: str) -> bool: return False _, ext = os.path.splitext(name) - return ext == ".json" and not name == "index.json" + return ext == ".yang" def adm_files() -> Tuple[str]: ''' Get a list of available ADMs from the test directory. From cb9ed6437e29ae6db7969282d27e7e4bf784c430 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 12:57:13 -0400 Subject: [PATCH 09/63] extract adms repo into env var --- .github/workflows/build-test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 3f78e9c..0cab09d 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -25,6 +25,7 @@ on: [push] env: ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@haining-ace-yang-updates" + ADMS_REPO: "https://github.com/JHUAPL-DTNMA/dtnma-adms.git" jobs: build: @@ -135,7 +136,7 @@ jobs: run: | pip3 install ${ACE_REPO} pip install -e '.[test]' - git clone https://github.com/JHUAPL-DTNMA/dtnma-adms.git tests/integration_test/anms-adms + git clone ${ADMS_REPO} tests/integration_test/anms-adms - name: Test run: python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py @@ -161,7 +162,7 @@ jobs: pip3 install -e '.[test]' - name: Prep repos run: | - git clone https://github.com/JHUAPL-DTNMA/dtnma-adms.git tests/integration_test/anms-adms + git clone ${ADMS_REPO} tests/integration_test/anms-adms git clone https://github.com/JHUAPL-DTNMA/dtnma-tools.git tests/integration_test/dtnma-tools sudo apt-get update sudo apt-get install -y cmake ninja-build ruby build-essential autoconf libtool civetweb libcivetweb-dev libssl-dev libcjson-dev From b7d2dd46901a923d3a03a849df04a1353cd26c80 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 16:30:14 -0400 Subject: [PATCH 10/63] change the minimum required metadata --- src/camp/tools/camp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/camp/tools/camp.py b/src/camp/tools/camp.py index 13daebe..2caf657 100644 --- a/src/camp/tools/camp.py +++ b/src/camp/tools/camp.py @@ -122,8 +122,8 @@ def run(args: argparse.Namespace): LOGGER.error("Loading error: %s", e) return 2 - for mdat in ('name', 'namespace', 'enum'): - if admset.get_child(adm, ace.models.Ident, mdat) is None: + for mdat in ('name', 'enum', 'latest_revision'): + if getattr(adm, mdat) is None: LOGGER.error('The ADM is missing an "%s" metadata item', mdat) return 2 From ce1e4f74aba06f1db6d43f66f2be370cc6b42236 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 17:03:17 -0400 Subject: [PATCH 11/63] remove unnecessary check --- src/camp/tools/camp.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/camp/tools/camp.py b/src/camp/tools/camp.py index 2caf657..357042d 100644 --- a/src/camp/tools/camp.py +++ b/src/camp/tools/camp.py @@ -122,11 +122,6 @@ def run(args: argparse.Namespace): LOGGER.error("Loading error: %s", e) return 2 - for mdat in ('name', 'enum', 'latest_revision'): - if getattr(adm, mdat) is None: - LOGGER.error('The ADM is missing an "%s" metadata item', mdat) - return 2 - # Call each generator to generate files for the JSON ADM LOGGER.info("Generating files under %s", args.out) generators = [] From c1fefbe4f19591be5735c72edd2bfb4bd80ec471 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 17:25:44 -0400 Subject: [PATCH 12/63] change namespaces to name --- src/camp/generators/create_agent_c.py | 22 ++++++------ src/camp/generators/create_gen_h.py | 48 +++++++++++++-------------- src/camp/generators/create_impl_c.py | 4 +-- src/camp/generators/create_impl_h.py | 4 +-- src/camp/generators/create_mgr_c.py | 26 +++++++-------- src/camp/generators/lib/campch.py | 48 +++++++++++++-------------- 6 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index 5e9c6f8..969847e 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -36,7 +36,7 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = "g_" + self.adm.norm_namespace.lower() + "_idx" + self._g_var_idx = "g_" + self.adm.norm_name.lower() + "_idx" def file_path(self) -> str: # Interface for AbstractWriter @@ -129,11 +129,11 @@ def write_init_metadata_function(self, outfile): for obj in self.adm.mdat: _,fname,_ = campch.make_meta_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_namespace, cs.META, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) body += add_str_template.format("0", ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.META, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.META, body) # # Constructs and writes the init_constants function @@ -148,7 +148,7 @@ def write_init_constant_function(self, outfile): for obj in self.adm.const: parms_tf = "0" _,fname,_ = campch.make_constant_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_namespace, cs.CONST, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) #FIXME: can const have parameters? # if obj.parmspec: @@ -156,7 +156,7 @@ def write_init_constant_function(self, outfile): body += add_str.format(parms_tf, ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.CONST, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CONST, body) # # Constructs and writes the init_edd function @@ -171,14 +171,14 @@ def write_init_edd_function(self, outfile): for obj in self.adm.edd: parms_tf = "0" _,fname,_ = campch.make_collect_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_namespace, cs.EDD, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) if obj.parmspec and obj.parmspec.items: parms_tf = "1" body += add_str.format(parms_tf, ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.EDD, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.EDD, body) # @@ -193,12 +193,12 @@ def write_init_op_function(self, outfile): adm_add_op_template = "\n\tadm_add_"+cs.get_sname(cs.OP)+"(" + self._g_var_idx + "["+cs.get_adm_idx(cs.OP)+"], {0}, {1}, {2});" for obj in self.adm.oper: - ari = cu.make_ari_name(self.adm.norm_namespace, cs.OP, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) in_types = obj.in_type if obj.in_type else [] body += adm_add_op_template.format(ari, len(in_types), ari.lower()) - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.OP, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.OP, body) # # Writes the init_variables body @@ -220,11 +220,11 @@ def write_init_control_function(self, outfile): adm_add_template = "\n\tadm_add_ctrldef(" + self._g_var_idx + "["+cs.get_adm_idx(cs.CTRL)+"], {0}, {1}, {2});" for obj in self.adm.ctrl: - ari = cu.make_ari_name(self.adm.norm_namespace, cs.CTRL, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) parms = obj.parmspec.items if obj.parmspec else [] body += adm_add_template.format(ari, len(parms), ari.lower()) - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.CTRL, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) # # Constructs and writes the init_macros function diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index a6a0be8..bad5fed 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -74,7 +74,7 @@ def write(self, outfile: TextIO): # def write_defines(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = self.adm.norm_namespace.upper() + ns_upper = self.adm.norm_name.upper() defines_str = """\ #ifndef ADM_{0}_H_ @@ -91,7 +91,7 @@ def write_defines(self, outfile): # def write_endifs(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = self.adm.norm_namespace.replace("/", "_").upper() + ns_upper = self.adm.norm_name.replace("/", "_").upper() endifs_str = """\ #endif /* _HAVE_{1}_ADM_ */ @@ -121,9 +121,9 @@ def write_adm_template_documentation(self, outfile): * ADM ROOT STRING:{} */ """ - outfile.write(documentation_str.format(header_str, self.adm.norm_namespace)) + outfile.write(documentation_str.format(header_str, self.adm.norm_name)) - g_var_idx = "g_" + self.adm.norm_namespace.replace("/", "_").lower() + "_idx" + g_var_idx = "g_" + self.adm.norm_name.replace("/", "_").lower() + "_idx" outfile.write("extern vec_idx_t {}[11];\n".format(g_var_idx)) # @@ -133,7 +133,7 @@ def write_agent_nickname_definitions(self, outfile): header_str = campch.make_formatted_comment_header("AGENT NICKNAME DEFINITIONS", True, True) outfile.write(header_str) - ns = self.adm.norm_namespace.lower() + ns = self.adm.norm_name.lower() enum_name = cu.make_enum_name_from_str(ns) outfile.write("#define {0} {1}\n".format(enum_name, self.adm.enum)) @@ -290,7 +290,7 @@ def write_metadata_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.mdat: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.META, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.META, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, obj.value) @@ -298,7 +298,7 @@ def write_metadata_definitions(self, outfile): defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" META-DATA DEFINITIONS", True) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" META-DATA DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -315,13 +315,13 @@ def write_edd_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.edd: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.EDD, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" EXTERNALLY DEFINED DATA DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" EXTERNALLY DEFINED DATA DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -338,13 +338,13 @@ def write_variable_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.var: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.VAR, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.VAR, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" VARIABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" VARIABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -361,13 +361,13 @@ def write_rptt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.rptt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.RPTT, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.RPTT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "TNVC", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" REPORT DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" REPORT DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -384,13 +384,13 @@ def write_tblt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.tblt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.TBLT, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.TBLT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" TABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" TABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -407,13 +407,13 @@ def write_ctrl_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.ctrl: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.CTRL, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" CONTROL DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" CONTROL DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -430,13 +430,13 @@ def write_const_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.const: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.CONST, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, obj.value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper() + " CONSTANT DEFINITIONS", True) + self.write_definition_table_header(outfile, self.adm.norm_name.upper() + " CONSTANT DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -453,13 +453,13 @@ def write_op_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.oper: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.OP, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.result_type, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" OPERATOR DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" OPERATOR DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -476,13 +476,13 @@ def write_macro_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.mac: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_namespace, cs.MACRO, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.MACRO, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "mc", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_namespace.upper()+" MACRO DEFINITIONS", False) + self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" MACRO DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -492,7 +492,7 @@ def write_macro_definitions(self, outfile): # name is the name returned by get_adm_names() # def write_initialization_functions(self, outfile): - name = self.adm.norm_namespace + name = self.adm.norm_name body = ( "/* Initialization functions. */\n" "void {0}_init();\n" diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 82a88de..6407a49 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -78,7 +78,7 @@ def write(self, outfile: TextIO): # scraper is the Scraper class object for this ADM # def write_setup(self, outfile): - outfile.write("void {}_setup()\n{{\n\n".format(self.adm.norm_namespace.lower())) + outfile.write("void {}_setup()\n{{\n\n".format(self.adm.norm_name.lower())) self._scraper.write_custom_body(outfile, "setup") @@ -91,7 +91,7 @@ def write_setup(self, outfile): # scraper is the Scraper class object for this ADM # def write_cleanup(self, outfile): - outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.norm_namespace.lower())) + outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.norm_name.lower())) self._scraper.write_custom_body(outfile, "cleanup") diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index b1b0fca..b7598be 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -67,8 +67,8 @@ def write(self, outfile: TextIO): self._scraper.write_custom_functions(outfile) # The setup and clean up functions - outfile.write("void "+self.adm.norm_namespace+"_setup();\n") - outfile.write("void "+self.adm.norm_namespace+"_cleanup();\n\n") + outfile.write("void "+self.adm.norm_name+"_setup();\n") + outfile.write("void "+self.adm.norm_name+"_cleanup();\n\n") self.write_metadata_functions(outfile) self.write_constant_functions(outfile) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 7d8a0ce..ec4cfdd 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -53,7 +53,7 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = "g_" + self.adm.norm_namespace.lower() + "_idx" + self._g_var_idx = "g_" + self.adm.norm_name.lower() + "_idx" def file_path(self) -> str: # Interface for AbstractWriter @@ -131,7 +131,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" add_str_template = self._make_std_adm_build_add_template(coll_type) - meta_add_template = campch.make_std_meta_add_coll_template(coll_type, self.adm.norm_namespace) + meta_add_template = campch.make_std_meta_add_coll_template(coll_type, self.adm.norm_name) added_coll = False added_parm = False @@ -139,7 +139,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): for obj in objlist: try: # Gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_namespace, coll_type, obj) + ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) amp_type = cu.make_amp_type_name_from_str(obj.type) paramspec = getattr(obj, 'parmspec', None) parms = paramspec.items if paramspec else [] @@ -176,7 +176,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, coll_type, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, coll_type, body) # # Writes the init_metadata() function to the open file descriptor passed as c_file @@ -191,7 +191,7 @@ def write_init_metadata(self, outfile): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" - meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.adm.norm_namespace) + meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.adm.norm_name) # NOTE: this function uses the CONST modifiers for most things, but needs the META IDX here: const_idx = cs.get_adm_idx(cs.CONST) @@ -203,7 +203,7 @@ def write_init_metadata(self, outfile): for obj in self.adm.mdat: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_namespace, cs.META, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) amp_type = cu.make_amp_type_name_from_str(obj.type) # format the meta_add_.* template for this item @@ -221,7 +221,7 @@ def write_init_metadata(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.META, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.META, body) # # Writes the init_constants() function to the open file descriptor passed as c_file @@ -252,14 +252,14 @@ def write_init_ops(self, outfile): add_op_ari_template = "\n\tadm_add_op_ari(id, {}, NULL);" build_str_template = campch.make_adm_build_ari_template(cs.OP, self._g_var_idx, True) - meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, self.adm.norm_namespace) + meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, self.adm.norm_name) added_coll = False added_parm = False for obj in self.adm.oper: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_namespace, cs.OP, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) amp_type = cu.make_amp_type_name_from_str(obj.result_type) in_types = obj.in_type if obj.in_type else [] @@ -291,7 +291,7 @@ def write_init_ops(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.OP, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.OP, body) # # Writes the init_variables() function to the open file descriptor passed as c_file @@ -313,7 +313,7 @@ def write_init_controls_function(self, outfile): build_str_template = campch.make_adm_build_ari_template(cs.CTRL, self._g_var_idx, True) add_ctrldef_template = "\n\tadm_add_ctrldef_ari(id, {}, NULL);" - enum_name = cu.make_enum_name_from_str(self.adm.norm_namespace) + enum_name = cu.make_enum_name_from_str(self.adm.norm_name) meta_add_template = "meta_add_" + cs.get_sname(cs.CTRL).lower() + "(id, " + enum_name + ", \"{0}\", \"{1}\");\n" added_coll = False @@ -321,7 +321,7 @@ def write_init_controls_function(self, outfile): for obj in self.adm.ctrl: # Gather the pieces of data that we need - ari = cu.make_ari_name(self.adm.norm_namespace, cs.CTRL, obj) + ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) parms = obj.parmspec.items if obj.parmspec else [] # Format the meta_add_.* template for this item @@ -353,7 +353,7 @@ def write_init_controls_function(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.CTRL, body) + campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) # diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 87c3f0a..3a402d3 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -192,7 +192,7 @@ def make_formatted_comment_header(name, c_open, c_close): # def make_collect_function(adm, edd): basename = "get_{}".format(edd.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -203,7 +203,7 @@ def make_collect_function(adm, edd): def make_meta_function(adm, meta): keyword = cs.get_sname(cs.META) basename = "{0}_{1}".format(keyword, meta.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -214,7 +214,7 @@ def make_meta_function(adm, meta): def make_constant_function(adm, const): keyword = "get" basename = "{0}_{1}".format(keyword, const.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -225,7 +225,7 @@ def make_constant_function(adm, const): def make_control_function(adm, control): keyword = cs.get_sname(cs.CTRL) basename = "{0}_{1}".format(keyword, control.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tnv_t *{}(eid_t *def_mgr, tnvc_t *parms, int8_t *status)".format(fullname) return basename, fullname, signature @@ -236,7 +236,7 @@ def make_control_function(adm, control): def make_operator_function(adm, op): keyword = cs.get_sname(cs.OP) basename = "{0}_{1}".format(keyword, op.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tnv_t *{}(vector_t *stack)".format(fullname) return basename, fullname, signature @@ -247,7 +247,7 @@ def make_operator_function(adm, op): def make_table_function(adm, tbl): keyword = cs.get_sname(cs.TBLT) basename = "{0}_{1}".format(keyword, tbl.name.lower()) - fullname = "{0}_{1}".format(adm.norm_namespace.lower(), basename) + fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) signature = "tbl_t *{}(ari_t *id)".format(fullname) return basename, fullname, signature @@ -357,13 +357,13 @@ def write_init_macro_function(c_file, adm, g_var_idx, mgr): adm_add_macdef_str = "\n\tadm_add_macdef(def);" meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" - enum_name = cu.make_enum_name_from_str(adm.norm_namespace) + enum_name = cu.make_enum_name_from_str(adm.norm_name) meta_add_macro_template = "\n\tmeta = meta_add_macro" + "(def->ari, " + enum_name + ", \"{0}\", \"{1}\");" build_ari_str_template = make_adm_build_ari_template(cs.MACRO, g_var_idx, False) for obj in adm.mac: # Preliminaries - ari = cu.make_ari_name(adm.norm_namespace, cs.MACRO, obj) + ari = cu.make_ari_name(adm.norm_name, cs.MACRO, obj) mac_name = obj.name description = obj.description or '' @@ -410,7 +410,7 @@ def write_init_macro_function(c_file, adm, g_var_idx, mgr): if added_meta: body = meta_decl_str + body - write_formatted_init_function(c_file, adm.norm_namespace, cs.MACRO, body) + write_formatted_init_function(c_file, adm.norm_name, cs.MACRO, body) # Builds a template for the # ``` @@ -448,14 +448,14 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): # gives you the adm_build_ari(...) build_str_template = "\n" + make_adm_build_ari_template(cs.VAR, g_var_idx, True) # gives you the meta_add_var(... ) - meta_add_template = make_std_meta_add_coll_template(cs.VAR, adm.norm_namespace) + meta_add_template = make_std_meta_add_coll_template(cs.VAR, adm.norm_name) added_coll = False added_expr = False for obj in adm.var: # Preliminaries - ari = cu.make_ari_name(adm.norm_namespace, cs.VAR, obj) + ari = cu.make_ari_name(adm.norm_name, cs.VAR, obj) amp_type = cu.make_amp_type_name_from_str(obj.type) var_name = obj.name @@ -503,7 +503,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): if added_coll: body = coll_decl_str + body - write_formatted_init_function(c_file, adm.norm_namespace, cs.VAR, body) + write_formatted_init_function(c_file, adm.norm_name, cs.VAR, body) # @@ -527,7 +527,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): add_item_template = "\n\trpttpl_add_item(def, {});" adm_add_str = "\n\tadm_add_rpttpl(def);" - enum_name = cu.make_enum_name_from_str(adm.norm_namespace) + enum_name = cu.make_enum_name_from_str(adm.norm_name) meta_add_rpt_template = "meta_add_rpttpl(def->id, " + enum_name + ", \"{0}\", \"{1}\");" meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" @@ -536,7 +536,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): rpt_name = obj.name description = obj.description or '' - ari = cu.make_ari_name(adm.norm_namespace, cs.RPTT, obj) + ari = cu.make_ari_name(adm.norm_name, cs.RPTT, obj) params = obj.parmspec.items if obj.parmspec else [] defs = obj.definition.items if obj.definition else [] @@ -589,7 +589,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): if added_meta: body = meta_decl_str + body - write_formatted_init_function(c_file, adm.norm_namespace, cs.RPTT, body) + write_formatted_init_function(c_file, adm.norm_name, cs.RPTT, body) # # Writes the init_tables funtion for the passed adm name and @@ -601,7 +601,7 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): tbl_create_template = "\n\tdef = tblt_create({0}, {1});" build_ari_template = make_adm_build_ari_template(cs.TBLT, g_var_idx, False) - enum_name = cu.make_enum_name_from_str(adm.norm_namespace) + enum_name = cu.make_enum_name_from_str(adm.norm_name) add_tblt_str = "\n\tadm_add_tblt(def);" meta_add_template = "\n\tmeta_add_tblt(def->id, " + enum_name + ", \"{0}\", \"{1}\");" @@ -611,7 +611,7 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): for obj in adm.tblt: # Preliminaries - ari = cu.make_ari_name(adm.norm_namespace, cs.TBLT, obj) + ari = cu.make_ari_name(adm.norm_name, cs.TBLT, obj) tbl_name = obj.name description = obj.description or '' @@ -648,18 +648,18 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): if added_table: body = tbl_decl_str + body - write_formatted_init_function(c_file, adm.norm_namespace, cs.TBLT, body) + write_formatted_init_function(c_file, adm.norm_name, cs.TBLT, body) # # Writes the init function to c_file # def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: bool): - enum_name = cu.make_enum_name_from_str(adm.norm_namespace) + enum_name = cu.make_enum_name_from_str(adm.norm_name) - vdb_adds = "\tadm_add_adm_info(\"" + adm.norm_namespace + "\", " + enum_name + ");\n" + vdb_adds = "\tadm_add_adm_info(\"" + adm.norm_name + "\", " + enum_name + ");\n" vdb_add_template = "\n\tVDB_ADD_NN(((" + enum_name + " * 20) + {0}), &({1}[{0}]));" - init_decl_template = "static void " + adm.norm_namespace + "_init_{0}(void);\n" - init_call_template = "\n\t" + adm.norm_namespace + "_init_{0}();" + init_decl_template = "static void " + adm.norm_name + "_init_{0}(void);\n" + init_call_template = "\n\t" + adm.norm_name + "_init_{0}();" # order of init functions matters obj_types = { @@ -677,7 +677,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: init_decls = "" init_calls = "" if not mgr: - init_calls = "\n\t" + adm.norm_namespace + "_setup();" + init_calls = "\n\t" + adm.norm_name + "_setup();" for coll, attrname in obj_types.items(): init_decls += init_decl_template.format(cs.get_sname(coll).lower()) @@ -691,7 +691,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: body = vdb_adds + "\n\n" + init_calls c_file.write(init_decls + "\n") - write_formatted_init_function(c_file, adm.norm_namespace, None, body) + write_formatted_init_function(c_file, adm.norm_name, None, body) def make_cplusplus_open(): ''' Open an "extern C" block for C++ inclusion. ''' From 5656cac8bc5b1e87ba6ddc15609293b2a72858cd Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 14 Aug 2024 17:36:19 -0400 Subject: [PATCH 13/63] change mdat to ident? --- src/camp/generators/create_agent_c.py | 2 +- src/camp/generators/create_gen_h.py | 2 +- src/camp/generators/create_impl_c.py | 2 +- src/camp/generators/create_impl_h.py | 2 +- src/camp/generators/create_mgr_c.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index 969847e..1c4099f 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -127,7 +127,7 @@ def write_init_metadata_function(self, outfile): body = "" add_str_template = self.make_std_meta_adm_build_template(cs.META) - for obj in self.adm.mdat: + for obj in self.adm.ident: _,fname,_ = campch.make_meta_function(self.adm, obj) ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index bad5fed..9375799 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -288,7 +288,7 @@ def write_metadata_definitions(self, outfile): defines = "" # the #defines and for all metadata (string) # Create the strings for the #defines and preceeding commented table - for obj in self.adm.mdat: + for obj in self.adm.ident: hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.META, obj) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 6407a49..b900b41 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -113,7 +113,7 @@ def write_metadata_functions(self, outfile): "\n}}" "\n\n") - for obj in self.adm.mdat: + for obj in self.adm.ident: _,_,signature = campch.make_meta_function(self.adm, obj) outfile.write(metadata_funct_str.format(signature, obj.value)) diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index b7598be..f146df4 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -121,7 +121,7 @@ def write_includes(self, outfile): # def write_metadata_functions(self, outfile): outfile.write("\n/* Metadata Functions */\n") - for obj in self.adm.mdat: + for obj in self.adm.ident: _,_,signature = campch.make_meta_function(self.adm, obj) outfile.write(signature + ";\n") diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index ec4cfdd..0244008 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -184,7 +184,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): # metadata is a list of the metadata to include # def write_init_metadata(self, outfile): - self._write_mgr_std_init_funct(outfile, cs.META, self.adm.mdat) + self._write_mgr_std_init_funct(outfile, cs.META, self.adm.ident) return body = "" @@ -201,7 +201,7 @@ def write_init_metadata(self, outfile): added_coll = False added_parm = False - for obj in self.adm.mdat: + for obj in self.adm.ident: # Preliminary; gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) amp_type = cu.make_amp_type_name_from_str(obj.type) From 0170b19ba32515893a3a31f0e7a1879cecde0297 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:09:18 -0400 Subject: [PATCH 14/63] missed namespaces, temp take out rpt, tblt, macs --- src/camp/generators/create_agent_c.py | 6 +++--- src/camp/generators/create_gen_h.py | 6 +++--- src/camp/generators/create_impl_c.py | 2 +- src/camp/generators/create_impl_h.py | 2 +- src/camp/generators/create_mgr_c.py | 6 +++--- src/camp/generators/create_sql.py | 12 ++++++------ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index 1c4099f..f5f34df 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -57,9 +57,9 @@ def write(self, outfile: TextIO): self.write_init_op_function(outfile) self.write_init_var_function(outfile) self.write_init_control_function(outfile) - self.write_init_macro_function(outfile) - self.write_init_reports_function(outfile) - self.write_init_tables_function(outfile) + # self.write_init_macro_function(outfile) + # self.write_init_reports_function(outfile) + # self.write_init_tables_function(outfile) # # Writes all of the #includes for this c file diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 9375799..9a47891 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -55,11 +55,11 @@ def write(self, outfile: TextIO): self.write_edd_definitions(outfile) self.write_variable_definitions(outfile) - self.write_rptt_definitions(outfile) - self.write_tblt_definitions(outfile) + # self.write_rptt_definitions(outfile) + # self.write_tblt_definitions(outfile) self.write_ctrl_definitions(outfile) self.write_const_definitions(outfile) - self.write_macro_definitions(outfile) + # self.write_macro_definitions(outfile) self.write_op_definitions(outfile) self.write_initialization_functions(outfile) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index b900b41..e874297 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -66,7 +66,7 @@ def write(self, outfile: TextIO): self.write_metadata_functions(outfile) self.write_constant_functions(outfile) - self.write_table_functions(outfile) + # self.write_table_functions(outfile) self.write_edd_functions(outfile) self.write_control_functions(outfile) self.write_operator_functions(outfile) diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index f146df4..b3bb032 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -75,7 +75,7 @@ def write(self, outfile: TextIO): self.write_collect_functions(outfile) self.write_control_functions(outfile) self.write_operator_functions(outfile) - self.write_table_functions(outfile) + # self.write_table_functions(outfile) outfile.write(campch.make_cplusplus_close()) self.write_endifs(outfile) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 0244008..b919799 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -76,9 +76,9 @@ def write(self, outfile: TextIO): self.write_init_ops(outfile) self.write_init_variables_function(outfile) self.write_init_controls_function(outfile) - self.write_init_macros(outfile) - self.write_init_reports(outfile) - self.write_init_tables(outfile) + # self.write_init_macros(outfile) + # self.write_init_reports(outfile) + # self.write_init_tables(outfile) # # Writes all of the #includes for this file diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 7f4b11e..55817e6 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -78,7 +78,7 @@ def __init__(self, admset, adm, out_path, dialect): self._vars_use = set() # The first half of the namespace - ns = self.adm.norm_namespace + ns = self.adm.norm_name hl_ns = ns.split('/')[0].lower() self._sql_ns = self._var_name(f"{hl_ns}_namespace_id") @@ -97,11 +97,11 @@ def write(self, outfile: TextIO): body += self.write_edd_functions() body += self.write_oper_functions() body += self.write_var_functions() - body += self.write_tblt_functions() - body += self.write_rptt_functions() + # body += self.write_tblt_functions() + # body += self.write_rptt_functions() body += self.write_ctrl_functions() body += self.write_const_functions() - body += self.write_mac_functions() + # body += self.write_mac_functions() head += self.body_pre() body += self.body_post() @@ -138,7 +138,7 @@ def _make_ari(self, coll, item): :param item: object to make the IDs for. :return: the augmented ARI text. ''' - ns = self.adm.norm_namespace + ns = self.adm.norm_name ari = cu.make_ari_name(ns, coll, item).lower() return ari @@ -284,7 +284,7 @@ def write_setup(self): "--", "-- -------------------------------------------------------------------", "", - "-- ADM: '{}'".format(self.adm.norm_namespace), + "-- ADM: '{}'".format(self.adm.norm_name), "", ] From f846274f859dc0e025e8f4f114e1f40cbfc6b20a Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:12:51 -0400 Subject: [PATCH 15/63] change obj.type to obj.typeobj --- src/camp/generators/create_gen_h.py | 8 ++++---- src/camp/generators/create_mgr_c.py | 4 ++-- src/camp/generators/create_sql.py | 2 +- src/camp/generators/lib/campch.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 9a47891..20ff1b4 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -292,7 +292,7 @@ def write_metadata_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.META, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, obj.value) + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.value) defines = defines + "// \"{}\"\n".format(obj.name) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) @@ -317,7 +317,7 @@ def write_edd_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file @@ -340,7 +340,7 @@ def write_variable_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.VAR, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file @@ -432,7 +432,7 @@ def write_const_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.type, obj.value) + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index b919799..1ecad20 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -140,7 +140,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): try: # Gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) - amp_type = cu.make_amp_type_name_from_str(obj.type) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj) paramspec = getattr(obj, 'parmspec', None) parms = paramspec.items if paramspec else [] @@ -204,7 +204,7 @@ def write_init_metadata(self, outfile): for obj in self.adm.ident: # Preliminary; gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) - amp_type = cu.make_amp_type_name_from_str(obj.type) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj) # format the meta_add_.* template for this item meta_add_str = meta_add_template.format(amp_type, obj.name, obj.description) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 55817e6..3231103 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -762,7 +762,7 @@ def write_gen_const_functions(self, objects, coll): lines += [ "", insert_obj_template.format(c_name, const_id), - insert_const_actual_def_template.format(const_id, c_desc, obj.type, obj.value, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.value, const_act_id), ] return lines diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 3a402d3..0db9c95 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -456,7 +456,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): for obj in adm.var: # Preliminaries ari = cu.make_ari_name(adm.norm_name, cs.VAR, obj) - amp_type = cu.make_amp_type_name_from_str(obj.type) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj) var_name = obj.name description = obj.description or '' From 41d79347d2bc74b29ed94b5fe1e34e68b5b6cea0 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:15:08 -0400 Subject: [PATCH 16/63] fix const value => init_value --- src/camp/generators/create_gen_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 20ff1b4..ea15027 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -432,7 +432,7 @@ def write_const_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.value) + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.init_value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file From 19bce9a952ac93beed2d52d60e7df22a787be86b Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:15:31 -0400 Subject: [PATCH 17/63] fix oper result_type => obj.result.typeobj --- src/camp/generators/create_gen_h.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index ea15027..156fc5e 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -455,7 +455,7 @@ def write_op_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.result_type, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.result.typeobj, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file From 36334f97ce6c62b4e06daf2fee01ca9dffb18b47 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:17:47 -0400 Subject: [PATCH 18/63] temp ignore meta, mac, rptt, tblt --- src/camp/generators/lib/campch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 0db9c95..f2d3ccc 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -663,15 +663,15 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: # order of init functions matters obj_types = { - cs.META: 'mdat', + # cs.META: 'mdat', cs.CONST: 'const', cs.EDD: 'edd', cs.OP: 'oper', cs.VAR: 'var', cs.CTRL: 'ctrl', - cs.MACRO: 'mac', - cs.RPTT: 'rptt', - cs.TBLT: 'tblt', + # cs.MACRO: 'mac', + # cs.RPTT: 'rptt', + # cs.TBLT: 'tblt', } init_decls = "" From d0665fabd39c404fc121d581c5d7871407354f85 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:38:45 -0400 Subject: [PATCH 19/63] fix type obj to strings --- src/camp/generators/create_mgr_c.py | 10 +++++----- src/camp/generators/lib/campch.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 1ecad20..2b207f6 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -140,7 +140,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): try: # Gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) - amp_type = cu.make_amp_type_name_from_str(obj.typeobj) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) paramspec = getattr(obj, 'parmspec', None) parms = paramspec.items if paramspec else [] @@ -204,7 +204,7 @@ def write_init_metadata(self, outfile): for obj in self.adm.ident: # Preliminary; gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) - amp_type = cu.make_amp_type_name_from_str(obj.typeobj) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) # format the meta_add_.* template for this item meta_add_str = meta_add_template.format(amp_type, obj.name, obj.description) @@ -260,8 +260,8 @@ def write_init_ops(self, outfile): for obj in self.adm.oper: # Preliminary; gather all of the pieces of data we need ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) - amp_type = cu.make_amp_type_name_from_str(obj.result_type) - in_types = obj.in_type if obj.in_type else [] + amp_type = cu.make_amp_type_name_from_str(obj.result.typeobj.type_text) + in_types = obj.operands.items if obj.operands.items else [] # Format the meta_add_.* template for this item meta_str = meta_add_template.format(amp_type, obj.name, obj.description) @@ -279,7 +279,7 @@ def write_init_ops(self, outfile): body += "\n\t" + meta_str for in_type in in_types: - parm_type = cu.make_amp_type_name_from_str(in_type.type) + parm_type = cu.make_amp_type_name_from_str(in_type.typeobj.type_text) body += add_parm_template.format("O{}".format(in_type.position + 1), parm_type) added_coll = True diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index f2d3ccc..bad4e15 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -456,7 +456,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): for obj in adm.var: # Preliminaries ari = cu.make_ari_name(adm.norm_name, cs.VAR, obj) - amp_type = cu.make_amp_type_name_from_str(obj.typeobj) + amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) var_name = obj.name description = obj.description or '' @@ -479,7 +479,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): # If postfixs are present, append the expr_create string, and prepend # the adm_add_var_from_expr stringq if pfxs: - init_type = cu.make_amp_type_name_from_str(obj.initializer.type) + init_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) expr_str = expr_create_str.format(init_type) + expr_str expr_str += add_var_from_expr.format(init_type) From d2ed0cb9d0a815b1f531272379266b2d55e9a661 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:49:46 -0400 Subject: [PATCH 20/63] ignore var for now --- src/camp/generators/create_agent_c.py | 2 +- src/camp/generators/create_mgr_c.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index f5f34df..e1bdba2 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -55,7 +55,7 @@ def write(self, outfile: TextIO): self.write_init_constant_function(outfile) self.write_init_edd_function(outfile) self.write_init_op_function(outfile) - self.write_init_var_function(outfile) + # self.write_init_var_function(outfile) self.write_init_control_function(outfile) # self.write_init_macro_function(outfile) # self.write_init_reports_function(outfile) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 2b207f6..e5bb265 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -74,7 +74,7 @@ def write(self, outfile: TextIO): self.write_init_constants(outfile) self.write_init_edd_function(outfile) self.write_init_ops(outfile) - self.write_init_variables_function(outfile) + # self.write_init_variables_function(outfile) self.write_init_controls_function(outfile) # self.write_init_macros(outfile) # self.write_init_reports(outfile) From 6bc2fae86c2efe469f5c4549c147990b4888a79d Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:55:01 -0400 Subject: [PATCH 21/63] fix mostly parmspec => parameters --- src/camp/generators/create_agent_c.py | 6 +++--- src/camp/generators/create_mgr_c.py | 4 ++-- src/camp/generators/create_sql.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index e1bdba2..ab03b67 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -173,7 +173,7 @@ def write_init_edd_function(self, outfile): _,fname,_ = campch.make_collect_function(self.adm, obj) ari = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) - if obj.parmspec and obj.parmspec.items: + if obj.parameters and obj.parameters.items: parms_tf = "1" body += add_str.format(parms_tf, ari, fname) @@ -194,7 +194,7 @@ def write_init_op_function(self, outfile): for obj in self.adm.oper: ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) - in_types = obj.in_type if obj.in_type else [] + in_types = obj.operands.items if obj.operands.items else [] body += adm_add_op_template.format(ari, len(in_types), ari.lower()) @@ -221,7 +221,7 @@ def write_init_control_function(self, outfile): for obj in self.adm.ctrl: ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) - parms = obj.parmspec.items if obj.parmspec else [] + parms = obj.parameters.items if obj.parameters else [] body += adm_add_template.format(ari, len(parms), ari.lower()) campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index e5bb265..1ee8e05 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -322,7 +322,7 @@ def write_init_controls_function(self, outfile): for obj in self.adm.ctrl: # Gather the pieces of data that we need ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) - parms = obj.parmspec.items if obj.parmspec else [] + parms = obj.parameters.items if obj.parameters else [] # Format the meta_add_.* template for this item meta_str = meta_add_template.format(obj.name, obj.description) @@ -341,7 +341,7 @@ def write_init_controls_function(self, outfile): body += "\n\t" + meta_str for parm in parms: - parm_type = cu.make_amp_type_name_from_str(parm.type) + parm_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) body += add_parm_template.format(parm.name, parm_type) added_coll = True diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 3231103..e3182d3 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -384,7 +384,7 @@ def write_edd_functions(self): name = edd.name etype = edd.type desc = escape_description_sql(edd.description) - parmspec = edd.parmspec.items if edd.parmspec else [] + parmspec = edd.parameters.items if edd.parameters else [] num_parmspec = len(parmspec) lines += [ "", @@ -580,7 +580,7 @@ def handle_report_fp_ap(self, item, lines, report_id): # Parameter types of referenced object, if there are any types = ( - [parm.type for parm in found_ref.parmspec.items] + [parm.type for parm in found_ref.parameters.items] if hasattr(found_ref, 'parmspec') and found_ref.parmspec else [] ) @@ -718,7 +718,7 @@ def write_ctrl_functions(self): for ctrl in self.adm.ctrl: ctrl_name = ctrl.name ctrl_desc = escape_description_sql(ctrl.description) - parmspec = ctrl.parmspec.items if ctrl.parmspec else [] + parmspec = ctrl.parameters.items if ctrl.parameters else [] ctrl_id, ctrl_def_id, ctrl_act_id = self.make_sql_ids(self._make_ari(cs.CTRL, ctrl)) lines += [ From d21cc76e4117649bc64972984e2e07a349a789e8 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 13:58:17 -0400 Subject: [PATCH 22/63] fix get_child w new ace --- src/camp/generators/create_sql.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index e3182d3..b79c1e7 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -343,13 +343,14 @@ def write_metadata_function(self): def val_or_none(obj, attr='value'): if obj is None: return '' - return getattr(obj, attr) - - name = val_or_none(self.admset.get_child(self.adm, models.Ident, 'name')) - ns = val_or_none(self.admset.get_child(self.adm, models.Ident, 'namespace')) - version = val_or_none(self.admset.get_child(self.adm, models.Ident, 'version')) - org = val_or_none(self.admset.get_child(self.adm, models.Ident, 'organization')) - desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, models.Ident, 'namespace'), 'description')) + return obj + + # TODO Karen fix + name = val_or_none(self.admset.get_child(self.adm, 'name')) + ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) + version = val_or_none(self.admset.get_child(self.adm, 'version')) + org = val_or_none(self.admset.get_child(self.adm, 'organization')) + desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) From 537b57ee4c0ae74407e87023302553de40a79a15 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 14:12:16 -0400 Subject: [PATCH 23/63] more type fixes --- src/camp/generators/create_sql.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index b79c1e7..89493a3 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -383,7 +383,7 @@ def write_edd_functions(self): edd_fp_id = self.make_fp_id(edd_obj_id) name = edd.name - etype = edd.type + etype = edd.typeobj.type_text desc = escape_description_sql(edd.description) parmspec = edd.parameters.items if edd.parameters else [] num_parmspec = len(parmspec) @@ -428,10 +428,10 @@ def write_oper_functions(self): for oper in self.adm.oper: oper_name = oper.name oper_desc = escape_description_sql(oper.description) - result_type = oper.result_type + result_type = oper.result.typeobj.type_text oper_obj_id, oper_def_id, oper_act_id = self.make_sql_ids(self._make_ari(cs.OP, oper)) - tnvc_collection_template,tnvc_entry_template,tnvc_unk_entry_template = self.create_insert_tnvc_templates(cs.OP, len(oper.in_type)) + tnvc_collection_template,tnvc_entry_template,tnvc_unk_entry_template = self.create_insert_tnvc_templates(cs.OP, len(oper.operands.items)) lines += [ "", @@ -439,8 +439,8 @@ def write_oper_functions(self): tnvc_collection_template.format("operands for "+ oper_name), ] - for in_type in oper.in_type: - t = in_type.type.lower() + for in_type in oper.operands.items: + t = in_type.typeobj.type_text.lower() # UNK has one fewer parameter if t == "unk": @@ -450,9 +450,9 @@ def write_oper_functions(self): # TODO: UNK is not a valid type, comment the actual_def for this out for now until ADM resolved if result_type.upper() == 'UNK': - lines += ["-- " + actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.in_type), oper_act_id)] + lines += ["-- " + actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.operands.items), oper_act_id)] else: - lines += [actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.in_type), oper_act_id)] + lines += [actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.operands.items), oper_act_id)] return lines @@ -779,14 +779,14 @@ def write_const_functions(self): return lines + self.write_gen_const_functions(self.adm.const, cs.CONST) def write_mdat_functions(self): - ''' Genreate lines for all of the MDATs in the ADM + ''' Generate lines for all of the MDATs in the ADM ''' lines = [ "", "", "-- MDAT", ] - return lines + self.write_gen_const_functions(self.adm.mdat, cs.META) + return lines + self.write_gen_const_functions(self.adm.ident, cs.META) def write_mac_functions(self): From 99ea6117161f4b3b047280dff8fe9baa6b7a9476 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 14:12:55 -0400 Subject: [PATCH 24/63] cont ignore var --- src/camp/generators/create_sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 89493a3..d4e17eb 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -96,7 +96,7 @@ def write(self, outfile: TextIO): body += self.write_mdat_functions() body += self.write_edd_functions() body += self.write_oper_functions() - body += self.write_var_functions() + # body += self.write_var_functions() # body += self.write_tblt_functions() # body += self.write_rptt_functions() body += self.write_ctrl_functions() From cae92feeb0a40a3587606452dbf34e9ffdb9a1c5 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 14:16:26 -0400 Subject: [PATCH 25/63] =?UTF-8?q?compiles=20and=20runs!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/camp/generators/create_mgr_c.py | 2 +- src/camp/generators/create_sql.py | 10 +++++----- src/camp/generators/lib/campch.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 1ee8e05..c038d68 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -43,7 +43,7 @@ def make_add_parms_str(parms): add_parms_str = "" for parm in parms: - p_type = cu.make_amp_type_name_from_str(parm.type) + p_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) add_parms_str = add_parms_str + add_parm_template.format(parm.name, p_type) return add_parms_str diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index d4e17eb..ea41703 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -397,7 +397,7 @@ def write_edd_functions(self): lines += [insert_formal_parmspec_template.format(num_parmspec, name, edd_fp_id, edd_obj_id)] for parm in parmspec: - lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, parm.type)] + lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, parm.typeobj.type_text)] # Only put actual definition here if no parmspec if not parmspec: @@ -581,7 +581,7 @@ def handle_report_fp_ap(self, item, lines, report_id): # Parameter types of referenced object, if there are any types = ( - [parm.type for parm in found_ref.parameters.items] + [parm.typeobj.type_text for parm in found_ref.parameters.items] if hasattr(found_ref, 'parmspec') and found_ref.parmspec else [] ) @@ -731,7 +731,7 @@ def write_ctrl_functions(self): fp_spec_id = self._var_name("fp_spec_id") lines += [insert_formal_parmspec_template.format(len(parmspec), ctrl_name, fp_spec_id, ctrl_id)] for parm in parmspec: - lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.type)] + lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.typeobj.type_text)] else: fp_spec_id = "null" @@ -763,7 +763,7 @@ def write_gen_const_functions(self, objects, coll): lines += [ "", insert_obj_template.format(c_name, const_id), - insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.value, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.init_value, const_act_id), ] return lines @@ -825,7 +825,7 @@ def write_mac_functions(self): fp_spec_id = self._var_name("fp_spec_id") lines += [insert_formal_parmspec_template.format(len(parmspec), mac_name, fp_spec_id)] for parm in parmspec: - lines += [insert_ac_formal_parmspec_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.type)] + lines += [insert_ac_formal_parmspec_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.typeobj.type_text)] lines += [insert_ac_id_template.format(num_parmspec, mac_name)] diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index bad4e15..52c10b9 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -401,7 +401,7 @@ def write_init_macro_function(c_file, adm, g_var_idx, mgr): body += meta_add_macro_template.format(mac_name, description) added_meta = True for parm in parms: - amp_type = cu.make_amp_type_name_from_str(parm.type) + amp_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) body += meta_add_parm_template.format(parm.name, amp_type) # only add these declarations if the variables will be used; to avoid compiler warnings in C code @@ -577,7 +577,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): # Create meta_add_parm string for each parameter found for parm in params: - amp_type = cu.make_amp_type_name_from_str(parm.type) + amp_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) meta_add_parm_str += meta_add_parm_template.format(parm.name, amp_type) # Add to body string From 686b64e299b11698b12dcd8baf33842c628a7611 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 16:00:33 -0400 Subject: [PATCH 26/63] fix const value --- src/camp/generators/create_impl_c.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index e874297..db86415 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -129,13 +129,13 @@ def write_constant_functions(self, outfile): const_function_str = ( "\n{0}" "\n{{" - "\n\treturn tnv_from_uvast({1});" + "\n\treturn tnv_from_uvast({1});" # TODO Karen not necessarily everything is uvast? "\n}}" "\n") for obj in self.adm.const: _,_,signature = campch.make_constant_function(self.adm, obj) - outfile.write(const_function_str.format(signature, getattr(obj, 'value', ''))) + outfile.write(const_function_str.format(signature, getattr(obj, 'init_value', ''))) # # writes the table functions to the file passed From 54fc749e63dc940898dd5632f14ec9d77818f303 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 16:15:37 -0400 Subject: [PATCH 27/63] at least type shows an actual value now... change it to more readable? --- src/camp/generators/create_gen_h.py | 8 ++++---- src/camp/generators/create_sql.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 156fc5e..332ea97 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -292,7 +292,7 @@ def write_metadata_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.META, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.value) + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, obj.value) defines = defines + "// \"{}\"\n".format(obj.name) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) @@ -317,7 +317,7 @@ def write_edd_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file @@ -340,7 +340,7 @@ def write_variable_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.VAR, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file @@ -432,7 +432,7 @@ def write_const_definitions(self, outfile): hex_str = format(obj.enum, '#04x') ari_str = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj, obj.init_value) + table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, obj.init_value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index ea41703..f02ed59 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -763,7 +763,7 @@ def write_gen_const_functions(self, objects, coll): lines += [ "", insert_obj_template.format(c_name, const_id), - insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.init_value, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj.type_text, obj.init_value, const_act_id), ] return lines From 30b087e5268089f4f6bd7618636e77cf0cb35d89 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 17:18:37 -0400 Subject: [PATCH 28/63] mostly jenny's changes from ep2-dev --- src/camp/generators/create_agent_c.py | 8 +-- src/camp/generators/create_gen_h.py | 64 +++++++++++----------- src/camp/generators/create_impl_c.py | 8 +-- src/camp/generators/create_impl_h.py | 6 +- src/camp/generators/create_mgr_c.py | 59 +++++++++++--------- src/camp/generators/create_sql.py | 79 ++++++++++++++++++--------- 6 files changed, 129 insertions(+), 95 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index ab03b67..a268a6f 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -127,7 +127,7 @@ def write_init_metadata_function(self, outfile): body = "" add_str_template = self.make_std_meta_adm_build_template(cs.META) - for obj in self.adm.ident: + for obj in self.adm.metadata_list.items: _,fname,_ = campch.make_meta_function(self.adm, obj) ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) @@ -151,7 +151,7 @@ def write_init_constant_function(self, outfile): ari = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) #FIXME: can const have parameters? -# if obj.parmspec: +# if obj.paramspec: # parms_tf = "1" body += add_str.format(parms_tf, ari, fname) @@ -173,7 +173,7 @@ def write_init_edd_function(self, outfile): _,fname,_ = campch.make_collect_function(self.adm, obj) ari = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) - if obj.parameters and obj.parameters.items: + if hasattr(obj, 'parameters') and obj.parameters.items: parms_tf = "1" body += add_str.format(parms_tf, ari, fname) @@ -221,7 +221,7 @@ def write_init_control_function(self, outfile): for obj in self.adm.ctrl: ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) - parms = obj.parameters.items if obj.parameters else [] + parms = obj.parameters.items if hasattr(obj, 'parameters') else [] body += adm_add_template.format(ari, len(parms), ari.lower()) campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 332ea97..2c96043 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -74,7 +74,7 @@ def write(self, outfile: TextIO): # def write_defines(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = self.adm.norm_name.upper() + ns_upper = str(self.adm.enum) defines_str = """\ #ifndef ADM_{0}_H_ @@ -91,7 +91,7 @@ def write_defines(self, outfile): # def write_endifs(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = self.adm.norm_name.replace("/", "_").upper() + ns_upper = str(self.adm.enum) endifs_str = """\ #endif /* _HAVE_{1}_ADM_ */ @@ -121,9 +121,9 @@ def write_adm_template_documentation(self, outfile): * ADM ROOT STRING:{} */ """ - outfile.write(documentation_str.format(header_str, self.adm.norm_name)) + outfile.write(documentation_str.format(header_str, self.adm.enum)) - g_var_idx = "g_" + self.adm.norm_name.replace("/", "_").lower() + "_idx" + g_var_idx = f"g_{self.adm.enum}_idx" outfile.write("extern vec_idx_t {}[11];\n".format(g_var_idx)) # @@ -133,7 +133,7 @@ def write_agent_nickname_definitions(self, outfile): header_str = campch.make_formatted_comment_header("AGENT NICKNAME DEFINITIONS", True, True) outfile.write(header_str) - ns = self.adm.norm_name.lower() + ns = str(self.adm.enum) enum_name = cu.make_enum_name_from_str(ns) outfile.write("#define {0} {1}\n".format(enum_name, self.adm.enum)) @@ -288,17 +288,17 @@ def write_metadata_definitions(self, outfile): defines = "" # the #defines and for all metadata (string) # Create the strings for the #defines and preceeding commented table - for obj in self.adm.ident: - hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.META, obj) + for obj in self.adm.metadata_list.items: + #hex_str = format(obj.enum, '#04x') + ari_str = cu.make_ari_name(str(self.adm.enum), cs.META, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, obj.value) + table = table + self.format_table_entry(False, obj.name, ari_str, obj.name, obj.arg)#obj.description, obj.type, obj.value) defines = defines + "// \"{}\"\n".format(obj.name) - defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) + #defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" META-DATA DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.adm.enum} META-DATA DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -315,13 +315,13 @@ def write_edd_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.edd: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.EDD, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, "") + table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" EXTERNALLY DEFINED DATA DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} EXTERNALLY DEFINED DATA DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -338,13 +338,13 @@ def write_variable_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.var: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.VAR, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.VAR, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, "") + table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" VARIABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} VARIABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -361,13 +361,13 @@ def write_rptt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.rptt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.RPTT, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.RPTT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "TNVC", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" REPORT DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} REPORT DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -384,13 +384,13 @@ def write_tblt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.tblt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.TBLT, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.TBLT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" TABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} TABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -407,13 +407,13 @@ def write_ctrl_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.ctrl: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.CTRL, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" CONTROL DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} CONTROL DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -430,13 +430,13 @@ def write_const_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.const: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.CONST, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.typeobj.type_text, obj.init_value) + table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), obj.init_value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper() + " CONSTANT DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.adm.enum} CONSTANT DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -453,13 +453,13 @@ def write_op_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.oper: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) + ari_str = cu.make_ari_name(str(self.adm.enum), cs.OP, obj) - table = table + self.format_table_entry(False, obj.name, obj.description, obj.result.typeobj, "") + table = table + self.format_table_entry(False, obj.name, obj.description, obj.result.name, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" OPERATOR DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} OPERATOR DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -476,13 +476,13 @@ def write_macro_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.mac: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.MACRO, obj) + ari_str = cu.make_ari_name(self.adm.enum, cs.MACRO, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "mc", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, self.adm.norm_name.upper()+" MACRO DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.enum} MACRO DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -492,7 +492,7 @@ def write_macro_definitions(self, outfile): # name is the name returned by get_adm_names() # def write_initialization_functions(self, outfile): - name = self.adm.norm_name + name = self.adm.enum body = ( "/* Initialization functions. */\n" "void {0}_init();\n" diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index db86415..4e2c543 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -78,7 +78,7 @@ def write(self, outfile: TextIO): # scraper is the Scraper class object for this ADM # def write_setup(self, outfile): - outfile.write("void {}_setup()\n{{\n\n".format(self.adm.norm_name.lower())) + outfile.write("void {}_setup()\n{{\n\n".format(self.adm.enum)) self._scraper.write_custom_body(outfile, "setup") @@ -91,7 +91,7 @@ def write_setup(self, outfile): # scraper is the Scraper class object for this ADM # def write_cleanup(self, outfile): - outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.norm_name.lower())) + outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.enum)) self._scraper.write_custom_body(outfile, "cleanup") @@ -113,9 +113,9 @@ def write_metadata_functions(self, outfile): "\n}}" "\n\n") - for obj in self.adm.ident: + for obj in self.adm.metadata_list.items: _,_,signature = campch.make_meta_function(self.adm, obj) - outfile.write(metadata_funct_str.format(signature, obj.value)) + outfile.write(metadata_funct_str.format(signature, obj.arg)) # # Writes the constant functions to the file passed diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index b3bb032..7182a65 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -67,8 +67,8 @@ def write(self, outfile: TextIO): self._scraper.write_custom_functions(outfile) # The setup and clean up functions - outfile.write("void "+self.adm.norm_name+"_setup();\n") - outfile.write("void "+self.adm.norm_name+"_cleanup();\n\n") + outfile.write(f"void {self.adm.enum}_setup();\n") + outfile.write(f"void {self.adm.enum}_cleanup();\n\n") self.write_metadata_functions(outfile) self.write_constant_functions(outfile) @@ -121,7 +121,7 @@ def write_includes(self, outfile): # def write_metadata_functions(self, outfile): outfile.write("\n/* Metadata Functions */\n") - for obj in self.adm.ident: + for obj in self.adm.metadata_list.items: _,_,signature = campch.make_meta_function(self.adm, obj) outfile.write(signature + ";\n") diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index c038d68..6dc6c70 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -43,8 +43,8 @@ def make_add_parms_str(parms): add_parms_str = "" for parm in parms: - p_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) - add_parms_str = add_parms_str + add_parm_template.format(parm.name, p_type) + p_type = cu.make_amp_type_name_from_str(parm.name) + add_parms_str = add_parms_str + add_parm_template.format(parm.default_value, p_type) return add_parms_str @@ -53,7 +53,7 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = "g_" + self.adm.norm_name.lower() + "_idx" + self._g_var_idx = f"g_{self.adm.enum}_idx" def file_path(self) -> str: # Interface for AbstractWriter @@ -131,7 +131,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" add_str_template = self._make_std_adm_build_add_template(coll_type) - meta_add_template = campch.make_std_meta_add_coll_template(coll_type, self.adm.norm_name) + meta_add_template = campch.make_std_meta_add_coll_template(coll_type, str(self.adm.enum)) added_coll = False added_parm = False @@ -139,13 +139,20 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): for obj in objlist: try: # Gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) - amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) - paramspec = getattr(obj, 'parmspec', None) - parms = paramspec.items if paramspec else [] + ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) + amp_type = cu.make_amp_type_name_from_str(obj.name) + paramspec = getattr(obj, 'parameters', None) + parms = paramspec.items if paramspec else [] # format the meta_add_.* template for this item - meta_add_str = meta_add_template.format(amp_type, obj.name, obj.description) + meta_add_str = '' + for valname in ['init_value', 'arg']: + print(obj.name, type(obj)) + if hasattr(obj, valname): + meta_add_str = meta_add_template.format(amp_type, obj.name, getattr(obj, valname)) + return + if not meta_add_str: + meta_add_str = meta_add_template.format(amp_type, obj.name, "edd") # Make the string to add the parms in the function add_parms_str = make_add_parms_str(parms) @@ -176,7 +183,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_name, coll_type, body) + campch.write_formatted_init_function(outfile, str(self.adm.enum), coll_type, body) # # Writes the init_metadata() function to the open file descriptor passed as c_file @@ -184,14 +191,14 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): # metadata is a list of the metadata to include # def write_init_metadata(self, outfile): - self._write_mgr_std_init_funct(outfile, cs.META, self.adm.ident) + self._write_mgr_std_init_funct(outfile, cs.META, self.adm.metadata_list.items) return body = "" coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" - meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.adm.norm_name) + meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.adm.norm_namespace) # NOTE: this function uses the CONST modifiers for most things, but needs the META IDX here: const_idx = cs.get_adm_idx(cs.CONST) @@ -201,10 +208,10 @@ def write_init_metadata(self, outfile): added_coll = False added_parm = False - for obj in self.adm.ident: + for obj in self.adm.mdat: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) - amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) + ari = cu.make_ari_name(self.adm.norm_namespace, cs.META, obj) + amp_type = cu.make_amp_type_name_from_str(obj.type) # format the meta_add_.* template for this item meta_add_str = meta_add_template.format(amp_type, obj.name, obj.description) @@ -221,7 +228,7 @@ def write_init_metadata(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.META, body) + campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.META, body) # # Writes the init_constants() function to the open file descriptor passed as c_file @@ -252,15 +259,15 @@ def write_init_ops(self, outfile): add_op_ari_template = "\n\tadm_add_op_ari(id, {}, NULL);" build_str_template = campch.make_adm_build_ari_template(cs.OP, self._g_var_idx, True) - meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, self.adm.norm_name) + meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, str(self.adm.enum)) added_coll = False added_parm = False for obj in self.adm.oper: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) - amp_type = cu.make_amp_type_name_from_str(obj.result.typeobj.type_text) + ari = cu.make_ari_name(str(self.adm.enum), cs.OP, obj) + amp_type = cu.make_amp_type_name_from_str(obj.result.name) in_types = obj.operands.items if obj.operands.items else [] # Format the meta_add_.* template for this item @@ -279,7 +286,7 @@ def write_init_ops(self, outfile): body += "\n\t" + meta_str for in_type in in_types: - parm_type = cu.make_amp_type_name_from_str(in_type.typeobj.type_text) + parm_type = cu.make_amp_type_name_from_str(in_type.name) body += add_parm_template.format("O{}".format(in_type.position + 1), parm_type) added_coll = True @@ -291,7 +298,7 @@ def write_init_ops(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.OP, body) + campch.write_formatted_init_function(outfile, str(self.adm.enum), cs.OP, body) # # Writes the init_variables() function to the open file descriptor passed as c_file @@ -313,7 +320,7 @@ def write_init_controls_function(self, outfile): build_str_template = campch.make_adm_build_ari_template(cs.CTRL, self._g_var_idx, True) add_ctrldef_template = "\n\tadm_add_ctrldef_ari(id, {}, NULL);" - enum_name = cu.make_enum_name_from_str(self.adm.norm_name) + enum_name = cu.make_enum_name_from_str(str(self.adm.enum)) meta_add_template = "meta_add_" + cs.get_sname(cs.CTRL).lower() + "(id, " + enum_name + ", \"{0}\", \"{1}\");\n" added_coll = False @@ -321,7 +328,7 @@ def write_init_controls_function(self, outfile): for obj in self.adm.ctrl: # Gather the pieces of data that we need - ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) + ari = cu.make_ari_name(str(self.adm.enum), cs.CTRL, obj) parms = obj.parameters.items if obj.parameters else [] # Format the meta_add_.* template for this item @@ -341,8 +348,8 @@ def write_init_controls_function(self, outfile): body += "\n\t" + meta_str for parm in parms: - parm_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) - body += add_parm_template.format(parm.name, parm_type) + parm_type = cu.make_amp_type_name_from_str(parm.name) + body += add_parm_template.format(parm.default_value, parm_type) added_coll = True @@ -353,7 +360,7 @@ def write_init_controls_function(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) + campch.write_formatted_init_function(outfile, str(self.adm.enum), cs.CTRL, body) # diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index f02ed59..89ed0bd 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -78,9 +78,9 @@ def __init__(self, admset, adm, out_path, dialect): self._vars_use = set() # The first half of the namespace - ns = self.adm.norm_name + """ns = self.adm.norm_namespace hl_ns = ns.split('/')[0].lower() - self._sql_ns = self._var_name(f"{hl_ns}_namespace_id") + self._sql_ns = self._var_name(f"{hl_ns}_namespace_id")""" def file_path(self) -> str: # Interface for AbstractWriter @@ -138,7 +138,7 @@ def _make_ari(self, coll, item): :param item: object to make the IDs for. :return: the augmented ARI text. ''' - ns = self.adm.norm_name + ns = str(self.adm.enum) ari = cu.make_ari_name(ns, coll, item).lower() return ari @@ -180,7 +180,7 @@ def create_insert_obj_metadata_template(self, obj_type): # convert to object type enumeration to decimal for function obj_type_enum = str(int(cs.ari_type_enum(obj_type), 16)) - formatted = general_template.format(obj_type_enum, "{}", self._sql_ns, "{}") + formatted = general_template.format(obj_type_enum, "{}", self.adm.enum, "{}")#self._sql_ns, "{}") return formatted @@ -239,7 +239,7 @@ def make_definition_ids(self, item): name = item.nm - if name.casefold().startswith('mdat.'): + if name.casefold().startswith('metadata_list.'): name = 'meta' + name[4:] elif name.casefold().startswith('oper.'): name = 'op' + name[4:] @@ -340,21 +340,21 @@ def write_metadata_function(self): # format with org, namespace, version, name, description from namespace, ns from get_highlevel_ns meta_template = "CALL SP__insert_adm_defined_namespace('{}', '{}', '{}', '{}', {}, NULL, '{}', {});" - def val_or_none(obj, attr='value'): + def val_or_none(obj, attr='arg'): if obj is None: return '' - return obj + return getattr(obj, attr) - # TODO Karen fix name = val_or_none(self.admset.get_child(self.adm, 'name')) - ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) + #ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) + ns = self.adm.norm_name version = val_or_none(self.admset.get_child(self.adm, 'version')) org = val_or_none(self.admset.get_child(self.adm, 'organization')) - desc = escape_description_sql(val_or_none(self.admset.get_child(self.adm, 'namespace'), 'description')) + desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg)#val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) - formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self._sql_ns) + formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.adm.enum)#self._sql_ns) return [ "", formatted_template @@ -378,12 +378,20 @@ def write_edd_functions(self): # Format with edd obj id and edd name (only used if no parmspec) edd_actual_def_template = "CALL SP__insert_edd_actual_definition({}, 'The singleton value for {}', NULL, {});" - for edd in self.adm.edd: + for i, edd in enumerate(self.adm.edd): edd_obj_id, edd_def_id, edd_act_id = self.make_sql_ids(self._make_ari(cs.EDD, edd)) edd_fp_id = self.make_fp_id(edd_obj_id) name = edd.name - etype = edd.typeobj.type_text + if hasattr(edd.typeobj, 'type_text'): + etype = edd.typeobj.type_text + else: + etype = [] + for col in edd.typeobj.columns: + if hasattr(col.base, 'type_text'): + etype.append(col.base.type_text) + else: + etype.append(col.base.base.type_text) desc = escape_description_sql(edd.description) parmspec = edd.parameters.items if edd.parameters else [] num_parmspec = len(parmspec) @@ -397,7 +405,7 @@ def write_edd_functions(self): lines += [insert_formal_parmspec_template.format(num_parmspec, name, edd_fp_id, edd_obj_id)] for parm in parmspec: - lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, parm.typeobj.type_text)] + lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, parm.name)] # Only put actual definition here if no parmspec if not parmspec: @@ -428,7 +436,7 @@ def write_oper_functions(self): for oper in self.adm.oper: oper_name = oper.name oper_desc = escape_description_sql(oper.description) - result_type = oper.result.typeobj.type_text + result_type = oper.result.name oper_obj_id, oper_def_id, oper_act_id = self.make_sql_ids(self._make_ari(cs.OP, oper)) tnvc_collection_template,tnvc_entry_template,tnvc_unk_entry_template = self.create_insert_tnvc_templates(cs.OP, len(oper.operands.items)) @@ -440,7 +448,7 @@ def write_oper_functions(self): ] for in_type in oper.operands.items: - t = in_type.typeobj.type_text.lower() + t = in_type.name.lower() # UNK has one fewer parameter if t == "unk": @@ -581,8 +589,8 @@ def handle_report_fp_ap(self, item, lines, report_id): # Parameter types of referenced object, if there are any types = ( - [parm.typeobj.type_text for parm in found_ref.parameters.items] - if hasattr(found_ref, 'parmspec') and found_ref.parmspec + [parm.name for parm in found_ref.parameters.items] + if hasattr(found_ref, 'parameters') and found_ref.parameters else [] ) @@ -658,7 +666,7 @@ def write_rptt_functions(self): report_name = rptt.name report_desc = escape_description_sql(rptt.description) definitions = rptt.definition.items if rptt.definition else [] - parmspec = rptt.parmspec.items if rptt.parmspec else [] + parmspec = rptt.parameters.items if rptt.parameters else [] report_id, report_def_id, report_act_id = self.make_sql_ids(self._make_ari(cs.RPTT, rptt)) @@ -731,7 +739,7 @@ def write_ctrl_functions(self): fp_spec_id = self._var_name("fp_spec_id") lines += [insert_formal_parmspec_template.format(len(parmspec), ctrl_name, fp_spec_id, ctrl_id)] for parm in parmspec: - lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.typeobj.type_text)] + lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.name)] else: fp_spec_id = "null" @@ -759,11 +767,10 @@ def write_gen_const_functions(self, objects, coll): c_desc = escape_description_sql(obj.description) const_id, const_def_id, const_act_id = self.make_sql_ids(self._make_ari(coll, obj)) - lines += [ "", insert_obj_template.format(c_name, const_id), - insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj.type_text, obj.init_value, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.init_value, const_act_id), ] return lines @@ -779,14 +786,34 @@ def write_const_functions(self): return lines + self.write_gen_const_functions(self.adm.const, cs.CONST) def write_mdat_functions(self): - ''' Generate lines for all of the MDATs in the ADM + ''' Genreate lines for all of the MDATs in the ADM ''' + coll = cs.META + objects = self.adm.metadata_list.items + insert_obj_template = self.create_insert_obj_metadata_template(coll) + + # Format with const id, definition, type, value, and const def id + insert_const_actual_def_template = "CALL SP__insert_const_actual_definition({}, '{}', '{}', '{}', {});" + lines = [ "", "", "-- MDAT", ] - return lines + self.write_gen_const_functions(self.adm.ident, cs.META) + for obj in objects: + c_name = obj.name + c_desc = escape_description_sql(obj.arg) + + const_id, const_def_id, const_act_id = self.make_sql_ids(self._make_ari(coll, obj)) + + lines += [ + "", + insert_obj_template.format(c_name, const_id), + #using metadata keyword for type + insert_const_actual_def_template.format(const_id, c_desc, obj.name, obj.arg, const_act_id), + ] + + return lines def write_mac_functions(self): @@ -811,7 +838,7 @@ def write_mac_functions(self): for mac in self.adm.mac: mac_name = mac.name mac_desc = escape_description_sql(mac.description) - parmspec = mac.parmspec.items if mac.parmspec else [] + parmspec = mac.parameters.items if mac.parameters else [] num_parmspec = len(parmspec) definition = mac.action.items if mac.action else [] @@ -825,7 +852,7 @@ def write_mac_functions(self): fp_spec_id = self._var_name("fp_spec_id") lines += [insert_formal_parmspec_template.format(len(parmspec), mac_name, fp_spec_id)] for parm in parmspec: - lines += [insert_ac_formal_parmspec_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.typeobj.type_text)] + lines += [insert_ac_formal_parmspec_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.type)] lines += [insert_ac_id_template.format(num_parmspec, mac_name)] From 3749ad0a4f1c81d0daea3edda0790d630b2dd97e Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 15 Aug 2024 17:39:58 -0400 Subject: [PATCH 29/63] revert enum names to norm_name + upper() when applicable --- src/camp/generators/create_gen_h.py | 50 ++++++++++++++-------------- src/camp/generators/create_impl_c.py | 4 +-- src/camp/generators/create_impl_h.py | 4 +-- src/camp/generators/create_mgr_c.py | 18 +++++----- src/camp/generators/create_sql.py | 12 +++---- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 2c96043..5a35d69 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -74,7 +74,7 @@ def write(self, outfile: TextIO): # def write_defines(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = str(self.adm.enum) + ns_upper = str(self.adm.norm_name).upper() defines_str = """\ #ifndef ADM_{0}_H_ @@ -91,7 +91,7 @@ def write_defines(self, outfile): # def write_endifs(self, outfile): name_upper = self.adm.norm_name.upper() - ns_upper = str(self.adm.enum) + ns_upper = str(self.adm.norm_name).upper() endifs_str = """\ #endif /* _HAVE_{1}_ADM_ */ @@ -121,9 +121,9 @@ def write_adm_template_documentation(self, outfile): * ADM ROOT STRING:{} */ """ - outfile.write(documentation_str.format(header_str, self.adm.enum)) + outfile.write(documentation_str.format(header_str, self.adm.norm_name)) - g_var_idx = f"g_{self.adm.enum}_idx" + g_var_idx = f"g_{self.adm.norm_name}_idx" outfile.write("extern vec_idx_t {}[11];\n".format(g_var_idx)) # @@ -133,9 +133,9 @@ def write_agent_nickname_definitions(self, outfile): header_str = campch.make_formatted_comment_header("AGENT NICKNAME DEFINITIONS", True, True) outfile.write(header_str) - ns = str(self.adm.enum) + ns = str(self.adm.norm_name).upper() enum_name = cu.make_enum_name_from_str(ns) - outfile.write("#define {0} {1}\n".format(enum_name, self.adm.enum)) + outfile.write("#define {0} {1}\n".format(enum_name, self.adm.norm_name)) # # Function for formatting the description field in the tables. @@ -290,7 +290,7 @@ def write_metadata_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.metadata_list.items: #hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.META, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.META, obj) table = table + self.format_table_entry(False, obj.name, ari_str, obj.name, obj.arg)#obj.description, obj.type, obj.value) @@ -298,7 +298,7 @@ def write_metadata_definitions(self, outfile): #defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} META-DATA DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} META-DATA DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -315,13 +315,13 @@ def write_edd_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.edd: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.EDD, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.EDD, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} EXTERNALLY DEFINED DATA DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} EXTERNALLY DEFINED DATA DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -338,13 +338,13 @@ def write_variable_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.var: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.VAR, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.VAR, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} VARIABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} VARIABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -361,13 +361,13 @@ def write_rptt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.rptt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.RPTT, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.RPTT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "TNVC", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} REPORT DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} REPORT DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -384,13 +384,13 @@ def write_tblt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.tblt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.TBLT, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.TBLT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} TABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} TABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -407,13 +407,13 @@ def write_ctrl_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.ctrl: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.CTRL, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.CTRL, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} CONTROL DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} CONTROL DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -430,13 +430,13 @@ def write_const_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.const: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.CONST, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.CONST, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), obj.init_value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} CONSTANT DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} CONSTANT DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -453,13 +453,13 @@ def write_op_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.oper: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.enum), cs.OP, obj) + ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.OP, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.result.name, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} OPERATOR DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} OPERATOR DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -476,13 +476,13 @@ def write_macro_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.mac: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.enum, cs.MACRO, obj) + ari_str = cu.make_ari_name(self.adm.norm_name, cs.MACRO, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "mc", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.enum} MACRO DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.adm.norm_name} MACRO DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -492,7 +492,7 @@ def write_macro_definitions(self, outfile): # name is the name returned by get_adm_names() # def write_initialization_functions(self, outfile): - name = self.adm.enum + name = self.adm.norm_name body = ( "/* Initialization functions. */\n" "void {0}_init();\n" diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 4e2c543..5a7dac3 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -78,7 +78,7 @@ def write(self, outfile: TextIO): # scraper is the Scraper class object for this ADM # def write_setup(self, outfile): - outfile.write("void {}_setup()\n{{\n\n".format(self.adm.enum)) + outfile.write("void {}_setup()\n{{\n\n".format(self.adm.norm_name)) self._scraper.write_custom_body(outfile, "setup") @@ -91,7 +91,7 @@ def write_setup(self, outfile): # scraper is the Scraper class object for this ADM # def write_cleanup(self, outfile): - outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.enum)) + outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.norm_name)) self._scraper.write_custom_body(outfile, "cleanup") diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index 7182a65..df7a963 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -67,8 +67,8 @@ def write(self, outfile: TextIO): self._scraper.write_custom_functions(outfile) # The setup and clean up functions - outfile.write(f"void {self.adm.enum}_setup();\n") - outfile.write(f"void {self.adm.enum}_cleanup();\n\n") + outfile.write(f"void {self.adm.norm_name}_setup();\n") + outfile.write(f"void {self.adm.norm_name}_cleanup();\n\n") self.write_metadata_functions(outfile) self.write_constant_functions(outfile) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 6dc6c70..11c9f54 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -53,7 +53,7 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = f"g_{self.adm.enum}_idx" + self._g_var_idx = f"g_{self.adm.norm_name}_idx" def file_path(self) -> str: # Interface for AbstractWriter @@ -131,7 +131,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" add_str_template = self._make_std_adm_build_add_template(coll_type) - meta_add_template = campch.make_std_meta_add_coll_template(coll_type, str(self.adm.enum)) + meta_add_template = campch.make_std_meta_add_coll_template(coll_type, str(self.adm.norm_name)) added_coll = False added_parm = False @@ -183,7 +183,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.enum), coll_type, body) + campch.write_formatted_init_function(outfile, str(self.adm.norm_name), coll_type, body) # # Writes the init_metadata() function to the open file descriptor passed as c_file @@ -259,14 +259,14 @@ def write_init_ops(self, outfile): add_op_ari_template = "\n\tadm_add_op_ari(id, {}, NULL);" build_str_template = campch.make_adm_build_ari_template(cs.OP, self._g_var_idx, True) - meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, str(self.adm.enum)) + meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, str(self.adm.norm_name)) added_coll = False added_parm = False for obj in self.adm.oper: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(str(self.adm.enum), cs.OP, obj) + ari = cu.make_ari_name(str(self.adm.norm_name), cs.OP, obj) amp_type = cu.make_amp_type_name_from_str(obj.result.name) in_types = obj.operands.items if obj.operands.items else [] @@ -298,7 +298,7 @@ def write_init_ops(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.enum), cs.OP, body) + campch.write_formatted_init_function(outfile, str(self.adm.norm_name), cs.OP, body) # # Writes the init_variables() function to the open file descriptor passed as c_file @@ -320,7 +320,7 @@ def write_init_controls_function(self, outfile): build_str_template = campch.make_adm_build_ari_template(cs.CTRL, self._g_var_idx, True) add_ctrldef_template = "\n\tadm_add_ctrldef_ari(id, {}, NULL);" - enum_name = cu.make_enum_name_from_str(str(self.adm.enum)) + enum_name = cu.make_enum_name_from_str(str(self.adm.norm_name)) meta_add_template = "meta_add_" + cs.get_sname(cs.CTRL).lower() + "(id, " + enum_name + ", \"{0}\", \"{1}\");\n" added_coll = False @@ -328,7 +328,7 @@ def write_init_controls_function(self, outfile): for obj in self.adm.ctrl: # Gather the pieces of data that we need - ari = cu.make_ari_name(str(self.adm.enum), cs.CTRL, obj) + ari = cu.make_ari_name(str(self.adm.norm_name), cs.CTRL, obj) parms = obj.parameters.items if obj.parameters else [] # Format the meta_add_.* template for this item @@ -360,7 +360,7 @@ def write_init_controls_function(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.enum), cs.CTRL, body) + campch.write_formatted_init_function(outfile, str(self.adm.norm_name), cs.CTRL, body) # diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 89ed0bd..cd9f9a9 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -138,7 +138,7 @@ def _make_ari(self, coll, item): :param item: object to make the IDs for. :return: the augmented ARI text. ''' - ns = str(self.adm.enum) + ns = str(self.adm.norm_name).upper() ari = cu.make_ari_name(ns, coll, item).lower() return ari @@ -180,7 +180,7 @@ def create_insert_obj_metadata_template(self, obj_type): # convert to object type enumeration to decimal for function obj_type_enum = str(int(cs.ari_type_enum(obj_type), 16)) - formatted = general_template.format(obj_type_enum, "{}", self.adm.enum, "{}")#self._sql_ns, "{}") + formatted = general_template.format(obj_type_enum, "{}", self.adm.norm_name, "{}")#self._sql_ns, "{}") return formatted @@ -304,13 +304,13 @@ def body_pre(self): "", "use amp_core;", "", - "SET @adm_enum = {};".format(self.adm.enum) + "SET @adm_enum = {};".format(self.adm.norm_name) ] elif self.dialect == 'pgsql': lines += [ "DO", "$do$", - "DECLARE adm_enum INTEGER := {};".format(self.adm.enum), + "DECLARE adm_enum INTEGER := {};".format(self.adm.norm_name), ] for name in sorted(self._vars_def): lines.append(f"DECLARE {name} INTEGER;") @@ -347,14 +347,14 @@ def val_or_none(obj, attr='arg'): name = val_or_none(self.admset.get_child(self.adm, 'name')) #ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) - ns = self.adm.norm_name + ns = self.adm.norm_name.upper() version = val_or_none(self.admset.get_child(self.adm, 'version')) org = val_or_none(self.admset.get_child(self.adm, 'organization')) desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg)#val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) - formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.adm.enum)#self._sql_ns) + formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.adm.norm_name)#self._sql_ns) return [ "", formatted_template From 1a4827237d8572f4622200c1736e351e59efe57e Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 11:30:28 -0400 Subject: [PATCH 30/63] handle yang identifier to c string translation --- src/camp/generators/create_agent_c.py | 31 ++++++------- src/camp/generators/create_gen_h.py | 64 ++++++++++++++------------- src/camp/generators/create_impl_c.py | 12 ++--- src/camp/generators/create_impl_h.py | 14 +++--- src/camp/generators/create_mgr_c.py | 34 +++++++------- src/camp/generators/lib/campch.py | 48 ++++++++++---------- src/camp/generators/lib/camputil.py | 7 +++ 7 files changed, 114 insertions(+), 96 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index a268a6f..7815142 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -36,15 +36,16 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = "g_" + self.adm.norm_name.lower() + "_idx" + self.c_norm_name = cu.yang_to_c(self.adm.norm_name) + self._g_var_idx = "g_" + self.c_norm_name.lower() + "_idx" def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "agent", f"adm_{self.adm.norm_name}_agent.c") + return os.path.join(self.out_path, "agent", f"adm_{self.c_norm_name}_agent.c") def write(self, outfile: TextIO): # Interface for AbstractWriter - campch.write_c_file_header(outfile, f"adm_{self.adm.norm_name}_agent.c") + campch.write_c_file_header(outfile, f"adm_{self.c_norm_name}_agent.c") self.write_includes(outfile) outfile.write("vec_idx_t {}[11];\n\n".format(self._g_var_idx)) @@ -72,11 +73,11 @@ def write_includes(self, outfile): files = [ "ion.h", "platform.h", - f"adm_{self.adm.norm_name}.h", + f"adm_{self.c_norm_name}.h", "shared/utils/utils.h", "shared/primitives/report.h", "shared/primitives/blob.h", - f"adm_{self.adm.norm_name}_impl.h", + f"adm_{self.c_norm_name}_impl.h", "agent/rda.h", ] outfile.write(campch.make_includes(files)) @@ -129,11 +130,11 @@ def write_init_metadata_function(self, outfile): for obj in self.adm.metadata_list.items: _,fname,_ = campch.make_meta_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_name, cs.META, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.META, obj) body += add_str_template.format("0", ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.META, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.META, body) # # Constructs and writes the init_constants function @@ -148,7 +149,7 @@ def write_init_constant_function(self, outfile): for obj in self.adm.const: parms_tf = "0" _,fname,_ = campch.make_constant_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_name, cs.CONST, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.CONST, obj) #FIXME: can const have parameters? # if obj.paramspec: @@ -156,7 +157,7 @@ def write_init_constant_function(self, outfile): body += add_str.format(parms_tf, ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CONST, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.CONST, body) # # Constructs and writes the init_edd function @@ -171,14 +172,14 @@ def write_init_edd_function(self, outfile): for obj in self.adm.edd: parms_tf = "0" _,fname,_ = campch.make_collect_function(self.adm, obj) - ari = cu.make_ari_name(self.adm.norm_name, cs.EDD, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.EDD, obj) if hasattr(obj, 'parameters') and obj.parameters.items: parms_tf = "1" body += add_str.format(parms_tf, ari, fname) - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.EDD, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.EDD, body) # @@ -193,12 +194,12 @@ def write_init_op_function(self, outfile): adm_add_op_template = "\n\tadm_add_"+cs.get_sname(cs.OP)+"(" + self._g_var_idx + "["+cs.get_adm_idx(cs.OP)+"], {0}, {1}, {2});" for obj in self.adm.oper: - ari = cu.make_ari_name(self.adm.norm_name, cs.OP, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.OP, obj) in_types = obj.operands.items if obj.operands.items else [] body += adm_add_op_template.format(ari, len(in_types), ari.lower()) - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.OP, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.OP, body) # # Writes the init_variables body @@ -220,11 +221,11 @@ def write_init_control_function(self, outfile): adm_add_template = "\n\tadm_add_ctrldef(" + self._g_var_idx + "["+cs.get_adm_idx(cs.CTRL)+"], {0}, {1}, {2});" for obj in self.adm.ctrl: - ari = cu.make_ari_name(self.adm.norm_name, cs.CTRL, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.CTRL, obj) parms = obj.parameters.items if hasattr(obj, 'parameters') else [] body += adm_add_template.format(ari, len(parms), ari.lower()) - campch.write_formatted_init_function(outfile, self.adm.norm_name, cs.CTRL, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.CTRL, body) # # Constructs and writes the init_macros function diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 5a35d69..f745768 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -36,14 +36,18 @@ class Writer(AbstractWriter, CHelperMixin): ''' The common header file writer. ''' + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.c_norm_name = cu.yang_to_c(self.adm.norm_name) + def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "shared", "adm", f"adm_{self.adm.norm_name}.h") + return os.path.join(self.out_path, "shared", "adm", f"adm_{self.c_norm_name}.h") def write(self, outfile: TextIO): # Interface for AbstractWriter - campch.write_h_file_header(outfile, f"adm_{self.adm.norm_name}.h") + campch.write_h_file_header(outfile, f"adm_{self.c_norm_name}.h") self.write_defines(outfile) self.write_includes(outfile) @@ -54,7 +58,7 @@ def write(self, outfile: TextIO): self.write_metadata_definitions(outfile) self.write_edd_definitions(outfile) - self.write_variable_definitions(outfile) + # self.write_variable_definitions(outfile) # self.write_rptt_definitions(outfile) # self.write_tblt_definitions(outfile) self.write_ctrl_definitions(outfile) @@ -73,8 +77,8 @@ def write(self, outfile: TextIO): # name and ns are the values returned from get_adm_names # def write_defines(self, outfile): - name_upper = self.adm.norm_name.upper() - ns_upper = str(self.adm.norm_name).upper() + name_upper = self.c_norm_name.upper() + ns_upper = self.c_norm_name.upper() defines_str = """\ #ifndef ADM_{0}_H_ @@ -90,8 +94,8 @@ def write_defines(self, outfile): # name and ns are the names returned by get_adm_names() # def write_endifs(self, outfile): - name_upper = self.adm.norm_name.upper() - ns_upper = str(self.adm.norm_name).upper() + name_upper = self.c_norm_name.upper() + ns_upper = self.c_norm_name.upper() endifs_str = """\ #endif /* _HAVE_{1}_ADM_ */ @@ -121,9 +125,9 @@ def write_adm_template_documentation(self, outfile): * ADM ROOT STRING:{} */ """ - outfile.write(documentation_str.format(header_str, self.adm.norm_name)) + outfile.write(documentation_str.format(header_str, self.c_norm_name)) - g_var_idx = f"g_{self.adm.norm_name}_idx" + g_var_idx = f"g_{self.c_norm_name}_idx" outfile.write("extern vec_idx_t {}[11];\n".format(g_var_idx)) # @@ -133,9 +137,9 @@ def write_agent_nickname_definitions(self, outfile): header_str = campch.make_formatted_comment_header("AGENT NICKNAME DEFINITIONS", True, True) outfile.write(header_str) - ns = str(self.adm.norm_name).upper() + ns = self.c_norm_name.upper() enum_name = cu.make_enum_name_from_str(ns) - outfile.write("#define {0} {1}\n".format(enum_name, self.adm.norm_name)) + outfile.write("#define {0} {1}\n".format(enum_name, self.c_norm_name)) # # Function for formatting the description field in the tables. @@ -290,7 +294,7 @@ def write_metadata_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.metadata_list.items: #hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.META, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.META, obj) table = table + self.format_table_entry(False, obj.name, ari_str, obj.name, obj.arg)#obj.description, obj.type, obj.value) @@ -298,7 +302,7 @@ def write_metadata_definitions(self, outfile): #defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} META-DATA DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} META-DATA DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -315,13 +319,13 @@ def write_edd_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.edd: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.EDD, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.EDD, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} EXTERNALLY DEFINED DATA DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} EXTERNALLY DEFINED DATA DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -338,13 +342,13 @@ def write_variable_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.var: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.VAR, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.VAR, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} VARIABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} VARIABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -361,13 +365,13 @@ def write_rptt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.rptt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.RPTT, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.RPTT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "TNVC", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} REPORT DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} REPORT DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -384,13 +388,13 @@ def write_tblt_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.tblt: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.TBLT, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.TBLT, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # Write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} TABLE DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} TABLE DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -407,13 +411,13 @@ def write_ctrl_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.ctrl: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.CTRL, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.CTRL, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} CONTROL DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} CONTROL DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -430,13 +434,13 @@ def write_const_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.const: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.CONST, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.CONST, obj) table = table + self.format_table_entry(False, obj.name, obj.description, type(obj), obj.init_value) defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} CONSTANT DEFINITIONS", True) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} CONSTANT DEFINITIONS", True) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -453,13 +457,13 @@ def write_op_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.oper: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(str(self.adm.norm_name), cs.OP, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.OP, obj) table = table + self.format_table_entry(False, obj.name, obj.description, obj.result.name, "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name.upper()} OPERATOR DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} OPERATOR DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -476,13 +480,13 @@ def write_macro_definitions(self, outfile): # Create the strings for the #defines and preceeding commented table for obj in self.adm.mac: hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.adm.norm_name, cs.MACRO, obj) + ari_str = cu.make_ari_name(self.c_norm_name, cs.MACRO, obj) table = table + self.format_table_entry(False, obj.name, obj.description, "mc", "") defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) # write everything to file - self.write_definition_table_header(outfile, f"{self.adm.norm_name} MACRO DEFINITIONS", False) + self.write_definition_table_header(outfile, f"{self.c_norm_name} MACRO DEFINITIONS", False) outfile.write(table + " */\n") outfile.write(defines + "\n") @@ -492,7 +496,7 @@ def write_macro_definitions(self, outfile): # name is the name returned by get_adm_names() # def write_initialization_functions(self, outfile): - name = self.adm.norm_name + name = self.c_norm_name body = ( "/* Initialization functions. */\n" "void {0}_init();\n" diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 5a7dac3..151103a 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -39,23 +39,25 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, admset, adm, out_path, scrape: bool): super().__init__(admset, adm, out_path) + self.c_norm_name = cu.yang_to_c(self.adm.norm_name) + full_path = self.file_path() scrape_src = full_path if scrape and os.path.exists(full_path) else None self._scraper = C_Scraper(scrape_src) def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "agent", f"adm_{self.adm.norm_name}_impl.c") + return os.path.join(self.out_path, "agent", f"adm_{self.c_norm_name}_impl.c") def write(self, outfile: TextIO): # Interface for AbstractWriter - campch.write_c_file_header(outfile, f"adm_{self.adm.norm_name}_impl.c") + campch.write_c_file_header(outfile, f"adm_{self.c_norm_name}_impl.c") # Custom includes tag self._scraper.write_custom_includes(outfile) outfile.write(campch.make_includes([ "shared/adm/adm.h", - "adm_{}_impl.h".format(self.adm.norm_name.lower()) + "adm_{}_impl.h".format(self.c_norm_name.lower()) ])) # Add any custom functions scraped @@ -78,7 +80,7 @@ def write(self, outfile: TextIO): # scraper is the Scraper class object for this ADM # def write_setup(self, outfile): - outfile.write("void {}_setup()\n{{\n\n".format(self.adm.norm_name)) + outfile.write("void {}_setup()\n{{\n\n".format(self.c_norm_name)) self._scraper.write_custom_body(outfile, "setup") @@ -91,7 +93,7 @@ def write_setup(self, outfile): # scraper is the Scraper class object for this ADM # def write_cleanup(self, outfile): - outfile.write("void {}_cleanup()\n{{\n\n".format(self.adm.norm_name)) + outfile.write("void {}_cleanup()\n{{\n\n".format(self.c_norm_name)) self._scraper.write_custom_body(outfile, "cleanup") diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index df7a963..607703c 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -40,17 +40,19 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, admset, adm, out_path, scrape: bool): super().__init__(admset, adm, out_path) + self.c_norm_name = cu.yang_to_c(self.adm.norm_name) + full_path = self.file_path() scrape_src = full_path if scrape and os.path.exists(full_path) else None self._scraper = H_Scraper(scrape_src) def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "agent", f"adm_{self.adm.norm_name}_impl.h") + return os.path.join(self.out_path, "agent", f"adm_{self.c_norm_name}_impl.h") def write(self, outfile: TextIO): # Interface for AbstractWriter - campch.write_h_file_header(outfile, f"adm_{self.adm.norm_name}_impl.h") + campch.write_h_file_header(outfile, f"adm_{self.c_norm_name}_impl.h") self.write_defines(outfile) @@ -67,8 +69,8 @@ def write(self, outfile: TextIO): self._scraper.write_custom_functions(outfile) # The setup and clean up functions - outfile.write(f"void {self.adm.norm_name}_setup();\n") - outfile.write(f"void {self.adm.norm_name}_cleanup();\n\n") + outfile.write(f"void {self.c_norm_name}_setup();\n") + outfile.write(f"void {self.c_norm_name}_cleanup();\n\n") self.write_metadata_functions(outfile) self.write_constant_functions(outfile) @@ -86,7 +88,7 @@ def write(self, outfile: TextIO): # name is the name returned from get_adm_names() # def write_defines(self, outfile): - name_upper = self.adm.norm_name.upper() + name_upper = self.c_norm_name.upper() define_str = """\ #ifndef ADM_{0}_IMPL_H_ #define ADM_{0}_IMPL_H_ @@ -95,7 +97,7 @@ def write_defines(self, outfile): outfile.write(define_str.format(name_upper)) def write_endifs(self, outfile): - name_upper = self.adm.norm_name.upper() + name_upper = self.c_norm_name.upper() endifs_str = """\ #endif /* ADM_{0}_IMPL_H_ */ diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 11c9f54..d6e3684 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -53,15 +53,17 @@ class Writer(AbstractWriter, CHelperMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._g_var_idx = f"g_{self.adm.norm_name}_idx" + + self.c_norm_name = cu.yang_to_c(self.adm.norm_name) + self._g_var_idx = f"g_{self.c_norm_name}_idx" def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "mgr", f"adm_{self.adm.norm_name}_mgr.c") + return os.path.join(self.out_path, "mgr", f"adm_{self.c_norm_name}_mgr.c") def write(self, outfile: TextIO): # Interface for AbstractWriter - campch.write_c_file_header(outfile, f"adm_{self.adm.norm_name}_mgr.c") + campch.write_c_file_header(outfile, f"adm_{self.c_norm_name}_mgr.c") # calling each of the helper functions to handle the writing of # various functions in this file @@ -91,7 +93,7 @@ def write_includes(self, outfile): files = [ "ion.h", "platform.h", - f"adm_{self.adm.norm_name}.h", + f"adm_{self.c_norm_name}.h", "shared/utils/utils.h", "shared/primitives/report.h", "shared/primitives/blob.h", @@ -131,7 +133,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" add_str_template = self._make_std_adm_build_add_template(coll_type) - meta_add_template = campch.make_std_meta_add_coll_template(coll_type, str(self.adm.norm_name)) + meta_add_template = campch.make_std_meta_add_coll_template(coll_type, self.c_norm_name) added_coll = False added_parm = False @@ -139,7 +141,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): for obj in objlist: try: # Gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_name, coll_type, obj) + ari = cu.make_ari_name(self.c_norm_name, coll_type, obj) amp_type = cu.make_amp_type_name_from_str(obj.name) paramspec = getattr(obj, 'parameters', None) parms = paramspec.items if paramspec else [] @@ -183,7 +185,7 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.norm_name), coll_type, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, coll_type, body) # # Writes the init_metadata() function to the open file descriptor passed as c_file @@ -198,7 +200,7 @@ def write_init_metadata(self, outfile): coll_decl_str = "\n\tari_t *id = NULL;\n" parm_decl_str = "\n\tmetadata_t *meta = NULL;\n" - meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.adm.norm_namespace) + meta_add_template = campch.make_std_meta_add_coll_template(cs.CONST, self.c_norm_namespace) # NOTE: this function uses the CONST modifiers for most things, but needs the META IDX here: const_idx = cs.get_adm_idx(cs.CONST) @@ -210,7 +212,7 @@ def write_init_metadata(self, outfile): for obj in self.adm.mdat: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(self.adm.norm_namespace, cs.META, obj) + ari = cu.make_ari_name(self.c_norm_namespace, cs.META, obj) amp_type = cu.make_amp_type_name_from_str(obj.type) # format the meta_add_.* template for this item @@ -228,7 +230,7 @@ def write_init_metadata(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, self.adm.norm_namespace, cs.META, body) + campch.write_formatted_init_function(outfile, self.c_norm_namespace, cs.META, body) # # Writes the init_constants() function to the open file descriptor passed as c_file @@ -259,14 +261,14 @@ def write_init_ops(self, outfile): add_op_ari_template = "\n\tadm_add_op_ari(id, {}, NULL);" build_str_template = campch.make_adm_build_ari_template(cs.OP, self._g_var_idx, True) - meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, str(self.adm.norm_name)) + meta_add_template = campch.make_std_meta_add_coll_template(cs.OP, self.c_norm_name) added_coll = False added_parm = False for obj in self.adm.oper: # Preliminary; gather all of the pieces of data we need - ari = cu.make_ari_name(str(self.adm.norm_name), cs.OP, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.OP, obj) amp_type = cu.make_amp_type_name_from_str(obj.result.name) in_types = obj.operands.items if obj.operands.items else [] @@ -298,7 +300,7 @@ def write_init_ops(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.norm_name), cs.OP, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.OP, body) # # Writes the init_variables() function to the open file descriptor passed as c_file @@ -320,7 +322,7 @@ def write_init_controls_function(self, outfile): build_str_template = campch.make_adm_build_ari_template(cs.CTRL, self._g_var_idx, True) add_ctrldef_template = "\n\tadm_add_ctrldef_ari(id, {}, NULL);" - enum_name = cu.make_enum_name_from_str(str(self.adm.norm_name)) + enum_name = cu.make_enum_name_from_str(self.c_norm_name) meta_add_template = "meta_add_" + cs.get_sname(cs.CTRL).lower() + "(id, " + enum_name + ", \"{0}\", \"{1}\");\n" added_coll = False @@ -328,7 +330,7 @@ def write_init_controls_function(self, outfile): for obj in self.adm.ctrl: # Gather the pieces of data that we need - ari = cu.make_ari_name(str(self.adm.norm_name), cs.CTRL, obj) + ari = cu.make_ari_name(self.c_norm_name, cs.CTRL, obj) parms = obj.parameters.items if obj.parameters else [] # Format the meta_add_.* template for this item @@ -360,7 +362,7 @@ def write_init_controls_function(self, outfile): if added_coll: body = coll_decl_str + body - campch.write_formatted_init_function(outfile, str(self.adm.norm_name), cs.CTRL, body) + campch.write_formatted_init_function(outfile, self.c_norm_name, cs.CTRL, body) # diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 52c10b9..c7c1f2a 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -192,7 +192,7 @@ def make_formatted_comment_header(name, c_open, c_close): # def make_collect_function(adm, edd): basename = "get_{}".format(edd.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -203,7 +203,7 @@ def make_collect_function(adm, edd): def make_meta_function(adm, meta): keyword = cs.get_sname(cs.META) basename = "{0}_{1}".format(keyword, meta.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -214,7 +214,7 @@ def make_meta_function(adm, meta): def make_constant_function(adm, const): keyword = "get" basename = "{0}_{1}".format(keyword, const.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -225,7 +225,7 @@ def make_constant_function(adm, const): def make_control_function(adm, control): keyword = cs.get_sname(cs.CTRL) basename = "{0}_{1}".format(keyword, control.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tnv_t *{}(eid_t *def_mgr, tnvc_t *parms, int8_t *status)".format(fullname) return basename, fullname, signature @@ -236,7 +236,7 @@ def make_control_function(adm, control): def make_operator_function(adm, op): keyword = cs.get_sname(cs.OP) basename = "{0}_{1}".format(keyword, op.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tnv_t *{}(vector_t *stack)".format(fullname) return basename, fullname, signature @@ -247,7 +247,7 @@ def make_operator_function(adm, op): def make_table_function(adm, tbl): keyword = cs.get_sname(cs.TBLT) basename = "{0}_{1}".format(keyword, tbl.name.lower()) - fullname = "{0}_{1}".format(adm.norm_name.lower(), basename) + fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) signature = "tbl_t *{}(ari_t *id)".format(fullname) return basename, fullname, signature @@ -357,13 +357,13 @@ def write_init_macro_function(c_file, adm, g_var_idx, mgr): adm_add_macdef_str = "\n\tadm_add_macdef(def);" meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" - enum_name = cu.make_enum_name_from_str(adm.norm_name) + enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) meta_add_macro_template = "\n\tmeta = meta_add_macro" + "(def->ari, " + enum_name + ", \"{0}\", \"{1}\");" build_ari_str_template = make_adm_build_ari_template(cs.MACRO, g_var_idx, False) for obj in adm.mac: # Preliminaries - ari = cu.make_ari_name(adm.norm_name, cs.MACRO, obj) + ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.MACRO, obj) mac_name = obj.name description = obj.description or '' @@ -410,7 +410,7 @@ def write_init_macro_function(c_file, adm, g_var_idx, mgr): if added_meta: body = meta_decl_str + body - write_formatted_init_function(c_file, adm.norm_name, cs.MACRO, body) + write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.MACRO, body) # Builds a template for the # ``` @@ -448,14 +448,14 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): # gives you the adm_build_ari(...) build_str_template = "\n" + make_adm_build_ari_template(cs.VAR, g_var_idx, True) # gives you the meta_add_var(... ) - meta_add_template = make_std_meta_add_coll_template(cs.VAR, adm.norm_name) + meta_add_template = make_std_meta_add_coll_template(cs.VAR, cu.yang_to_c(adm.norm_name)) added_coll = False added_expr = False for obj in adm.var: # Preliminaries - ari = cu.make_ari_name(adm.norm_name, cs.VAR, obj) + ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.VAR, obj) amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) var_name = obj.name @@ -503,7 +503,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): if added_coll: body = coll_decl_str + body - write_formatted_init_function(c_file, adm.norm_name, cs.VAR, body) + write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.VAR, body) # @@ -527,7 +527,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): add_item_template = "\n\trpttpl_add_item(def, {});" adm_add_str = "\n\tadm_add_rpttpl(def);" - enum_name = cu.make_enum_name_from_str(adm.norm_name) + enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) meta_add_rpt_template = "meta_add_rpttpl(def->id, " + enum_name + ", \"{0}\", \"{1}\");" meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" @@ -536,7 +536,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): rpt_name = obj.name description = obj.description or '' - ari = cu.make_ari_name(adm.norm_name, cs.RPTT, obj) + ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.RPTT, obj) params = obj.parmspec.items if obj.parmspec else [] defs = obj.definition.items if obj.definition else [] @@ -589,7 +589,7 @@ def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): if added_meta: body = meta_decl_str + body - write_formatted_init_function(c_file, adm.norm_name, cs.RPTT, body) + write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.RPTT, body) # # Writes the init_tables funtion for the passed adm name and @@ -601,7 +601,7 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): tbl_create_template = "\n\tdef = tblt_create({0}, {1});" build_ari_template = make_adm_build_ari_template(cs.TBLT, g_var_idx, False) - enum_name = cu.make_enum_name_from_str(adm.norm_name) + enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) add_tblt_str = "\n\tadm_add_tblt(def);" meta_add_template = "\n\tmeta_add_tblt(def->id, " + enum_name + ", \"{0}\", \"{1}\");" @@ -611,7 +611,7 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): for obj in adm.tblt: # Preliminaries - ari = cu.make_ari_name(adm.norm_name, cs.TBLT, obj) + ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.TBLT, obj) tbl_name = obj.name description = obj.description or '' @@ -648,18 +648,18 @@ def write_init_tables_function(c_file, adm, g_var_idx, mgr): if added_table: body = tbl_decl_str + body - write_formatted_init_function(c_file, adm.norm_name, cs.TBLT, body) + write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.TBLT, body) # # Writes the init function to c_file # def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: bool): - enum_name = cu.make_enum_name_from_str(adm.norm_name) + enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) - vdb_adds = "\tadm_add_adm_info(\"" + adm.norm_name + "\", " + enum_name + ");\n" + vdb_adds = "\tadm_add_adm_info(\"" + cu.yang_to_c(adm.norm_name) + "\", " + enum_name + ");\n" vdb_add_template = "\n\tVDB_ADD_NN(((" + enum_name + " * 20) + {0}), &({1}[{0}]));" - init_decl_template = "static void " + adm.norm_name + "_init_{0}(void);\n" - init_call_template = "\n\t" + adm.norm_name + "_init_{0}();" + init_decl_template = "static void " + cu.yang_to_c(adm.norm_name) + "_init_{0}(void);\n" + init_call_template = "\n\t" + cu.yang_to_c(adm.norm_name) + "_init_{0}();" # order of init functions matters obj_types = { @@ -677,7 +677,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: init_decls = "" init_calls = "" if not mgr: - init_calls = "\n\t" + adm.norm_name + "_setup();" + init_calls = "\n\t" + cu.yang_to_c(adm.norm_name) + "_setup();" for coll, attrname in obj_types.items(): init_decls += init_decl_template.format(cs.get_sname(coll).lower()) @@ -691,7 +691,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: body = vdb_adds + "\n\n" + init_calls c_file.write(init_decls + "\n") - write_formatted_init_function(c_file, adm.norm_name, None, body) + write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), None, body) def make_cplusplus_open(): ''' Open an "extern C" block for C++ inclusion. ''' diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index 6300032..51923d0 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -80,3 +80,10 @@ def make_amp_type_name_from_str(t_name): # def make_enum_name_from_str(name): return "ADM_ENUM_{}".format(name.upper()) + +# +# Translates a valid YANG identifier to a valid C99 fragment +# identifier is a valid YANG identifier +# +def yang_to_c(identifier): + return identifier.replace('_','__').replace('-','_').replace('.','_p_') From b9ed96797695d343d9e29d9e931f1a3b8365ea10 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 13:45:35 -0400 Subject: [PATCH 31/63] metadata -- sanitize newlines so c output isn't broken across lines --- src/camp/generators/create_impl_c.py | 3 ++- src/camp/generators/create_sql.py | 2 +- src/camp/generators/lib/camputil.py | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 151103a..46ca5eb 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -116,8 +116,9 @@ def write_metadata_functions(self, outfile): "\n\n") for obj in self.adm.metadata_list.items: + val = cu.sanitize_newlines(obj.arg) _,_,signature = campch.make_meta_function(self.adm, obj) - outfile.write(metadata_funct_str.format(signature, obj.arg)) + outfile.write(metadata_funct_str.format(signature, val)) # # Writes the constant functions to the file passed diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index cd9f9a9..0d0ccb9 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -335,7 +335,7 @@ def body_post(self): return lines def write_metadata_function(self): - ''' Genreate lines for the ADM metadata + ''' Generate lines for the ADM metadata ''' # format with org, namespace, version, name, description from namespace, ns from get_highlevel_ns meta_template = "CALL SP__insert_adm_defined_namespace('{}', '{}', '{}', '{}', {}, NULL, '{}', {});" diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index 51923d0..82a575b 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -87,3 +87,10 @@ def make_enum_name_from_str(name): # def yang_to_c(identifier): return identifier.replace('_','__').replace('-','_').replace('.','_p_') + +# +# Adds \ to the end of a new line of string +# str is the string to be modified +# +def sanitize_newlines(str): + return str.replace("\n", "\\\n") \ No newline at end of file From 393e1d424659fd7add09c01b620bc396f9cf0373 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 14:05:04 -0400 Subject: [PATCH 32/63] fix the nickname (should've still been enum) --- src/camp/generators/create_gen_h.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index f745768..9f86c3c 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -139,7 +139,7 @@ def write_agent_nickname_definitions(self, outfile): ns = self.c_norm_name.upper() enum_name = cu.make_enum_name_from_str(ns) - outfile.write("#define {0} {1}\n".format(enum_name, self.c_norm_name)) + outfile.write("#define {0} {1}\n".format(enum_name, self.adm.enum)) # # Function for formatting the description field in the tables. @@ -292,14 +292,15 @@ def write_metadata_definitions(self, outfile): defines = "" # the #defines and for all metadata (string) # Create the strings for the #defines and preceeding commented table + enum = 0 for obj in self.adm.metadata_list.items: - #hex_str = format(obj.enum, '#04x') + hex_str = format(enum, '#04x') ari_str = cu.make_ari_name(self.c_norm_name, cs.META, obj) table = table + self.format_table_entry(False, obj.name, ari_str, obj.name, obj.arg)#obj.description, obj.type, obj.value) - defines = defines + "// \"{}\"\n".format(obj.name) - #defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) + defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) + enum += 1 # Write everything to file self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} META-DATA DEFINITIONS", True) From 33e1084397205be5639c2a7d48332454b4e16f9c Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 15:52:01 -0400 Subject: [PATCH 33/63] remove mac, rptt, tblt --- src/camp/generators/create_gen_h.py | 72 -------- src/camp/generators/create_sql.py | 158 ---------------- src/camp/generators/lib/campch.py | 231 ------------------------ src/camp/generators/lib/campsettings.py | 12 +- 4 files changed, 6 insertions(+), 467 deletions(-) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 9f86c3c..8af67a6 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -59,11 +59,8 @@ def write(self, outfile: TextIO): self.write_edd_definitions(outfile) # self.write_variable_definitions(outfile) - # self.write_rptt_definitions(outfile) - # self.write_tblt_definitions(outfile) self.write_ctrl_definitions(outfile) self.write_const_definitions(outfile) - # self.write_macro_definitions(outfile) self.write_op_definitions(outfile) self.write_initialization_functions(outfile) @@ -353,52 +350,6 @@ def write_variable_definitions(self, outfile): outfile.write(table + " */\n") outfile.write(defines + "\n") - # - # Writes the report template definitions and #defines to the file - # h_file is an open file descriptor to write to - # name and ns are the values returned by get_adm_names() - # templates is a list of report templates to include - # - def write_rptt_definitions(self, outfile): - table = "" # the commented table of all reports (string) - defines = "" # the #defines and for all reports (string) - - # Create the strings for the #defines and preceeding commented table - for obj in self.adm.rptt: - hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.c_norm_name, cs.RPTT, obj) - - table = table + self.format_table_entry(False, obj.name, obj.description, "TNVC", "") - defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) - - # Write everything to file - self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} REPORT DEFINITIONS", False) - outfile.write(table + " */\n") - outfile.write(defines + "\n") - - # - # Writes the table definitions and #defines to the file - # h_file is an open file descriptor to write to - # name and ns are the values returned by get_adm_names() - # tbls is a list of tabels to include - # - def write_tblt_definitions(self, outfile): - table = "" # the commented table of all tables (string) - defines = "" # the #defines and for all tables (string) - - # Create the strings for the #defines and preceeding commented table - for obj in self.adm.tblt: - hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.c_norm_name, cs.TBLT, obj) - - table = table + self.format_table_entry(False, obj.name, obj.description, "", "") - defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) - - # Write everything to file - self.write_definition_table_header(outfile, f"{self.c_norm_name.upper()} TABLE DEFINITIONS", False) - outfile.write(table + " */\n") - outfile.write(defines + "\n") - # # Writes the control definitions and #defines to the file # h_file is an open file descriptor to write to @@ -468,29 +419,6 @@ def write_op_definitions(self, outfile): outfile.write(table + " */\n") outfile.write(defines + "\n") - # - # Writes the macro definitions and #defines to the file - # h_file is an open file descriptor to write to - # name and ns are the values returned by get_adm_names() - # macros is a list of macros to include - # - def write_macro_definitions(self, outfile): - table = "" # the commented table of all macros (string) - defines = "" # the #defines and for all macros (string) - - # Create the strings for the #defines and preceeding commented table - for obj in self.adm.mac: - hex_str = format(obj.enum, '#04x') - ari_str = cu.make_ari_name(self.c_norm_name, cs.MACRO, obj) - - table = table + self.format_table_entry(False, obj.name, obj.description, "mc", "") - defines = defines + "#define {0} {1}\n".format(ari_str, hex_str) - - # write everything to file - self.write_definition_table_header(outfile, f"{self.c_norm_name} MACRO DEFINITIONS", False) - outfile.write(table + " */\n") - outfile.write(defines + "\n") - # # Writes the initialization functions' forward declars to the file # h_file is an open file descriptor to write to diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 0d0ccb9..72eefea 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -97,11 +97,8 @@ def write(self, outfile: TextIO): body += self.write_edd_functions() body += self.write_oper_functions() # body += self.write_var_functions() - # body += self.write_tblt_functions() - # body += self.write_rptt_functions() body += self.write_ctrl_functions() body += self.write_const_functions() - # body += self.write_mac_functions() head += self.body_pre() body += self.body_post() @@ -511,40 +508,6 @@ def write_var_functions(self): return lines - def write_tblt_functions(self): - ''' Genreate lines for all of the TBLTs in the ADM - ''' - lines = [ - "", - "", - "-- TBLT", - ] - - insert_obj_template = self.create_insert_obj_metadata_template(cs.TBLT) - - # Format with table object id (above), table description, tblt definition id - insert_def_template = "CALL SP__insert_table_template_actual_definition({}, '{}', " + self._var_name("tbl_tnvc_id") + ", {});" - - for tblt in self.adm.tblt: - tblt_name = tblt.name - tblt_desc = escape_description_sql(tblt.description) - - tblt_id, tblt_def_id, tblt_act_id = self.make_sql_ids(self._make_ari(cs.TBLT, tblt)) - add_tnvc_coll_template,insert_column_template,_ = self.create_insert_tnvc_templates(cs.TBL, len(tblt.columns.items)) - - lines += [ - "", - insert_obj_template.format(tblt_name, tblt_id), - add_tnvc_coll_template.format('columns for the '+tblt_name+' table'), - ] - - for col in tblt.columns.items: - lines += [insert_column_template.format(col.type.lower(), col.position + 1, "'" + col.name + "'", col.position + 1)] - - lines += [insert_def_template.format(tblt_id, tblt_desc, tblt_def_id)] - - return lines - def handle_report_fp_ap(self, item, lines, report_id): ''' Helper function to handle creation of stored procedures for the fps and aps within the reports templates in the ADM @@ -643,73 +606,6 @@ def handle_report_fp_ap(self, item, lines, report_id): return result - def write_rptt_functions(self): - ''' Genreate lines for all of the RPTTs in the ADM - ''' - lines = [ - "", - "", - "-- RPTT", - ] - - insert_report_template = self.create_insert_ac_id_template(cs.RPTT, "ac for report template {}") - insert_obj_template = self.create_insert_obj_metadata_template(cs.RPTT) - - # Format with entry id name and enum of entry - insert_entry_template = "CALL SP__insert_ac_actual_entry(" + self._var_name("rptt_ac_id") + ", {0}, {1}, " + self._var_name("r_ac_rpt_entry_", None) + "{1});" - - # Format with report id, report description, report_def_id - insert_formal_def_template = "CALL SP__insert_report_template_formal_definition({}, '{}', {}, " + self._var_name("rptt_ac_id") + ", {});" - # Format with report id, report name - insert_actual_def_template = "CALL SP__insert_report_actual_definition({0}, null, null, 'Singleton value for {1}', {2});" - for rptt in self.adm.rptt: - report_name = rptt.name - report_desc = escape_description_sql(rptt.description) - definitions = rptt.definition.items if rptt.definition else [] - parmspec = rptt.parameters.items if rptt.parameters else [] - - report_id, report_def_id, report_act_id = self.make_sql_ids(self._make_ari(cs.RPTT, rptt)) - - lines += [ - "", - insert_obj_template.format(report_name, report_id), - ] - - # For each definition in the rptt template - defn_lines = [ - insert_report_template.format(len(definitions), report_name, report_id), - ] - for item in definitions: - item_id = self.handle_report_fp_ap(item, lines, report_id) - - # preallocate names - self._var_name(item_id, False) - self._var_name(f"r_ac_rpt_entry_{item.position + 1}") - # Keeping this in a separate list because it has to happen - # after all of the calls to handle_report_fp_ap() - defn_lines += [insert_entry_template.format(item_id, item.position + 1)] - - lines += defn_lines - - # check if has formal parameter - if parmspec: - fp_spec_id = self._var_name("fp_spec_id") - else: - fp_spec_id = "null" - - self._var_name(report_def_id) - lines += [ - "", - insert_formal_def_template.format(report_id, report_desc, fp_spec_id, report_def_id), - ] - if not parmspec: - lines += [ - "", - insert_actual_def_template.format(report_id, report_name, report_act_id), - ] - - return lines - def write_ctrl_functions(self): ''' Genreate lines for all of the CTRLs in the ADM ''' @@ -815,60 +711,6 @@ def write_mdat_functions(self): return lines - - def write_mac_functions(self): - ''' Genreate lines for all of the MACs in the ADM - ''' - lines = [ - "", - "", - "-- MAC", - ] - - insert_obj_template = self.create_insert_obj_metadata_template(cs.MACRO) - insert_formal_parmspec_template, insert_ac_formal_parmspec_entry_template = self.create_insert_formal_parmspec_templates("parms for the {} macro") - insert_ac_id_template = self.create_insert_ac_id_template(cs.MACRO, "ac for {} macro") - - # Format with def id, def enumeration in this macro - insert_ac_formal_entry_template = "CALL SP__insert_ac_formal_entry(" + self._var_name("mac_ac_id") + ", {}, {}, " + self._var_name("r_ac_entry_id") + ");" - - # Format with mac id, description, fp_spec_id, number of parmspec (?), and mac def id - insert_mac_formal_def_template = "\nCALL SP__insert_macro_formal_definition({}, '{}', {}, {}, " + self._var_name("mac_ac_id") + ", {});" - - for mac in self.adm.mac: - mac_name = mac.name - mac_desc = escape_description_sql(mac.description) - parmspec = mac.parameters.items if mac.parameters else [] - num_parmspec = len(parmspec) - definition = mac.action.items if mac.action else [] - - mac_id, mac_def_id, mac_act_id = self.make_sql_ids(self._make_ari(cs.MACRO, m)) - lines += [ - "", - insert_obj_template.format(mac_name, mac_id), - ] - - if parmspec: - fp_spec_id = self._var_name("fp_spec_id") - lines += [insert_formal_parmspec_template.format(len(parmspec), mac_name, fp_spec_id)] - for parm in parmspec: - lines += [insert_ac_formal_parmspec_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.type)] - - lines += [insert_ac_id_template.format(num_parmspec, mac_name)] - - for item in definition: - def_id,_,_,_ = self.make_definition_ids(item) - lines += [insert_ac_formal_entry_template.format(def_id, item.position + 1)] - - #lines += [insert_mac_formal_def_template.format(mac_id, mac_desc, fp_spec_id, num_parmspec, mac_def_id)] - # according to the comment in all_routines.sql, - # num_parmspec at this line is p_max_call_depth int(10) unsigned - max call depth of the macro - # however, we don't know how to specify that - max_call_depth = 0 - lines += [insert_mac_formal_def_template.format(mac_id, mac_desc, fp_spec_id, max_call_depth, mac_def_id)] - - return lines - # If the setup.mysql file exists in the output dir, and this # file is not already sourced in the setup script, add it to # the file. diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index c7c1f2a..9e0c21d 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -240,18 +240,6 @@ def make_operator_function(adm, op): signature = "tnv_t *{}(vector_t *stack)".format(fullname) return basename, fullname, signature -# -# Makes and returns the basename, fullname, and signature tuple for the table -# functions; where basename = tbl_ and fullname = _ -# -def make_table_function(adm, tbl): - keyword = cs.get_sname(cs.TBLT) - basename = "{0}_{1}".format(keyword, tbl.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) - signature = "tbl_t *{}(ari_t *id)".format(fullname) - return basename, fullname, signature - - ##################### FUNCTIONS SHARED BY CREATE_MGR.PY AND CREATE_AGENT.PY ################### @@ -338,80 +326,6 @@ def _make_adm_build_ari_parm(adm, item, params): else: return make_adm_build_ari_template(item_coll, item_g_var_idx, False).format("0", item_ari) -# -# constructs and writes the init_macros function -# -# c_file is an open file descriptor to write to, -# name is the name of the adm from the caller; g_var_idx is the -# g_var_idx value in the calling function. -# -def write_init_macro_function(c_file, adm, g_var_idx, mgr): - body = "" - meta_decl_str = "\n\tmetadata_t *meta = NULL;\n" - macdef_decl_str = "\n\tmacdef_t *def = NULL;\n" - added_meta = False - added_macdef = False - - macdef_create_template = "macdef_create({0}, {1});" - add_macdef_ctrl_str = "\n\tadm_add_macdef_ctrl(def, {});" - adm_add_macdef_str = "\n\tadm_add_macdef(def);" - meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" - - enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) - meta_add_macro_template = "\n\tmeta = meta_add_macro" + "(def->ari, " + enum_name + ", \"{0}\", \"{1}\");" - build_ari_str_template = make_adm_build_ari_template(cs.MACRO, g_var_idx, False) - - for obj in adm.mac: - # Preliminaries - ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.MACRO, obj) - mac_name = obj.name - description = obj.description or '' - - acts = obj.action.items if obj.action else [] - parms = obj.parmspec.items if obj.parmspec else [] - - defs_str = "" - parms_tf = "0" - if parms: - parms_tf = "1" - - # Use templates to make calls specific to this macro - build_ari_str = build_ari_str_template.format(parms_tf, ari) - macdef_create_str = macdef_create_template.format(len(defs), build_ari_str) - if defs: - macdef_create_str = "\n\tdef = " + macdef_create_str - added_macdef = True - else: - macdef_create_str = "\n\t" + macdef_create_str - - - # Create necessary strings for each definition - for item in acts: - def_build_ari_parm_str = _make_adm_build_ari_parm(adm, item, parms); - defs_str += add_macdef_ctrl_str.format(def_build_ari_parm_str) - - # Add all the formatted strings to the body - body += "\n\n\t/* {} */".format(mac_name.upper()) - body += macdef_create_str - body += defs_str - body += adm_add_macdef_str - - # Additional strings to be added if this the the manager code - if mgr: - body += meta_add_macro_template.format(mac_name, description) - added_meta = True - for parm in parms: - amp_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) - body += meta_add_parm_template.format(parm.name, amp_type) - - # only add these declarations if the variables will be used; to avoid compiler warnings in C code - if added_macdef: - body = macdef_decl_str + body - if added_meta: - body = meta_decl_str + body - - write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.MACRO, body) - # Builds a template for the # ``` # meta_add_... @@ -505,151 +419,6 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.VAR, body) - -# -# writes the init_reports() function to the open file descriptor passed as c_file -# name is the value returned from get_adm_names() -# g_var_idx is the g_var_idx variable for the caller. Retriever is the retriever -# class instance to be used to populate the reports. -# mgr is a boolean value which will result in the addition of the meta_add_*() -# function for every report if == True -# -def write_parameterized_init_reports_function(c_file, adm, g_var_idx, mgr): - body = "" - rpt_decl_str = "\n\trpttpl_t *def = NULL;\n" - meta_decl_str = "\n\tmetadata_t *meta = NULL;\n" - added_rpt = False - added_meta = False - - rpt_create_template = "rpttpl_create_id({});" - build_ari_str_template = make_adm_build_ari_template(cs.RPTT, g_var_idx, False) - - add_item_template = "\n\trpttpl_add_item(def, {});" - adm_add_str = "\n\tadm_add_rpttpl(def);" - - enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) - meta_add_rpt_template = "meta_add_rpttpl(def->id, " + enum_name + ", \"{0}\", \"{1}\");" - meta_add_parm_template = "\n\tmeta_add_parm(meta, \"{0}\", {1});" - - for obj in adm.rptt: - # Preliminaries - rpt_name = obj.name - description = obj.description or '' - - ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.RPTT, obj) - params = obj.parmspec.items if obj.parmspec else [] - defs = obj.definition.items if obj.definition else [] - - defs_str = "" - params_tf = "0" - if params: - params_tf = "1" - - # The rpt_create template is slightly different depending on presence of defs - rpt_create_str = rpt_create_template.format(build_ari_str_template.format(params_tf, ari)) - if defs: - rpt_create_str = "\n\tdef = " + rpt_create_str - added_rpt = True - else: - rpt_create_str = "\n\t" + rpt_create_str - - # Add to the defs string for each definition found - for item in defs: - def_build_ari_str = _make_adm_build_ari_parm(adm, item, params) - defs_str += add_item_template.format(def_build_ari_str) - - # Add all formatted strings to the body - body += "\n\t/* {} */".format(obj.name.upper()) - body += rpt_create_str - body += defs_str - body += adm_add_str - - added_rpt = True - - # If this is the mgr code generation, need meta_add_rpt strings also - if mgr: - meta_add_rpt_str = meta_add_rpt_template.format(rpt_name, description) - - meta_add_parm_str = "" - if params: - meta_add_rpt_str = "meta = " + meta_add_rpt_str - added_meta = True - - # Create meta_add_parm string for each parameter found - for parm in params: - amp_type = cu.make_amp_type_name_from_str(parm.typeobj.type_text) - meta_add_parm_str += meta_add_parm_template.format(parm.name, amp_type) - - # Add to body string - body += "\n\t" + meta_add_rpt_str + meta_add_parm_str - - # only declare variables if they're going to be used - if added_rpt: - body = rpt_decl_str + body - if added_meta: - body = meta_decl_str + body - - write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.RPTT, body) - -# -# Writes the init_tables funtion for the passed adm name and -# retriever class instance. -# -def write_init_tables_function(c_file, adm, g_var_idx, mgr): - body = "" - tbl_decl_str = "\n\ttblt_t *def = NULL;" - tbl_create_template = "\n\tdef = tblt_create({0}, {1});" - - build_ari_template = make_adm_build_ari_template(cs.TBLT, g_var_idx, False) - enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) - - add_tblt_str = "\n\tadm_add_tblt(def);" - meta_add_template = "\n\tmeta_add_tblt(def->id, " + enum_name + ", \"{0}\", \"{1}\");" - add_col_template = "\n\ttblt_add_col(def, {0}, \"{1}\");" - - added_table = False - - for obj in adm.tblt: - # Preliminaries - ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.TBLT, obj) - tbl_name = obj.name - description = obj.description or '' - - cols = obj.columns.items if obj.columns else [] - cols_str = "" - - # Format the templates needed for the tables function - tbl_build_ari_str = build_ari_template.format("0", ari) - - # The appearance of this template depends on whether this is the mgr code or not - if mgr: - tbl_create_str = tbl_create_template.format(tbl_build_ari_str, "NULL") - else: - tbl_create_str = tbl_create_template.format(tbl_build_ari_str, ari.lower()) - - # Add to the cols string for each column present - for col in cols: - c_amp_type = cu.make_amp_type_name_from_str(col.type) - cols_str += add_col_template.format(c_amp_type, col.name) - - # Add formatted strings to the body - body += "\n\n\t/* {} */\n".format(tbl_name.upper()) - body += tbl_create_str - body += cols_str - body += add_tblt_str - - added_table = True - - # If this the the mgr code generation, also need to call meta_add function - if mgr: - body += meta_add_template.format(tbl_name, description) - - # tbl variable is only declared if needed; in order to avoid C compiler warnings for unused variable - if added_table: - body = tbl_decl_str + body - - write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.TBLT, body) - # # Writes the init function to c_file # diff --git a/src/camp/generators/lib/campsettings.py b/src/camp/generators/lib/campsettings.py index c3ccd5f..1e0b853 100644 --- a/src/camp/generators/lib/campsettings.py +++ b/src/camp/generators/lib/campsettings.py @@ -28,11 +28,11 @@ CONST = 0 CTRL = 1 EDD = 2 -MACRO = 3 +# MACRO = 3 OP = 4 -RPTT = 5 +# RPTT = 5 SBR = 6 -TBLT = 7 +# TBLT = 7 TBR = 8 VAR = 9 META = 10 @@ -45,11 +45,11 @@ collections[CONST] = {"sname":"cnst", "lname":"Const", "ari_type":"0", "amp_type":"cnst", "adm_idx":"Const"} # CONST = 0 collections[CTRL] = {"sname":"ctrl", "lname":"Ctrl", "ari_type":"1", "amp_type":"ctrl", "adm_idx":"Ctrl"} # CTRL = 1 collections[EDD] = {"sname":"edd", "lname":"Edd", "ari_type":"2", "amp_type":"edd", "adm_idx":"Edd"} # EDD = 2 -collections[MACRO] = {"sname":"mac", "lname":"Mac", "ari_type":"4", "amp_type":"mac", "adm_idx":"Mac"} # MACRO = 3 +# collections[MACRO] = {"sname":"mac", "lname":"Mac", "ari_type":"4", "amp_type":"mac", "adm_idx":"Mac"} # MACRO = 3 collections[OP] = {"sname":"op", "lname":"Oper", "ari_type":"5", "amp_type":"Oper", "adm_idx":"Oper"} # OP = 4 -collections[RPTT] = {"sname":"rpttpl", "lname":"Rptt", "ari_type":"7", "amp_type":"rpttpl", "adm_idx":"Rptt"} # RPTT = 5 +# collections[RPTT] = {"sname":"rpttpl", "lname":"Rptt", "ari_type":"7", "amp_type":"rpttpl", "adm_idx":"Rptt"} # RPTT = 5 collections[SBR] = {"sname":"sbr", "lname":"Sbr", "ari_type":"8", "amp_type":"sbr", "adm_idx":"Sbr"} # SBR = 6 -collections[TBLT] = {"sname":"tblt", "lname":"Tblt", "ari_type":"a", "amp_type":"tblt", "adm_idx":"Tblt"} # TBLT = 7 +# collections[TBLT] = {"sname":"tblt", "lname":"Tblt", "ari_type":"a", "amp_type":"tblt", "adm_idx":"Tblt"} # TBLT = 7 collections[TBR] = {"sname":"tbr", "lname":"Tbr", "ari_type":"b", "amp_type":"tbr", "adm_idx":"Tbr"} # TBR = 8 collections[VAR] = {"sname":"var", "lname":"Var", "ari_type":"c", "amp_type":"var", "adm_idx":"Var"} # VAR = 9 collections[META] = {"sname":"meta", "lname":"Mdat", "ari_type":"0", "amp_type":"cnst", "adm_idx":"Meta"} # META = 10 From 64deb58ba6a923c06471f32f6d31e1a2ebad4b02 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 15:52:08 -0400 Subject: [PATCH 34/63] dummy amp type --- src/camp/generators/lib/camputil.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index 82a575b..61083c4 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -72,7 +72,10 @@ def make_ari_name(name, coll, item): # t_name is the name of the type # def make_amp_type_name_from_str(t_name): - return "AMP_TYPE_{}".format(t_name.upper()) + # return "AMP_TYPE_{}".format(t_name.upper()) + + # TODO type fixes + return "AMP_TYPE_UNK" # # Makes and returns the adm enum type string for the passed From 077264ecd5c01e8ffa121c6923269d96d1f26bfc Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 16 Aug 2024 15:57:16 -0400 Subject: [PATCH 35/63] add var back in, remove more unused --- src/camp/generators/create_agent_c.py | 2 +- src/camp/generators/create_gen_h.py | 2 +- src/camp/generators/create_impl_c.py | 1 - src/camp/generators/create_impl_h.py | 1 - src/camp/generators/create_mgr_c.py | 5 +---- src/camp/generators/create_sql.py | 2 +- 6 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index 7815142..1246e5f 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -56,7 +56,7 @@ def write(self, outfile: TextIO): self.write_init_constant_function(outfile) self.write_init_edd_function(outfile) self.write_init_op_function(outfile) - # self.write_init_var_function(outfile) + self.write_init_var_function(outfile) self.write_init_control_function(outfile) # self.write_init_macro_function(outfile) # self.write_init_reports_function(outfile) diff --git a/src/camp/generators/create_gen_h.py b/src/camp/generators/create_gen_h.py index 8af67a6..3b3a4ff 100644 --- a/src/camp/generators/create_gen_h.py +++ b/src/camp/generators/create_gen_h.py @@ -58,7 +58,7 @@ def write(self, outfile: TextIO): self.write_metadata_definitions(outfile) self.write_edd_definitions(outfile) - # self.write_variable_definitions(outfile) + self.write_variable_definitions(outfile) self.write_ctrl_definitions(outfile) self.write_const_definitions(outfile) self.write_op_definitions(outfile) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 46ca5eb..a561945 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -68,7 +68,6 @@ def write(self, outfile: TextIO): self.write_metadata_functions(outfile) self.write_constant_functions(outfile) - # self.write_table_functions(outfile) self.write_edd_functions(outfile) self.write_control_functions(outfile) self.write_operator_functions(outfile) diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index 607703c..36a8232 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -77,7 +77,6 @@ def write(self, outfile: TextIO): self.write_collect_functions(outfile) self.write_control_functions(outfile) self.write_operator_functions(outfile) - # self.write_table_functions(outfile) outfile.write(campch.make_cplusplus_close()) self.write_endifs(outfile) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index d6e3684..dced794 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -76,11 +76,8 @@ def write(self, outfile: TextIO): self.write_init_constants(outfile) self.write_init_edd_function(outfile) self.write_init_ops(outfile) - # self.write_init_variables_function(outfile) + self.write_init_variables_function(outfile) self.write_init_controls_function(outfile) - # self.write_init_macros(outfile) - # self.write_init_reports(outfile) - # self.write_init_tables(outfile) # # Writes all of the #includes for this file diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 72eefea..6850894 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -96,7 +96,7 @@ def write(self, outfile: TextIO): body += self.write_mdat_functions() body += self.write_edd_functions() body += self.write_oper_functions() - # body += self.write_var_functions() + body += self.write_var_functions() body += self.write_ctrl_functions() body += self.write_const_functions() From 7391212c29ca60f96c83abf791aeba7e60438109 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 11:54:09 -0400 Subject: [PATCH 36/63] working c var --- src/camp/generators/lib/campch.py | 41 ++++++------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 9e0c21d..6b6f809 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -353,20 +353,16 @@ def make_std_meta_add_coll_template(coll, name): def write_init_var_function(c_file, adm, g_var_idx, mgr): body = "" coll_decl_str = "\n\tari_t *id = NULL;\n" - expr_decl_str = "\n\texpr_t *expr = NULL;\n" - expr_create_str = "\n\texpr = expr_create({});" - expr_add_str = "\n\texpr_add_item(expr, {});" - add_var_from_expr = "\n\tadm_add_var_from_expr(id, {}, expr);" + # TODO fix typing + tnv_decl_str = "\n\ttnv_t *tnv = tnv_from_int({});\n" + add_var_from_tnv = "\n\tadm_add_var_from_tnv(id, *tnv);" # gives you the adm_build_ari(...) build_str_template = "\n" + make_adm_build_ari_template(cs.VAR, g_var_idx, True) # gives you the meta_add_var(... ) meta_add_template = make_std_meta_add_coll_template(cs.VAR, cu.yang_to_c(adm.norm_name)) - added_coll = False - added_expr = False - for obj in adm.var: # Preliminaries ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.VAR, obj) @@ -375,35 +371,14 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): var_name = obj.name description = obj.description or '' - expr_str = "" - - # Add to the expr str for each postfix - pfxs = obj.initializer.postfix.items if obj.initializer else [] - for pfx in pfxs: - pfx_ns,pfx_coll,pfx_name = cu.ari_get_names(pfx) - pfx_ari = cu.make_ari_name_from_str(pfx_ns, pfx_coll, pfx_name) - pfx_g_var_idx = cu.get_g_var_idx(pfx_ns) - #FIXME: _,param_flag = retriever.postfix_has_params(pfx) - param_flag = "0" - - pfx_build_ari = make_adm_build_ari_template(pfx_coll, pfx_g_var_idx, False).format(param_flag, pfx_ari) - - expr_str += expr_add_str.format(pfx_build_ari) - - # If postfixs are present, append the expr_create string, and prepend - # the adm_add_var_from_expr stringq - if pfxs: - init_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) - - expr_str = expr_create_str.format(init_type) + expr_str - expr_str += add_var_from_expr.format(init_type) - - added_expr = True + val = obj.init_ari.value # Add formatted strings to body body += "\n\n\t/* {} */".format(var_name.upper()) body += build_str_template.format("0", ari) - body += expr_str + + body += tnv_decl_str.format(val) + body += add_var_from_tnv # Additional meta_add function needs to be called if this is the mgr code generation if mgr: @@ -412,8 +387,6 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): added_coll = True # only add these declarations if the variables will be used; to avoid compiler warnings - if added_expr: - body = expr_decl_str + body if added_coll: body = coll_decl_str + body From a3ebc59e91bc993d22673f2e9464c80ab3430dba Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 12:07:56 -0400 Subject: [PATCH 37/63] =?UTF-8?q?no=20error=20running=20camp=20on=20all=20?= =?UTF-8?q?yang=20examples=20in=20dtnma-adms!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/camp/generators/create_mgr_c.py | 1 - src/camp/generators/create_sql.py | 70 ++++++++++++++--------------- src/camp/generators/lib/campch.py | 21 +++++---- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index dced794..a16b3e6 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -146,7 +146,6 @@ def _write_mgr_std_init_funct(self, outfile, coll_type, objlist): # format the meta_add_.* template for this item meta_add_str = '' for valname in ['init_value', 'arg']: - print(obj.name, type(obj)) if hasattr(obj, valname): meta_add_str = meta_add_template.format(amp_type, obj.name, getattr(obj, valname)) return diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 6850894..71809e5 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -470,41 +470,41 @@ def write_var_functions(self): "-- VAR", ] - ac_comment = "-- create ac for expression" - - var_template = self.create_insert_obj_metadata_template(cs.VAR) - insert_ac_id_template = self.create_insert_ac_id_template(cs.VAR) - - # format with entry id, enumeration of entry in this var - insert_actual_entry_template = "CALL SP__insert_ac_actual_entry(" + self._var_name("var_ac_id") + ", {0}, {1}, " + self._var_name("r_ac_entry_id_", None) + "{1} );" - - # format with var id, description, var def id - # TODO: should be encoding the out type of the variable instead of passing hardcoded '20' for all - var_def_template = "CALL SP__insert_variable_definition({}, '{}', 20, " + self._var_name("var_ac_id") + ", {});" - for var in self.adm.var: - var_name = var.name - var_desc = escape_description_sql(var.description) - postfix = var.initializer.postfix.items - - var_id, var_def_id, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) - ac_description = f"ac for the expression used by {var_id}" - lines += [ - "", - ac_comment, - var_template.format(var_name, var_id), - insert_ac_id_template.format(len(postfix), ac_description, var_id), - ] - - for item in postfix: - pfx_obj_id, pfx_def_id, pfx_act_id, line = self.make_definition_ids(item) - lines += [line] - lines += [insert_actual_entry_template.format(pfx_act_id, item.position + 1)] - # preallocate names - self._var_name(f"r_ac_entry_id_{item.position + 1}") - - lines += [ - var_def_template.format(var_id, var_desc, var_act_id), - ] + # ac_comment = "-- create ac for expression" + + # var_template = self.create_insert_obj_metadata_template(cs.VAR) + # insert_ac_id_template = self.create_insert_ac_id_template(cs.VAR) + + # # format with entry id, enumeration of entry in this var + # insert_actual_entry_template = "CALL SP__insert_ac_actual_entry(" + self._var_name("var_ac_id") + ", {0}, {1}, " + self._var_name("r_ac_entry_id_", None) + "{1} );" + + # # format with var id, description, var def id + # # TODO: should be encoding the out type of the variable instead of passing hardcoded '20' for all + # var_def_template = "CALL SP__insert_variable_definition({}, '{}', 20, " + self._var_name("var_ac_id") + ", {});" + # for var in self.adm.var: + # var_name = var.name + # var_desc = escape_description_sql(var.description) + # postfix = var.initializer.postfix.items + + # var_id, var_def_id, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) + # ac_description = f"ac for the expression used by {var_id}" + # lines += [ + # "", + # ac_comment, + # var_template.format(var_name, var_id), + # insert_ac_id_template.format(len(postfix), ac_description, var_id), + # ] + + # for item in postfix: + # pfx_obj_id, pfx_def_id, pfx_act_id, line = self.make_definition_ids(item) + # lines += [line] + # lines += [insert_actual_entry_template.format(pfx_act_id, item.position + 1)] + # # preallocate names + # self._var_name(f"r_ac_entry_id_{item.position + 1}") + + # lines += [ + # var_def_template.format(var_id, var_desc, var_act_id), + # ] return lines diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 6b6f809..81490f3 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -371,14 +371,17 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): var_name = obj.name description = obj.description or '' - val = obj.init_ari.value + added_coll = False - # Add formatted strings to body - body += "\n\n\t/* {} */".format(var_name.upper()) - body += build_str_template.format("0", ari) + if obj.init_ari: + val = obj.init_ari.value - body += tnv_decl_str.format(val) - body += add_var_from_tnv + # Add formatted strings to body + body += "\n\n\t/* {} */".format(var_name.upper()) + body += build_str_template.format("0", ari) + + body += tnv_decl_str.format(val) + body += add_var_from_tnv # Additional meta_add function needs to be called if this is the mgr code generation if mgr: @@ -386,9 +389,9 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): added_coll = True - # only add these declarations if the variables will be used; to avoid compiler warnings - if added_coll: - body = coll_decl_str + body + # only add these declarations if the variables will be used; to avoid compiler warnings + if added_coll: + body = coll_decl_str + body write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.VAR, body) From c60c0f5352d26bf9bdf8f7325041cce1e17eb51d Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 13:32:09 -0400 Subject: [PATCH 38/63] touch up sql file --- src/camp/generators/create_sql.py | 71 +++++++++++------------------ src/camp/generators/lib/camputil.py | 8 ++++ 2 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 71809e5..25874ee 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -84,7 +84,7 @@ def __init__(self, admset, adm, out_path, dialect): def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "amp-sql", "Agent_Scripts", f"adm_{self.adm.norm_name}.sql") + return os.path.join(self.out_path, "amp-sql", "Agent_Scripts", f"adm_{cu.yang_to_sql(self.adm.norm_name)}.sql") def write(self, outfile: TextIO): # Interface for AbstractWriter @@ -135,7 +135,7 @@ def _make_ari(self, coll, item): :param item: object to make the IDs for. :return: the augmented ARI text. ''' - ns = str(self.adm.norm_name).upper() + ns = cu.yang_to_sql(self.adm.norm_name).upper() ari = cu.make_ari_name(ns, coll, item).lower() return ari @@ -177,7 +177,7 @@ def create_insert_obj_metadata_template(self, obj_type): # convert to object type enumeration to decimal for function obj_type_enum = str(int(cs.ari_type_enum(obj_type), 16)) - formatted = general_template.format(obj_type_enum, "{}", self.adm.norm_name, "{}")#self._sql_ns, "{}") + formatted = general_template.format(obj_type_enum, "{}", cu.yang_to_sql(self.adm.norm_name), "{}")#self._sql_ns, "{}") return formatted @@ -266,7 +266,7 @@ def write_setup(self): lines = [ "-- -------------------------------------------------------------------", "--", - "-- File Name: adm_{}.sql".format(self.adm.norm_name), + "-- File Name: adm_{}.sql".format(cu.yang_to_sql(self.adm.norm_name)), "--", "-- Description: TODO", "--", @@ -281,7 +281,7 @@ def write_setup(self): "--", "-- -------------------------------------------------------------------", "", - "-- ADM: '{}'".format(self.adm.norm_name), + "-- ADM: '{}'".format(cu.yang_to_sql(self.adm.norm_name)), "", ] @@ -301,13 +301,13 @@ def body_pre(self): "", "use amp_core;", "", - "SET @adm_enum = {};".format(self.adm.norm_name) + "SET @adm_enum = {};".format(cu.yang_to_sql(self.adm.norm_name)) ] elif self.dialect == 'pgsql': lines += [ "DO", "$do$", - "DECLARE adm_enum INTEGER := {};".format(self.adm.norm_name), + "DECLARE adm_enum INTEGER := {};".format(cu.yang_to_sql(self.adm.norm_name)), ] for name in sorted(self._vars_def): lines.append(f"DECLARE {name} INTEGER;") @@ -344,14 +344,14 @@ def val_or_none(obj, attr='arg'): name = val_or_none(self.admset.get_child(self.adm, 'name')) #ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) - ns = self.adm.norm_name.upper() + ns = cu.yang_to_sql(self.adm.norm_name).upper() version = val_or_none(self.admset.get_child(self.adm, 'version')) org = val_or_none(self.admset.get_child(self.adm, 'organization')) desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg)#val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) - formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.adm.norm_name)#self._sql_ns) + formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, cu.yang_to_sql(self.adm.norm_name))#self._sql_ns) return [ "", formatted_template @@ -462,7 +462,7 @@ def write_oper_functions(self): return lines def write_var_functions(self): - ''' Genreate lines for all of the VARs in the ADM + ''' Generate lines for all of the VARs in the ADM ''' lines = [ "", @@ -470,41 +470,22 @@ def write_var_functions(self): "-- VAR", ] - # ac_comment = "-- create ac for expression" - - # var_template = self.create_insert_obj_metadata_template(cs.VAR) - # insert_ac_id_template = self.create_insert_ac_id_template(cs.VAR) - - # # format with entry id, enumeration of entry in this var - # insert_actual_entry_template = "CALL SP__insert_ac_actual_entry(" + self._var_name("var_ac_id") + ", {0}, {1}, " + self._var_name("r_ac_entry_id_", None) + "{1} );" - - # # format with var id, description, var def id - # # TODO: should be encoding the out type of the variable instead of passing hardcoded '20' for all - # var_def_template = "CALL SP__insert_variable_definition({}, '{}', 20, " + self._var_name("var_ac_id") + ", {});" - # for var in self.adm.var: - # var_name = var.name - # var_desc = escape_description_sql(var.description) - # postfix = var.initializer.postfix.items - - # var_id, var_def_id, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) - # ac_description = f"ac for the expression used by {var_id}" - # lines += [ - # "", - # ac_comment, - # var_template.format(var_name, var_id), - # insert_ac_id_template.format(len(postfix), ac_description, var_id), - # ] - - # for item in postfix: - # pfx_obj_id, pfx_def_id, pfx_act_id, line = self.make_definition_ids(item) - # lines += [line] - # lines += [insert_actual_entry_template.format(pfx_act_id, item.position + 1)] - # # preallocate names - # self._var_name(f"r_ac_entry_id_{item.position + 1}") - - # lines += [ - # var_def_template.format(var_id, var_desc, var_act_id), - # ] + var_template = self.create_insert_obj_metadata_template(cs.VAR) + lines += [var_template] + + # format with var id, description, var def id + # TODO: should be encoding the out type of the variable instead of passing hardcoded '20' for all + var_def_template = "CALL SP__insert_variable_definition({}, '{}', 20, " + self._var_name("var_ac_id") + ", {});" + for var in self.adm.var: + var_name = var.name + var_desc = escape_description_sql(var.description) + var_value = var.init_ari.value + + var_id, _, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) + + lines += [ + var_def_template.format(cu.yang_to_sql(var_id), var_desc, var_act_id), + ] return lines diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index 61083c4..6a002d9 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -91,6 +91,14 @@ def make_enum_name_from_str(name): def yang_to_c(identifier): return identifier.replace('_','__').replace('-','_').replace('.','_p_') +# +# Translates a valid YANG identifier to a valid SQL identifier +# identifier is a valid YANG identifier +# +def yang_to_sql(identifier): + return identifier.replace('_','__').replace('-','_').replace('.','_p_') + + # # Adds \ to the end of a new line of string # str is the string to be modified From 599c9720772a69e4860d802401f1f29d4e4ae006 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 13:35:36 -0400 Subject: [PATCH 39/63] fix wrong attr name --- src/camp/generators/create_sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 25874ee..0284f26 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -479,7 +479,7 @@ def write_var_functions(self): for var in self.adm.var: var_name = var.name var_desc = escape_description_sql(var.description) - var_value = var.init_ari.value + # var_value = var.init_value var_id, _, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) From ae68e160fa029c8553663d89621bfe248f0d4c06 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 14:34:37 -0400 Subject: [PATCH 40/63] condense yang to sql name logic --- src/camp/generators/create_sql.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 0284f26..363941e 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -76,6 +76,7 @@ def __init__(self, admset, adm, out_path, dialect): self._var_prefix = "@" if self.dialect == 'mysql' else '' self._vars_def = set() self._vars_use = set() + self.sql_name = cu.yang_to_sql(self.adm.norm_name) # The first half of the namespace """ns = self.adm.norm_namespace @@ -84,7 +85,7 @@ def __init__(self, admset, adm, out_path, dialect): def file_path(self) -> str: # Interface for AbstractWriter - return os.path.join(self.out_path, "amp-sql", "Agent_Scripts", f"adm_{cu.yang_to_sql(self.adm.norm_name)}.sql") + return os.path.join(self.out_path, "amp-sql", "Agent_Scripts", f"adm_{self.sql_name}.sql") def write(self, outfile: TextIO): # Interface for AbstractWriter @@ -135,7 +136,7 @@ def _make_ari(self, coll, item): :param item: object to make the IDs for. :return: the augmented ARI text. ''' - ns = cu.yang_to_sql(self.adm.norm_name).upper() + ns = self.sql_name.upper() ari = cu.make_ari_name(ns, coll, item).lower() return ari @@ -177,7 +178,7 @@ def create_insert_obj_metadata_template(self, obj_type): # convert to object type enumeration to decimal for function obj_type_enum = str(int(cs.ari_type_enum(obj_type), 16)) - formatted = general_template.format(obj_type_enum, "{}", cu.yang_to_sql(self.adm.norm_name), "{}")#self._sql_ns, "{}") + formatted = general_template.format(obj_type_enum, "{}", self.sql_name, "{}")#self._sql_ns, "{}") return formatted @@ -266,7 +267,7 @@ def write_setup(self): lines = [ "-- -------------------------------------------------------------------", "--", - "-- File Name: adm_{}.sql".format(cu.yang_to_sql(self.adm.norm_name)), + "-- File Name: adm_{}.sql".format(self.sql_name), "--", "-- Description: TODO", "--", @@ -281,7 +282,7 @@ def write_setup(self): "--", "-- -------------------------------------------------------------------", "", - "-- ADM: '{}'".format(cu.yang_to_sql(self.adm.norm_name)), + "-- ADM: '{}'".format(self.sql_name), "", ] @@ -301,13 +302,13 @@ def body_pre(self): "", "use amp_core;", "", - "SET @adm_enum = {};".format(cu.yang_to_sql(self.adm.norm_name)) + "SET @adm_enum = {};".format(self.sql_name) ] elif self.dialect == 'pgsql': lines += [ "DO", "$do$", - "DECLARE adm_enum INTEGER := {};".format(cu.yang_to_sql(self.adm.norm_name)), + "DECLARE adm_enum INTEGER := {};".format(self.sql_name), ] for name in sorted(self._vars_def): lines.append(f"DECLARE {name} INTEGER;") @@ -344,14 +345,14 @@ def val_or_none(obj, attr='arg'): name = val_or_none(self.admset.get_child(self.adm, 'name')) #ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) - ns = cu.yang_to_sql(self.adm.norm_name).upper() + ns = self.sql_name.upper() version = val_or_none(self.admset.get_child(self.adm, 'version')) org = val_or_none(self.admset.get_child(self.adm, 'organization')) desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg)#val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) adm_enum = self._var_name("adm_enum", None) - formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, cu.yang_to_sql(self.adm.norm_name))#self._sql_ns) + formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.sql_name)#self._sql_ns) return [ "", formatted_template @@ -484,7 +485,7 @@ def write_var_functions(self): var_id, _, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) lines += [ - var_def_template.format(cu.yang_to_sql(var_id), var_desc, var_act_id), + var_def_template.format(self.sql_name, var_desc, var_act_id), ] return lines From 716c6a25e4aee8087118bfc59d52407314390ab9 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 23 Aug 2024 14:39:27 -0400 Subject: [PATCH 41/63] pull out more yang_to_c calls --- src/camp/generators/lib/campch.py | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index 81490f3..bbc7b7b 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -186,13 +186,16 @@ def make_formatted_comment_header(name, c_open, c_close): ############################# FUNCTIONS SHARED BY IMPL_C and IMPL_H ############################### +def _make_fullname(adm, basename): + return "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + # # Makes and returns the basename, fullname, and signature tuple for the edd # collect functions; where basename = edd_ and fullname = _ # def make_collect_function(adm, edd): basename = "get_{}".format(edd.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -203,7 +206,7 @@ def make_collect_function(adm, edd): def make_meta_function(adm, meta): keyword = cs.get_sname(cs.META) basename = "{0}_{1}".format(keyword, meta.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -214,7 +217,7 @@ def make_meta_function(adm, meta): def make_constant_function(adm, const): keyword = "get" basename = "{0}_{1}".format(keyword, const.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -225,7 +228,7 @@ def make_constant_function(adm, const): def make_control_function(adm, control): keyword = cs.get_sname(cs.CTRL) basename = "{0}_{1}".format(keyword, control.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(eid_t *def_mgr, tnvc_t *parms, int8_t *status)".format(fullname) return basename, fullname, signature @@ -236,7 +239,7 @@ def make_control_function(adm, control): def make_operator_function(adm, op): keyword = cs.get_sname(cs.OP) basename = "{0}_{1}".format(keyword, op.name.lower()) - fullname = "{0}_{1}".format(cu.yang_to_c(adm.norm_name).lower(), basename) + fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(vector_t *stack)".format(fullname) return basename, fullname, signature @@ -351,6 +354,8 @@ def make_std_meta_add_coll_template(coll, name): # TODO: cur_ari in generated function is unused # def write_init_var_function(c_file, adm, g_var_idx, mgr): + norm_name = cu.yang_to_c(adm.norm_name) + body = "" coll_decl_str = "\n\tari_t *id = NULL;\n" @@ -361,11 +366,12 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): # gives you the adm_build_ari(...) build_str_template = "\n" + make_adm_build_ari_template(cs.VAR, g_var_idx, True) # gives you the meta_add_var(... ) - meta_add_template = make_std_meta_add_coll_template(cs.VAR, cu.yang_to_c(adm.norm_name)) + meta_add_template = make_std_meta_add_coll_template(cs.VAR, norm_name) + for obj in adm.var: # Preliminaries - ari = cu.make_ari_name(cu.yang_to_c(adm.norm_name), cs.VAR, obj) + ari = cu.make_ari_name(norm_name, cs.VAR, obj) amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) var_name = obj.name @@ -393,18 +399,19 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): if added_coll: body = coll_decl_str + body - write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), cs.VAR, body) + write_formatted_init_function(c_file, norm_name, cs.VAR, body) # # Writes the init function to c_file # def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: bool): - enum_name = cu.make_enum_name_from_str(cu.yang_to_c(adm.norm_name)) + norm_name = cu.yang_to_c(adm.norm_name) + enum_name = cu.make_enum_name_from_str(norm_name) - vdb_adds = "\tadm_add_adm_info(\"" + cu.yang_to_c(adm.norm_name) + "\", " + enum_name + ");\n" + vdb_adds = "\tadm_add_adm_info(\"" + norm_name + "\", " + enum_name + ");\n" vdb_add_template = "\n\tVDB_ADD_NN(((" + enum_name + " * 20) + {0}), &({1}[{0}]));" - init_decl_template = "static void " + cu.yang_to_c(adm.norm_name) + "_init_{0}(void);\n" - init_call_template = "\n\t" + cu.yang_to_c(adm.norm_name) + "_init_{0}();" + init_decl_template = "static void " + norm_name + "_init_{0}(void);\n" + init_call_template = "\n\t" + norm_name + "_init_{0}();" # order of init functions matters obj_types = { @@ -422,7 +429,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: init_decls = "" init_calls = "" if not mgr: - init_calls = "\n\t" + cu.yang_to_c(adm.norm_name) + "_setup();" + init_calls = "\n\t" + norm_name + "_setup();" for coll, attrname in obj_types.items(): init_decls += init_decl_template.format(cs.get_sname(coll).lower()) @@ -436,7 +443,7 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: body = vdb_adds + "\n\n" + init_calls c_file.write(init_decls + "\n") - write_formatted_init_function(c_file, cu.yang_to_c(adm.norm_name), None, body) + write_formatted_init_function(c_file, norm_name, None, body) def make_cplusplus_open(): ''' Open an "extern C" block for C++ inclusion. ''' From 4f7ecebe7171576cc30a4872349a5f9c5422032f Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Mon, 26 Aug 2024 14:20:07 -0400 Subject: [PATCH 42/63] remove expected json failures --- tests/integration_test/test_c_integration.py | 3 +-- tests/integration_test/test_sql_integration.py | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/integration_test/test_c_integration.py b/tests/integration_test/test_c_integration.py index 703bd6f..a562e91 100644 --- a/tests/integration_test/test_c_integration.py +++ b/tests/integration_test/test_c_integration.py @@ -23,8 +23,7 @@ def test_adms(adm): Compiles each adm in ADMS_DIR against the dtnma-tools repo @pre: DTNMA_TOOLS_DIR is a git working copy, tests should be run from home directory of camp repo """ - if adm == 'amp_agent.json' or adm == 'ion_bpsec_admin.json': - pytest.xfail("ADM with known issue") + # input file full filepath filepath = os.path.join(ADMS_DIR, adm) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index 5d023a1..b99eaac 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -41,8 +41,6 @@ def test_adms(setup, adm): """ cursor = setup[0] - if adm == 'ion_bpsec_admin.json': - pytest.xfail("ADM with known issue") # input file full filepath filepath = os.path.join(ADMS_DIR, adm) From d3c5cf749c5f60cceef7b140104c2528e68e5470 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Mon, 26 Aug 2024 14:23:54 -0400 Subject: [PATCH 43/63] install ace before this repo is checked out --- .github/workflows/build-test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 0cab09d..c0da076 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -58,6 +58,10 @@ jobs: matrix: python-version: ["3.10"] steps: + - name: Prep + run: | + pip3 install ${ACE_REPO} + pip3 install -e '.[test]' - name: Checkout repository uses: actions/checkout@v4 with: @@ -66,10 +70,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Prep - run: | - pip3 install ${ACE_REPO} - pip3 install -e '.[test]' - name: Test run: python3 -m pytest -v --cov=camp tests/unit_test From d2c3699506820b64b47184253f09634baa4ba855 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 27 Aug 2024 11:46:02 -0400 Subject: [PATCH 44/63] add "# TODO type fixes" to the hacks --- src/camp/generators/create_impl_c.py | 2 +- src/camp/generators/lib/camputil.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index a561945..8829799 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -131,7 +131,7 @@ def write_constant_functions(self, outfile): const_function_str = ( "\n{0}" "\n{{" - "\n\treturn tnv_from_uvast({1});" # TODO Karen not necessarily everything is uvast? + "\n\treturn tnv_from_str(\"{1}\");" # TODO type fixes "\n}}" "\n") diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index 6a002d9..a46e31e 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -73,9 +73,7 @@ def make_ari_name(name, coll, item): # def make_amp_type_name_from_str(t_name): # return "AMP_TYPE_{}".format(t_name.upper()) - - # TODO type fixes - return "AMP_TYPE_UNK" + return "AMP_TYPE_UNK" # TODO type fixes # # Makes and returns the adm enum type string for the passed From 1df3366e66ddde2b56d8ed0a2d33450049eabc20 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 27 Aug 2024 13:27:35 -0400 Subject: [PATCH 45/63] standardize naming --- src/camp/generators/create_mgr_c.py | 10 +++++++--- src/camp/generators/lib/campch.py | 12 ++++++------ src/camp/generators/lib/camputil.py | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index a16b3e6..70ee3fe 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -268,8 +268,10 @@ def write_init_ops(self, outfile): amp_type = cu.make_amp_type_name_from_str(obj.result.name) in_types = obj.operands.items if obj.operands.items else [] + obj_name = cu.yang_to_c(obj.name) + # Format the meta_add_.* template for this item - meta_str = meta_add_template.format(amp_type, obj.name, obj.description) + meta_str = meta_add_template.format(amp_type, obj_name, obj.description) # A couple of variables depend on the presence or absence of parms parms_tf = "0" @@ -329,8 +331,10 @@ def write_init_controls_function(self, outfile): ari = cu.make_ari_name(self.c_norm_name, cs.CTRL, obj) parms = obj.parameters.items if obj.parameters else [] + obj_name = cu.yang_to_c(obj.name) + # Format the meta_add_.* template for this item - meta_str = meta_add_template.format(obj.name, obj.description) + meta_str = meta_add_template.format(obj_name, obj.description) # A couple of variables depend on the presence or absence of parms parms_tf = "0" @@ -340,7 +344,7 @@ def write_init_controls_function(self, outfile): meta_str = "meta = " + meta_str # Add formatted strings to the body of the function - body += "\n\n\t/* {} */".format(obj.name.upper()) + body += "\n\n\t/* {} */".format(obj_name.upper()) body += "\n" + build_str_template.format(parms_tf, ari) body += add_ctrldef_template.format(len(parms)) body += "\n\t" + meta_str diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index bbc7b7b..f63916d 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -194,7 +194,7 @@ def _make_fullname(adm, basename): # collect functions; where basename = edd_ and fullname = _ # def make_collect_function(adm, edd): - basename = "get_{}".format(edd.name.lower()) + basename = "get_{}".format(cu.yang_to_c(edd.name).lower()) fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -205,7 +205,7 @@ def make_collect_function(adm, edd): # def make_meta_function(adm, meta): keyword = cs.get_sname(cs.META) - basename = "{0}_{1}".format(keyword, meta.name.lower()) + basename = "{0}_{1}".format(keyword, cu.yang_to_c(meta.name).lower()) fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -216,7 +216,7 @@ def make_meta_function(adm, meta): # def make_constant_function(adm, const): keyword = "get" - basename = "{0}_{1}".format(keyword, const.name.lower()) + basename = "{0}_{1}".format(keyword, cu.yang_to_c(const.name).lower()) fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(tnvc_t *parms)".format(fullname) return basename, fullname, signature @@ -227,7 +227,7 @@ def make_constant_function(adm, const): # def make_control_function(adm, control): keyword = cs.get_sname(cs.CTRL) - basename = "{0}_{1}".format(keyword, control.name.lower()) + basename = "{0}_{1}".format(keyword, cu.yang_to_c(control.name).lower()) fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(eid_t *def_mgr, tnvc_t *parms, int8_t *status)".format(fullname) return basename, fullname, signature @@ -238,7 +238,7 @@ def make_control_function(adm, control): # def make_operator_function(adm, op): keyword = cs.get_sname(cs.OP) - basename = "{0}_{1}".format(keyword, op.name.lower()) + basename = "{0}_{1}".format(keyword, cu.yang_to_c(op.name).lower()) fullname = _make_fullname(adm, basename) signature = "tnv_t *{}(vector_t *stack)".format(fullname) return basename, fullname, signature @@ -374,7 +374,7 @@ def write_init_var_function(c_file, adm, g_var_idx, mgr): ari = cu.make_ari_name(norm_name, cs.VAR, obj) amp_type = cu.make_amp_type_name_from_str(obj.typeobj.type_text) - var_name = obj.name + var_name = cu.yang_to_c(obj.name) description = obj.description or '' added_coll = False diff --git a/src/camp/generators/lib/camputil.py b/src/camp/generators/lib/camputil.py index a46e31e..42d2c18 100644 --- a/src/camp/generators/lib/camputil.py +++ b/src/camp/generators/lib/camputil.py @@ -53,7 +53,7 @@ def ari_get_names(jari): # make the ari for i_name is the name of the item # def make_ari_name_from_str(name, coll, i_name): - name = name.replace("/", "_") + i_name = yang_to_c(i_name) template = "{0}_{1}_{2}" return template.format(name.upper(), cs.get_sname(coll).upper(), i_name.upper()) From d16269dc719f658847295e30b1d65ac48c840672 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 27 Aug 2024 13:36:00 -0400 Subject: [PATCH 46/63] remove mac, rptt, tblt --- src/camp/generators/create_agent_c.py | 33 --------------------- src/camp/generators/create_impl_c.py | 38 ------------------------- src/camp/generators/create_impl_h.py | 11 ------- src/camp/generators/create_mgr_c.py | 23 --------------- src/camp/generators/create_sql.py | 2 +- src/camp/generators/lib/campch.py | 3 -- src/camp/generators/lib/campsettings.py | 8 +----- 7 files changed, 2 insertions(+), 116 deletions(-) diff --git a/src/camp/generators/create_agent_c.py b/src/camp/generators/create_agent_c.py index 1246e5f..8305373 100644 --- a/src/camp/generators/create_agent_c.py +++ b/src/camp/generators/create_agent_c.py @@ -58,9 +58,6 @@ def write(self, outfile: TextIO): self.write_init_op_function(outfile) self.write_init_var_function(outfile) self.write_init_control_function(outfile) - # self.write_init_macro_function(outfile) - # self.write_init_reports_function(outfile) - # self.write_init_tables_function(outfile) # # Writes all of the #includes for this c file @@ -227,33 +224,3 @@ def write_init_control_function(self, outfile): campch.write_formatted_init_function(outfile, self.c_norm_name, cs.CTRL, body) - # - # Constructs and writes the init_macros function - # - # c_file is an open file descriptor to write to, - # name is the value returned from get_adm_names() - # macros is a list of macros to add - # - def write_init_macro_function(self, outfile): - campch.write_init_macro_function(outfile, self.adm, self._g_var_idx, False) - - # - # Constructs and writes the init reports function - # - # c_file is an open file descriptor to write to - # name is the name returned by the call to get_adm_names() - # retriever is the Retriever class instance for this ADM - # - def write_init_reports_function(self, outfile): - campch.write_parameterized_init_reports_function(outfile, self.adm, self._g_var_idx, False) - - # - # Constructs and writes the init tables function - # - # c_file is an open file descriptor to write to - # name is the name returned by the call to get_adm_names() - # retriever is the Retriever class instance for this ADM - # - def write_init_tables_function(self, outfile): - campch.write_init_tables_function(outfile, self.adm, self._g_var_idx, False) - diff --git a/src/camp/generators/create_impl_c.py b/src/camp/generators/create_impl_c.py index 8829799..82895d5 100644 --- a/src/camp/generators/create_impl_c.py +++ b/src/camp/generators/create_impl_c.py @@ -139,44 +139,6 @@ def write_constant_functions(self, outfile): _,_,signature = campch.make_constant_function(self.adm, obj) outfile.write(const_function_str.format(signature, getattr(obj, 'init_value', ''))) - # - # writes the table functions to the file passed - # outfile is an open file descriptor to write to - # name is the value returned from get_adm_names() - # table is a list of tables to include - # scraper is the Scraper object associated with this ADM - # - def write_table_functions(self, outfile): - outfile.write("\n/* Table Functions */\n\n") - table_function_begin_str = ( - "\n{0}" - "\n{1}" - "\n{{" - "\n\ttbl_t *table = NULL;" - "\n\tif((table = tbl_create(id)) == NULL)" - "\n\t{{" - "\n\t\treturn NULL;" - "\n\t}}" - "\n\n") - conditional_body_str = ( - "\n\t{" - "\n\t\treturn NULL;" - "\n\t}" - "\n\n") - table_function_end_str = "\treturn table;\n}\n\n" - - for obj in self.adm.tblt: - basename,_,signature = campch.make_table_function(self.adm, obj) - description = campch.multiline_comment_format(obj.description or '') - - outfile.write(table_function_begin_str.format(description, signature)) - - # Add custom body tags and any scrapped lines found - self._scraper.write_custom_body(outfile, basename) - - # Close out the function - outfile.write(table_function_end_str) - # # Writes the edd functions to the file passed # outfile is an open file descriptor to write to diff --git a/src/camp/generators/create_impl_h.py b/src/camp/generators/create_impl_h.py index 36a8232..e4af1f2 100644 --- a/src/camp/generators/create_impl_h.py +++ b/src/camp/generators/create_impl_h.py @@ -168,14 +168,3 @@ def write_operator_functions(self, outfile): for obj in self.adm.oper: _,_,signature = campch.make_operator_function(self.adm, obj) outfile.write(signature + ";\n") - - # - # Writes the table functions to the passed file, new_h - # name is the value returned from get_adm_names - # tables is a list of tables to include - # - def write_table_functions(self, outfile): - outfile.write("\n\n/* Table Build Functions */\n") - for obj in self.adm.tblt: - _,_,signature = campch.make_table_function(self.adm, obj) - outfile.write(signature + ";\n") diff --git a/src/camp/generators/create_mgr_c.py b/src/camp/generators/create_mgr_c.py index 70ee3fe..e54b203 100644 --- a/src/camp/generators/create_mgr_c.py +++ b/src/camp/generators/create_mgr_c.py @@ -365,29 +365,6 @@ def write_init_controls_function(self, outfile): campch.write_formatted_init_function(outfile, self.c_norm_name, cs.CTRL, body) - # - # Writes the init_macros() function to the open file descriptor passed as c_file - # name is the value returned from get_adm_names() - # macros is a list of macros to include - # - def write_init_macros(self, outfile): - campch.write_init_macro_function(outfile, self.adm, self._g_var_idx, True) - - - # - # Writes the init_reports() function to the open file descriptor passed as c_file - # name is the value returned from get_adm_names() - # - def write_init_reports(self, outfile): - campch.write_parameterized_init_reports_function(outfile, self.adm, self._g_var_idx, True) - - # - # Writes the init_tables() function to the open file descriptor passed as c_file - # name is the value returns from get_adm_names() - # - def write_init_tables(self, outfile): - campch.write_init_tables_function(outfile, self.adm, self._g_var_idx, True) - # Builds a template for the # ``` # id = adm_build_ari(...) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 363941e..4ce3051 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -215,7 +215,7 @@ def create_insert_tnvc_templates(self, obj_type, num_entries): return collection_template, entry_template, unk_entry_template # Helper function for insert_ac functions - # obj_type is the type of object (OP, MACRO, etc.) + # obj_type is the type of object (OP, etc.) # description_format is any formatting you wish to impose on the description # Returns template for insert_ac_id function, format with number of acs and the description def create_insert_ac_id_template(self, obj_type, description_format="{}"): diff --git a/src/camp/generators/lib/campch.py b/src/camp/generators/lib/campch.py index f63916d..d65e1e6 100644 --- a/src/camp/generators/lib/campch.py +++ b/src/camp/generators/lib/campch.py @@ -421,9 +421,6 @@ def write_init_function(c_file, adm: ace.models.AdmModule, g_var_idx: str, mgr: cs.OP: 'oper', cs.VAR: 'var', cs.CTRL: 'ctrl', - # cs.MACRO: 'mac', - # cs.RPTT: 'rptt', - # cs.TBLT: 'tblt', } init_decls = "" diff --git a/src/camp/generators/lib/campsettings.py b/src/camp/generators/lib/campsettings.py index 1e0b853..1fd40c5 100644 --- a/src/camp/generators/lib/campsettings.py +++ b/src/camp/generators/lib/campsettings.py @@ -28,16 +28,13 @@ CONST = 0 CTRL = 1 EDD = 2 -# MACRO = 3 OP = 4 -# RPTT = 5 SBR = 6 -# TBLT = 7 TBR = 8 VAR = 9 META = 10 -# NOTE: sname and lname are often essentially the same, expect for CONST, OP, RPTT, and META +# NOTE: sname and lname are often essentially the same, expect for CONST, OP, and META # NOTE: amp_type is often same as sname, except for OP and META # NOTE: adm_idx is often the same as lname, except for META # XXX: ensure these differences are necessary, or change if all could use same keyword. @@ -45,11 +42,8 @@ collections[CONST] = {"sname":"cnst", "lname":"Const", "ari_type":"0", "amp_type":"cnst", "adm_idx":"Const"} # CONST = 0 collections[CTRL] = {"sname":"ctrl", "lname":"Ctrl", "ari_type":"1", "amp_type":"ctrl", "adm_idx":"Ctrl"} # CTRL = 1 collections[EDD] = {"sname":"edd", "lname":"Edd", "ari_type":"2", "amp_type":"edd", "adm_idx":"Edd"} # EDD = 2 -# collections[MACRO] = {"sname":"mac", "lname":"Mac", "ari_type":"4", "amp_type":"mac", "adm_idx":"Mac"} # MACRO = 3 collections[OP] = {"sname":"op", "lname":"Oper", "ari_type":"5", "amp_type":"Oper", "adm_idx":"Oper"} # OP = 4 -# collections[RPTT] = {"sname":"rpttpl", "lname":"Rptt", "ari_type":"7", "amp_type":"rpttpl", "adm_idx":"Rptt"} # RPTT = 5 collections[SBR] = {"sname":"sbr", "lname":"Sbr", "ari_type":"8", "amp_type":"sbr", "adm_idx":"Sbr"} # SBR = 6 -# collections[TBLT] = {"sname":"tblt", "lname":"Tblt", "ari_type":"a", "amp_type":"tblt", "adm_idx":"Tblt"} # TBLT = 7 collections[TBR] = {"sname":"tbr", "lname":"Tbr", "ari_type":"b", "amp_type":"tbr", "adm_idx":"Tbr"} # TBR = 8 collections[VAR] = {"sname":"var", "lname":"Var", "ari_type":"c", "amp_type":"var", "adm_idx":"Var"} # VAR = 9 collections[META] = {"sname":"meta", "lname":"Mdat", "ari_type":"0", "amp_type":"cnst", "adm_idx":"Meta"} # META = 10 From c8de8c883140501257c564bbe80f9326c62026fb Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Tue, 27 Aug 2024 14:29:40 -0400 Subject: [PATCH 47/63] update sql integration test for yang --- tests/integration_test/test_sql_integration.py | 6 +++--- tests/integration_test/util.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index b99eaac..11e6d3a 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -2,9 +2,9 @@ import os import ace import pytest +import camp -from .util import ADMS_DIR, adm_files, run_camp - +from .util import ADMS_DIR, adm_files, run_camp, normalize_filename @pytest.fixture(scope="session", autouse=True) def setup(): @@ -50,7 +50,7 @@ def test_adms(setup, adm): # execute sql adm_set = ace.AdmSet() - norm_name = adm_set.load_from_file(filepath).norm_name + norm_name = normalize_filename(adm_set.load_from_file(filepath).norm_name) sql_file = os.path.join(ADMS_DIR, "amp-sql", "Agent_Scripts", 'adm_{name}.sql'.format(name=norm_name)) with open(sql_file, "r") as f: cursor.execute(f.read()) diff --git a/tests/integration_test/util.py b/tests/integration_test/util.py index dae902e..da19b3a 100644 --- a/tests/integration_test/util.py +++ b/tests/integration_test/util.py @@ -45,3 +45,9 @@ def run_camp(filepath, outpath, only_sql, only_ch, scrape=False) -> int: args.only_ch = only_ch args.scrape = scrape return run(args) + +def normalize_filename(fname): + """ + Normalizes filename according to how camp generates file names + """ + return fname.replace('_','__').replace('-','_').replace('.','_p_') From d827089be8a3dbbd5f13cf1be0ba820c7762c097 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 28 Aug 2024 11:53:51 -0400 Subject: [PATCH 48/63] passing sql integration tests (w/ type fix TODOs) also had to change one ADM enum) --- src/camp/generators/create_sql.py | 54 +++++++++---------- .../integration_test/test_sql_integration.py | 6 +-- tests/integration_test/util.py | 6 --- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 4ce3051..883f9e8 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -79,9 +79,8 @@ def __init__(self, admset, adm, out_path, dialect): self.sql_name = cu.yang_to_sql(self.adm.norm_name) # The first half of the namespace - """ns = self.adm.norm_namespace - hl_ns = ns.split('/')[0].lower() - self._sql_ns = self._var_name(f"{hl_ns}_namespace_id")""" + ns = self.sql_name.lower() + self._sql_ns = self._var_name(f"{ns}_namespace_id") def file_path(self) -> str: # Interface for AbstractWriter @@ -97,7 +96,7 @@ def write(self, outfile: TextIO): body += self.write_mdat_functions() body += self.write_edd_functions() body += self.write_oper_functions() - body += self.write_var_functions() + # body += self.write_var_functions() body += self.write_ctrl_functions() body += self.write_const_functions() @@ -178,7 +177,7 @@ def create_insert_obj_metadata_template(self, obj_type): # convert to object type enumeration to decimal for function obj_type_enum = str(int(cs.ari_type_enum(obj_type), 16)) - formatted = general_template.format(obj_type_enum, "{}", self.sql_name, "{}")#self._sql_ns, "{}") + formatted = general_template.format(obj_type_enum, "{}", self._sql_ns, "{}") return formatted @@ -302,13 +301,13 @@ def body_pre(self): "", "use amp_core;", "", - "SET @adm_enum = {};".format(self.sql_name) + "SET @adm_enum = {};".format(self.adm.enum) ] elif self.dialect == 'pgsql': lines += [ "DO", "$do$", - "DECLARE adm_enum INTEGER := {};".format(self.sql_name), + "DECLARE adm_enum INTEGER := {};".format(self.adm.enum), ] for name in sorted(self._vars_def): lines.append(f"DECLARE {name} INTEGER;") @@ -344,15 +343,14 @@ def val_or_none(obj, attr='arg'): return getattr(obj, attr) name = val_or_none(self.admset.get_child(self.adm, 'name')) - #ns = val_or_none(self.admset.get_child(self.adm, 'namespace')) ns = self.sql_name.upper() version = val_or_none(self.admset.get_child(self.adm, 'version')) org = val_or_none(self.admset.get_child(self.adm, 'organization')) - desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg)#val_or_none(self.admset.get_child(self.adm, models.Mdat, 'namespace'), 'description')) + desc = escape_description_sql(self.admset.get_child(self.adm, "description").arg) adm_enum = self._var_name("adm_enum", None) - formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self.sql_name)#self._sql_ns) + formatted_template = meta_template.format(org, ns, version, name, adm_enum, desc, self._sql_ns) return [ "", formatted_template @@ -381,15 +379,7 @@ def write_edd_functions(self): edd_fp_id = self.make_fp_id(edd_obj_id) name = edd.name - if hasattr(edd.typeobj, 'type_text'): - etype = edd.typeobj.type_text - else: - etype = [] - for col in edd.typeobj.columns: - if hasattr(col.base, 'type_text'): - etype.append(col.base.type_text) - else: - etype.append(col.base.base.type_text) + etype = "UINT" # TODO type fixes desc = escape_description_sql(edd.description) parmspec = edd.parameters.items if edd.parameters else [] num_parmspec = len(parmspec) @@ -403,17 +393,17 @@ def write_edd_functions(self): lines += [insert_formal_parmspec_template.format(num_parmspec, name, edd_fp_id, edd_obj_id)] for parm in parmspec: - lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, parm.name)] + lines += [insert_entry_template.format(edd_fp_id, parm.position + 1, parm.name, "UINT")] # TODO type fixes + + lines += [edd_formal_def_template.format(edd_obj_id, desc, edd_fp_id, etype, edd_def_id)] # Only put actual definition here if no parmspec - if not parmspec: + else: self._var_name(edd_act_id) lines += [ edd_formal_def_template.format(edd_obj_id, desc, "NULL", etype, edd_def_id), edd_actual_def_template.format(edd_obj_id, name, edd_act_id), ] - else: - lines += [edd_formal_def_template.format(edd_obj_id, desc, edd_fp_id, etype, edd_def_id)] return lines @@ -434,7 +424,8 @@ def write_oper_functions(self): for oper in self.adm.oper: oper_name = oper.name oper_desc = escape_description_sql(oper.description) - result_type = oper.result.name + # result_type = oper.result.name + result_type = "UNK" # TODO type fixes oper_obj_id, oper_def_id, oper_act_id = self.make_sql_ids(self._make_ari(cs.OP, oper)) tnvc_collection_template,tnvc_entry_template,tnvc_unk_entry_template = self.create_insert_tnvc_templates(cs.OP, len(oper.operands.items)) @@ -446,7 +437,9 @@ def write_oper_functions(self): ] for in_type in oper.operands.items: - t = in_type.name.lower() + # t = in_type.name.lower() + t = "unk" + # TODO type fixes # UNK has one fewer parameter if t == "unk": @@ -456,7 +449,8 @@ def write_oper_functions(self): # TODO: UNK is not a valid type, comment the actual_def for this out for now until ADM resolved if result_type.upper() == 'UNK': - lines += ["-- " + actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.operands.items), oper_act_id)] + pass # TODO commenting out like below doesn't work well with multi-line descriptions! + # lines += ["-- " + actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.operands.items), oper_act_id)] else: lines += [actual_def_template.format(oper_obj_id, oper_desc, result_type, len(oper.operands.items), oper_act_id)] @@ -617,7 +611,7 @@ def write_ctrl_functions(self): fp_spec_id = self._var_name("fp_spec_id") lines += [insert_formal_parmspec_template.format(len(parmspec), ctrl_name, fp_spec_id, ctrl_id)] for parm in parmspec: - lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, parm.name)] + lines += [insert_entry_template.format(fp_spec_id, parm.position + 1, parm.name, "UINT")] # TODO type fixes else: fp_spec_id = "null" @@ -648,7 +642,7 @@ def write_gen_const_functions(self, objects, coll): lines += [ "", insert_obj_template.format(c_name, const_id), - insert_const_actual_def_template.format(const_id, c_desc, obj.typeobj, obj.init_value, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, "UINT", obj.init_value, const_act_id), # TODO type fixes ] return lines @@ -688,11 +682,13 @@ def write_mdat_functions(self): "", insert_obj_template.format(c_name, const_id), #using metadata keyword for type - insert_const_actual_def_template.format(const_id, c_desc, obj.name, obj.arg, const_act_id), + insert_const_actual_def_template.format(const_id, c_desc, "STR", c_desc, const_act_id), # TODO type fixes ] return lines + + # If the setup.mysql file exists in the output dir, and this # file is not already sourced in the setup script, add it to # the file. diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index 11e6d3a..b78d9ed 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -2,9 +2,9 @@ import os import ace import pytest -import camp -from .util import ADMS_DIR, adm_files, run_camp, normalize_filename +from .util import ADMS_DIR, adm_files, run_camp +from camp.generators.lib.camputil import yang_to_sql @pytest.fixture(scope="session", autouse=True) def setup(): @@ -50,7 +50,7 @@ def test_adms(setup, adm): # execute sql adm_set = ace.AdmSet() - norm_name = normalize_filename(adm_set.load_from_file(filepath).norm_name) + norm_name = yang_to_sql(adm_set.load_from_file(filepath).norm_name) sql_file = os.path.join(ADMS_DIR, "amp-sql", "Agent_Scripts", 'adm_{name}.sql'.format(name=norm_name)) with open(sql_file, "r") as f: cursor.execute(f.read()) diff --git a/tests/integration_test/util.py b/tests/integration_test/util.py index da19b3a..dae902e 100644 --- a/tests/integration_test/util.py +++ b/tests/integration_test/util.py @@ -45,9 +45,3 @@ def run_camp(filepath, outpath, only_sql, only_ch, scrape=False) -> int: args.only_ch = only_ch args.scrape = scrape return run(args) - -def normalize_filename(fname): - """ - Normalizes filename according to how camp generates file names - """ - return fname.replace('_','__').replace('-','_').replace('.','_p_') From 1d3e64e4763142b59dee9a8486269ecfe9d874a5 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 28 Aug 2024 12:18:06 -0400 Subject: [PATCH 49/63] fix typos --- src/camp/generators/create_sql.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 883f9e8..07cae55 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -261,7 +261,7 @@ def make_fp_id(self, obj_id): # Functions to format and write stored procedures to the SQL file based on the ADM def write_setup(self): - ''' Genreate lines for the introductory material for the sql file + ''' Generate lines for the introductory material for the sql file ''' lines = [ "-- -------------------------------------------------------------------", @@ -288,7 +288,7 @@ def write_setup(self): return lines def body_pre(self): - ''' Genreate lines before the SQL body. + ''' Generate lines before the SQL body. ''' undef = self._vars_use - self._vars_def @@ -319,7 +319,7 @@ def body_pre(self): return lines def body_post(self): - ''' Generate liens after the SQL body. + ''' Generate lines after the SQL body. ''' lines = [] if self.dialect == 'pgsql': @@ -357,7 +357,7 @@ def val_or_none(obj, attr='arg'): ] def write_edd_functions(self): - ''' Genreate lines for all of the EDDs in the ADM + ''' Generate lines for all of the EDDs in the ADM ''' lines = [ "", @@ -408,7 +408,7 @@ def write_edd_functions(self): return lines def write_oper_functions(self): - ''' Genreate lines for all of the OPERs in the ADM + ''' Generate lines for all of the OPERs in the ADM ''' lines = [ "", @@ -583,7 +583,7 @@ def handle_report_fp_ap(self, item, lines, report_id): return result def write_ctrl_functions(self): - ''' Genreate lines for all of the CTRLs in the ADM + ''' Generate lines for all of the CTRLs in the ADM ''' lines = [ "", @@ -623,7 +623,7 @@ def write_gen_const_functions(self, objects, coll): ''' Helper function for the META and CONST objects to allow code reuse since they use the same stored procedures. - Genreate lines for all of the passed objects. + Generate lines for all of the passed objects. :param objects: list of objects (CONSTs or METAs) to write the stored procedures for :param coll: type of collection (cs.CONST or cs.META) @@ -648,7 +648,7 @@ def write_gen_const_functions(self, objects, coll): return lines def write_const_functions(self): - ''' Genreate lines for all of the CONSTs in the ADM + ''' Generate lines for all of the CONSTs in the ADM ''' lines = [ "", @@ -658,7 +658,7 @@ def write_const_functions(self): return lines + self.write_gen_const_functions(self.adm.const, cs.CONST) def write_mdat_functions(self): - ''' Genreate lines for all of the MDATs in the ADM + ''' Generate lines for all of the MDATs in the ADM ''' coll = cs.META objects = self.adm.metadata_list.items From 2a2e8ae79fb438f1a3ec7fd85a6ec12d8b8209cf Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Wed, 28 Aug 2024 15:39:50 -0400 Subject: [PATCH 50/63] default git branch --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index c0da076..e08cb97 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -24,7 +24,7 @@ name: Build and run tests on: [push] env: - ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@haining-ace-yang-updates" + ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git" ADMS_REPO: "https://github.com/JHUAPL-DTNMA/dtnma-adms.git" jobs: From ecaaa4235f49ef3de4a1810eb96a08842eacac25 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 10:14:11 -0400 Subject: [PATCH 51/63] add var back in --- src/camp/generators/create_sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index 07cae55..ddb5c98 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -96,7 +96,7 @@ def write(self, outfile: TextIO): body += self.write_mdat_functions() body += self.write_edd_functions() body += self.write_oper_functions() - # body += self.write_var_functions() + body += self.write_var_functions() body += self.write_ctrl_functions() body += self.write_const_functions() From 320c74408fe2d390db4f9807912fe5ce303513ad Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 10:19:23 -0400 Subject: [PATCH 52/63] xfail ietf-amm.yang (doesn't have unique enum) --- tests/integration_test/test_sql_integration.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index b78d9ed..9c160dd 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -39,6 +39,10 @@ def test_adms(setup, adm): Integration test for an ADM found in the ADMS_DIR folder Resulting sql files will be placed in ADMS_DIR/amp-sql/Agent_Scripts and executed in the anms library. """ + + if adm == 'ietf-amm.yang': # doesn't have unique enum + pytest.xfail("ADM with known issue") + cursor = setup[0] # input file full filepath From 13d87b716048ce87f40fc9093c1aa41919b6fe39 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 10:19:58 -0400 Subject: [PATCH 53/63] switch back branch --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index e08cb97..c0da076 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -24,7 +24,7 @@ name: Build and run tests on: [push] env: - ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git" + ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@haining-ace-yang-updates" ADMS_REPO: "https://github.com/JHUAPL-DTNMA/dtnma-adms.git" jobs: From ee7e500264e4b419368a39901313439fc512cb35 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 10:39:28 -0400 Subject: [PATCH 54/63] add debug --- tests/integration_test/test_sql_integration.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index 9c160dd..905c0d7 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -57,5 +57,10 @@ def test_adms(setup, adm): norm_name = yang_to_sql(adm_set.load_from_file(filepath).norm_name) sql_file = os.path.join(ADMS_DIR, "amp-sql", "Agent_Scripts", 'adm_{name}.sql'.format(name=norm_name)) with open(sql_file, "r") as f: - cursor.execute(f.read()) + + # TODO Karen remove debug + content = f.read() + print(content) + + cursor.execute(content) cursor.execute("rollback") From 4def2304a96199007fcd959cd53e41628f55bbe8 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 12:13:48 -0400 Subject: [PATCH 55/63] passing tests w var added back in --- src/camp/generators/create_sql.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/camp/generators/create_sql.py b/src/camp/generators/create_sql.py index ddb5c98..fce3a5c 100644 --- a/src/camp/generators/create_sql.py +++ b/src/camp/generators/create_sql.py @@ -466,7 +466,6 @@ def write_var_functions(self): ] var_template = self.create_insert_obj_metadata_template(cs.VAR) - lines += [var_template] # format with var id, description, var def id # TODO: should be encoding the out type of the variable instead of passing hardcoded '20' for all @@ -474,12 +473,13 @@ def write_var_functions(self): for var in self.adm.var: var_name = var.name var_desc = escape_description_sql(var.description) - # var_value = var.init_value - - var_id, _, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) + var_id, var_def_id, var_act_id = self.make_sql_ids(self._make_ari(cs.VAR, var)) lines += [ - var_def_template.format(self.sql_name, var_desc, var_act_id), + "", + "CALL SP__insert_ac_id(1, 'dummy AC', var_ac_id);", # TODO type fixes (TBD how does var params work?) + var_template.format(var_name, var_id), + var_def_template.format(var_id, var_desc, var_act_id), ] return lines From 4fdcd6195aca3d301eab11fdcb2c684de95c8f23 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 12:36:20 -0400 Subject: [PATCH 56/63] update docs sha --- .github/workflows/docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 0f761ec..1d1030a 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -45,7 +45,7 @@ concurrency: cancel-in-progress: false env: - ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@aa879be" + ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@57fa2e5" jobs: apidoc: From 63c084a2d259eb574d92dea0b00e76d832441e56 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 12:57:08 -0400 Subject: [PATCH 57/63] remove debug print --- tests/integration_test/test_sql_integration.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index 905c0d7..9c160dd 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -57,10 +57,5 @@ def test_adms(setup, adm): norm_name = yang_to_sql(adm_set.load_from_file(filepath).norm_name) sql_file = os.path.join(ADMS_DIR, "amp-sql", "Agent_Scripts", 'adm_{name}.sql'.format(name=norm_name)) with open(sql_file, "r") as f: - - # TODO Karen remove debug - content = f.read() - print(content) - - cursor.execute(content) + cursor.execute(f.read()) cursor.execute("rollback") From e550511c2e65e7be2c209b1aad5db8b90c1554b9 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Thu, 29 Aug 2024 13:16:54 -0400 Subject: [PATCH 58/63] fix comment --- tests/integration_test/test_sql_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_test/test_sql_integration.py b/tests/integration_test/test_sql_integration.py index 9c160dd..5f8a357 100644 --- a/tests/integration_test/test_sql_integration.py +++ b/tests/integration_test/test_sql_integration.py @@ -11,8 +11,8 @@ def setup(): """ Connects to the ADMS library session. Cleans up connections once done. @pre: IP Address of the library session should be stored in env var $PGHOST, - username and password should be stored in env vars $PGSQL_USERNAME and - $PGSQL_PASSWORD, respectively + username and password should be stored in env vars $PGUSER and + $PGPASSWORD, respectively @yields tuple of (connection object, AdmSet()) """ From 27bf3f0c3ff9cb0646fef3a33b4d3d609ab15bed Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 30 Aug 2024 10:24:18 -0400 Subject: [PATCH 59/63] capture stdout for debug --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index c0da076..1ab6840 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -138,7 +138,7 @@ jobs: pip install -e '.[test]' git clone ${ADMS_REPO} tests/integration_test/anms-adms - name: Test - run: python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py + run: python3 -m pytest -v -s --cov=camp tests/integration_test/test_sql_integration.py test-integration-c: needs: [build] From 3eb3d244e7c5079061cf270ccb7b5a24fcd1a6a5 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 30 Aug 2024 10:34:41 -0400 Subject: [PATCH 60/63] clear cache --- .github/workflows/build-test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 1ab6840..a87476b 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -138,7 +138,9 @@ jobs: pip install -e '.[test]' git clone ${ADMS_REPO} tests/integration_test/anms-adms - name: Test - run: python3 -m pytest -v -s --cov=camp tests/integration_test/test_sql_integration.py + run: | + rm /github/home/.cache/ace/adms.sqlite + python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py test-integration-c: needs: [build] From f688672203c12a0b1b81a6f0e6b62ec91c189116 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 30 Aug 2024 10:49:58 -0400 Subject: [PATCH 61/63] force? --- .github/workflows/build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index a87476b..07e91fb 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -139,7 +139,7 @@ jobs: git clone ${ADMS_REPO} tests/integration_test/anms-adms - name: Test run: | - rm /github/home/.cache/ace/adms.sqlite + rm -f /github/home/.cache/ace/adms.sqlite python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py test-integration-c: From c023173cb79a2d5dd9b421ba95d50ea62d67fa29 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 30 Aug 2024 10:58:06 -0400 Subject: [PATCH 62/63] remove the cache clear --- .github/workflows/build-test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 07e91fb..c0da076 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -138,9 +138,7 @@ jobs: pip install -e '.[test]' git clone ${ADMS_REPO} tests/integration_test/anms-adms - name: Test - run: | - rm -f /github/home/.cache/ace/adms.sqlite - python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py + run: python3 -m pytest -v --cov=camp tests/integration_test/test_sql_integration.py test-integration-c: needs: [build] From 6168e9abc73147e5154efa4e54879c814ec6ba43 Mon Sep 17 00:00:00 2001 From: Karen Haining Date: Fri, 30 Aug 2024 11:37:38 -0400 Subject: [PATCH 63/63] remove rpt tblt mac from database creation --- .github/workflows/build-test.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index c0da076..73202dc 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -118,13 +118,10 @@ jobs: psql -f Database_Scripts/Views/ari_view.sql psql -f Database_Scripts/Views/ctrl_view.sql psql -f Database_Scripts/Views/edd_view.sql - psql -f Database_Scripts/Views/mac_view.sql psql -f Database_Scripts/Views/oper_view.sql psql -f Database_Scripts/Views/message_view.sql - psql -f Database_Scripts/Views/rpt_view.sql psql -f Database_Scripts/Views/sbr_view.sql psql -f Database_Scripts/Views/tbr_view.sql - psql -f Database_Scripts/Views/tblt_view.sql psql -f Database_Scripts/Views/tnvc_view.sql psql -f Database_Scripts/Views/parm_view.sql psql -f Database_Scripts/Views/var_view.sql