Changeset 5b51f5e for src/SynTree


Ignore:
Timestamp:
Jan 5, 2018, 3:21:42 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
65deb18, cae28da
Parents:
5c4f2c2 (diff), b834e98 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SynTree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AggregateDecl.cc

    r5c4f2c2 r5b51f5e  
    8686std::string TraitDecl::typeString() const { return "trait"; }
    8787
     88namespace {
     89        long long int getConstValue( Expression * expr ) {
     90                if ( CastExpr * castExpr = dynamic_cast< CastExpr * > ( expr ) ) {
     91                        return getConstValue( castExpr->arg );
     92                } else if ( ConstantExpr * constExpr = dynamic_cast< ConstantExpr * >( expr ) ) {
     93                        return constExpr->intValue();
     94                } else {
     95                        assertf( false, "Unhandled expression type in getConstValue for enumerators: %s", toString( expr ).c_str() );
     96                }
     97        }
     98}
     99
     100bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) {
     101        if ( enumValues.empty() ) {
     102                long long int currentValue = 0;
     103                for ( Declaration * member : members ) {
     104                        ObjectDecl * field = strict_dynamic_cast< ObjectDecl * >( member );
     105                        if ( field->init ) {
     106                                SingleInit * init = strict_dynamic_cast< SingleInit * >( field->init );
     107                                currentValue = getConstValue( init->value );
     108                        }
     109                        assertf( enumValues.count( field->name ) == 0, "Enum %s has multiple members with the name %s", name.c_str(), field->name.c_str() );
     110                        enumValues[ field->name ] = currentValue;
     111                        ++currentValue;
     112                }
     113        }
     114        if ( enumValues.count( enumerator->name ) ) {
     115                value = enumValues[ enumerator->name ];
     116                return true;
     117        }
     118        return false;
     119}
     120
    88121// Local Variables: //
    89122// tab-width: 4 //
  • src/SynTree/Declaration.h

    r5c4f2c2 r5b51f5e  
    319319        EnumDecl( const EnumDecl &other ) : Parent( other ) {}
    320320
     321        bool valueOf( Declaration * enumerator, long long int & value );
     322
    321323        virtual EnumDecl *clone() const override { return new EnumDecl( *this ); }
    322324        virtual void accept( Visitor &v ) override { v.visit( this ); }
    323325        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    324326  private:
     327        std::map< std::string, long long int > enumValues;
    325328        virtual std::string typeString() const override;
    326329};
  • src/SynTree/Expression.cc

    r5c4f2c2 r5b51f5e  
    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 );
     
    589602        if ( ! body.empty() ) {
    590603                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
    591                         set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
     604                        result = maybeClone( exprStmt->expr->result );
    592605                }
    593606        }
    594607        // ensure that StmtExpr has a result type
    595608        if ( ! result ) {
    596                 set_result( new VoidType( Type::Qualifiers() ) );
     609                result = new VoidType( Type::Qualifiers() );
    597610        }
    598611}
  • src/SynTree/Expression.h

    r5c4f2c2 r5b51f5e  
    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 ); }
  • src/SynTree/Type.h

    r5c4f2c2 r5b51f5e  
    356356        bool isTtype() const;
    357357
     358        bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; }
     359
    358360        virtual FunctionType *clone() const override { return new FunctionType( *this ); }
    359361        virtual void accept( Visitor & v ) override { v.visit( this ); }
Note: See TracChangeset for help on using the changeset viewer.