class GetVariable(Expression): name: str var: Declaration = dataclasses.field( default=None, compare=False, ) type: Type = dataclasses.field( default=None, compare=False, )
class FunctionCall(Expression): name: str args: typing.List[Expression] decl: FunctionDeclaration = dataclasses.field( default=None, compare=False, ) type: Type = dataclasses.field( default=None, compare=False, )
class Class(Type, Markable): cst: cst_.Class = dataclasses.field(repr=False, compare=False) native: bool inheritable: bool scope: Scope name: str base: typing.Optional[Type] type_parameters: typing.Optional[typing.List[TypeParameter]] generic: bool own_fields: typing.Dict[str, Field] all_fields: typing.Dict[str, Field] own_methods: typing.Dict[str, Method] all_methods: typing.Dict[str, Method] def usable_as(self, other_cls): if not isinstance(other_cls, Class): return False while self is not None and self is not other_cls: self = self.base return self is other_cls def __eq__(self, other): return self is other def __hash__(self): return hash(self) def __str__(self): return f'(class {self.name})'
class While(Statement): cond: Expression body: Statement rstates: typing.Set[ReturnState] = dataclasses.field( default=None, compare=False, )
class Method(Markable): cst: cst_.Method = dataclasses.field(repr=False, compare=False) scope: Scope abstract: bool return_type: Type name: str parameters: typing.List[Parameter] body: typing.Optional[Expression]
class If(Statement): cond: Expression body: Statement other: typing.Optional[Statement] rstates: typing.Set[ReturnState] = dataclasses.field( default=None, compare=False, )
class Function(Markable): cst: cst_.Function = dataclasses.field(repr=False, compare=False) scope: Scope native: bool return_type: Type name: str type_parameters: typing.Optional[typing.List[TypeParameter]] generic: bool parameters: typing.List[Parameter] body: typing.Optional[Expression]
class Node: mark: typing.Optional[Mark] = dataclasses.field( compare=False, repr=False, ) @staticmethod def dict(node): args = {'mark': node.mark} for field_name in type(node).__dataclass_fields__: args[field_name] = getattr(node, field_name) return args
class _Context: fwd: list = dataclasses.field(default_factory=lambda: []) hdr: list = dataclasses.field(default_factory=lambda: []) src: list = dataclasses.field(default_factory=lambda: []) tu_set: set = dataclasses.field(default_factory=lambda: set()) depth: int = 0 emit_debug_info: bool = True def indent(self): self.src.append(self.depth * ' ') def mark_file(self, node): if self.emit_debug_info: self.src.append(f'#line {1} "{node.mark.source.path}"\n') def mark_line(self, node): if self.emit_debug_info: self.src.append(f'#line {node.mark.lineno}\n') @contextlib.contextmanager def push_indent(self): self.depth += 1 try: yield finally: self.depth -= 1 def __iadd__(self, line): self.indent() self.src.append(line) self.src.append('\n') return self def __str__(self): return ''.join(''.join(map(str, xs)) for xs in [self.fwd, self.hdr, self.src])
class TypeParameter(Type, Markable): name: str base: typing.Optional[Type] = dataclasses.field( repr=False, ) def __eq__(self, other): return self is other def __hash__(self): return id(self) def __str__(self): if self.base is None: return f'(type-param {self.name})' else: return f'(type-param {self.name}: {self.base})'
class Import(GlobalStatement): path: str tu: TranslationUnit = dataclasses.field(compare=False, repr=False)
class MatchResult: mark: Mark = dataclasses.field(compare=False, repr=False) @property def source(self): return self.mark.source
class Markable: mark: typing.Optional[base.Mark] = dataclasses.field( compare=False, repr=False, )
class Block(Statement): stmts: typing.List[Statement] rstates: typing.Set[ReturnState] = dataclasses.field( default=None, compare=False, )
class Return(Statement): expr: typing.Optional[Expression] rstates: typing.Set[ReturnState] = dataclasses.field( default=None, compare=False, )
class ExpressionStatement(Statement): expr: Expression rstates: typing.Set[ReturnState] = dataclasses.field( default=None, compare=False, )