refactor: address review comments

Not sure why VS Code suddenly decides to remove some empty spaces, but they don't make sense anyway
This commit is contained in:
jonschz 2024-06-08 10:26:23 +02:00
parent 24275b460b
commit 59ed0b1aa9
4 changed files with 29 additions and 26 deletions

View File

@ -189,7 +189,7 @@ In order to keep the code clean and consistent, we use `pylint` and `black`:
### Run pylint (ignores build and virtualenv) ### Run pylint (ignores build and virtualenv)
`pylint tools/` `pylint tools/ --ignore=ncc`
### Check code formatting without rewriting files ### Check code formatting without rewriting files

View File

@ -119,7 +119,7 @@ def get_func_signature(self, fn: SymbolsEntry) -> Optional[FunctionSignature]:
def get_function_list(self) -> list[tuple[MatchInfo, FunctionSignature]]: def get_function_list(self) -> list[tuple[MatchInfo, FunctionSignature]]:
handled = ( handled = (
self.handle_matched_function(match) self.handle_matched_function(match)
for match in self.compare.db.get_matches_by_type(SymbolType.FUNCTION) for match in self.compare.get_functions()
) )
return [signature for signature in handled if signature is not None] return [signature for signature in handled if signature is not None]

View File

@ -214,11 +214,9 @@ class CvdumpTypesParser:
LF_ENUM_ATTRIBUTES = [ LF_ENUM_ATTRIBUTES = [
re.compile(r"^\s*# members = (?P<num_members>\d+)$"), re.compile(r"^\s*# members = (?P<num_members>\d+)$"),
re.compile(
r"^\s*type = (?P<underlying_type>\S+) field list type (?P<field_type>0x\w{4})$"
),
re.compile(r"^\s*enum name = (?P<name>.+)$"), re.compile(r"^\s*enum name = (?P<name>.+)$"),
] ]
LF_ENUM_TYPES = re.compile(r"^\s*type = (?P<underlying_type>\S+) field list type (?P<field_type>0x\w{4})$")
LF_ENUM_UDT = re.compile(r"^\s*UDT\((?P<udt>0x\w+)\)$") LF_ENUM_UDT = re.compile(r"^\s*UDT\((?P<udt>0x\w+)\)$")
LF_UNION_LINE = re.compile( LF_UNION_LINE = re.compile(
r".*field list type (?P<field_type>0x\w+),.*Size = (?P<size>\d+)\s*,class name = (?P<name>(?:[^,]|,\S)+),\s.*UDT\((?P<udt>0x\w+)\)" r".*field list type (?P<field_type>0x\w+),.*Size = (?P<size>\d+)\s*,class name = (?P<name>(?:[^,]|,\S)+),\s.*UDT\((?P<udt>0x\w+)\)"
@ -628,6 +626,7 @@ def read_enum_line(self, line: str):
continue continue
obj |= self.parse_enum_attribute(pair) obj |= self.parse_enum_attribute(pair)
def parse_enum_attribute(self, attribute: str) -> dict[str, Any]: def parse_enum_attribute(self, attribute: str) -> dict[str, Any]:
for attribute_regex in self.LF_ENUM_ATTRIBUTES: for attribute_regex in self.LF_ENUM_ATTRIBUTES:
if (match := attribute_regex.match(attribute)) is not None: if (match := attribute_regex.match(attribute)) is not None:
@ -640,6 +639,10 @@ def parse_enum_attribute(self, attribute: str) -> dict[str, Any]:
match = self.LF_ENUM_UDT.match(attribute) match = self.LF_ENUM_UDT.match(attribute)
assert match is not None assert match is not None
return {"udt": normalize_type_id(match.group("udt"))} return {"udt": normalize_type_id(match.group("udt"))}
if (match := self.LF_ENUM_TYPES.match(attribute)) is not None:
result = match.groupdict()
result["underlying_type"] = normalize_type_id(result["underlying_type"])
return result
logger.error("Unknown attribute in enum: %s", attribute) logger.error("Unknown attribute in enum: %s", attribute)
return {} return {}

View File

@ -374,7 +374,7 @@ def test_2d_array(parser):
def test_enum(parser): def test_enum(parser):
"""LF_ENUM should equal 4-byte int""" """LF_ENUM should equal 4-byte int"""
assert parser.get("0x3cc2").size == 4 assert parser.get("0x3cc2").size == 4
assert parser.get_scalars("0x3cc2") == [(0, None, "T_INT4(0074)")] assert parser.get_scalars("0x3cc2") == [(0, None, "T_INT4")]
# Now look at an array of enum, 24 bytes # Now look at an array of enum, 24 bytes
enum_array = parser.get_scalars("0x4262") enum_array = parser.get_scalars("0x4262")