Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6f4b7f2 rf685679  
    397397                ThrowStmt::Kind kind;
    398398                switch (node->kind) {
    399                 case ast::ExceptionKind::Terminate:
     399                case ast::ThrowStmt::Terminate:
    400400                        kind = ThrowStmt::Terminate;
    401401                        break;
    402                 case ast::ExceptionKind::Resume:
     402                case ast::ThrowStmt::Resume:
    403403                        kind = ThrowStmt::Resume;
    404404                        break;
     
    429429                CatchStmt::Kind kind;
    430430                switch (node->kind) {
    431                 case ast::ExceptionKind::Terminate:
     431                case ast::CatchStmt::Terminate:
    432432                        kind = CatchStmt::Terminate;
    433433                        break;
    434                 case ast::ExceptionKind::Resume:
     434                case ast::CatchStmt::Resume:
    435435                        kind = CatchStmt::Resume;
    436436                        break;
     
    704704        }
    705705
     706        bool isIntlikeConstantType(const ast::Type *t) {
     707                if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) {
     708                        if ( basicType->isInteger() ) {
     709                                return true;
     710                        }
     711                } else if ( dynamic_cast< const ast::OneType * >( t ) ) {
     712                        return true;
     713                } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) {
     714                        return true;
     715                } else if ( dynamic_cast< const ast::PointerType * >( t ) ) {
     716                        // null pointer constants, with zero int-values
     717                        return true;
     718                }
     719                return false;
     720        }
     721
     722        bool isFloatlikeConstantType(const ast::Type *t) {
     723                if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) {
     724                        if ( ! bty->isInteger() ) {
     725                                return true;
     726                        }
     727                }
     728                return false;
     729        }
     730
     731        bool isStringlikeConstantType(const ast::Type *t) {
     732                if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) {
     733                        if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) {
     734                           if ( bty->kind == ast::BasicType::Kind::Char ) {
     735                                   return true;
     736                           }
     737                        }
     738                }
     739                return false;
     740        }
     741
    706742        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    707743                ConstantExpr *rslt = nullptr;
    708                 switch ( node->kind ) {
    709                 case ast::ConstantExpr::Integer:
    710                         rslt = new ConstantExpr{Constant{
    711                                 get<Type>().accept1( node->result ),
     744                if (isIntlikeConstantType(node->result)) {
     745                        rslt = new ConstantExpr(Constant(
     746                                get<Type>().accept1(node->result),
    712747                                node->rep,
    713748                                (unsigned long long) node->intValue()
    714                         }};
    715                         break;
    716                 case ast::ConstantExpr::FloatingPoint:
    717                         rslt = new ConstantExpr{Constant{
     749                        ));
     750                } else if (isFloatlikeConstantType(node->result)) {
     751                        rslt = new ConstantExpr(Constant(
    718752                                get<Type>().accept1(node->result),
    719753                                node->rep,
    720754                                (double) node->floatValue()
    721                         }};
    722                         break;
    723                 case ast::ConstantExpr::String:
    724                         rslt = new ConstantExpr{Constant::from_string( node->rep )};
    725                         break;
     755                        ));
     756                } else if (isStringlikeConstantType(node->result)) {
     757                        rslt = new ConstantExpr(Constant::from_string(
     758                                node->rep
     759                        ));
    726760                }
    727761                assert(rslt);
     
    17391773        virtual void visit( ThrowStmt * old ) override final {
    17401774                if ( inCache( old ) ) return;
    1741                 ast::ExceptionKind kind;
     1775                ast::ThrowStmt::Kind kind;
    17421776                switch (old->kind) {
    17431777                case ThrowStmt::Terminate:
    1744                         kind = ast::ExceptionKind::Terminate;
     1778                        kind = ast::ThrowStmt::Terminate;
    17451779                        break;
    17461780                case ThrowStmt::Resume:
    1747                         kind = ast::ExceptionKind::Resume;
     1781                        kind = ast::ThrowStmt::Resume;
    17481782                        break;
    17491783                default:
     
    17751809        virtual void visit( CatchStmt * old ) override final {
    17761810                if ( inCache( old ) ) return;
    1777                 ast::ExceptionKind kind;
     1811                ast::CatchStmt::Kind kind;
    17781812                switch (old->kind) {
    17791813                case CatchStmt::Terminate:
    1780                         kind = ast::ExceptionKind::Terminate;
     1814                        kind = ast::CatchStmt::Terminate;
    17811815                        break;
    17821816                case CatchStmt::Resume:
    1783                         kind = ast::ExceptionKind::Resume;
     1817                        kind = ast::CatchStmt::Resume;
    17841818                        break;
    17851819                default:
Note: See TracChangeset for help on using the changeset viewer.