Changeset 801978b


Ignore:
Timestamp:
Jul 13, 2021, 12:41:41 PM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
ca69a8a
Parents:
37c6f77
Message:

GenPoly? field-number selection for dynamic layouts uses uniqueId to match anonymous fields, rather than accepting first name match. fixed #253?

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r37c6f77 r801978b  
    15461546                        long i = 0;
    15471547                        for(std::list< Declaration* >::const_iterator decl = baseDecls.begin(); decl != baseDecls.end(); ++decl, ++i ) {
    1548                                 if ( memberDecl->get_name() != (*decl)->get_name() ) continue;
    1549 
    1550                                 if ( DeclarationWithType *declWithType = dynamic_cast< DeclarationWithType* >( *decl ) ) {
    1551                                         if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty()
    1552                                              || memberDecl->get_mangleName() == declWithType->get_mangleName() ) return i;
    1553                                         else continue;
    1554                                 } else return i;
     1548                                if ( memberDecl->get_name() != (*decl)->get_name() )
     1549                                        continue;
     1550
     1551                                if ( memberDecl->get_name().empty() ) {
     1552                                        // plan-9 field: match on unique_id
     1553                                        if ( memberDecl->get_uniqueId() == (*decl)->get_uniqueId() )
     1554                                                return i;
     1555                                        else
     1556                                                continue;
     1557                                }
     1558
     1559                                DeclarationWithType *declWithType = strict_dynamic_cast< DeclarationWithType* >( *decl );
     1560
     1561                                if ( memberDecl->get_mangleName().empty() || declWithType->get_mangleName().empty() ) {
     1562                                        // tuple-element field: expect neither had mangled name; accept match on simple name (like field_2) only
     1563                                        assert( memberDecl->get_mangleName().empty() && declWithType->get_mangleName().empty() );
     1564                                        return i;
     1565                                }
     1566
     1567                                // ordinary field: use full name to accommodate overloading
     1568                                if ( memberDecl->get_mangleName() == declWithType->get_mangleName() )
     1569                                        return i;
     1570                                else
     1571                                        continue;
    15551572                        }
    15561573                        return -1;
  • tests/.expect/polymorphism.txt

    r37c6f77 r801978b  
    11123 456 456
    225 5
     3=== checkPlan9offsets
     4static:
     5  offset of inner double: 8
     6  offset of inner float:  16
     7dynamic:
     8  offset of inner double: 8
     9  offset of inner float:  16
  • tests/polymorphism.cfa

    r37c6f77 r801978b  
    5454        b.i = s.i;
    5555        return b.j;
     56}
     57
     58void checkPlan9offsets() {
     59
     60        forall( T )
     61        struct thing {
     62                T q;                // variable-sized padding
     63                inline double;
     64                inline float;
     65        };
     66
     67        #define SHOW_OFFSETS \
     68                double & x_inner_double = x; \
     69                float  & x_inner_float  = x; \
     70                printf("  offset of inner double: %ld\n", ((char *) & x_inner_double) - ((char *) & x) ); \
     71                printf("  offset of inner float:  %ld\n", ((char *) & x_inner_float ) - ((char *) & x) );
     72
     73        void showStatic( thing(int) & x ) {
     74                printf("static:\n");
     75                SHOW_OFFSETS
     76        }
     77
     78        forall( T )
     79        void showDynamic( thing(T) & x ) {
     80                printf("dynamic:\n");
     81                SHOW_OFFSETS
     82        }
     83
     84        #undef SHOW_OFFSETS
     85
     86        printf("=== checkPlan9offsets\n");
     87        thing(int) x;
     88        showStatic(x);
     89        showDynamic(x);
    5690}
    5791
     
    114148                assertf(ret == u.f2, "union operation fails in polymorphic context.");
    115149        }
     150
     151        checkPlan9offsets();
    116152}
    117153
Note: See TracChangeset for help on using the changeset viewer.