~ubuntu-branches/ubuntu/vivid/nip2/vivid-proposed

« back to all changes in this revision

Viewing changes to src/compile.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Terry
  • Date: 2009-05-12 09:26:46 UTC
  • mfrom: (1.2.11 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090512092646-j8lb1w2x69pvgma4
Tags: 7.18.1-1ubuntu1
* Merge from debian unstable (LP: #375435), remaining changes:
  - debian/control: Also Recommend abrowser

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
}
81
81
 
82
82
static void *
83
 
compile_name_sub( Expr *expr, BufInfo *buf )
 
83
compile_name_sub( Expr *expr, VipsBuf *buf )
84
84
{
85
85
        if( expr->row ) {
86
 
                if( !buf_is_empty( buf ) )
87
 
                        buf_appends( buf, ", " );
 
86
                if( !vips_buf_is_empty( buf ) )
 
87
                        vips_buf_appends( buf, ", " );
88
88
                row_qualified_name( expr->row, buf );
89
89
        }
90
90
 
92
92
}
93
93
 
94
94
void
95
 
compile_name( Compile *compile, BufInfo *buf )
 
95
compile_name( Compile *compile, VipsBuf *buf )
96
96
{
97
 
        BufInfo buf2;
 
97
        VipsBuf buf2;
98
98
        char txt[256];
99
99
 
100
 
        buf_appends( buf, "\"" );
 
100
        vips_buf_appends( buf, "\"" );
101
101
        symbol_qualified_name( compile->sym, buf );
102
 
        buf_appends( buf, "\"" );
 
102
        vips_buf_appends( buf, "\"" );
103
103
 
104
 
        buf_init_static( &buf2, txt, 256 );
 
104
        vips_buf_init_static( &buf2, txt, 256 );
105
105
        slist_map( compile->exprs,
106
106
                (SListMapFn) compile_name_sub, &buf2 );
107
 
        if( !buf_is_empty( &buf2 ) ) 
108
 
                buf_appendf( buf, " (%s)", buf_all( &buf2 ) );
 
107
        if( !vips_buf_is_empty( &buf2 ) ) 
 
108
                vips_buf_appendf( buf, " (%s)", vips_buf_all( &buf2 ) );
109
109
}
110
110
 
111
111
static Compile *
190
190
 
191
191
        /* Must be there.
192
192
         */
193
 
        assert( g_slist_find( compile->children, child ) &&
 
193
        g_assert( g_slist_find( compile->children, child ) &&
194
194
                g_slist_find( child->parents, compile ) );
195
195
 
196
196
        compile->children = g_slist_remove( compile->children, child );
209
209
void *
210
210
compile_expr_link_break( Compile *compile, Expr *expr )
211
211
{
212
 
        assert( expr->compile == compile );
213
 
        assert( g_slist_find( compile->exprs, expr ) );
 
212
        g_assert( expr->compile == compile );
 
213
        g_assert( g_slist_find( compile->exprs, expr ) );
214
214
 
215
215
        expr->compile = NULL;
216
216
        compile->exprs = g_slist_remove( compile->exprs, expr );
229
229
void 
230
230
compile_expr_link_make( Compile *compile, Expr *expr )
231
231
{
232
 
        assert( !expr->compile );
233
 
        assert( !g_slist_find( compile->exprs, expr ) );
234
 
        assert( compile->sym == expr->sym );
 
232
        g_assert( !expr->compile );
 
233
        g_assert( !g_slist_find( compile->exprs, expr ) );
 
234
        g_assert( compile->sym == expr->sym );
235
235
 
236
236
        expr->compile = compile;
237
237
        compile->exprs = g_slist_prepend( compile->exprs, expr );
280
280
        /* Remove static strings we created.
281
281
         */
282
282
        slist_map( compile->statics, 
283
 
                (SListMapFn) heap_static_string_unref, NULL );
 
283
                (SListMapFn) managed_destroy_nonheap, NULL );
284
284
        IM_FREEF( g_slist_free, compile->statics );
285
285
 
286
286
        /* Junk heap.
303
303
        /* If we're being finalized, we must have a ref count of zero, so
304
304
         * there shouldn't be any exprs looking at us.
305
305
         */
306
 
        assert( !compile->exprs );
 
306
        g_assert( !compile->exprs );
307
307
 
308
308
        G_OBJECT_CLASS( parent_class )->finalize( gobject );
309
309
}
310
310
 
311
311
static void
312
 
compile_child_add( iContainer *parent, iContainer *child, int pos )
313
 
{
314
 
        Compile *compile = COMPILE( parent );
315
 
        Symbol *sym = SYMBOL( child );
316
 
 
317
 
        if( sym ) 
318
 
                compile->last_sym = sym;
319
 
 
320
 
        ICONTAINER_CLASS( parent_class )->child_add( parent, child, pos );
321
 
}
322
 
 
323
 
static void 
324
 
compile_child_remove( iContainer *parent, iContainer *child )
325
 
{
326
 
        Compile *compile = COMPILE( parent );
327
 
        Symbol *sym = SYMBOL( child );
328
 
 
329
 
        if( sym && compile->last_sym == sym )
330
 
                compile->last_sym = NULL;
331
 
 
332
 
        ICONTAINER_CLASS( parent_class )->child_remove( parent, child );
333
 
}
334
 
 
335
 
static void
336
312
compile_class_init( CompileClass *class )
337
313
{
338
314
        GObjectClass *gobject_class = (GObjectClass *) class;
339
 
        iContainerClass *icontainer_class = (iContainerClass *) class;
340
315
 
341
316
        parent_class = g_type_class_peek_parent( class );
342
317
 
343
318
        gobject_class->finalize = compile_finalize;
344
319
 
345
 
        icontainer_class->child_add = compile_child_add;
346
 
        icontainer_class->child_remove = compile_child_remove;
347
 
 
348
320
        /* Create signals.
349
321
         */
350
322
 
827
799
                switch( pn->con.type ) {
828
800
                case PARSE_CONST_STR:
829
801
                {
830
 
                        HeapStaticString *string;
831
 
 
832
 
                        if( !(string = heap_static_string_new( 
833
 
                                reduce_context->heap,
 
802
                        Managedstring *managedstring;
 
803
                                
 
804
                        if( !(managedstring = managedstring_find( 
 
805
                                reduce_context->heap, 
834
806
                                pn->con.val.str )) )
835
807
                                return( FALSE );
 
808
                        MANAGED_REF( managedstring );
836
809
                        compile->statics = g_slist_prepend( compile->statics,
837
 
                                string );
838
 
 
839
 
                        PEPUTP( out, ELEMENT_STATIC, string );
840
 
 
 
810
                                managedstring );
 
811
                        PEPUTP( out, ELEMENT_MANAGED, managedstring );
 
812
                }
841
813
                        break;
842
 
                }
843
814
 
844
815
                case PARSE_CONST_CHAR:
845
816
                        PEPUTP( out, ELEMENT_CHAR, pn->con.val.ch );
864
835
                        break;
865
836
 
866
837
                default:
867
 
                        assert( FALSE );
 
838
                        g_assert( FALSE );
868
839
                }
869
840
 
870
841
                break;
871
842
 
872
843
        case NODE_NONE:
873
844
        default:
874
 
                assert( FALSE );
 
845
                g_assert( FALSE );
875
846
        }
876
847
 
877
848
        return( TRUE );
948
919
                case TAG_FILE:
949
920
                case TAG_FREE:  
950
921
                default:
951
 
                        assert( FALSE );
 
922
                        g_assert( FALSE );
952
923
                }
953
924
 
954
925
                break;
969
940
                *used = TRUE;
970
941
                break;
971
942
 
 
943
        case ELEMENT_MANAGED:
972
944
        case ELEMENT_CHAR:
973
945
        case ELEMENT_BOOL:
974
946
        case ELEMENT_BINOP:
979
951
        case ELEMENT_COMPILEREF:
980
952
        case ELEMENT_NOVAL:
981
953
        case ELEMENT_TAG:
982
 
        case ELEMENT_STATIC:
983
954
                /* Leave alone.
984
955
                 */
985
956
                break;
986
957
 
987
 
        /* Should not exist at compile time.
988
 
         */
989
 
        case ELEMENT_MANAGED:
990
958
        default:
991
 
                assert( FALSE );
 
959
                g_assert( FALSE );
992
960
        }
993
961
 
994
962
        return( 0 );
1214
1182
                hash = INT_TO_HASH( g_str_hash( PEGETTAG( e ) ) );
1215
1183
                break;
1216
1184
 
1217
 
        case ELEMENT_STATIC:
1218
 
                hash = INT_TO_HASH( g_str_hash( PEGETSTATIC( e )->text ) );
 
1185
        case ELEMENT_MANAGED:
 
1186
                if( PEISMANAGEDSTRING( e ) )
 
1187
                        hash = INT_TO_HASH( g_str_hash( 
 
1188
                                PEGETMANAGEDSTRING( e )->string ) );
1219
1189
                break;
1220
1190
 
1221
1191
        case ELEMENT_NOVAL:
1222
 
        case ELEMENT_MANAGED:
1223
1192
        default:
1224
 
                assert( 0 );
 
1193
                g_assert( 0 );
1225
1194
        }
