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

« back to all changes in this revision

Viewing changes to src/action.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:
87
87
        const char *top_str = str ? str : _( "Bad arguments." );
88
88
        const char *op_name = op >= 0 ? decode_BinOp( op ) : name;
89
89
 
90
 
        BufInfo buf;
 
90
        VipsBuf buf;
91
91
        char txt[MAX_ERROR_FRAG];
92
 
        BufInfo buf2;
 
92
        VipsBuf buf2;
93
93
        char txt2[MAX_ERROR_FRAG];
94
 
        BufInfo buf3;
 
94
        VipsBuf buf3;
95
95
        char txt3[MAX_ERROR_FRAG];
96
96
 
97
 
        buf_init_static( &buf, txt, MAX_ERROR_FRAG );
 
97
        vips_buf_init_static( &buf, txt, MAX_ERROR_FRAG );
98
98
        itext_value_ev( rc, &buf, a );
99
99
 
100
 
        buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
 
100
        vips_buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
101
101
        itext_value_ev( rc, &buf2, b );
102
102
 
103
 
        buf_init_static( &buf3, txt3, MAX_ERROR_FRAG );
 
103
        vips_buf_init_static( &buf3, txt3, MAX_ERROR_FRAG );
104
104
        if( compile ) {
105
105
                /* Expands to eg. 'bad args to "+", called from "fred"'
106
106
                 */
107
 
                buf_appends( &buf3, _( "Called from" ) );
108
 
                buf_appends( &buf3, " " );
 
107
                vips_buf_appends( &buf3, _( "Called from" ) );
 
108
                vips_buf_appends( &buf3, " " );
109
109
                compile_name( compile, &buf3 );
110
110
        }
111
111
 
113
113
        error_sub( _( "Error in binary \"%s\".\n"
114
114
                "left = %s\n"
115
115
                "right = %s\n%s" ),
116
 
                op_name, buf_all( &buf ), buf_all( &buf2 ), buf_all( &buf3 ) );
 
116
                op_name, vips_buf_all( &buf ), vips_buf_all( &buf2 ), vips_buf_all( &buf3 ) );
117
117
        reduce_throw( rc );
118
118
}
119
119
 
