156 * real_c or integer_c with the value being negated. |
162 * real_c or integer_c with the value being negated. |
157 * neg_literal_c -> integer_literal_c |
163 * neg_literal_c -> integer_literal_c |
158 * OR |
164 * OR |
159 * neg_literal_c -> real_literal_c |
165 * neg_literal_c -> real_literal_c |
160 * |
166 * |
161 * In the semantic verification and code generation stages of the compiler, |
167 * However, this has since been changed to... |
162 * the integer_c is treated as a basic (undefined) data type, since an integer |
|
163 * constant may be used as a BYTE, BOOLEAN, REAL, etc..., depending on the |
|
164 * context in which it is used. |
|
165 * However, an integer_c that is preceded by a '-' may not be used |
|
166 * as an ANY_BIT data type (BYTE, BOOLEAN, WORD, ...). |
|
167 * We must therefore be able to determine, holding a simple pointer |
|
168 * to an integer_c, if that integer_c value is preceded by a '-'. |
|
169 * However, since the neg_literal_c points to the integer_c, and not |
|
170 * vice-versa, we can't determine that. |
|
171 * There are 3 simple ways of working around this: |
|
172 * - change the order of the pointers: |
|
173 * have the integer_c and real_c point to the neg_literal_c |
|
174 * - maintain the order of the pointers, and |
|
175 * add redundant info to the integer_c and real_c |
|
176 * - replace the neg_literal_c with two distinc classes |
168 * - replace the neg_literal_c with two distinc classes |
177 * (neg_integer_c and neg_real_c), one for each |
169 * (neg_integer_c and neg_real_c), one for each |
178 * lietral type. This means that we can now treat |
170 * lietral type. |
179 * each of these classes as an unknown data type |
171 * |
180 * just as we do with the integer_c and real_c. |
172 * This change was done in order to ease the writing of semantic verification (stage3) code. |
181 * |
173 * However, that version of the code has since been replaced by a newer and better algoritm. |
182 * The second option is simply ugly. |
174 * This means the above change can now be undone, but there is really no need to undo it, |
183 * and the first has a serious drawback: when generating code it is |
175 * so we leave it as it is. |
184 * easier to encapsulate the real or integer values inside prefix |
|
185 * and postfix symbols (e.g. NEG(<value>) - with postfix ')' ) |
|
186 * if we keep the pointer order as is. |
|
187 * |
|
188 * For the above reasoning, we use the third option. |
|
189 */ |
176 */ |
190 SYM_REF1(neg_real_c, exp) |
177 SYM_REF1(neg_real_c, exp) |
191 SYM_REF1(neg_integer_c, exp) |
178 SYM_REF1(neg_integer_c, exp) |
192 |
179 |
193 /* Not required: |
180 /* Not required: |
221 /************************/ |
208 /************************/ |
222 /* B 1.2.3.1 - Duration */ |
209 /* B 1.2.3.1 - Duration */ |
223 /************************/ |
210 /************************/ |
224 SYM_REF0(neg_time_c) |
211 SYM_REF0(neg_time_c) |
225 SYM_REF3(duration_c, type_name, neg, interval) |
212 SYM_REF3(duration_c, type_name, neg, interval) |
|
213 SYM_REF5(interval_c, days, hours, minutes, seconds, milliseconds) |
226 SYM_TOKEN(fixed_point_c) |
214 SYM_TOKEN(fixed_point_c) |
|
215 /* |
227 SYM_REF2(days_c, days, hours) |
216 SYM_REF2(days_c, days, hours) |
228 SYM_REF2(hours_c, hours, minutes) |
217 SYM_REF2(hours_c, hours, minutes) |
229 SYM_REF2(minutes_c, minutes, seconds) |
218 SYM_REF2(minutes_c, minutes, seconds) |
230 SYM_REF2(seconds_c, seconds, milliseconds) |
219 SYM_REF2(seconds_c, seconds, milliseconds) |
231 SYM_REF1(milliseconds_c, milliseconds) |
220 SYM_REF1(milliseconds_c, milliseconds) |
232 |
221 */ |
233 |
222 |
234 /************************************/ |
223 /************************************/ |
235 /* B 1.2.3.2 - Time of day and Date */ |
224 /* B 1.2.3.2 - Time of day and Date */ |
236 /************************************/ |
225 /************************************/ |
237 SYM_REF2(time_of_day_c, type_name, daytime) |
226 SYM_REF2(time_of_day_c, type_name, daytime) |
474 SYM_LIST(subscript_list_c) |
464 SYM_LIST(subscript_list_c) |
475 |
465 |
476 /* record_variable '.' field_selector */ |
466 /* record_variable '.' field_selector */ |
477 /* WARNING: input and/or output variables of function blocks |
467 /* WARNING: input and/or output variables of function blocks |
478 * may be accessed as fields of a structured variable! |
468 * may be accessed as fields of a structured variable! |
479 * Code handling a structured_variable_c must take |
469 * Code handling a structured_variable_c must take this into account! |
480 * this into account! |
470 * (i.e. that a FB instance may be accessed as a structured variable)! |
|
471 * |
|
472 * WARNING: Status bit (.X) and activation time (.T) of STEPS in SFC diagrams |
|
473 * may be accessed as fields of a structured variable! |
|
474 * Code handling a structured_variable_c must take this into account |
|
475 * (i.e. that an SFC STEP may be accessed as a structured variable)! |
481 */ |
476 */ |
482 SYM_REF2(structured_variable_c, record_variable, field_selector) |
477 SYM_REF2(structured_variable_c, record_variable, field_selector) |
483 |
478 |
484 /******************************************/ |
479 /******************************************/ |
485 /* B 1.4.3 - Declaration & Initialisation */ |
480 /* B 1.4.3 - Declaration & Initialisation */ |
911 /***********************************/ |
906 /***********************************/ |
912 /*| instruction_list il_instruction */ |
907 /*| instruction_list il_instruction */ |
913 SYM_LIST(instruction_list_c) |
908 SYM_LIST(instruction_list_c) |
914 |
909 |
915 /* | label ':' [il_incomplete_instruction] eol_list */ |
910 /* | label ':' [il_incomplete_instruction] eol_list */ |
916 SYM_REF2(il_instruction_c, label, il_instruction) |
911 /* NOTE: The parameter 'prev_il_instruction' is used to point to all previous il instructions that may be executed imedaitely before this instruction. |
|
912 * In case of an il instruction preceded by a label, this will include all IL instructions that jump to this label! |
|
913 * It is filled in by the flow_control_analysis_c during stage 3. |
|
914 */ |
|
915 SYM_REF2(il_instruction_c, label, il_instruction, std::vector <symbol_c *> prev_il_instruction;) |
917 |
916 |
918 |
917 |
919 /* | il_simple_operator [il_operand] */ |
918 /* | il_simple_operator [il_operand] */ |
920 SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
919 SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
921 |
920 |
922 /* | function_name [il_operand_list] */ |
921 /* | function_name [il_operand_list] */ |
923 /* NOTE: The parameters 'called_function_declaration' is used to pass |
922 /* NOTE: The parameter 'called_function_declaration', 'extensible_param_count' and 'candidate_functions' are used to pass data between the stage 3 and stage 4. |
924 * data between the stage 3 and stage 4. |
923 * data between the stage 3 and stage 4. |
925 * See the comment above function_invocation_c for more details |
924 * See the comment above function_invocation_c for more details |
926 */ |
925 */ |
927 SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;) |
926 SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;) |
928 |
927 |
929 |
928 |
930 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
929 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
931 SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list) |
930 SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list) |
932 |
931 |
937 * | il_call_operator prev_declared_fb_name '(' ')' |
936 * | il_call_operator prev_declared_fb_name '(' ')' |
938 * | il_call_operator prev_declared_fb_name '(' eol_list ')' |
937 * | il_call_operator prev_declared_fb_name '(' eol_list ')' |
939 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
938 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
940 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
939 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
941 */ |
940 */ |
942 SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) |
941 /* 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 */ |
|
942 SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration;) |
943 |
943 |
944 |
944 |
945 /* | function_name '(' eol_list [il_param_list] ')' */ |
945 /* | function_name '(' eol_list [il_param_list] ')' */ |
946 /* NOTE: The parameters 'called_function_declaration' is used to pass |
946 /* NOTE: The parameter 'called_function_declaration', 'extensible_param_count' and 'candidate_functions' are used to pass data between the stage 3 and stage 4. |
947 * data between the stage 3 and stage 4. |
947 * See the comment above function_invocation_c for more details. |
948 * See the comment above function_invocation_c for more details |
948 */ |
949 */ |
949 SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;) |
950 SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;) |
|
951 |
950 |
952 /* | il_operand_list ',' il_operand */ |
951 /* | il_operand_list ',' il_operand */ |
953 SYM_LIST(il_operand_list_c) |
952 SYM_LIST(il_operand_list_c) |
954 |
953 |
955 /* | simple_instr_list il_simple_instruction */ |
954 /* | simple_instr_list il_simple_instruction */ |
956 SYM_LIST(simple_instr_list_c) |
955 SYM_LIST(simple_instr_list_c) |
|
956 |
|
957 |
|
958 /* il_simple_instruction: |
|
959 * il_simple_operation eol_list |
|
960 * | il_expression eol_list |
|
961 * | il_formal_funct_call eol_list |
|
962 */ |
|
963 /* NOTE: The parameter 'prev_il_instruction' is used to point to all previous il instructions that may be executed imedaitely before this instruction. */ |
|
964 SYM_REF1(il_simple_instruction_c, il_simple_instruction, std::vector <symbol_c *> prev_il_instruction;) |
957 |
965 |
958 /* | il_initial_param_list il_param_instruction */ |
966 /* | il_initial_param_list il_param_instruction */ |
959 SYM_LIST(il_param_list_c) |
967 SYM_LIST(il_param_list_c) |
960 |
968 |
961 /* il_assign_operator il_operand |
969 /* il_assign_operator il_operand |
969 |
977 |
970 |
978 |
971 /*******************/ |
979 /*******************/ |
972 /* B 2.2 Operators */ |
980 /* B 2.2 Operators */ |
973 /*******************/ |
981 /*******************/ |
|
982 /* 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 */ |
|
983 /* NOTE: The parameter 'deprecated_operation' indicates that the operation, with the specific data types being used, is currently defined |
|
984 * in the standard as being deprecated. This variable is filled in with the correct value in stage 3 (narrow_candidate_datatypes_c) |
|
985 * and currently only used in stage 3 (print_datatypes_error_c). |
|
986 */ |
974 SYM_REF0(LD_operator_c) |
987 SYM_REF0(LD_operator_c) |
975 SYM_REF0(LDN_operator_c) |
988 SYM_REF0(LDN_operator_c) |
976 SYM_REF0(ST_operator_c) |
989 SYM_REF0(ST_operator_c) |
977 SYM_REF0(STN_operator_c) |
990 SYM_REF0(STN_operator_c) |
978 SYM_REF0(NOT_operator_c) |
991 SYM_REF0(NOT_operator_c) |
979 SYM_REF0(S_operator_c) |
992 SYM_REF0(S_operator_c, symbol_c *called_fb_declaration;) |
980 SYM_REF0(R_operator_c) |
993 SYM_REF0(R_operator_c, symbol_c *called_fb_declaration;) |
981 SYM_REF0(S1_operator_c) |
994 SYM_REF0(S1_operator_c, symbol_c *called_fb_declaration;) |
982 SYM_REF0(R1_operator_c) |
995 SYM_REF0(R1_operator_c, symbol_c *called_fb_declaration;) |
983 SYM_REF0(CLK_operator_c) |
996 SYM_REF0(CLK_operator_c, symbol_c *called_fb_declaration;) |
984 SYM_REF0(CU_operator_c) |
997 SYM_REF0(CU_operator_c, symbol_c *called_fb_declaration;) |
985 SYM_REF0(CD_operator_c) |
998 SYM_REF0(CD_operator_c, symbol_c *called_fb_declaration;) |
986 SYM_REF0(PV_operator_c) |
999 SYM_REF0(PV_operator_c, symbol_c *called_fb_declaration;) |
987 SYM_REF0(IN_operator_c) |
1000 SYM_REF0(IN_operator_c, symbol_c *called_fb_declaration;) |
988 SYM_REF0(PT_operator_c) |
1001 SYM_REF0(PT_operator_c, symbol_c *called_fb_declaration;) |
989 SYM_REF0(AND_operator_c) |
1002 SYM_REF0(AND_operator_c) |
990 SYM_REF0(OR_operator_c) |
1003 SYM_REF0(OR_operator_c) |
991 SYM_REF0(XOR_operator_c) |
1004 SYM_REF0(XOR_operator_c) |
992 SYM_REF0(ANDN_operator_c) |
1005 SYM_REF0(ANDN_operator_c) |
993 SYM_REF0(ORN_operator_c) |
1006 SYM_REF0(ORN_operator_c) |
994 SYM_REF0(XORN_operator_c) |
1007 SYM_REF0(XORN_operator_c) |
995 SYM_REF0(ADD_operator_c) |
1008 SYM_REF0(ADD_operator_c, bool deprecated_operation;) |
996 SYM_REF0(SUB_operator_c) |
1009 SYM_REF0(SUB_operator_c, bool deprecated_operation;) |
997 SYM_REF0(MUL_operator_c) |
1010 SYM_REF0(MUL_operator_c, bool deprecated_operation;) |
998 SYM_REF0(DIV_operator_c) |
1011 SYM_REF0(DIV_operator_c, bool deprecated_operation;) |
999 SYM_REF0(MOD_operator_c) |
1012 SYM_REF0(MOD_operator_c) |
1000 SYM_REF0(GT_operator_c) |
1013 SYM_REF0(GT_operator_c) |
1001 SYM_REF0(GE_operator_c) |
1014 SYM_REF0(GE_operator_c) |
1002 SYM_REF0(EQ_operator_c) |
1015 SYM_REF0(EQ_operator_c) |
1003 SYM_REF0(LT_operator_c) |
1016 SYM_REF0(LT_operator_c) |
1034 SYM_REF2(notequ_expression_c, l_exp, r_exp) |
1047 SYM_REF2(notequ_expression_c, l_exp, r_exp) |
1035 SYM_REF2(lt_expression_c, l_exp, r_exp) |
1048 SYM_REF2(lt_expression_c, l_exp, r_exp) |
1036 SYM_REF2(gt_expression_c, l_exp, r_exp) |
1049 SYM_REF2(gt_expression_c, l_exp, r_exp) |
1037 SYM_REF2(le_expression_c, l_exp, r_exp) |
1050 SYM_REF2(le_expression_c, l_exp, r_exp) |
1038 SYM_REF2(ge_expression_c, l_exp, r_exp) |
1051 SYM_REF2(ge_expression_c, l_exp, r_exp) |
1039 SYM_REF2(add_expression_c, l_exp, r_exp) |
1052 SYM_REF2(add_expression_c, l_exp, r_exp, bool deprecated_operation;) |
1040 SYM_REF2(sub_expression_c, l_exp, r_exp) |
1053 SYM_REF2(sub_expression_c, l_exp, r_exp, bool deprecated_operation;) |
1041 SYM_REF2(mul_expression_c, l_exp, r_exp) |
1054 SYM_REF2(mul_expression_c, l_exp, r_exp, bool deprecated_operation;) |
1042 SYM_REF2(div_expression_c, l_exp, r_exp) |
1055 SYM_REF2(div_expression_c, l_exp, r_exp, bool deprecated_operation;) |
1043 SYM_REF2(mod_expression_c, l_exp, r_exp) |
1056 SYM_REF2(mod_expression_c, l_exp, r_exp) |
1044 SYM_REF2(power_expression_c, l_exp, r_exp) |
1057 SYM_REF2(power_expression_c, l_exp, r_exp) |
1045 SYM_REF1(neg_expression_c, exp) |
1058 SYM_REF1(neg_expression_c, exp) |
1046 SYM_REF1(not_expression_c, exp) |
1059 SYM_REF1(not_expression_c, exp) |
1047 |
1060 |
1048 /* formal_param_list -> may be NULL ! */ |
1061 /* formal_param_list -> may be NULL ! */ |
1049 /* nonformal_param_list -> may be NULL ! */ |
1062 /* nonformal_param_list -> may be NULL ! */ |
1050 /* NOTE: The parameters 'called_function_declaration' is used to pass |
1063 /* NOTES: |
1051 * data between the stage 3 and stage 4. |
1064 * The parameter 'called_function_declaration'... |
|
1065 * ...is used to pass data between the stage 3 and stage 4. |
1052 * The IEC 61131-3 standard allows for overloaded standard functions. This means that some |
1066 * The IEC 61131-3 standard allows for overloaded standard functions. This means that some |
1053 * function calls are not compeletely defined by the name of the function being called, |
1067 * function calls are not completely defined by the name of the function being called, |
1054 * and need to be disambiguated with using the data types of the parameters being passed. |
1068 * and need to be disambiguated with using the data types of the parameters being passed. |
1055 * Stage 3 does this to verify semantic correctnes. |
1069 * Stage 3 does this to verify semantic correctness. |
1056 * Stage 4 also needs to do this in order to determine which function to call. |
1070 * Stage 4 also needs to do this in order to determine which function to call. |
1057 * It does not make sense to determine the exact function being called twice (once in stage 3, |
1071 * It does not make sense to determine the exact function being called twice (once in stage 3, |
1058 * and again in stage 4), so stage 3 will store this infor in the parameter called_function_declaration |
1072 * and again in stage 4), so stage 3 will store this info in the parameter called_function_declaration |
1059 * for stage 4 to use it later on. |
1073 * for stage 4 to use it later on. |
1060 */ |
1074 * The parameter 'candidate_functions'... |
1061 SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count;) |
1075 * ...is used to pass data between two passes within stage 3 |
|
1076 * (actually between fill_candidate_datatypes_c and narrow_candidate_datatypes_c). |
|
1077 * It is used to store all the functions that may be legally called with the current parameters |
|
1078 * being used in this function invocation. Note that the standard includes some standard functions |
|
1079 * that have the exact same input parameter types, but return different data types. |
|
1080 * In order to determine which of these functions should be called, we first create a list |
|
1081 * of all possible functions, and then narrow down the list (hopefully down to 1 function) |
|
1082 * once we know the data type that the function invocation must return (this will take into |
|
1083 * account the expression in which the function invocation is inserted/occurs). |
|
1084 * The 'called_function_declaration' will eventually be set (in stage 3) to one of |
|
1085 * the functions in the 'candidate_functions' list! |
|
1086 * The parameter 'extensible_param_count'... |
|
1087 * ...is used to pass data between the stage 3 and stage 4. |
|
1088 * The IEC 61131-3 standard allows for extensible standard functions. This means that some |
|
1089 * standard functions may be called with a variable number of paramters. Stage 3 will store |
|
1090 * in extensible_param_count the number of parameters being passed to the extensible parameter. |
|
1091 */ |
|
1092 SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;) |
1062 |
1093 |
1063 |
1094 |
1064 /********************/ |
1095 /********************/ |
1065 /* B 3.2 Statements */ |
1096 /* B 3.2 Statements */ |
1066 /********************/ |
1097 /********************/ |