forked from eugenechevski/CodeGeneratorSPL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid_use.c
More file actions
executable file
·47 lines (43 loc) · 1.52 KB
/
id_use.c
File metadata and controls
executable file
·47 lines (43 loc) · 1.52 KB
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
/* $Id: id_use.c,v 1.10 2024/10/23 13:13:07 leavens Exp $ */
#include <stdlib.h>
#include "machine_types.h"
#include "id_use.h"
#include "utilities.h"
// Requires: attrs != NULL
// Return a (pointer to a fresh) id_use struct containing the attributes
// given by attrs and the information about the number of lexical levels
// outward from the current scope where the declaration was found.
// If there is no space, bail with an error message,
// so this should never return NULL.
extern id_use *id_use_create(id_attrs *attrs, unsigned int levelsOut)
{
id_use *ret = (id_use *)malloc(sizeof(id_use));
if (ret == NULL) {
bail_with_error("No space to allocate id_use!");
}
ret->attrs = attrs;
ret->levelsOutward = levelsOut;
// Shouldn't create a label for procedures here!
// A label should only be created when creating the proc_decl's AST!
return ret;
}
// Requires: idu != NULL
// Return a pointer to the attributes of this id_use
// and the result will never be NULL
id_attrs *id_use_get_attrs(id_use *idu)
{
assert(idu != NULL);
return idu->attrs;
}
// Requires: idu != NULL
// Return (a pointer to) the lexical address for idu.
lexical_address *id_use_2_lexical_address(id_use *idu)
{
lexical_address *ret = (lexical_address *)malloc(sizeof(lexical_address));
if (ret == NULL) {
bail_with_error("No space to allocate lexical_address!");
}
ret->levelsOutward = idu->levelsOutward;
ret->offsetInAR = idu->attrs->offset_count;
return ret;
}