~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to AspectC++/WeaverBase.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-12-23 10:49:40 UTC
  • Revision ID: james.westby@ubuntu.com-20051223104940-ig4klhoi991zs7km
Tags: upstream-0.99+1.0pre2
ImportĀ upstreamĀ versionĀ 0.99+1.0pre2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of the AspectC++ compiler 'ac++'.
 
2
// Copyright (C) 1999-2003  The 'ac++' developers (see aspectc.org)
 
3
//                                                                
 
4
// This program is free software;  you can redistribute it and/or 
 
5
// modify it under the terms of the GNU General Public License as 
 
6
// published by the Free Software Foundation; either version 2 of 
 
7
// the License, or (at your option) any later version.            
 
8
//                                                                
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 
12
// GNU General Public License for more details.                   
 
13
//                                                                
 
14
// You should have received a copy of the GNU General Public      
 
15
// License along with this program; if not, write to the Free     
 
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __WeaverBase_h__
 
20
#define __WeaverBase_h__
 
21
 
 
22
// This class encapsulates all code manipulation or analysis functions
 
23
// that are needed by AspectC++, but which do not depend on AspectC++
 
24
// specific classes. They can be seen as a general purpose PUMA extension.
 
25
 
 
26
#include <iostream>
 
27
#include <set>
 
28
using namespace std;
 
29
 
 
30
#include "Puma/ManipCommander.h"
 
31
#include "Puma/CProtection.h"
 
32
using namespace Puma;
 
33
 
 
34
#include "ACUnit.h"
 
35
 
 
36
namespace Puma {
 
37
  class ErrorSink;
 
38
  class CObjectInfo;
 
39
  class CFunctionInfo;
 
40
  class CArgumentInfo;
 
41
  class CClassInfo;
 
42
  class CTree;
 
43
} // namespace Puma
 
44
 
 
45
class WeaverBase;
 
46
class LineDirectiveMgr;
 
47
 
 
48
class WeavePos {
 
49
public:
 
50
  enum Pos { WP_BEFORE, WP_AFTER };
 
51
  int operator < (const WeavePos& key) const {
 
52
    return _token == key._token ?
 
53
      (_pos < key._pos) : (_token < key._token);
 
54
  }
 
55
private:
 
56
  friend class WeaverBase;
 
57
  WeavePos (Token *t, Pos p) : _token (t), _pos (p) {}
 
58
  Token *_token;
 
59
  Pos _pos;
 
60
};
 
61
 
 
62
class WeaverBase {
 
63
 
 
64
  // These data structures are needed to store and find weaving positions that
 
65
  // were already used. Some of them are stored separately, because they are
 
66
  // relevant for the insertion of #line directives
 
67
  typedef set<WeavePos> WPSet;
 
68
  WPSet _positions;
 
69
  typedef set<WeavePos*> WPPtrSet;
 
70
  WPPtrSet _line_done;
 
71
  WPPtrSet _line_todo;
 
72
  ManipCommander _commander;
 
73
  
 
74
protected:
 
75
  ErrorSink &_err;
 
76
  LineDirectiveMgr &_line_mgr;
 
77
 
 
78
  // not a very good function
 
79
  void print_tree (ostream &out, CTree *node);
 
80
 
 
81
  // checks whether a function needs a 'this'-pointer
 
82
  bool needs_this (CFunctionInfo *func);
 
83
  
 
84
  // scope functions
 
85
  CClassInfo *cscope (CObjectInfo *obj);
 
86
  CScopeInfo *nscope (CObjectInfo *obj);
 
87
  
 
88
  void rename_args (CFunctionInfo *func, const char * new_name);
 
89
  void rename (CArgumentInfo *arg, const string &new_name, int app = -1);
 
90
  void rename_simple_name (CObjectInfo *renamed_obj,
 
91
                           const char *new_name, int app,
 
92
                           CTree *node);
 
93
  CT_SimpleName *is_name (CTree *node);
 
94
  CT_FctDeclarator *fct_declarator (CT_Declarator *declarator);
 
95
  CT_SimpleName *name (CT_Declarator *&declarator);
 
96
 
 
97
  // return LinkageSpec node for extern "C" <decl> like declarations
 
98
  CTree *linkage_adjust (CT_Decl *decl);
 
99
  
 
100
public:
 
101
  WeaverBase (ErrorSink &e, LineDirectiveMgr &ldm) :
 
102
    _err (e), _line_mgr (ldm) {}
 
103
 
 
104
  // helper functions (could be regarded as Puma extensions)
 
105
  
 
106
  // returns "\nprivate:\n", ...
 
107
  static string protection_string (CProtection::Type prot);
 
108
 
 
109
  // code manipulation layer:
 
110
  
 
111
  // get a weaving position
 
112
  const WeavePos &weave_pos (Token *t, WeavePos::Pos p);
 
113
  
 
114
  // check/ignore manipulations for unbalanced preprocessor directives
 
115
  void ignore_unbalanced () { _commander.ignore_mask (MIM_UNBALANCED); }
 
116
  void check_unbalanced () { _commander.ignore_mask (MIM_NONE); }
 
117
   
 
118
  // insert the contents of a generated unit at a given position (with move)
 
119
  void paste (const WeavePos &pos, Unit *unit);
 
120
 
 
121
  // insert a generated string a given position
 
122
  void paste (const WeavePos &pos, const string &str);
 
123
  
 
124
  // replace the text between two positions with some new text
 
125
  void replace (const WeavePos &from, const WeavePos &to, const string &str);
 
126
  
 
127
  // replace the text of a syntax tree with some new text
 
128
  void replace (CTree *node, const string &str);
 
129
 
 
130
  // copy the text between two position to another location
 
131
  void copy (const WeavePos &from, const WeavePos &to, const WeavePos &dest);
 
132
  
 
133
  // copy the text of a syntax tree to another location
 
134
  void copy (CTree *node, const WeavePos &dest);
 
135
  
 
136
  // kill the text between two positions
 
137
  void kill (const WeavePos &from, const WeavePos &to);
 
138
  
 
139
  // kill the text of a syntax tree
 
140
  void kill (CTree *node);
 
141
 
 
142
  // commit a transformation transaction  
 
143
  bool commit ();
 
144
  
 
145
  // check if there is a problem
 
146
  bool macro_problem (const WeavePos &pos);
 
147
  
 
148
};
 
149
 
 
150
#endif // __WeaverBase_h__