Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r20a5977 r0b57626  
    700700        }
    701701
     702        bool isIntlikeConstantType(const ast::Type *t) {
     703                if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) {
     704                        if ( basicType->isInteger() ) {
     705                                return true;
     706                        }
     707                } else if ( dynamic_cast< const ast::OneType * >( t ) ) {
     708                        return true;
     709                } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) {
     710                        return true;
     711                } else if ( dynamic_cast< const ast::PointerType * >( t ) ) {
     712                        // null pointer constants, with zero int-values
     713                        return true;
     714                }
     715                return false;
     716        }
     717
     718        bool isFloatlikeConstantType(const ast::Type *t) {
     719                if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) {
     720                        if ( ! bty->isInteger() ) {
     721                                return true;
     722                        }
     723                }
     724                return false;
     725        }
     726
     727        bool isStringlikeConstantType(const ast::Type *t) {
     728                if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) {
     729                        if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) {
     730                           if ( bty->kind == ast::BasicType::Kind::Char ) {
     731                                   return true;
     732                           }
     733                        }
     734                }
     735                return false;
     736        }
     737
    702738        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    703739                ConstantExpr *rslt = nullptr;
    704                 switch ( node->kind ) {
    705                 case ast::ConstantExpr::Integer:
    706                         rslt = new ConstantExpr{Constant{
    707                                 get<Type>().accept1( node->result ),
     740                if (isIntlikeConstantType(node->result)) {
     741                        rslt = new ConstantExpr(Constant(
     742                                get<Type>().accept1(node->result),
    708743                                node->rep,
    709744                                (unsigned long long) node->intValue()
    710                         }};
    711                         break;
    712                 case ast::ConstantExpr::FloatingPoint:
    713                         rslt = new ConstantExpr{Constant{
     745                        ));
     746                } else if (isFloatlikeConstantType(node->result)) {
     747                        rslt = new ConstantExpr(Constant(
    714748                                get<Type>().accept1(node->result),
    715749                                node->rep,
    716750                                (double) node->floatValue()
    717                         }};
    718                         break;
    719                 case ast::ConstantExpr::String:
    720                         rslt = new ConstantExpr{Constant::from_string( node->rep )};
    721                         break;
     751                        ));
     752                } else if (isStringlikeConstantType(node->result)) {
     753                        rslt = new ConstantExpr(Constant::from_string(
     754                                node->rep
     755                        ));
    722756                }
    723757                assert(rslt);
Note: See TracChangeset for help on using the changeset viewer.