Changes in / [ac1ed49:44b7088]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    rac1ed49 r44b7088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Unify.cc --
     7// Unify.cc -- 
    88//
    99// Author           : Richard C. Bilson
     
    3838                WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; }
    3939                operator bool() { return widenFirst && widenSecond; }
    40 
     40 
    4141                bool widenFirst : 1, widenSecond : 1;
    4242        };
     
    4545          public:
    4646                Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    47 
     47 
    4848                bool get_result() const { return result; }
    4949          private:
     
    7979        bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common );
    8080        bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    81 
     81 
    8282        bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    8383                TypeEnvironment newEnv;
     
    137137                  case TypeDecl::Dtype:
    138138                        return ! isFtype( type, indexer );
    139 
     139 
    140140                  case TypeDecl::Ftype:
    141141                        return isFtype( type, indexer );
     
    196196                bool widen1 = false, widen2 = false;
    197197                Type *type1 = 0, *type2 = 0;
    198 
     198 
    199199                if ( env.lookup( var1->get_name(), class1 ) ) {
    200200                        hasClass1 = true;
     
    217217                        widen2 = widenMode.widenSecond && class2.allowWidening;
    218218                } // if
    219 
     219 
    220220                if ( type1 && type2 ) {
    221221//    std::cout << "has type1 && type2" << std::endl;
     
    436436                // to unify, array types must both be VLA or both not VLA
    437437                // and must both have a dimension expression or not have a dimension
    438                 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
     438                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen()
     439                                && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0)
     440                                        || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) {
    439441
    440442                        // not positive this is correct in all cases, but it's needed for typedefs
     
    447449                                ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() );
    448450                                ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() );
    449                                 // see C11 Reference Manual 6.7.6.2.6
    450                                 // two array types with size specifiers that are integer constant expressions are
    451                                 // compatible if both size specifiers have the same constant value
    452                                 if ( ce1 && ce2 ) {
    453                                         Constant * c1 = ce1->get_constant();
    454                                         Constant * c2 = ce2->get_constant();
    455 
    456                                         if ( c1->get_value() != c2->get_value() ) {
    457                                                 // does not unify if the dimension is different
    458                                                 return;
    459                                         }
     451                                assert(ce1 && ce2);
     452
     453                                Constant * c1 = ce1->get_constant();
     454                                Constant * c2 = ce2->get_constant();
     455
     456                                if ( c1->get_value() != c2->get_value() ) {
     457                                        // does not unify if the dimension is different
     458                                        return;
    460459                                }
    461460                        }
     
    486485
    487486                        if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    488 
     487       
    489488                                if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    490489
  • src/SynTree/Expression.cc

    rac1ed49 r44b7088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Expression.cc --
     7// Expression.cc -- 
    88//
    99// Author           : Richard C. Bilson
     
    422422}
    423423
    424 AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
    425 
    426 
    427424void AsmExpr::print( std::ostream &os, int indent ) const {
    428425        os << "Asm Expression: " << std::endl;
     
    432429}
    433430
    434 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
    435 
    436 UntypedValofExpr::~UntypedValofExpr() { delete body; }
    437 
    438431void UntypedValofExpr::print( std::ostream &os, int indent ) const {
    439432        os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
     
    441434                get_body()->print( os, indent + 2 );
    442435}
    443 
    444 
    445436
    446437std::ostream & operator<<( std::ostream & out, Expression * expr ) {
  • src/SynTree/Expression.h

    rac1ed49 r44b7088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Expression.h --
     7// Expression.h -- 
    88//
    99// Author           : Richard C. Bilson
     
    155155};
    156156
    157 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack
    158157class LabelAddressExpr : public Expression {
    159158  public:
    160159        LabelAddressExpr( Expression *arg );
    161         LabelAddressExpr( const LabelAddressExpr &other );
     160        LabelAddressExpr( const AddressExpr &other );
    162161        virtual ~LabelAddressExpr();
    163162
     
    252251};
    253252
    254 /// ConstantExpr represents an expression that simply refers to the value of a constant
     253/// ConstantExpr represents an expression that simply refers to the value of a constant 
    255254class ConstantExpr : public Expression {
    256255  public:
     
    516515  public:
    517516        AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    518         AsmExpr( const AsmExpr & other );
    519517        virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };
    520518
     
    543541  public:
    544542        UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {}
    545         UntypedValofExpr( const UntypedValofExpr & other );
    546         virtual ~UntypedValofExpr();
     543        virtual ~UntypedValofExpr() {}
    547544
    548545        Expression *get_value();
  • src/SynTree/Statement.cc

    rac1ed49 r44b7088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Statement.cc --
     7// Statement.cc -- 
    88//
    99// Author           : Richard C. Bilson
     
    3636ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
    3737
    38 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    39 
    40 ExprStmt::~ExprStmt() {
    41         delete expr;
    42 }
     38ExprStmt::~ExprStmt() {}
    4339
    4440void ExprStmt::print( std::ostream &os, int indent ) const {
    4541        os << string( indent, ' ' ) << "Expression Statement:" << endl;
    4642        expr->print( os, indent + 2 );
    47 }
     43} 
    4844
    4945
    5046AsmStmt::AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement( labels ), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    51 
    52 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
    53   cloneAll( other.output, output );
    54   cloneAll( other.input, input );
    55   cloneAll( other.clobber, clobber );
    56 }
    5747
    5848AsmStmt::~AsmStmt() {
     
    7060                os << endl << std::string( indent, ' ' ) << "output: " << endl;
    7161                printAll( output, os, indent + 2 );
    72         } // if
     62        } // if 
    7363        if ( ! input.empty() ) {
    7464                os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' );
     
    7969                printAll( clobber, os, indent + 2 );
    8070        } // if
    81 }
     71} 
    8272
    8373
     
    10393ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {}
    10494
    105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {}
    106 
    10795ReturnStmt::~ReturnStmt() {
    10896        delete expr;
     
    118106        Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
    119107
    120 IfStmt::IfStmt( const IfStmt & other ) :
    121         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
    122 
    123108IfStmt::~IfStmt() {}
    124109
     
    138123SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ):
    139124        Statement( _labels ), condition( _condition ), branches( _branches ) {
    140 }
    141 
    142 SwitchStmt::SwitchStmt( const SwitchStmt & other ):
    143         Statement( other ), condition( maybeClone( other.condition ) ) {
    144         cloneAll( other.branches, branches );
    145125}
    146126
     
    165145}
    166146
    167 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
     147CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 
    168148        Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
    169149        if ( isDefault() && condition != 0 )
    170150                throw SemanticError("default with conditions");
    171 }
    172 
    173 CaseStmt::CaseStmt( const CaseStmt & other ) :
    174         Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) {
    175         cloneAll( other.stmts, stmts );
    176151}
    177152
     
    206181}
    207182
    208 ChooseStmt::ChooseStmt( const ChooseStmt & other ):
    209         Statement( other ), condition( maybeClone( other.condition ) ) {
    210                 cloneAll( other.branches, branches );
    211 }
    212 
    213183ChooseStmt::~ChooseStmt() {
    214184        delete condition;
     
    238208}
    239209
    240 WhileStmt::WhileStmt( const WhileStmt & other ):
    241         Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
    242 }
    243 
    244210WhileStmt::~WhileStmt() {
    245211        delete body;
     
    257223ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    258224        Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
    259 }
    260 
    261 ForStmt::ForStmt( const ForStmt & other ):
    262         Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) {
    263                 cloneAll( other.initialization, initialization );
    264 
    265225}
    266226
     
    281241        os << string( indent, ' ' ) << "For Statement" << endl ;
    282242
    283         os << string( indent + 2, ' ' ) << "initialization: \n";
     243        os << string( indent + 2, ' ' ) << "initialization: \n"; 
    284244        for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
    285245                (*it)->print( os, indent + 4 );
    286246        }
    287247
    288         os << "\n" << string( indent + 2, ' ' ) << "condition: \n";
     248        os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 
    289249        if ( condition != 0 )
    290250                condition->print( os, indent + 4 );
    291251
    292         os << "\n" << string( indent + 2, ' ' ) << "increment: \n";
     252        os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 
    293253        if ( increment != 0 )
    294254                increment->print( os, indent + 4 );
    295255
    296         os << "\n" << string( indent + 2, ' ' ) << "statement block: \n";
     256        os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 
    297257        if ( body != 0 )
    298258                body->print( os, indent + 4 );
     
    305265}
    306266
    307 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    308         cloneAll( other.handlers, handlers );
     267TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) {
     268        block = other.block;
     269        std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) );
     270        finallyBlock = other.finallyBlock;
    309271}
    310272
     
    332294CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) :
    333295        Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) {
    334 }
    335 
    336 CatchStmt::CatchStmt( const CatchStmt & other ) :
    337         Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest ) {
    338296}
    339297
     
    361319}
    362320
    363 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {
    364 }
    365 
    366321FinallyStmt::~FinallyStmt() {
    367322        delete block;
     
    376331NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {}
    377332NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {}
     333NullStmt::~NullStmt() {}
    378334
    379335void NullStmt::print( std::ostream &os, int indent ) const {
  • src/SynTree/Statement.h

    rac1ed49 r44b7088  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Statement.h --
     7// Statement.h -- 
    88//
    99// Author           : Richard C. Bilson
     
    5757  public:
    5858        ExprStmt( std::list<Label> labels, Expression *expr );
    59         ExprStmt( const ExprStmt &other );
    6059        virtual ~ExprStmt();
    6160
     
    7473  public:
    7574        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    76         AsmStmt( const AsmStmt &other );
    7775        virtual ~AsmStmt();
    7876
     
    105103  public:
    106104        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    107         IfStmt( const IfStmt &other );
    108105        virtual ~IfStmt();
    109106
     
    114111        Statement *get_elsePart() { return elsePart; }
    115112        void set_elsePart( Statement *newValue ) { elsePart = newValue; }
    116 
     113       
    117114        virtual IfStmt *clone() const { return new IfStmt( *this ); }
    118115        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    128125  public:
    129126        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
    130         SwitchStmt( const SwitchStmt &other );
    131127        virtual ~SwitchStmt();
    132128
     
    150146  public:
    151147        ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
    152         ChooseStmt( const ChooseStmt &other );
    153148        virtual ~ChooseStmt();
    154149
     
    182177class CaseStmt : public Statement {
    183178  public:
    184         CaseStmt( std::list<Label> labels, Expression *conditions,
     179        CaseStmt( std::list<Label> labels, Expression *conditions, 
    185180              std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    186         CaseStmt( const CaseStmt &other );
    187181        virtual ~CaseStmt();
    188182
     
    198192        std::list<Statement *> &get_statements() { return stmts; }
    199193        void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
    200 
     194       
    201195        virtual void accept( Visitor &v ) { v.visit( this ); }
    202196        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     
    214208        WhileStmt( std::list<Label> labels, Expression *condition,
    215209               Statement *body, bool isDoWhile = false );
    216         WhileStmt( const WhileStmt &other );
    217210        virtual ~WhileStmt();
    218211
     
    223216        bool get_isDoWhile() { return isDoWhile; }
    224217        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
    225 
     218       
    226219        virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
    227220        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    238231        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    239232             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
    240         ForStmt( const ForStmt &other );
    241233        virtual ~ForStmt();
    242234
     
    249241        Statement *get_body() { return body; }
    250242        void set_body( Statement *newValue ) { body = newValue; }
    251 
     243       
    252244        virtual ForStmt *clone() const { return new ForStmt( *this ); }
    253245        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    267259        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
    268260        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
     261        virtual ~BranchStmt() {}
    269262
    270263        Label get_originalTarget() { return originalTarget; }
    271264        Label get_target() { return target; }
    272265        void set_target( Label newValue ) { target = newValue; }
    273 
     266       
    274267        Expression *get_computedTarget() { return computedTarget; }
    275268        void set_target( Expression * newValue ) { computedTarget = newValue; }
     
    293286  public:
    294287        ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false );
    295         ReturnStmt( const ReturnStmt &other );
    296288        virtual ~ReturnStmt();
    297289
    298290        Expression *get_expr() { return expr; }
    299291        void set_expr( Expression *newValue ) { expr = newValue; }
    300 
     292       
    301293        virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
    302294        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    313305        NullStmt();
    314306        NullStmt( std::list<Label> labels );
     307        virtual ~NullStmt();
    315308
    316309        virtual NullStmt *clone() const { return new NullStmt( *this ); }
     
    318311        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    319312        virtual void print( std::ostream &os, int indent = 0 ) const;
    320 
    321   private:
    322 };
    323 
    324 class TryStmt : public Statement {
     313       
     314  private:
     315};
     316
     317class TryStmt : public Statement { 
    325318  public:
    326319        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
     
    339332        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    340333        virtual void print( std::ostream &os, int indent = 0 ) const;
    341 
     334       
    342335  private:
    343336        CompoundStmt *block;
    344337        std::list<Statement *> handlers;
    345338        FinallyStmt *finallyBlock;
    346 };
     339}; 
    347340
    348341class CatchStmt : public Statement {
    349342  public:
    350343        CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false );
    351         CatchStmt( const CatchStmt &other );
    352344        virtual ~CatchStmt();
    353345
     
    357349        Statement *get_body() { return body; }
    358350        void set_body( Statement *newValue ) { body = newValue; }
    359 
     351       
    360352        virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
    361353        virtual void accept( Visitor &v ) { v.visit( this ); }
    362354        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    363355        virtual void print( std::ostream &os, int indent = 0 ) const;
    364 
     356       
    365357  private:
    366358        Declaration *decl;
     
    369361};
    370362
    371 class FinallyStmt : public Statement {
     363class FinallyStmt : public Statement { 
    372364  public:
    373365        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    374         FinallyStmt( const FinallyStmt &other );
    375366        virtual ~FinallyStmt();
    376367
    377368        CompoundStmt *get_block() const { return block; }
    378369        void set_block( CompoundStmt *newValue ) { block = newValue; }
    379 
     370       
    380371        virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
    381372        virtual void accept( Visitor &v ) { v.visit( this ); }
     
    384375  private:
    385376        CompoundStmt *block;
    386 };
     377}; 
    387378
    388379
Note: See TracChangeset for help on using the changeset viewer.