[orbitcpp-list] Another bug with #included idl file
Status: Beta
Brought to you by:
philipd
From: Kuba <kp...@po...> - 2001-05-22 08:52:19
|
Hi, I have found another problem, when you're #including one idl from another. Situation is as follows. We have two idl files: file1.idl: module A { interface Empty { }; }; file2.idl: #include <file1.idl> module A { struct SomeStruct { string SomeString; }; interface NotEmpty { void SomeFunction (int SomeStruct inParam); }; }; Trying to compile file2.idl causes orbit-idl c++ compiler to complain, that SomeStruct is unknown. The reason for that is fact, that in IDL_Tree analyzed by compiler there are two subtrees for module A. When searching for SomeStruct function lookupLocal from language.cc looks into the first module A subtree only, so it doesn't find SomeStruct declared in the second subtree. Here is a patch (sorry for some garbage inside, my editor cuts white spaces at the end of the lines - the only changed functions are lookupLocal () and getScope): ---------------------------------------------------------- diff -u compiler/language.cc compiler.new/language.cc --- compiler/language.cc Fri Apr 6 11:41:42 2001 +++ compiler.new/language.cc Sun Apr 22 00:05:24 2001 @@ -95,7 +95,7 @@ switch (IDL_UNARYOP(constant).op) { case IDL_UNARYOP_PLUS: op = '+'; break; case IDL_UNARYOP_MINUS: op = '-'; break; - case IDL_UNARYOP_COMPLEMENT: op = '~'; + case IDL_UNARYOP_COMPLEMENT: op = '~'; } return string("(") + op + idlTranslateConstant(IDL_UNARYOP(constant).operand,scope) + ")"; } @@ -111,7 +111,7 @@ case IDL_BINOP_SUB: op = "-"; break; case IDL_BINOP_MULT: op = "*"; break; case IDL_BINOP_DIV: op = "/"; break; - case IDL_BINOP_MOD: op = "%"; + case IDL_BINOP_MOD: op = "%"; } return '(' + idlTranslateConstant(IDL_BINOP(constant).left,scope) + op + idlTranslateConstant(IDL_BINOP(constant).right,scope) + ')'; @@ -135,7 +135,7 @@ IDLElement *slot = parentscope->getItem(id); // I've removed the following check, since forward dcls mean that - // there can be duplicate identifiers -PD + // there can be duplicate identifiers -PD // okay, libIDL should catch all real evil cases for us anyway. -andy //if (slot) throw IDLExDuplicateIdentifier(node,*parentscope,m_identifier); @@ -152,7 +152,7 @@ -string +string IDLElement::getQualifiedIDLIdentifier(IDLScope const *up_to, IDLScope const *assumed_base = NULL) const { if (up_to == this) return ""; @@ -170,7 +170,7 @@ -string +string IDLElement::getQualifiedCIdentifier(IDLScope const *up_to, IDLScope const *assumed_base = NULL) const { if (up_to == this) return ""; @@ -190,7 +190,7 @@ -string +string IDLElement::getQualifiedCPPIdentifier(IDLScope const *up_to, IDLScope const *assumed_base = NULL) const { if (up_to == this) return ""; @@ -275,20 +275,26 @@ string::size_type first = 0; string::size_type nextscopeq = id.find("::",first); - while (nextscopeq != string::npos) { - IDLScope *nextscope = scope->getScope(id.substr(first,nextscopeq-first)); - if (!nextscope) return NULL; - scope = nextscope; - first = nextscopeq + 2; - nextscopeq = id.find("::",first); + if (nextscopeq == string::npos) { + return scope->getItem(id.substr(first)); + } + else { + int spos = 0; + IDLScope *nextscope = NULL; + while ((nextscope = scope->getScope(id.substr(first,nextscopeq-first),spos)) != NULL) { + spos++; + IDLElement* element = nextscope->lookupLocal(id.substr(nextscopeq+2,id.length()-nextscopeq-2)); + if (element != NULL) return element; + } } - return scope->getItem(id.substr(first)); + return NULL; } + IDLElement * IDLScope::getItem(IDL_tree node) const { ItemList::const_iterator first = m_items.begin(),last = m_items.end(); @@ -317,14 +323,23 @@ -IDLScope * -IDLScope::getScope(string const &id) const { - ScopeList::const_iterator first = m_scopes.begin(),last = m_scopes.end(); +IDLScope* +IDLScope::getScope (string const &id, int &spos) const { + ScopeList::const_iterator first = m_scopes.begin(), last = m_scopes.end (); + string IDLIdentifier; + int pos_counter = 0; while (first != last) { - if ((*first)->getIDLIdentifier() == id) return *first; + IDLIdentifier = (*first)->getIDLIdentifier(); + if ((*first)->getIDLIdentifier() == id && pos_counter >= spos) { + spos = pos_counter; + return *first; + } + first++; + pos_counter++; } + return NULL; } @@ -358,7 +373,7 @@ -void +void IDLScope::getCPPNamespaceDecl(string &ns_begin,string &ns_end, string const &prefix) { IDLScope const *scope = this; @@ -396,9 +411,9 @@ list = IDL_LIST(list).next; } } - + // IDLOperation --------------------------------------------------------------- -string +string IDLOperation::getCPPOpParameterList() { string result; vector<ParameterInfo>::const_iterator @@ -418,7 +433,7 @@ -string +string IDLOperation::getCOpParameterList() { string result; vector<ParameterInfo>::const_iterator diff -u compiler/language.hh compiler.new/language.hh --- compiler/language.hh Mon Jan 22 08:44:05 2001 +++ compiler.new/language.hh Sun Apr 22 00:04:43 2001 @@ -129,7 +129,7 @@ IDLElement *getItem(IDL_tree node) const; IDLElement *getItem(string const &id) const; - IDLScope *getScope(string const &id) const; + IDLScope *getScope (string const &id, int &spos) const; IDLScope const *getRootScope() const { if (getParentScope()) return Super::getRootScope(); else return this; @@ -209,7 +209,7 @@ typedef std::list<std::string> LabelList; typedef LabelList::const_iterator const_iterator; private: - IDLMember *m_member; + IDLMember *m_member; LabelList m_labels; bool m_isDefault; public: @@ -220,7 +220,7 @@ ~IDLCaseStmt() { delete m_member; } - + IDLMember const &getMember() { return *m_member; } @@ -271,7 +271,7 @@ IDLType *m_type; bool m_readOnly; - + public: IDLAttribute(string const &id,IDL_tree node,IDLType *type,IDLScope *parentscope = NULL) -------------------------------------------------------- -- 26 maja - Dzien Matki. Wygraj kwiaty dla swojej Mamy! Do rozdania 75 bukietow z dostawa i zyczeniami. [ http://zakupy.onet.pl/prezenty.asp?k=7 ] |