# HG changeset patch # User Mario de Sousa # Date 1331656701 0 # Node ID b13feab3b91801914e36d64b5346e7aff16f1064 # Parent c0c6ff7357b7f333cec7f7793a7f70cf33c6a016 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c. Expand widening tables for ADD, SUB, MUL and DIV. diff -r c0c6ff7357b7 -r b13feab3b918 absyntax/absyntax.def --- a/absyntax/absyntax.def Tue Mar 13 12:39:09 2012 +0000 +++ b/absyntax/absyntax.def Tue Mar 13 16:38:21 2012 +0000 @@ -972,7 +972,7 @@ /*******************/ /* 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 */ /* NOTE: The parameter 'deprecated_operation' indicates that the operation, with the specific data types being used, is currently defined - * in the standard as being deprecated. This variable is filled in with the correct value in stage 3 (fill_candidate_datatypes_c) + * in the standard as being deprecated. This variable is filled in with the correct value in stage 3 (narrow_candidate_datatypes_c) * and currently only used in stage 3 (print_datatypes_error_c). */ SYM_REF0(LD_operator_c) diff -r c0c6ff7357b7 -r b13feab3b918 stage3/datatype_functions.cc --- a/stage3/datatype_functions.cc Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/datatype_functions.cc Tue Mar 13 16:38:21 2012 +0000 @@ -88,13 +88,28 @@ */ const struct widen_entry widen_ADD_table[] = { - { &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, - { &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, - /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, - { &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, - /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, +#define __add(TYPE) \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, + __ANY_NUM(__add) +#undef __add + + /*******************************************/ + /*******************************************/ + /*** Operations with TIME, DT and TOD... ***/ + /*******************************************/ + /*******************************************/ + { &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, + { &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, + /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, + { &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, + /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, /*******************************/ /* SAFE version on the left... */ @@ -102,10 +117,12 @@ { &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, { &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, { &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, /********************************/ /* SAFE version on the right... */ @@ -113,10 +130,12 @@ { &search_constant_type_c::time_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::time_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::time_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, { &search_constant_type_c::dt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::time_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::time_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, /*************************************/ /* SAFE version on left and right... */ @@ -124,10 +143,12 @@ { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::ok }, { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, widen_entry::deprecated }, { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, widen_entry::deprecated }, /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, widen_entry::deprecated }, + /* not currently supported by stage4, so it is best no tto add it for now... */ +// { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, widen_entry::deprecated }, { NULL, NULL, NULL, widen_entry::ok }, }; @@ -139,6 +160,19 @@ const struct widen_entry widen_SUB_table[] = { +#define __sub(TYPE) \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, + __ANY_NUM(__sub) +#undef __sub + + /*******************************************/ + /*******************************************/ + /*** Operations with TIME, DT and TOD... ***/ + /*******************************************/ + /*******************************************/ { &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, { &search_constant_type_c::date_type_name, &search_constant_type_c::date_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, { &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, @@ -159,22 +193,22 @@ /********************************/ /* SAFE version on the right... */ /********************************/ - { &search_constant_type_c::time_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, - { &search_constant_type_c::date_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, - { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, - { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, - { &search_constant_type_c::dt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, - { &search_constant_type_c::dt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, + { &search_constant_type_c::time_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, + { &search_constant_type_c::date_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, + { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, widen_entry::deprecated }, + { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, + { &search_constant_type_c::dt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, widen_entry::deprecated }, + { &search_constant_type_c::dt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, /*************************************/ /* SAFE version on left and right... */ /*************************************/ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::ok }, - { &search_constant_type_c::safedate_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, - { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, widen_entry::deprecated }, - { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, - { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, widen_entry::deprecated }, - { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, + { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::ok }, + { &search_constant_type_c::safedate_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, + { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, widen_entry::deprecated }, + { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, + { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, widen_entry::deprecated }, + { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, { NULL, NULL, NULL, widen_entry::ok }, }; @@ -186,17 +220,29 @@ const struct widen_entry widen_MUL_table[] = { +#define __mul(TYPE) \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, + __ANY_NUM(__mul) +#undef __mul + + /*******************************************/ + /*******************************************/ + /*** Operations with TIME, DT and TOD... ***/ + /*******************************************/ + /*******************************************/ #define __multime(TYPE) \ - { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, \ /* NOTE: the standard des not explicitly support the following semantics. However, since 'multiplication' is supposed to be commutative, we add it anyway... */ \ - { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, - + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, __ANY_NUM(__multime) #undef __multime @@ -208,11 +254,24 @@ const struct widen_entry widen_DIV_table[] = { +#define __div(TYPE) \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ + { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, + __ANY_NUM(__div) +#undef __div + + /*******************************************/ + /*******************************************/ + /*** Operations with TIME, DT and TOD... ***/ + /*******************************************/ + /*******************************************/ #define __divtime(TYPE) \ - { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ - { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, + { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, widen_entry::deprecated }, \ + { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, widen_entry::deprecated }, __ANY_NUM(__divtime) #undef __divtime diff -r c0c6ff7357b7 -r b13feab3b918 stage3/datatype_functions.hh --- a/stage3/datatype_functions.hh Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/datatype_functions.hh Tue Mar 13 16:38:21 2012 +0000 @@ -67,48 +67,48 @@ /***********************************/ /* 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(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"; }; }; @@ -151,53 +151,53 @@ /* A helper function... */ -bool is_ANY_ELEMENTARY_type (symbol_c *type_symbol); -bool is_ANY_SAFEELEMENTARY_type (symbol_c *type_symbol); -bool is_ANY_ELEMENTARY_compatible (symbol_c *type_symbol); - -bool is_ANY_MAGNITUDE_type (symbol_c *type_symbol); -bool is_ANY_SAFEMAGNITUDE_type (symbol_c *type_symbol); -bool is_ANY_MAGNITUDE_compatible (symbol_c *type_symbol); +bool is_ANY_ELEMENTARY_type (symbol_c *type_symbol); +bool is_ANY_SAFEELEMENTARY_type (symbol_c *type_symbol); +bool is_ANY_ELEMENTARY_compatible (symbol_c *type_symbol); + +bool is_ANY_MAGNITUDE_type (symbol_c *type_symbol); +bool is_ANY_SAFEMAGNITUDE_type (symbol_c *type_symbol); +bool is_ANY_MAGNITUDE_compatible (symbol_c *type_symbol); bool is_ANY_signed_MAGNITUDE_type (symbol_c *type_symbol); bool is_ANY_signed_SAFEMAGNITUDE_type (symbol_c *type_symbol); bool is_ANY_signed_MAGNITUDE_compatible (symbol_c *type_symbol); -bool is_ANY_DATE_type (symbol_c *type_symbol); -bool is_ANY_SAFEDATE_type (symbol_c *type_symbol); -bool is_ANY_DATE_compatible (symbol_c *type_symbol); - -bool is_ANY_STRING_type (symbol_c *type_symbol); -bool is_ANY_SAFESTRING_type (symbol_c *type_symbol); -bool is_ANY_STRING_compatible (symbol_c *type_symbol); - -bool is_ANY_INT_type (symbol_c *type_symbol); -bool is_ANY_SAFEINT_type (symbol_c *type_symbol); -bool is_ANY_INT_compatible (symbol_c *type_symbol); +bool is_ANY_DATE_type (symbol_c *type_symbol); +bool is_ANY_SAFEDATE_type (symbol_c *type_symbol); +bool is_ANY_DATE_compatible (symbol_c *type_symbol); + +bool is_ANY_STRING_type (symbol_c *type_symbol); +bool is_ANY_SAFESTRING_type (symbol_c *type_symbol); +bool is_ANY_STRING_compatible (symbol_c *type_symbol); + +bool is_ANY_INT_type (symbol_c *type_symbol); +bool is_ANY_SAFEINT_type (symbol_c *type_symbol); +bool is_ANY_INT_compatible (symbol_c *type_symbol); bool is_ANY_signed_INT_type (symbol_c *type_symbol); bool is_ANY_signed_SAFEINT_type (symbol_c *type_symbol); bool is_ANY_signed_INT_compatible (symbol_c *type_symbol); -bool is_ANY_REAL_type (symbol_c *type_symbol); -bool is_ANY_SAFEREAL_type (symbol_c *type_symbol); -bool is_ANY_REAL_compatible (symbol_c *type_symbol); - -bool is_ANY_NUM_type (symbol_c *type_symbol); -bool is_ANY_SAFENUM_type (symbol_c *type_symbol); -bool is_ANY_NUM_compatible (symbol_c *type_symbol); +bool is_ANY_REAL_type (symbol_c *type_symbol); +bool is_ANY_SAFEREAL_type (symbol_c *type_symbol); +bool is_ANY_REAL_compatible (symbol_c *type_symbol); + +bool is_ANY_NUM_type (symbol_c *type_symbol); +bool is_ANY_SAFENUM_type (symbol_c *type_symbol); +bool is_ANY_NUM_compatible (symbol_c *type_symbol); bool is_ANY_signed_NUM_type (symbol_c *type_symbol); bool is_ANY_signed_SAFENUM_type (symbol_c *type_symbol); bool is_ANY_signed_NUM_compatible (symbol_c *type_symbol); -bool is_ANY_BIT_type (symbol_c *type_symbol); -bool is_ANY_SAFEBIT_type (symbol_c *type_symbol); -bool is_ANY_BIT_compatible (symbol_c *type_symbol); - -bool is_BOOL_type (symbol_c *type_symbol); -bool is_SAFEBOOL_type (symbol_c *type_symbol); -bool is_ANY_BOOL_compatible (symbol_c *type_symbol); +bool is_ANY_BIT_type (symbol_c *type_symbol); +bool is_ANY_SAFEBIT_type (symbol_c *type_symbol); +bool is_ANY_BIT_compatible (symbol_c *type_symbol); + +bool is_BOOL_type (symbol_c *type_symbol); +bool is_SAFEBOOL_type (symbol_c *type_symbol); +bool is_ANY_BOOL_compatible (symbol_c *type_symbol); bool is_type_equal(symbol_c *first_type, symbol_c *second_type); diff -r c0c6ff7357b7 -r b13feab3b918 stage3/fill_candidate_datatypes.cc --- a/stage3/fill_candidate_datatypes.cc Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/fill_candidate_datatypes.cc Tue Mar 13 16:38:21 2012 +0000 @@ -53,14 +53,12 @@ fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) { } -symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[], bool &deprecated_operation) { +symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]) { int k; /* find a widening table entry compatible */ for (k = 0; NULL != widen_table[k].left; k++) - if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right))) { - deprecated_operation = (widen_table[k].status == widen_entry::deprecated); + if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right))) return widen_table[k].result; - } return NULL; } @@ -68,6 +66,12 @@ /* add a data type to a candidate data type list, while guaranteeing no duplicate entries! */ /* Returns true if it really did add the datatype to the list, or false if it was already present in the list! */ bool fill_candidate_datatypes_c::add_datatype_to_candidate_list(symbol_c *symbol, symbol_c *datatype) { + /* If it is an invalid data type, do not insert! + * NOTE: it reduces overall code size to do this test here, instead of doing every time before calling the add_datatype_to_candidate_list() function. + */ + if (!is_type_valid(datatype)) /* checks for NULL and invalid_type_name_c */ + return false; + if (search_in_candidate_datatype_list(datatype, symbol->candidate_datatypes) >= 0) /* already in the list, Just return! */ return false; @@ -1278,15 +1282,8 @@ for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; operand_type = il_operand->candidate_datatypes[j]; - if (is_type_equal(prev_instruction_type, operand_type) && - is_ANY_NUM_compatible(prev_instruction_type)) - add_datatype_to_candidate_list(symbol, prev_instruction_type); - else { - symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_ADD_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(prev_instruction_type, operand_type, widen_ADD_table)); } } if (debug) std::cout << "ADD [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1302,14 +1299,8 @@ for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; operand_type = il_operand->candidate_datatypes[j]; - if (is_type_equal(prev_instruction_type, operand_type) && - is_ANY_NUM_compatible(prev_instruction_type)) - add_datatype_to_candidate_list(symbol, prev_instruction_type); - else { - symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_SUB_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(prev_instruction_type, operand_type, widen_SUB_table)); } } if (debug) std::cout << "SUB [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1325,14 +1316,8 @@ for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; operand_type = il_operand->candidate_datatypes[j]; - if (is_type_equal(prev_instruction_type, operand_type) && - is_ANY_NUM_compatible(prev_instruction_type)) - add_datatype_to_candidate_list(symbol, prev_instruction_type); - else { - symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_MUL_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(prev_instruction_type, operand_type, widen_MUL_table)); } } if (debug) std::cout << "MUL [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1348,14 +1333,8 @@ for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; operand_type = il_operand->candidate_datatypes[j]; - if (is_type_equal(prev_instruction_type, operand_type) && - is_ANY_NUM_compatible(prev_instruction_type)) - add_datatype_to_candidate_list(symbol, prev_instruction_type); - else { - symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_DIV_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(prev_instruction_type, operand_type, widen_DIV_table)); } } if (debug) std::cout << "DIV [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1771,13 +1750,8 @@ for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { left_type = symbol->l_exp->candidate_datatypes[i]; right_type = symbol->r_exp->candidate_datatypes[j]; - if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type)) - add_datatype_to_candidate_list(symbol, left_type); - else { - symbol_c *result = widening_conversion(left_type, right_type, widen_ADD_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(left_type, right_type, widen_ADD_table)); } } if (debug) std::cout << "+ [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1795,13 +1769,8 @@ for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { left_type = symbol->l_exp->candidate_datatypes[i]; right_type = symbol->r_exp->candidate_datatypes[j]; - if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type)) - add_datatype_to_candidate_list(symbol, left_type); - else { - symbol_c *result = widening_conversion(left_type, right_type, widen_SUB_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(left_type, right_type, widen_SUB_table)); } } if (debug) std::cout << "- [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1819,14 +1788,8 @@ for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { left_type = symbol->l_exp->candidate_datatypes[i]; right_type = symbol->r_exp->candidate_datatypes[j]; - if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type)) - add_datatype_to_candidate_list(symbol, left_type); - else { - symbol_c *result = widening_conversion(left_type, right_type, widen_MUL_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } - + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(left_type, right_type, widen_MUL_table)); } } if (debug) std::cout << "* [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1844,14 +1807,8 @@ for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { left_type = symbol->l_exp->candidate_datatypes[i]; right_type = symbol->r_exp->candidate_datatypes[j]; - if (is_type_equal(left_type, right_type) && is_ANY_NUM_type(left_type)) - add_datatype_to_candidate_list(symbol, left_type); - else { - symbol_c *result = widening_conversion(left_type, right_type, widen_DIV_table, symbol->deprecated_operation); - if (result) - add_datatype_to_candidate_list(symbol, result); - } - + /* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */ + add_datatype_to_candidate_list(symbol, widening_conversion(left_type, right_type, widen_DIV_table)); } } if (debug) std::cout << "/ [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; diff -r c0c6ff7357b7 -r b13feab3b918 stage3/fill_candidate_datatypes.hh --- a/stage3/fill_candidate_datatypes.hh Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/fill_candidate_datatypes.hh Tue Mar 13 16:38:21 2012 +0000 @@ -79,7 +79,7 @@ /* the current IL operand being analyzed - its symbol and its data type */ symbol_c *il_operand_type; symbol_c *il_operand; - symbol_c *widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[], bool &deprecated_operation); + symbol_c *widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]); /* Match a function declaration with a function call through their parameters.*/ /* returns true if compatible function/FB invocation, otherwise returns false */ diff -r c0c6ff7357b7 -r b13feab3b918 stage3/narrow_candidate_datatypes.cc --- a/stage3/narrow_candidate_datatypes.cc Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/narrow_candidate_datatypes.cc Tue Mar 13 16:38:21 2012 +0000 @@ -95,11 +95,12 @@ -bool narrow_candidate_datatypes_c::is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]) { +bool narrow_candidate_datatypes_c::is_widening_compatible(const struct widen_entry widen_table[], symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, bool &deprecated_status) { for (int k = 0; NULL != widen_table[k].left; k++) { if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right)) - && (typeid(*result_type) == typeid(*widen_table[k].result))) { + && (typeid(*result_type) == typeid(*widen_table[k].result))) { + deprecated_status = (widen_table[k].status == widen_entry::deprecated); return true; } } @@ -749,6 +750,54 @@ /*******************/ /* B 2.2 Operators */ /*******************/ +void *narrow_candidate_datatypes_c::handle_il_instruction_widen(symbol_c *symbol, bool &deprecated_operation, const struct widen_entry widen_table[]) { + symbol_c *prev_instruction_type, *operand_type; + int count = 0; + bool deprecated_status; + + if (NULL == symbol->datatype) + /* next IL instructions were unable to determine the datatype this instruction should produce */ + return NULL; + + /* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. + * e.g. LD 33 + * AND ( 45 + * OR 56 + * ) + * When we handle the first 'AND' IL_operator, the il_operand will point to an simple_instr_list_c. + * In this case, when we call il_operand->accept(*this);, the prev_il_instruction pointer will be overwritten! + * + * We must therefore set the prev_il_instruction->datatype = symbol->datatype; + * __before__ calling il_operand->accept(*this) !! + * + * NOTE 2: We do not need to call prev_il_instruction->accept(*this), as the object to which prev_il_instruction + * is pointing to will be later narrowed by the call from the for() loop of the instruction_list_c + * (or simple_instr_list_c), which iterates backwards. + */ + deprecated_operation = false; + for(unsigned int i = 0; i < fake_prev_il_instruction->candidate_datatypes.size(); i++) { + for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { + prev_instruction_type = fake_prev_il_instruction->candidate_datatypes[i]; + operand_type = il_operand->candidate_datatypes[j]; + if (is_widening_compatible(widen_table, prev_instruction_type, operand_type, symbol->datatype, deprecated_operation)) { + /* set the desired datatype of the previous il instruction */ + set_datatype_in_prev_il_instructions(prev_instruction_type, fake_prev_il_instruction); + /* set the datatype for the operand */ + il_operand->datatype = operand_type; + + count ++; + } + } + } + +// if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */ + if (is_type_valid(symbol->datatype) && (count <= 0)) ERROR; + + il_operand->accept(*this); + return NULL; +} + + void *narrow_candidate_datatypes_c::handle_il_instruction(symbol_c *symbol) { if (NULL == symbol->datatype) @@ -778,6 +827,9 @@ return NULL; } + + + void *narrow_candidate_datatypes_c::visit(LD_operator_c *symbol) { if (NULL == symbol->datatype) /* next IL instructions were unable to determine the datatype this instruction should produce */ @@ -862,10 +914,10 @@ void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_il_instruction(symbol);} void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol) {return handle_il_instruction(symbol);} void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol) {return handle_il_instruction(symbol);} -void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol) {return handle_il_instruction(symbol);} -void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol) {return handle_il_instruction(symbol);} -void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol) {return handle_il_instruction(symbol);} -void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol) {return handle_il_instruction(symbol);} +void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol) {return handle_il_instruction_widen(symbol, symbol->deprecated_operation, widen_ADD_table);} +void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol) {return handle_il_instruction_widen(symbol, symbol->deprecated_operation, widen_SUB_table);} +void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol) {return handle_il_instruction_widen(symbol, symbol->deprecated_operation, widen_MUL_table);} +void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol) {return handle_il_instruction_widen(symbol, symbol->deprecated_operation, widen_DIV_table);} void *narrow_candidate_datatypes_c::visit( MOD_operator_c *symbol) {return handle_il_instruction(symbol);} void *narrow_candidate_datatypes_c::visit( GT_operator_c *symbol) {return handle_il_instruction(symbol);} void *narrow_candidate_datatypes_c::visit( GE_operator_c *symbol) {return handle_il_instruction(symbol);} @@ -1178,29 +1230,26 @@ } void *narrow_candidate_datatypes_c::visit(add_expression_c *symbol) { + symbol_c *left_type, *right_type; int count = 0; - - if (is_ANY_NUM_compatible(symbol->datatype)) { - symbol->l_exp->datatype = symbol->datatype; - symbol->r_exp->datatype = symbol->datatype; - count++; - } else { - /* TIME data type */ - for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { - for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { - /* test widening compatibility */ - if (is_widening_compatible(symbol->l_exp->candidate_datatypes[i], - symbol->r_exp->candidate_datatypes[j], - symbol->datatype, widen_ADD_table)) { - symbol->l_exp->datatype = symbol->l_exp->candidate_datatypes[i]; - symbol->r_exp->datatype = symbol->r_exp->candidate_datatypes[j]; - count ++; - } + bool deprecated_status; + + for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { + for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { + /* test widening compatibility */ + left_type = symbol->l_exp->candidate_datatypes[i]; + right_type = symbol->r_exp->candidate_datatypes[j]; + if (is_widening_compatible(widen_ADD_table, left_type, right_type, symbol->datatype, deprecated_status)) { + symbol->l_exp->datatype = left_type; + symbol->r_exp->datatype = right_type; + symbol->deprecated_operation = deprecated_status; + count ++; } } } - if (count > 1) - ERROR; +// if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */ + if (is_type_valid(symbol->datatype) && (count <= 0)) ERROR; + symbol->l_exp->accept(*this); symbol->r_exp->accept(*this); return NULL; @@ -1209,93 +1258,91 @@ void *narrow_candidate_datatypes_c::visit(sub_expression_c *symbol) { + symbol_c *left_type, *right_type; int count = 0; - - if (is_ANY_NUM_compatible(symbol->datatype)) { - symbol->l_exp->datatype = symbol->datatype; - symbol->r_exp->datatype = symbol->datatype; - count++; - } else { - /* TIME data type */ - for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { - for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { - /* test widening compatibility */ - if (is_widening_compatible(symbol->l_exp->candidate_datatypes[i], - symbol->r_exp->candidate_datatypes[j], - symbol->datatype, widen_SUB_table)) { - symbol->l_exp->datatype = symbol->l_exp->candidate_datatypes[i]; - symbol->r_exp->datatype = symbol->r_exp->candidate_datatypes[j]; - count ++; - } + bool deprecated_status; + + for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { + for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { + /* test widening compatibility */ + left_type = symbol->l_exp->candidate_datatypes[i]; + right_type = symbol->r_exp->candidate_datatypes[j]; + if (is_widening_compatible(widen_SUB_table, left_type, right_type, symbol->datatype, deprecated_status)) { + symbol->l_exp->datatype = left_type; + symbol->r_exp->datatype = right_type; + symbol->deprecated_operation = deprecated_status; + count ++; } } } - if (count > 1) - ERROR; +// if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */ + if (is_type_valid(symbol->datatype) && (count <= 0)) ERROR; + symbol->l_exp->accept(*this); symbol->r_exp->accept(*this); return NULL; } + + void *narrow_candidate_datatypes_c::visit(mul_expression_c *symbol) { + symbol_c *left_type, *right_type; int count = 0; - - if (is_ANY_NUM_compatible(symbol->datatype)) { - symbol->l_exp->datatype = symbol->datatype; - symbol->r_exp->datatype = symbol->datatype; - count++; - } else { - /* TIME data type */ - for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { - for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { - /* test widening compatibility */ - if (is_widening_compatible(symbol->l_exp->candidate_datatypes[i], - symbol->r_exp->candidate_datatypes[j], - symbol->datatype, widen_MUL_table)) { - symbol->l_exp->datatype = symbol->l_exp->candidate_datatypes[i]; - symbol->r_exp->datatype = symbol->r_exp->candidate_datatypes[j]; - count ++; - } + bool deprecated_status; + + for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { + for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { + /* test widening compatibility */ + left_type = symbol->l_exp->candidate_datatypes[i]; + right_type = symbol->r_exp->candidate_datatypes[j]; + if (is_widening_compatible(widen_MUL_table, left_type, right_type, symbol->datatype, deprecated_status)) { + symbol->l_exp->datatype = left_type; + symbol->r_exp->datatype = right_type; + symbol->deprecated_operation = deprecated_status; + count ++; } } } - if (count > 1) - ERROR; +// if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */ + if (is_type_valid(symbol->datatype) && (count <= 0)) ERROR; + symbol->l_exp->accept(*this); symbol->r_exp->accept(*this); return NULL; } + + + void *narrow_candidate_datatypes_c::visit(div_expression_c *symbol) { + symbol_c *left_type, *right_type; int count = 0; - - if (is_ANY_NUM_compatible(symbol->datatype)) { - symbol->l_exp->datatype = symbol->datatype; - symbol->r_exp->datatype = symbol->datatype; - count++; - } else { - /* TIME data type */ - for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { - for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { - /* test widening compatibility */ - if (is_widening_compatible(symbol->l_exp->candidate_datatypes[i], - symbol->r_exp->candidate_datatypes[j], - symbol->datatype, widen_DIV_table)) { - symbol->l_exp->datatype = symbol->l_exp->candidate_datatypes[i]; - symbol->r_exp->datatype = symbol->r_exp->candidate_datatypes[j]; - count ++; - } + bool deprecated_status; + + for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) { + for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) { + /* test widening compatibility */ + left_type = symbol->l_exp->candidate_datatypes[i]; + right_type = symbol->r_exp->candidate_datatypes[j]; + if (is_widening_compatible(widen_DIV_table, left_type, right_type, symbol->datatype, deprecated_status)) { + symbol->l_exp->datatype = left_type; + symbol->r_exp->datatype = right_type; + symbol->deprecated_operation = deprecated_status; + count ++; } } } - if (count > 1) - ERROR; +// if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */ + if (is_type_valid(symbol->datatype) && (count <= 0)) ERROR; + symbol->l_exp->accept(*this); symbol->r_exp->accept(*this); return NULL; } + + void *narrow_candidate_datatypes_c::visit(mod_expression_c *symbol) { symbol->l_exp->datatype = symbol->datatype; symbol->l_exp->accept(*this); diff -r c0c6ff7357b7 -r b13feab3b918 stage3/narrow_candidate_datatypes.hh --- a/stage3/narrow_candidate_datatypes.hh Tue Mar 13 12:39:09 2012 +0000 +++ b/stage3/narrow_candidate_datatypes.hh Tue Mar 13 16:38:21 2012 +0000 @@ -46,13 +46,16 @@ std::vector *prev_il_instructions; std::vector *prev_il_instructions_intersected_datatypes; - bool is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]); + bool is_widening_compatible(const struct widen_entry widen_table[], symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, bool &deprecated_status); void narrow_function_invocation(symbol_c *f_call, generic_function_call_t fcall_data); void narrow_nonformal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL); void narrow_formal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL); void *narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration); + void *handle_il_instruction(symbol_c *symbol); + void *handle_il_instruction_widen(symbol_c *symbol, bool &deprecated_operation, const struct widen_entry widen_table[]); + void *narrow_conditional_flow_control_IL_instruction(symbol_c *symbol);