Changeset 933f32f for src/ResolvExpr/Resolver.cc
- Timestamp:
- May 24, 2019, 10:19:41 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d908563
- Parents:
- 6a9d4b4 (diff), 292642a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r6a9d4b4 r933f32f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Fri Oct 05 09:43:00 201813 // Update Count : 2 1411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 19 18:09:56 2019 13 // Update Count : 240 14 14 // 15 15 … … 54 54 } 55 55 56 void previsit( FunctionDecl * functionDecl );57 void postvisit( FunctionDecl * functionDecl );58 void previsit( ObjectDecl * objectDecll );56 void previsit( FunctionDecl * functionDecl ); 57 void postvisit( FunctionDecl * functionDecl ); 58 void previsit( ObjectDecl * objectDecll ); 59 59 void previsit( EnumDecl * enumDecl ); 60 60 void previsit( StaticAssertDecl * assertDecl ); … … 63 63 void previsit( PointerType * at ); 64 64 65 void previsit( ExprStmt * exprStmt );66 void previsit( AsmExpr * asmExpr );67 void previsit( AsmStmt * asmStmt );68 void previsit( IfStmt * ifStmt );69 void previsit( WhileStmt * whileStmt );70 void previsit( ForStmt * forStmt );71 void previsit( SwitchStmt * switchStmt );72 void previsit( CaseStmt * caseStmt );73 void previsit( BranchStmt * branchStmt );74 void previsit( ReturnStmt * returnStmt );75 void previsit( ThrowStmt * throwStmt );76 void previsit( CatchStmt * catchStmt );65 void previsit( ExprStmt * exprStmt ); 66 void previsit( AsmExpr * asmExpr ); 67 void previsit( AsmStmt * asmStmt ); 68 void previsit( IfStmt * ifStmt ); 69 void previsit( WhileStmt * whileStmt ); 70 void previsit( ForStmt * forStmt ); 71 void previsit( SwitchStmt * switchStmt ); 72 void previsit( CaseStmt * caseStmt ); 73 void previsit( BranchStmt * branchStmt ); 74 void previsit( ReturnStmt * returnStmt ); 75 void previsit( ThrowStmt * throwStmt ); 76 void previsit( CatchStmt * catchStmt ); 77 77 void previsit( WaitForStmt * stmt ); 78 78 79 void previsit( SingleInit * singleInit );80 void previsit( ListInit * listInit );81 void previsit( ConstructorInit * ctorInit );79 void previsit( SingleInit * singleInit ); 80 void previsit( ListInit * listInit ); 81 void previsit( ConstructorInit * ctorInit ); 82 82 private: 83 83 typedef std::list< Initializer * >::iterator InitIterator; … … 105 105 } 106 106 107 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {107 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) { 108 108 PassVisitor<Resolver> resolver( indexer ); 109 109 maybeAccept( decl, resolver ); … … 149 149 }; 150 150 151 void finishExpr( Expression *& expr, const TypeEnvironment &env, TypeSubstitution * oldenv = nullptr ) {151 void finishExpr( Expression *& expr, const TypeEnvironment & env, TypeSubstitution * oldenv = nullptr ) { 152 152 expr->env = oldenv ? oldenv->clone() : new TypeSubstitution; 153 153 env.makeSubstitution( *expr->env ); … … 280 280 281 281 // used in resolveTypeof 282 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer ) {282 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer ) { 283 283 TypeEnvironment env; 284 284 return resolveInVoidContext( expr, indexer, env ); 285 285 } 286 286 287 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer, TypeEnvironment &env ) {287 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer, TypeEnvironment & env ) { 288 288 // it's a property of the language that a cast expression has either 1 or 0 interpretations; if it has 0 289 289 // interpretations, an exception has already been thrown. 290 290 assertf( expr, "expected a non-null expression." ); 291 291 292 static CastExpr untyped( nullptr ); // cast to void293 untyped .location = expr->location;292 CastExpr * untyped = new CastExpr( expr ); // cast to void 293 untyped->location = expr->location; 294 294 295 295 // set up and resolve expression cast to void 296 untyped.arg = expr;297 296 Alternative choice; 298 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() );297 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() ); 299 298 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 299 assert( castExpr ); 300 300 env = std::move( choice.env ); 301 301 … … 305 305 306 306 // unlink the arg so that it isn't deleted twice at the end of the program 307 untyped .arg = nullptr;307 untyped->arg = nullptr; 308 308 return ret; 309 309 } 310 310 311 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {311 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 312 312 resetTyVarRenaming(); 313 313 TypeEnvironment env; … … 318 318 } 319 319 320 void findSingleExpression( Expression *& untyped, const SymTab::Indexer &indexer ) {320 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 321 321 findKindExpression( untyped, indexer, "", standardAlternativeFilter ); 322 322 } … … 337 337 if ( dynamic_cast< EnumInstType * >( type ) ) { 338 338 return true; 339 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) {339 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) { 340 340 return bt->isInteger(); 341 341 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) { … … 346 346 } 347 347 348 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {348 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 349 349 findKindExpression( untyped, indexer, "condition", isIntegralType ); 350 350 } … … 402 402 } 403 403 404 void Resolver::previsit( ObjectDecl * objectDecl ) {404 void Resolver::previsit( ObjectDecl * objectDecl ) { 405 405 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 406 406 // class-variable initContext is changed multiple time because the LHS is analysed twice. … … 432 432 } 433 433 434 void Resolver::previsit( FunctionDecl * functionDecl ) {434 void Resolver::previsit( FunctionDecl * functionDecl ) { 435 435 #if 0 436 436 std::cerr << "resolver visiting functiondecl "; … … 442 442 } 443 443 444 void Resolver::postvisit( FunctionDecl * functionDecl ) {444 void Resolver::postvisit( FunctionDecl * functionDecl ) { 445 445 // default value expressions have an environment which shouldn't be there and trips up 446 446 // later passes. … … 467 467 } 468 468 469 void Resolver::previsit( ExprStmt * exprStmt ) {469 void Resolver::previsit( ExprStmt * exprStmt ) { 470 470 visit_children = false; 471 471 assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" ); … … 473 473 } 474 474 475 void Resolver::previsit( AsmExpr * asmExpr ) {475 void Resolver::previsit( AsmExpr * asmExpr ) { 476 476 visit_children = false; 477 477 findVoidExpression( asmExpr->operand, indexer ); … … 481 481 } 482 482 483 void Resolver::previsit( AsmStmt * asmStmt ) {483 void Resolver::previsit( AsmStmt * asmStmt ) { 484 484 visit_children = false; 485 485 acceptAll( asmStmt->get_input(), *visitor ); … … 487 487 } 488 488 489 void Resolver::previsit( IfStmt * ifStmt ) {489 void Resolver::previsit( IfStmt * ifStmt ) { 490 490 findIntegralExpression( ifStmt->condition, indexer ); 491 491 } 492 492 493 void Resolver::previsit( WhileStmt * whileStmt ) {493 void Resolver::previsit( WhileStmt * whileStmt ) { 494 494 findIntegralExpression( whileStmt->condition, indexer ); 495 495 } 496 496 497 void Resolver::previsit( ForStmt * forStmt ) {497 void Resolver::previsit( ForStmt * forStmt ) { 498 498 if ( forStmt->condition ) { 499 499 findIntegralExpression( forStmt->condition, indexer ); … … 505 505 } 506 506 507 void Resolver::previsit( SwitchStmt * switchStmt ) {507 void Resolver::previsit( SwitchStmt * switchStmt ) { 508 508 GuardValue( currentObject ); 509 509 findIntegralExpression( switchStmt->condition, indexer ); … … 512 512 } 513 513 514 void Resolver::previsit( CaseStmt * caseStmt ) {514 void Resolver::previsit( CaseStmt * caseStmt ) { 515 515 if ( caseStmt->condition ) { 516 516 std::list< InitAlternative > initAlts = currentObject.getOptions(); … … 531 531 } 532 532 533 void Resolver::previsit( BranchStmt * branchStmt ) {533 void Resolver::previsit( BranchStmt * branchStmt ) { 534 534 visit_children = false; 535 535 // must resolve the argument for a computed goto … … 542 542 } 543 543 544 void Resolver::previsit( ReturnStmt * returnStmt ) {544 void Resolver::previsit( ReturnStmt * returnStmt ) { 545 545 visit_children = false; 546 546 if ( returnStmt->expr ) { … … 549 549 } 550 550 551 void Resolver::previsit( ThrowStmt * throwStmt ) {551 void Resolver::previsit( ThrowStmt * throwStmt ) { 552 552 visit_children = false; 553 553 // TODO: Replace *exception type with &exception type. … … 561 561 } 562 562 563 void Resolver::previsit( CatchStmt * catchStmt ) {563 void Resolver::previsit( CatchStmt * catchStmt ) { 564 564 if ( catchStmt->cond ) { 565 565 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); … … 725 725 726 726 } 727 catch( SemanticErrorException & e ) {727 catch( SemanticErrorException & e ) { 728 728 errors.append( e ); 729 729 } 730 730 } 731 731 } 732 catch( SemanticErrorException & e ) {732 catch( SemanticErrorException & e ) { 733 733 errors.append( e ); 734 734 } … … 782 782 } 783 783 784 void Resolver::previsit( SingleInit * singleInit ) {784 void Resolver::previsit( SingleInit * singleInit ) { 785 785 visit_children = false; 786 786 // resolve initialization using the possibilities as determined by the currentObject cursor … … 814 814 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 815 815 if ( isCharType( pt->get_base() ) ) { 816 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) {816 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) { 817 817 // strip cast if we're initializing a char[] with a char *, 818 818 // e.g. char x[] = "hello"; … … 894 894 } 895 895 896 void Resolver::previsit( ConstructorInit * ctorInit ) {896 void Resolver::previsit( ConstructorInit * ctorInit ) { 897 897 visit_children = false; 898 898 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
Note: See TracChangeset
for help on using the changeset viewer.