Changes in src/AST/Convert.cpp [20a5977:0b57626]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r20a5977 r0b57626 700 700 } 701 701 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 702 738 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 703 739 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), 708 743 node->rep, 709 744 (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( 714 748 get<Type>().accept1(node->result), 715 749 node->rep, 716 750 (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 )); 722 756 } 723 757 assert(rslt);
Note:
See TracChangeset
for help on using the changeset viewer.