Changeset 7f9968a for src/ControlStruct


Ignore:
Timestamp:
Jun 24, 2020, 12:30:42 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8b58bae
Parents:
a8a3485
Message:

Fixed a problem with 'throwResume;' translation and added some tests to check for similar problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    ra8a3485 r7f9968a  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 26 10:56:00 2020
    13 // Update Count     : 16
     12// Last Modified On : Wed Jun 24 11:18:00 2020
     13// Update Count     : 17
    1414//
    1515
     
    7272                        ThrowStmt * throwStmt, const char * throwFunc );
    7373                Statement * create_terminate_rethrow( ThrowStmt * throwStmt );
    74                 Statement * create_resume_rethrow( ThrowStmt * throwStmt );
    7574
    7675        public:
     
    113112                        new UntypedExpr( new NameExpr( "__cfaehm_rethrow_terminate" ) )
    114113                        ) );
    115                 delete throwStmt;
    116                 return result;
    117         }
    118 
    119         Statement * ThrowMutatorCore::create_resume_rethrow(
    120                         ThrowStmt *throwStmt ) {
    121                 // return false;
    122                 Statement * result = new ReturnStmt(
    123                         new ConstantExpr( Constant::from_bool( false ) )
    124                         );
    125                 result->labels = throwStmt->labels;
    126114                delete throwStmt;
    127115                return result;
     
    167155                                return create_either_throw( throwStmt, "$throwResume" );
    168156                        } else if ( ResHandler == cur_context ) {
    169                                 return create_resume_rethrow( throwStmt );
     157                                // This has to be handled later.
     158                                return throwStmt;
    170159                        } else {
    171160                                abort("Invalid throwResume in %s at %i\n",
     
    196185                FunctionDecl * create_finally_wrapper( TryStmt * tryStmt );
    197186                ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper );
     187                Statement * create_resume_rethrow( ThrowStmt * throwStmt );
    198188
    199189                // Types used in translation, make sure to use clone.
     
    227217                void premutate( StructDecl *structDecl );
    228218                Statement * postmutate( TryStmt *tryStmt );
     219                Statement * postmutate( ThrowStmt *throwStmt );
    229220        };
    230221
     
    594585                        attributes
    595586                        );
     587        }
     588
     589        Statement * TryMutatorCore::create_resume_rethrow( ThrowStmt *throwStmt ) {
     590                // return false;
     591                Statement * result = new ReturnStmt(
     592                        new ConstantExpr( Constant::from_bool( false ) )
     593                        );
     594                result->labels = throwStmt->labels;
     595                delete throwStmt;
     596                return result;
    596597        }
    597598
     
    668669        }
    669670
     671        Statement * TryMutatorCore::postmutate( ThrowStmt *throwStmt ) {
     672                // Only valid `throwResume;` statements should remain. (2/3 checks)
     673                assert( ThrowStmt::Resume == throwStmt->kind && ! throwStmt->expr );
     674                return create_resume_rethrow( throwStmt );
     675        }
     676
    670677        void translateThrows( std::list< Declaration *> & translationUnit ) {
    671678                PassVisitor<ThrowMutatorCore> translator;
Note: See TracChangeset for help on using the changeset viewer.