Changeset 558d13b


Ignore:
Timestamp:
Jun 10, 2019, 2:42:31 PM (5 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5485e10, 86a8be5
Parents:
6949c45
Message:

fix conversion bug in constants; string constants were being mistaken for int after resolution when their type changes from char[k] to char*

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6949c45 r558d13b  
    21912191
    21922192        int isStringlikeConstantType(const Type *t) {
     2193                const Type *referentType = nullptr;
    21932194                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
    2194                         if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
     2195                        referentType = aty->base;
     2196                } else if ( const PointerType * pty = dynamic_cast< const PointerType * >( t ) ) {
     2197                        referentType = pty->base;
     2198                }
     2199                if (referentType) {
     2200                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( referentType ) ) {
    21952201                           if ( bty->kind == BasicType::Kind::Char ) {
    21962202                                   return true;
     
    22032209        virtual void visit( ConstantExpr * old ) override final {
    22042210                ast::ConstantExpr *rslt = nullptr;
    2205                 if (isIntlikeConstantType(old->result)) {
     2211                if (isStringlikeConstantType(old->result)) {
     2212                        rslt = new ast::ConstantExpr(
     2213                                old->location,
     2214                                GET_ACCEPT_1(result, Type),
     2215                                old->constant.get_value(),
     2216                                0,
     2217                                ast::ConstantExpr::Kind::String
     2218                        );
     2219                } else if (isIntlikeConstantType(old->result)) {
    22062220                        rslt = new ast::ConstantExpr(
    22072221                                old->location,
     
    22172231                                old->constant.get_value(),
    22182232                                (double) old->constant.get_dval()
    2219                         );
    2220                 } else if (isStringlikeConstantType(old->result)) {
    2221                         rslt = new ast::ConstantExpr(
    2222                                 old->location,
    2223                                 GET_ACCEPT_1(result, Type),
    2224                                 old->constant.get_value(),
    2225                                 0,
    2226                                 ast::ConstantExpr::Kind::String
    22272233                        );
    22282234                }
Note: See TracChangeset for help on using the changeset viewer.