commiting merge with Laurent's repository
authorMario de Sousa <msousa@fe.up.pt>
Mon, 11 Jul 2011 09:47:27 +0100
changeset 341 ba80c3ceb6fb
parent 340 27a56785e9cd (diff)
parent 336 229eb3e29216 (current diff)
child 342 8fb0fbfcc71b
child 350 2c3c4dc34979
commiting merge with Laurent's repository
--- a/absyntax_utils/absyntax_utils.cc	Fri Jul 08 11:06:27 2011 +0200
+++ b/absyntax_utils/absyntax_utils.cc	Mon Jul 11 09:47:27 2011 +0100
@@ -117,15 +117,26 @@
 /* A symbol table with all user declared type definitions... */
 /* Note that function block types and program types have their
  * own symbol tables, so do not get placed in this symbol table!
+ *
+ * The symbol_c * associated to the value will point to the data type declaration.
  */
 symbol_c null_symbol4;
 symtable_c<symbol_c *, &null_symbol4> type_symtable;
 
 /* A symbol table with all values declared for enumerated type... */
-/* Note that if the value is defined multiple times the value
+/* Notes:
+ * - if the value is defined multiple times the value
  * is the null pointer.
- */
-symtable_c<symbol_c *, &null_symbol4> enumerated_value_symtable;
+ *
+ * - The stored symbol_c * associated to the value points to the enumerated_type_name
+ * (i.e. the name of the enumerated data type) in which the the value/identifier
+ * is used/declared.
+ *
+ * - We could re-use the null_symbol4 object, but it is safer to use a distinct object
+ *   (i.e. it might make it easier to find strange bugs).
+ */
+symbol_c null_symbol5;
+symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
 
 
 /***********************************************************************/
@@ -214,11 +225,25 @@
       if (symbol->type != NULL) ERROR;
 
       symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value);
-      if (value_type == current_enumerated_type) ERROR;
+      /* NOTE: The following condition checks whether the same identifier is used more than once
+       *       when defining the enumerated values of the type declaration of the new enumerated type.
+       *       If this occurs, then the program beeing compiled contains a semantic error, which
+       *       must be caught and reported by the semantic analyser. However, since
+       *       this code is run before the semantic analyser, we must not yet raise the ERROR (internal
+       *       compiler error message).
+       *       For this reason, the follosing check is commented out.
+       */
+      /* if (value_type == current_enumerated_type) ERROR; */
 
       if (value_type == enumerated_value_symtable.end_value())
+	/* This identifier has not yet been used in any previous declaration of an enumeration data type.
+	 * so we add it to the symbol table.
+	 */
         enumerated_value_symtable.insert(symbol->value, current_enumerated_type);
       else if (value_type != NULL)
+	/* This identifier has already been used in a previous declaration of an enumeration data type.
+	 * so we set the symbol in symbol table pointing to NULL.
+	 */
         enumerated_value_symtable.set(symbol->value, NULL);
     }
     return NULL;
--- a/absyntax_utils/absyntax_utils.hh	Fri Jul 08 11:06:27 2011 +0200
+++ b/absyntax_utils/absyntax_utils.hh	Mon Jul 11 09:47:27 2011 +0100
@@ -70,15 +70,26 @@
 /* A symbol table with all user declared type definitions... */
 /* Note that function block types and program types have their
  * own symbol tables, so do not get placed in this symbol table!
+ *
+ * The symbol_c * associated to the value will point to the data type declaration.
  */
 extern symbol_c null_symbol4;
 extern symtable_c<symbol_c *, &null_symbol4> type_symtable;
 
 /* A symbol table with all values declared for enumerated type... */
-/* Note that if the value is defined multiple times the value
+/* Notes:
+ * - if the value is defined multiple times the value
  * is the null pointer.
+ *
+ * - The stored symbol_c * associated to the value points to the enumerated_type_name
+ * (i.e. the name of the enumerated data type) in which the the value/identifier
+ * is used/declared.
+ *
+ * - We could re-use the null_symbol4 object, but it is safer to use a distinct object
+ *   (i.e. it might make it easier to find strange bugs).
  */
-extern symtable_c<symbol_c *, &null_symbol4> enumerated_value_symtable;
+extern symbol_c null_symbol5;
+extern symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
 
 
 /***********************************************************************/
--- a/absyntax_utils/search_constant_type.cc	Fri Jul 08 11:06:27 2011 +0200
+++ b/absyntax_utils/search_constant_type.cc	Mon Jul 11 09:47:27 2011 +0100
@@ -43,13 +43,8 @@
 
 #include "../util/symtable.hh"
 #include "search_constant_type.hh"
+#include "absyntax_utils.hh"
 
-/* A symbol table with all values declared for enumerated type... */
-/* Note that if the value is defined multiple times the value
- * is the null pointer.
- */
-extern symbol_c null_symbol4;
-extern symtable_c<symbol_c *, &null_symbol4> enumerated_value_symtable;
 
 #define ERROR error_exit(__FILE__,__LINE__)
 /* function defined in main.cc */
--- a/absyntax_utils/search_constant_type.hh	Fri Jul 08 11:06:27 2011 +0200
+++ b/absyntax_utils/search_constant_type.hh	Mon Jul 11 09:47:27 2011 +0100
@@ -43,6 +43,8 @@
 
 #include "../absyntax/visitor.hh"
 
+#ifndef _SEARCH_CONSTANT_TYPE_HH
+#define _SEARCH_CONSTANT_TYPE_HH
 
 class search_constant_type_c: public search_visitor_c {
 
@@ -162,3 +164,4 @@
 
 
 
+#endif /* ifndef _SEARCH_CONSTANT_TYPE_HH */
--- a/lib/ieclib.txt	Fri Jul 08 11:06:27 2011 +0200
+++ b/lib/ieclib.txt	Mon Jul 11 09:47:27 2011 +0100
@@ -24,6 +24,11 @@
 (* This is the library conatining the standard function blocks defined in the standard. *)
 
 (* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) *)
+
+(* The standard functions *)
+{#include "standard_functions.txt" }
+
+(* The standard function blocks *)
 {#include "edge_detection.txt" }
 {#include "bistable.txt" }
 {#include "counter.txt" }
@@ -34,6 +39,6 @@
 {#include "pid_st.txt" }
 {#include "ramp_st.txt" }
 
-(* Frome later versions of the standard *)
+(* From later versions of the standard *)
 {#include "sema.txt" }