Beispiel #1
0
/* ----------------------------------------------------------------------- 
 * Adds an identifier to the end of the identifier_list
 * ----------------------------------------------------------------------- 
 */
void add_to_identifier_list(struct identifier_list_t **il, char *id)
{
  if (*il == NULL) {
    *il = new_identifier_list();
    (*il)->id = id;
  }
  else {
    struct identifier_list_t *temp;
    
    temp = *il;

    GOTO_END_OF_LIST(temp)
    temp->next = new_identifier_list();
    temp->next->id = id;
  }
}
Beispiel #2
0
/* ----------------------------------------------------------------------- 
 * Adds an actual_parameter to the end of the actual_parameter_list
 * ----------------------------------------------------------------------- 
 */
void add_to_actual_parameter_list(struct actual_parameter_list_t **apl,
                                  struct actual_parameter_t *ap)
{
  if (*apl == NULL) {
    *apl = new_actual_parameter_list();
    (*apl)->ap = ap;
  }
  else {
    struct actual_parameter_list_t *temp;

    temp = *apl;

    GOTO_END_OF_LIST(temp)
    temp->next = new_actual_parameter_list();
    temp->next->ap = ap;
  }
}
Beispiel #3
0
/*
 * Inserts the type denoter into the list
 */
struct type_denoter_t *usrdef_insert(struct type_denoter_t *td) {
	// Create head if it does not exist
	if(usrdef_types == NULL) {
		usrdef_types = (struct type_denoter_list_t *) malloc(sizeof(struct type_denoter_list_t));
		usrdef_types->tden = td;
		usrdef_types->next = NULL;
		return usrdef_types->tden;
	} else {
		// Go to the end of the list
		struct type_denoter_list_t *temp_il = usrdef_types;
		GOTO_END_OF_LIST(temp_il);
		// Insert new node at end of list
		temp_il->next = (struct type_denoter_list_t *) malloc(sizeof(struct type_denoter_list_t));
		temp_il->next->tden = td;
		temp_il->next->next = NULL;
		return temp_il->next->tden;
	}
}
Beispiel #4
0
/* ----------------------------------------------------------------------- 
 * Adds a function_declaration to the end of the func_declaration_list
 * ----------------------------------------------------------------------- 
 */
void add_to_func_declaration_list(struct func_declaration_list_t **fdl,
				  struct function_declaration_t *fd)
{
 if (*fdl == NULL) {
    *fdl = new_func_declaration_list();
    (*fdl)->fd = fd;
  }
  else {
    struct func_declaration_list_t *temp;

    temp = *fdl;

    GOTO_END_OF_LIST(temp)

    temp->next = new_func_declaration_list();
    temp->next->fd = fd;
  }
}
Beispiel #5
0
/* ----------------------------------------------------------------------- 
 * Adds a factor to the end of the term
 * ----------------------------------------------------------------------- 
 */
void add_to_term(struct term_t **t, int mulop, struct factor_t *f)
{
 if (*t == NULL) {
    *t = new_term();
    (*t)->f = f;
  }
  else {
    struct term_t *temp;

    temp = *t;

    GOTO_END_OF_LIST(temp)

    temp->next = new_term();
    temp->next->f = f;
    temp->mulop = mulop;
  }
}
Beispiel #6
0
/* ----------------------------------------------------------------------- 
 * Adds a index_expression to the end of the index_expression_list
 * ----------------------------------------------------------------------- 
 */
void add_to_index_expression_list(struct index_expression_list_t **iel,
				  struct expression_t *e)
{
 if (*iel == NULL) {
    *iel = new_index_expression_list();
    (*iel)->e = e;
  }
  else {
    struct index_expression_list_t *temp;

    temp = *iel;

    GOTO_END_OF_LIST(temp)

    temp->next = new_index_expression_list();
    temp->next->e = e;
  }
}
Beispiel #7
0
/* ----------------------------------------------------------------------- 
 * Adds a statement to the end of the statement_sequence
 * ----------------------------------------------------------------------- 
 */
void add_to_statement_sequence(struct statement_sequence_t **ss,
			       struct statement_t *s)
{
 if (*ss == NULL) {
    *ss = new_statement_sequence();
    (*ss)->s = s;
  }
  else {
    struct statement_sequence_t *temp;

    temp = *ss;

    GOTO_END_OF_LIST(temp)

    temp->next = new_statement_sequence();
    temp->next->s = s;
  }
}
Beispiel #8
0
/* ----------------------------------------------------------------------- 
 * Adds a formal_parameter_section to the end of the formal_parameter_section_list
 * ----------------------------------------------------------------------- 
 */
void add_to_formal_parameter_section_list(struct formal_parameter_section_list_t **fpsl,
					  struct formal_parameter_section_t *fps)
{
 if (*fpsl == NULL) {
    *fpsl = new_formal_parameter_section_list();
    (*fpsl)->fps = fps;
  }
  else {
    struct formal_parameter_section_list_t *temp;

    temp = *fpsl;

    GOTO_END_OF_LIST(temp)

    temp->next = new_formal_parameter_section_list();
    temp->next->fps = fps;
  }
}
Beispiel #9
0
/* ----------------------------------------------------------------------- 
 * Adds a variable_declaration to the end of the variable_declaration_list
 * ----------------------------------------------------------------------- 
 */
