Skip to content

Commit 1275e89

Browse files
committed
Inserted conversion and code generation of logic operators AND, OR, NOT
1 parent a08e838 commit 1275e89

3 files changed

Lines changed: 75 additions & 24 deletions

File tree

MCG/MCG_CC/mcg_cc_file_checker.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# responsible for checking of model module content from .exml file.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 7 JUN 2023
8+
# DATE: 13 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -39,12 +39,15 @@
3939
class FileChecker(object):
4040

4141
# list of actions types
42-
action_type_list = ["ADD", "SUB", "MUL", "DIV"]
42+
action_3letter_type_list = ["ADD", "SUB", "MUL", "DIV", "AND", "NOT"]
43+
44+
action_2letter_type_list = ["OR"]
4345

4446
# list of interface element types
4547
interface_element_type_list = ["INT8", "INT16", "INT32", "INT64",
4648
"UINT8", "UINT16", "UINT32", "UINT64",
47-
"FLOAT32", "FLOAT64"]
49+
"FLOAT32", "FLOAT64",
50+
"BOOL"]
4851

4952
# Description:
5053
# This is class constructor.
@@ -93,14 +96,29 @@ def check_action_type(action_type_ref):
9396
# result flag
9497
action_type_valid = False
9598

96-
# for all possible action types
97-
for action_type in FileChecker.action_type_list:
98-
# if action type is the same as in reference
99-
if action_type == action_type_ref[0:3]:
100-
# set flag
101-
action_type_valid = True
102-
# exit loop
103-
break
99+
# check 3-letter action types
100+
if len(action_type_ref) > 2:
101+
102+
# for all possible action types
103+
for action_type in FileChecker.action_3letter_type_list:
104+
# if action type is the same as in reference
105+
if action_type == action_type_ref[0:3]:
106+
# set flag
107+
action_type_valid = True
108+
# exit loop
109+
break
110+
111+
# check 2-letter action types
112+
elif len(action_type_ref) < 3:
113+
114+
# for all possible action types
115+
for action_type in FileChecker.action_2letter_type_list:
116+
# if action type is the same as in reference
117+
if action_type == action_type_ref[0:2]:
118+
# set flag
119+
action_type_valid = True
120+
# exit loop
121+
break
104122

105123
# return flag
106124
return action_type_valid

MCG/MCG_CC/mcg_cc_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# file.
88
#
99
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
10-
# DATE: 10 JUN 2023
10+
# DATE: 13 JUN 2023
1111
#
1212
# LICENSE:
1313
# This file is part of Mod Code Generator (MCG).
@@ -142,15 +142,15 @@ def convert_model():
142142
# check errors
143143
ErrorHandler.check_errors()
144144

145-
# initialize sorter
145+
# initialize module sorter
146146
module_sorter = ModuleSorter(file_reader_list)
147147
# sort module content
148148
module_sorter_list = module_sorter.sort_module()
149149

150150
# check errors
151151
ErrorHandler.check_errors()
152152

153-
# initialize converter
153+
# initialize module converter
154154
module_converter = ModuleConverter(file_finder_list, file_reader_list, module_sorter_list)
155155
# convert module content
156156
module_converter.convert_module()

MCG/MCG_CC/mcg_cc_module_converter.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# for conversion of module content into configuration file format.
66
#
77
# COPYRIGHT: Copyright (C) 2021-2023 Kamil Deć github.com/deckamil
8-
# DATE: 28 MAY 2023
8+
# DATE: 13 JUN 2023
99
#
1010
# LICENSE:
1111
# This file is part of Mod Code Generator (MCG).
@@ -240,8 +240,8 @@ def convert_operation_node(self, sorted_node):
240240
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
241241

242242
# Description:
243-
# This method converts module specific action node into configuration file.
244-
def convert_specific_action_node(self, sorted_node, math_symbol):
243+
# This method converts module specific action node with n-argument operator into configuration file.
244+
def convert_specific_action_node_arity_n(self, sorted_node, operator):
245245

246246
# get output link
247247
output_link = sorted_node.output_data_list[0]
@@ -254,40 +254,73 @@ def convert_specific_action_node(self, sorted_node, math_symbol):
254254
input_data_name = input_link[Node.DATA_NAME_INDEX]
255255
# append input data element to conversion line
256256
conversion_line = conversion_line + str(input_data_name)
257-
# append math symbol to conversion line
258-
conversion_line = conversion_line + str(" ") + str(math_symbol) + str(" ")
257+
# append operator to conversion line
258+
conversion_line = conversion_line + str(" ") + str(operator) + str(" ")
259259

260-
# remove spare math symbol and whitespace
260+
# remove spare operator and whitespace
261261
conversion_line = conversion_line[0:len(conversion_line) - 3]
262262
# append conversion line to configuration file
263263
self.configuration_file.append(conversion_line)
264264

265265
# record info
266266
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
267267

268+
# Description:
269+
# This method converts module specific action node with 1-argument operator into configuration file.
270+
def convert_specific_action_node_arity_1(self, sorted_node, operator):
271+
272+
# get input link
273+
input_link = sorted_node.input_data_list[0]
274+
# get output link
275+
output_link = sorted_node.output_data_list[0]
276+
# set beginning of action interaction to conversion line
277+
conversion_line = str("$INS ") + str(output_link[Node.DATA_NAME_INDEX]) + str(" = ") + \
278+
str(operator) + str(input_link[Node.DATA_NAME_INDEX])
279+
280+
# append conversion line to configuration file
281+
self.configuration_file.append(conversion_line)
282+
283+
# record info
284+
Logger.save_in_log_file("ModuleConverter", "Have converted to " + str(conversion_line) + " line", False)
285+
268286
# Description:
269287
# This method converts module action node into configuration file.
270288
def convert_action_node(self, sorted_node):
271289

272290
# if sorted node contains ADD action
273291
if sorted_node.name[0:3] == "ADD":
274292
# convert ADD action
275-
self.convert_specific_action_node(sorted_node, "+")
293+
self.convert_specific_action_node_arity_n(sorted_node, "+")
276294

277295
# if sorted node contains SUB action
278296
elif sorted_node.name[0:3] == "SUB":
279297
# convert SUB action
280-
self.convert_specific_action_node(sorted_node, "-")
298+
self.convert_specific_action_node_arity_n(sorted_node, "-")
281299

282300
# if sorted node contains MUL action
283301
elif sorted_node.name[0:3] == "MUL":
284302
# convert MUL action
285-
self.convert_specific_action_node(sorted_node, "*")
303+
self.convert_specific_action_node_arity_n(sorted_node, "*")
286304

287305
# if sorted node contains DIV action
288306
elif sorted_node.name[0:3] == "DIV":
289307
# convert DIV action
290-
self.convert_specific_action_node(sorted_node, "/")
308+
self.convert_specific_action_node_arity_n(sorted_node, "/")
309+
310+
# if sorted node contains AND action
311+
elif sorted_node.name[0:3] == "AND":
312+
# convert DIV action
313+
self.convert_specific_action_node_arity_n(sorted_node, "&&")
314+
315+
# if sorted node contains OR action
316+
elif sorted_node.name[0:2] == "OR":
317+
# convert DIV action
318+
self.convert_specific_action_node_arity_n(sorted_node, "||")
319+
320+
# if sorted node contains NOT action
321+
elif sorted_node.name[0:3] == "NOT":
322+
# convert DIV action
323+
self.convert_specific_action_node_arity_1(sorted_node, "!")
291324

292325
# Description:
293326
# This method converts module data node into configuration file.

0 commit comments

Comments
 (0)