- Timestamp:
- Jun 10, 2020, 4:19:30 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ab8a023
- Parents:
- a5873bd (diff), ee06db5c (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. - Location:
- src
- Files:
-
- 4 edited
-
ControlStruct/ExceptTranslate.cc (modified) (5 diffs)
-
ControlStruct/ExceptTranslate.h (modified) (1 diff)
-
Parser/parser.yy (modified) (13 diffs)
-
Virtual/ExpandCasts.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
ra5873bd r97392b69 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hr May 21 13:18:00 202013 // Update Count : 1 512 // Last Modified On : Tue May 26 10:56:00 2020 13 // Update Count : 16 14 14 // 15 15 … … 107 107 nameOf( terminate_handler_except ), 108 108 new ConstantExpr( Constant::null( 109 //new PointerType( 110 // noQualifiers, 111 terminate_handler_except->get_type()->clone() 112 // ) 109 terminate_handler_except->get_type()->clone() 113 110 ) ) 114 111 ) ) ); … … 137 134 ObjectDecl * decl = dynamic_cast<ObjectDecl *>( catchStmt->get_decl() ); 138 135 // Also checking the type would be nice. 139 if ( decl ) { 140 // Pass. 141 } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) { 142 SemanticError(catchStmt->location, "catch must have exception type"); 143 } else { 144 SemanticError(catchStmt->location, "catchResume must have exception type"); 136 if ( !decl || !dynamic_cast<PointerType *>( decl->type ) ) { 137 std::string kind = (CatchStmt::Terminate == catchStmt->kind) ? "catch" : "catchResume"; 138 SemanticError( catchStmt->location, kind + " must have pointer to an exception type" ); 145 139 } 146 140 … … 232 226 233 227 void premutate( StructDecl *structDecl ); 234 Statement * postmutate( ThrowStmt *throwStmt );235 228 Statement * postmutate( TryStmt *tryStmt ); 236 229 }; … … 621 614 } 622 615 623 Statement * TryMutatorCore::postmutate( ThrowStmt * ) {624 // All throws should be removed by this point.625 assert( false );626 }627 628 616 Statement * TryMutatorCore::postmutate( TryStmt *tryStmt ) { 629 617 assert( except_decl ); -
src/ControlStruct/ExceptTranslate.h
ra5873bd r97392b69 29 29 /* Replaces all try blocks (and their many clauses) with function definitions and calls. 30 30 * This uses the exception built-ins to produce typed output and should take place after 31 * the resolver. 31 * the resolver. It also produces virtual casts and should happen before they are expanded. 32 32 */ 33 33 } -
src/Parser/parser.yy
ra5873bd r97392b69 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 27 12:25:42202013 // Update Count : 4 48312 // Last Modified On : Thu May 28 12:11:45 2020 13 // Update Count : 4500 14 14 // 15 15 … … 329 329 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 330 330 %type<en> comma_expression comma_expression_opt 331 %type<en> argument_expression_list argument_expression default_initialize_opt331 %type<en> argument_expression_list_opt argument_expression default_initialize_opt 332 332 %type<ifctl> if_control_expression 333 333 %type<fctl> for_control_expression for_control_expression_list … … 624 624 // equivalent to the old x[i,j]. 625 625 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 626 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call626 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 627 627 { 628 628 Token fn; … … 630 630 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 631 631 } 632 | postfix_expression '(' argument_expression_list ')'632 | postfix_expression '(' argument_expression_list_opt ')' 633 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 634 | postfix_expression '`' identifier // CFA, postfix call … … 662 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 663 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 664 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call664 | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call 665 665 { 666 666 Token fn; … … 670 670 ; 671 671 672 argument_expression_list :672 argument_expression_list_opt: 673 673 // empty 674 674 { $$ = nullptr; } 675 675 | argument_expression 676 | argument_expression_list ',' argument_expression676 | argument_expression_list_opt ',' argument_expression 677 677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 678 678 ; … … 1196 1196 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1197 1197 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1198 | '=' comma_expression // CFA1198 | '=' comma_expression // CFA 1199 1199 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1200 1200 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1203 1203 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1204 1204 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1205 | comma_expression ';' // CFA 1206 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); } 1205 1207 | comma_expression ';' comma_expression // CFA 1206 1208 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1207 1209 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1208 | comma_expression ';' '=' comma_expression // CFA1210 | comma_expression ';' '=' comma_expression // CFA 1209 1211 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1210 1212 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1304 1306 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex". 1305 1307 mutex_statement: 1306 MUTEX '(' argument_expression_list ')' statement1308 MUTEX '(' argument_expression_list_opt ')' statement 1307 1309 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } 1308 1310 ; … … 1321 1323 WAITFOR '(' cast_expression ')' 1322 1324 { $$ = $3; } 1323 // | WAITFOR '(' cast_expression ',' argument_expression_list ')'1325 // | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')' 1324 1326 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1325 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'1327 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')' 1326 1328 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1327 1329 ; … … 1330 1332 cast_expression 1331 1333 | cast_expression_list ',' cast_expression 1332 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1334 // { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1335 { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; } 1333 1336 ; 1334 1337 … … 2095 2098 2096 2099 aggregate_control: // CFA 2097 GENERATOR 2100 MONITOR 2101 { yyy = true; $$ = AggregateDecl::Monitor; } 2102 | MUTEX STRUCT 2103 { yyy = true; $$ = AggregateDecl::Monitor; } 2104 | GENERATOR 2098 2105 { yyy = true; $$ = AggregateDecl::Generator; } 2099 | M ONITORGENERATOR2106 | MUTEX GENERATOR 2100 2107 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2101 2108 | COROUTINE 2102 2109 { yyy = true; $$ = AggregateDecl::Coroutine; } 2103 | MONITOR 2104 { yyy = true; $$ = AggregateDecl::Monitor; } 2105 | MONITOR COROUTINE 2110 | MUTEX COROUTINE 2106 2111 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2107 2112 | THREAD 2108 2113 { yyy = true; $$ = AggregateDecl::Thread; } 2109 | M ONITORTHREAD2114 | MUTEX THREAD 2110 2115 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2111 2116 ; … … 2774 2779 | attr_name 2775 2780 { $$ = DeclarationNode::newAttribute( $1 ); } 2776 | attr_name '(' argument_expression_list ')'2781 | attr_name '(' argument_expression_list_opt ')' 2777 2782 { $$ = DeclarationNode::newAttribute( $1, $3 ); } 2778 2783 ; -
src/Virtual/ExpandCasts.cc
ra5873bd r97392b69 10 10 // Created On : Mon Jul 24 13:59:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tu s Aug 2 14:59:00 201713 // Update Count : 112 // Last Modified On : Tue May 26 14:37:00 2020 13 // Update Count : 2 14 14 // 15 15 … … 111 111 } 112 112 113 // Better error locations for generated casts. 114 static CodeLocation castLocation( VirtualCastExpr * castExpr ) { 115 if ( castExpr->location.isSet() ) { 116 return castExpr->location; 117 } else if ( castExpr->arg->location.isSet() ) { 118 return castExpr->arg->location; 119 } else if ( castExpr->result->location.isSet() ) { 120 return castExpr->result->location; 121 } else { 122 return CodeLocation(); 123 } 124 } 125 113 126 Expression * VirtualCastCore::postmutate( VirtualCastExpr * castExpr ) { 114 127 assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." ); … … 117 130 assert( pvt_decl ); 118 131 119 // May only cast to a pointer or reference type. 120 // A earlier validation should give a syntax error, this is 121 // just to make sure errors don't creep during translation. 122 // Move to helper with more detailed error messages. 123 PointerType * target_type = 124 dynamic_cast<PointerType *>( castExpr->get_result() ); 125 assert( target_type ); 132 // Get the base type of the pointer/reference. 133 Type * base; 134 Type * result_type = castExpr->result; 135 if ( PointerType * target = dynamic_cast<PointerType *>( result_type ) ) { 136 base = target->base; 137 } else if ( ReferenceType * target = dynamic_cast<ReferenceType *>( result_type ) ) { 138 base = target->base; 139 } else { 140 SemanticError( castLocation( castExpr ), 141 "Virtual cast type must be a pointer or reference type." ); 142 } 126 143 127 StructInstType * target_struct = 128 dynamic_cast<StructInstType *>( target_type->get_base() ); 129 assert( target_struct ); 130 144 StructInstType * target_struct = dynamic_cast<StructInstType *>( base ); 145 if ( nullptr == target_struct ) { 146 SemanticError( castLocation( castExpr ), 147 "Virtual cast type must refer to a structure type." ); 148 } 131 149 StructDecl * target_decl = target_struct->get_baseStruct(); 132 150 133 151 std::map<std::string, ObjectDecl *>::iterator found = 134 vtable_instances.find( 135 get_vtable_inst_name( target_decl->get_name() ) ); 152 vtable_instances.find( get_vtable_inst_name( target_decl->get_name() ) ); 136 153 if ( vtable_instances.end() == found ) { 137 assertf( false, "virtual table instance not found." ); 154 SemanticError( castLocation( castExpr ), 155 "Virtual cast type does not have a virtual table instance." ); 138 156 } 139 157 ObjectDecl * table = found->second; 140 158 141 159 Expression * result = new CastExpr( 142 //new ApplicationExpr(143 //new AddressExpr( new VariableExpr( vcast_decl ) ),144 //new CastExpr( new VariableExpr( vcast_decl ),145 // new PointerType( noQualifiers,146 // vcast_decl->get_type()->clone()147 // )148 // ),149 160 new ApplicationExpr( VariableExpr::functionPointer( vcast_decl ), { 150 161 new CastExpr(
Note:
See TracChangeset
for help on using the changeset viewer.