[Qt-creator] Multiple Symbols in Scope for same Namespace

Bertjan Broeksema b.broeksema at home.nl
Tue Mar 10 20:43:03 CET 2009


Hi List (Roberto especially =:),

I'm working on a custom application using the parser framework of Qt Creator 
and noticed some strange behavior.

My application creates translation units for a file and all files which are 
somewhere in the include tree of that file (given that the files can be found 
in the configured environment of course). After that I create a scope object 
that adds the symbols of all these translation units to one Scope like this:

void Document::check(Scope *globals)
{
  foreach(Include inc, _includes)
    inc.document()->check(globals);

  if (!_translationUnit->ast())
    parse();

  Semantic semantic(_control);
  if (TranslationUnitAST *ast = _translationUnit->ast()->asTranslationUnit())
  {
    for (DeclarationAST *decl = ast->declarations; decl; decl = decl->next)
    {
      semantic.check(decl, globals);
    }
  }
}

I wrote a simple Scope dumper to be able to have a quick look at the result 
and noticed a strange thing. It seems that there is no check to see if a 
namespace already is defined in the current scope and it is just added without 
additional checks to the current scope. I think this is where it happens:

CheckDeclaration.cpp:308

bool CheckDeclaration::visit(NamespaceAST *ast)
{
    Identifier *id = identifier(ast->identifier_token);
    Name *namespaceName = control()->nameId(id);
    Namespace *ns = control()->newNamespace(ast->firstToken(), namespaceName);
    ast->symbol = ns;
    _scope->enterSymbol(ns);
    semantic()->check(ast->linkage_body, ns->members()); // ### we'll do the 
merge later.

    if (ast->next && ast->next->asEmptyDeclaration()) {
        translationUnit()->warning(ast->next->firstToken(),
                                   "unnecessary semicolon after namespace");
    }

    return false;
}

What I would expect is that the namespace is not just added to the scope but 
that a lookup would be done to see if it is already defined and use that 
object in stead of adding a new one. Is this a known issue or is are there 
plans to change this behavior?

Thanks in advance,

Bertjan Broeksema



More information about the Qt-creator-old mailing list