Changes in src/Virtual/ExpandCasts.cc [c19bc90:8e6214f]
- File:
-
- 1 edited
-
src/Virtual/ExpandCasts.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Virtual/ExpandCasts.cc
rc19bc90 r8e6214f 10 10 // Created On : Mon Jul 24 13:59:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tu e May 26 14:37:00 202013 // Update Count : 212 // Last Modified On : Tus Aug 2 14:59:00 2017 13 // Update Count : 1 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 126 113 Expression * VirtualCastCore::postmutate( VirtualCastExpr * castExpr ) { 127 114 assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." ); … … 130 117 assert( pvt_decl ); 131 118 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 } 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 ); 143 126 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 } 127 StructInstType * target_struct = 128 dynamic_cast<StructInstType *>( target_type->get_base() ); 129 assert( target_struct ); 130 149 131 StructDecl * target_decl = target_struct->get_baseStruct(); 150 132 151 133 std::map<std::string, ObjectDecl *>::iterator found = 152 vtable_instances.find( get_vtable_inst_name( target_decl->get_name() ) ); 134 vtable_instances.find( 135 get_vtable_inst_name( target_decl->get_name() ) ); 153 136 if ( vtable_instances.end() == found ) { 154 SemanticError( castLocation( castExpr ), 155 "Virtual cast type does not have a virtual table instance." ); 137 assertf( false, "virtual table instance not found." ); 156 138 } 157 139 ObjectDecl * table = found->second; 158 140 159 141 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 // ), 160 149 new ApplicationExpr( VariableExpr::functionPointer( vcast_decl ), { 161 150 new CastExpr(
Note:
See TracChangeset
for help on using the changeset viewer.