1
// This file is part of PUMA.
2
// Copyright (C) 1999-2003 The PUMA developer team.
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 "Puma/CScopeInfo.h"
20
#include "Puma/CFunctionInfo.h"
21
#include "Puma/CNamespaceInfo.h"
22
#include "Puma/CClassInfo.h"
23
#include "Puma/CUnionInfo.h"
24
#include "Puma/CFctInstance.h"
25
#include "Puma/CClassInstance.h"
26
#include "Puma/CUnionInstance.h"
27
#include "Puma/CLocalScope.h"
28
#include "Puma/CTemplateInfo.h"
33
CScopeInfo::~CScopeInfo () {
34
// for (unsigned i = 0; i < Children (); i++) {
35
// CScopeInfo *s = Child (i);
36
// if (s->TemplateInfo ())
37
// s->TemplateInfo ()->removeLinks ();
38
// s->Parent ((CScopeInfo*)0);
39
// if (! _DeleteMembersOnly) {
40
// if (s->LocalScope ()) delete s->LocalScope ();
41
// else if (s->FctInstance ()) delete s->FctInstance ();
42
// else if (s->ClassInstance ()) delete s->ClassInstance ();
43
// else if (s->UnionInstance ()) delete s->UnionInstance ();
44
// else if (s->FunctionInfo ()) delete s->FunctionInfo ();
45
// else if (s->ClassInfo ()) delete s->ClassInfo ();
46
// else if (s->UnionInfo ()) delete s->UnionInfo ();
47
// else if (s->TemplateInfo ()) delete s->TemplateInfo ();
48
// else if (s->NamespaceInfo () && ! s->FileInfo ())
49
// delete s->NamespaceInfo ();
52
// if (Parent () && Parent () != this)
53
// Parent ()->removeChild (this);
56
bool CScopeInfo::isMethod () const {
57
return FunctionInfo () && FunctionInfo ()->Record ();
60
bool CScopeInfo::isClassTemplate () const {
61
return TemplateInfo () && (TemplateInfo ()->isClass () ||
62
TemplateInfo ()->isAttribute ());
65
bool CScopeInfo::isFctTemplate () const {
66
return TemplateInfo () && TemplateInfo ()->isFunction ();
69
void CScopeInfo::Parent (const CScopeInfo *info) {
70
if (_Parent != info) {
72
((CScopeInfo*)info)->addChild (this);
74
_Parent = (CScopeInfo*)info;
78
void CScopeInfo::addChild (CScopeInfo *info) {
79
// for (unsigned i = Children (); i > 0; i--)
80
// if (Child (i-1) == info)
82
_Children.append (info);
85
void CScopeInfo::removeChild (const CScopeInfo *info) {
86
for (unsigned i = Children (); i > 0; i--)
87
if (Child (i-1) == info) {
88
_Children.remove (i-1);
93
CLocalScope *CScopeInfo::newLocalScope () {
94
CLocalScope *info = new CLocalScope;
95
info->ClassDB (ClassDB ());
100
CNamespaceInfo *CScopeInfo::newNamespace () {
101
CNamespaceInfo *info = new CNamespaceInfo;
103
info->ClassDB (ClassDB ());
105
Structure ()->addNamespace (info);
109
CTemplateInfo *CScopeInfo::newTemplate () {
110
CTemplateInfo *info = new CTemplateInfo;
111
info->ClassDB (ClassDB ());
116
CFunctionInfo *CScopeInfo::newFunction (bool inst) {
119
info = new CFctInstance;
121
info = new CFunctionInfo;
123
info->ClassDB (ClassDB ());
125
Structure ()->addFunction (info);
129
CClassInfo *CScopeInfo::newClass (bool inst) {
132
info = new CClassInstance;
134
info = new CClassInfo;
136
info->ClassDB (ClassDB ());
138
Structure ()->addType (info);
142
CUnionInfo *CScopeInfo::newUnion (bool inst) {
145
info = new CUnionInstance;
147
info = new CUnionInfo;
149
info->ClassDB (ClassDB ());
151
Structure ()->addType (info);
155
void CScopeInfo::deleteLocalScope (const CLocalScope *info) {
156
for (unsigned i = Children (); i > 0; i--)
157
if (Child (i-1) == (CScopeInfo*)info) {
158
delete (CLocalScope*)_Children[i-1];
159
_Children.remove (i-1);
164
void CScopeInfo::deleteNamespace (const CNamespaceInfo *info) {
165
for (unsigned i = Children (); i > 0; i--)
166
if (Child (i-1) == (CScopeInfo*)info) {
167
delete (CNamespaceInfo*)_Children[i-1];
168
_Children.remove (i-1);
173
void CScopeInfo::deleteTemplate (const CTemplateInfo *info) {
174
for (unsigned i = Children (); i > 0; i--)
175
if (Child (i-1) == (CScopeInfo*)info) {
176
delete (CTemplateInfo*)_Children[i-1];
177
_Children.remove (i-1);
182
void CScopeInfo::deleteFunction (const CFunctionInfo *info) {
183
for (unsigned i = Children (); i > 0; i--)
184
if (Child (i-1) == (CScopeInfo*)info) {
185
delete (CFunctionInfo*)_Children[i-1];
186
_Children.remove (i-1);
191
void CScopeInfo::deleteClass (const CClassInfo *info) {
192
for (unsigned i = Children (); i > 0; i--)
193
if (Child (i-1) == (CScopeInfo*)info) {
194
delete (CClassInfo*)_Children[i-1];
195
_Children.remove (i-1);
200
void CScopeInfo::deleteUnion (const CUnionInfo *info) {
201
for (unsigned i = Children (); i > 0; i--)
202
if (Child (i-1) == (CScopeInfo*)info) {
203
delete (CUnionInfo*)_Children[i-1];
204
_Children.remove (i-1);