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
#include "IntroductionInfo.h"
21
#include "Puma/ACTree.h"
22
#include "Puma/ACIntroductionInfo.h"
23
#include "Puma/CFunctionInfo.h"
24
#include "Puma/CArgumentInfo.h"
25
#include "Puma/CClassDatabase.h"
27
IntroductionInfo::IntroductionInfo (AspectInfo *ai, ACIntroductionInfo *acii) :
28
_aspect (ai), _acii(acii), _tree (acii->def_node ()), _prot (acii->prot ()) {
31
if (_tree->Decl ()->NodeName () == CT_Intro::NodeId ()) {
32
// Copy all tokens of the intro pattern => intro source code can be removed
33
// The pattern contains no whitespace or any kind of formatting!
34
// Token positions are identical with the entry number.
35
CT_Intro *intro = (CT_Intro*)_tree->Decl ();
36
// set the name for #line directives
37
_pattern.name (((Unit*)intro->token ()->belonging_to ())->name ());
38
for (int e = 0; e < intro->Entries (); e++) {
39
Token *tok = intro->Entry (e)->token ();
40
_pattern.append (*tok->duplicate ());
44
else if (_tree->Decl ()->NodeName () == CT_SliceRef::NodeId ()) {
45
_type = INTRO_SLICE_REF;
46
CObjectInfo *obj = ((CT_SliceRef*)_tree->Decl ())->name ()->Object ();
47
ACSliceInfo *acsi = obj->ClassDB ()->SliceInfo (obj)->definition ();
49
if (acsi->type () == ACSliceInfo::SL_STRUCT)
50
_prot = CProtection::PROT_PUBLIC;
52
_prot = CProtection::PROT_PRIVATE;
53
_objs.append (acsi->object ());
54
CT_ClassSliceDecl *csd = acsi->def_node ();
55
if (csd->members ()) {
56
for (int m = 0; m < csd->members ()->Entries (); m++) {
57
// set the name for #line directives
58
_pattern.name (((Unit*)csd->token ()->belonging_to ())->name ());
59
CT_Intro *intro = (CT_Intro*)csd->members ()->Entry (m);
60
for (int e = 0; e < intro->Entries (); e++) {
61
Token *tok = intro->Entry (e)->token ();
62
_pattern.append (*tok->duplicate ());
68
_objs.append (obj); // append the declaration, error message later
70
else if (_tree->Decl ()->NodeName () == CT_ClassSliceDecl::NodeId ()) {
71
_type = INTRO_SLICE_DECL;
72
CObjectInfo *obj = ((CT_ClassSliceDecl*)_tree->Decl ())->Object ();
73
ACSliceInfo *acsi = obj->ClassDB ()->SliceInfo (obj)->definition ();
75
if (acsi->type () == ACSliceInfo::SL_STRUCT)
76
_prot = CProtection::PROT_PUBLIC;
78
_prot = CProtection::PROT_PRIVATE;
79
_objs.append (acsi->object ());
80
CT_ClassSliceDecl *csd = acsi->def_node ();
81
if (csd->members ()) {
82
// set the name for #line directives
83
_pattern.name (((Unit*)csd->token ()->belonging_to ())->name ());
84
for (int m = 0; m < csd->members ()->Entries (); m++) {
85
CT_Intro *intro = (CT_Intro*)csd->members ()->Entry (m);
86
for (int e = 0; e < intro->Entries (); e++) {
87
Token *tok = intro->Entry (e)->token ();
88
_pattern.append (*tok->duplicate ());
94
else if (_tree->Decl ()->NodeName () == CT_ObjDecl::NodeId ()) {
95
CT_DeclaratorList *dl = ((CT_ObjDecl*)_tree->Decl ())->Declarators();
96
if (dl->Entries () > 0) {
97
CObjectInfo *obj = ((CT_InitDeclarator*)dl->Entry (0))->Object ();
99
// check for baseclass introductions
100
if (obj->FunctionInfo () && strcmp (obj->Name (), "baseclass") == 0) {
101
_type = INTRO_BASECLASS;
104
else if (obj->FunctionInfo () &&
105
strcmp (obj->Name (), "inherited") == 0) {
106
_type = INTRO_INHERITED;
114
void IntroductionInfo::print (ostream& os) const {
116
case INTRO_BASECLASS:
118
object(0)->FunctionInfo ()->Argument (0u)->TypeInfo ()->print (os);
120
case INTRO_INHERITED:
123
case INTRO_SLICE_REF:
124
os << "slice ref " << object (0)->QualName ();
126
case INTRO_SLICE_DECL:
127
os << "slice decl " << object (0)->QualName ();
130
CT_Intro *intro = (CT_Intro*)_tree->Decl ();
131
bool is_fct = (intro->Entry (intro->Entries () - 1)->
132
token ()->type () == TOK_CLOSE_CURLY);
133
for (int i = 0; i < intro->Entries (); i++) {
134
Token *tok = intro->Entry (i)->token ();
135
if (is_fct && tok->type () == TOK_OPEN_CURLY) {
139
os << tok->text () << " ";