Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/lang/cx_locator.h

Go to the documentation of this file.
00001 //  Copyright (C) 2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 //
00027 //  $Id: cx_locator.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00028 
00029 
00030 #ifndef MORE_LANG_CX_LOCATOR_H
00031 #define MORE_LANG_CX_LOCATOR_H
00032 
00033 #include <stdexcept>
00034 #include <more/gen/gc_string.h>
00035 #include <more/lang/fwd.h>
00036 #include <more/lang/ct_struct.h>
00037 #include <more/lang/ct_proto.h>
00038 #include <more/lang/cx_expr.h>
00039 #include <more/lang/location.h>
00040 
00041 
00042 namespace more {
00043 namespace lang {
00044 
00045   /** The locator of an object inside a compound.  This can be be used
00046       to runtime or to gererate C source code. */
00047   struct cx_locator : cx_expr
00048   {
00049       typedef std::size_t size_type;
00050     private:
00051       typedef ct_struct::member_const_iterator member_const_iterator;
00052 
00053 //     public:
00054 //       /** Construct the identity locator operator. */
00055 //       cx_locator(ct_type* rtt)
00056 //        : m_cxt_locr(0),
00057 //          m_cxt_type(0),
00058 //          m_offset_count(0),
00059 //          m_offset_arr(0) {}
00060 
00061     protected:
00062       /// Used for struct members and pointer derefs.
00063       cx_locator(cx_locator* cxt_locr,
00064                  ct_type const* cxt_type,
00065                  ct_type const* result_type,
00066                  size_type offset_count);
00067 
00068       /// Partical construction used by ct_struct::member.
00069       cx_locator(ct_type const* arg0_type,
00070                  ct_type const* result_type);
00071 
00072     public:
00073       /** The result type of the locator. */
00074       ct_type const* result_type() const
00075       {
00076           return static_cast<ct_proto const*>(type_of())->result_type();
00077       }
00078 
00079       /** The argument type of the locator. */
00080       ct_type const* arg0_type() const
00081       {
00082           return static_cast<ct_proto const*>(type_of())->arg_type(0);
00083       }
00084 
00085       virtual void print_operation_pre(std::ostream&) const = 0;
00086       virtual void print_operation_post(std::ostream&) const = 0;
00087 
00088       virtual void append_ctors_to(cx_block*);
00089       virtual void append_dtors_to(cx_block*);
00090 
00091       /** The locator of the context.  If this is a member, the
00092           context is a structure, if this is a pointer dereference,
00093           the context is a pointer, etc.  */
00094       cx_locator const* context_locator() const { return m_cxt_locr; }
00095 
00096       /** Return true iff \a loc0 and \a loc1 are equal.  The locators
00097           are equal if, given the same argument address, they give the
00098           same address.
00099           \pre \c loc0->type_of() and \c loc1->type_of() are the
00100           same. */
00101       friend bool
00102       equal(cx_locator* loc0, cx_locator* loc1)
00103       {
00104           return loc0->offset_count() == loc1->offset_count()
00105               && std::equal(loc0->offset_begin(), loc0->offset_end(),
00106                             loc1->offset_begin());
00107       }
00108 
00109     protected:
00110       /** Returns the type of the context of this locator.  It is
00111           more instructive to look at the overloads provided in
00112           derived classes. */
00113       ct_type const* context_type() const { return m_cxt_type; }
00114 
00115     public:
00116       /** Apply the locator operator to ptr. */
00117       void* apply(void* ptr);
00118 
00119       void debug_dump(std::ostream& os);
00120 
00121     private:
00122       size_type         offset_count() const { return m_offset_count; }
00123       size_type const*  offset_begin() const { return m_offset_arr; }
00124       size_type const*  offset_end() const
00125       {
00126           return m_offset_arr + m_offset_count;
00127       }
00128 
00129       // The context of this locator and its type.
00130       cx_locator const*         m_cxt_locr;
00131       ct_type const*            m_cxt_type;
00132 
00133       // Runtime locator: Offsets.
00134       // An optimalization. Each element represents a translation of
00135       // the address, and dereference happend _beween_ each element.
00136       size_type                 m_offset_count;
00137       size_type*                m_offset_arr;
00138 
00139       friend struct cx_member_locator;
00140       friend struct cx_deref_locator;
00141       friend struct rt_arg_locator;
00142       friend struct rt_result_locator;
00143   };
00144 
00145   /** The locator of a member in a structure. */
00146   struct cx_member_locator : cx_locator
00147   {
00148       cx_member_locator(ct_struct const*, ct_struct::member_const_iterator);
00149       cx_member_locator(cx_locator*, ct_struct::member_const_iterator);
00150       cx_member_locator(cx_locator*, cx_member_locator const*);
00151 
00152       virtual ct_type const* result_type() const;
00153       virtual void print_operation_pre(std::ostream&) const;
00154       virtual void print_operation_post(std::ostream&) const;
00155 
00156       ct_struct const* context_type() const
00157       {
00158           return static_cast<ct_struct const*>(m_cxt_type);
00159       }
00160 
00161     private:
00162       ct_struct::member_const_iterator  m_it_memb;
00163   };
00164 
00165   /** The locator of an object referred to by a pointer. */
00166   struct cx_deref_locator : cx_locator
00167   {
00168       explicit cx_deref_locator(ct_pointer const*);
00169       explicit cx_deref_locator(cx_locator*);
00170       cx_deref_locator(cx_locator*, cx_deref_locator const*);
00171 
00172       virtual ct_type const* result_type() const;
00173       virtual void print_operation_pre(std::ostream&) const;
00174       virtual void print_operation_post(std::ostream&) const;
00175 
00176       ct_pointer const* context_type() const
00177       {
00178           return static_cast<ct_pointer const*>(m_cxt_type);
00179       }
00180   };
00181 
00182   /** Handler for a location inside a location.  This is implemented
00183       as an \c cx_locator applied to the result of another
00184       <tt>cx_resolver</tt>. */
00185   struct cx_locator_resolver : resolver
00186   {
00187       /** Construct a sublocation \a lr of \a h. */
00188       cx_locator_resolver(resolver* h, cx_locator* lr)
00189           : m_locn(h),
00190             m_locr(lr) {}
00191 
00192       virtual ct_type const* resolve_type_of() const;
00193       virtual void* resolve();
00194       virtual bool equal_to(resolver* rhs);
00195 
00196     private:
00197       location          m_locn;
00198       cx_locator*       m_locr;
00199   };
00200 
00201 }}
00202 
00203 #endif

Generated on Sat Sep 7 19:11:17 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.