mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Swift: slightly simplify a cppgen change
This commit is contained in:
@@ -13,7 +13,6 @@ Each class in the schema gets a corresponding `struct` in `TrapClasses.h`, where
|
||||
|
||||
import functools
|
||||
import pathlib
|
||||
import typing
|
||||
from typing import Dict
|
||||
|
||||
import inflection
|
||||
@@ -35,25 +34,22 @@ def _get_type(t: str) -> str:
|
||||
return t
|
||||
|
||||
|
||||
def _get_fields(cls: schema.Class) -> typing.Iterable[cpp.Field]:
|
||||
for p in cls.properties:
|
||||
if "cpp_skip" in p.pragmas:
|
||||
continue
|
||||
trap_name = None
|
||||
if not p.is_single:
|
||||
trap_name = inflection.camelize(f"{cls.name}_{p.name}")
|
||||
if not p.is_predicate:
|
||||
trap_name = inflection.pluralize(trap_name)
|
||||
args = dict(
|
||||
field_name=p.name + ("_" if p.name in cpp.cpp_keywords else ""),
|
||||
type=_get_type(p.type),
|
||||
is_optional=p.is_optional,
|
||||
is_repeated=p.is_repeated,
|
||||
is_predicate=p.is_predicate,
|
||||
trap_name=trap_name,
|
||||
)
|
||||
args.update(cpp.get_field_override(p.name))
|
||||
yield cpp.Field(**args)
|
||||
def _get_field(cls: schema.Class, p: schema.Property) -> cpp.Field:
|
||||
trap_name = None
|
||||
if not p.is_single:
|
||||
trap_name = inflection.camelize(f"{cls.name}_{p.name}")
|
||||
if not p.is_predicate:
|
||||
trap_name = inflection.pluralize(trap_name)
|
||||
args = dict(
|
||||
field_name=p.name + ("_" if p.name in cpp.cpp_keywords else ""),
|
||||
type=_get_type(p.type),
|
||||
is_optional=p.is_optional,
|
||||
is_repeated=p.is_repeated,
|
||||
is_predicate=p.is_predicate,
|
||||
trap_name=trap_name,
|
||||
)
|
||||
args.update(cpp.get_field_override(p.name))
|
||||
return cpp.Field(**args)
|
||||
|
||||
|
||||
class Processor:
|
||||
@@ -69,7 +65,7 @@ class Processor:
|
||||
return cpp.Class(
|
||||
name=name,
|
||||
bases=[self._get_class(b) for b in cls.bases],
|
||||
fields=list(_get_fields(cls)),
|
||||
fields=[_get_field(cls, p) for p in cls.properties if "cpp_skip" not in p.pragmas],
|
||||
final=not cls.derived,
|
||||
trap_name=trap_name,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user