ALLOC(5)

Table of Contents

Name

alloc
allocates a node
agmalloc
ivy*meta SDTB version of malloc
agfree
ivy*meta SDTB version of free

Synopsis

ANY alloc(ntype)
TYPE ntype;
char *agmalloc(size)
int size;
VOID agfree(ptr)
char *ptr;

Description

These components of the run-time library provide dynamic memory management features.

The alloc function allocates space and initializes a parse tree or list-structure node of any type. The single argument to alloc is the type index value (of the predefined type TYPE) that specifies what kind of node to create. The type field of the new node is initialized to ntype; all other fields are initialized to NULL. The code that calls alloc must fill in proper values for the fields of the node data structure (see example).

The agmalloc and agfree functions are the ivy*meta SDTB replacements for the standard C library functions malloc and free. Both functions will terminate the SDTool using the standard ivy*meta SDTB error handling routines (see REPORTINFO(5) ) if errors occur.

Note that calls to alloc and agmalloc usually need casting in order to avoid C warning or error messages.

Example

Given the grammar rule:
fentry: ( id:<[A-Z]+> arg+ [ head ] value:INT filename )
then the following C code constructs an FENTRY node: FENTRY a_fentry; /* make a fentry from scratch */ ID an_id;
ARG first, second, lastarg;
HEAD a_head;
an_id = (ID) alloc(Id);
tok(an_id) = «ABC";
first = (ARG) alloc(Arg);
initialize fields of first

second = (ARG) alloc(Arg);
initialize fields of second
lastarg = (ARG) alloc(Arg);
initialize fields of lastarg
a_head = (HEAD) alloc(Head);
initialize fields of a_head
append(second, &first); /* build a list of ARGs */ append(lastarg, &first);
a_fentry = (FENTRY) alloc(Fentry);
tag(a_fentry) = Id;
id(a_fentry) = an_id;
parent(an_id) = (ANY) a_fentry;
arg(a_fentry) = first;
parent(first) = (ANY) a_fentry;
parent(second) = (ANY) a_fentry;
parent(lastarg) = (ANY) a_fentry;
head(a_fentry) = a_head;
parent(a_head) = (ANY) a_fentry;
value(a_fentry) = 19;

See Also

ANY(5)
LIST(5)
REPORTINFO(5)
TOKEN(5)


© 1990 Lucent Technologies, Inc
© 1998 Harmony Software, Inc