Class Table
OExpL compilation requires only one additional data structure - the class table.
The class table stores information pertaining to all the classes declared in an OExpL program. For a class it
stores member fields, member functions, name of the class and parent class pointer.
Structure
The structure of Class Table(CT) is as follows:
✛NOTE:
Memberfield list is used to store the information regarding the type, name, fieldindex and type of class of all the member fields
of that class.
Memberfunc list is used to store the information regarding the type, name of the function, argument list, it's flabel and it's position.
Associated Methods
- struct Classtable* CInstall(char *name,char *parent_class_name) : Creates a class table entry of given 'name' and extends the fields and the methods of parent class and
returns a pointer to the newly created class entry.
- struct Classtable* CLookup(char *name) : Search for a class table entry with the given 'name', if exists, return pointer to class table entry else return NULL.
-
void Class_Finstall(struct Classtable *cptr, char *typename, char *name) : Installs the field into the given class table entry which is given as an argument.
-
void Class_Minstall(struct Classtable *cptr, char *name, struct Typetable *type, struct Paramstruct *Paramlist) : Installs the method into the given class table entry which is given as an argument.
-
struct Memberfunclist* Class_Mlookup (struct Classtable* Ctype,char* Name) : Search through the VFunclist of the class using Ctype that is being parsed and return pointer to the entry in the list with function name as Name. Returns NULL if entry is not found.
-
struct Fieldlist* Class_Flookup(struct Classtable* Ctype,char* Name)) : Search through the Memberfield of the current class using Ctype that is being parsed and return pointer to the entry in the list with variable name as Name. Returns NULL if entry is not found.
Illustration
Here is an example illustrating it.
- As soon as the compiler encounters the class name, it installs the class name and the parent class name if present into the class table.
Subsequently, If there is an extension to the parent class, all the member fields and methods of parent class are inherited. Following is how class table looks when class Person is installed.
-
Following is how class table looks when class Student is installed.