awic compiles again.
[fail.git] / src / core / idlast / namespace.cpp
blobd301ca289fdd5dc2e6b361983942f93876adcd04
1 #include <stack>
2 #include "core/idlast/namespace.h"
4 using namespace awful;
5 using namespace awful::idlast;
7 Pointer< Namespace > Namespace::addNamespace( Namespace* pNamespace_ )
9 Pointer< Namespace > pNS = m_Namespaces.get( pNamespace_->getName() );
10 if( pNS )
11 return pNS;
13 if( !m_Namespaces.add( pNamespace_ ) )
14 return 0;
16 pNamespace_->m_pParent = this;
17 return pNamespace_;
20 Pointer< Namespace > Namespace::findNamespace( std::string Name_ ) const
22 Pointer< Namespace > pNS = m_Namespaces.get( Name_ );
23 if( pNS )
24 return pNS;
26 if( !m_pParent )
27 return NULL;
29 return m_pParent->findNamespace( Name_ );
32 Pointer< Class > Namespace::findClass( std::string Name_, bool bStruct_ ) const
34 Pointer< Class > pClass;
36 if( bStruct_ )
37 pClass = m_Structs.get( Name_ );
38 else
39 pClass = m_Classes.get( Name_ );
41 if( pClass )
42 return pClass;
44 if( !m_pParent )
45 return NULL;
47 return m_pParent->findClass( Name_, bStruct_ );
50 void Namespace::resolveRefs() const
52 std::stack< const Namespace* > WorkStack;
54 WorkStack.push( this );
55 while( !WorkStack.empty() )
57 const Namespace* pCurrentNamespace = WorkStack.top();
58 WorkStack.pop();
60 // Push child namespaces on the stack
61 const Dictionary< Namespace >& Namespaces = pCurrentNamespace->getNamespaces();
62 Dictionary< Namespace >::const_iterator nsit;
63 for( nsit = Namespaces.begin(); nsit != Namespaces.end(); ++nsit )
64 WorkStack.push( nsit->second );
66 // Process classes
67 const Dictionary< Class >& Classes = pCurrentNamespace->getClasses();
68 Dictionary< Class >::const_iterator clit;
69 for( clit = Classes.begin(); clit != Classes.end(); ++clit )
70 clit->second->resolveRefs( false );
72 // Process structs
73 const Dictionary< Class >& Structs = pCurrentNamespace->getStructs();
74 Dictionary< Class >::const_iterator stit;
75 for( stit = Structs.begin(); stit != Structs.end(); ++stit )
76 stit->second->resolveRefs( true );
79 // Iterate through classes again to resolve the polymorphism flag
80 WorkStack.push( this );
81 while( !WorkStack.empty() )
83 const Namespace* pCurrentNamespace = WorkStack.top();
84 WorkStack.pop();
86 // Push child namespaces on the stack
87 const Dictionary< Namespace >& Namespaces = pCurrentNamespace->getNamespaces();
88 Dictionary< Namespace >::const_iterator nsit;
89 for( nsit = Namespaces.begin(); nsit != Namespaces.end(); ++nsit )
90 WorkStack.push( nsit->second );
92 // Process classes
93 const Dictionary< Class >& Classes = pCurrentNamespace->getClasses();
94 Dictionary< Class >::const_iterator clit;
95 for( clit = Classes.begin(); clit != Classes.end(); ++clit )
96 clit->second->resolvePolymorphism();