void add_to_variable_declaration_list(struct variable_declaration_list_t **vdl,
				      struct variable_declaration_t *vd)
{
 if (*vdl == NULL) {
    *vdl = new_variable_declaration_list();
    (*vdl)->vd = vd;
  }
  else {
    struct variable_declaration_list_t *temp;

    temp = *vdl;

    GOTO_END_OF_LIST(temp)

    temp->next = new_variable_declaration_list();
    temp->next->vd = vd;
  }
}
Beispiel #10
0
/* ----------------------------------------------------------------------- 
 * Adds a class_identification and block to the end of the class_list
 * ----------------------------------------------------------------------- 
 */
void add_to_class_list(struct class_list_t **cl, struct class_identification_t *ci, struct class_block_t *cb)
{
  if (*cl == NULL) {
    *cl = new_class_list();
    (*cl)->ci = ci;
    (*cl)->cb = cb;
  }
  else {
    struct class_list_t *temp;
    
    temp = *cl;

    GOTO_END_OF_LIST(temp)
    temp->next = new_class_list();
    temp->next->ci = ci;
    temp->next->cb = cb;
  }
}
Beispiel #11
0
/* ----------------------------------------------------------------------- 
 * Adds a term to the end of the simple_expression
 * ----------------------------------------------------------------------- 
 */
void add_to_simple_expression(struct simple_expression_t **se,
			      int addop,
			      struct term_t *t)
{
 if (*se == NULL) {
    *se = new_simple_expression();
    (*se)->t = t;
  }
  else {
    struct simple_expression_t *temp;

    temp = *se;

    GOTO_END_OF_LIST(temp)

    temp->next = new_simple_expression();
    temp->next->t = t;
    temp->addop = addop;
  }
}
Beispiel #12
0
/*
 * Calculates the offsets for vars in a single scope.  Returns the offset
 * of the last declared var + the sizeof that vars type (the next available offset)
 */
int symtab_calc_scope_offsets(struct scope_t *scope) {

	// If the offsets have already been done, just return the last value
	if(scope->symbol_list != NULL) {
		struct symbol_list_t *end = scope->symbol_list;
		GOTO_END_OF_LIST(end);

		// Figure out the size of this variable
		struct variable_declaration_t *varDecl = symtab_lookup_variable(scope, end->id);
		int size = symtab_calc_td_size(varDecl->tden);

		// Return the sum, which would be the next available offset
		return end->offset + size;
	}

	// For classes, have to check for inheritence and continue offsets where we left off in parent
	if(scope->attrId == SYM_ATTR_CLASS || scope->attrId == SYM_ATTR_FUNC) {
		int off = 0;
		struct variable_declaration_list_t *vdl_it = NULL;
		if(scope->attrId == SYM_ATTR_CLASS) {
			// Determine the start by checking for parent classes
			if(scope->cl->ci->extend != NULL) {
				off = symtab_calc_scope_offsets(scope->parent);
			}

			// Iterate through every variable declared
			vdl_it = scope->cl->cb->vdl;
		} else if(scope->attrId == SYM_ATTR_FUNC) {
			// Calculate offsets for parameters first
			struct formal_parameter_section_list_t *fp_it = scope->fd->fh->fpsl;
			while(fp_it != NULL) {
				int size = symtab_calc_td_size(usrdef_lookup_name(fp_it->fps->id));
				
				// The scope for the type of the declared variable (for objects)
				struct scope_t *objScope = symtab_lookup_class(fp_it->fps->id);
				
				struct identifier_list_t *id_it = fp_it->fps->il;
				while(id_it != NULL) {
					// Add to the offset list
					struct symbol_list_t *addedOffset = add_to_symbol_list(&scope->symbol_list, id_it->id, off);
					// If the scope found above was not null ( meaning it is a pointer ) set the objScope
					if(objScope != NULL) {
						addedOffset->objScope = objScope;
					}
	
					off += size; // Update the offset by the size
	
					id_it = id_it->next;
				}
			
				fp_it = fp_it->next;
			}
		
			vdl_it = scope->fd->fb->vdl;
		}


		while(vdl_it != NULL) {
			// Size of the data structure for the var
			int size = symtab_calc_td_size(vdl_it->vd->tden);

			// The scope for the type of the declared variable (for objects)
			struct scope_t *objScope = symtab_lookup_class(vdl_it->vd->tden->name);

			// Iterate through every identifier in the list
			struct identifier_list_t *il_it = vdl_it->vd->il;
			while(il_it != NULL) {
				// Add to the offset list
				struct symbol_list_t *addedOffset = add_to_symbol_list(&scope->symbol_list, il_it->id, off);
				// If the scope found above was not null ( meaning it is a pointer ) set the objScope
				if(objScope != NULL) {
					addedOffset->objScope = objScope;
				}

				off += size; // Update the start by the size

				il_it = il_it->next;
			}

			vdl_it = vdl_it->next;
		}
		
		// Compiler generated temporaries occupy one WORD each
		struct set_t *set_it = scope->temps;
		while(set_it != NULL) {
			add_to_symbol_list(&scope->symbol_list, set_it->value, off);
			off += SIZE_WORD;
			
			set_it = set_it->next;
		}
 
		return off;

	}
	return 0;
}