Ignore:
Timestamp:
Nov 25, 2016, 6:11:03 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0f35657
Parents:
186fd86
Message:

add support for built-in sized trait which decouples size/alignment information from otype parameters, add test for sized trait

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CommonType.cc

    r186fd86 r2c57025  
    5757                Type *result = visitor.get_result();
    5858                if ( ! result ) {
     59                        // this appears to be handling for opaque type declarations
    5960                        if ( widenSecond ) {
    60                                 TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 );
    61                                 if ( inst ) {
    62                                         NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
    63                                         if ( nt ) {
    64                                                 TypeDecl *type = dynamic_cast< TypeDecl* >( nt );
    65                                                 assert( type );
     61                                if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) {
     62                                        if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) {
     63                                                TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt );
    6664                                                if ( type->get_base() ) {
    6765                                                        Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers();
     
    145143        }
    146144
     145        /// true if a common type for t must be a complete type
     146        bool requiredComplete( Type * t ) {
     147                if ( TypeInstType * inst = dynamic_cast< TypeInstType * > ( t ) ) {
     148                        return inst->get_baseType()->isComplete();
     149                }
     150                return false;
     151        }
     152
    147153        void CommonType::visit( PointerType *pointerType ) {
    148154                if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
    149                         if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) ) {
     155                        // Note: relationship between formal and actual types is antisymmetric
     156                        //   void free(void *);
     157                        //   forall(otype T) void foo(T *);
     158                        //
     159                        // should be able to pass T* to free, but should not be able to pass a void* to foo.
     160                        // because of this, the requiredComplete check occurs only on the first, since it corresponds
     161                        // to the formal parameter type (though this may be incorrect in some cases, in which case
     162                        // perhaps the widen mode needs to incorporate another bit for whether this is a formal or actual context)
     163                        if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) && ! requiredComplete( pointerType->get_base() ) ) {
    150164                                result = otherPointer->clone();
    151165                                result->get_qualifiers() += pointerType->get_qualifiers();
     
    211225                        NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
    212226                        if ( nt ) {
    213                                 TypeDecl *type = dynamic_cast< TypeDecl* >( nt );
    214                                 assert( type );
     227                                TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt );
    215228                                if ( type->get_base() ) {
    216229                                        Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers();
Note: See TracChangeset for help on using the changeset viewer.