summaryrefslogtreecommitdiff
path: root/src/select
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-12-03 13:35:34 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2022-12-03 17:19:50 +0000
commitdf45c6cfb4c385e8a7d6d85d78b5dca7844c37f5 (patch)
tree7406e3fdb0e939b5a8b0dd6f4a4e61a38b045e67 /src/select
parent022a04d022f446b57818dfa7d5b49928f9d63bf4 (diff)
downloadlibcss-df45c6cfb4c385e8a7d6d85d78b5dca7844c37f5.tar.gz
libcss-df45c6cfb4c385e8a7d6d85d78b5dca7844c37f5.tar.bz2
select: generator: Remove dead code
This doesn't change the output of the generator at all. It removes the capability to handle property groups, which has been unused since property grouping was removed. Property grouping was originally an attempt to reduce computed style size, which became redundant complexity when computed styles became interned.
Diffstat (limited to 'src/select')
-rw-r--r--src/select/autogenerated_computed.h1
-rw-r--r--src/select/select_generator.py185
2 files changed, 36 insertions, 150 deletions
diff --git a/src/select/autogenerated_computed.h b/src/select/autogenerated_computed.h
index b26560d..c65cf98 100644
--- a/src/select/autogenerated_computed.h
+++ b/src/select/autogenerated_computed.h
@@ -263,7 +263,6 @@ struct css_computed_style_i {
css_fixed width;
css_fixed word_spacing;
int32_t z_index;
-
};
struct css_computed_style {
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
index 05a4511..ebac659 100644
--- a/src/select/select_generator.py
+++ b/src/select/select_generator.py
@@ -429,21 +429,12 @@ class CSSGroup:
return bits_array
- def get_idot_grp(self):
- """Make parameters for accessing bits and values in this group."""
- i_dot = '' if self.name == 'page' else 'i.'
- grp = '' if self.name == 'style' else '->{}{}'.format(
- '' if self.name == 'page' else i_dot, self.name)
- return (i_dot, grp)
-
def make_computed_h(self):
"""Output this group's text for the computed.h file."""
t = Text()
t.append()
- typedef = 'typedef ' if self.name == 'page' else ''
- t.append('{}struct css_computed_{}{} {{'.format(
- typedef, self.name, '' if self.name == 'page' else '_i'))
+ t.append('struct css_computed_style_i {')
t.comment()
commented = []
@@ -490,103 +481,28 @@ class CSSGroup:
t.append()
t.append(self.make_value_declaration(for_commented=False))
- if self.name == 'style':
- t.append()
- for g in css_groups:
- if g.name != 'style' and g.name != 'page':
- t.append('css_computed_{0} *{0};'.format(g.name))
-
t.indent(-1)
- t.append('}}{};'.format(
- ' css_computed_' + self.name if typedef else ''))
+ t.append('};')
- if self.name != 'page':
- typedef = 'typedef ' if self.name != 'style' else ''
- t.append()
- t.append('{}struct css_computed_{} {{'.format(
- typedef, self.name))
- t.indent(1)
- t.append('struct css_computed_' + self.name + '_i i;')
- t.append()
- t.append(self.make_value_declaration(for_commented=True))
- t.append()
+ t.append()
+ t.append('struct css_computed_style {')
+ t.indent(1)
+ t.append('struct css_computed_style_i i;')
+ t.append()
+ t.append(self.make_value_declaration(for_commented=True))
+ t.append()
- t.append('struct css_computed_' + self.name + ' *next;')
- t.append('uint32_t count;')
- t.append('uint32_t bin;')
- t.indent(-1)
- t.append('}}{};'.format(
- ' css_computed_' + self.name if typedef else ''))
+ t.append('struct css_computed_style *next;')
+ t.append('uint32_t count;')
+ t.append('uint32_t bin;')
+ t.indent(-1)
+ t.append('};')
return t.to_string()
def make_propset_h(self):
- """Output this group's property functions for the propset.h file.
-
- If group is not `style`, will also output the defaults
- and the ENSURE_{group} texts.
- """
+ """Output this group's property functions for the propset.h file."""
t = Text()
- i_dot, grp = self.get_idot_grp()
-
- if self.name != 'style':
- t.append('static const css_computed_{0} default_{0} = {{'.format(
- self.name))
- t.indent(1)
-
- if self.name != 'page':
- t.append('.i = {')
- t.indent(1)
-
- t.append('.bits = {')
- t.indent(1)
-
- bits_ops = []
- for b in self.bits_array:
- or_ops = []
- for p in b.contents:
- or_ops.append('({} << {})'.format(p.defaults, str(p.shift))
- if p.shift else p.defaults)
- bits_ops.append(' | '.join(or_ops))
-
- t.append(',\n'.join(bits_ops).split('\n'))
- t.indent(-1)
- t.append('},')
- t.append(',\n'.join(
- self.make_value_declaration(False, True)).split('\n'))
-
- if self.name != 'page':
- t.indent(-1)
- t.append('},')
- t.append(',\n'.join(
- self.make_value_declaration(True, True) +
- [ '.next = NULL', '.count = 0', '.bin = UINT32_MAX' ]
- ).split('\n'))
-
- t.indent(-1)
- t.append('};')
-
- t.append()
- t.escape_newline()
- t.append('#define ENSURE_{} do {{'.format(self.name.upper()))
- t.indent(1)
- t.append('if (style->{}{} == NULL) {{'.format(i_dot, self.name))
- t.indent(1)
- t.append('style->{}{n} = malloc(sizeof(css_computed_{n}));'.format(
- i_dot, n=self.name))
- t.append('if (style->{}{} == NULL)'.format(i_dot, self.name))
- t.indent(1)
- t.append('return CSS_NOMEM;')
- t.indent(-1)
- t.append()
- t.append('memcpy(style->{}{n}, &default_{n}, '
- 'sizeof(css_computed_{n}));'.format(i_dot, n=self.name))
- t.indent(-1)
- t.append('}')
- t.indent(-1)
- t.append('} while(0)')
- t.escape_newline()
- t.append()
for p in sorted(self.props, key=(lambda x: x.name)):
defines, undefs = p.def_undefs
@@ -611,12 +527,7 @@ class CSSGroup:
t.append('uint32_t *bits;')
t.append()
- if self.name != 'style':
- t.append('ENSURE_{};'.format(self.name.upper()))
- t.append()
-
- t.append('bits = &style{}->{}bits[{}_INDEX];'.format(
- grp, i_dot, p.name.upper()))
+ t.append('bits = &style->i.bits[{}_INDEX];'.format(p.name.upper()))
t.append()
type_mask, shift_list, bits_comment = p.get_bits()
@@ -637,19 +548,17 @@ class CSSGroup:
old_t, old_n_shift = shift_star(v.type, old_n)
if v.name == 'string':
- t.append('{} {} = style{}->{}{};'.format(
- old_t, old_n_shift,
- grp, i_dot, p.name + v.suffix))
+ t.append('{} {} = style->i.{};'.format(
+ old_t, old_n_shift, p.name + v.suffix))
t.append()
t.append('if ({} != NULL) {{'.format(v.name + v.suffix))
t.indent(1)
- t.append('style{}->{}{} = lwc_string_ref({});'.format(
- grp, i_dot, p.name + v.suffix, v.name + v.suffix))
+ t.append('style->i.{} = lwc_string_ref({});'.format(
+ p.name + v.suffix, v.name + v.suffix))
t.indent(-1)
t.append('} else {')
t.indent(1)
- t.append('style{}->{}{} = NULL;'.format(
- grp, i_dot, p.name + v.suffix))
+ t.append('style->i.{} = NULL;'.format(p.name + v.suffix))
t.indent(-1)
t.append('}')
t.append()
@@ -661,9 +570,9 @@ class CSSGroup:
elif v.name == 'string_arr' or v.name == 'counter_arr':
iter_var = 's' if v.name == 'string_arr' else 'c'
iter_deref = '*s' if v.name == 'string_arr' else 'c->name'
- t.append('{} {} = style{}->{};'.format(
+ t.append('{} {} = style->{};'.format(
old_t, old_n_shift,
- grp, p.name + v.suffix))
+ p.name + v.suffix))
t.append('{} {};'.format(old_t,
shift_star(v.type, iter_var)[1]))
t.append()
@@ -674,8 +583,8 @@ class CSSGroup:
t.append('{0} = lwc_string_ref({0});'.format(iter_deref))
t.indent(-1)
t.append()
- t.append('style{}->{} = {};'.format(
- grp, p.name + v.suffix, v.name + v.suffix))
+ t.append('style->{} = {};'.format(
+ p.name + v.suffix, v.name + v.suffix))
t.append()
t.append('/* Free existing array */')
t.append('if ({} != NULL) {{'.format(old_n))
@@ -693,8 +602,8 @@ class CSSGroup:
t.append('}')
elif not v.is_ptr:
- t.append('style{}->{}{} = {};'.format(
- grp, i_dot, p.name + v.suffix, v.name + v.suffix))
+ t.append('style->i.{} = {};'.format(
+ p.name + v.suffix, v.name + v.suffix))
else:
raise ValueError('Cannot handle value ' + v.name +'!')
@@ -708,23 +617,18 @@ class CSSGroup:
return t.to_string()
def print_propget(self, t, p, only_bits=False):
- i_dot, grp = self.get_idot_grp()
-
vals = [] if only_bits else p.get_param_values(pointer=True)
params = ', '.join([ 'css_computed_style *style' ]
+ [ ' '.join(x) for x in vals ])
+
underscore_bits = '_bits' if only_bits else ''
t.append('static inline uint8_t get_{}{}(const {})'.format(
p.name, underscore_bits, params))
t.append('{')
t.indent(1)
- if self.name != 'style':
- t.append('if (style{} != NULL) {{'.format(grp))
- t.indent(1)
-
- t.append('uint32_t bits = style{}->{}bits[{}_INDEX];'.format(
- grp, i_dot, p.name.upper()))
+ t.append('uint32_t bits = style->i.bits[{}_INDEX];'.format(
+ p.name.upper()))
t.append('bits &= {}_MASK;'.format(p.name.upper()))
t.append('bits >>= {}_SHIFT;'.format(p.name.upper()))
t.append()
@@ -733,16 +637,15 @@ class CSSGroup:
t.append(bits_comment)
if only_bits == False:
-
if p.condition:
t.append('if ((bits & {}) == {}) {{'.format(
type_mask, p.condition))
t.indent(1)
for v in p.values:
- this_idot = '' if v.is_ptr and v.name != 'string' else i_dot
- t.append('*{} = style{}->{}{};'.format(
- v.name + v.suffix, grp, this_idot, p.name + v.suffix))
+ i_dot = '' if v.is_ptr and v.name != 'string' else 'i.'
+ t.append('*{} = style->{}{};'.format(
+ v.name + v.suffix, i_dot, p.name + v.suffix))
for i, v in enumerate(list(reversed(shift_list))):
if i == 0:
t.append('*{} = bits >> {};'.format(v[0], v[1]))
@@ -757,18 +660,6 @@ class CSSGroup:
t.append('return (bits & {});'.format(type_mask))
- if self.name != 'style':
- t.indent(-1)
- t.append('}')
- t.append()
- t.append('/* Initial value */')
- for v in p.values:
- t.append('*{} = {};'.format(v.name + v.suffix, v.defaults))
- if v.bits is not None:
- t.append('*{} = {};'.format(
- v.bits['name'] + v.suffix, v.bits['defaults']))
- t.append('return {};'.format(p.defaults))
-
t.indent(-1)
t.append('}')
@@ -793,7 +684,7 @@ class CSSGroup:
return t.to_string()
- def make_value_declaration(self, for_commented, defaults=False):
+ def make_value_declaration(self, for_commented):
"""Output declarations of values for this group's properties.
Args:
@@ -805,12 +696,8 @@ class CSSGroup:
for p in sorted(self.props, key=(lambda x: x.name)):
if bool(p.comments) == for_commented:
for v in p.values:
- if defaults:
- r.append('.{}{} = {}'.format(p.name, v.suffix,
- v.defaults))
- else:
- v_type, v_name = shift_star(v.type, p.name)
- r.append('{} {}{};'.format(v_type, v_name, v.suffix))
+ v_type, v_name = shift_star(v.type, p.name)
+ r.append('{} {}{};'.format(v_type, v_name, v.suffix))
return r
def make_text(self, filename):