8 using namespace awful::idlast
;
10 void EnumRef::resolve( const Class
* pClass_
)
12 // If the name is unqualified, just look it up in the current class
13 if( m_NameComponents
.size() == 1 )
15 *this = pClass_
->getEnums().get( m_NameComponents
[0] );
19 // Look up for the first namespace up from the class' namespace.
20 // Any following namespace name will be looked up only in the current namespace (and will
21 // become the new current namespace)
22 const Namespace
* pCurrentNamespace
= pClass_
->getNamespace();
24 std::vector
< std::string
>::const_iterator it
= m_NameComponents
.begin();
26 // Go through intermediate namespace names, if any
27 if( m_NameComponents
.size() > 2 )
29 pCurrentNamespace
= pCurrentNamespace
->findNamespace( *it
);
32 std::vector
< std::string
>::const_iterator endit
=
33 m_NameComponents
.begin() + m_NameComponents
.size() - 2;
35 for( ; it
!= endit
&& pCurrentNamespace
; ++it
)
37 pCurrentNamespace
= pCurrentNamespace
->getNamespaces().get( *it
);
41 // The penultimate component of the reference (currently pointed to by it)
42 // should be either a class or a struct name.
44 if( pCurrentNamespace
)
46 pClass_
= pCurrentNamespace
->getClasses().get( *it
);
48 // No luck with classes, try the structs
49 pClass_
= pCurrentNamespace
->getStructs().get( *it
);
53 *this = pClass_
->getEnums().get( m_NameComponents
.back() );
58 std::stringstream msg
;
59 msg
<< "undefined enum '";
60 std::vector
< std::string
>::const_iterator it
;
61 for( it
= m_NameComponents
.begin(); it
!= m_NameComponents
.end(); ++it
)
63 if( it
!= m_NameComponents
.begin() )
70 throw ASTError( getFileName(), getLine(), msg
.str() );