Changeset 89e6ffc for src/ResolvExpr


Ignore:
Timestamp:
Sep 19, 2016, 5:23:41 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
a6fe3de
Parents:
fc4a0fa
Message:

Added support for ZeroType? and OneType? to all relevant visitors

Location:
src/ResolvExpr
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AdjustExprType.cc

    rfc4a0fa r89e6ffc  
    3737                virtual Type* mutate( TupleType *tupleType );
    3838                virtual Type* mutate( VarArgsType *varArgsType );
     39                virtual Type* mutate( ZeroType *zeroType );
     40                virtual Type* mutate( OneType *oneType );
    3941
    4042                const TypeEnvironment &env;
     
    117119                return varArgsType;
    118120        }
     121
     122        Type *AdjustExprType::mutate( ZeroType *zeroType ) {
     123                return zeroType;
     124        }
     125
     126        Type *AdjustExprType::mutate( OneType *oneType ) {
     127                return oneType;
     128        }
    119129} // namespace ResolvExpr
    120130
  • src/ResolvExpr/CommonType.cc

    rfc4a0fa r89e6ffc  
    3939                virtual void visit( TupleType *tupleType );
    4040                virtual void visit( VarArgsType *varArgsType );
     41                virtual void visit( ZeroType *zeroType );
     42                virtual void visit( OneType *oneType );
    4143
    4244                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    134136                                result = new BasicType( basicType->get_qualifiers() + otherBasic->get_qualifiers(), newType );
    135137                        } // if
    136                 } else if ( EnumInstType *enumInstType = dynamic_cast< EnumInstType * > ( type2 ) ) {
    137                         // use signed int in lieu of the enum type
     138                } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
     139                        // use signed int in lieu of the enum/zero/one type
    138140                        BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ];
    139                         if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= enumInstType->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= enumInstType->get_qualifiers() ) || widenSecond ) ) {
    140                                 result = new BasicType( basicType->get_qualifiers() + enumInstType->get_qualifiers(), newType );
     141                        if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) {
     142                                result = new BasicType( basicType->get_qualifiers() + type2->get_qualifiers(), newType );
    141143                        } // if
    142144                } // if
     
    171173                                otherPointer->get_base()->get_qualifiers() = tq2;
    172174                        } // if
     175                } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
     176                        result = pointerType->clone();
     177                        result->get_qualifiers() += type2->get_qualifiers();
    173178                } // if
    174179        }
     
    190195
    191196        void CommonType::visit( EnumInstType *enumInstType ) {
    192                 if ( dynamic_cast< BasicType * >( type2 ) ) {
     197                if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
    193198                        // reuse BasicType, EnumInstType code by swapping type2 with enumInstType
    194199                        Type * temp = type2;
     
    230235        void CommonType::visit( VarArgsType *varArgsType ) {
    231236        }
     237
     238        void CommonType::visit( ZeroType *zeroType ) {
     239                if ( widenFirst ) {
     240                        if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
     241                                if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) {
     242                                        result = type2->clone();
     243                                        result->get_qualifiers() += zeroType->get_qualifiers();
     244                                }
     245                        }
     246                }
     247        }
     248
     249        void CommonType::visit( OneType *oneType ) {
     250                if ( widenFirst ) {
     251                        if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
     252                                if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) {
     253                                        result = type2->clone();
     254                                        result->get_qualifiers() += oneType->get_qualifiers();
     255                                }
     256                        }
     257                }
     258        }
    232259} // namespace ResolvExpr
    233260
  • src/ResolvExpr/ConversionCost.cc

    rfc4a0fa r89e6ffc  
    160160                        // xxx - not positive this is correct, but appears to allow casting int => enum
    161161                        cost = Cost( 1, 0, 0 );
    162     } // if
     162                } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
     163                        cost = Cost( 1, 0, 0 );
     164                } // if
    163165        }
    164166
     
    175177                                } // if
    176178                        } // if
     179                } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
     180                        cost = Cost( 1, 0, 0 );
    177181                } // if
    178182        }
     
    256260                }
    257261        }
     262
     263        void ConversionCost::visit(ZeroType *zeroType) {
     264                if ( dynamic_cast< ZeroType* >( dest ) ) {
     265                        cost = Cost::zero;
     266                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
     267                        // copied from visit(BasicType*) for signed int, but +1 for safe conversions
     268                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
     269                        if ( tableResult == -1 ) {
     270                                cost = Cost( 1, 0, 0 );
     271                        } else {
     272                                cost = Cost( 0, 0, tableResult + 1 );
     273                        }
     274                } else if ( dynamic_cast< PointerType* >( dest ) ) {
     275                        cost = Cost( 0, 0, 1 );
     276                }
     277        }
     278
     279        void ConversionCost::visit(OneType *oneType) {
     280                if ( dynamic_cast< OneType* >( dest ) ) {
     281                        cost = Cost::zero;
     282                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
     283                        // copied from visit(BasicType*) for signed int, but +1 for safe conversions
     284                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
     285                        if ( tableResult == -1 ) {
     286                                cost = Cost( 1, 0, 0 );
     287                        } else {
     288                                cost = Cost( 0, 0, tableResult + 1 );
     289                        }
     290                }
     291        }
    258292} // namespace ResolvExpr
    259293
  • src/ResolvExpr/ConversionCost.h

    rfc4a0fa r89e6ffc  
    4141                virtual void visit(TupleType *tupleType);
    4242                virtual void visit(VarArgsType *varArgsType);
     43                virtual void visit(ZeroType *zeroType);
     44                virtual void visit(OneType *oneType);
    4345          protected:
    4446                Type *dest;
  • src/ResolvExpr/PtrsAssignable.cc

    rfc4a0fa r89e6ffc  
    3939                virtual void visit( TupleType *tupleType );
    4040                virtual void visit( VarArgsType *varArgsType );
     41                virtual void visit( ZeroType *zeroType );
     42                virtual void visit( OneType *oneType );
    4143          private:
    4244                Type *dest;
     
    141143        void PtrsAssignable::visit( VarArgsType *varArgsType ) {
    142144        }
     145
     146        void PtrsAssignable::visit( ZeroType *zeroType ) {
     147        }
     148       
     149        void PtrsAssignable::visit( OneType *oneType ) {
     150        }
     151       
    143152} // namespace ResolvExpr
    144153
  • src/ResolvExpr/PtrsCastable.cc

    rfc4a0fa r89e6ffc  
    4040                virtual void visit(TupleType *tupleType);
    4141                virtual void visit(VarArgsType *varArgsType);
     42                virtual void visit(ZeroType *zeroType);
     43                virtual void visit(OneType *oneType);
    4244          private:
    4345                Type *dest;
     
    144146                result = objectCast( dest, env, indexer );
    145147        }
     148
     149        void PtrsCastable::visit(ZeroType *zeroType) {
     150                result = objectCast( dest, env, indexer );
     151        }
     152
     153        void PtrsCastable::visit(OneType *oneType) {
     154                result = objectCast( dest, env, indexer );
     155        }
    146156} // namespace ResolvExpr
    147157
  • src/ResolvExpr/RenameVars.cc

    rfc4a0fa r89e6ffc  
    110110        }
    111111
     112        void RenameVars::visit( ZeroType *zeroType ) {
     113                typeBefore( zeroType );
     114                typeAfter( zeroType );
     115        }
     116
     117        void RenameVars::visit( OneType *oneType ) {
     118                typeBefore( oneType );
     119                typeAfter( oneType );
     120        }
     121
    112122        void RenameVars::typeBefore( Type *type ) {
    113123                if ( ! type->get_forall().empty() ) {
  • src/ResolvExpr/RenameVars.h

    rfc4a0fa r89e6ffc  
    4444                virtual void visit( TupleType *tupleType );
    4545                virtual void visit( VarArgsType *varArgsType );
     46                virtual void visit( ZeroType *zeroType );
     47                virtual void visit( OneType *oneType );
    4648
    4749                void typeBefore( Type *type );
  • src/ResolvExpr/Resolver.cc

    rfc4a0fa r89e6ffc  
    133133                        } else if ( BasicType *bt = dynamic_cast< BasicType * >( type ) ) {
    134134                                return bt->isInteger();
     135                        } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) {
     136                                return true;
    135137                        } else {
    136138                                return false;
     
    459461                        }
    460462                } else {
    461                         assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) );
     463                        assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext )
     464                                || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) );
    462465                        // basic types are handled here
    463466                        Visitor::visit( listInit );
  • src/ResolvExpr/Unify.cc

    rfc4a0fa r89e6ffc  
    6060                virtual void visit(TupleType *tupleType);
    6161                virtual void visit(VarArgsType *varArgsType);
     62                virtual void visit(ZeroType *zeroType);
     63                virtual void visit(OneType *oneType);
    6264
    6365                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    588590        }
    589591
     592        void Unify::visit(ZeroType *zeroType) {
     593                result = dynamic_cast< ZeroType* >( type2 );
     594        }
     595
     596        void Unify::visit(OneType *oneType) {
     597                result = dynamic_cast< OneType* >( type2 );
     598        }
     599
    590600} // namespace ResolvExpr
    591601
Note: See TracChangeset for help on using the changeset viewer.