122
122
static void
123
123
action_nomerror( Reduce *rc, Compile *compile, PElement *a, PElement *b )
124
124
{
125
 
        BufInfo buf;
 
125
        VipsBuf buf;
126
126
        char txt[500];
127
 
        BufInfo buf2;
 
127
        VipsBuf buf2;
128
128
        char txt2[MAX_ERROR_FRAG];
129
 
        BufInfo buf3;
 
129
        VipsBuf buf3;
130
130
        char txt3[MAX_ERROR_FRAG];
131
131
 
132
 
        buf_init_static( &buf, txt, 500 );
133
 
        buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
134
 
        buf_init_static( &buf3, txt3, MAX_ERROR_FRAG );
 
132
        vips_buf_init_static( &buf, txt, 500 );
 
133
        vips_buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
 
134
        vips_buf_init_static( &buf3, txt3, MAX_ERROR_FRAG );
135
135
 
136
136
        if( PEISCLASS( a ) ) 
137
137
                symbol_qualified_name( PEGETCLASSCOMPILE( a )->sym, &buf3 );
142
142
        else if( PEISCOMPILEREF( a ) ) 
143
143
                symbol_qualified_name( PEGETCOMPILE( a )->sym, &buf3 );
144
144
        else
145
 
                buf_appends( &buf3, "<thing>" );
 
145
                vips_buf_appends( &buf3, "<thing>" );
146
146
        itext_value_ev( rc, &buf2, b );
147
 
        buf_appendf( &buf, _( "Member \"%s\" not found in class \"%s\"." ),
148
 
                buf_all( &buf2 ), buf_all( &buf3 ) );
149
 
        buf_appendf( &buf, "\n" );
 
147
        vips_buf_appendf( &buf, _( "Member \"%s\" not found in class \"%s\"." ),
 
148
                vips_buf_all( &buf2 ), vips_buf_all( &buf3 ) );
 
149
        vips_buf_appendf( &buf, "\n" );
150
150
 
151
 
        buf_rewind( &buf3 );
 
151
        vips_buf_rewind( &buf3 );
152
152
        itext_value_ev( rc, &buf3, a );
153
 
        buf_appendf( &buf, "  " );
154
 
        buf_appendf( &buf, _( "object = %s" ), buf_all( &buf3 ) );
155
 
        buf_appendf( &buf, "\n" );
156
 
 
157
 
        buf_appendf( &buf, "  " );
158
 
        buf_appendf( &buf, _( "tag = %s" ), buf_all( &buf2 ) );
159
 
        buf_appendf( &buf, "\n" );
160
 
 
161
 
        buf_rewind( &buf3 );
 
153
        vips_buf_appendf( &buf, "  " );
 
154
        vips_buf_appendf( &buf, _( "object = %s" ), vips_buf_all( &buf3 ) );
 
155
        vips_buf_appendf( &buf, "\n" );
 
156
 
 
157
        vips_buf_appendf( &buf, "  " );
 
158
        vips_buf_appendf( &buf, _( "tag = %s" ), vips_buf_all( &buf2 ) );
 
159
        vips_buf_appendf( &buf, "\n" );
 
160
 
 
161
        vips_buf_rewind( &buf3 );
162
162
        symbol_qualified_name( compile->sym, &buf3 );
163
 
        buf_appendf( &buf, _( "Reference attempted in \"%s\"." ),
164
 
                buf_all( &buf3 ) );
165
 
        buf_appendf( &buf, "\n" );
 
163
        vips_buf_appendf( &buf, _( "Reference attempted in \"%s\"." ),
 
164
                vips_buf_all( &buf3 ) );
 
165
        vips_buf_appendf( &buf, "\n" );
166
166
 
167
167
        error_top( _( "Member not found." ) );
168
 
        error_sub( "%s", buf_all( &buf ) );
 
168
        error_sub( "%s", vips_buf_all( &buf ) );
169
169
        reduce_throw( rc );
170
170
}
171
171
 
178
178
        const char *top_str = str ? str : _( "Bad argument." );
179
179
        const char *op_name = op >= 0 ? decode_UnOp( op ) : name;
180
180
 
181
 
        BufInfo buf;
 
181
        VipsBuf buf;
182
182
        char txt[MAX_ERROR_FRAG];
183
 
        BufInfo buf2;
 
183
        VipsBuf buf2;
184
184
        char txt2[MAX_ERROR_FRAG];
185
185
 
186
 
        buf_init_static( &buf, txt, MAX_ERROR_FRAG );
 
186
        vips_buf_init_static( &buf, txt, MAX_ERROR_FRAG );
187
187
        itext_value_ev( rc, &buf, a );
188
188
 
189
 
        buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
 
189
        vips_buf_init_static( &buf2, txt2, MAX_ERROR_FRAG );
190
190
        if( compile ) {
191
191
                /* Expands to eg. 'bad args to "+", called from "fred"'
192
192
                 */
193
 
                buf_appends( &buf2, _( "Called from" ) );
194
 
                buf_appends( &buf2, " " );
 
193
                vips_buf_appends( &buf2, _( "Called from" ) );
 
194
                vips_buf_appends( &buf2, " " );
195
195
                compile_name( compile, &buf2 );
196
196
        }
197
197
 
198
198
        error_top( "%s", top_str );
199
199
        error_sub( _( "Error in unary \"%s\".\n"
200
200
                "argument = %s\n%s" ),
201
 
                op_name, buf_all( &buf ), buf_all( &buf2 ) );
 
201
                op_name, vips_buf_all( &buf ), vips_buf_all( &buf2 ) );
202
202
        reduce_throw( rc );
203
203
}
204
204
 
325
325
        return( link_add( child, expr, TRUE ) );
326
326
}
327
327
 
 
328
static char *
 
329
action_proc_dot_tag( PElement *b, char *tag, int n )
 
