/* corrige un prototype Si le type de la fonction manque, ajoute int Si le type d'un des arguments manque, ajoute int */ #include #include "assert.h" #include #include "proto.h" /* Corrige certain detail dans un prototype moderne Si la fonction n'a pas de type, ajoute int Si un parametre n'a pas de type, ajoute int (seulement pour K&R) Si la fonction n'a pas de parametre, ajoute void Copie le commentaire du token next (OPN_BRACE) dans le dernier token du prototype */ void cproto_patch ( TOKEN_LIST *tokl, TOKEN *next, /* Prochain token après la déclaration */ /* Ce token contient peut-être un commentaire */ /* qu'il faudra */ /* associé au denier token de la déclaration */ int ret_fct, /* C'est un fonction qui retourne un pointeur */ /* de fonction */ int operator_fct, /* fonction de type operator() (...) */ /* Il faut ignorer un groupe de () */ int isold) /* Déclaration K&R */ { int nbtok=0; TOKEN *token; TOKEN tokint; TOKEN *token1; int nbavant = ret_fct ? 1 : 2; token_make (&tokint,"int"); /* Ajoute le int a la declaration de la fonction */ tokrec_inilec (tokl); token1 = tokrec_get(tokl); do { token=tokrec_get(tokl); assert (token!=NULL); nbtok++; if (token->type == TOK_OPNPAR){ if (nbtok == nbavant){ tokint.comment = token1->comment; token1->comment = NULL; tokrec_recule (tokl); tokrec_insert (tokl,&tokint); tokint.comment = NULL; } break; } }while (tokrec_next (tokl)!=-1); /* Ajoute le int au parametres */ tokrec_inilec (tokl); if (cproto_findpar(tokl,operator_fct ? 1 : 0)!=-1){ int ok = 0; if (ret_fct){ ok=tokrec_descend(tokl); if (ok != -1) ok = cproto_findpar (tokl,0); } if (ok != -1){ int ok=tokrec_descend(tokl); TOKEN tokvoid; token_make (&tokvoid,"void"); assert (ok!=-1); nbtok = 0; do{ token = tokrec_get (tokl); if (token->type == TOK_KEYWORD) nbtok=2; if (token->type == TOK_DOT3) nbtok=2; if (nbtok == 0){ if (token->type == TOK_OPNPAR){ /* argument => pointeur de fonction */ tokrec_insert(tokl,&tokint); tokrec_next(tokl); }else if (token->type == TOK_CLSPAR){ tokrec_insert (tokl,&tokvoid); tokrec_next (tokl); } }else if(nbtok == 1 && (token->type == TOK_VIRGULE || token->type == TOK_CLSPAR)){ if (isold){ tokrec_recule(tokl); tokrec_insert(tokl,&tokint); tokrec_next(tokl); tokrec_next(tokl); } } nbtok++; if (token->type == TOK_VIRGULE) nbtok = 0; }while (tokrec_next(tokl)!=-1); } } if (next->comment != NULL){ token->comment = next->comment; next->comment = NULL; } }