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 // class_type_info.cc: Methods for __class_type_info.
     29 
     30 #include "cxxabi_defines.h"
     31 
     32 namespace __cxxabiv1
     33 {
     34   __class_type_info::~__class_type_info()
     35   {
     36   }
     37 
     38   bool __class_type_info::can_catch(const __shim_type_info* thrown_type,
     39                                     void*& adjustedPtr) const {
     40     if (*this == *thrown_type) {
     41       return true;
     42     }
     43 
     44     const __class_type_info* thrown_class_type =
     45       dynamic_cast<const __class_type_info*>(thrown_type);
     46     if (thrown_class_type == 0) {
     47       return false;
     48     }
     49 
     50     __UpcastInfo info(this);
     51     thrown_class_type->walk_to(this, adjustedPtr, info);
     52 
     53     if (info.status != __UpcastInfo::has_public_contained) {
     54       return false;
     55     }
     56 
     57     adjustedPtr = info.adjustedPtr;
     58     return true;
     59   }
     60 
     61   bool __class_type_info::walk_to(const __class_type_info* base_type,
     62                                   void*& adjustedPtr,
     63                                   __UpcastInfo& info) const {
     64     return self_class_type_match(base_type, adjustedPtr, info);
     65   }
     66 
     67   bool __class_type_info::self_class_type_match(const __class_type_info* base_type,
     68                                                 void*& adjustedPtr,
     69                                                 __UpcastInfo& info) const {
     70     if (*this == *base_type) {
     71       info.status = __UpcastInfo::has_public_contained;
     72       info.base_type = base_type;
     73       info.adjustedPtr = adjustedPtr;
     74       info.nullobj_may_conflict = true;
     75       return true;
     76     }
     77 
     78     return false;
     79   }
     80 
     81 
     82   __UpcastInfo::__UpcastInfo(const __class_type_info* type)
     83     : status(unknown), base_type(0), adjustedPtr(0),
     84       premier_flags(0), nullobj_may_conflict(true) {
     85     // Keep the shape information for future use.
     86     if (const __vmi_class_type_info* p =
     87            dynamic_cast<const __vmi_class_type_info*>(type)) {
     88       premier_flags = p->__flags;
     89     }
     90   }
     91 } // namespace __cxxabiv1
     92