stage1_2/create_enumtype_conversion_functions.cc
changeset 754 36f91a5e4fc8
parent 753 5c389814f496
child 756 634f476cb60f
equal deleted inserted replaced
753:5c389814f496 754:36f91a5e4fc8
   155   ...
   155   ...
   156   IF IN = '<ENUM.VALU_N>' THEN
   156   IF IN = '<ENUM.VALU_N>' THEN
   157    STRING_TO_<ENUM> := <ENUM.VALUE_N>;
   157    STRING_TO_<ENUM> := <ENUM.VALUE_N>;
   158    RETURN;
   158    RETURN;
   159   END_IF;
   159   END_IF;
       
   160   ENO := FALSE;
   160   END_FUNCTION
   161   END_FUNCTION
   161 
   162 
   162   Note: if you change code below remember to update this comment.
   163   Note: if you change code below remember to update this comment.
   163  */
   164  */
   164 void create_enumtype_conversion_functions_c::printStringToEnum  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
   165 void create_enumtype_conversion_functions_c::printStringToEnum  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
   170     text += "\nVAR_INPUT\nIN : STRING;\nEND_VAR\n";
   171     text += "\nVAR_INPUT\nIN : STRING;\nEND_VAR\n";
   171     for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
   172     for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
   172        std::string value = *itr;
   173        std::string value = *itr;
   173        text += "IF IN = '" + value + "' THEN\n";
   174        text += "IF IN = '" + value + "' THEN\n";
   174        text += " " + functionName + " := " + value + ";\n";
   175        text += " " + functionName + " := " + value + ";\n";
   175        text += " RETURN;\n";
   176        text += " RETURN;\n"; 
   176        text += "END_IF;\n";
   177        text += "END_IF;\n";
   177     }
   178     }
       
   179     text += "ENO := FALSE;\n";
   178     text += "END_FUNCTION\n\n";
   180     text += "END_FUNCTION\n\n";
   179 }
   181 }
   180 
   182 
   181 /*
   183 /*
   182  * printEnumToString function print conversion function from <ENUM> to STRING:
   184  * printEnumToString function print conversion function from <ENUM> to STRING:
   194   ...
   196   ...
   195   IF IN = <ENUM.VALUE_N> THEN
   197   IF IN = <ENUM.VALUE_N> THEN
   196    <ENUM>_TO_STRING := '<ENUM.VALUE_N>';
   198    <ENUM>_TO_STRING := '<ENUM.VALUE_N>';
   197    RETURN;
   199    RETURN;
   198   END_IF;
   200   END_IF;
       
   201   ENO := FALSE;
   199   END_FUNCTION
   202   END_FUNCTION
   200 
   203 
   201   Note: if you change code below remember to update this comment.
   204   Note: if you change code below remember to update this comment.
   202  */
   205  */
   203 void create_enumtype_conversion_functions_c::printEnumToString  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
   206 void create_enumtype_conversion_functions_c::printEnumToString  (std::string &enumerateName, std::list<std::string> &enumerateValues) {
   212         text += "IF IN = " + value + " THEN\n";
   215         text += "IF IN = " + value + " THEN\n";
   213         text += " " + functionName + " := '" + value + "';\n";
   216         text += " " + functionName + " := '" + value + "';\n";
   214         text += " RETURN;\n";
   217         text += " RETURN;\n";
   215         text += "END_IF;\n";
   218         text += "END_IF;\n";
   216     }
   219     }
       
   220     text += "ENO := FALSE;\n";
   217     text += "END_FUNCTION\n\n";
   221     text += "END_FUNCTION\n\n";
   218 }
   222 }
   219 
   223 
   220 /*
   224 /*
   221  * printIntegerToEnum function print conversion function from <INTEGER> to <ENUM>:
   225  * printIntegerToEnum function print conversion function from <INTEGER> to <ENUM>:
   233   ...
   237   ...
   234   IF IN = N THEN
   238   IF IN = N THEN
   235    <INTEGER>_TO_<ENUM> := <ENUM.VALUE_N>;
   239    <INTEGER>_TO_<ENUM> := <ENUM.VALUE_N>;
   236    RETURN;
   240    RETURN;
   237   END_IF;
   241   END_IF;
       
   242   ENO := FALSE;
   238   END_FUNCTION
   243   END_FUNCTION
   239 
   244 
   240   Note: if you change code below remember to update this comment.
   245   Note: if you change code below remember to update this comment.
   241  */
   246  */
   242 void create_enumtype_conversion_functions_c::printIntegerToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
   247 void create_enumtype_conversion_functions_c::printIntegerToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
   258         text += " " + functionName + " := " + value + ";\n";
   263         text += " " + functionName + " := " + value + ";\n";
   259         text += " RETURN;\n";
   264         text += " RETURN;\n";
   260         text += "END_IF;\n";
   265         text += "END_IF;\n";
   261         count++;
   266         count++;
   262     }
   267     }
       
   268     text += "ENO := FALSE;\n";
   263     text += "END_FUNCTION\n\n";
   269     text += "END_FUNCTION\n\n";
   264 }
   270 }
   265 
   271 
   266 /*
   272 /*
   267  * printEnumToInteger function print conversion function from <ENUM> to <INTEGER>:
   273  * printEnumToInteger function print conversion function from <ENUM> to <INTEGER>:
   279   ...
   285   ...
   280   IF IN = <ENUM.VALUE_N> THEN
   286   IF IN = <ENUM.VALUE_N> THEN
   281    <ENUM>_TO_<INTEGER> := N;
   287    <ENUM>_TO_<INTEGER> := N;
   282    RETURN;
   288    RETURN;
   283   END_IF;
   289   END_IF;
       
   290   ENO := FALSE;
   284   END_FUNCTION
   291   END_FUNCTION
   285 
   292 
   286   Note: if you change code below remember to update this comment.
   293   Note: if you change code below remember to update this comment.
   287  */
   294  */
   288 void create_enumtype_conversion_functions_c::printEnumToInteger (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
   295 void create_enumtype_conversion_functions_c::printEnumToInteger (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
   304         text += " " + functionName + " := " + out.str() + ";\n";
   311         text += " " + functionName + " := " + out.str() + ";\n";
   305         text += " RETURN;\n";
   312         text += " RETURN;\n";
   306         text += "END_IF;\n";
   313         text += "END_IF;\n";
   307         count++;
   314         count++;
   308     }
   315     }
       
   316     text += "ENO := FALSE;\n";
   309     text += "END_FUNCTION\n\n";
   317     text += "END_FUNCTION\n\n";
   310 }
   318 }
   311 
   319 
   312 
   320 
   313 
   321