//check parametertypes of funcall and give type of function to info_type node *CTfuncall(node *arg_node, info *arg_info){ DBUG_ENTER("CTfuncall"); //check parameter types, if there are any if(FUNCALL_ARGS(arg_node)!=NULL){ node *args = FUNCALL_ARGS(arg_node); //check param type against expression type node * param = FUNDEF_PARAMS(FSYMBOL_FUNCTION(FUNCALL_DECL(arg_node))); EXPRS_EXPRS(args) = TRAVdo(EXPRS_EXPRS(args), arg_info); type exprtype = INFO_TYPE(arg_info); type paramtype = PARAM_TYPE(param); if(exprtype != paramtype){ CTIerrorLine(NODE_LINE(arg_node), "argument type does not match function definition"); } //keep checking till there are no parameters left while(EXPRS_NEXT(args)!=NULL){ args = EXPRS_NEXT(args); param = PARAM_NEXT(param); EXPRS_EXPRS(args) = TRAVdo(EXPRS_EXPRS(args), arg_info); exprtype = INFO_TYPE(arg_info); paramtype = PARAM_TYPE(param); if(exprtype != paramtype){ CTIerrorLine(NODE_LINE(arg_node), "argument type does not match function definition"); } } } //set info_type to return type of the function INFO_TYPE(arg_info) = FUNDEF_TYPE(FSYMBOL_FUNCTION(FUNCALL_DECL(arg_node))); DBUG_RETURN(arg_node); }
/** <!--******************************************************************--> * * @fn CHKMparam * * @brief Touched the node and its sons/attributes * * @param arg_node Param node to process * @param arg_info pointer to info structure * * @return processed node * ***************************************************************************/ node * CHKMparam (node * arg_node, info * arg_info) { DBUG_ENTER ("CHKMparam"); NODE_ERROR (arg_node) = CHKMTRAV (NODE_ERROR (arg_node), arg_info); PARAM_TYPE (arg_node) = CHKMTRAV (PARAM_TYPE (arg_node), arg_info); PARAM_VAR (arg_node) = CHKMTRAV (PARAM_VAR (arg_node), arg_info); DBUG_RETURN (arg_node); }
/** <!--******************************************************************--> * * @fn COPYparam * * @brief Copies the node and its sons/attributes * * @param arg_node Param node to process * @param arg_info pointer to info structure * * @return processed node * ***************************************************************************/ node * COPYparam (node * arg_node, info * arg_info) { node *result = TBmakeParam (NULL, NULL); DBUG_ENTER ("COPYparam"); LUTinsertIntoLutP (INFO_LUT (arg_info), arg_node, result); /* Copy sons */ PARAM_TYPE (result) = COPYTRAV (PARAM_TYPE (arg_node), arg_info); PARAM_VAR (result) = COPYTRAV (PARAM_VAR (arg_node), arg_info); /* Return value */ DBUG_RETURN (result); }
int get_param(int param_nb, t_vm *data, t_proc *process) { int param_value; if (PARAM_TYPE(param_nb) == REG_CODE && is_reg(process, param_nb)) param_value = REG(param_nb); else if (PARAM_TYPE(param_nb) == DIR_CODE) param_value = PARAM(param_nb); else if (PARAM_TYPE(param_nb) == IND_CODE) param_value = ft_ramcpy(data, 4, PC + PARAM(param_nb)); else return (ERR_CODE_PARAM); return (param_value); }
/* * status_packet - process status packet, return 0 on success processing, -1 on error * @inpack: received packet * @outpack:response packet * @sockfd: the socket that receive packet */ int status_packet(struct packet *inpack, struct packet *outpack, int sockfd) { uint16_t num; assert(inpack && outpack); stat_dbg("Status_packet: processing packet --->\n"); switch (inpack->cmd) { case CMD_STATUS_CHANGE: //status chage request stat_dbg("STATUS_CHANGE type: uin %d, stat: %d port %d\n", *PARAM_UIN(inpack), \ *PARAM_TYPE(inpack), *PARAM_PORT(inpack)); if (set_status(*PARAM_UIN(inpack), *PARAM_IP(inpack), *PARAM_PORT(inpack), \ *PARAM_TYPE(inpack))) return -1; fill_packet_header(outpack, PACKET_HEADER_LEN, REP_STATUS_CHANGED, \ *PARAM_UIN(inpack)); break; case CMD_GET_STATUS: //user status request *PARAM_UIN(outpack) = *PARAM_UIN(inpack); if (get_status(*PARAM_UIN(inpack), PARAM_IP(outpack), PARAM_PORT(outpack), \ PARAM_TYPE(outpack))) return -1; stat_dbg("GET_STATUS: uin %d, stat %d port %d\n", *PARAM_UIN(inpack), \ *PARAM_TYPE(outpack), *PARAM_PORT(outpack)); fill_packet_header(outpack, PACKET_HEADER_LEN+12, REP_STATUS, inpack->uin); break; case CMD_MULTI_STATUS: //multi-user status request num = *(uint16_t *)inpack->params; stat_dbg("%d uins to got status\n", num); *(uint16_t *)outpack->params = num; fill_packet_header(outpack, PACKET_HEADER_LEN + 2 + num * 6, \ REP_MULTI_STATUS, inpack->uin); get_multi_status((uint32_t *)(inpack->params + 2), num, \ (struct user_status *)(outpack->params + 2)); break; default: return -1; } /* send back response packet */ write(sockfd, outpack, outpack->len); return 0; }
int get_param_long(t_vm *data, t_proc *process, int param, int *val) { if (PARAM_TYPE(param) == REG_CODE) { if (is_reg(process, param)) *val = REG(param); else return (0); } else if (process->arg_type[param] == DIR_CODE) *val = PARAM(param); else *val = ft_ramcpy(data, 4, (process->pc + process->av[param])); return (1); }