Changeset 5170d95 for src/ResolvExpr
- Timestamp:
- Feb 19, 2019, 11:24:40 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 2ede686
- Parents:
- 45af7e1
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r45af7e1 r5170d95 10 10 // Created On : Sun May 17 12:17:01 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:13:43201913 // Update Count : 2 1612 // Last Modified On : Tue Feb 19 18:09:56 2019 13 // Update Count : 240 14 14 // 15 15 … … 53 53 } 54 54 55 void previsit( FunctionDecl * functionDecl );56 void postvisit( FunctionDecl * functionDecl );57 void previsit( ObjectDecl * objectDecll );55 void previsit( FunctionDecl * functionDecl ); 56 void postvisit( FunctionDecl * functionDecl ); 57 void previsit( ObjectDecl * objectDecll ); 58 58 void previsit( EnumDecl * enumDecl ); 59 59 void previsit( StaticAssertDecl * assertDecl ); … … 62 62 void previsit( PointerType * at ); 63 63 64 void previsit( ExprStmt * exprStmt );65 void previsit( AsmExpr * asmExpr );66 void previsit( AsmStmt * asmStmt );67 void previsit( IfStmt * ifStmt );68 void previsit( WhileStmt * whileStmt );69 void previsit( ForStmt * forStmt );70 void previsit( SwitchStmt * switchStmt );71 void previsit( CaseStmt * caseStmt );72 void previsit( BranchStmt * branchStmt );73 void previsit( ReturnStmt * returnStmt );74 void previsit( ThrowStmt * throwStmt );75 void previsit( CatchStmt * catchStmt );64 void previsit( ExprStmt * exprStmt ); 65 void previsit( AsmExpr * asmExpr ); 66 void previsit( AsmStmt * asmStmt ); 67 void previsit( IfStmt * ifStmt ); 68 void previsit( WhileStmt * whileStmt ); 69 void previsit( ForStmt * forStmt ); 70 void previsit( SwitchStmt * switchStmt ); 71 void previsit( CaseStmt * caseStmt ); 72 void previsit( BranchStmt * branchStmt ); 73 void previsit( ReturnStmt * returnStmt ); 74 void previsit( ThrowStmt * throwStmt ); 75 void previsit( CatchStmt * catchStmt ); 76 76 void previsit( WaitForStmt * stmt ); 77 77 78 void previsit( SingleInit * singleInit );79 void previsit( ListInit * listInit );80 void previsit( ConstructorInit * ctorInit );78 void previsit( SingleInit * singleInit ); 79 void previsit( ListInit * listInit ); 80 void previsit( ConstructorInit * ctorInit ); 81 81 private: 82 82 typedef std::list< Initializer * >::iterator InitIterator; … … 104 104 } 105 105 106 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {106 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) { 107 107 PassVisitor<Resolver> resolver( indexer ); 108 108 maybeAccept( decl, resolver ); … … 148 148 }; 149 149 150 void finishExpr( Expression *& expr, const TypeEnvironment &env, TypeSubstitution * oldenv = nullptr ) {150 void finishExpr( Expression *& expr, const TypeEnvironment & env, TypeSubstitution * oldenv = nullptr ) { 151 151 expr->env = oldenv ? oldenv->clone() : new TypeSubstitution; 152 152 env.makeSubstitution( *expr->env ); … … 279 279 280 280 // used in resolveTypeof 281 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer ) {281 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer ) { 282 282 TypeEnvironment env; 283 283 return resolveInVoidContext( expr, indexer, env ); 284 284 } 285 285 286 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer, TypeEnvironment &env ) {286 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer, TypeEnvironment & env ) { 287 287 // it's a property of the language that a cast expression has either 1 or 0 interpretations; if it has 0 288 288 // interpretations, an exception has already been thrown. 289 289 assertf( expr, "expected a non-null expression." ); 290 290 291 static CastExpr untyped( nullptr ); // cast to void292 untyped .location = expr->location;291 CastExpr * untyped = new CastExpr( expr ); // cast to void 292 untyped->location = expr->location; 293 293 294 294 // set up and resolve expression cast to void 295 untyped.arg = expr;296 295 Alternative choice; 297 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() );296 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() ); 298 297 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 298 assert( castExpr ); 299 299 env = std::move( choice.env ); 300 300 … … 304 304 305 305 // unlink the arg so that it isn't deleted twice at the end of the program 306 untyped .arg = nullptr;306 untyped->arg = nullptr; 307 307 return ret; 308 308 } 309 309 310 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {310 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 311 311 resetTyVarRenaming(); 312 312 TypeEnvironment env; … … 317 317 } 318 318 319 void findSingleExpression( Expression *& untyped, const SymTab::Indexer &indexer ) {319 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 320 320 findKindExpression( untyped, indexer, "", standardAlternativeFilter ); 321 321 } … … 336 336 if ( dynamic_cast< EnumInstType * >( type ) ) { 337 337 return true; 338 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) {338 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) { 339 339 return bt->isInteger(); 340 340 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) { … … 345 345 } 346 346 347 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {347 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 348 348 findKindExpression( untyped, indexer, "condition", isIntegralType ); 349 349 } … … 401 401 } 402 402 403 void Resolver::previsit( ObjectDecl * objectDecl ) {403 void Resolver::previsit( ObjectDecl * objectDecl ) { 404 404 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 405 405 // class-variable initContext is changed multiple time because the LHS is analysed twice. … … 431 431 } 432 432 433 void Resolver::previsit( FunctionDecl * functionDecl ) {433 void Resolver::previsit( FunctionDecl * functionDecl ) { 434 434 #if 0 435 435 std::cerr << "resolver visiting functiondecl "; … … 441 441 } 442 442 443 void Resolver::postvisit( FunctionDecl * functionDecl ) {443 void Resolver::postvisit( FunctionDecl * functionDecl ) { 444 444 // default value expressions have an environment which shouldn't be there and trips up 445 445 // later passes. … … 466 466 } 467 467 468 void Resolver::previsit( ExprStmt * exprStmt ) {468 void Resolver::previsit( ExprStmt * exprStmt ) { 469 469 visit_children = false; 470 470 assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" ); … … 472 472 } 473 473 474 void Resolver::previsit( AsmExpr * asmExpr ) {474 void Resolver::previsit( AsmExpr * asmExpr ) { 475 475 visit_children = false; 476 476 findVoidExpression( asmExpr->operand, indexer ); … … 480 480 } 481 481 482 void Resolver::previsit( AsmStmt * asmStmt ) {482 void Resolver::previsit( AsmStmt * asmStmt ) { 483 483 visit_children = false; 484 484 acceptAll( asmStmt->get_input(), *visitor ); … … 486 486 } 487 487 488 void Resolver::previsit( IfStmt * ifStmt ) {488 void Resolver::previsit( IfStmt * ifStmt ) { 489 489 findIntegralExpression( ifStmt->condition, indexer ); 490 490 } 491 491 492 void Resolver::previsit( WhileStmt * whileStmt ) {492 void Resolver::previsit( WhileStmt * whileStmt ) { 493 493 findIntegralExpression( whileStmt->condition, indexer ); 494 494 } 495 495 496 void Resolver::previsit( ForStmt * forStmt ) {496 void Resolver::previsit( ForStmt * forStmt ) { 497 497 if ( forStmt->condition ) { 498 498 findIntegralExpression( forStmt->condition, indexer ); … … 504 504 } 505 505 506 void Resolver::previsit( SwitchStmt * switchStmt ) {506 void Resolver::previsit( SwitchStmt * switchStmt ) { 507 507 GuardValue( currentObject ); 508 508 findIntegralExpression( switchStmt->condition, indexer ); … … 511 511 } 512 512 513 void Resolver::previsit( CaseStmt * caseStmt ) {513 void Resolver::previsit( CaseStmt * caseStmt ) { 514 514 if ( caseStmt->condition ) { 515 515 std::list< InitAlternative > initAlts = currentObject.getOptions(); … … 530 530 } 531 531 532 void Resolver::previsit( BranchStmt * branchStmt ) {532 void Resolver::previsit( BranchStmt * branchStmt ) { 533 533 visit_children = false; 534 534 // must resolve the argument for a computed goto … … 541 541 } 542 542 543 void Resolver::previsit( ReturnStmt * returnStmt ) {543 void Resolver::previsit( ReturnStmt * returnStmt ) { 544 544 visit_children = false; 545 545 if ( returnStmt->expr ) { … … 548 548 } 549 549 550 void Resolver::previsit( ThrowStmt * throwStmt ) {550 void Resolver::previsit( ThrowStmt * throwStmt ) { 551 551 visit_children = false; 552 552 // TODO: Replace *exception type with &exception type. … … 560 560 } 561 561 562 void Resolver::previsit( CatchStmt * catchStmt ) {562 void Resolver::previsit( CatchStmt * catchStmt ) { 563 563 if ( catchStmt->cond ) { 564 564 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); … … 724 724 725 725 } 726 catch( SemanticErrorException & e ) {726 catch( SemanticErrorException & e ) { 727 727 errors.append( e ); 728 728 } 729 729 } 730 730 } 731 catch( SemanticErrorException & e ) {731 catch( SemanticErrorException & e ) { 732 732 errors.append( e ); 733 733 } … … 781 781 } 782 782 783 void Resolver::previsit( SingleInit * singleInit ) {783 void Resolver::previsit( SingleInit * singleInit ) { 784 784 visit_children = false; 785 785 // resolve initialization using the possibilities as determined by the currentObject cursor … … 813 813 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 814 814 if ( isCharType( pt->get_base() ) ) { 815 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) {815 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) { 816 816 // strip cast if we're initializing a char[] with a char *, 817 817 // e.g. char x[] = "hello"; … … 893 893 } 894 894 895 void Resolver::previsit( ConstructorInit * ctorInit ) {895 void Resolver::previsit( ConstructorInit * ctorInit ) { 896 896 visit_children = false; 897 897 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit -
src/ResolvExpr/Resolver.h
r45af7e1 r5170d95 10 10 // Created On : Sun May 17 12:18:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:36:57 201713 // Update Count : 312 // Last Modified On : Mon Feb 18 20:40:38 2019 13 // Update Count : 4 14 14 // 15 15 … … 29 29 /// Checks types and binds syntactic constructs to typed representations 30 30 void resolve( std::list< Declaration * > translationUnit ); 31 void resolveDecl( Declaration *, const SymTab::Indexer & indexer );32 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer );33 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer );34 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer );35 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer );31 void resolveDecl( Declaration *, const SymTab::Indexer & indexer ); 32 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer ); 33 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ); 34 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer ); 35 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer ); 36 36 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 37 37 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );
Note: See TracChangeset
for help on using the changeset viewer.