Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/PtrsAssignable.cc

    r5ccb10d rb0837e4  
    1414//
    1515
    16 #include "typeops.h"
    17 #include "SynTree/Type.h"
    18 #include "SynTree/Declaration.h"
    19 #include "SynTree/Visitor.h"
     16#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
     17#include "SynTree/Type.h"                // for TypeInstType, Type, BasicType
     18#include "SynTree/Visitor.h"             // for Visitor
    2019
    2120
     
    4847
    4948        int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ) {
     49                // std::cerr << "assignable: " << src << " | " << dest << std::endl;
    5050                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    5151                        EqvClass eqvClass;
     
    5555                } // if
    5656                if ( dynamic_cast< VoidType* >( dest ) ) {
    57                         return 1;
     57                        // void * = T * for any T is unsafe
     58                        // xxx - this should be safe, but that currently breaks the build
     59                        return -1;
    5860                } else {
    5961                        PtrsAssignable ptrs( dest, env );
     
    6668
    6769        void PtrsAssignable::visit( __attribute((unused)) VoidType *voidType ) {
    68                 if ( dynamic_cast< FunctionType* >( dest ) ) {
    69                         result = 0;
    70                 } else {
    71                         result = -1;
     70                if ( ! dynamic_cast< FunctionType* >( dest ) ) {
     71                        // T * = void * is safe for any T that is not a function type.
     72                        // xxx - this should be unsafe...
     73                        result = 1;
    7274                } // if
    7375        }
     
    7678        void PtrsAssignable::visit( __attribute__((unused)) PointerType *pointerType ) {}
    7779        void PtrsAssignable::visit( __attribute__((unused)) ArrayType *arrayType ) {}
    78         void PtrsAssignable::visit( __attribute__((unused)) FunctionType *functionType ) {
    79                 result = -1;
    80         }
     80        void PtrsAssignable::visit( __attribute__((unused)) FunctionType *functionType ) {}
    8181
    8282        void PtrsAssignable::visit(  __attribute__((unused)) StructInstType *inst ) {}
     
    8484
    8585        void PtrsAssignable::visit( EnumInstType * ) {
    86                 if ( dynamic_cast< EnumInstType* >( dest ) ) {
     86                if ( dynamic_cast< BasicType* >( dest ) ) {
     87                        // int * = E *, etc. is safe. This isn't technically correct, as each
     88                        // enum has one basic type that it is compatible with, an that type can
     89                        // differ from enum to enum. Without replicating GCC's internal logic,
     90                        // there is no way to know which type this particular enum is compatible
     91                        // with, so punt on this for now.
    8792                        result = 1;
    88                 } else if ( BasicType *bt = dynamic_cast< BasicType* >( dest ) ) {
    89                         result = bt->get_kind() == BasicType::SignedInt;
    9093                }
    9194        }
     
    9598                EqvClass eqvClass;
    9699                if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) {
     100                        // T * = S * for any S depends on the type bound to T
    97101                        result = ptrsAssignable( eqvClass.type, dest, env );
    98                 } else {
    99                         result = 0;
    100102                } // if
    101103        }
Note: See TracChangeset for help on using the changeset viewer.