Reshuffling directories to separate include and sources, part one.
[fail.git] / include / core / idlast / enumref.cpp
blobb260638440c98eb3bbfb45f567941818a585041f
1 #include <sstream>
2 #include "ast.h"
3 #include "enumref.h"
4 #include "namespace.h"
5 #include "class.h"
7 using namespace awful;
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] );
17 else
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();
23 pClass_ = 0;
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 );
30 ++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.
43 // Look for it.
44 if( pCurrentNamespace )
46 pClass_ = pCurrentNamespace->getClasses().get( *it );
47 if( !pClass_ )
48 // No luck with classes, try the structs
49 pClass_ = pCurrentNamespace->getStructs().get( *it );
52 if( pClass_ )
53 *this = pClass_->getEnums().get( m_NameComponents.back() );
56 if( *this == NULL )
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() )
64 msg << "::";
65 msg << *it;
68 msg << "'.";
70 throw ASTError( getFileName(), getLine(), msg.str() );