From a031310a662304d4624b5bc0ed455685bc134a49 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 19 Aug 2026 17:57:13 +0500 Subject: [PATCH] express/run.bat: rewrite in Python --- .../ifcopenshell/express/bootstrap.py | 2 +- .../ifcopenshell/express/cat.py | 16 -- .../ifcopenshell/express/express_parser.py | 1 - .../ifcopenshell/express/run.bat | 199 ------------------ .../express/txt/header_ifc2x3.txt | 25 --- .../ifcopenshell/express/txt/header_ifc4.txt | 25 --- .../express/txt/header_ifc4x1.txt | 25 --- .../express/txt/header_ifc4x2.txt | 25 --- .../express/txt/header_ifc4x3_add1.txt | 25 --- .../express/txt/header_ifc4x3_add2.txt | 25 --- .../express/txt/header_ifc4x3_rc1.txt | 25 --- .../express/txt/header_ifc4x3_rc2.txt | 25 --- .../express/txt/header_ifc4x3_tc1.txt | 25 --- .../scripts/generate-exp-cpp.py | 150 +++++++++++++ 14 files changed, 151 insertions(+), 442 deletions(-) delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/cat.py delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/run.bat delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc2x3.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x1.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x2.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add1.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add2.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc1.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc2.txt delete mode 100644 src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_tc1.txt create mode 100755 src/ifcopenshell-python/scripts/generate-exp-cpp.py diff --git a/src/ifcopenshell-python/ifcopenshell/express/bootstrap.py b/src/ifcopenshell-python/ifcopenshell/express/bootstrap.py index 2e2fc2e120..e6056feea8 100644 --- a/src/ifcopenshell-python/ifcopenshell/express/bootstrap.py +++ b/src/ifcopenshell-python/ifcopenshell/express/bootstrap.py @@ -258,5 +258,5 @@ if __name__ == "__main__": for output in sys.argv[2:]: mdl = importlib.import_module(output) mdl.Generator(m).emit() - sys.stdout.write(m.schema.name) + print(m.schema.name) """ % ("\n ".join(statements))) diff --git a/src/ifcopenshell-python/ifcopenshell/express/cat.py b/src/ifcopenshell-python/ifcopenshell/express/cat.py deleted file mode 100644 index 373afeb1d5..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/cat.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys, fileinput - -if sys.platform == "win32" and not hasattr(sys.stdout, "buffer"): - import os, msvcrt - - msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) - -files = sys.argv[1:] -if files[0] == "-o": - b = open(files[1], "wb") - files = files[2:] -else: - b = getattr(sys.stdout, "buffer", sys.stdout) - -for line in fileinput.input(files=files, mode="rb"): - b.write(line) diff --git a/src/ifcopenshell-python/ifcopenshell/express/express_parser.py b/src/ifcopenshell-python/ifcopenshell/express/express_parser.py index 34bb69585c..7508b895a4 100644 --- a/src/ifcopenshell-python/ifcopenshell/express/express_parser.py +++ b/src/ifcopenshell-python/ifcopenshell/express/express_parser.py @@ -486,5 +486,4 @@ if __name__ == "__main__": for output in sys.argv[2:]: mdl = importlib.import_module(output) mdl.Generator(m).emit() - sys.stdout.write(m.schema.name) diff --git a/src/ifcopenshell-python/ifcopenshell/express/run.bat b/src/ifcopenshell-python/ifcopenshell/express/run.bat deleted file mode 100644 index 9a8be5c466..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/run.bat +++ /dev/null @@ -1,199 +0,0 @@ -@ECHO OFF - -:: python bootstrap.py express.bnf > express_parser.py - -IF EXIST IFC2X3_TC1.exp ( - python express_parser.py IFC2X3_TC1.exp header implementation schema_class definitions - - IF EXIST Ifc2x3-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3.cpp txt/header_ifc2x3.txt Ifc2x3.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3.h txt/header_ifc2x3.txt Ifc2x3.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3-schema.cpp txt/header_ifc2x3.txt Ifc2x3-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3-definitions.h txt/header_ifc2x3.txt Ifc2x3-definitions.h - ) ELSE ( - :: v0.5.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3.cpp txt/header_ifc2x3.txt txt/ifndef_ifc4.txt Ifc2x3.cpp txt/endif.txt - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3.h txt/header_ifc2x3.txt Ifc2x3.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3enum.h txt/header_ifc2x3.txt Ifc2x3enum.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3-latebound.cpp txt/header_ifc2x3.txt txt/ifndef_ifc4.txt Ifc2x3-latebound.cpp txt/endif.txt - python cat.py -o ..\..\..\ifcparse\schemas\Ifc2x3-latebound.h txt/header_ifc2x3.txt Ifc2x3-latebound.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4_ADD2TC1.exp ( - python express_parser.py IFC4_ADD2TC1.exp header implementation schema_class definitions - - IF EXIST Ifc4-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4.cpp txt/header_ifc4.txt Ifc4.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4.h txt/header_ifc4.txt Ifc4.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4-schema.cpp txt/header_ifc4.txt Ifc4-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4-definitions.h txt/header_ifc4.txt Ifc4-definitions.h - ) ELSE ( - :: v0.5.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4.cpp txt/header_ifc4.txt txt/ifdef_ifc4.txt Ifc4.cpp txt/endif.txt - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4.h txt/header_ifc4.txt Ifc4.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4enum.h txt/header_ifc4.txt Ifc4enum.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4-latebound.cpp txt/header_ifc4.txt txt/ifdef_ifc4.txt Ifc4-latebound.cpp txt/endif.txt - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4-latebound.h txt/header_ifc4.txt Ifc4-latebound.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x1.exp ( - python express_parser.py IFC4x1.exp header implementation schema_class definitions - - IF EXIST Ifc4x1-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x1.cpp txt/header_ifc4x1.txt Ifc4x1.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x1.h txt/header_ifc4x1.txt Ifc4x1.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x1-schema.cpp txt/header_ifc4x1.txt Ifc4x1-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x1-definitions.h txt/header_ifc4x1.txt Ifc4x1-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x2.exp ( - python express_parser.py IFC4x2.exp header implementation schema_class definitions - - IF EXIST Ifc4x2-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x2.cpp txt/header_ifc4x2.txt Ifc4x2.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x2.h txt/header_ifc4x2.txt Ifc4x2.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x2-schema.cpp txt/header_ifc4x2.txt Ifc4x2-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x2-definitions.h txt/header_ifc4x2.txt Ifc4x2-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x3_RC1.exp ( - python express_parser.py IFC4x3_RC1.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_rc1-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc1.cpp txt/header_ifc4x3_rc1.txt Ifc4x3_rc1.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc1.h txt/header_ifc4x3_rc1.txt Ifc4x3_rc1.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc1-schema.cpp txt/header_ifc4x3_rc1.txt Ifc4x3_rc1-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc1-definitions.h txt/header_ifc4x3_rc1.txt Ifc4x3_rc1-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x3_RC2.exp ( - python express_parser.py IFC4x3_RC2.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_rc2-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc2.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc2.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc2.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc2.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc2-schema.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc2-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc2-definitions.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc2-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x3_RC3.exp ( - python express_parser.py IFC4x3_RC3.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_rc3-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc3.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc3.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc3.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc3.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc3-schema.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc3-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc3-definitions.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc3-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4x3_RC4.exp ( - python express_parser.py IFC4x3_RC4.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_rc4-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc4.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc4.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc4.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc4.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc4-schema.cpp txt/header_ifc4x3_rc2.txt Ifc4x3_rc4-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_rc4-definitions.h txt/header_ifc4x3_rc2.txt Ifc4x3_rc4-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4X3.exp ( - python express_parser.py IFC4X3.exp header implementation schema_class definitions - - IF EXIST Ifc4x3-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3.cpp txt/header_ifc4x3_rc2.txt Ifc4x3.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3.h txt/header_ifc4x3_rc2.txt Ifc4x3.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3-schema.cpp txt/header_ifc4x3_rc2.txt Ifc4x3-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3-definitions.h txt/header_ifc4x3_rc2.txt Ifc4x3-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4X3_TC1.exp ( - python express_parser.py IFC4X3_TC1.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_tc1-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_tc1.cpp txt/header_ifc4x3_tc1.txt Ifc4x3_tc1.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_tc1.h txt/header_ifc4x3_tc1.txt Ifc4x3_tc1.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_tc1-schema.cpp txt/header_ifc4x3_tc1.txt Ifc4x3_tc1-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_tc1-definitions.h txt/header_ifc4x3_tc1.txt Ifc4x3_tc1-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4X3_ADD1.exp ( - python express_parser.py IFC4X3_ADD1.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_add1-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add1.cpp txt/header_ifc4x3_add1.txt Ifc4x3_add1.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add1.h txt/header_ifc4x3_add1.txt Ifc4x3_add1.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add1-schema.cpp txt/header_ifc4x3_add1.txt Ifc4x3_add1-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add1-definitions.h txt/header_ifc4x3_add1.txt Ifc4x3_add1-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST IFC4X3_ADD2.exp ( - python express_parser.py IFC4X3_ADD2.exp header implementation schema_class definitions - - IF EXIST Ifc4x3_add2-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add2.cpp txt/header_ifc4x3_add2.txt Ifc4x3_add2.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add2.h txt/header_ifc4x3_add2.txt Ifc4x3_add2.h - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add2-schema.cpp txt/header_ifc4x3_add2.txt Ifc4x3_add2-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Ifc4x3_add2-definitions.h txt/header_ifc4x3_add2.txt Ifc4x3_add2-definitions.h - ) - - del *.cpp *.h -) - -IF EXIST header_schema.exp ( - python express_parser.py header_schema.exp header implementation schema_class definitions - - IF EXIST Header_section_schema-schema.cpp ( - :: v0.6.0 - python cat.py -o ..\..\..\ifcparse\schemas\Header_section_schema.cpp Header_section_schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Header_section_schema.h Header_section_schema.h - python cat.py -o ..\..\..\ifcparse\schemas\Header_section_schema-schema.cpp Header_section_schema-schema.cpp - python cat.py -o ..\..\..\ifcparse\schemas\Header_section_schema-definitions.h Header_section_schema-definitions.h - ) - - del *.cpp *.h -) diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc2x3.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc2x3.txt deleted file mode 100644 index 2487658eb8..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc2x3.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC2X3_TC1.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4.txt deleted file mode 100644 index 52da1accf8..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x1.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x1.txt deleted file mode 100644 index dfacb0e04b..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x1.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4x1.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x2.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x2.txt deleted file mode 100644 index 5f6f1f75a7..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x2.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4x2.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add1.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add1.txt deleted file mode 100644 index 85aac44883..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add1.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4X3_ADD1.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add2.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add2.txt deleted file mode 100644 index 6616f73b69..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_add2.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4X3_ADD2.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc1.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc1.txt deleted file mode 100644 index 208e687c24..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc1.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4x3_RC1.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc2.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc2.txt deleted file mode 100644 index 5d228771fd..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_rc2.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4x3_RC2.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_tc1.txt b/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_tc1.txt deleted file mode 100644 index cb46c3274f..0000000000 --- a/src/ifcopenshell-python/ifcopenshell/express/txt/header_ifc4x3_tc1.txt +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This file has been generated from IFC4X3_TC1.exp. Do not make modifications * - * but instead modify the python script that has been used to generate this. * - * * - ********************************************************************************/ diff --git a/src/ifcopenshell-python/scripts/generate-exp-cpp.py b/src/ifcopenshell-python/scripts/generate-exp-cpp.py new file mode 100755 index 0000000000..1ba41e7039 --- /dev/null +++ b/src/ifcopenshell-python/scripts/generate-exp-cpp.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +# /// script +# /// +"""Generate C++ ifcparse schema sources from EXPRESS (.exp) definitions +and copy them into src/ifcparse/schemas. + +Usage: + python generate-exp-cpp.py +""" + +import itertools +import shlex +import subprocess +import sys +from pathlib import Path +from typing import NamedTuple + + +class Schema(NamedTuple): + exp: str + schema_name: str + + +LICENSE_HEADER = """\ +/******************************************************************************** + * * + * This file is part of IfcOpenShell. * + * * + * IfcOpenShell is free software: you can redistribute it and/or modify * + * it under the terms of the Lesser GNU General Public License as published by * + * the Free Software Foundation, either version 3.0 of the License, or * + * (at your option) any later version. * + * * + * IfcOpenShell is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Lesser GNU General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see . * + * * + ********************************************************************************/ + +/******************************************************************************** + * * +{exp_line} + * but instead modify the python script that has been used to generate this. * + * * + ********************************************************************************/ +""" + +BOX_WIDTH = 81 + + +def generated_header(exp: str) -> str: + text = f" * This file has been generated from {exp}. Do not make modifications" + exp_line = text + " " * (BOX_WIDTH - len(text) - 1) + "*" + return LICENSE_HEADER.format(exp_line=exp_line) + + +class C: + RED = "\033[31m" + GREEN = "\033[32m" + RESET = "\033[0m" + + +SCRIPT_DIR = Path(__file__).resolve().parent +REPO_ROOT = Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], cwd=SCRIPT_DIR, text=True).strip()) +EXPRESS_DIR = REPO_ROOT / "src" / "ifcopenshell-python" / "ifcopenshell" / "express" +SCHEMAS_DIR = REPO_ROOT / "src" / "ifcparse" / "schemas" + + +def run(*cmd: str) -> None: + print("$", shlex.join(cmd)) + subprocess.check_call(cmd, cwd=EXPRESS_DIR) + + +def write_generated_file(out: str, exp: str, *ins: str) -> None: + out_path = SCHEMAS_DIR / out + with out_path.open("w") as f_out: + f_out.write(generated_header(exp)) + for fn in ins: + f_out.write((EXPRESS_DIR / fn).read_text()) + print(f"{C.GREEN}wrote {out_path}{C.RESET}") + + +def cleanup() -> None: + for fn in itertools.chain(EXPRESS_DIR.glob("*.cpp"), EXPRESS_DIR.glob("*.h")): + fn.unlink() + + +def run_express_parser(exp: str) -> None: + run( + sys.executable, + "express_parser.py", + exp, + "header", + "implementation", + "schema_class", + "definitions", + ) + + +def generate_schema(schema: Schema) -> None: + if not (EXPRESS_DIR / schema.exp).exists(): + print(f"{C.RED}skipping {schema.exp}, not found{C.RESET}") + return + + run_express_parser(schema.exp) + + name = schema.schema_name + write_generated_file(f"{name}.cpp", schema.exp, f"{name}.cpp") + write_generated_file(f"{name}.h", schema.exp, f"{name}.h") + write_generated_file(f"{name}-schema.cpp", schema.exp, f"{name}-schema.cpp") + write_generated_file(f"{name}-definitions.h", schema.exp, f"{name}-definitions.h") + + cleanup() + + +SCHEMAS = [ + Schema("IFC2X3_TC1.exp", "Ifc2x3"), + Schema("IFC4_ADD2_TC1.exp", "Ifc4"), + Schema("IFC4x1.exp", "Ifc4x1"), + Schema("IFC4x2.exp", "Ifc4x2"), + Schema("IFC4x3_RC1.exp", "Ifc4x3_rc1"), + Schema("IFC4x3_RC2.exp", "Ifc4x3_rc2"), + Schema("IFC4x3_RC3.exp", "Ifc4x3_rc3"), + Schema("IFC4x3_RC4.exp", "Ifc4x3_rc4"), + Schema("IFC4X3.exp", "Ifc4x3"), + Schema("IFC4X3_TC1.exp", "Ifc4x3_tc1"), + Schema("IFC4X3_ADD1.exp", "Ifc4x3_add1"), + Schema("IFC4X3_ADD2.exp", "Ifc4x3_add2"), +] + + +def main() -> None: + for schema in SCHEMAS: + generate_schema(schema) + + run_express_parser("header_schema.exp") + + write_generated_file("Header_section_schema.cpp", "header_schema.exp", "Header_section_schema.cpp") + write_generated_file("Header_section_schema.h", "header_schema.exp", "Header_section_schema.h") + write_generated_file("Header_section_schema-schema.cpp", "header_schema.exp", "Header_section_schema-schema.cpp") + + cleanup() + + +if __name__ == "__main__": + main()