Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
--- a/stage3/fill_candidate_datatypes.hh Tue May 20 08:25:59 2014 +0100
+++ b/stage3/fill_candidate_datatypes.hh Thu May 29 12:06:22 2014 +0100
@@ -242,7 +242,6 @@
/********************************************/
/* B 1.6 Sequential function chart elements */
/********************************************/
-
void *visit(transition_condition_c *symbol);
/********************************/
--- a/stage3/narrow_candidate_datatypes.cc Tue May 20 08:25:59 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.cc Thu May 29 12:06:22 2014 +0100
@@ -817,17 +817,16 @@
/********************************************/
/* B 1.6 Sequential function chart elements */
/********************************************/
-
void *narrow_candidate_datatypes_c::visit(transition_condition_c *symbol) {
- if (symbol->candidate_datatypes.size() != 1)
- return NULL;
- symbol->datatype = symbol->candidate_datatypes[0];
+ // We can safely ask for a BOOL type, as even if the result is a SAFEBOOL, in that case it will aslo include BOOL as a possible datatype.
+ set_datatype(&get_datatype_info_c::bool_type_name /* datatype*/, symbol /* symbol */);
+
if (symbol->transition_condition_il != NULL) {
- symbol->transition_condition_il->datatype = symbol->datatype;
+ set_datatype(symbol->datatype, symbol->transition_condition_il);
symbol->transition_condition_il->accept(*this);
}
if (symbol->transition_condition_st != NULL) {
- symbol->transition_condition_st->datatype = symbol->datatype;
+ set_datatype(symbol->datatype, symbol->transition_condition_st);
symbol->transition_condition_st->accept(*this);
}
return NULL;
--- a/stage3/narrow_candidate_datatypes.hh Tue May 20 08:25:59 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.hh Thu May 29 12:06:22 2014 +0100
@@ -222,7 +222,6 @@
/********************************************/
/* B 1.6 Sequential function chart elements */
/********************************************/
-
void *visit(transition_condition_c *symbol);
/********************************/
--- a/stage3/print_datatypes_error.cc Tue May 20 08:25:59 2014 +0100
+++ b/stage3/print_datatypes_error.cc Thu May 29 12:06:22 2014 +0100
@@ -689,6 +689,18 @@
}
+/********************************************/
+/* B 1.6 Sequential function chart elements */
+/********************************************/
+void *print_datatypes_error_c::visit(transition_condition_c *symbol) {
+ if (symbol->transition_condition_il != NULL) symbol->transition_condition_il->accept(*this);
+ if (symbol->transition_condition_st != NULL) symbol->transition_condition_st->accept(*this);
+
+ if (!get_datatype_info_c::is_type_valid(symbol->datatype))
+ STAGE3_ERROR(0, symbol, symbol, "Transition condition has invalid data type (should be BOOL).");
+ return NULL;
+}
+
/********************************/
/* B 1.7 Configuration elements */
@@ -1163,7 +1175,7 @@
symbol->expression->accept(*this);
if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
(symbol->expression->candidate_datatypes.size() > 0)) {
- STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'IF' condition.");
+ STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'IF' condition (should be BOOL).");
}
if (NULL != symbol->statement_list)
symbol->statement_list->accept(*this);
@@ -1178,7 +1190,7 @@
symbol->expression->accept(*this);
if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
(symbol->expression->candidate_datatypes.size() > 0)) {
- STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'ELSIF' condition.");
+ STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'ELSIF' condition (should be BOOL).");
}
if (NULL != symbol->statement_list)
symbol->statement_list->accept(*this);
--- a/stage3/print_datatypes_error.hh Tue May 20 08:25:59 2014 +0100
+++ b/stage3/print_datatypes_error.hh Thu May 29 12:06:22 2014 +0100
@@ -203,6 +203,11 @@
/**********************/
void *visit(program_declaration_c *symbol);
+ /********************************************/
+ /* B 1.6 Sequential function chart elements */
+ /********************************************/
+ void *visit(transition_condition_c *symbol);
+
/********************************/
/* B 1.7 Configuration elements */
/********************************/