Changes in / [ac1ed49:44b7088]
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
rac1ed49 r44b7088 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Unify.cc -- 7 // Unify.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 38 38 WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; } 39 39 operator bool() { return widenFirst && widenSecond; } 40 40 41 41 bool widenFirst : 1, widenSecond : 1; 42 42 }; … … 45 45 public: 46 46 Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 47 47 48 48 bool get_result() const { return result; } 49 49 private: … … 79 79 bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common ); 80 80 bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 81 81 82 82 bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 83 83 TypeEnvironment newEnv; … … 137 137 case TypeDecl::Dtype: 138 138 return ! isFtype( type, indexer ); 139 139 140 140 case TypeDecl::Ftype: 141 141 return isFtype( type, indexer ); … … 196 196 bool widen1 = false, widen2 = false; 197 197 Type *type1 = 0, *type2 = 0; 198 198 199 199 if ( env.lookup( var1->get_name(), class1 ) ) { 200 200 hasClass1 = true; … … 217 217 widen2 = widenMode.widenSecond && class2.allowWidening; 218 218 } // if 219 219 220 220 if ( type1 && type2 ) { 221 221 // std::cout << "has type1 && type2" << std::endl; … … 436 436 // to unify, array types must both be VLA or both not VLA 437 437 // 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))) { 439 441 440 442 // not positive this is correct in all cases, but it's needed for typedefs … … 447 449 ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() ); 448 450 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; 460 459 } 461 460 } … … 486 485 487 486 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 489 488 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 490 489 -
src/SynTree/Expression.cc
rac1ed49 r44b7088 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Expression.cc -- 7 // Expression.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 422 422 } 423 423 424 AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}425 426 427 424 void AsmExpr::print( std::ostream &os, int indent ) const { 428 425 os << "Asm Expression: " << std::endl; … … 432 429 } 433 430 434 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}435 436 UntypedValofExpr::~UntypedValofExpr() { delete body; }437 438 431 void UntypedValofExpr::print( std::ostream &os, int indent ) const { 439 432 os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl; … … 441 434 get_body()->print( os, indent + 2 ); 442 435 } 443 444 445 436 446 437 std::ostream & operator<<( std::ostream & out, Expression * expr ) { -
src/SynTree/Expression.h
rac1ed49 r44b7088 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Expression.h -- 7 // Expression.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 155 155 }; 156 156 157 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack158 157 class LabelAddressExpr : public Expression { 159 158 public: 160 159 LabelAddressExpr( Expression *arg ); 161 LabelAddressExpr( const LabelAddressExpr &other );160 LabelAddressExpr( const AddressExpr &other ); 162 161 virtual ~LabelAddressExpr(); 163 162 … … 252 251 }; 253 252 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 255 254 class ConstantExpr : public Expression { 256 255 public: … … 516 515 public: 517 516 AsmExpr( Expression *inout, ConstantExpr *constraint, Expression *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 518 AsmExpr( const AsmExpr & other );519 517 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; }; 520 518 … … 543 541 public: 544 542 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 545 UntypedValofExpr( const UntypedValofExpr & other ); 546 virtual ~UntypedValofExpr(); 543 virtual ~UntypedValofExpr() {} 547 544 548 545 Expression *get_value(); -
src/SynTree/Statement.cc
rac1ed49 r44b7088 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Statement.cc -- 7 // Statement.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 36 36 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {} 37 37 38 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 39 40 ExprStmt::~ExprStmt() { 41 delete expr; 42 } 38 ExprStmt::~ExprStmt() {} 43 39 44 40 void ExprStmt::print( std::ostream &os, int indent ) const { 45 41 os << string( indent, ' ' ) << "Expression Statement:" << endl; 46 42 expr->print( os, indent + 2 ); 47 } 43 } 48 44 49 45 50 46 AsmStmt::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 }57 47 58 48 AsmStmt::~AsmStmt() { … … 70 60 os << endl << std::string( indent, ' ' ) << "output: " << endl; 71 61 printAll( output, os, indent + 2 ); 72 } // if 62 } // if 73 63 if ( ! input.empty() ) { 74 64 os << std::string( indent, ' ' ) << "input: " << endl << std::string( indent, ' ' ); … … 79 69 printAll( clobber, os, indent + 2 ); 80 70 } // if 81 } 71 } 82 72 83 73 … … 103 93 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {} 104 94 105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ), isThrow( other.isThrow ) {}106 107 95 ReturnStmt::~ReturnStmt() { 108 96 delete expr; … … 118 106 Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} 119 107 120 IfStmt::IfStmt( const IfStmt & other ) :121 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}122 123 108 IfStmt::~IfStmt() {} 124 109 … … 138 123 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 139 124 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 );145 125 } 146 126 … … 165 145 } 166 146 167 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 147 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 168 148 Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) { 169 149 if ( isDefault() && condition != 0 ) 170 150 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 );176 151 } 177 152 … … 206 181 } 207 182 208 ChooseStmt::ChooseStmt( const ChooseStmt & other ):209 Statement( other ), condition( maybeClone( other.condition ) ) {210 cloneAll( other.branches, branches );211 }212 213 183 ChooseStmt::~ChooseStmt() { 214 184 delete condition; … … 238 208 } 239 209 240 WhileStmt::WhileStmt( const WhileStmt & other ):241 Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {242 }243 244 210 WhileStmt::~WhileStmt() { 245 211 delete body; … … 257 223 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 258 224 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 265 225 } 266 226 … … 281 241 os << string( indent, ' ' ) << "For Statement" << endl ; 282 242 283 os << string( indent + 2, ' ' ) << "initialization: \n"; 243 os << string( indent + 2, ' ' ) << "initialization: \n"; 284 244 for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) { 285 245 (*it)->print( os, indent + 4 ); 286 246 } 287 247 288 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 248 os << "\n" << string( indent + 2, ' ' ) << "condition: \n"; 289 249 if ( condition != 0 ) 290 250 condition->print( os, indent + 4 ); 291 251 292 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 252 os << "\n" << string( indent + 2, ' ' ) << "increment: \n"; 293 253 if ( increment != 0 ) 294 254 increment->print( os, indent + 4 ); 295 255 296 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 256 os << "\n" << string( indent + 2, ' ' ) << "statement block: \n"; 297 257 if ( body != 0 ) 298 258 body->print( os, indent + 4 ); … … 305 265 } 306 266 307 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { 308 cloneAll( other.handlers, handlers ); 267 TryStmt::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; 309 271 } 310 272 … … 332 294 CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : 333 295 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 ) {338 296 } 339 297 … … 361 319 } 362 320 363 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) {364 }365 366 321 FinallyStmt::~FinallyStmt() { 367 322 delete block; … … 376 331 NullStmt::NullStmt( std::list<Label> labels ) : CompoundStmt( labels ) {} 377 332 NullStmt::NullStmt() : CompoundStmt( std::list<Label>() ) {} 333 NullStmt::~NullStmt() {} 378 334 379 335 void NullStmt::print( std::ostream &os, int indent ) const { -
src/SynTree/Statement.h
rac1ed49 r44b7088 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Statement.h -- 7 // Statement.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 57 57 public: 58 58 ExprStmt( std::list<Label> labels, Expression *expr ); 59 ExprStmt( const ExprStmt &other );60 59 virtual ~ExprStmt(); 61 60 … … 74 73 public: 75 74 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 );77 75 virtual ~AsmStmt(); 78 76 … … 105 103 public: 106 104 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 107 IfStmt( const IfStmt &other );108 105 virtual ~IfStmt(); 109 106 … … 114 111 Statement *get_elsePart() { return elsePart; } 115 112 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 116 113 117 114 virtual IfStmt *clone() const { return new IfStmt( *this ); } 118 115 virtual void accept( Visitor &v ) { v.visit( this ); } … … 128 125 public: 129 126 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 130 SwitchStmt( const SwitchStmt &other );131 127 virtual ~SwitchStmt(); 132 128 … … 150 146 public: 151 147 ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 152 ChooseStmt( const ChooseStmt &other );153 148 virtual ~ChooseStmt(); 154 149 … … 182 177 class CaseStmt : public Statement { 183 178 public: 184 CaseStmt( std::list<Label> labels, Expression *conditions, 179 CaseStmt( std::list<Label> labels, Expression *conditions, 185 180 std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 186 CaseStmt( const CaseStmt &other );187 181 virtual ~CaseStmt(); 188 182 … … 198 192 std::list<Statement *> &get_statements() { return stmts; } 199 193 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 200 194 201 195 virtual void accept( Visitor &v ) { v.visit( this ); } 202 196 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } … … 214 208 WhileStmt( std::list<Label> labels, Expression *condition, 215 209 Statement *body, bool isDoWhile = false ); 216 WhileStmt( const WhileStmt &other );217 210 virtual ~WhileStmt(); 218 211 … … 223 216 bool get_isDoWhile() { return isDoWhile; } 224 217 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 225 218 226 219 virtual WhileStmt *clone() const { return new WhileStmt( *this ); } 227 220 virtual void accept( Visitor &v ) { v.visit( this ); } … … 238 231 ForStmt( std::list<Label> labels, std::list<Statement *> initialization, 239 232 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 240 ForStmt( const ForStmt &other );241 233 virtual ~ForStmt(); 242 234 … … 249 241 Statement *get_body() { return body; } 250 242 void set_body( Statement *newValue ) { body = newValue; } 251 243 252 244 virtual ForStmt *clone() const { return new ForStmt( *this ); } 253 245 virtual void accept( Visitor &v ) { v.visit( this ); } … … 267 259 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 268 260 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 261 virtual ~BranchStmt() {} 269 262 270 263 Label get_originalTarget() { return originalTarget; } 271 264 Label get_target() { return target; } 272 265 void set_target( Label newValue ) { target = newValue; } 273 266 274 267 Expression *get_computedTarget() { return computedTarget; } 275 268 void set_target( Expression * newValue ) { computedTarget = newValue; } … … 293 286 public: 294 287 ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); 295 ReturnStmt( const ReturnStmt &other );296 288 virtual ~ReturnStmt(); 297 289 298 290 Expression *get_expr() { return expr; } 299 291 void set_expr( Expression *newValue ) { expr = newValue; } 300 292 301 293 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } 302 294 virtual void accept( Visitor &v ) { v.visit( this ); } … … 313 305 NullStmt(); 314 306 NullStmt( std::list<Label> labels ); 307 virtual ~NullStmt(); 315 308 316 309 virtual NullStmt *clone() const { return new NullStmt( *this ); } … … 318 311 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 319 312 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 317 class TryStmt : public Statement { 325 318 public: 326 319 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); … … 339 332 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 340 333 virtual void print( std::ostream &os, int indent = 0 ) const; 341 334 342 335 private: 343 336 CompoundStmt *block; 344 337 std::list<Statement *> handlers; 345 338 FinallyStmt *finallyBlock; 346 }; 339 }; 347 340 348 341 class CatchStmt : public Statement { 349 342 public: 350 343 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); 351 CatchStmt( const CatchStmt &other );352 344 virtual ~CatchStmt(); 353 345 … … 357 349 Statement *get_body() { return body; } 358 350 void set_body( Statement *newValue ) { body = newValue; } 359 351 360 352 virtual CatchStmt *clone() const { return new CatchStmt( *this ); } 361 353 virtual void accept( Visitor &v ) { v.visit( this ); } 362 354 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 363 355 virtual void print( std::ostream &os, int indent = 0 ) const; 364 356 365 357 private: 366 358 Declaration *decl; … … 369 361 }; 370 362 371 class FinallyStmt : public Statement { 363 class FinallyStmt : public Statement { 372 364 public: 373 365 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 374 FinallyStmt( const FinallyStmt &other );375 366 virtual ~FinallyStmt(); 376 367 377 368 CompoundStmt *get_block() const { return block; } 378 369 void set_block( CompoundStmt *newValue ) { block = newValue; } 379 370 380 371 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } 381 372 virtual void accept( Visitor &v ) { v.visit( this ); } … … 384 375 private: 385 376 CompoundStmt *block; 386 }; 377 }; 387 378 388 379
Note: See TracChangeset
for help on using the changeset viewer.