Distributed Namespace -- changes in ClassParser.cc
Thomas Regner
tomte at subdimension.com
Thu Feb 10 15:40:38 GMT 2000
Hi,
I tried to change the ClassParser, so that it recognizes namespaces distributed
over several files.
Since I am a stupid Idiot, I didn´t saved an unchanged copy of ClassParser.cc,
so I post the whole method parseNamespace() instead of a patch file ( there are only a few changes).
These changes are made against the CVS-Version,
I got it via cvsup February, 10th 2000, ~16:12 MET
It works now, if you have several files in which the same namespace is used to organize
classes in one scope.
If you define the ClassMethods now with the fullscope,
i.e.
declaration
namespace foo {
class bar {
bar();
~bar();
void method1();
};
} // namespace foo
definition:
foo::bar::bar(){ //do something;}
foo::bar::~bar(){//do something;}
void foo::bar::method1(){//do something;}
KDevelop recognizes this, and you may navigate through your classes in the namespaces folder ;), but alas,
not in the classes folder anymore :(
But to me it´s an improvement, cause before my changes, only the first parsed class ( the only class in the first parsed file) was visible and browsable.
This was a blind flight, I did NOT understand how this parsing code is organized, so this change MAY BREAK things,
but it worked so far for me.
by
Tom
--
/--------------
| Thomas Regner
| Kaiserstr. 5
| 26122 Oldenburg
| Tel.: +49 441 7775005
| E.: tomte at subdimension.com
|______________________________/
new Method:
void CClassParser::parseNamespace( CParsedScopeContainer * scope )
{
REQUIRE( "Valid scope", scope != NULL );
// begin changed block
bool newScope = false;
getNextLexem();
CParsedScopeContainer *ns;
if( scope->hasScope(getText()))
ns = scope->getScopeByName( getText());
else{
ns = new CParsedScopeContainer();
newScope = true;
}
//end changed block
// Set some info about the namespace
ns->setDeclaredOnLine( declStart );
ns->setDeclaredInFile( currentFile );
ns->setDefinedInFile( currentFile );
if( commentInRange( ns ) )
ns->setComment( comment );
// cerr << "parsing namespace" << endl;
// cerr << "lexem = " << lexem << ":" << static_cast<char>(lexem) << endl;
if( lexem == '{' )
{
// anonymous namespace
// assume 1-1 correspondence between file name and translation unit
QString short_file_name(currentFile);
short_file_name.replace( QRegExp(".*/"), "");
QString trans_unit_ident("(");
trans_unit_ident += short_file_name;
trans_unit_ident += ")";
ns->setName( trans_unit_ident );
}
else
{
ns->setName( getText() );
// check that it is well-formed, moving to beginning of block
getNextLexem();
while(lexem != 0 && lexem != '{') {
debug("Bad namespace identifier.");
getNextLexem();
}
}
// skip over '{'
getNextLexem();
while(lexem != 0 && lexem != '}')
{
declStart = getLineno();
if( isGenericLexem() )
parseGenericLexem( ns );
else
parseTopLevelLexem( ns );
getNextLexem();
}
ASSERT( lexem == '}' );
// If the parsing went ok, we add the scope.
if( lexem != 0 )
{
ns->setDeclarationEndsOnLine( getLineno() );
//begin changed block
if( newScope)
scope->addScope( ns );
//end changed block
// Always add namespaces to the global container.
if( scope != &store.globalContainer )
store.addScope( ns );
}
}
More information about the KDevelop
mailing list