330
{
 
331
        if( PEISTAG( b ) ) 
 
332
                return( PEGETTAG( b ) );
 
333
        else if( heap_get_string( b, tag, n ) )
 
334
                return( tag );
 
335
 
 
336
        return( NULL );
 
337
}
 
338
 
328
339
/* Extract field from object. Be careful, a can be equal to out. 
329
340
 */
330
341
static void
332
343
        int op, const char *name, PElement *a, PElement *b, PElement *out )
333
344
{
334
345
        char tag[256];
 
346
        char *p;
335
347
 
336
348
        if( PEISCLASS( a ) ) {
337
349
                PElement c;
338
350
 
339
 
                if( PEISTAG( b ) ) {
340
 
                        if( !class_get_member( a, PEGETTAG( b ), NULL, &c ) )
 
351
                if( (p = action_proc_dot_tag( b, tag, 256 )) ) {
 
352
                        if( !class_get_member( a, p, NULL, &c ) )
341
353
                                action_nomerror( rc, compile, a, b );
342
354
 
343
355
                        PEPUTPE( out, &c );
348
360
 
349
361
                        PEPUTPE( out, &c );
350
362
                }
351
 
                else if( heap_get_string( b, tag, 256 ) ) {
352
 
                        if( !class_get_member( a, tag, NULL, &c ) )
353
 
                                action_nomerror( rc, compile, a, b );
354
 
 
355
 
                        PEPUTPE( out, &c );
356
 
                }
357
363
                else
358
364
                        action_boperror( rc, compile, 
359
365
                                _( "Bad right hand side of '.'." ),
370
376
                                "is not scope" ), 
371
377
                                op, name, a, b );
372
378
 
373
 
                assert( sym->expr );
 
379
                g_assert( sym->expr );
374
380
 
375
 
                if( PEISTAG( b ) ) 
376
 
                        child = compile_lookup( sym->expr->compile, 
377
 
                                PEGETTAG( b ) );
378
 
                else if( heap_get_string( b, tag, 256 ) ) 
379
 
                        child = compile_lookup( sym->expr->compile, tag );
380
 
                else
 
381
                if( !(p = action_proc_dot_tag( b, tag, 256 )) ) 
381
382
                        action_boperror( rc, compile, 
382
383
                                _( "Bad right hand side of '.'." ),
383
384
                                op, name, a, b );
384
 
 
385
 
                if( !child )
 
385
                if( !(child = compile_lookup( sym->expr->compile, p )) )
386
386
                        action_nomerror( rc, compile, a, b );
387
387
 
388
388
                /* Add all exprs which use compile to dynamic link graph.
402
402
                        PEPUTP( out, ELEMENT_SYMREF, child );
403
403
                }
404
404
        }
 
405
        else if( PEISMANAGEDGOBJECT( a ) ) {
 
406
                GObject *gobject = PEGETMANAGEDGOBJECT( a );
 
407
                GObjectClass *gclass = G_OBJECT_GET_CLASS( gobject );
 
408
                GValue value = { 0 };
 
409
                GParamSpec *pspec;
 
410
 
 
411
                if( !(p = action_proc_dot_tag( b, tag, 256 )) )
 
412
                        action_boperror( rc, compile, 
 
413
                                _( "Bad right hand side of '.'." ),
 
414
                                op, name, a, b );
 
415
                if( !(pspec = g_object_class_find_property( gclass, p )) )
 
416
                        action_boperror( rc, compile, 
 
417
                                _( "Property not found." ),
 
418
                                op, name, a, b );
 
419
 
 
420
                g_value_init( &value, G_PARAM_SPEC_VALUE_TYPE( pspec ) );
 
421
                g_object_get_property( gobject, p, &value);
 
422
 
 
423
                if( !heap_gvalue_to_ip( &value, out ) ) {
 
424
                        g_value_unset( &value );
 
425
                        reduce_throw( rc );
 
426
                }
 
427
 
 
428
                g_value_unset( &value );
 
429
        }
405
430
        else
406
431
                action_boperror( rc, compile, _( "Bad left hand side of '.'." ),
407
432
                        op, name, a, b );
419
444
        else if( PEISCHAR( a ) && PEISCHAR( b ) ) {
420
445
                PEPUTP( out, ELEMENT_BOOL, PEGETCHAR( a ) <= PEGETCHAR( b ) );
421
446
        }
422
 
        else if( PEISLIST( a ) && PEISLIST( b ) ) {
 
447
        else if( PEISLIST( a ) && PEISLIST( b ) &&
 
448
                reduce_is_string( rc, a ) && reduce_is_string( rc, b ) ) {
423
449
                char a_string[MAX_STRSIZE];
424
450
                char b_string[MAX_STRSIZE];
425
451
 
452
478
        else if( PEISCHAR( a ) && PEISCHAR( b ) ) {
453
479
                PEPUTP( out, ELEMENT_BOOL, PEGETCHAR( a ) < PEGETCHAR( b ) );
454
480
        }
455
 
        else if( PEISLIST( a ) && PEISLIST( b ) ) {
 
481
        else if( PEISLIST( a ) && PEISLIST( b ) &&
 
482
                reduce_is_string( rc, a ) && reduce_is_string( rc, b ) ) {
456
483
                char a_string[MAX_STRSIZE];
457
484
                char b_string[MAX_STRSIZE];
458
485
 
520
547
        case TAG_SHARED:
521
548
        case TAG_REFERENCE:
522
549
        default:
523
 
                assert( FALSE );
 
550
                g_assert( FALSE );
524
551
 
525
552
                /* Keep gcc happy.
526
553
                 */
541
568
         */
542
569
        ii[0] = a;
543
570
        ii[1] = b;
544
 
        assert( !ii[0] && !ii[1] );
 
571
        g_assert( !ii[0] && !ii[1] );
545
572
        if( ii[0] == ii[1] )
546
573
                /* Trivial!
547
574
                 */
585
612
        return( mn == 255 );
586
613
}
587
614
 
 
615
/* One of p1/p2 is a managedstring. 
 
616
 *
 
617
 * This is pretty dumb. We could have a special loop down the list side which
 
618
 * compared to the managedstring directly, but I doubt if this will ever be a
 
619
 * performance issue.
 
620
 */
 
621
static gboolean
 
622
action_string_equal( Reduce *rc, PElement *p1, PElement *p2 )
 
623
{
 
624
        char a_string[MAX_STRSIZE];
 
625
        char b_string[MAX_STRSIZE];
 
626
 
 
627
        reduce_get_string( rc, p1, a_string, MAX_STRSIZE );
 
628
        reduce_get_string( rc, p2, b_string, MAX_STRSIZE );
 
629
 
 
630
        return( strcmp( a_string, b_string ) == 0 );
 
631
}
 
632
 
588
633
/* Test two elements for equality. Force computation as required.
589
634
 */
590
635
static gboolean
595
640
        reduce_spine( rc, p1 );
596
641
        reduce_spine( rc, p2 );
597
642
 
598
 
        /* Easy!
 
643
        /* We can often test for eg. "fred" == "fred" by just checking
 
644
         * pointers.
 
645
         */
 
646
        if( PEGETTYPE( p1 ) == PEGETTYPE( p2 ) ) {
 
647
                switch( PEGETTYPE( p1 ) ) {
 
648
                case ELEMENT_CHAR:
 
649
                case ELEMENT_NODE:
 
650
                case ELEMENT_BOOL:
 
651
                case ELEMENT_MANAGED:
 
652
                        if( PEGETVAL( p1 ) == PEGETVAL( p2 ) )
 
653
                                return( TRUE );
 
654
                        break;
 
655
 
 
656
                case ELEMENT_ELIST:
 
657
                        return( TRUE );
 
658
                }
 
659
        }
 
660
 
 
661
        /* Special case if either is a managedstring.
 
662
         */
 
663
        if( PEISMANAGEDSTRING( p1 ) ||
 
664
                PEISMANAGEDSTRING( p2 ) ) 
 
665
                return( action_string_equal( rc, p1, p2 ) );
 
666
 
 
667
        /* No other implicit conversions, so types must match.
599
668
         */
600
669
        if( PEGETTYPE( p1 ) != PEGETTYPE( p2 ) )
601
670
                return( FALSE );
636
705
                return( TRUE );
637
706
 
638
707
        case ELEMENT_NOVAL:
639
 
        case ELEMENT_STATIC:
640
708
        default:
641
 
                assert( FALSE );
 
709
                g_assert( FALSE );
642
710
 
643
711
                /* Keep gcc happy.
644
712
                 */
1552
1620
        Compile *compile, HeapNode **arg, PElement *out )
