Skip to content
Snippets Groups Projects
Commit 6bf6c245 authored by Jammer, Tim's avatar Jammer, Tim
Browse files

added Type hints (#7) for the Instruction Classes

parent 92f7fa9c
No related branches found
No related tags found
1 merge request!9Infrastructure: Type Hints, Instruction class and lists of instructions
...@@ -24,7 +24,7 @@ alloc_template = """ ...@@ -24,7 +24,7 @@ alloc_template = """
class AllocCall(Instruction): class AllocCall(Instruction):
@override @override
def __init__(self, type, num_elements, name="buf", use_malloc=False): def __init__(self, type: str, num_elements: int, name: str = "buf", use_malloc: bool = False):
""" """
Creates a New allocation Call Creates a New allocation Call
...@@ -55,13 +55,13 @@ class AllocCall (Instruction): ...@@ -55,13 +55,13 @@ class AllocCall (Instruction):
.replace("@{NUM}@", str(self._num_elements)) .replace("@{NUM}@", str(self._num_elements))
.replace("@{SEP}@", delim)) .replace("@{SEP}@", delim))
def set_num_elements(self, num_elements): def set_num_elements(self, num_elements: int):
self._num_elements = num_elements self._num_elements = num_elements
def set_name(self, name): def set_name(self, name: str):
self._name = name self._name = name
def set_type(self, type): def set_type(self, type: str):
self._type = type self._type = type
def set_use_malloc(self): def set_use_malloc(self):
...@@ -70,19 +70,19 @@ class AllocCall (Instruction): ...@@ -70,19 +70,19 @@ class AllocCall (Instruction):
def set_use_calloc(self): def set_use_calloc(self):
self._use_malloc = False self._use_malloc = False
def get_num_elements(self): def get_num_elements(self) -> int:
return self._num_elements return self._num_elements
def get_name(self): def get_name(self) -> str:
return self._name return self._name
def get_type(self): def get_type(self) -> str:
return self._type return self._type
def get_use_malloc(self): def get_use_malloc(self) -> bool:
return self._use_malloc return self._use_malloc
def get_free(alloc_call): def get_free(alloc_call: AllocCall) -> Instruction:
assert isinstance(alloc_call, AllocCall) assert isinstance(alloc_call, AllocCall)
return "free(" + alloc_call.get_name() + ");\n" return Instruction("free(" + alloc_call.get_name() + ");")
...@@ -10,4 +10,4 @@ class Instruction(object): ...@@ -10,4 +10,4 @@ class Instruction(object):
self._str_representation = str_representation self._str_representation = str_representation
def __str__(self): def __str__(self):
return self._str_representation return self._str_representation + "\n"
#! /usr/bin/python3 #! /usr/bin/python3
import typing
from typing_extensions import override from typing_extensions import override
from scripts.Infrastructure.Instruction import Instruction from scripts.Infrastructure.Instruction import Instruction
...@@ -8,7 +9,7 @@ from scripts.Infrastructure.Variables import ERROR_MARKER_COMMENT ...@@ -8,7 +9,7 @@ from scripts.Infrastructure.Variables import ERROR_MARKER_COMMENT
class MPI_Call(Instruction): class MPI_Call(Instruction):
@override @override
def __init__(self, function, args, version): def __init__(self, function: str, args: typing.OrderedDict[str, str], version: str):
self._function = function self._function = function
self._args = args self._args = args
self._version = version self._version = version
...@@ -27,16 +28,15 @@ class MPI_Call (Instruction): ...@@ -27,16 +28,15 @@ class MPI_Call (Instruction):
return s return s
def set_arg(self, arg, value): def set_arg(self, arg: str, value: str):
assert self.has_arg(arg) assert self.has_arg(arg)
self._args[arg] = value self._args[arg] = value
def has_arg(self, arg): def has_arg(self, arg: str) -> bool:
return arg in self._args return arg in self._args
def get_version(self): def get_version(self) -> str:
return self._version return self._version
def set_has_error(self, has_error=True): def set_has_error(self, has_error: bool = True):
self._has_error = has_error self._has_error = has_error
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment