~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to AspectC++/IntroductionInfo.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

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
 
#include "IntroductionInfo.h"
20
 
 
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"
26
 
 
27
 
IntroductionInfo::IntroductionInfo (AspectInfo *ai, ACIntroductionInfo *acii) :
28
 
  _aspect (ai), _acii(acii), _tree (acii->def_node ()), _prot (acii->prot ()) {
29
 
 
30
 
  _type = INTRO_ERROR;
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 ());
41
 
    }
42
 
    _type = INTRO_OTHER;
43
 
  }
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 ();
48
 
    if (acsi) {
49
 
      if (acsi->type () == ACSliceInfo::SL_STRUCT)
50
 
        _prot = CProtection::PROT_PUBLIC;
51
 
      else
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 ());
63
 
          }
64
 
        }
65
 
      }
66
 
    }
67
 
    else
68
 
      _objs.append (obj); // append the declaration, error message later
69
 
  }
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 ();
74
 
    if (acsi) {
75
 
      if (acsi->type () == ACSliceInfo::SL_STRUCT)
76
 
        _prot = CProtection::PROT_PUBLIC;
77
 
      else
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 ());
89
 
          }
90
 
        }
91
 
      }
92
 
    }
93
 
  }
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 ();
98
 
      
99
 
      // check for baseclass introductions
100
 
      if (obj->FunctionInfo () && strcmp (obj->Name (), "baseclass") == 0) {
101
 
        _type = INTRO_BASECLASS;
102
 
        _objs.append (obj);
103
 
      }
104
 
      else if (obj->FunctionInfo () &&
105
 
                     strcmp (obj->Name (), "inherited") == 0) {
106
 
        _type = INTRO_INHERITED;
107
 
        _objs.append (obj);
108
 
      }
109
 
    }
110
 
  }
111
 
}
112
 
 
113
 
 
114
 
void IntroductionInfo::print (ostream& os) const {
115
 
  switch (_type) {
116
 
  case INTRO_BASECLASS:
117
 
    os << "baseclass ";
118
 
    object(0)->FunctionInfo ()->Argument (0u)->TypeInfo ()->print (os);
119
 
    break;
120
 
  case INTRO_INHERITED:
121
 
    os << "inherited";
122
 
    break;
123
 
  case INTRO_SLICE_REF:
124
 
    os << "slice ref " << object (0)->QualName ();
125
 
    break;
126
 
  case INTRO_SLICE_DECL:
127
 
    os << "slice decl " << object (0)->QualName ();
128
 
    break;
129
 
  case INTRO_OTHER: {
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) {
136
 
        os << "{ ... }";
137
 
        break;
138
 
      }
139
 
      os << tok->text () << " ";
140
 
    }
141
 
  }
142
 
    break;
143
 
  default:
144
 
    os << "unknown";
145
 
  }
146
 
}