summaryrefslogtreecommitdiff
path: root/misc-test/compilateur_c_en_c/table_sym.c
blob: 9fa3803d84756aab8553357f2518cc8e76746bbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "table_sym.h"

void symbolPush(symbolStack *symStack, struct symbolEntry *sym)
{
	struct symbolStackCell *newCell = malloc(sizeof(struct symbolStackCell));
	newCell->symbol = sym;
	newCell->next = *symStack;
	*symStack=newCell;
}

struct symbolEntry * symbolFind(symbolStack symStack, char *symName, int contextMinProf, int contextMaxProf)
{
	struct symbolEntry *res = NULL;
	int trouve = 0;
	while (!trouve && symStack != NULL)
	{
		if ( strcmp(symStack->symbol->symName,symName) == 0 
				&& symStack->symbol->contextProf >= contextMinProf
				&& symStack->symbol->contextProf <= contextMaxProf )
		{
			trouve=1;
			res=symStack->symbol;
		} else {
			symStack=symStack->next;
		}
	}
	return res;
}

void printSymTable(symbolStack symStack)
{
	printf("DEBUG :Table des symboles\n");
	printf("const?\t        nom variable\taddress\tinit?\tcontextProf\n");
	for(;symStack!=NULL;symStack=symStack->next)
	{
		if ( symStack->symbol->readOnly )
		{
			printf("const\t%20s\t%x\t%i\t%i\n",	symStack->symbol->symName,
								symStack->symbol->address,
								symStack->symbol->initialized,
								symStack->symbol->contextProf);
		} else {
			printf("\t%20s\t%x\t%i\t%i\n",		symStack->symbol->symName,
								symStack->symbol->address,
								symStack->symbol->initialized,
								symStack->symbol->contextProf);
		}
	}

	printf("FIN DEBUG\n");
}

void cleanSymStack(symbolStack *symStack, int contextProf)
{
	printf("void cleanSymStack(symbolStack *symStack, %i)\n", contextProf);
	while ((*symStack)!=NULL && ((*symStack)->symbol->contextProf > contextProf))
	{
		symbolStack next = (*symStack)->next;

		free( (*symStack)->symbol->symName );
		free( (*symStack)->symbol );
		free( (*symStack) );
		
		*symStack = next;
	}
}