stage4/generate_iec/generate_iec.cc
changeset 205 96d8b6e006f0
parent 202 da1a8186f86f
child 257 90782e241346
equal deleted inserted replaced
200:fde2d08ebaee 205:96d8b6e006f0
    41 
    41 
    42 // #include <stdio.h>  /* required for NULL */
    42 // #include <stdio.h>  /* required for NULL */
    43 #include <string>
    43 #include <string>
    44 #include <iostream>
    44 #include <iostream>
    45 #include <sstream>
    45 #include <sstream>
       
    46 #include <typeinfo>
    46 #include "generate_iec.hh"
    47 #include "generate_iec.hh"
    47 
    48 
    48 #include "../stage4.hh"
    49 #include "../stage4.hh"
    49 
    50 
    50 
    51 
   120 
   121 
   121 
   122 
   122   public:
   123   public:
   123 
   124 
   124 /*  EN/ENO */
   125 /*  EN/ENO */
       
   126 #if 0
   125 void *visit(en_param_c *symbol) {
   127 void *visit(en_param_c *symbol) {
   126   s4o.print("EN");
   128   s4o.print("EN");
   127   return NULL;
   129   return NULL;
   128 }
   130 }
   129 
   131 
   130 void *visit(eno_param_c *symbol) {
   132 void *visit(eno_param_c *symbol) {
   131   s4o.print("ENO");
   133   s4o.print("ENO");
   132   return NULL;
   134   return NULL;
   133 }
   135 }
       
   136 void *visit(en_param_c *symbol) {
       
   137   return symbol->param_name->accept(*this);
       
   138 }
       
   139 
       
   140 void *visit(eno_param_c *symbol) {
       
   141   return symbol->param_name->accept(*this);
       
   142 }
       
   143 #endif
       
   144 
       
   145 
       
   146 
   134 
   147 
   135 /***************************/
   148 /***************************/
   136 /* 2.1.6 Pragmas */
   149 /* 2.1.6 Pragmas */
   137 /***************************/
   150 /***************************/
   138 void *visit(pragma_c *symbol) {return print_token(symbol);}
   151 void *visit(pragma_c *symbol) {return print_token(symbol);}
   159 void *visit(integer_c *symbol) {return print_token(symbol);}
   172 void *visit(integer_c *symbol) {return print_token(symbol);}
   160 void *visit(binary_integer_c *symbol) {return print_token(symbol);}
   173 void *visit(binary_integer_c *symbol) {return print_token(symbol);}
   161 void *visit(octal_integer_c *symbol) {return print_token(symbol);}
   174 void *visit(octal_integer_c *symbol) {return print_token(symbol);}
   162 void *visit(hex_integer_c *symbol) {return print_token(symbol);}
   175 void *visit(hex_integer_c *symbol) {return print_token(symbol);}
   163 
   176 
   164 void *visit(numeric_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
       
   165 void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   177 void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   166 void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   178 void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   167 void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   179 void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   168 void *visit(boolean_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   180 void *visit(boolean_literal_c *symbol) {return print_literal(symbol->type, symbol->value);}
   169 void *visit(neg_literal_c *symbol) {return print_unary_expression(symbol->exp, "-");}
   181 void *visit(neg_literal_c *symbol) {return print_unary_expression(symbol->exp, "-");}
   312 void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;}
   324 void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;}
   313 void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;}
   325 void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;}
   314 void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;}
   326 void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;}
   315 void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;}
   327 void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;}
   316 void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;}
   328 void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;}
       
   329 /*
   317 void *visit(constant_int_type_name_c *symbol) {return NULL;}
   330 void *visit(constant_int_type_name_c *symbol) {return NULL;}
   318 void *visit(constant_real_type_name_c *symbol) {return NULL;}
   331 void *visit(constant_real_type_name_c *symbol) {return NULL;}
   319 
   332 */
   320 
   333 
   321 /********************************/
   334 /********************************/
   322 /* B 1.3.3 - Derived data types */
   335 /* B 1.3.3 - Derived data types */
   323 /********************************/
   336 /********************************/
   324 /*  TYPE type_declaration_list END_TYPE */
   337 /*  TYPE type_declaration_list END_TYPE */
   587 void *visit(non_retain_option_c *symbol) {s4o.print("NON_RETAIN"); return NULL;}
   600 void *visit(non_retain_option_c *symbol) {s4o.print("NON_RETAIN"); return NULL;}
   588 
   601 
   589 /* VAR_INPUT [RETAIN | NON_RETAIN] input_declaration_list END_VAR */
   602 /* VAR_INPUT [RETAIN | NON_RETAIN] input_declaration_list END_VAR */
   590 /* option -> the RETAIN/NON_RETAIN/<NULL> directive... */
   603 /* option -> the RETAIN/NON_RETAIN/<NULL> directive... */
   591 void *visit(input_declarations_c *symbol) {
   604 void *visit(input_declarations_c *symbol) {
   592   s4o.print(s4o.indent_spaces); s4o.print("VAR_INPUT ");
   605   if (typeid(*(symbol->method)) == typeid(explicit_definition_c)) {
   593   if (symbol->option != NULL)
   606     s4o.print(s4o.indent_spaces); s4o.print("VAR_INPUT ");
   594     symbol->option->accept(*this);
   607     if (symbol->option != NULL)
   595   s4o.print("\n");
   608       symbol->option->accept(*this);
   596   s4o.indent_right();
   609     s4o.print("\n");
   597   symbol->input_declaration_list->accept(*this);
   610     s4o.indent_right();
   598   s4o.indent_left();
   611     symbol->input_declaration_list->accept(*this);
   599   s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n");
   612     s4o.indent_left();
       
   613     s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n");
       
   614   }
   600   return NULL;
   615   return NULL;
   601 }
   616 }
   602 
   617 
   603 /* helper symbol for input_declarations */
   618 /* helper symbol for input_declarations */
   604 /*| input_declaration_list input_declaration ';' */
   619 /*| input_declaration_list input_declaration ';' */
   612   s4o.print(" : BOOL ");
   627   s4o.print(" : BOOL ");
   613   symbol->edge->accept(*this);
   628   symbol->edge->accept(*this);
   614   return NULL;
   629   return NULL;
   615 }
   630 }
   616 
   631 
       
   632 /* dummy classes only used as flags! */
       
   633 void *visit(explicit_definition_c *symbol) {return NULL;}
       
   634 void *visit(implicit_definition_c *symbol) {return NULL;}
       
   635 
       
   636 /* EN : BOOL := 1 */
   617 void *visit(en_param_declaration_c *symbol) {
   637 void *visit(en_param_declaration_c *symbol) {
   618   s4o.print("EN : BOOL := 1");
   638   if (typeid(*(symbol->method)) == typeid(explicit_definition_c)) {
       
   639     symbol->name->accept(*this);
       
   640     s4o.print(" : ");
       
   641     symbol->type->accept(*this);
       
   642     s4o.print(" := ");
       
   643     symbol->value->accept(*this);
       
   644   }
       
   645   return NULL;
       
   646 }
       
   647 
       
   648 /* ENO : BOOL */
       
   649 void *visit(eno_param_declaration_c *symbol) {
       
   650   if (typeid(*(symbol->method)) == typeid(explicit_definition_c)) {
       
   651     symbol->name->accept(*this);
       
   652     s4o.print(" : ");
       
   653     symbol->type->accept(*this);
       
   654   }
   619   return NULL;
   655   return NULL;
   620 }
   656 }
   621 
   657 
   622 void *visit(raising_edge_option_c *symbol) {
   658 void *visit(raising_edge_option_c *symbol) {
   623   s4o.print("R_EDGE");
   659   s4o.print("R_EDGE");
   680 void *visit(fb_name_list_c *symbol) {return print_list(symbol, "", ", ");}
   716 void *visit(fb_name_list_c *symbol) {return print_list(symbol, "", ", ");}
   681 
   717 
   682 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   718 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   683 /* option -> may be NULL ! */
   719 /* option -> may be NULL ! */
   684 void *visit(output_declarations_c *symbol) {
   720 void *visit(output_declarations_c *symbol) {
   685   s4o.print(s4o.indent_spaces); s4o.print("VAR_OUTPUT ");
   721   if (typeid(*(symbol->method)) == typeid(explicit_definition_c)) {
   686   if (symbol->option != NULL)
   722     s4o.print(s4o.indent_spaces); s4o.print("VAR_OUTPUT ");
   687     symbol->option->accept(*this);
   723     if (symbol->option != NULL)
   688   s4o.print("\n");
   724       symbol->option->accept(*this);
   689   s4o.indent_right();
   725     s4o.print("\n");
   690   symbol->var_init_decl_list->accept(*this);
   726     s4o.indent_right();
   691   s4o.indent_left();
   727     symbol->var_init_decl_list->accept(*this);
   692   s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n");
   728     s4o.indent_left();
   693   return NULL;
   729     s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n");
   694 }
   730   }
   695 
       
   696 void *visit(eno_param_declaration_c *symbol) {
       
   697   s4o.print("EN0 : BOOL");
       
   698   return NULL;
   731   return NULL;
   699 }
   732 }
   700 
   733 
   701 /*  VAR_IN_OUT  END_VAR */
   734 /*  VAR_IN_OUT  END_VAR */
   702 void *visit(input_output_declarations_c *symbol) {
   735 void *visit(input_output_declarations_c *symbol) {
  1687 void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "NOT ");}
  1720 void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "NOT ");}
  1688 
  1721 
  1689 void *visit(function_invocation_c *symbol) {
  1722 void *visit(function_invocation_c *symbol) {
  1690   symbol->function_name->accept(*this);
  1723   symbol->function_name->accept(*this);
  1691   s4o.print("(");
  1724   s4o.print("(");
  1692   symbol->parameter_assignment_list->accept(*this);
  1725 
       
  1726   /* If the syntax parser is working correctly, exactly one of the 
       
  1727    * following two symbols will be NULL, while the other is != NULL.
       
  1728    */
       
  1729   if (symbol->   formal_param_list != NULL) symbol->   formal_param_list->accept(*this);
       
  1730   if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this);
       
  1731 
  1693   s4o.print(")");
  1732   s4o.print(")");
  1694   return NULL;
  1733   return NULL;
  1695 }
  1734 }
  1696 
  1735 
  1697 /********************/
  1736 /********************/
  1724 
  1763 
  1725 /* fb_name '(' [param_assignment_list] ')' */
  1764 /* fb_name '(' [param_assignment_list] ')' */
  1726 void *visit(fb_invocation_c *symbol) {
  1765 void *visit(fb_invocation_c *symbol) {
  1727   symbol->fb_name->accept(*this);
  1766   symbol->fb_name->accept(*this);
  1728   s4o.print("(");
  1767   s4o.print("(");
  1729   if (symbol->param_assignment_list != NULL)
  1768   /* If the syntax parser is working correctly, at most one of the 
  1730     symbol->param_assignment_list->accept(*this);
  1769    * following two symbols will be NULL, while the other is != NULL.
       
  1770    * The two may be NULL simultaneously!
       
  1771    */
       
  1772   if (symbol->   formal_param_list != NULL) symbol->   formal_param_list->accept(*this);
       
  1773   if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this);
       
  1774 
  1731   s4o.print(")");
  1775   s4o.print(")");
  1732   return NULL;
  1776   return NULL;
  1733 }
  1777 }
  1734 
  1778 
  1735 
  1779