Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rc36298d r60aaa51d  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 15 17:00:00 2019
    11 // Last Modified By : Andrew Beach
    12 // Created On       : Thr Jun 13 13:38:00 2019
    13 // Update Count     : 2
     11// Last Modified By : Aaron B. Moss
     12// Created On       : Wed May 15 17:00:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    194194        if ( const BasicType * bty = result.as< BasicType >() ) {
    195195                if ( bty->isInteger() ) {
    196                         assert(ival);
    197                         return ival.value();
     196                        return val.ival;
    198197                }
    199198        } else if ( result.as< ZeroType >() ) {
     
    205204}
    206205
     206double 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
    207215ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
    208216        return new ConstantExpr{
    209217                loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b };
     218}
     219
     220ConstantExpr * 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 };
    210223}
    211224
     
    219232                loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ),
    220233                (unsigned long long)i };
     234}
     235
     236ConstantExpr * ConstantExpr::from_double( const CodeLocation & loc, double d ) {
     237        return new ConstantExpr{ loc, new BasicType{ BasicType::Double }, std::to_string( d ), d };
     238}
     239
     240ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & s ) {
     241        return new ConstantExpr{
     242                loc,
     243                new ArrayType{
     244                        new BasicType{ BasicType::Char, CV::Const },
     245                        ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ),
     246                        FixedLen, DynamicDim },
     247                std::string{"\""} + s + "\"",
     248                (unsigned long long)0,
     249                ConstantExpr::String };
    221250}
    222251
     
    353382
    354383UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i )
    355 : Expr( loc, e->result ), expr( e ), id( i ) {
     384: Expr( loc, e->result ), id( i ) {
    356385        assert( expr );
    357386        if ( id == -1ull ) {
Note: See TracChangeset for help on using the changeset viewer.