No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tab_fonctions.c 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "tab_fonctions.h"
  2. #define MAX_TAILLE_FONC 50
  3. // Table des fonctions
  4. struct fonction_t tab_fonctions[MAX_TAILLE_FONC];
  5. // Index dispo dans la table
  6. int indexTab = 0;
  7. // Renvoi une fonction a partir de son nom
  8. struct fonction_t get_fonction(char * name){
  9. int not_found = 1;
  10. int i = 0;
  11. struct fonction_t res;
  12. while (not_found && (i <= indexTab)){
  13. if (!strcmp(name,tab_fonctions[i].name)){
  14. res = tab_fonctions[i];
  15. not_found = 0;
  16. }
  17. i++;
  18. }
  19. return res;
  20. }
  21. // Insere une fonction
  22. void push_fonction(char * name, struct type_t type, int line, int taille_args){
  23. if (indexTab < MAX_TAILLE_FONC){
  24. struct fonction_t fonc;
  25. fonc.name = malloc(sizeof(char)*50);
  26. strcpy(fonc.name,name);
  27. fonc.return_type = type;
  28. fonc.first_instruction_line = line;
  29. fonc.taille_args = taille_args;
  30. tab_fonctions[indexTab] = fonc;
  31. indexTab++;
  32. }
  33. }
  34. // Fonction d'affichage des fonctions connues
  35. void print_fonctions(){
  36. printf("Affichage table des fonctions\n");
  37. printf("\t Size : %d\n",indexTab);
  38. printf("\t Contenu : \n");
  39. for (int i =0; i<indexTab; i++){
  40. printf("\t\t{Fonction : %s returns %s and starts at line %d and its args have a size of %d}\n",tab_fonctions[i].name, type_to_string(tab_fonctions[i].return_type), tab_fonctions[i].first_instruction_line, tab_fonctions[i].taille_args);
  41. }
  42. }