File: PumaResultBuffer.cc

package info (click to toggle)
aspectc%2B%2B 1%3A2.2%2Bgit20181008-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,704 kB
  • sloc: cpp: 110,629; ansic: 7,644; sh: 2,192; makefile: 1,317; pascal: 634; python: 402; xml: 349
file content (151 lines) | stat: -rw-r--r-- 4,602 bytes parent folder | download | duplicates (7)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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 "PumaResultBuffer.h"
#include "Puma/CTypeInfo.h"
#include <sstream>
using std::stringstream;
using namespace Puma;

bool PumaResultBuffer::has_constructor_problem () const {
  return _type->isRecord () && !_type->isAddress ();
}

string PumaResultBuffer::tjp_result_type () const {
  stringstream out;
  CTypeInfo *type = _type;
  if (type->isVoid () || type->isUndefined ())
    out << "void";
  else if (type->isAddress ()) {
    if (_use_typedef) {
      if (type->BaseType()->isConst())
        out << "const ";
      out << "TResult";
    }
    else
      type->BaseType ()->TypeText (out, "", true, true);
  }
  else
    if (_use_typedef) {
      if (type->isConst())
        out << "const ";
      out << "TResult";
    }
    else
      type->TypeText (out, "", true, true);
  return out.str ();
}

string PumaResultBuffer::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;
    if (_use_typedef) {
      if (type->BaseType()->isConst())
        out << "const ";
      out << "TResult " << ptrname;
    }
    else {
      if (type->BaseType ()->TypeFunction () || type->BaseType ()->TypeArray ())
        ptrname = string("(") + ptrname + ")";
      type->BaseType ()->TypeText (out, ptrname.c_str (), true, true);
    }
  }
  else
    if (_use_typedef) {
      if (type->isConst())
        out << "const ";
      out << "TResult " << name;
    }
    else
      type->TypeText (out, name.c_str (), true, true);
  return out.str ();
}

string PumaResultBuffer::result_declaration() const {
  stringstream out;
  if (!(_type->isVoid () || _type->isUndefined ())) {
    if (_problem)
      out << "AC::ResultBuffer< " << result_type ("", false) << " > " << result_name();
    else
      out << result_type (result_name(), true);
    out << ";" << endl;
  }
  return out.str ();
}

string PumaResultBuffer::result_assignment(const string &result) const {
  stringstream out;
  if (!(_type->isVoid() || _type->isUndefined ()))  {
    if (_problem) {
      out << "::new (&" << result_name() << ") ";
      out << result_type ("", true);
      out << " (";
    }
    else
      out << result_name() << " = ";
    if (_type->isAddress ())
      out << "&";
  }
  out << result;
  if (!(_type->isVoid() || _type->isUndefined ()))
    if (_problem)
      out << ")";
  return out.str ();
}

string PumaResultBuffer::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 PumaResultBuffer::result_return() const {
  stringstream out;
  if (!(_type->isVoid () || _type->isUndefined ())) {
    out << "return ";
    if (_type->isAddress ())
      out << "*";
    out << "(";
    out << result_type ("&");
    out << ")" << result_name() << ";" << endl;
  }
  return out.str ();
}