1226
1195
 
1227
1196
        return( hash );
1266
1235
        case TAG_SHARED:
1267
1236
        case TAG_FREE:
1268
1237
        default:
1269
 
                assert( FALSE );
 
1238
                g_assert( FALSE );
1270
1239
        }
1271
1240
 
1272
1241
        /* Add to accumulated table.
1312
1281
 
1313
1282
        /* If compound type, something is wrong! Only built by reduce.
1314
1283
         */
1315
 
        assert( hn1->type != TAG_CLASS );
 
1284
        g_assert( hn1->type != TAG_CLASS );
1316
1285
 
1317
1286
        /* In two parts, test tags.
1318
1287
         */
1350
1319
{
1351
1320
#ifdef DEBUG
1352
1321
        Heap *heap = compile->heap;
1353
 
        BufInfo buf;
 
1322
        VipsBuf buf;
1354
1323
        char txt[100];
1355
1324
#endif /*DEBUG*/
1356
1325
 
1357
1326
#ifdef DEBUG
1358
 
        buf_init_static( &buf, txt, 80 );
 
1327
        vips_buf_init_static( &buf, txt, 80 );
1359
1328
        graph_node( heap, &buf, hn1, TRUE );
1360
 
        printf( "Found common subexpression: %s\n", buf_all( &buf ) );
 
1329
        printf( "Found common subexpression: %s\n", vips_buf_all( &buf ) );
1361
1330
#endif /*DEBUG*/
1362
1331
 
1363
1332
#ifdef DEBUG_COMMON
1422
1391
        case TAG_FREE:
1423
1392
        case TAG_FILE:
1424
1393
        default:
1425
 
                assert( FALSE );
 
1394
                g_assert( FALSE );
1426
1395
        }
