コード例 #1
0
ファイル: graphcut.c プロジェクト: MaChao5/pdfviewer-win32
static void combust_tree(graphcut_workspace_t*w, posqueue_t*q1, posqueue_t*q2, path_t*path)
{
    graph_t*graph = w->graph;
    int t;
    for(t=0;t<path->length-1 && path->firsthalf[t+1];t++) {
        node_t*pos = path->pos[t];
	halfedge_t*dir = path->dir[t];
        node_t*newpos = dir->fwd->node;
        if(!dir->weight) {
            /* disconnect node */
            DBG printf("remove link %d -> %d from tree 1\n", NR(pos), NR(newpos));
	   
	    dir->used = 0;
            w->flags1[NR(newpos)] &= ACTIVE;
            bool_op(w, w->flags1, newpos, ~IN_TREE, 0);

            /* try to reconnect the path to some other tree part */
            if(reconnect(w, w->flags1, newpos, 0)) {
                bool_op(w, w->flags1, newpos, ~0, IN_TREE);
            } else {
                destroy_subtree(w, w->flags1, newpos, q1);
                break;
            }
        }
    }

    for(t=path->length-1;t>0 && !path->firsthalf[t-1];t--) {
        node_t*pos = path->pos[t];
        node_t*newpos = path->pos[t-1];
        halfedge_t*dir = path->dir[t-1]->fwd;
        node_t*newpos2 = dir->fwd->node;
        assert(newpos == newpos2);
        if(!dir->fwd->weight) {
            /* disconnect node */
            DBG printf("remove link %d->%d from tree 2\n", NR(pos), NR(newpos));

	    dir->used = 0;
            w->flags2[NR(newpos)] &= ACTIVE;
            bool_op(w, w->flags2, newpos, ~IN_TREE, 0);

            /* try to reconnect the path to some other tree part */
            if(reconnect(w, w->flags2, newpos, 1)) {
                bool_op(w, w->flags2, newpos, ~0, IN_TREE);
            } else {
                destroy_subtree(w, w->flags2, newpos, q2);
                break;
            }
        }
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: drozas/cc_ntnu
int
main ( int argc, char **argv )
{
    read_args ( argc, argv );
    yyparse ();

#ifdef DUMPTREES
    FILE *pre = fopen ( "pre.tree", "w" ),
        *post = fopen ( "post.tree", "w" );
    print_node ( pre, root, 0 );
#endif

    root = simplify_tree ( root );

#ifdef DUMPTREES
    print_node ( post, root, 0 );
    fclose ( pre );
    fclose ( post );
#endif

    init_scopes ( 256 );

    find_symbols ( root );

    destroy_scopes ();
    destroy_subtree ( root );
    exit ( EXIT_SUCCESS );
}
コード例 #3
0
ファイル: tree.c プロジェクト: sondrele/NTNU
void destroy_subtree ( node_t *discard ) {
	if ( discard != NULL ) {
		for ( uint32_t i = 0; i < discard->n_children; i++ )
			destroy_subtree ( discard->children[i] );
		node_finalize ( discard );
	}
}
コード例 #4
0
ファイル: vslc.c プロジェクト: stoutbeard/ntnu
int
main ( int argc, char **argv )
{
    outputStage = 12;

    options ( argc, argv );

    /* In order to only scan the tokens we call yylex() directly */
    if ( outputStage == 1 ) {
        do { } while ( yylex() ); // "Token files"
        exit(0);
    }

    /* The parser calls yylex(), match the rules and builds the abstract syntax tree */
    // "BuildTree files"
    yyparse();
    if ( outputStage == 2 ) {
        exit(0); // Exit if we are only printing this stages debug information. "BuildTree files"
    }

    /* Print the abstract syntax tree */
    if ( outputStage == 3 ) {
        node_print ( stderr, root, 0 ); // "Tree files"
        exit(0);
    }

    destroy_subtree ( stderr, root );


    yylex_destroy(); // Free internal data structures of the scanner.

    exit ( EXIT_SUCCESS );
}
コード例 #5
0
ファイル: vslc.c プロジェクト: esiqveland/skole
int
main ( int argc, char **argv )
{
    options ( argc, argv );

    yyparse();

#ifdef DUMP_TREES
    if ( (DUMP_TREES & 1) != 0 ) {
	fprintf( stderr, "Dumping tree:\n");
	if( root == NULL )
		fprintf( stderr, "Root is NULL!:\n\n");
        node_print ( stderr, root, 0 );
    }
#endif

    /* Parsing and semantics are ok, redirect stdout to file (if requested) */
    if ( outfile != NULL )
    {
        if ( freopen ( outfile, "w", stdout ) == NULL )
        {
            fprintf ( stderr, "Could not open output file '%s'\n", outfile );
            exit ( EXIT_FAILURE );
        }
        free ( outfile );
    }

    destroy_subtree ( root );
    exit ( EXIT_SUCCESS );
}
コード例 #6
0
ファイル: vslc.c プロジェクト: edgarmv/NTNU
int
main ( int argc, char **argv )
{
    yyparse();
    node_print ( root, 0 );
    destroy_subtree ( root );
}
コード例 #7
0
ファイル: tree.c プロジェクト: ogdans3/kompilatorteknikk
/* Remove a node and its contents */
void
node_finalize ( node_t *discard )
{
    free( discard->data );
    for( int i = 0; i < (int)discard->n_children; i++ ){
        destroy_subtree( discard->children[i] );
    }
}
コード例 #8
0
ファイル: tree.c プロジェクト: somaen/komptek
void destroy_subtree(node_t *discard) {
	if (!discard)
		return;
	for (int i=0; i < discard->n_children; i++) {
		destroy_subtree((node_t*)discard->children + i);
	}
	node_finalize(discard);
}
コード例 #9
0
ファイル: tree.c プロジェクト: peterhgombos/tdt4205
void destroy_subtree ( node_t *discard ){
    if(discard == NULL) return;

    for(int i =0; i < discard->n_children; i++){
        destroy_subtree(discard->children[i]);
    }
    node_finalize(discard);
    
}
コード例 #10
0
ファイル: tree.c プロジェクト: cristeahub/komptek
void destroy_subtree ( FILE *output, node_t *discard )
{
    if ( discard != NULL )
    {
        for ( int i=0; i<discard->n_children; i++ )
            destroy_subtree ( output, discard->children[i] );
        if( output != NULL)
        	fprintf ( output, "Freeing %s\n", discard->nodetype.text );
        node_finalize ( discard );
    }
}
コード例 #11
0
ファイル: vslc.c プロジェクト: andsild/TDT4205
int
main ( int argc, char **argv )
{
    yyparse();
    node_print ( root, 0 );
    destroy_subtree ( root );
    
    // int token;
    // while ((token = yylex()) != 0)
    //     printf("Token: %d ('%s')\n", token, yytext);
    // printf("\n");
}
コード例 #12
0
ファイル: vslc.c プロジェクト: andsild/TDT4205
int
main ( int argc, char **argv )
{
    yyparse();
    simplify_tree ( &root, root );
    // node_print(root, 0);
    find_globals();
    size_t n_globals = tlhash_size(global_names);
    symbol_t *global_list[n_globals];
    tlhash_values ( global_names, (void **)&global_list );
    for ( size_t i=0; i<n_globals; i++ )
        if ( global_list[i]->type == SYM_FUNCTION )
            bind_names ( global_list[i], global_list[i]->node );

//    print_globals();

    generate_program ();    

    destroy_subtree ( root );
    destroy_symtab();
}
コード例 #13
0
ファイル: vslc.c プロジェクト: CheeKinTANG/Skole
int
main ( int argc, char **argv )
{
    options ( argc, argv );

    symtab_init ();
    yyparse();

#ifdef DUMP_TREES
    if ( (DUMP_TREES & 1) != 0 )
        node_print ( stderr, root, 0 );
#endif

    simplify_tree ( root );

#ifdef DUMP_TREES
    if ( (DUMP_TREES & 2) != 0 )
        node_print ( stderr, root, 0 );
#endif

    bind_names ( root );

    /* Parsing and semantics are ok, redirect stdout to file (if requested) */
    if ( outfile != NULL )
    {
        if ( freopen ( outfile, "w", stdout ) == NULL )
        {
            fprintf ( stderr, "Could not open output file '%s'\n", outfile );
            exit ( EXIT_FAILURE );
        }
        free ( outfile );
    }

    generate ( stdout, root );

    destroy_subtree ( root );
    symtab_finalize();

    exit ( EXIT_SUCCESS );
}
コード例 #14
0
ファイル: vslc.c プロジェクト: cristeahub/komptek
int
main ( int argc, char **argv )
{
	outputStage = 12;

    options ( argc, argv );

    symtab_init ();
    
    /* In order to only scan the tokens we call yylex() directly */
    if ( outputStage == 1 ) {
    	do { } while ( yylex() ); // "Token files"
        exit(0);
    }
    
    /* The parser calls yylex(), match the rules and builds the abstract syntax tree */
    // "BuildTree files"
    yyparse();
    if ( outputStage == 2 ) { 
        exit(0); // Exit if we are only printing this stages debug information. "BuildTree files"
    }
    
    /* Print the abstract syntax tree */
    if ( outputStage == 3 ) {
        node_print ( stderr, root, 0 ); // "Tree files"
        exit(0);
    }

    //simplify_tree ( root );
    /* Assign nodes functions according to their type; Handout first time only? */
    assignFunctionsToNodes( root );
    /* Simplify the abstract syntax tree */
    root->simplify( root, 0 );
    
    if ( outputStage == 4 ) { 
        exit(0); // Exit if we are only printing this stages debug information. "Build Simple Tree files"
    }

    /* Print the abstract syntax tree after simplification "Final Simple Tree files" */
    if ( outputStage == 5 ) {
        node_print ( stderr, root, 0 );
        exit(0);
    }

    //bind_names ( root );
    root->bind_names( root, 0);
    if ( outputStage == 6 || outputStage == 7) {
        exit(0); // Exit if we are only printing this stages debug information. "Scopes&String files" and "Symbol table files"
    }
    
    /* Print the .data (strings) segment of the assembly file */
    if ( outputStage == 8) {
        strings_output(stderr);
        exit(0);
    }
    
    /* Print the entries and string indexes in the node tree "Entries files" */
    if ( outputStage == 9) {
        node_print_entries ( stderr, root, 0 );
        exit(0);
    }
    
    root->typecheck(root);
    if (outputStage == 10) {
    	exit(0);
    }


    /* Parsing and semantics are ok, redirect stdout to file (if requested) */
    if ( outfile != NULL )
    {
        if ( freopen ( outfile, "w", stdout ) == NULL )
        {
            fprintf ( stderr, "Could not open output file '%s'\n", outfile );
            exit ( EXIT_FAILURE );
        }
        free ( outfile );
    }

	root->generate(root, 1);
	/*
	if(outputStage > 10 )
    	generate ( NULL, NULL, root ); // Output nothing, for later debugging stages.
    else if(outputStage == 10 )
    	generate ( NULL, stderr, root ); // Output only the traversal process.
    else if(outputStage == -1 )
    	generate ( stderr, NULL, root ); // Output the asm as no debug text is made.
	*/
	
    //destroy_subtree ( stderr, root );
    
    if ( outputStage == 11 ) {
    	destroy_subtree ( stderr, root );
        exit(0);
    } else
    	destroy_subtree ( NULL, root );
    
    symtab_finalize();
    
    yylex_destroy(); // Free internal data structures of the scanner.

    exit ( EXIT_SUCCESS );
}
コード例 #15
0
ファイル: avltree.c プロジェクト: pombredanne/libxdg
void clear_avl_tree(AvlTree *tree)
{
	destroy_subtree(tree, &tree->tree_root);
}
コード例 #16
0
ファイル: avltree.c プロジェクト: pombredanne/libxdg
void free_avl_tree(AvlTree *tree)
{
	destroy_subtree(tree, &tree->tree_root);
	free(tree);
}