diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 6ef4330..683f9bd 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -31,6 +31,7 @@ function supported_tokens() 'id', 'owner', 'pkey', + 'bhl_bind' //TODO: //'obscured', //'bitfields', diff --git a/tpl/codegen_bundle.twig b/tpl/codegen_bundle.twig index 9f842d8..34082e4 100644 --- a/tpl/codegen_bundle.twig +++ b/tpl/codegen_bundle.twig @@ -4,9 +4,9 @@ using metagen; {%- import "macro.twig" as macro -%} -{% if namespace is defined %} +{#{% if namespace is defined ~%} namespace {{namespace}} { -{% endif %} +{% endif %}#} {{ macro.decl_units(meta) }} @@ -33,7 +33,7 @@ static public class AutogenBundle switch(class_id) { {%- for u in meta.getunits ~%} -{%- if u.object is instanceof('\\mtgMetaEnum') or u.object is instanceof('\\mtgMetaStruct')~%} +{%- if u.object is instanceof('\\mtgMetaStruct')~%} case {{u.object.classid}}: { return new {{u.object.name}}(); } {%- endif ~%} {%- endfor ~%} @@ -49,7 +49,7 @@ static public class AutogenBundle switch(class_id) { {%- for u in meta.getunits ~%} -{%- if u.object is instanceof('\\mtgMetaEnum') or u.object is instanceof('\\mtgMetaStruct')~%} +{%- if u.object is instanceof('\\mtgMetaStruct')~%} case {{u.object.classid}}: { return typeof({{u.object.name}}); } {%- endif ~%} {%- endfor ~%} @@ -61,6 +61,6 @@ static public class AutogenBundle } } -{% if namespace is defined %} +{#{% if namespace is defined ~%} } //namespace {{namespace}} -{% endif %} +{% endif %}#} diff --git a/tpl/macro.twig b/tpl/macro.twig index f9e8192..28febb4 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -22,7 +22,7 @@ {%- endif -%} {{_self.attributes(o)}} -public {{_self.struct_type(o)}} {{o.name}} {{_self.base_class(o)}} +public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}} { {{_self.decl_struct_fields(o)}} @@ -59,8 +59,9 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_class(o)}} reset(); syncFields(ctx); ctx.reader.EndContainer(); - - {{_self.copy_fields(o)}} +{%- if has_token(o, 'bitfields') ~%} + fields_mask = other.fields_mask; +{%- endif ~%} } public {{_self.virtual_clone(o)}} IMetaStruct clone() @@ -94,6 +95,10 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_class(o)}} {%- if has_token(o, 'bitfields') ~%} {{_self.bitmask_helpers(o)}} {%- endif -%} + +{%- if has_token(o, 'bhl_bind') ~%} + {{_self.get_itype(o)}} +{%- endif -%} {{extra}} } @@ -111,7 +116,7 @@ public long fields_mask; {%- macro decl_struct_field(o, f) -%} {{_self.attributes(f)}} -public {{f.type|cs_type}} {{f.name}} {% if not has_token(f, 'POD') -%} {{_self.decl_init_value(f.type)}} {%- endif -%}; +public {{f.type|cs_type}} {{f.name}} {% if not has_token(o, 'POD') -%} {{_self.decl_init_value(f.type)}} {%- endif -%}; {%- endmacro -%} {% macro decl_init_value(type) %} @@ -146,9 +151,13 @@ fields_mask = 0L; {{has_token(o, 'POD') ? 'struct' : 'class'}} {%- endmacro -%} -{%- macro base_class(o) -%} -{%- if not has_token(o, 'POD') -%} -: {{o.parent ? o.parent.name : 'BaseMetaStruct'}} {{has_token(o, 'cloneable')?',IMetaCloneable'}} +{%- macro base_struct_class(o) -%} +{%- if has_token(o, 'POD') -%} +: IMetaStruct +{%- else -%} +: {{o.parent ? o.parent.name : 'BaseMetaStruct'}} +{{- has_token(o, 'cloneable') and not o.parent ? ', IMetaCloneable' -}} +{{- has_token(o, 'bhl_bind') and not o.parent ? ', bhl.ITyped' -}} {%- endif -%} {%- endmacro -%} @@ -158,6 +167,12 @@ override {%- endif -%} {%- endmacro -%} +{%- macro virtual(o) -%} +{%- if not has_token(o, 'POD') -%} +{{o.parent ? 'override' : 'virtual'}} +{%- endif -%} +{%- endmacro -%} + {%- macro comment_POD_begin(o) -%} {%- if has_token(o, 'POD') -%} /* commented in POD @@ -183,18 +198,13 @@ override {%- endmacro -%} {%- macro virtual_clone(o) -%} -{%- if not has_token(o, 'POD') -%} -{%- if o.parent and has_token_in_parent(o.parent, 'cloneable') -%} -override -{%- else -%} -virtual -{%- endif -%} -{%- endif -%} -{%- endmacro -%} - -{%- macro copy_fields(o) -%} -{%- if has_token(o, 'POD') ~%} -fields_mask = other.fields_mask; +{%- if has_token(o, 'cloneable') -%} + {%- if has_token(o, 'POD') -%} + {%- elseif o.parent and has_token_in_parent(o.parent, 'cloneable') -%} + override + {%- else -%} + virtual + {%- endif -%} {%- endif -%} {%- endmacro -%} @@ -253,6 +263,15 @@ base.syncFields(ctx); {%- endmacro -%} + +{% macro get_itype(o) %} + + public {{_self.virtual(o)}} bhl.IType GetIType() + { + return bhl.BHL_Types.Type_{{o.name}}; + } +{%- endmacro -%} + {% macro decl_enum(o) %} {{_self.attributes(o)}} public enum {{o.name}}