1427
1396
}
1428
1397
 
1452
1421
        Heap *heap = compile->heap;
1453
1422
 
1454
1423
#ifdef DEBUG
1455
 
        BufInfo buf;
 
1424
        VipsBuf buf;
1456
1425
        char txt[100];
1457
1426
#endif /*DEBUG*/
1458
1427
 
1463
1432
                        HeapNode *hn2;
1464
1433
 
1465
1434
#ifdef DEBUG
1466
 
                        buf_init_static( &buf, txt, 80 );
 
1435
                        vips_buf_init_static( &buf, txt, 80 );
1467
1436
                        graph_node( heap, &buf, hn1, TRUE );
1468
 
                        printf( "Found shared code: %s\n", buf_all( &buf ) );
 
1437
                        printf( "Found shared code: %s\n", vips_buf_all( &buf ) );
1469
1438
#endif /*DEBUG*/
1470
1439
 
1471
1440
                        if( NEWNODE( heap, hn2 ) )
1551
1520
{
1552
1521
        PElement base;
1553
1522
#ifdef DEBUG
1554
 
        BufInfo buf;
 
1523
        VipsBuf buf;
1555
1524
        char txt[1024];
1556
1525
#endif /*DEBUG*/
1557
1526
 
1591
1560
        }
1592
1561
 
