[webkit-changes] [WebKit/WebKit] 33e16a: Data driven CSS property parsing

Sam Weinig noreply at github.com
Fri Nov 18 19:00:14 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 33e16a60b9c5713b5df84d9b59f212e36bb1e3ce
      https://github.com/WebKit/WebKit/commit/33e16a60b9c5713b5df84d9b59f212e36bb1e3ce
  Author: Sam Weinig <weinig at apple.com>
  Date:   2022-11-18 (Fri, 18 Nov 2022)

  Changed paths:
    M Source/WebCore/CMakeLists.txt
    M Source/WebCore/DerivedSources-output.xcfilelist
    M Source/WebCore/DerivedSources.make
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    A Source/WebCore/css/CSSFontVariantLigaturesParser.h
    A Source/WebCore/css/CSSFontVariantNumericParser.h
    M Source/WebCore/css/CSSProperties.json
    M Source/WebCore/css/CSSTimingFunctionValue.cpp
    M Source/WebCore/css/ComputedStyleExtractor.cpp
    M Source/WebCore/css/parser/CSSAtRuleID.h
    M Source/WebCore/css/parser/CSSParserFastPaths.cpp
    M Source/WebCore/css/parser/CSSParserFastPaths.h
    M Source/WebCore/css/parser/CSSParserIdioms.cpp
    M Source/WebCore/css/parser/CSSParserImpl.cpp
    M Source/WebCore/css/parser/CSSPropertyParser.cpp
    M Source/WebCore/css/parser/CSSPropertyParser.h
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.h
    M Source/WebCore/css/process-css-properties.py
    M Source/WebCore/css/typedom/StylePropertyMap.cpp
    M Tools/Scripts/webkitpy/style/checkers/jsonchecker.py

  Log Message:
  -----------
  Data driven CSS property parsing
https://bugs.webkit.org/show_bug.cgi?id=248036
rdar://102467693

Reviewed by Darin Adler.

Introduce the initial infrastructure for data/grammar driven
parsing of CSS properties, starting with parsing of keyword
only property values.

The long term goal is to add enough information in CSSProperties.json
to generate the property parsers and ASTs, but this initial
change just puts in place enough to generate the boilerplate
for CSSPropertyParser::parseSingleValue() (e.g. we now generate
the big switch statement) with most of the parsing still being
done by hand written "consume" functions. To make inclusion
easier and simplify where to look for the consume functions,
the existing consume functions in CSSPropertyParser.cpp were
moved to CSSPropertyParserHelpers, where most of the other
consume functions already lived.

In addition to generating the core switch statement, this change
also generates the consume functions for properties that support
taking a single keyword CSSValue as their input. This utilized
the existing "values" arrays CSSProperties.json, updated as needed
to match the current status in WebCore. The same data is also
used to generate implementations for the CSSParserFastPaths'
`isValidKeywordPropertyAndValue` and `isKeywordPropertyID`. In
the future, more properties that allow single keywords can be
automatically added based on their grammar, with no additional
work needed by the person adding them.

To aid the transition to generated parsing, a number of new
attributes were added to the "codegen-properties" dictionaries
in CSSProperties.json for specifying custom consume functions
and optionally passing additional arguments.

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
Added new files.

* Source/WebCore/css/CSSFontVariantLigaturesParser.h: Added.
* Source/WebCore/css/CSSFontVariantNumericParser.h: Added.
Moved here from CSSPropertyParser.cpp so it can be used in multiple files.

* Source/WebCore/css/CSSProperties.json:
Update properties to indicate where a custom parser is needed and if any
additional parameterization of that custom parser is required. Also updates
the "values" arrays where they were out of sync with the engine as they are
now used if no custom parser is requested.

* Source/WebCore/css/CSSTimingFunctionValue.cpp:
Add a missing newline.

* Source/WebCore/css/ComputedStyleExtractor.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
(WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
Use the new reference overload of isExposed to avoid a null check.

* Source/WebCore/css/parser/CSSAtRuleID.h:
Add a missing newline.

* Source/WebCore/css/parser/CSSParserFastPaths.h:
* Source/WebCore/css/parser/CSSParserFastPaths.cpp:
(WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):
(WebCore::CSSParserFastPaths::isKeywordPropertyID):
Replace implementations with calls to generated versions.

(WebCore::CSSParserFastPaths::isPartialKeywordPropertyID): Deleted.
No longer needed, as the one caller now can handle this in
generated code.

* Source/WebCore/css/parser/CSSParserIdioms.cpp:
Add a missing newline.

* Source/WebCore/css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::CSSParserImpl):
Remove an extraneous newline and fix an includes's style.

* Source/WebCore/css/parser/CSSPropertyParser.cpp:
* Source/WebCore/css/parser/CSSPropertyParser.h:
Move lots of things out. Generate parseSingleValue.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
Move all the loose consume functions in from CSSPropertyParser.cpp
so they can used in multiple files (including the new generated ones).

* Source/WebCore/css/process-css-properties.py:
Generates new files CSSPropertyParsing.h/cpp which contain the base
switch for parsing single longhand values as well as the keyword only
checking and consumer functions.

* Source/WebCore/css/typedom/StylePropertyMap.cpp:
(WebCore::StylePropertyMap::set):
(WebCore::StylePropertyMap::remove):
Use the new reference overload of isExposed to avoid a null check.

Canonical link: https://commits.webkit.org/256867@main




More information about the webkit-changes mailing list