stage3/narrow_candidate_datatypes.cc
changeset 834 783ef40344dd
parent 827 e3800aff352c
child 836 149398f525a7
equal deleted inserted replaced
833:27f246b35ac2 834:783ef40344dd
   320  */
   320  */
   321 void *narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
   321 void *narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
   322 
   322 
   323 	/* set the datatype of the il_operand, this is, the FB being called! */
   323 	/* set the datatype of the il_operand, this is, the FB being called! */
   324 	if (NULL != il_operand) {
   324 	if (NULL != il_operand) {
   325 		/* only set it if it is in the candidate datatypes list! */  
   325 		set_datatype(called_fb_declaration, il_operand); /* only set it if it is in the candidate datatypes list! */  
   326 		set_datatype(called_fb_declaration, il_operand);
       
   327 		il_operand->accept(*this);
   326 		il_operand->accept(*this);
   328 	}
   327 	}
   329 	symbol_c *fb_decl = il_operand->datatype;
       
   330 
   328 
   331 	if (0 == fake_prev_il_instruction->prev_il_instruction.size()) {
   329 	if (0 == fake_prev_il_instruction->prev_il_instruction.size()) {
   332 		/* This IL implicit FB call (e.g. CLK ton_var) is not preceded by another IL instruction
   330 		/* This IL implicit FB call (e.g. CLK ton_var) is not preceded by another IL instruction
   333 		 * (or list of instructions) that will set the IL current/default value.
   331 		 * (or list of instructions) that will set the IL current/default value.
   334 		 * We cannot proceed verifying type compatibility of something that does not exist.
   332 		 * We cannot proceed verifying type compatibility of something that does not exist.
   335 		 */
   333 		 */
   336 		return NULL;
   334 		return NULL;
   337 	}
   335 	}
   338 
   336 
       
   337 	symbol_c *fb_decl = (NULL == il_operand)? NULL : il_operand->datatype;
       
   338 	
   339 	if (NULL == fb_decl) {
   339 	if (NULL == fb_decl) {
   340 		/* the il_operand is a not FB instance */
   340 		/* the il_operand is a not FB instance, or it simply does not even exist, */
   341 		/* so we simply pass on the required datatype to the prev_il_instructions */
   341 		/* so we simply pass on the required datatype to the prev_il_instructions */
   342 		/* The invalid FB invocation will be caught in the print_datatypes_error_c by analysing NULL value in il_operand->datatype! */
   342 		/* The invalid FB invocation will be caught in the print_datatypes_error_c by analysing NULL value in il_operand->datatype! */
   343 		set_datatype_in_prev_il_instructions(il_instruction->datatype, fake_prev_il_instruction);
   343 		set_datatype_in_prev_il_instructions(il_instruction->datatype, fake_prev_il_instruction);
   344 		return NULL;
   344 		return NULL;
   345 	}
   345 	}
   997  * | il_call_operator prev_declared_fb_name '(' ')'
   997  * | il_call_operator prev_declared_fb_name '(' ')'
   998  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
   998  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
   999  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
   999  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  1000  * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  1000  * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  1001  */
  1001  */
  1002 /* 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 */
  1002 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 */
  1003 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
  1003 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
  1004 void *narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1004 void *narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1005 	symbol_c *fb_decl = symbol->called_fb_declaration;
  1005 	symbol_c *fb_decl = symbol->called_fb_declaration;
  1006 	
  1006 	
  1007 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1007 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1091 		return NULL;
  1091 		return NULL;
  1092 
  1092 
  1093         if (NULL != deprecated_operation)
  1093         if (NULL != deprecated_operation)
  1094 		*deprecated_operation = false;
  1094 		*deprecated_operation = false;
  1095 
  1095 
  1096 	/* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
  1096 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
       
  1097 
       
  1098 	 /* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
  1097 	 * e.g.  LD 33
  1099 	 * e.g.  LD 33
  1098 	 *       AND ( 45
  1100 	 *       AND ( 45
  1099 	 *            OR 56
  1101 	 *            OR 56
  1100 	 *            )
  1102 	 *            )
  1101 	 *       When we handle the first 'AND' IL_operator, the il_operand will point to an simple_instr_list_c.
  1103 	 *       When we handle the first 'AND' IL_operator, the il_operand will point to an simple_instr_list_c.
  1134 
  1136 
  1135 
  1137 
  1136 
  1138 
  1137 
  1139 
  1138 void *narrow_candidate_datatypes_c::handle_il_instruction(symbol_c *symbol) {
  1140 void *narrow_candidate_datatypes_c::handle_il_instruction(symbol_c *symbol) {
  1139 	if (NULL == symbol->datatype)
  1141 	if (NULL == symbol->datatype) return NULL; /* next IL instructions were unable to determine the datatype this instruction should produce */
  1140 		/* next IL instructions were unable to determine the datatype this instruction should produce */
  1142   
  1141 		return NULL;
       
  1142 	/* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
  1143 	/* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
  1143 	 * e.g.  LD 33
  1144 	 * e.g.  LD 33
  1144 	 *       AND ( 45
  1145 	 *       AND ( 45
  1145 	 *            OR 56
  1146 	 *            OR 56
  1146 	 *            )
  1147 	 *            )
  1156 	 */
  1157 	 */
  1157 	/* set the desired datatype of the previous il instruction */
  1158 	/* set the desired datatype of the previous il instruction */
  1158 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1159 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1159 	  
  1160 	  
  1160 	/* set the datatype for the operand */
  1161 	/* set the datatype for the operand */
       
  1162 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
  1161 	il_operand->datatype = symbol->datatype;
  1163 	il_operand->datatype = symbol->datatype;
  1162 	il_operand->accept(*this);
  1164 	il_operand->accept(*this);
  1163 	return NULL;
  1165 	return NULL;
  1164 }
  1166 }
  1165 
  1167 
  1166 
  1168 
  1167 
  1169 
  1168 
  1170 
  1169 void *narrow_candidate_datatypes_c::visit(LD_operator_c *symbol)   {
  1171 void *narrow_candidate_datatypes_c::visit(LD_operator_c *symbol)   {
  1170 	if (NULL == symbol->datatype)
  1172 	if (NULL == symbol->datatype) return NULL; /* next IL instructions were unable to determine the datatype this instruction should produce */
  1171 		/* next IL instructions were unable to determine the datatype this instruction should produce */
  1173 
  1172 		return NULL;
       
  1173 	/* set the datatype for the operand */
  1174 	/* set the datatype for the operand */
       
  1175 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
  1174 	il_operand->datatype = symbol->datatype;
  1176 	il_operand->datatype = symbol->datatype;
  1175 	il_operand->accept(*this);
  1177 	il_operand->accept(*this);
  1176 	return NULL;
  1178 	return NULL;
  1177 }
  1179 }
  1178 
  1180 
  1179 
  1181 
  1180 void *narrow_candidate_datatypes_c::visit(LDN_operator_c *symbol)  {
  1182 void *narrow_candidate_datatypes_c::visit(LDN_operator_c *symbol)  {
  1181 	if (NULL == symbol->datatype)
  1183 	if (NULL == symbol->datatype) return NULL; /* next IL instructions were unable to determine the datatype this instruction should produce */
  1182 		/* next IL instructions were unable to determine the datatype this instruction should produce */
  1184 
  1183 		return NULL;
       
  1184 	/* set the datatype for the operand */
  1185 	/* set the datatype for the operand */
       
  1186 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
  1185 	il_operand->datatype = symbol->datatype;
  1187 	il_operand->datatype = symbol->datatype;
  1186 	il_operand->accept(*this);
  1188 	il_operand->accept(*this);
  1187 	return NULL;
  1189 	return NULL;
  1188 }
  1190 }
  1189 
  1191 
  1190 void *narrow_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1192 void *narrow_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1191 	if (symbol->candidate_datatypes.size() != 1)
  1193 	if (symbol->candidate_datatypes.size() != 1)
  1192 		return NULL;
  1194 		return NULL;
       
  1195 
  1193 	symbol->datatype = symbol->candidate_datatypes[0];
  1196 	symbol->datatype = symbol->candidate_datatypes[0];
  1194 	/* set the datatype for the operand */
       
  1195 	il_operand->datatype = symbol->datatype;
       
  1196 	il_operand->accept(*this);
       
  1197 	/* set the desired datatype of the previous il instruction */
  1197 	/* set the desired datatype of the previous il instruction */
  1198 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1198 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1199 	/* In the case of the ST operator, we must set the datatype of the il_instruction_c object that points to this ST_operator_c ourselves,
  1199 	/* In the case of the ST operator, we must set the datatype of the il_instruction_c object that points to this ST_operator_c ourselves,
  1200 	 * since the following il_instruction_c objects have not done it, as is normal/standard for other instructions!
  1200 	 * since the following il_instruction_c objects have not done it, as is normal/standard for other instructions!
  1201 	 */
  1201 	 */
  1202 	current_il_instruction->datatype = symbol->datatype;
  1202 	current_il_instruction->datatype = symbol->datatype;
       
  1203 	
       
  1204 	/* set the datatype for the operand */
       
  1205 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
       
  1206 	il_operand->datatype = symbol->datatype;
       
  1207 	il_operand->accept(*this);
       
  1208 
  1203 	return NULL;
  1209 	return NULL;
  1204 }
  1210 }
  1205 
  1211 
  1206 void *narrow_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1212 void *narrow_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1207 	if (symbol->candidate_datatypes.size() != 1)
  1213 	if (symbol->candidate_datatypes.size() != 1)
  1208 		return NULL;
  1214 		return NULL;
       
  1215 	
  1209 	symbol->datatype = symbol->candidate_datatypes[0];
  1216 	symbol->datatype = symbol->candidate_datatypes[0];
       
  1217 	/* set the desired datatype of the previous il instruction */
       
  1218 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
       
  1219 	/* In the case of the ST operator, we must set the datatype of the il_instruction_c object that points to this ST_operator_c ourselves,
       
  1220 	 * since the following il_instruction_c objects have not done it, as is normal/standard for other instructions!
       
  1221 	 */
       
  1222 	current_il_instruction->datatype = symbol->datatype;
       
  1223 
  1210 	/* set the datatype for the operand */
  1224 	/* set the datatype for the operand */
       
  1225 	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
  1211 	il_operand->datatype = symbol->datatype;
  1226 	il_operand->datatype = symbol->datatype;
  1212 	il_operand->accept(*this);
  1227 	il_operand->accept(*this);
  1213 	/* set the desired datatype of the previous il instruction */
       
  1214 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
       
  1215 	return NULL;
  1228 	return NULL;
  1216 }
  1229 }
  1217 
  1230 
  1218 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
  1231 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
  1219 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
  1232 	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
  1220 	 *              NOT [<il_operand>]
  1233 	 *              NOT [<il_operand>]
  1221 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
  1234 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
  1222 	 *       We therefore consider it an error if an il_operand is specified!
  1235 	 *       We therefore consider it an error if an il_operand is specified!
  1223 	 */
  1236 	 *       This error will be detected in print_datatypes_error_c!!
  1224 	/* We do not change the data type, we simply invert the bits in bit types! */
  1237 	 */
       
  1238 	/* This operator does not change the data type, it simply inverts the bits in the ANT_BIT data types! */
  1225 	/* So, we set the desired datatype of the previous il instruction */
  1239 	/* So, we set the desired datatype of the previous il instruction */
  1226 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1240 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
  1227 	return NULL;
  1241 	return NULL;
  1228 }
  1242 }
  1229 
  1243 
  1230 void *narrow_candidate_datatypes_c::visit(S_operator_c *symbol)  {
  1244 void *narrow_candidate_datatypes_c::visit(S_operator_c *symbol)  {
  1231   /* TODO: what if this is a FB call? */
  1245 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return narrow_implicit_il_fb_call(symbol, "S",  symbol->called_fb_declaration); 
  1232 	return handle_il_instruction(symbol);
  1246 	else                                       /* Reset   semantics */  return handle_il_instruction(symbol);
  1233 }
  1247 }
       
  1248 
  1234 void *narrow_candidate_datatypes_c::visit(R_operator_c *symbol)  {
  1249 void *narrow_candidate_datatypes_c::visit(R_operator_c *symbol)  {
  1235   /* TODO: what if this is a FB call? */
  1250 	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return narrow_implicit_il_fb_call(symbol, "R",  symbol->called_fb_declaration); 
  1236 	return handle_il_instruction(symbol);
  1251 	else                                       /* Reset   semantics */  return handle_il_instruction(symbol);
  1237 }
  1252 }
  1238 
       
  1239 
  1253 
  1240 void *narrow_candidate_datatypes_c::visit(  S1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "S1",  symbol->called_fb_declaration);}
  1254 void *narrow_candidate_datatypes_c::visit(  S1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "S1",  symbol->called_fb_declaration);}
  1241 void *narrow_candidate_datatypes_c::visit(  R1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "R1",  symbol->called_fb_declaration);}
  1255 void *narrow_candidate_datatypes_c::visit(  R1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "R1",  symbol->called_fb_declaration);}
  1242 void *narrow_candidate_datatypes_c::visit( CLK_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
  1256 void *narrow_candidate_datatypes_c::visit( CLK_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
  1243 void *narrow_candidate_datatypes_c::visit(  CU_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CU",  symbol->called_fb_declaration);}
  1257 void *narrow_candidate_datatypes_c::visit(  CU_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CU",  symbol->called_fb_declaration);}