Virtual inheritance prototype for select

This commit is contained in:
Thomas Krijnen
2021-09-06 18:52:37 +02:00
parent 66faea1285
commit 41f2b11234
25 changed files with 8202 additions and 8158 deletions
@@ -23,11 +23,16 @@ import codegen
import templates
import documentation
from collections import defaultdict
class Header(codegen.Base):
def __init__(self, mapping):
declarations = []
case_lookup = lambda nm: [k for k in mapping.schema.keys if k.lower() == nm.lower()][0]
case_normalize = lambda nm: nm if nm.startswith("IfcUtil::") else case_lookup(nm)
create_supertype_statement = lambda nms: ", ".join("public %s %s" % ("" if c.startswith("IfcUtil::") else "",c) for c in nms)
write = lambda str, **kwargs: declarations.append(
str
% dict({"documentation": templates.multi_line_comment(documentation.description(kwargs["name"]))}, **kwargs)
@@ -36,9 +41,19 @@ class Header(codegen.Base):
forward_names = list(mapping.schema.entities.keys()) + list(mapping.schema.simpletypes.keys())
forward_definitions = "".join(["class %s; " % n for n in forward_names])
select_super_types = defaultdict(list)
for name, type in mapping.schema.selects.items():
for nm in type.values:
select_super_types[str(nm).lower()].append(name)
write(templates.select, name=name)
def get_select_super_types(nm):
x = list(select_super_types[nm.lower()])
for y in x:
x.extend(get_select_super_types(y))
return set(x)
for name, type in mapping.schema.enumerations.items():
short_name = name[:-4] if name.endswith("Enum") else name
write(templates.enumeration, name=name, values=", ".join(["%s_%s" % (short_name, v) for v in type.values]))
@@ -46,19 +61,31 @@ class Header(codegen.Base):
emitted_simpletypes = set()
while len(emitted_simpletypes) < len(mapping.schema.simpletypes):
for name, type in mapping.schema.simpletypes.items():
if name.lower() in emitted_simpletypes:
continue
type_str = mapping.make_type_string(mapping.flatten_type_string(type))
attr_type = mapping.make_argument_type(type)
superclass = mapping.simple_type_parent(name)
if superclass is None:
superclass = "IfcUtil::IfcBaseType"
elif superclass.lower() not in emitted_simpletypes:
continue
superclasses = []
if superclass is not None:
superclasses.append(superclass)
else:
# Case normalize
superclass = [k for k in mapping.schema.simpletypes.keys() if k.lower() == superclass.lower()][0]
superclasses.append("IfcUtil::IfcBaseType")
superclasses.extend(get_select_super_types(name))
is_emitted = lambda nm: nm == "IfcUtil::IfcBaseType" or nm in mapping.schema.selects or nm.lower() in emitted_simpletypes
if not all(map(is_emitted, superclasses)):
continue
superclasses = list(map(case_normalize, superclasses))
emitted_simpletypes.add(name.lower())
superclass = create_supertype_statement(superclasses)
write(templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass)
class_definitions = []
@@ -73,6 +100,7 @@ class Header(codegen.Base):
for name, type in mapping.schema.entities.items():
if name.lower() in emitted_entities:
continue
if len(type.supertypes) == 0 or set(map(str.lower, type.supertypes)) <= emitted_entities:
attr_lines = []
@@ -106,13 +134,11 @@ class Header(codegen.Base):
if len(inverse):
inverse += "\n"
def case_norm(n):
n = n.lower()
return [k for k in mapping.schema.entities.keys() if k.lower() == n][0]
supertypes = map(case_norm, type.supertypes) if len(type.supertypes) else ["IfcUtil::IfcBaseEntity"]
superclass = ": %s " % (", ".join(["public %s" % c for c in supertypes]))
supertypes = list(type.supertypes) if len(type.supertypes) else ["IfcUtil::IfcBaseEntity"]
supertypes.extend(get_select_super_types(name))
supertypes = list(map(case_normalize, supertypes))
superclass = create_supertype_statement(supertypes)
argument_count = mapping.argument_count(type)
argument_start = argument_count - len(type.attributes)
@@ -107,7 +107,7 @@ derived_field_statement = " {std::set<int> idxs; %(statements)sderived_map[Ty
derived_field_statement_attrs = "idxs.insert(%d); "
simpletype = """%(documentation)s
class IFC_PARSE_API %(name)s : public %(superclass)s {
class IFC_PARSE_API %(name)s : %(superclass)s {
public:
virtual const IfcParse::type_declaration& declaration() const;
static const IfcParse::type_declaration& Class();
@@ -137,7 +137,7 @@ simpletype_impl_cast_templated = (
simpletype_impl_declaration = "return *%(schema_name_upper)s_%(class_name)s_type;"
select = """%(documentation)s
typedef IfcUtil::IfcBaseClass %(name)s;
class IFC_PARSE_API %(name)s : public virtual IfcUtil::IfcBaseInterface {};
"""
enumeration = """class IFC_PARSE_API %(name)s : public IfcUtil::IfcBaseType {
@@ -157,7 +157,7 @@ public:
"""
entity = """%(documentation)s
class IFC_PARSE_API %(name)s %(superclass)s{
class IFC_PARSE_API %(name)s : %(superclass)s {
public:
%(attributes)s %(inverse)s virtual const IfcParse::entity& declaration() const;
static const IfcParse::entity& Class();