Changeset e8ccca3 for src


Ignore:
Timestamp:
Sep 1, 2017, 3:33:19 PM (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:
78a0b88
Parents:
76c62b2
Message:

second attempt at user-defined constants (units)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r76c62b2 re8ccca3  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 31 21:05:04 2017
    13 // Update Count     : 605
     12// Last Modified On : Fri Sep  1 15:07:09 2017
     13// Update Count     : 618
    1414//
    1515
     
    6161        string::size_type posn = str.find_first_of( "`" );
    6262        if ( posn != string::npos ) {
    63                 units = str.substr( posn );                                             // extract units
     63                units = "?" + str.substr( posn );                               // extract units
    6464                str.erase( posn );                                                              // remove units
    6565        } // if
     
    145145        } // if
    146146
    147 //      if ( units.length() == 0 ) {
    148                 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    149 //      } else {
    150 //              // ROB: generate call to units routine
    151 //              ret = nullptr;
    152 //      } // if
     147        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
    153148  CLEANUP:
     149        if ( units.length() != 0 ) {
     150                ret = new UntypedExpr( new NameExpr( units, ret ) );
     151        } // if
     152
    154153        delete &str;                                                                            // created by lex
    155154        return ret;
     
    189188        } // if
    190189
    191         Expression * ret;
    192 //      if ( units.length() == 0 ) {
    193                 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
    194 //      } else {
    195 //              ret = nullptr;
    196 //              // ROB: generate call to units routine
    197 //      } // if
     190        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) );
     191        if ( units.length() != 0 ) {
     192                ret = new UntypedExpr( new NameExpr( units, ret ) );
     193        } // if
    198194
    199195        delete &str;                                                                            // created by lex
     
    204200        string::size_type posn = str.find_last_of( delimit ) + 1;
    205201        if ( posn != str.length() ) {
    206                 units = str.substr( posn );                                             // extract units
     202                units = "?" + str.substr( posn );                               // extract units
    207203                str.erase( posn );                                                              // remove units
    208204        } // if
     
    213209        sepString( str, units, '\'' );                                          // separate constant from units
    214210
    215         Expression * ret;
    216 //      if ( units.length() == 0 ) {
    217                 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
    218 //      } else {
    219 //              ret = nullptr;
    220 //              // ROB: generate call to units routine
    221 //      } // if
     211        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
     212        if ( units.length() != 0 ) {
     213                ret = new UntypedExpr( new NameExpr( units, ret ) );
     214        } // if
    222215
    223216        delete &str;                                                                            // created by lex
     
    229222        sepString( str, units, '"' );                                           // separate constant from units
    230223
    231         ConstantExpr * ret;
    232 //      if ( units.length() == 0 ) {
    233                 // string should probably be a primitive type
    234                 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    235                                                                                 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    236                                                                                 false, false );
    237                 ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
    238 //      } else {
    239 //              ret = nullptr;
    240 //              // ROB: generate call to units routine
    241 //      } // if
     224        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     225                                                                        new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
     226                                                                        false, false );
     227        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
     228// ROB: type mismatch
     229        // if ( units.length() != 0 ) {
     230        //      ret = new UntypedExpr( new NameExpr( units, ret ) );
     231        // } // if
    242232               
    243233        delete &str;                                                                            // created by lex
Note: See TracChangeset for help on using the changeset viewer.