1 / 10

RTTI

RTTI. CNS 4490. Example. class One{ } class Two : One { } class Driver{ void main() { One bob = new Two(); if (bob is Two) doSomething(); } }. Example. Steps 1. Alloc space for bob 2. In bob’s v-table Include type info

Download Presentation

RTTI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RTTI CNS 4490

  2. Example class One{ } class Two : One { } class Driver{ void main() { One bob = new Two(); if (bob is Two) doSomething(); } }

  3. Example Steps 1. Alloc space for bob 2. In bob’s v-table Include type info 3. Call constructor for Bob 4. check type var with numeric code for Two 5. doSomething( ) class One{ } class Two : One { } class Driver{ void main() { One bob = new Two(); if (bob is Two) doSomething(); } }

  4. typeid ptr to parent vtable virtual fun1 virtual fun2 v-table

  5. typeid ptr to parent vtable virtual fun1 2 4008 4000 virtual fun2 v-table for Two v-table 1 4000 0 v-table for One

  6. Example class One{ } class Two : One { } class Driver{ void main() { int j; One bob = new Two(); if (bob is Two) j = 3; } } bob ptr vtable ptr bp j ctrl link ret-addr

  7. Example mov r1, [bp +4] ; 4008 mov r1, [r1] ; 2 :check cmp r1 , 2 je assign mov r1, [r1+4] ; 4000 mov r1, [r1] :assign mov r1, bp ; j mov [r1], 3 class One{ } class Two : One { } class Driver{ void main() { int j; One bob = new Two(); if (bob is Two) j = 3; } } bob ptr vtable ptr bp j ctrl link ret-addr

  8. Example 2 class One { } class Two { void printMe() {…} } class Driver { void main() { One bob = new Two( ); Two joe = bob as Two; } } • steps: • Set up bob • check bob’s type • assign pointer to joe

  9. Example 2 class One { } class Two { void printMe() {…} } class Driver { void main() { One bob = new Two( ); Two joe = bob as Two; } } • steps: • Set up bob • check bob’s type • assign pointer to joe joe ptr bp bob ptr vtable ptr ctrl link ret-addr

  10. Example 2 mov r1, [bp] ; 4008 mov r1, [r1] ; 2 :check cmp r1 , 2 je assign throw invalid cast exception :assign mov r1, bp + 4 ; joe mov r2, [bp] mov [r1], r2 class One { } class Two { void printMe() {…} } class Driver { void main() { One bob = new Two( ); Two joe = bob as Two; } } joe ptr bp bob ptr vtable ptr ctrl link ret-addr

More Related