File: ClangResultBuffer.h

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 (78 lines) | stat: -rw-r--r-- 3,293 bytes parent folder | download | duplicates (3)
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
// 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                                            

#ifndef __ClangResultBuffer_h__
#define __ClangResultBuffer_h__

#include "ACModel/Elements.h"
#include "TransformInfo.h"
#include "ACProject.h"
#include "ACModel/Utils.h"

#include <string>
using std::string;

namespace Puma {
  class CTypeInfo;
}

class ClangResultBuffer {
  clang::QualType _type;
  ACProject &_project;
  clang::ASTContext& _ast_ctx;
  bool _problem;
  bool _use_typedef;
  bool _const_result;
  bool has_constructor_problem () const;
  bool workaround_const_result() const { return _const_result; }
public:
  ClangResultBuffer (ACProject &project, ACM_Code *jpl, bool use_typedef = false) :
    _project (project),
    _ast_ctx(project.get_compiler_instance ()->getASTContext ()),
    _use_typedef( use_typedef ), _const_result( false ) {
    //_policy.SuppressUnwrittenScope = true; // Suppress printing of <anonymous>
    // builtin constructors/destructors have no decl -> result type is 'void'
    if ( jpl->type_val() == JPT_Get )
      // FIXME: If the get join point accesses an array, the function
      //        get_result_type( *jpl ) returns the type of the array
      //        instead of the actual element type.
      //        As a workaround, use TI_GET::entity_type() here.
      //        Once get_result_type( *jpl ) yields the correct type,
      //        this special case can be removed.
      _type = TI_Get::of(*static_cast<ACM_Get*>(jpl))->entity_type();
    else if( has_result_type( *jpl ) )
      _type = TI_Type::of( *get_result_type( *jpl ) )->type();
    else
      _type = _ast_ctx.VoidTy;
    _problem = has_constructor_problem ();
  }
  string tjp_result_type () const;
  string result_type (const string &name, bool unqual = false) const;
  string result_declaration() const;
  string result_assignment(const string &result) const;
  string action_result_assignment(const string &result) const;
  string result_return() const;

  void has_const_result() { _const_result = true; }
  
  // the name of the result buffer allocated in each wrapper function.
  // must not shadow the functions' arguments
  static const string result_name() { return "__result_buffer"; }
};

#endif // __ClangResultBuffer_h__