Changeset c19bc90
- Timestamp:
- May 26, 2020, 4:03:30 PM (4 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:
- ada0246d
- Parents:
- b2de2e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Virtual/ExpandCasts.cc
rb2de2e0 rc19bc90 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.