store POU reference to POU declaration instead of global var declarations.
authorMario de Sousa <msousa@fe.up.pt>
Wed, 19 Sep 2012 11:23:15 +0100
changeset 658 fe5e1f01a49e
parent 657 cac2973b6884
child 659 165aa7b87e0d
store POU reference to POU declaration instead of global var declarations.
stage3/declaration_check.cc
stage3/declaration_check.hh
--- a/stage3/declaration_check.cc	Tue Sep 18 14:21:19 2012 +0200
+++ b/stage3/declaration_check.cc	Wed Sep 19 11:23:15 2012 +0100
@@ -1,7 +1,7 @@
 /*
  *  matiec - a compiler for the programming languages defined in IEC 61131-3
  *
- *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
+ *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
  *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -86,7 +86,7 @@
 	symbol_c *var_name;
 	search_base_type_c search_base_type;
 
-	search_var_instance_decl_c search_var_instance_glo_decl(global_var_decls);
+	search_var_instance_decl_c search_var_instance_glo_decl(current_pou_decl);
 	search_var_instance_decl_c search_var_instance_ext_decl(p_decl);
 	function_param_iterator_c fpi(p_decl);
 	while((var_name = fpi.next()) != NULL) {
@@ -101,21 +101,22 @@
          *       We need a new class (like search_base_type class) to get type id by variable declaration.
          *  symbol_c *glo_type = ????;
          *  symbol_c *ext_type = fpi.param_type();
-         *  if (! is_type_equal(glo_type, ext_type))
-         *	 STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error an external redefinition data type.");
-         */
+	 */
+	/* For the moment, we will just use search_base_type_c instead... */
+        symbol_c *glo_type = search_base_type.get_basetype_decl(glo_decl);
+        symbol_c *ext_type = search_base_type.get_basetype_decl(ext_decl);
+        if (! is_type_equal(glo_type, ext_type))
+          STAGE3_ERROR(0, ext_decl, ext_decl, "Declaration error an external redefinition data type.");
       }
 	}
 
 }
 
 /******************************************/
-/* B 1.4.3 - Declaration & Initialisation */
+/* B 1.5.3 - Declaration & Initialisation */
 /******************************************/
-void *declaration_check_c::visit(global_var_declarations_c *symbol) {
-  global_var_decls = dynamic_cast<list_c *>(symbol->global_var_decl_list);
-  if (NULL == global_var_decls)
-	  ERROR;
+void *declaration_check_c::visit(program_declaration_c *symbol) {
+  current_pou_decl = symbol;
   return NULL;
 }
 
--- a/stage3/declaration_check.hh	Tue Sep 18 14:21:19 2012 +0200
+++ b/stage3/declaration_check.hh	Wed Sep 19 11:23:15 2012 +0100
@@ -1,7 +1,7 @@
 /*
  *  matiec - a compiler for the programming languages defined in IEC 61131-3
  *
- *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
+ *  Copyright (C) 2003-2012  Mario de Sousa (msousa@fe.up.pt)
  *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -39,7 +39,7 @@
     int error_count;
     int current_display_error_level;
     search_base_type_c search_base_type;
-    list_c *global_var_decls;
+    symbol_c *current_pou_decl;
 
 public:
     declaration_check_c(symbol_c *ignore);
@@ -48,9 +48,9 @@
 
     void check_global_decl(symbol_c *p_decl);
     /******************************************/
-    /* B 1.4.3 - Declaration & Initialisation */
+    /* B 1.5.3 - Declaration & Initialisation */
     /******************************************/
-    void *visit(global_var_declarations_c *symbol);
+    void *visit(program_declaration_c *symbol);
     /********************************/
     /* B 1.7 Configuration elements */
     /********************************/