Example #1
0
bool
sp_itor_next(sp_itor* itor)
{
    ASSERT(itor != NULL);

    return tree_iterator_next(itor);
}
static bool included_libraries_are_up_to_date (CompileProject *project, Compile *compile)
{
	Compile *library;
	TreeIterator *iterator;
	
	if (!(iterator = tree_iterator_create (compile->libraries))) {
		compile_debug_allocate_memory ();
		return false;
	}
	while (tree_iterator_next (iterator)) {
		if (!(library = tree_search (project->directory_to_compile, iterator->key))) {
			continue;
		}
		if (!library->actions) {
			continue;
		}
		if (list_count (library->actions) != 0) {
			tree_iterator_destroy (iterator);
			compile_print ("The library '%s' is out of date.\n", library->directory->name);
			return false;
		}
	}
	tree_iterator_destroy (iterator);
	return true;
}
static bool recursively_flatten_libraries_inner (CompileProject *project, 
                                                 Compile *compile, 
                                                 Directory *library, 
                                                 Tree *append)
{
	Compile *compile_library;
	TreeIterator *iterator;
	
	if (!(compile_library = tree_search (project->directory_to_compile, (Object *)library))) {
		compile_debug_operation_failed ();
		return false;
	}
	if (!(iterator = tree_iterator_create (compile_library->libraries))) {
		compile_debug_allocate_memory ();
		return false;
	}
	while (tree_iterator_next (iterator)) {
		if (!recursively_flatten_libraries_inner (project, 
                                                          compile, 
                                                          (Directory *)iterator->key, 
                                                          append)) {
			tree_iterator_destroy (iterator);
			return false;
		}
	}
	tree_iterator_destroy (iterator);
	if (!tree_search (compile->libraries, (Object *)library) &&
	    !tree_search (append, (Object *)library)) {
		if (!tree_insert (append, (Object *)library, library)) {
			compile_debug_operation_failed ();
			return false;
		}
	}
	return true;
}
Example #4
0
void free_connection_table(connection_table* ct) {
	if (ct) {
		tree_iterator *it = new_tree_iterator(ct);
		while (tree_iterator_has_next(it)) {
			rt_connection* c = (rt_connection*) tree_iterator_next(it);
			free_rtconnection(c);
		}
		destroy_iterator(it);
		destroy_rbtree(ct);
		ct = NULL;
	}
}
static bool recursively_flatten_libraries (CompileProject *project, Compile *compile)
{
	TreeIterator *iterator;
	Tree *append;

	if (!(append = tree_create ())) {
		compile_debug_allocate_memory ();
		return false;
	}
	if (!(iterator = tree_iterator_create (compile->libraries))) {
		compile_debug_allocate_memory ();
		return false;
	}
	while (tree_iterator_next (iterator)) {
		if (!recursively_flatten_libraries_inner (project, 
                                                          compile, 
                                                          (Directory *)iterator->key, 
                                                          append)) {
			tree_iterator_destroy (iterator);
			tree_destroy (append);
			return false;
		}
	}
	tree_iterator_destroy (iterator);
	if (!(iterator = tree_iterator_create (append))) {
		compile_debug_allocate_memory ();
		return false;
	}
	while (tree_iterator_next (iterator)) {
		if (!tree_insert (compile->libraries, iterator->key, iterator->key)) {
			tree_iterator_destroy (iterator);
			tree_destroy (append);
			compile_debug_operation_failed ();
			return false;
		}
	}
	tree_iterator_destroy (iterator);
	tree_destroy (append);
	return true;
}
bool compile_project_prepare (CompileProject *project)
{
	ListNode *node;
	Directory *sub_directory;
	Compile *compile;
	Compile *sub_compile;
	TreeIterator *iterator;

	if (!project) {
                error (InvalidArgument);
		return false;
	}
	if (!directory_read (project->directory)) {
		compile_print ("Failed to read directory: %s\n", project->directory->name);
                error_code (FunctionCall, 1);
		return false;
	}
	for (node = list_first (project->directory->directories); node; node = list_next (node)) {
		if (!(sub_directory = node->data)) {
                        error_code (InvalidOperation, 1);
			return false;
		}
		if (!string_begins_with (sub_directory->name, "lib.") &&
		    !string_begins_with (sub_directory->name, "app.") &&
                    !string_begins_with (sub_directory->name, "plugin.")) {
			continue;
		}
		if (!(compile = compile_create (project->directory, sub_directory))) {
                        error_code (FunctionCall, 2);
			return false;
		}
		if (!list_append (project->nodes, compile)) {
			compile_destroy (compile);
                        error_code (FunctionCall, 3);
			return false;
		}
		if (!topological_add_vertex (project->topological, (Object *)compile)) {
                        error_code (FunctionCall, 4);
			return false;
		}
		if (!tree_insert (project->directory_to_compile, (Object *)sub_directory, compile)) {
                        error_code (FunctionCall, 5);
			return false;
		}
	}
	for (node = list_first (project->directory->directories); node; node = list_next (node)) {
		if (!(sub_directory = node->data)) {
                        error_code (InvalidOperation, 3);
			return false;
		}
                if (!string_begins_with (sub_directory->name, "lib.") &&
		    !string_begins_with (sub_directory->name, "app.") &&
                    !string_begins_with (sub_directory->name, "plugin.")) {
			continue;
		}
		if (!(compile = tree_search (project->directory_to_compile, 
                                             (Object *)sub_directory))) {
                        error_code (InvalidOperation, 5);
			return false;
		}
		if (!compile_prepare (compile)) {
                        error_code (FunctionCall, 6);
			return false;
		}
		if (!(iterator = tree_iterator_create (compile->libraries))) {
                        error_code (FunctionCall, 7);
			return false;
		}
		while (tree_iterator_next (iterator)) {
			if (string_equals (sub_directory->name, 
                                           ((Directory *)iterator->key)->name)) {
				continue;
			}
			if (!(sub_compile = tree_search (project->directory_to_compile, 
                                                         iterator->key))) {
				tree_iterator_destroy (iterator);
                                error_code (InvalidOperation, 6);
				return false;
			}
			if (!topological_set_edge (project->topological, 
                                                   (Object *)compile, 
                                                   (Object *)sub_compile)) {
				tree_iterator_destroy (iterator);
				error_code (FunctionCall, 8);
				return false;
			}
		}
		tree_iterator_destroy (iterator);
	}
	if (!(project->sorted = topological_sort (project->topological))) {
		compile_print ("Topological sort of project directories failed.\n");
                error_code (InvalidOperation, 7);        
		return false;
	}
	for (node = list_first (project->sorted); node; node = list_next (node)) {
		if (!recursively_flatten_libraries (project, node->data)) {
			return false;
		}
		if (!sort_libraries (project, node->data)) {
			return false;
		}
	}
	for (node = list_last (project->sorted); node; node = list_previous (node)) {
		if (!compile_actions (node->data, project->directory->path)) {
                        error_code (FunctionCall, 9);
			return false;
		}
	}
	return true;
}