1
// This file is part of the AspectC++ compiler 'ac++'.
2
// Copyright (C) 1999-2003 The 'ac++' developers (see aspectc.org)
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.
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.
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,
19
#ifndef __WeaverBase_h__
20
#define __WeaverBase_h__
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.
30
#include "Puma/ManipCommander.h"
31
#include "Puma/CProtection.h"
46
class LineDirectiveMgr;
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);
56
friend class WeaverBase;
57
WeavePos (Token *t, Pos p) : _token (t), _pos (p) {}
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;
69
typedef set<WeavePos*> WPPtrSet;
72
ManipCommander _commander;
76
LineDirectiveMgr &_line_mgr;
78
// not a very good function
79
void print_tree (ostream &out, CTree *node);
81
// checks whether a function needs a 'this'-pointer
82
bool needs_this (CFunctionInfo *func);
85
CClassInfo *cscope (CObjectInfo *obj);
86
CScopeInfo *nscope (CObjectInfo *obj);
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,
93
CT_SimpleName *is_name (CTree *node);
94
CT_FctDeclarator *fct_declarator (CT_Declarator *declarator);
95
CT_SimpleName *name (CT_Declarator *&declarator);
97
// return LinkageSpec node for extern "C" <decl> like declarations
98
CTree *linkage_adjust (CT_Decl *decl);
101
WeaverBase (ErrorSink &e, LineDirectiveMgr &ldm) :
102
_err (e), _line_mgr (ldm) {}
104
// helper functions (could be regarded as Puma extensions)
106
// returns "\nprivate:\n", ...
107
static string protection_string (CProtection::Type prot);
109
// code manipulation layer:
111
// get a weaving position
112
const WeavePos &weave_pos (Token *t, WeavePos::Pos p);
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); }
118
// insert the contents of a generated unit at a given position (with move)
119
void paste (const WeavePos &pos, Unit *unit);
121
// insert a generated string a given position
122
void paste (const WeavePos &pos, const string &str);
124
// replace the text between two positions with some new text
125
void replace (const WeavePos &from, const WeavePos &to, const string &str);
127
// replace the text of a syntax tree with some new text
128
void replace (CTree *node, const string &str);
130
// copy the text between two position to another location
131
void copy (const WeavePos &from, const WeavePos &to, const WeavePos &dest);
133
// copy the text of a syntax tree to another location
134
void copy (CTree *node, const WeavePos &dest);
136
// kill the text between two positions
137
void kill (const WeavePos &from, const WeavePos &to);
139
// kill the text of a syntax tree
140
void kill (CTree *node);
142
// commit a transformation transaction
145
// check if there is a problem
146
bool macro_problem (const WeavePos &pos);
150
#endif // __WeaverBase_h__