3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Fail.
7 Fail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Fail is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "core/idlast/namespace.h"
23 using namespace fail::idlast
;
25 Pointer
< Namespace
> Namespace::addNamespace( Namespace
* pNamespace_
)
27 Pointer
< Namespace
> pNS
= m_Namespaces
.get( pNamespace_
->getName() );
31 if( !m_Namespaces
.add( pNamespace_
) )
34 pNamespace_
->m_pParent
= this;
38 Pointer
< Namespace
> Namespace::findNamespace( std::string Name_
) const
40 Pointer
< Namespace
> pNS
= m_Namespaces
.get( Name_
);
47 return m_pParent
->findNamespace( Name_
);
50 Pointer
< Class
> Namespace::findClass( std::string Name_
, bool bStruct_
) const
52 Pointer
< Class
> pClass
;
55 pClass
= m_Structs
.get( Name_
);
57 pClass
= m_Classes
.get( Name_
);
65 return m_pParent
->findClass( Name_
, bStruct_
);
68 void Namespace::resolveRefs() const
70 std::stack
< const Namespace
* > WorkStack
;
72 WorkStack
.push( this );
73 while( !WorkStack
.empty() )
75 const Namespace
* pCurrentNamespace
= WorkStack
.top();
78 // Push child namespaces on the stack
79 const Dictionary
< Namespace
>& Namespaces
= pCurrentNamespace
->getNamespaces();
80 Dictionary
< Namespace
>::const_iterator nsit
;
81 for( nsit
= Namespaces
.begin(); nsit
!= Namespaces
.end(); ++nsit
)
82 WorkStack
.push( nsit
->second
);
85 const Dictionary
< Class
>& Classes
= pCurrentNamespace
->getClasses();
86 Dictionary
< Class
>::const_iterator clit
;
87 for( clit
= Classes
.begin(); clit
!= Classes
.end(); ++clit
)
88 clit
->second
->resolveRefs( false );
91 const Dictionary
< Class
>& Structs
= pCurrentNamespace
->getStructs();
92 Dictionary
< Class
>::const_iterator stit
;
93 for( stit
= Structs
.begin(); stit
!= Structs
.end(); ++stit
)
94 stit
->second
->resolveRefs( true );
97 // Iterate through classes again to resolve the polymorphism flag
98 WorkStack
.push( this );
99 while( !WorkStack
.empty() )
101 const Namespace
* pCurrentNamespace
= WorkStack
.top();
104 // Push child namespaces on the stack
105 const Dictionary
< Namespace
>& Namespaces
= pCurrentNamespace
->getNamespaces();
106 Dictionary
< Namespace
>::const_iterator nsit
;
107 for( nsit
= Namespaces
.begin(); nsit
!= Namespaces
.end(); ++nsit
)
108 WorkStack
.push( nsit
->second
);
111 const Dictionary
< Class
>& Classes
= pCurrentNamespace
->getClasses();
112 Dictionary
< Class
>::const_iterator clit
;
113 for( clit
= Classes
.begin(); clit
!= Classes
.end(); ++clit
)
114 clit
->second
->resolvePolymorphism();