From c634bffa100801fd6158891bd07ba9605d2ea416 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 14 Feb 2023 10:02:58 +0100 Subject: [PATCH] Update reverse compilation to eliminate getattr() calls --- .../ifcopenshell/express/rule_executor.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/express/rule_executor.py b/src/ifcopenshell-python/ifcopenshell/express/rule_executor.py index 5579d3cf41..238f7890e5 100644 --- a/src/ifcopenshell-python/ifcopenshell/express/rule_executor.py +++ b/src/ifcopenshell-python/ifcopenshell/express/rule_executor.py @@ -1,4 +1,5 @@ import os +import re import ast import collections import ifcopenshell @@ -7,7 +8,24 @@ from codegen import indent def reverse_compile(s): - return s.strip().replace("len(", "SIZEOF(").replace("assert ", "").replace(" is not False", "") + return re.sub( + "\s*\-\s*EXPRESS_ONE_BASED_INDEXING", + "", + re.sub( + ", )?+.(, INDETERMINATE)\\"[::-1], + "]\\1[", + re.sub( + r", '(\w+)', INDETERMINATE\)", + ".\\1", + s.strip() + .replace("len(", "SIZEOF(") + .replace("assert ", "") + .replace(" is not False", "") + .replace("getattr(", "") + .replace("express_getitem(", ""), + )[::-1], + )[::-1], + ) @dataclass