1593
1562
#ifdef DEBUG
1594
 
        buf_init_static( &buf, txt, 1024 );
 
1563
        vips_buf_init_static( &buf, txt, 1024 );
1595
1564
        graph_pelement( compile->heap, &buf, &base, TRUE );
1596
1565
        printf( "before var abstraction, compiled \"%s\" to: %s\n", 
1597
 
                IOBJECT( compile->sym )->name, buf_all( &buf ) );
 
1566
                IOBJECT( compile->sym )->name, vips_buf_all( &buf ) );
1598
1567
#endif /*DEBUG*/
1599
1568
 
1600
1569
        /* Abstract real parameters.
1622
1591
 
1623
1592
#ifdef DEBUG_RESULT
1624
1593
{
1625
 
        BufInfo buf;
 
1594
        VipsBuf buf;
1626
1595
        char txt[1024];
1627
1596
 
1628
1597
        printf( "compiled \"" );
1629
1598
        symbol_name_print( compile->sym );
1630
1599
        printf( "\" to: " );
1631
 
        buf_init_static( &buf, txt, 1024 );
 
1600
        vips_buf_init_static( &buf, txt, 1024 );
1632
1601
        graph_pelement( compile->heap, &buf, &base, TRUE );
1633
 
        printf( "%s\n", buf_all( &buf ) );
 
1602
        printf( "%s\n", vips_buf_all( &buf ) );
1634
1603
}
1635
1604
#endif /*DEBUG_RESULT*/
1636
1605
 
2106
2075
 
2107
2076
        /* Must be a different place.
2108
2077
         */
2109
 
        assert( symbol_get_parent( sym )->expr->compile != dest );
 
2078
        g_assert( symbol_get_parent( sym )->expr->compile != dest );
2110
2079
 
2111
2080
        /* Must not be an existing sym of that name. Or if there is, it has to
2112
2081
         * be a zombie.
2113
2082
         */
2114
 
        assert( !compile_lookup( dest, name ) ||
 
2083
        g_assert( !compile_lookup( dest, name ) ||
2115
2084
                compile_lookup( dest, name )->type == SYM_ZOMBIE );
2116
2085
 
2117
2086
        switch( sym->type ) {
2153
2122
        case SYM_EXTERNAL:
2154
2123
        case SYM_BUILTIN:
2155
2124
        default:
2156
 
                assert( 0 );
 
2125
                g_assert( 0 );
2157
2126
        }
2158
2127
 
2159
2128
        return( NULL );
2210
2179
 
2211
2180
  Example: after parse we have:
2212
2181
 
2213
 
        [(x, y) | x <- [1..3]; y <- [x..3]; x + y > 3];
 
2182
        [(x, y) :: x <- [1..3]; y <- [x..3]; x + y > 3];
2214
2183
 
2215
2184
        ... $$lcomp1 ...
2216
2185
        {
2424
2393
 
2425
2394
        /* Copy the code for the final result.
2426
2395
         */
2427
 
        assert( result );
 
2396
        g_assert( result );
2428
2397
 
2429
2398
        n1 = compile_copy_tree( result->expr->compile, 
2430
2399
                result->expr->compile->tree, scope );