--- a/absyntax_utils/get_datatype_info.cc Thu Dec 27 15:04:58 2012 +0000
+++ b/absyntax_utils/get_datatype_info.cc Thu Dec 27 15:31:01 2012 +0000
@@ -103,6 +103,113 @@
+/***********************************************************************/
+/***********************************************************************/
+
+
+/* A small helper class, to transform elementary data type to string.
+ * this allows us to generate more relevant error messages...
+ */
+
+class get_datatype_id_str_c: public null_visitor_c {
+ protected:
+ get_datatype_id_str_c(void) {};
+ ~get_datatype_id_str_c(void) {};
+
+ private:
+ /* singleton class! */
+ static get_datatype_id_str_c *singleton;
+
+ public:
+ static const char *get_id_str(symbol_c *symbol) {
+ if (NULL == singleton) singleton = new get_datatype_id_str_c;
+ if (NULL == singleton) ERROR;
+ const char *res = (const char *)symbol->accept(*singleton);
+ if (NULL == res) ERROR;
+ return res;
+ }
+
+
+ /*************************/
+ /* B.1 - Common elements */
+ /*************************/
+ /*******************************************/
+ /* B 1.1 - Letters, digits and identifiers */
+ /*******************************************/
+ void *visit(identifier_c *symbol) {return (void *)symbol->value;};
+
+ /***********************************/
+ /* B 1.3.1 - Elementary Data Types */
+ /***********************************/
+ void *visit(time_type_name_c *symbol) {return (void *)"TIME"; };
+ void *visit(bool_type_name_c *symbol) {return (void *)"BOOL"; };
+ void *visit(sint_type_name_c *symbol) {return (void *)"SINT"; };
+ void *visit(int_type_name_c *symbol) {return (void *)"INT"; };
+ void *visit(dint_type_name_c *symbol) {return (void *)"DINT"; };
+ void *visit(lint_type_name_c *symbol) {return (void *)"LINT"; };
+ void *visit(usint_type_name_c *symbol) {return (void *)"USINT"; };
+ void *visit(uint_type_name_c *symbol) {return (void *)"UINT"; };
+ void *visit(udint_type_name_c *symbol) {return (void *)"UDINT"; };
+ void *visit(ulint_type_name_c *symbol) {return (void *)"ULINT"; };
+ void *visit(real_type_name_c *symbol) {return (void *)"REAL"; };
+ void *visit(lreal_type_name_c *symbol) {return (void *)"LREAL"; };
+ void *visit(date_type_name_c *symbol) {return (void *)"DATE"; };
+ void *visit(tod_type_name_c *symbol) {return (void *)"TOD"; };
+ void *visit(dt_type_name_c *symbol) {return (void *)"DT"; };
+ void *visit(byte_type_name_c *symbol) {return (void *)"BYTE"; };
+ void *visit(word_type_name_c *symbol) {return (void *)"WORD"; };
+ void *visit(lword_type_name_c *symbol) {return (void *)"LWORD"; };
+ void *visit(dword_type_name_c *symbol) {return (void *)"DWORD"; };
+ void *visit(string_type_name_c *symbol) {return (void *)"STRING"; };
+ void *visit(wstring_type_name_c *symbol) {return (void *)"WSTRING"; };
+
+ void *visit(safetime_type_name_c *symbol) {return (void *)"SAFETIME"; };
+ void *visit(safebool_type_name_c *symbol) {return (void *)"SAFEBOOL"; };
+ void *visit(safesint_type_name_c *symbol) {return (void *)"SAFESINT"; };
+ void *visit(safeint_type_name_c *symbol) {return (void *)"SAFEINT"; };
+ void *visit(safedint_type_name_c *symbol) {return (void *)"SAFEDINT"; };
+ void *visit(safelint_type_name_c *symbol) {return (void *)"SAFELINT"; };
+ void *visit(safeusint_type_name_c *symbol) {return (void *)"SAFEUSINT"; };
+ void *visit(safeuint_type_name_c *symbol) {return (void *)"SAFEUINT"; };
+ void *visit(safeudint_type_name_c *symbol) {return (void *)"SAFEUDINT"; };
+ void *visit(safeulint_type_name_c *symbol) {return (void *)"SAFEULINT"; };
+ void *visit(safereal_type_name_c *symbol) {return (void *)"SAFEREAL"; };
+ void *visit(safelreal_type_name_c *symbol) {return (void *)"SAFELREAL"; };
+ void *visit(safedate_type_name_c *symbol) {return (void *)"SAFEDATE"; };
+ void *visit(safetod_type_name_c *symbol) {return (void *)"SAFETOD"; };
+ void *visit(safedt_type_name_c *symbol) {return (void *)"SAFEDT"; };
+ void *visit(safebyte_type_name_c *symbol) {return (void *)"SAFEBYTE"; };
+ void *visit(safeword_type_name_c *symbol) {return (void *)"SAFEWORD"; };
+ void *visit(safelword_type_name_c *symbol) {return (void *)"SAFELWORD"; };
+ void *visit(safedword_type_name_c *symbol) {return (void *)"SAFEDWORD"; };
+ void *visit(safestring_type_name_c *symbol) {return (void *)"SAFESTRING"; };
+ void *visit(safewstring_type_name_c *symbol) {return (void *)"SAFEWSTRING"; };
+
+ /********************************/
+ /* B 1.3.3 - Derived data types */
+ /********************************/
+ /* simple_type_name ':' simple_spec_init */
+ void *visit(simple_type_declaration_c *symbol) {return symbol->simple_type_name->accept(*this);}
+ /* subrange_type_name ':' subrange_spec_init */
+ void *visit(subrange_type_declaration_c *symbol) {return symbol->subrange_type_name->accept(*this);}
+ /* enumerated_type_name ':' enumerated_spec_init */
+ void *visit(enumerated_type_declaration_c *symbol) {return symbol->enumerated_type_name->accept(*this);}
+ /* identifier ':' array_spec_init */
+ void *visit(array_type_declaration_c *symbol) {return symbol->identifier->accept(*this);}
+ /* structure_type_name ':' structure_specification */
+ void *visit(structure_type_declaration_c *symbol) {return symbol->structure_type_name->accept(*this);}
+ /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
+ void *visit(string_type_declaration_c *symbol) {return symbol->string_type_name->accept(*this);}
+
+ /*****************************/
+ /* B 1.5.2 - Function Blocks */
+ /*****************************/
+ /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
+ void *visit(function_block_declaration_c *symbol) {return symbol->fblock_name->accept(*this);}
+};
+
+get_datatype_id_str_c *get_datatype_id_str_c::singleton = NULL;
+
/**********************************************************/
@@ -117,9 +224,12 @@
/**********************************************************/
/**********************************************************/
-
-
-symbol_c *get_datatype_info_c::get_datatype_id(symbol_c *datatype) {
+const char *get_datatype_info_c::get_id_str(symbol_c *datatype) {
+ return get_datatype_id_str_c::get_id_str(datatype);
+}
+
+
+symbol_c *get_datatype_info_c::get_id(symbol_c *datatype) {
return get_datatype_id_c::get_id(datatype);
}
--- a/absyntax_utils/get_datatype_info.hh Thu Dec 27 15:04:58 2012 +0000
+++ b/absyntax_utils/get_datatype_info.hh Thu Dec 27 15:31:01 2012 +0000
@@ -57,7 +57,8 @@
public:
- static symbol_c *get_datatype_id(symbol_c *datatype); /* get the identifier (name) of the datatype); returns NULL if anonymous datatype! */
+ static symbol_c *get_id (symbol_c *datatype); /* get the identifier (name) of the datatype); returns NULL if anonymous datatype! Does not work for elementary datatypes!*/
+ static const char *get_id_str(symbol_c *datatype); /* get the identifier (name) of the datatype); returns NULL if anonymous datatype! */
static bool is_type_equal(symbol_c *first_type, symbol_c *second_type);
static bool is_type_valid(symbol_c *type);
--- a/stage3/datatype_functions.cc Thu Dec 27 15:04:58 2012 +0000
+++ b/stage3/datatype_functions.cc Thu Dec 27 15:31:01 2012 +0000
@@ -31,19 +31,6 @@
-elementary_type_c *elementary_type_c::singleton = NULL;
-
-const char *elementary_type_c::to_string(symbol_c *symbol) {
- if (NULL == singleton) singleton = new elementary_type_c;
- if (NULL == singleton) ERROR;
- const char *res = (const char *)symbol->accept(*singleton);
- if (NULL == res) ERROR;
- return res;
-}
-
-
-
-
/* Macro that expand to subtypes */
/* copied from matiec/lib/create_standard_functions_txt.sh */
--- a/stage3/datatype_functions.hh Thu Dec 27 15:04:58 2012 +0000
+++ b/stage3/datatype_functions.hh Thu Dec 27 15:31:01 2012 +0000
@@ -47,71 +47,6 @@
-/* A small helper class, to transform elementary data type to string.
- * this allows us to generate more relevant error messages...
- */
-
-class elementary_type_c: public null_visitor_c {
- protected:
- elementary_type_c(void) {};
- ~elementary_type_c(void) {};
-
- private:
- /* singleton class! */
- static elementary_type_c *singleton;
-
- public:
- static const char * to_string(symbol_c *symbol);
-
-
- /***********************************/
- /* B 1.3.1 - Elementary Data Types */
- /***********************************/
- void *visit(time_type_name_c *symbol) {return (void *)"TIME"; };
- void *visit(bool_type_name_c *symbol) {return (void *)"BOOL"; };
- void *visit(sint_type_name_c *symbol) {return (void *)"SINT"; };
- void *visit(int_type_name_c *symbol) {return (void *)"INT"; };
- void *visit(dint_type_name_c *symbol) {return (void *)"DINT"; };
- void *visit(lint_type_name_c *symbol) {return (void *)"LINT"; };
- void *visit(usint_type_name_c *symbol) {return (void *)"USINT"; };
- void *visit(uint_type_name_c *symbol) {return (void *)"UINT"; };
- void *visit(udint_type_name_c *symbol) {return (void *)"UDINT"; };
- void *visit(ulint_type_name_c *symbol) {return (void *)"ULINT"; };
- void *visit(real_type_name_c *symbol) {return (void *)"REAL"; };
- void *visit(lreal_type_name_c *symbol) {return (void *)"LREAL"; };
- void *visit(date_type_name_c *symbol) {return (void *)"DATE"; };
- void *visit(tod_type_name_c *symbol) {return (void *)"TOD"; };
- void *visit(dt_type_name_c *symbol) {return (void *)"DT"; };
- void *visit(byte_type_name_c *symbol) {return (void *)"BYTE"; };
- void *visit(word_type_name_c *symbol) {return (void *)"WORD"; };
- void *visit(lword_type_name_c *symbol) {return (void *)"LWORD"; };
- void *visit(dword_type_name_c *symbol) {return (void *)"DWORD"; };
- void *visit(string_type_name_c *symbol) {return (void *)"STRING"; };
- void *visit(wstring_type_name_c *symbol) {return (void *)"WSTRING"; };
-
- void *visit(safetime_type_name_c *symbol) {return (void *)"SAFETIME"; };
- void *visit(safebool_type_name_c *symbol) {return (void *)"SAFEBOOL"; };
- void *visit(safesint_type_name_c *symbol) {return (void *)"SAFESINT"; };
- void *visit(safeint_type_name_c *symbol) {return (void *)"SAFEINT"; };
- void *visit(safedint_type_name_c *symbol) {return (void *)"SAFEDINT"; };
- void *visit(safelint_type_name_c *symbol) {return (void *)"SAFELINT"; };
- void *visit(safeusint_type_name_c *symbol) {return (void *)"SAFEUSINT"; };
- void *visit(safeuint_type_name_c *symbol) {return (void *)"SAFEUINT"; };
- void *visit(safeudint_type_name_c *symbol) {return (void *)"SAFEUDINT"; };
- void *visit(safeulint_type_name_c *symbol) {return (void *)"SAFEULINT"; };
- void *visit(safereal_type_name_c *symbol) {return (void *)"SAFEREAL"; };
- void *visit(safelreal_type_name_c *symbol) {return (void *)"SAFELREAL"; };
- void *visit(safedate_type_name_c *symbol) {return (void *)"SAFEDATE"; };
- void *visit(safetod_type_name_c *symbol) {return (void *)"SAFETOD"; };
- void *visit(safedt_type_name_c *symbol) {return (void *)"SAFEDT"; };
- void *visit(safebyte_type_name_c *symbol) {return (void *)"SAFEBYTE"; };
- void *visit(safeword_type_name_c *symbol) {return (void *)"SAFEWORD"; };
- void *visit(safelword_type_name_c *symbol) {return (void *)"SAFELWORD"; };
- void *visit(safedword_type_name_c *symbol) {return (void *)"SAFEDWORD"; };
- void *visit(safestring_type_name_c *symbol) {return (void *)"SAFESTRING"; };
- void *visit(safewstring_type_name_c *symbol) {return (void *)"SAFEWSTRING"; };
-};
-
--- a/stage3/print_datatypes_error.cc Thu Dec 27 15:04:58 2012 +0000
+++ b/stage3/print_datatypes_error.cc Thu Dec 27 15:31:01 2012 +0000
@@ -398,7 +398,7 @@
void *print_datatypes_error_c::visit(integer_literal_c *symbol) {
if (symbol->candidate_datatypes.size() == 0) {
- STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
+ STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
} else if (NULL == symbol->datatype) {
STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
}
@@ -407,7 +407,7 @@
void *print_datatypes_error_c::visit(real_literal_c *symbol) {
if (symbol->candidate_datatypes.size() == 0) {
- STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
+ STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
} else if (NULL == symbol->datatype) {
STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
}
@@ -416,7 +416,7 @@
void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) {
if (symbol->candidate_datatypes.size() == 0) {
- STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
+ STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
} else if (NULL == symbol->datatype) {
STAGE3_ERROR(4, symbol, symbol, "ANY_BIT data type not valid in this location.");
}
@@ -425,7 +425,7 @@
void *print_datatypes_error_c::visit(boolean_literal_c *symbol) {
if (symbol->candidate_datatypes.size() == 0) {
- STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", elementary_type_c::to_string(symbol->type));
+ STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
} else if (NULL == symbol->datatype) {
STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
}
--- a/stage4/generate_c/generate_c_typedecl.cc Thu Dec 27 15:04:58 2012 +0000
+++ b/stage4/generate_c/generate_c_typedecl.cc Thu Dec 27 15:31:01 2012 +0000
@@ -321,7 +321,7 @@
debug_c::print(symbol);
ERROR;
}
- symbol_c *type_name = get_datatype_info_c::get_datatype_id(symbol->datatype);
+ symbol_c *type_name = get_datatype_info_c::get_id(symbol->datatype);
if (NULL == type_name) {
// ERROR_MSG("generate_c does not support anonymous enumerated data types.");
} else