1553
1621
{
1554
1622
        if( trace_flags & TRACE_CLASS_NEW ) {
1555
 
                BufInfo *buf = trace_push();
 
1623
                VipsBuf *buf = trace_push();
1556
1624
 
1557
 
                buf_appendf( buf, "constructor \"%s\" ", 
 
1625
                vips_buf_appendf( buf, "constructor \"%s\" ", 
1558
1626
                        IOBJECT( compile->sym )->name );
1559
1627
                trace_args( arg, compile->nparam + compile->nsecret );
1560
1628
        }
1589
1657
        base = *pe;
1590
1658
        heap_appl_init( &base, fn );
1591
1659
        if( !heap_appl_add( rc->heap, &base, &rhs ) ||
1592
 
                !heap_string_new( rc->heap, name, &rhs ) ||
 
1660
                !heap_managedstring_new( rc->heap, name, &rhs ) ||
1593
1661
                !heap_appl_add( rc->heap, &base, &rhs ) ) 
1594
1662
                return( out );
1595
1663
 
1609
1677
        PElement fn;
1610
1678
 
1611
1679
        if( trace_flags & flags ) {
1612
 
                BufInfo *buf = trace_push();
 
1680
                VipsBuf *buf = trace_push();
1613
1681
 
1614
 
                buf_appendf( buf, "%s\n", _( "invoking method:" ) );
1615
 
                buf_appends( buf, "     " );
 
1682
                vips_buf_appendf( buf, "%s\n", _( "invoking method:" ) );
 
1683
                vips_buf_appends( buf, "     " );
1616
1684
                trace_pelement( a );
1617
 
                buf_appendf( buf, ".%s \"%s\" ", MEMBER_OO_BINARY, name );
 
1685
                vips_buf_appendf( buf, ".%s \"%s\" ", MEMBER_OO_BINARY, name );
1618
1686
                trace_pelement( b );
1619
 
                buf_appends( buf, "\n" );
 
1687
                vips_buf_appends( buf, "\n" );
1620
1688
 
1621
 
                trace_text( flags, buf_all( buf ) );
 
1689
                trace_text( flags, "%s", vips_buf_all( buf ) );
1622
1690
 
1623
1691
                trace_pop();
1624
1692
        }
1645
1713
        PElement fn;
1646
1714
 
1647
1715
        if( trace_flags & flags ) {
1648
 
                BufInfo *buf = trace_push();
 
1716
                VipsBuf *buf = trace_push();
1649
1717
 
1650
 
                buf_appendf( buf, "%s\n", _( "invoking method:" ) );
1651
 
                buf_appends( buf, "     " );
 
1718
                vips_buf_appendf( buf, "%s\n", _( "invoking method:" ) );
 
1719
                vips_buf_appends( buf, "     " );
1652
1720
                trace_pelement( b );
1653
 
                buf_appendf( buf, ".%s \"%s\" ", MEMBER_OO_BINARY2, name );
 
1721
                vips_buf_appendf( buf, ".%s \"%s\" ", MEMBER_OO_BINARY2, name );
1654
1722
                trace_pelement( a );
1655
 
                buf_appends( buf, "\n" );
 
1723
                vips_buf_appends( buf, "\n" );
1656
1724
 
1657
 
                trace_text( flags, buf_all( buf ) );
 
1725
                trace_text( flags, "%s", vips_buf_all( buf ) );
1658
1726
 
1659
1727
                trace_pop();
1660
1728
        }
1772
1840
                 */
1773
1841
                if( PEISBOOL( a ) ) {
1774
1842
                        if( trace_flags & TRACE_OPERATOR ) {
1775
 
                                BufInfo *buf = trace_push();
 
1843
                                VipsBuf *buf = trace_push();
1776
1844
 
1777
 
                                buf_appendf( buf, "if " );
 
1845
                                vips_buf_appendf( buf, "if " );
1778
1846
                                trace_pelement( a );
1779
 
                                buf_appendf( buf, " then " );
 
1847
                                vips_buf_appendf( buf, " then " );
1780
1848
                                trace_pelement( &t );
1781
 
                                buf_appendf( buf, " else " );
 
1849
                                vips_buf_appendf( buf, " else " );
1782
1850
                                trace_pelement( &e );
1783
 
                                buf_appendf( buf, " ->\n" );
 
1851
                                vips_buf_appendf( buf, " ->\n" );
1784
1852
                        }
1785
1853
 
1786
1854
                        if( PEGETBOOL( a ) ) {
1887
1955
        base = *pe;
1888
1956
        heap_appl_init( &base, fn );
1889
1957
        if( !heap_appl_add( rc->heap, &base, &rhs ) ||
1890
 
                !heap_string_new( rc->heap, name, &rhs ) )
 
1958
                !heap_managedstring_new( rc->heap, name, &rhs ) )
1891
1959
                return( out );
1892
1960
 
1893
1961
        PEPUTPE( out, pe );
1903
1971
        PElement fn;
1904
1972
 
1905
1973
        if( trace_flags & flags ) {
1906
 
                BufInfo *buf = trace_push();
 
1974
                VipsBuf *buf = trace_push();
1907
1975
 
1908
 
                buf_appendf( buf, "%s\n", _( "invoking method:" ) );
1909
 
                buf_appends( buf, "     " );
 
1976
                vips_buf_appendf( buf, "%s\n", _( "invoking method:" ) );
 
1977
                vips_buf_appends( buf, "     " );
1910
1978
                trace_pelement( a );
1911
 
                buf_appendf( buf, ".%s \"%s\"\n", MEMBER_OO_UNARY, name );
 
1979
                vips_buf_appendf( buf, ".%s \"%s\"\n", MEMBER_OO_UNARY, name );
1912
1980
 
1913
 
                trace_text( flags, buf_all( buf ) );
 
1981
                trace_text( flags, "%s", vips_buf_all( buf ) );
1914
1982
 
1915
1983
                trace_pop();
1916
1984
        }
1917
1985
 
1918
1986
        /* Look up a.dispatch_unary and build 
1919
 
         * (a.dispatch_unary "minus") application.
 
1987
         * (a.oo_unary "minus") application.
1920
1988
         */
1921
1989
        if( !class_get_member( a, MEMBER_OO_UNARY, NULL, &fn ) )
1922
1990
                action_uoperror( rc, compile, error_get_sub(), op, name, a );
1943
2011
        /* Don't allow nargs == 0. We rely on having a bit of graph we can
1944
2012
         * replace with (I result) for caching.
1945
2013
         */
1946
 
        assert( nargs > 0 );
 
2014
        g_assert( nargs > 0 );
 
2015
 
 
2016
        /* We need to have the 
 
2017
         */
 
2018
        g_assert( noperator_table == UN_LAST );
1947
2019
 
1948
2020
        /* Reduce all the args.
1949
2021
         */
1964
2036
        PEPOINTRIGHT( arg[1], &a );
1965
2037
 
1966
2038
        if( trace_flags & flags ) {
1967
 
                BufInfo *buf = trace_push();
 
2039
                VipsBuf *buf = trace_push();
1968
2040
 
1969
 
                buf_appendf( buf, "\"%s\" ", name );
 
2041
                vips_buf_appendf( buf, "\"%s\" ", name );
1970
2042
                trace_args( arg, nargs );
1971
2043
        }
1972
2044