Semantic verification of NOT operator.
authorMario de Sousa <msousa@fe.up.pt>
Fri, 09 Mar 2012 17:58:19 +0000
changeset 470 d2cd05c5e01a
parent 469 9fe6c4633ed6
child 471 da650a87662d
Semantic verification of NOT operator.
stage3/fill_candidate_datatypes.cc
stage3/narrow_candidate_datatypes.cc
stage3/print_datatypes_error.cc
stage4/generate_c/generate_c_il.cc
--- a/stage3/fill_candidate_datatypes.cc	Fri Mar 09 10:52:23 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Fri Mar 09 17:58:19 2012 +0000
@@ -1122,6 +1122,17 @@
 }
 
 void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
+	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
+	 *              NOT [<il_operand>]
+	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
+	 *       We therefore consider it an error if an il_operand is specified!
+	 */
+	if (NULL == prev_il_instruction) return NULL;
+	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
+		if (is_ANY_BIT_compatible(prev_il_instruction->candidate_datatypes[i]))
+			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
+	}
+	if (debug) std::cout <<  "NOT_operator [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
 	return NULL;
 }
 
--- a/stage3/narrow_candidate_datatypes.cc	Fri Mar 09 10:52:23 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.cc	Fri Mar 09 17:58:19 2012 +0000
@@ -825,7 +825,14 @@
 }
 
 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
-  /* TODO: ... */
+	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
+	 *              NOT [<il_operand>]
+	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
+	 *       We therefore consider it an error if an il_operand is specified!
+	 */
+	/* We do not change the data type, we simply invert the bits in bit types! */
+	/* So, we set the desired datatype of the previous il instruction */
+	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
 	return NULL;
 }
 
--- a/stage3/print_datatypes_error.cc	Fri Mar 09 10:52:23 2012 +0000
+++ b/stage3/print_datatypes_error.cc	Fri Mar 09 17:58:19 2012 +0000
@@ -862,6 +862,15 @@
 }
 
 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
+	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
+	 *              NOT [<il_operand>]
+	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
+	 *       We therefore consider it an error if an il_operand is specified!
+	 */
+	if (il_operand != NULL)
+		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
+	if (symbol->candidate_datatypes.size() == 0)
+		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
 	return NULL;
 }
 
--- a/stage4/generate_c/generate_c_il.cc	Fri Mar 09 10:52:23 2012 +0000
+++ b/stage4/generate_c/generate_c_il.cc	Fri Mar 09 17:58:19 2012 +0000
@@ -1640,6 +1640,12 @@
 }
 
 void *visit(NOT_operator_c *symbol)	{
+  /* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
+   *              NOT [<il_operand>]
+   *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
+   *       We therefore consider it an error if an il_operand is specified!
+   *       The error is caught in stage 3!
+   */  
   if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR;
   XXX_operator(&(this->default_variable_name),
                search_expression_type->is_bool_type(this->default_variable_name.current_type)?" = !":" = ~",