Home | History | Annotate | Download | only in src
      1 // Copyright (C) 2011 The Android Open Source Project
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions
      6 // are met:
      7 // 1. Redistributions of source code must retain the above copyright
      8 //    notice, this list of conditions and the following disclaimer.
      9 // 2. Redistributions in binary form must reproduce the above copyright
     10 //    notice, this list of conditions and the following disclaimer in the
     11 //    documentation and/or other materials provided with the distribution.
     12 // 3. Neither the name of the project nor the names of its contributors
     13 //    may be used to endorse or promote products derived from this software
     14 //    without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19 // ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26 // SUCH DAMAGE.
     27 //
     28 // pbase_type_info.cc: Methods for __pbase_type_info.
     29 
     30 #include "cxxabi_defines.h"
     31 
     32 namespace __cxxabiv1
     33 {
     34   __pbase_type_info::~__pbase_type_info()
     35   {
     36   }
     37 
     38   bool __pbase_type_info::can_catch(const __shim_type_info* thr_type,
     39                                     void*& adjustedPtr) const {
     40     unsigned tracker = first_time_init;
     41     return can_catch_typeinfo_wrapper(thr_type, adjustedPtr, tracker);
     42   }
     43 
     44   bool __pbase_type_info::can_catch_typeinfo_wrapper(const __shim_type_info* thr_type,
     45                                                      void*& adjustedPtr,
     46                                                      unsigned tracker) const {
     47     if (*this == *thr_type) {
     48       return true;
     49     }
     50 
     51     if (typeid(*this) != typeid(*thr_type)) {
     52       return false;
     53     }
     54     const __pbase_type_info *thrown_type =
     55         static_cast<const __pbase_type_info *>(thr_type);
     56 
     57     // Both side must be the same cv-qualified
     58     if (~__flags & thrown_type->__flags) {
     59       return false;
     60     }
     61 
     62     // Handle the annoying constness problem
     63     // Ref: http://www.parashift.com/c++-faq-lite/constptrptr-conversion.html
     64     if (tracker == first_time_init &&
     65         (tracker & keep_constness) != keep_constness &&
     66         (tracker & after_gap) != after_gap) {
     67       tracker |= keep_constness;
     68     } else {
     69       tracker &= ~first_time_init;
     70     }
     71 
     72     if ((tracker & first_time_init) != first_time_init &&
     73         (tracker & after_gap) == after_gap) {
     74       return false;
     75     }
     76 
     77     if (!(__flags & __const_mask)) {
     78       tracker |= after_gap;
     79     }
     80 
     81     return can_catch_ptr(thrown_type, adjustedPtr, tracker);
     82   }
     83 
     84   bool __pbase_type_info::can_catch_ptr(const __pbase_type_info* thrown_type,
     85                                         void*& adjustedPtr,
     86                                         unsigned tracker) const {
     87     bool result;
     88     if (do_can_catch_ptr(thrown_type, adjustedPtr, tracker,
     89                          result)) {
     90       return result;
     91     }
     92 
     93     const __pbase_type_info* ptr_pointee =
     94         dynamic_cast<const __pbase_type_info*>(__pointee);
     95 
     96     if (ptr_pointee) {
     97       return ptr_pointee->can_catch_typeinfo_wrapper(thrown_type->__pointee,
     98                                                      adjustedPtr,
     99                                                      tracker);
    100     } else {
    101       return __pointee->can_catch(thrown_type->__pointee, adjustedPtr);
    102     }
    103   }
    104 } // namespace __cxxabiv1
    105