# Stores a list of classes with elements (index, classname, [propertyIDs, ..]). self._api_classes = [] ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids')) for i, classname in enumerate(properties_for_class.keys()): self._api_classes.append(ApiClass( index=i + 1, classname=classname, property_ids=properties_for_class[classname] )) @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') def generate_property_descriptor_cpp(self): return { 'api_classes': self._api_classes, } # Provides a function object given the classname of the property. # This returned function generates a .h file for the specified property. def generate_property_api_h_builder(self, api_classname): @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') def generate_property_api_h(): return { 'api_classname': api_classname, } return generate_property_api_h if __name__ == '__main__': in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv)
@template_expander.use_jinja('ComputedStyleBase.h.tmpl') def generate_base_computed_style_h(self): return { 'properties': self._properties, 'enums': self._computed_enums, 'fields': self._fields, 'expected_total_field_bytes': self._expected_total_field_bytes, } @template_expander.use_jinja('ComputedStyleBase.cpp.tmpl') def generate_base_computed_style_cpp(self): return { 'properties': self._properties, 'enums': self._computed_enums, 'fields': self._fields, 'expected_total_field_bytes': self._expected_total_field_bytes, } @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') def generate_base_computed_style_constants(self): return { 'properties': self._properties, 'enums': self._computed_enums, 'fields': self._fields, 'expected_total_field_bytes': self._expected_total_field_bytes, } if __name__ == '__main__': in_generator.Maker(ComputedStyleBaseWriter).main(sys.argv)
import template_expander # We want exactly the same parsing as RuntimeFeatureWriter # but generate different files. class OriginTrialsWriter(make_runtime_features.RuntimeFeatureWriter): class_name = 'OriginTrials' def __init__(self, in_file_path): super(OriginTrialsWriter, self).__init__(in_file_path) self._outputs = { (self.class_name + '.cpp'): self.generate_implementation, (self.class_name + '.h'): self.generate_header, } @template_expander.use_jinja(class_name + '.cpp.tmpl') def generate_implementation(self): return { 'features': self._features, } @template_expander.use_jinja(class_name + '.h.tmpl') def generate_header(self): return { 'features': self._features, } if __name__ == '__main__': in_generator.Maker(OriginTrialsWriter).main(sys.argv)
interface_counts = defaultdict(int) for tag in tags: tag['interface'] = self._interface(tag) interface_counts[tag['interface']] += 1 for tag in tags: tag['multipleTagNames'] = (interface_counts[tag['interface']] > 1 or tag['interface'] == self.fallbackInterface) @template_expander.use_jinja("ElementTypeHelpers.h.tmpl", filters=filters) def generate_helper_header(self): return self._template_context def _interface(self, tag): if tag['interfaceName']: return tag['interfaceName'] name = name_utilities.upper_first(tag['name']) # FIXME: We shouldn't hard-code HTML here. if name == 'HTML': name = 'Html' dash = name.find('-') while dash != -1: name = name[:dash] + name[dash + 1].upper() + name[dash + 2:] dash = name.find('-') return '%s%sElement' % (self.namespace, name) if __name__ == "__main__": in_generator.Maker(MakeElementTypeHelpersWriter).main(sys.argv)
property['should_declare_functions'] = not property[ 'use_handlers_for'] and not property[ 'direction_aware'] and not property['skip'] self._properties = dict((property['property_id'], property) for property in self._properties) @template_expander.use_jinja('StyleBuilderFunctions.h.tmpl', filters=filters) def generate_style_builder_functions_h(self): return { 'properties': self._properties, } @template_expander.use_jinja('StyleBuilderFunctions.cpp.tmpl', filters=filters) def generate_style_builder_functions_cpp(self): return { 'properties': self._properties, } @template_expander.use_jinja('StyleBuilder.cpp.tmpl', filters=filters) def generate_style_builder(self): return { 'properties': self._properties, } if __name__ == '__main__': in_generator.Maker(StyleBuilderWriter).main(sys.argv)
for dependant_name in feature['depends_on']: enabled_condition += ' && is%sEnabled' % dependant_name feature['enabled_condition'] = enabled_condition self._standard_features = [ feature for feature in self._features if not feature['custom'] ] def _feature_sets(self): # Another way to think of the status levels is as "sets of features" # which is how we're referring to them in this generator. return list(self.valid_values['status']) def _template_inputs(self): return { 'features': self._features, 'feature_sets': self._feature_sets(), 'standard_features': self._standard_features, } @template_expander.use_jinja(class_name + '.h.tmpl') def generate_header(self): return self._template_inputs() @template_expander.use_jinja(class_name + '.cpp.tmpl') def generate_implementation(self): return self._template_inputs() if __name__ == '__main__': in_generator.Maker(RuntimeFeatureWriter).main(sys.argv)
# FIXME: some of these might be better in a utils file def _camelcase_property_name(self, property_name): return re.sub(r'(^[^-])|-(.)', lambda match: (match.group(1) or match.group(2)).upper(), property_name) def _create_css_property_name_enum_value(self, property_name): return "CSSProperty" + property_name def _lower_first(self, string): lowered = string[0].lower() + string[1:] lowered = lowered.replace("cSS", "css") return lowered @template_expander.use_jinja("StylePropertyShorthand.cpp.tmpl") def generate_style_property_shorthand_cpp(self): return { "properties": self._properties, "longhands_dictionary": self._longhand_dictionary, } @template_expander.use_jinja("StylePropertyShorthand.h.tmpl") def generate_style_property_shorthand_h(self): return { "properties": self._properties, } if __name__ == "__main__": in_generator.Maker(StylePropertyShorthandWriter).main(sys.argv)
def __init__(self, in_file_path, enabled_conditions): super(MakeNamesWriter, self).__init__(in_file_path, enabled_conditions) namespace = self.in_file.parameters['namespace'].strip('"') export = self.in_file.parameters['export'].strip('"') assert namespace, 'A namespace is required.' self._outputs = { (namespace + 'Names.h'): self.generate_header, (namespace + 'Names.cpp'): self.generate_implementation, } self._template_context = { 'namespace': namespace, 'export': export, 'entries': self.in_file.name_dictionaries, } @template_expander.use_jinja("MakeNames.h.tmpl", filters=filters) def generate_header(self): return self._template_context @template_expander.use_jinja("MakeNames.cpp.tmpl", filters=filters) def generate_implementation(self): return self._template_context if __name__ == "__main__": in_generator.Maker(MakeNamesWriter).main(sys.argv)
self.flush_codeblock() self._output = self._output.strip() return self._output @classmethod def minimize_css(cls, content): minimizer = CSSMinimizer() return minimizer.parse(content) class CSSMinimizerWriter(in_generator.GenericWriter): def __init__(self, in_file_paths): super(CSSMinimizerWriter, self).__init__(in_file_paths) self._outputs = {} for in_file_path in in_file_paths: out_path = os.path.basename(in_file_path) self._outputs[out_path] = functools.partial( self.generate_implementation, in_file_path) def generate_implementation(self, in_file_path): content = '' with open(os.path.abspath(in_file_path)) as in_file: content = in_file.read() return CSSMinimizer.minimize_css(content) if __name__ == '__main__': in_generator.Maker(CSSMinimizerWriter).main(sys.argv)
namespace_prefix, 'namespace_uri': namespace_uri, 'use_namespace_for_attrs': use_namespace_for_attrs, 'tags': self.tags_in_file.name_dictionaries if self.tags_in_file else [], 'attrs': self.attrs_in_file.name_dictionaries, } def _parameter(self, name): parameter = self.attrs_in_file.parameters[name].strip('"') if self.tags_in_file: assert parameter == self.tags_in_file.parameters[name].strip( '"'), 'Both in files must have the same %s.' % name return parameter @template_expander.use_jinja('MakeQualifiedNames.h.tmpl', filters=filters) def generate_header(self): return self._template_context @template_expander.use_jinja('MakeQualifiedNames.cpp.tmpl', filters=filters) def generate_implementation(self): return self._template_context if __name__ == "__main__": in_generator.Maker(MakeQualifiedNamesWriter).main(sys.argv)
types.append('SimpleLength') types.append('CalcLength') else: types.append(singleType) property['typedom_types'] = types # Generate Keyword ID values from keywords. property['keywordIDs'] = map(enum_for_css_keyword, property['keywords']) self._outputs = { 'CSSOMTypes.cpp': self.generate_types, 'CSSOMKeywords.cpp': self.generate_keywords, } @template_expander.use_jinja('CSSOMTypes.cpp.tmpl') def generate_types(self): return { 'properties': self._properties, } @template_expander.use_jinja('CSSOMKeywords.cpp.tmpl') def generate_keywords(self): return { 'properties': self._properties, } if __name__ == '__main__': in_generator.Maker(CSSOMTypesWriter).main(sys.argv)
base_header_for_suffix = '' if self.suffix: base_header_for_suffix = '\n#include "core/%(namespace)sHeaders.h"\n' % { 'namespace': self.namespace } return HEADER_TEMPLATE % { 'license': license.license_for_generated_cpp(), 'namespace': self.namespace, 'suffix': self.suffix, 'base_header_for_suffix': base_header_for_suffix, 'includes': '\n'.join( self._headers_header_includes(self.in_file.name_dictionaries)), } @template_expander.use_jinja('EventFactory.cpp.tmpl', filters=filters) def generate_implementation(self): return { 'namespace': self.namespace, 'suffix': self.suffix, 'events': self.in_file.name_dictionaries, } if __name__ == "__main__": in_generator.Maker(EventFactoryWriter).main(sys.argv)
import template_expander # We want exactly the same parsing as RuntimeFeatureWriter # but generate different files. class ExperimentalFeatureWriter(make_runtime_features.RuntimeFeatureWriter): class_name = 'ExperimentalFeatures' def __init__(self, in_file_path): super(ExperimentalFeatureWriter, self).__init__(in_file_path) self._outputs = { (self.class_name + '.cpp'): self.generate_implementation, (self.class_name + '.h'): self.generate_header, } @template_expander.use_jinja(class_name + '.cpp.tmpl') def generate_implementation(self): return { 'features': self._features, } @template_expander.use_jinja(class_name + '.h.tmpl') def generate_header(self): return { 'features': self._features, } if __name__ == '__main__': in_generator.Maker(ExperimentalFeatureWriter).main(sys.argv)
self.in_file.name_dictionaries.sort(key=lambda entry: entry['name']) self._outputs = { ('InternalSettingsGenerated.h'): self.generate_header, ('InternalSettingsGenerated.cpp'): self.generate_implementation, ('InternalSettingsGenerated.idl'): self.generate_idl, } self._template_context = { 'settings': self.in_file.name_dictionaries, } @template_expander.use_jinja('InternalSettingsGenerated.h.tmpl', filters=filters) def generate_header(self): return self._template_context @template_expander.use_jinja('InternalSettingsGenerated.cpp.tmpl', filters=filters) def generate_implementation(self): return self._template_context @template_expander.use_jinja('InternalSettingsGenerated.idl.tmpl', filters=filters) def generate_idl(self): return self._template_context if __name__ == '__main__': in_generator.Maker(MakeInternalSettingsWriter).main(sys.argv)
'RuntimeEnabled': None, 'ImplementedAs': None, } filters = { 'symbol': media_feature_symbol.getMediaFeatureSymbolWithSuffix(''), 'to_macro_style': name_utilities.to_macro_style, } default_parameters = { 'namespace': '', 'export': '', } def __init__(self, in_file_path): super(MakeMediaFeaturesWriter, self).__init__(in_file_path) self._outputs = { ('MediaFeatures.h'): self.generate_header, } self._template_context = { 'namespace': '', 'export': '', 'entries': self.in_file.name_dictionaries, } @template_expander.use_jinja('MediaFeatures.h.tmpl', filters=filters) def generate_header(self): return self._template_context if __name__ == '__main__': in_generator.Maker(MakeMediaFeaturesWriter).main(sys.argv)
return self._template_context @template_expander.use_jinja('ElementWrapperFactory.cpp.tmpl', filters=filters) def generate_wrapper_factory_implementation(self): return self._template_context def _interface(self, tag): if tag['interfaceName']: return tag['interfaceName'] name = name_utilities.upper_first(tag['name']) # FIXME: We shouldn't hard-code HTML here. if name == 'HTML': name = 'Html' dash = name.find('-') while dash != -1: name = name[:dash] + name[dash + 1].upper() + name[dash + 2:] dash = name.find('-') return '%s%sElement' % (self.namespace, name) def _js_interface(self, tag): if tag['JSInterfaceName']: return tag['JSInterfaceName'] return self._interface(tag) def _has_js_interface(self, tag): return not tag['noConstructor'] and self._js_interface(tag) != ('%sElement' % self.namespace) if __name__ == "__main__": in_generator.Maker(MakeElementFactoryWriter).main(sys.argv)
default_parameters = { 'namespace': '', 'export': '', } def __init__(self, in_file_path): super(MakeCSSTokenizerCodePointsWriter, self).__init__(in_file_path) self._outputs = { ('CSSTokenizerCodepoints.cpp'): self.generate, } self._template_context = { 'namespace': '', 'export': '', } def generate(self): array_size = 128 # SCHAR_MAX + 1 token_lines = [ ' &CSSTokenizer::%s,' % token_type(i) if token_type(i) else ' 0,' for i in range(array_size) ] return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join(token_lines), module_pyname=module_pyname) if __name__ == '__main__': in_generator.Maker(MakeCSSTokenizerCodePointsWriter).main(sys.argv)
def _value_keywords_with_mode(self, mode): return filter(lambda property: property['mode'] == mode, self._value_keywords) def generate_implementation(self): keyword_offsets = [0] current_offset = 1 for keyword in self._value_keywords: keyword_offsets.append(current_offset) current_offset += len(keyword["name"]) + 1 gperf_input = GPERF_TEMPLATE % { 'license': license.license_for_generated_cpp(), 'class_name': self.class_name, 'value_keyword_strings': '\n'.join(map(lambda property: ' "%(name)s\\0"' % property, self._value_keywords)), 'value_keyword_offsets': '\n'.join(map(lambda offset: ' %d,' % offset, keyword_offsets)), 'value_keyword_to_enum_map': '\n'.join(map(lambda property: '%(name)s, %(enum_name)s' % property, self._value_keywords)), 'ua_sheet_mode_values_keywords': '\n '.join(map(self._case_value_keyword, self._value_keywords_with_mode('UASheet'))), 'quirks_mode_or_ua_sheet_mode_values_keywords': '\n '.join(map(self._case_value_keyword, self._value_keywords_with_mode('QuirksOrUASheet'))), } # FIXME: If we could depend on Python 2.7, we would use subprocess.check_output gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. gperf_args.append('-D') # Allow duplicate hashes -> More compact code. gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) return gperf.communicate(gperf_input)[0] if __name__ == "__main__": in_generator.Maker(CSSValueKeywordsWriter).main(sys.argv)
# We want exactly the same parsing as RuntimeFeatureWriter # but generate different files. class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): class_name = "InternalRuntimeFlags" def __init__(self, in_file_path): super(InternalRuntimeFlagsWriter, self).__init__(in_file_path) self._outputs = { (self.class_name + ".idl"): self.generate_idl, (self.class_name + ".h"): self.generate_header, } @template_expander.use_jinja(class_name + ".idl.tmpl") def generate_idl(self): return { 'features': self._features, } @template_expander.use_jinja(class_name + ".h.tmpl") def generate_header(self): return { 'features': self._features, 'feature_sets': self._feature_sets(), } if __name__ == "__main__": in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv)
self._outputs = { (self._namespace + 'ElementLookupTrie.h'): self.generate_header, (self._namespace + 'ElementLookupTrie.cpp'): self.generate_implementation, } @template_expander.use_jinja('ElementLookupTrie.h.tmpl') def generate_header(self): return { 'namespace': self._namespace, } @template_expander.use_jinja('ElementLookupTrie.cpp.tmpl') def generate_implementation(self): # First sort, so groupby works self._tags.sort(key=lambda tag: (len(tag), tag)) # Group tags by length length_tags = ((k, g) for k, g in groupby(self._tags, len)) return { 'namespace': self._namespace, 'length_tries': ((length, _trie(tags, 0)) for length, tags in length_tags), } if __name__ == '__main__': in_generator.Maker(ElementLookupTrieWriter).main(sys.argv)
'namespace': '', 'export': '', } def __init__(self, in_file_path): super(MakeMediaQueryTokenizerCodePointsWriter, self).__init__(in_file_path) self._outputs = { ('MediaQueryTokenizerCodepoints.cpp'): self.generate, } self._template_context = { 'namespace': '', 'export': '', } def generate(self): array_size = 128 # SCHAR_MAX + 1 token_lines = [ ' &MediaQueryTokenizer::%s,' % token_type(i) if token_type(i) else ' 0,' for i in range(array_size) ] return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join(token_lines), module_pyname=module_pyname) if __name__ == '__main__': in_generator.Maker(MakeMediaQueryTokenizerCodePointsWriter).main(sys.argv)
class CSSPropertyMetadataWriter(css_properties.CSSProperties): filters = { 'lower_first': lower_first, } def __init__(self, in_file_path): super(CSSPropertyMetadataWriter, self).__init__(in_file_path) self._outputs = { 'CSSPropertyMetadata.cpp': self.generate_css_property_metadata_cpp } @template_expander.use_jinja('CSSPropertyMetadata.cpp.tmpl', filters=filters) def generate_css_property_metadata_cpp(self): return { 'properties': self._properties, 'switches': [('descriptor_only', 'isDescriptorOnly'), ('interpolable', 'isInterpolableProperty'), ('inherited', 'isInheritedProperty'), ('supports_percentage', 'propertySupportsPercentage'), ('repeated', 'propertyIsRepeated')], 'first_enum_value': self._first_enum_value, } if __name__ == '__main__': in_generator.Maker(CSSPropertyMetadataWriter).main(sys.argv)
import in_generator import trie_builder import template_expander class UnitTrieWriter(in_generator.Writer): defaults = {'unit_type': None} def __init__(self, in_file_paths): super(UnitTrieWriter, self).__init__(in_file_paths) self._units = { entry['name']: entry['unit_type'] for entry in self.in_file.name_dictionaries } self._outputs = { 'CSSPrimitiveValueUnitTrie.cpp': self.generate_implementation } @template_expander.use_jinja('CSSPrimitiveValueUnitTrie.cpp.tmpl') def generate_implementation(self): return { 'length_tries': trie_builder.trie_list_by_str_length(self._units) } if __name__ == '__main__': in_generator.Maker(UnitTrieWriter).main(sys.argv)