typeinfo revision 233699
1169691Skan// RTTI support for -*- C++ -*-
2169691Skan// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3169691Skan// 2003, 2004, 2005, 2006, 2007
4169691Skan// Free Software Foundation
5169691Skan//
6169691Skan// This file is part of GCC.
7169691Skan//
8169691Skan// GCC is free software; you can redistribute it and/or modify
9169691Skan// it under the terms of the GNU General Public License as published by
10169691Skan// the Free Software Foundation; either version 2, or (at your option)
11169691Skan// any later version.
12169691Skan// 
13169691Skan// GCC is distributed in the hope that it will be useful,
14169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of
15169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16169691Skan// GNU General Public License for more details.
17169691Skan// 
18169691Skan// You should have received a copy of the GNU General Public License
19169691Skan// 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.
22169691Skan
23169691Skan// As a special exception, you may use this file as part of a free software
24169691Skan// library without restriction.  Specifically, if other files instantiate
25169691Skan// templates or use macros or inline functions from this file, or you compile
26169691Skan// this file and link it with other files to produce an executable, this
27169691Skan// file does not by itself cause the resulting executable to be covered by
28169691Skan// the GNU General Public License.  This exception does not however
29169691Skan// invalidate any other reasons why the executable file might be covered by
30169691Skan// the GNU General Public License.
31169691Skan
32169691Skan/** @file typeinfo
33169691Skan *  This is a Standard C++ Library header.
34169691Skan */
35169691Skan
36169691Skan#ifndef _TYPEINFO
37169691Skan#define _TYPEINFO
38169691Skan
39169691Skan#include <exception>
40169691Skan
41169691Skan#pragma GCC visibility push(default)
42169691Skan
43169691Skanextern "C++" {
44169691Skan
45169691Skannamespace __cxxabiv1
46169691Skan{
47169691Skan  class __class_type_info;
48169691Skan} // namespace __cxxabiv1
49169691Skan
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
58169691Skan#endif
59169691Skan
60169691Skannamespace std 
61169691Skan{
62169691Skan  /**
63169691Skan   *  @brief  Part of RTTI.
64169691Skan   *
65169691Skan   *  The @c type_info class describes type information generated by
66169691Skan   *  an implementation.
67169691Skan  */
68169691Skan  class type_info 
69169691Skan  {
70169691Skan  public:
71169691Skan    /** Destructor first. Being the first non-inline virtual function, this
72169691Skan     *  controls in which translation unit the vtable is emitted. The
73169691Skan     *  compiler makes use of that information to know where to emit
74169691Skan     *  the runtime-mandated type_info structures in the new-abi.  */
75169691Skan    virtual ~type_info();
76169691Skan
77169691Skan    /** Returns an @e implementation-defined byte string; this is not
78169691Skan     *  portable between compilers!  */
79169691Skan    const char* name() const
80169691Skan    { return __name; }
81169691Skan
82169691Skan#if !__GXX_MERGED_TYPEINFO_NAMES
83169691Skan    bool before(const type_info& __arg) const;
84169691Skan
85169691Skan    // In old abi, or when weak symbols are not supported, there can
86169691Skan    // be multiple instances of a type_info object for one
87169691Skan    // type. Uniqueness must use the _name value, not object address.
88169691Skan    bool operator==(const type_info& __arg) const;
89169691Skan#else
90169691Skan    /** Returns true if @c *this precedes @c __arg in the implementation's
91169691Skan     *  collation order.  */
92169691Skan    // In new abi we can rely on type_info's NTBS being unique,
93169691Skan    // and therefore address comparisons are sufficient.
94169691Skan    bool before(const type_info& __arg) const
95169691Skan    { return __name < __arg.__name; }
96169691Skan
97169691Skan    bool operator==(const type_info& __arg) const
98169691Skan    { return __name == __arg.__name; }
99169691Skan#endif
100169691Skan    bool operator!=(const type_info& __arg) const
101169691Skan    { return !operator==(__arg); }
102169691Skan
103169691Skan    // Return true if this is a pointer type of some kind
104169691Skan    virtual bool __is_pointer_p() const;
105169691Skan
106169691Skan    // Return true if this is a function type
107169691Skan    virtual bool __is_function_p() const;
108169691Skan
109169691Skan    // Try and catch a thrown type. Store an adjusted pointer to the
110169691Skan    // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
111169691Skan    // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
112169691Skan    // type, then THR_OBJ is the pointer itself. OUTER indicates the
113169691Skan    // number of outer pointers, and whether they were const
114169691Skan    // qualified.
115169691Skan    virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
116169691Skan			    unsigned __outer) const;
117169691Skan
118169691Skan    // Internally used during catch matching
119169691Skan    virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
120169691Skan			     void **__obj_ptr) const;
121169691Skan
122169691Skan  protected:
123169691Skan    const char *__name;
124169691Skan    
125169691Skan    explicit type_info(const char *__n): __name(__n) { }
126169691Skan    
127169691Skan  private:
128169691Skan    /// Assigning type_info is not supported.
129169691Skan    type_info& operator=(const type_info&);
130169691Skan    type_info(const type_info&);
131169691Skan  };
132169691Skan
133169691Skan  /**
134169691Skan   *  @brief  Thrown during incorrect typecasting.
135169691Skan   *
136169691Skan   *  If you attempt an invalid @c dynamic_cast expression, an instance of
137169691Skan   *  this class (or something derived from this class) is thrown.  */
138169691Skan  class bad_cast : public exception 
139169691Skan  {
140169691Skan  public:
141169691Skan    bad_cast() throw() { }
142169691Skan
143169691Skan    // This declaration is not useless:
144169691Skan    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
145169691Skan    virtual ~bad_cast() throw();
146169691Skan
147169691Skan    // See comment in eh_exception.cc.
148169691Skan    virtual const char* what() const throw();
149169691Skan  };
150169691Skan  
151169691Skan  /** If you use a NULL pointer in a @c typeid expression, this is thrown.  */
152169691Skan  class bad_typeid : public exception 
153169691Skan  {
154169691Skan  public:
155169691Skan    bad_typeid () throw() { }
156169691Skan
157169691Skan    // This declaration is not useless:
158169691Skan    // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
159169691Skan    virtual ~bad_typeid() throw();
160169691Skan
161169691Skan    // See comment in eh_exception.cc.
162169691Skan    virtual const char* what() const throw();
163169691Skan  };
164169691Skan} // namespace std
165169691Skan
166169691Skan#pragma GCC visibility pop
167169691Skan
168169691Skan} // extern "C++"
169169691Skan#endif
170169691Skan