1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// This file is part of the AspectC++ compiler 'ac++'.
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
#include "NamespaceAC.h"
#include "CFlow.h"
// Puma includes
#include "Puma/CTypeInfo.h"
using namespace Puma;
// C++ includes
#include <sstream>
using std::ostringstream;
using std::endl;
string NamespaceAC::def (string size_type) {
string acdef;
acdef +=
"\n"
"#ifndef __ac_h_\n"
"#define __ac_h_\n"
"#ifdef __cplusplus\n"
"namespace AC {\n"
" typedef const char* Type;\n"
" enum JPType { CALL = 0x0004, EXECUTION = 0x0008, "
"CONSTRUCTION = 0x0010, DESTRUCTION = 0x0020 };\n"
" struct Action {\n"
" void **_args; void *_result; void *_target; void *_that; void *_fptr;\n"
" void (*_wrapper)(Action &);\n"
" inline void trigger () { _wrapper (*this); }\n"
" };\n"
" struct AnyResultBuffer {};\n"
" template <typename T> struct ResultBuffer : "
"public AnyResultBuffer {\n"
" char _data[sizeof (T)];\n"
" ~ResultBuffer () { ((T*)_data)->T::~T(); }\n"
" operator T& () const { return *(T*)_data; }\n"
" };\n"
" template <typename T, typename N> struct TL {\n"
" typedef T type; typedef N next; enum { ARGS = next::ARGS + 1 };\n"
" };\n"
" struct TLE { enum { ARGS = 0 }; };\n"
" template <typename T> struct Referred { typedef T type; };\n"
" template <typename T> struct Referred<T &> { typedef T type; };\n"
" template <typename TL, int I> struct Arg {\n"
" typedef typename Arg<typename TL::next, I - 1>::Type Type;\n"
" typedef typename Referred<Type>::type ReferredType;\n"
" };\n"
" template <typename TL> struct Arg<TL, 0> {\n"
" typedef typename TL::type Type;\n"
" typedef typename Referred<Type>::type ReferredType;\n"
" };\n"
" template <typename T> int ttest(...);\n"
" template <typename T> char ttest(typename T::__AttrTypes const volatile *);\n"
" template<typename T> struct HasTypeInfo {\n"
" enum { RET=((sizeof(ttest<T>(0))==1)?1:0) };\n"
" };\n"
" template<typename T, int HAVE = HasTypeInfo<T>::RET> struct TypeInfo {\n"
" enum { AVAILABLE = 0 };\n"
" };\n"
" template<typename T> struct TypeInfo<T, 1> {\n"
" enum { AVAILABLE = 1 };\n"
" enum { ELEMENTS = T::__AttrTypes::ARGS };\n"
" template<int I>\n"
" struct Member : public AC::Arg<typename T::__AttrTypes,I> {};\n"
" template<int I>\n"
" static typename Member<I>::ReferredType* member (T* obj) {\n"
" return (typename Member<I>::ReferredType*)obj->__attr (I);\n"
" }\n"
" static const char *member_name (T &obj, int i) {\n"
" return obj.__attr_name (i);\n"
" }\n"
" };\n";
// class(es) needed to implement CFlows
acdef += CFlow::ac_namespace_contributions ();
acdef +=
"}\n"
"inline void * operator new (";
if (size_type == "") {
ostringstream size_type_stream;
size_type_stream << *CTypeInfo::CTYPE_SIZE_T;
acdef += size_type_stream.str ();
}
else
acdef += size_type;
acdef +=
", AC::AnyResultBuffer *p) { return p; }\n"
"inline void operator delete "
"(void *, AC::AnyResultBuffer *) { } // for VC++\n"
"#endif // __cplusplus\n"
"#endif // __ac_h_\n";
return acdef;
}
|