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
|
// 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 "ResultBuffer.h"
#include "Puma/CTypeInfo.h"
#include <sstream>
using std::stringstream;
bool ResultBuffer::has_constructor_problem () const {
return _type->isRecord () && !_type->isAddress ();
}
string ResultBuffer::result_type (const string &name, bool unqual) const {
stringstream out;
CTypeInfo *type = _type;
if (unqual)
type = type->UnqualType ();
if (type->isVoid () || type->isUndefined ())
out << "void";
else if (type->isAddress ()) {
string ptrname = string ("*") + name;
type->BaseType ()->TypeText (out, ptrname.c_str (), true, true);
}
else
type->TypeText (out, name.c_str (), true, true);
return out.str ();
}
string ResultBuffer::result_declaration() const {
stringstream out;
if (!(_type->isVoid () || _type->isUndefined ())) {
if (_problem)
out << "AC::ResultBuffer< " << result_type ("", false) << " > result";
else
out << result_type ("result", true);
out << ";" << endl;
}
return out.str ();
}
string ResultBuffer::result_assignment(const string &result) const {
stringstream out;
if (!(_type->isVoid() || _type->isUndefined ())) {
if (_problem) {
out << "::new (&result) ";
out << result_type ("", true);
out << " (";
}
else
out << "result = ";
if (_type->isAddress ())
out << "&";
}
out << result;
if (!(_type->isVoid() || _type->isUndefined ()))
if (_problem)
out << ")";
return out.str ();
}
string ResultBuffer::action_result_assignment(const string &result) const {
stringstream out;
if (!(_type->isVoid() || _type->isUndefined ())) {
if (_problem) {
out << "::new ((AC::ResultBuffer< ";
out << result_type ("", false);
out << " >*)__TJP::result ()) ";
out << result_type ("", false);
out << " (";
}
else {
out << "*__TJP::result () = (" << result_type ("", false) << ")";
}
if (_type->isAddress ())
out << "&";
}
out << result;
if (!(_type->isVoid() || _type->isUndefined ()))
if (_problem)
out << ")";
return out.str ();
}
string ResultBuffer::result_return() const {
stringstream out;
if (!(_type->isVoid () || _type->isUndefined ())) {
out << "return ";
if (_type->isAddress ())
out << "*";
out << "(";
out << result_type ("&");
out << ")result;" << endl;
}
return out.str ();
}
|