Support custom derives for generated types (#34356)

* script: Derive more Default implementations for dictionaries.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Support arbitrary derives on generated enums.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Support arbitrary derives for generated dictionaries.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Support arbitrary derives for generated unions.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Derive more impls for generated dicts and unions.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Implement FromStr for generated enums.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* crown: Allow returning unrooted values from Default::default.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-11-24 13:15:50 -05:00 committed by GitHub
parent 3faed9b921
commit c60e4afbee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 124 additions and 129 deletions

View file

@ -18,6 +18,9 @@ class Configuration:
glbl = {}
exec(compile(open(filename).read(), filename, 'exec'), glbl)
config = glbl['DOMInterfaces']
self.enumConfig = glbl['Enums']
self.dictConfig = glbl['Dictionaries']
self.unionConfig = glbl['Unions']
# Build descriptors for all the interfaces we have in the parse data.
# This allows callers to specify a subset of interfaces by filtering
@ -110,6 +113,9 @@ class Configuration:
def getEnums(self, webIDLFile):
return [e for e in self.enums if e.filename == webIDLFile]
def getEnumConfig(self, name):
return self.enumConfig.get(name, {})
def getTypedefs(self, webIDLFile):
return [e for e in self.typedefs if e.filename == webIDLFile]
@ -121,9 +127,15 @@ class Configuration:
return [x for x in items if x.filename == webIDLFile]
def getUnionConfig(self, name):
return self.unionConfig.get(name, {})
def getDictionaries(self, webIDLFile=""):
return self._filterForFile(self.dictionaries, webIDLFile=webIDLFile)
def getDictConfig(self, name):
return self.dictConfig.get(name, {})
def getCallbacks(self, webIDLFile=""):
return self._filterForFile(self.callbacks, webIDLFile=webIDLFile)