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

Refactoring: set_has_error into base class

parent 8fb97451
No related branches found
No related tags found
1 merge request!9Infrastructure: Type Hints, Instruction class and lists of instructions
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from typing_extensions import override from typing_extensions import override
from scripts.Infrastructure.Instruction import Instruction from scripts.Infrastructure.Instruction import Instruction
from scripts.Infrastructure.Variables import ERROR_MARKER_COMMENT
alloc_template = """ alloc_template = """
@{TYPE}@* @{NAME}@ = (@{TYPE}@*) @{FUNCTION}@(@{NUM}@ @{SEP}@ sizeof(@{TYPE}@)); @{TYPE}@* @{NAME}@ = (@{TYPE}@*) @{FUNCTION}@(@{NUM}@ @{SEP}@ sizeof(@{TYPE}@));
...@@ -34,6 +35,7 @@ class AllocCall(Instruction): ...@@ -34,6 +35,7 @@ class AllocCall(Instruction):
name: name of buffer variable name: name of buffer variable
use_malloc: True: use Malloc, False: use calloc for allocation use_malloc: True: use Malloc, False: use calloc for allocation
""" """
super().__init__("")
self._use_malloc = use_malloc self._use_malloc = use_malloc
self._type = type self._type = type
self._num_elements = num_elements self._num_elements = num_elements
...@@ -48,13 +50,18 @@ class AllocCall(Instruction): ...@@ -48,13 +50,18 @@ class AllocCall(Instruction):
delim = ',' delim = ','
func = "calloc" func = "calloc"
return (alloc_template s = (alloc_template
.replace("@{NAME}@", self._name) .replace("@{NAME}@", self._name)
.replace("@{TYPE}@", self._type) .replace("@{TYPE}@", self._type)
.replace("@{FUNCTION}@", func) .replace("@{FUNCTION}@", func)
.replace("@{NUM}@", str(self._num_elements)) .replace("@{NUM}@", str(self._num_elements))
.replace("@{SEP}@", delim)) .replace("@{SEP}@", delim))
if self._has_error:
s += ERROR_MARKER_COMMENT
return s
def set_num_elements(self, num_elements: int): def set_num_elements(self, num_elements: int):
self._num_elements = num_elements self._num_elements = num_elements
......
#! /usr/bin/python3 #! /usr/bin/python3
from scripts.Infrastructure.Variables import ERROR_MARKER_COMMENT
class Instruction(object): class Instruction(object):
...@@ -8,6 +9,13 @@ class Instruction(object): ...@@ -8,6 +9,13 @@ class Instruction(object):
def __init__(self, str_representation): def __init__(self, str_representation):
self._str_representation = str_representation self._str_representation = str_representation
self._has_error = False
def set_has_error(self, has_error: bool = True):
self._has_error = has_error
def __str__(self): def __str__(self):
return self._str_representation + "\n" if self._has_error:
return self._str_representation + ERROR_MARKER_COMMENT
else:
return self._str_representation
...@@ -10,6 +10,7 @@ class MPI_Call(Instruction): ...@@ -10,6 +10,7 @@ class MPI_Call(Instruction):
@override @override
def __init__(self, function: str, args: typing.OrderedDict[str, str], version: str): def __init__(self, function: str, args: typing.OrderedDict[str, str], version: str):
super().__init__("")
self._function = function self._function = function
self._args = args self._args = args
self._version = version self._version = version
...@@ -37,6 +38,3 @@ class MPI_Call(Instruction): ...@@ -37,6 +38,3 @@ class MPI_Call(Instruction):
def get_version(self) -> str: def get_version(self) -> str:
return self._version return self._version
def set_has_error(self, has_error: bool = True):
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