197403Sobrien// RTTI support for -*- C++ -*-
2169691Skan// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3169691Skan// 2003, 2004, 2005, 2006, 2007
497403Sobrien// Free Software Foundation
597403Sobrien//
6132720Skan// This file is part of GCC.
797403Sobrien//
8132720Skan// GCC is free software; you can redistribute it and/or modify
997403Sobrien// it under the terms of the GNU General Public License as published by
1097403Sobrien// the Free Software Foundation; either version 2, or (at your option)
1197403Sobrien// any later version.
1297403Sobrien// 
13132720Skan// GCC is distributed in the hope that it will be useful,
1497403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1597403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1697403Sobrien// GNU General Public License for more details.
1797403Sobrien// 
1897403Sobrien// You should have received a copy of the GNU General Public License
19132720Skan// along with GCC; see the file COPYING.  If not, write to
20169691Skan// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21169691Skan// Boston, MA 02110-1301, USA.
2297403Sobrien
2397403Sobrien// As a special exception, you may use this file as part of a free software
2497403Sobrien// library without restriction.  Specifically, if other files instantiate
2597403Sobrien// templates or use macros or inline functions from this file, or you compile
2697403Sobrien// this file and link it with other files to produce an executable, this
2797403Sobrien// file does not by itself cause the resulting executable to be covered by
2897403Sobrien// the GNU General Public License.  This exception does not however
2997403Sobrien// invalidate any other reasons why the executable file might be covered by
3097403Sobrien// the GNU General Public License.
3197403Sobrien
3297403Sobrien/** @file typeinfo
33169691Skan *  This is a Standard C++ Library header.
3497403Sobrien */
3597403Sobrien
36132720Skan#ifndef _TYPEINFO
37132720Skan#define _TYPEINFO
3897403Sobrien
3997403Sobrien#include <exception>
4097403Sobrien
41169691Skan#pragma GCC visibility push(default)
42169691Skan
4397403Sobrienextern "C++" {
4497403Sobrien
4597403Sobriennamespace __cxxabiv1
4697403Sobrien{
4797403Sobrien  class __class_type_info;
4897403Sobrien} // namespace __cxxabiv1
4997403Sobrien
50169691Skan#ifndef __GXX_MERGED_TYPEINFO_NAMES
51169691Skan  #if !__GXX_WEAK__
52169691Skan    // If weak symbols are not supported, typeinfo names are not merged.
53169691Skan    #define __GXX_MERGED_TYPEINFO_NAMES 0
54169691Skan  #else
55169691Skan    // On platforms that support weak symbols, typeinfo names are merged.
56169691Skan    #define __GXX_MERGED_TYPEINFO_NAMES 1
57169691Skan  #endif
5897403Sobrien#endif
5997403Sobrien
6097403Sobriennamespace std 
6197403Sobrien{
62117397Skan  /**
63117397Skan   *  @brief  Part of RTTI.
64117397Skan   *
65117397Skan   *  The @c type_info class describes type information generated by
6697403Sobrien   *  an implementation.
67117397Skan  */
6897403Sobrien  class type_info 
6997403Sobrien  {
7097403Sobrien  public:
71171827Skan    /** Destructor first. Being the first non-inline virtual function, this
7297403Sobrien     *  controls in which translation unit the vtable is emitted. The
7397403Sobrien     *  compiler makes use of that information to know where to emit
7497403Sobrien     *  the runtime-mandated type_info structures in the new-abi.  */
7597403Sobrien    virtual ~type_info();
7697403Sobrien
7797403Sobrien    /** Returns an @e implementation-defined byte string; this is not
7897403Sobrien     *  portable between compilers!  */
7997403Sobrien    const char* name() const
8097403Sobrien    { return __name; }
8197403Sobrien
8297403Sobrien#if !__GXX_MERGED_TYPEINFO_NAMES
8397403Sobrien    bool before(const type_info& __arg) const;
84171827Skan
8597403Sobrien    // In old abi, or when weak symbols are not supported, there can
8697403Sobrien    // be multiple instances of a type_info object for one
8797403Sobrien    // type. Uniqueness must use the _name value, not object address.
8897403Sobrien    bool operator==(const type_info& __arg) const;
8997403Sobrien#else
9097403Sobrien    /** Returns true if @c *this precedes @c __arg in the implementation's
9197403Sobrien     *  collation order.  */
9297403Sobrien    // In new abi we can rely on type_info's NTBS being unique,
9397403Sobrien    // and therefore address comparisons are sufficient.
9497403Sobrien    bool before(const type_info& __arg) const
9597403Sobrien    { return __name < __arg.__name; }
96171827Skan
9797403Sobrien    bool operator==(const type_info& __arg) const
9897403Sobrien    { return __name == __arg.__name; }
9997403Sobrien#endif
10097403Sobrien    bool operator!=(const type_info& __arg) const
10197403Sobrien    { return !operator==(__arg); }
102228780Spfg
103233699Stheraven    // Return true if this is a pointer type of some kind
104233699Stheraven    virtual bool __is_pointer_p() const;
105233699Stheraven
106233699Stheraven    // Return true if this is a function type
107233699Stheraven    virtual bool __is_function_p() const;
108233699Stheraven
10997403Sobrien    // Try and catch a thrown type. Store an adjusted pointer to the
11097403Sobrien    // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
11197403Sobrien    // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
11297403Sobrien    // type, then THR_OBJ is the pointer itself. OUTER indicates the
11397403Sobrien    // number of outer pointers, and whether they were const
11497403Sobrien    // qualified.
11597403Sobrien    virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
11697403Sobrien			    unsigned __outer) const;
11797403Sobrien
118171827Skan    // Internally used during catch matching
11997403Sobrien    virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
12097403Sobrien			     void **__obj_ptr) const;
121171827Skan
122171827Skan  protected:
123171827Skan    const char *__name;
124171827Skan    
125171827Skan    explicit type_info(const char *__n): __name(__n) { }
126171827Skan    
127171827Skan  private:
128171827Skan    /// Assigning type_info is not supported.
129171827Skan    type_info& operator=(const type_info&);
130171827Skan    type_info(const type_info&);
13197403Sobrien  };
13297403Sobrien
133117397Skan  /**
134117397Skan   *  @brief  Thrown during incorrect typecasting.
135117397Skan   *
136117397Skan   *  If you attempt an invalid @c dynamic_cast expression, an instance of
13797403Sobrien   *  this class (or something derived from this class) is thrown.  */
13897403Sobrien  class bad_cast : public exception 
13997403Sobrien  {
14097403Sobrien  public:
14197403Sobrien    bad_cast() throw() { }
142171827Skan
14397403Sobrien    // This declaration is not useless:
14497403Sobrien    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
14597403Sobrien    virtual ~bad_cast() throw();
146171827Skan
147169691Skan    // See comment in eh_exception.cc.
148169691Skan    virtual const char* what() const throw();
14997403Sobrien  };
15097403Sobrien  
15197403Sobrien  /** If you use a NULL pointer in a @c typeid expression, this is thrown.  */
15297403Sobrien  class bad_typeid : public exception 
15397403Sobrien  {
15497403Sobrien  public:
15597403Sobrien    bad_typeid () throw() { }
156171827Skan
15797403Sobrien    // This declaration is not useless:
15897403Sobrien    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
15997403Sobrien    virtual ~bad_typeid() throw();
160171827Skan
161169691Skan    // See comment in eh_exception.cc.
162169691Skan    virtual const char* what() const throw();
16397403Sobrien  };
16497403Sobrien} // namespace std
16597403Sobrien
166169691Skan#pragma GCC visibility pop
167169691Skan
16897403Sobrien} // extern "C++"
16997403Sobrien#endif
170