Ignore:
Timestamp:
Sep 12, 2017, 10:19:47 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
28b8949
Parents:
ea0c5e3
Message:

handle "z" suffix cast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    rea0c5e3 rbeec62c  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 11 16:06:42 2017
    13 // Update Count     : 666
     12// Last Modified On : Tue Sep 12 10:00:29 2017
     13// Update Count     : 672
    1414//
    1515
     
    4949// type.
    5050
    51 extern const Type::Qualifiers noQualifiers;             // no qualifiers on constants
     51extern const Type::Qualifiers noQualifiers;                             // no qualifiers on constants
    5252
    5353static inline bool checkH( char c ) { return c == 'h' || c == 'H'; }
     
    7979
    8080        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    81         int size;                                                                                       // 0 => int, 1 => long, 2 => long long
     81        int size;                                                                                       // 0 => short, 1 => char, 2 => int, 3 => long int, 4 => long long int, 5 => size_t
    8282        unsigned long long int v;                                                       // converted integral value
    8383        size_t last = str.length() - 1;                                         // last character of constant
     
    163163                str.erase( last - size, size + 1 );                             // remove 'h'/"hh"
    164164        } else if ( checkZ( str[last] ) ) {                                     // suffix 'z' ?
     165                size = 5;
    165166                str.erase( last, 1 );                                                   // remove 'z'
    166167        } // if
     
    168169        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    169170        if ( Unsigned && size < 2 ) {                                           // less than int ?
    170                 // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates some warnings for large
    171                 // values.
     171                // int i = -1uh => 65535 not -1, so cast is necessary for unsigned, which eliminates warnings for large values.
    172172                ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][size] ) );
     173        } else if ( size == 5 ) {                                                       // explicit cast to size_t
     174                ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), "size_t", false ) );
    173175        } // if
    174176  CLEANUP:
Note: See TracChangeset for help on using the changeset viewer.