Exemplo n.º 1
0
static void process_record_string(FILE *file, struct strings *strings)
{
	assert(file);
	assert(strings);

	strings_add(strings, string_read(file));
}
Exemplo n.º 2
0
int bind_constant ( node_t *root, int stackOffset)
{
    if(outputStage == 6)
        fprintf(stderr, "CONSTANT\n");

    if(root->data_type.base_type == STRING_TYPE)
    	root->string_index = strings_add(root->string_const);
    return 0;
}
Exemplo n.º 3
0
uint deps_add_evr(struct deps *deps, const char *name, int flags, uint epoch,
		const char *version, const char *release) {
	uint i, iter = 0, hash, size = array_get_size(&deps->names), ver, rel, nam;

	nam = strings_add(deps->strings, name);
	ver = strings_add(deps->strings, version != NULL ? version : "");
	rel = strings_add(deps->strings, release != NULL ? release : "");

	if (hashtable_resize(&deps->hashtable)) {
		for (i = 0; i < size; i++) {
			hash = dephash(array_get(&deps->names, i));
			hashtable_add(&deps->hashtable, i, hash);
		}
	}

	hash = dephash(nam);

	while ((i = hashtable_find(&deps->hashtable, hash, &iter)) != -1)
		if (array_get(&deps->names, i) == nam &&
				array_get(&deps->epochs, i) == epoch &&
				array_get(&deps->vers, i) == ver &&
				array_get(&deps->rels, i) == rel &&
				array_get(&deps->flags, i) == flags)
			break;
	if (i != -1)
		/* already stored */
		return i;

	i = size;
	array_set(&deps->names, i, nam);
	array_set(&deps->epochs, i, epoch);
	array_set(&deps->vers, i, ver);
	array_set(&deps->rels, i, rel);
	array_set(&deps->flags, i, flags);
	hashtable_add_dir(&deps->hashtable, i, hash, iter);

	return i;
}
Exemplo n.º 4
0
void 
recurse_tree(node_t* root){
if(root == NULL) return;
    if(root->type.index == DECLARATION){
        declare_tree(root);
    }else if(root->type.index == BLOCK){
        next_stack_offset = -4; 
        scope_add();
    }else if(root->type.index == FUNCTION){
        next_stack_offset = -4;
        scope_add();
        //function is defined already, but not the parameters.
        define_parameters(root);
    }else if(root->type.index == EXPRESSION
          || root->type.index == ASSIGNMENT_STATEMENT){
        for(int i = 0; i< root->n_children;i++){
            node_t* child = root->children[i];
            if(child == NULL) continue;
            if(child->type.index == VARIABLE){
                symbol_t* symbol = symbol_get((char*)child->data);
                root->entry = symbol;
            }
        }
    }else if(root->type.index == TEXT){
        char* text = (char*) root->data;

        //For future ease of use, I will not store 
        //the index directly in the pointer.
        int32_t* intpoint = malloc(sizeof(int32_t));
        *intpoint = strings_add(text); 
        //Store the string index instead of the string
        root->data = intpoint;
    }

    for(int i = 0; i < root->n_children; i++){
        node_t* child = root->children[i];
        recurse_tree(child); 
    }

    if(root->type.index == BLOCK
    || root->type.index == FUNCTION){
        scope_remove();
    }
}
Exemplo n.º 5
0
//Adds string to the string list.
void string (node_t *node) {
	char* str = (char*)node->data;
	node->data = (void*)malloc(sizeof(int));
	*((int*)(node->data)) = strings_add(str);
}
Exemplo n.º 6
0
void bind_names ( node_t* root )
{
    /* TODO: bind tree nodes to symtab entries */

	node_t* child;
	if(root != NULL) {
		for(int i = 0; i < root->n_children; i++) {
			child = root->children[i];

            int counter = 0;

            if(child == NULL)
                continue; // move along, nothing to see here

			switch(child->type.index) {
                case FUNCTION_LIST:
                    // add an upper scope to hold the functions (can functions be defined in a function?)
                    // need this so that the scope in another function can know about all the other functions that are defined.
                    scope_add();
                    for(int i = 0; i < child->n_children; i++) {
                        // populate symbol table with known functions
                        add_functions(child->children[i]);
                    }
                    bind_names(child);
                    scope_remove();
                    break;

                case FUNCTION: ;
                    /* reset depth, reset offset, add arguments */
                    dybde = 0;
                    local_offset = -4;
                    scope_add();

                    // add vars in the var list under (arguments)
                    node_t* varlist = child->children[1];
                    if( varlist != NULL) {
                        int count = 8+(4*(varlist->n_children-1));
                        for( int i = 0; i < varlist->n_children; i++ ) {
                            char* key = varlist->children[i]->data;

                            symbol_t* s = malloc(sizeof(symbol_t));
                            s->stack_offset = count;
                            count -= 4;
                            s->n_args = 0;
                            s->depth = dybde;
                            s->label = key;

                            symbol_insert( key, s );
                        }
                    }

                    // traverse child 2 ( a BLOCK )
                    bind_names(child->children[2]);
                    scope_remove();
                    break;

                case BLOCK: ;
                    /* start new scope, add depth */
					scope_add();
                    dybde++;
                    local_offset = -4;
					bind_names( child );
					dybde--;
					scope_remove();
					break;

                case DECLARATION_LIST: ;
					for( int dec = 0; dec < child->n_children; dec++) {
						node_t* declaration = child->children[dec];
						// add vars in the var list under
						node_t* varlist = declaration->children[0];

                        for( int i = 0; i < varlist->n_children; i++ ) {
                            char* key = varlist->children[i]->data;

							symbol_t* s = malloc(sizeof(symbol_t));
                            s->stack_offset = local_offset;
                            local_offset -= 4;
							s->n_args = 0;
							s->depth = dybde;
							s->label = key;

							symbol_insert( key, s );
						}
					}
                    //return; // safe to return now ?
                    //bind_names(child); // not needed?
					break;

                case VARIABLE: ;
                    char* key = child->data;
                    symbol_t* temp = NULL;
                    symbol_get( &temp, key );
                    if( temp != NULL ) {
                        child->entry = temp;
                    } else { // symbol not yet declared, do some error ?
                        fprintf( stderr, "Error: Symbol \"%s\" not yet declared\n", key );
                    }
					bind_names( child );
					break;
                case TEXT: ;
					/* set data to index in the table of strings */
                    uint32_t* index = malloc(sizeof(uint32_t));
                    *index = strings_add(child->data);
                    child->data = index;
                    break;

                default: ;
					bind_names( child );
			}
		}
	}	
}
Exemplo n.º 7
0
Arquivo: tree.c Projeto: sondrele/NTNU
void add_text ( node_t *text_n ) {
	int *str_ptr = malloc ( sizeof(int *) );
	*str_ptr = strings_add ( (char *) text_n->data );
	text_n->data = str_ptr;
}