Changes in src/AST/Convert.cpp [0b57626:20a5977]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r0b57626 r20a5977 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-values713 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 738 702 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 739 703 ConstantExpr *rslt = nullptr; 740 if (isIntlikeConstantType(node->result)) { 741 rslt = new ConstantExpr(Constant( 742 get<Type>().accept1(node->result), 704 switch ( node->kind ) { 705 case ast::ConstantExpr::Integer: 706 rslt = new ConstantExpr{Constant{ 707 get<Type>().accept1( node->result ), 743 708 node->rep, 744 709 (unsigned long long) node->intValue() 745 )); 746 } else if (isFloatlikeConstantType(node->result)) { 747 rslt = new ConstantExpr(Constant( 710 }}; 711 break; 712 case ast::ConstantExpr::FloatingPoint: 713 rslt = new ConstantExpr{Constant{ 748 714 get<Type>().accept1(node->result), 749 715 node->rep, 750 716 (double) node->floatValue() 751 ));752 } else if (isStringlikeConstantType(node->result)) {753 rslt = new ConstantExpr(Constant::from_string(754 node->rep755 ));717 }}; 718 break; 719 case ast::ConstantExpr::String: 720 rslt = new ConstantExpr{Constant::from_string( node->rep )}; 721 break; 756 722 } 757 723 assert(rslt);
Note:
See TracChangeset
for help on using the changeset viewer.