Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
--- a/absyntax/absyntax.def Fri Feb 10 19:04:31 2012 +0000
+++ b/absyntax/absyntax.def Mon Feb 13 13:45:57 2012 +0000
@@ -938,7 +938,8 @@
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
*/
-SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
+/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
+SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration;)
/* | function_name '(' eol_list [il_param_list] ')' */
@@ -1099,14 +1100,7 @@
/* fb_name '(' [param_assignment_list] ')' */
/* formal_param_list -> may be NULL ! */
/* nonformal_param_list -> may be NULL ! */
-/* NOTES:
- * The parameter 'called_fb_declaration'...
- * ...is used to pass data between two passes of stage 3.
- * (actually set in fill_candidate_datatypes_c, and used in narrow_candidate_datatypes_c and print_datatypes_error_c).
- * This allows fill_candidate_datatypes_c to figure out whether it is a valid FB call,
- * and let the other classes handle it aproproately.
- * It could also be used in stage 4, if required.
- */
+/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list, symbol_c *called_fb_declaration;)
/* helper symbol for fb_invocation */
--- a/stage3/fill_candidate_datatypes.cc Fri Feb 10 19:04:31 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc Mon Feb 13 13:45:57 2012 +0000
@@ -841,8 +841,40 @@
return NULL;
}
+
+/* il_call_operator prev_declared_fb_name
+ * | il_call_operator prev_declared_fb_name '(' ')'
+ * | il_call_operator prev_declared_fb_name '(' eol_list ')'
+ * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
+ * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
+ */
+/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
+// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
-}
+ bool compatible = false;
+ symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
+ /* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
+ if (NULL == fb_decl) ERROR;
+
+ if (symbol-> il_param_list != NULL) {
+ symbol->il_param_list->accept(*this);
+ compatible = match_formal_call(symbol, fb_decl);
+ }
+ if (symbol->il_operand_list != NULL) {
+ symbol->il_operand_list->accept(*this);
+ compatible = match_nonformal_call(symbol, fb_decl);
+ }
+
+ /* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that
+ * we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe,
+ * as the compiler will never reach the compilation stage!
+ */
+ symbol->called_fb_declaration = fb_decl;
+
+ if (debug) std::cout << "FB [] ==> " << symbol->candidate_datatypes.size() << " result.\n";
+ return NULL;
+}
+
/* | function_name '(' eol_list [il_param_list] ')' */
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */
--- a/stage3/narrow_candidate_datatypes.cc Fri Feb 10 19:04:31 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.cc Mon Feb 13 13:45:57 2012 +0000
@@ -414,9 +414,39 @@
return NULL;
}
+/* il_call_operator prev_declared_fb_name
+ * | il_call_operator prev_declared_fb_name '(' ')'
+ * | il_call_operator prev_declared_fb_name '(' eol_list ')'
+ * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
+ * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
+ */
+/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
+// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
void *narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
- return NULL;
-}
+ /* Note: We do not use the symbol->called_fb_declaration value (set in fill_candidate_datatypes_c)
+ * because we try to identify any other datatype errors in the expressions used in the
+ * parameters to the FB call. e.g.
+ * fb_var(
+ * in1 := var1,
+ * in2 := (
+ * LD 56
+ * ADD 43
+ * )
+ * )
+ * even it the call to the FB is invalid.
+ * This makes sense because it may be errors in those expressions which are
+ * making this an invalid call, so it makes sense to point them out to the user!
+ */
+ symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
+
+ /* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
+ if (NULL == fb_decl) ERROR;
+ if (NULL != symbol->il_operand_list) narrow_nonformal_call(symbol, fb_decl);
+ if (NULL != symbol-> il_param_list) narrow_formal_call(symbol, fb_decl);
+
+ return NULL;
+}
+
/* | function_name '(' eol_list [il_param_list] ')' */
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */
--- a/stage3/print_datatypes_error.cc Fri Feb 10 19:04:31 2012 +0000
+++ b/stage3/print_datatypes_error.cc Mon Feb 13 13:45:57 2012 +0000
@@ -1140,14 +1140,7 @@
/* fb_name '(' [param_assignment_list] ')' */
/* formal_param_list -> may be NULL ! */
/* nonformal_param_list -> may be NULL ! */
-/* NOTES:
- * The parameter 'called_fb_declaration'...
- * ...is used to pass data between two passes of stage 3.
- * (actually set in fill_candidate_datatypes_c, and used in narrow_candidate_datatypes_c and print_datatypes_error_c).
- * This allows fill_candidate_datatypes_c to figure out whether it is a valid FB call,
- * and let the other classes handle it aproproately.
- * It could also be used in stage 4, if required.
- */
+/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list, symbol_c *called_fb_declaration;)
void *print_datatypes_error_c::visit(fb_invocation_c *symbol) {
symbol_c *param_value, *param_name;