44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import json
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Dict, List
|
|
|
|
|
|
@dataclass
|
|
class OperationLog:
|
|
operation: str
|
|
line: int
|
|
operand_lhs: str
|
|
operand_rhs: str
|
|
operand_result: str
|
|
is_fallthrough: bool
|
|
current_for_loops: list[int] = field(default_factory=list)
|
|
|
|
|
|
class OperationLogReader:
|
|
def __init__(self, path: str) -> None:
|
|
self._path = path
|
|
self._data: dict = {}
|
|
|
|
self.files: Dict[str, List[OperationLog]] = {}
|
|
|
|
def read(self) -> None:
|
|
with open(self._path, "r") as infile:
|
|
self._data = json.load(infile)
|
|
|
|
for name, ops_list in self._data.items():
|
|
ops: List[OperationLog] = []
|
|
|
|
for op_json in ops_list:
|
|
ops.append(OperationLog(**op_json))
|
|
|
|
self.files[name] = ops
|
|
|
|
def get_lines(self, file: str, line_number: int) -> List[OperationLog]:
|
|
res: List[OperationLog] = []
|
|
for line in self.files[file]:
|
|
if line.line == line_number:
|
|
res.append(line)
|
|
|
|
return res
|