Changeset c36298d for src/AST/Expr.cpp


Ignore:
Timestamp:
Jun 17, 2019, 11:01:04 AM (6 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:
b4d34fa
Parents:
6a1dfda
Message:

Fixed handling of "literals.cfa" string-detail test cases by simplifying constant analysis. Now a ConstantExpr? is a minial passthrough from parser to code generator, with special-case analysis only for integer values. Awareness of how to build a string-constant type is back in ExpressionNode?.cc; now, this knowlede is only needed there. AST conversion no longer specializes string-int-float constants; it just converts types and passes values through. Unused constant API features are removed, notably from-to-float and from-string.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r6a1dfda rc36298d  
    194194        if ( const BasicType * bty = result.as< BasicType >() ) {
    195195                if ( bty->isInteger() ) {
    196                         return val.ival;
     196                        assert(ival);
     197                        return ival.value();
    197198                }
    198199        } else if ( result.as< ZeroType >() ) {
     
    204205}
    205206
    206 double ConstantExpr::floatValue() const {
    207         if ( const BasicType * bty = result.as< BasicType >() ) {
    208                 if ( ! bty->isInteger() ) {
    209                         return val.dval;
    210                 }
    211         }
    212         SemanticError( this, "Constant expression of non-floating-point type " );
    213 }
    214 
    215207ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
    216208        return new ConstantExpr{
    217209                loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b };
    218 }
    219 
    220 ConstantExpr * ConstantExpr::from_char( const CodeLocation & loc, char c ) {
    221         return new ConstantExpr{
    222                 loc, new BasicType{ BasicType::Char }, std::to_string( c ), (unsigned long long)c };
    223210}
    224211
     
    232219                loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ),
    233220                (unsigned long long)i };
    234 }
    235 
    236 ConstantExpr * ConstantExpr::from_double( const CodeLocation & loc, double d ) {
    237         return new ConstantExpr{ loc, new BasicType{ BasicType::Double }, std::to_string( d ), d };
    238221}
    239222
Note: See TracChangeset for help on using the changeset viewer.