Skip to content

Commit

Permalink
Black formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaya-mankad committed Jan 16, 2025
1 parent b673249 commit ea3c259
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
22 changes: 13 additions & 9 deletions lattice/cpp/cpp_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
FunctionalHeaderEntry,
ObjectSerializationDeclaration,
InlineDependency,
VirtualDestructor
VirtualDestructor,
)

logger = logging.getLogger()
Expand Down Expand Up @@ -244,9 +244,7 @@ def process_data_group(self, reference_header_entry: HeaderEntry): ...
class CPPTranslator:
def __init__(self, container_class_name, header_tree):
self._preamble = list()
self._extensions = [
extension_object() for extension_object in CPPExtensionInterface.extensions
]
self._extensions = [extension_object() for extension_object in CPPExtensionInterface.extensions]
self._translate(container_class_name, header_tree)

def __str__(self):
Expand All @@ -273,7 +271,9 @@ def _get_items_to_serialize(self, header_tree: HeaderEntry):
cpp_entry: Optional[ImplementationEntry] = None
logger.debug(f"Header entry being processed: {h_entry.name} under {h_entry.parent.name}")
if isinstance(h_entry, Struct) and len([c for c in h_entry.child_entries if isinstance(c, DataElement)]):
cpp_entry = StructSerialization(h_entry, self._namespace) # Create the "from_json" function definition (header), only if it won't be empty
cpp_entry = StructSerialization(
h_entry, self._namespace
) # Create the "from_json" function definition (header), only if it won't be empty

for data_element_entry in [c for c in h_entry.child_entries if isinstance(c, DataElement)]:
# In function body, create each "get_to" for individual data elements
Expand All @@ -290,10 +290,14 @@ def _get_items_to_serialize(self, header_tree: HeaderEntry):
cpp_entry = DependencyInitialization(h_entry, self._namespace)

# Initialize and Populate overrides (Currently the only Member_function_override is the Initialize override)
elif (isinstance(h_entry, FunctionalHeaderEntry)
and not isinstance(h_entry, ObjectSerializationDeclaration)
and not isinstance(h_entry, VirtualDestructor)):
cpp_entry = MemberFunctionDefinition(h_entry, self._namespace) # Create the override function definition (header) using the declaration's signature
elif (
isinstance(h_entry, FunctionalHeaderEntry)
and not isinstance(h_entry, ObjectSerializationDeclaration)
and not isinstance(h_entry, VirtualDestructor)
):
cpp_entry = MemberFunctionDefinition(
h_entry, self._namespace
) # Create the override function definition (header) using the declaration's signature

# In function body, choose element-wise ops based on the superclass
for data_element_entry in [c for c in h_entry.parent.child_entries if isinstance(c, DataElement)]:
Expand Down
5 changes: 2 additions & 3 deletions lattice/cpp/header_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ def __lt__(self, other):
return self._less_than(self, other)

@staticmethod
def _less_than(this: HeaderEntry | FunctionalHeaderEntry,
other: HeaderEntry | FunctionalHeaderEntry):
def _less_than(this: HeaderEntry | FunctionalHeaderEntry, other: HeaderEntry | FunctionalHeaderEntry):
""" """
lt = False
t = f"{other._f_ret} {other.args}" if isinstance(other, FunctionalHeaderEntry) else f"{other.type} {other.name}"
t = f"{other._f_ret} {other.args}" if isinstance(other, FunctionalHeaderEntry) else f"{other.type} {other.name}"
# \b is a "boundary" character, or specifier for a whole word
if re.search(r"\b" + this.name + r"\b", t):
return True
Expand Down
18 changes: 11 additions & 7 deletions lattice/cpp/header_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class PluginInterface(ABC):
extensions: dict[str, list[Callable]] = {} # TODO: list should be a set
extensions: dict[str, list[Callable]] = {} # TODO: list should be a set

def __init_subclass__(cls, **kwargs):
super().__init_subclass__()
Expand Down Expand Up @@ -49,11 +49,13 @@ def modified_insertion_sort(obj_list):


class HeaderTranslator:
def __init__(self,
input_file_path: pathlib.Path,
forward_declarations_path: pathlib.Path,
output_path: pathlib.Path,
top_namespace: str):
def __init__(
self,
input_file_path: pathlib.Path,
forward_declarations_path: pathlib.Path,
output_path: pathlib.Path,
top_namespace: str,
):
self._referenced_data_types: list[ReferencedDataType] = []
self._references: dict[str, list[str]] = {}
self._fundamental_data_types: dict[str, str] = {}
Expand All @@ -66,7 +68,9 @@ def __init__(self,
self._extensions: dict[str, list[PluginInterface]] = {}

for base_class in PluginInterface.extensions:
self._extensions[base_class] = [PluginInterface.extensions[base_class][i]() for i in range(len(PluginInterface.extensions[base_class]))]
self._extensions[base_class] = [
PluginInterface.extensions[base_class][i]() for i in range(len(PluginInterface.extensions[base_class]))
]

self._translate(input_file_path, forward_declarations_path, output_path, top_namespace)

Expand Down
12 changes: 5 additions & 7 deletions lattice/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,8 @@ def setup_cpp_source_files(self):
self._cpp_output_include_dir = make_dir(include_dir / f"{self.root_directory.name}")
self._cpp_output_src_dir = make_dir(self.cpp_output_dir / "src")
for schema in self.cpp_schemas:
schema.cpp_header_file_path = (
self._cpp_output_include_dir / f"{schema.name}.h"
)
schema.cpp_source_file_path = (
self._cpp_output_src_dir / f"{schema.name}.cpp"
)
schema.cpp_header_file_path = self._cpp_output_include_dir / f"{schema.name}.h"
schema.cpp_source_file_path = self._cpp_output_src_dir / f"{schema.name}.cpp"

def setup_cpp_repository(self, submodules: list[str]):
"""Initialize the CPP output directory as a Git repo."""
Expand All @@ -263,7 +259,9 @@ def cpp_support_headers(self) -> list[Path]:
def generate_cpp_project(self, submodules: list[str]):
"""Generate CPP header files, source files, and build support files."""
for schema in self.cpp_schemas:
h = HeaderTranslator(schema.file_path, self.schema_directory_path, self._cpp_output_include_dir, self.root_directory.name)
h = HeaderTranslator(
schema.file_path, self.schema_directory_path, self._cpp_output_include_dir, self.root_directory.name
)
dump(str(h), schema.cpp_header_file_path)
c = CPPTranslator(self.root_directory.name, h)
dump(str(c), schema.cpp_source_file_path)
Expand Down

0 comments on commit ea3c259

Please sign in to comment.