Changeset ddb80bd


Ignore:
Timestamp:
Dec 22, 2017, 4:16:53 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
fc9153d
Parents:
fdd0509
Message:

Add intValue helper function to ConstantExpr?

Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    rfdd0509 rddb80bd  
    8383}
    8484
     85long long int ConstantExpr::intValue() const {
     86        if ( BasicType * basicType = dynamic_cast< BasicType * >( result ) ) {
     87                if ( basicType->isInteger() ) {
     88                        return get_constant()->get_ival();
     89                }
     90        } else if ( dynamic_cast< OneType * >( result ) ) {
     91                return 1;
     92        } else if ( dynamic_cast< ZeroType * >( result ) ) {
     93                return 0;
     94        }
     95        throw SemanticError( "Constant expression of non-integral type ", this );
     96}
     97
    8598VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
    8699        assert( var );
  • src/SynTree/Expression.h

    rfdd0509 rddb80bd  
    295295
    296296        Constant * get_constant() { return & constant; }
     297        const Constant * get_constant() const { return & constant; }
    297298        void set_constant( const Constant & newValue ) { constant = newValue; }
     299
     300        long long int intValue() const;
    298301
    299302        virtual ConstantExpr * clone() const { return new ConstantExpr( * this ); }
Note: See TracChangeset for help on using the changeset viewer.