Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 6060568db87cd997f4b198faf8da5c8685b608dd
https://github.com/WebKit/WebKit/commit/6060568db87cd997f4b198faf8da5c8685b608dd
Author: Sam Weinig <[email protected]>
Date: 2022-11-27 (Sun, 27 Nov 2022)
Changed paths:
M Source/WebCore/css/process-css-properties.py
Log Message:
-----------
Add utilities to process-css-properties to make generation simpler
https://bugs.webkit.org/show_bug.cgi?id=248362
rdar://102682125
Reviewed by Darin Adler.
Adds a few utilities to make code generation a bit more streamlined.
- `Writer` class replaces direct use of file output and now automatically
handles newlines and indentation for callers. Includes a `context manager`,
a python object that can be used with a `with` statement to scope some
activity, call `Indent` to support easy scoped indentation.
As an example. this snippet shows off both automatic newlines and the
indentation context manager:
```
writer.write("void foo(int x)")
writer.write("{")
with writer.indent():
writer.write("use(x);")
writer.write("}")
```
and results in output of:
```
void foo(int x)
{
use(x);
}
```
- Additionally, the GenerationContext got some new utilities for creating common
constructs like includes, forward declarations and namespaces. For namespaces,
another context manager was added to allow automatic closing of the namespace
when the `with` block ends.
The new utilities and Writer class still allow for use of custom whitespace
where
it is more practical or creates more readable code, so some parts, notably parts
of StyleBuilderGenerated.cpp don't fully adopt the indentation mechanism (though
they do make use of the newline generation).
* Source/WebCore/css/process-css-properties.py:
(Writer):
(Writer.__init__):
(Writer._current_indent):
(Writer.write):
(Writer.write_block):
(Writer.write_lines):
(Writer.newline):
(Writer.Indent):
(Writer.Indent.__init__):
(Writer.Indent.__enter__):
(Writer.Indent.__exit__):
(Writer.indent):
(KeywordTerm.perform_fixups):
(MatchOneTerm.__init__):
(MatchOneTerm):
(MatchOneTerm.terms):
(MatchOneTerm.from_json):
(GenerationContext.generate_heading):
(GenerationContext):
(GenerationContext.generate_required_header_pragma):
(GenerationContext.generate_open_namespaces):
(GenerationContext.generate_close_namespaces):
(GenerationContext.generate_open_namespace):
(GenerationContext.generate_close_namespace):
(GenerationContext.Namespaces):
(GenerationContext.Namespaces.__init__):
(GenerationContext.Namespaces.__enter__):
(GenerationContext.Namespaces.__exit__):
(GenerationContext.namespace):
(GenerationContext.namespaces):
(GenerationContext.generate_using_namespace_declarations):
(GenerationContext.generate_includes):
(GenerationContext.generate_cpp_required_includes):
(GenerationContext.generate_forward_declarations):
(GenerationContext.generate_property_id_switch_function):
(GenerationContext.generate_property_id_switch_function_bool):
(GenerateCSSPropertyNames._generate_css_property_names_gperf_prelude):
(GenerateCSSPropertyNames):
(GenerateCSSPropertyNames._generate_css_property_names_gperf_heading): Deleted.
Canonical link: https://commits.webkit.org/257046@main
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes