[cfe-dev] Repeated NNS in Elaborated types?

Enea Zaffanella zaffanella at cs.unipr.it
Wed Mar 2 08:44:47 PST 2011


Doug is doing a great job in creating and propagating nested name
specifier location info in the AST. Here is one of the few places where
we are still obtaining something not completely accurate:

==================
namespace ns {
  template <typename T> struct S { typedef int FOO; };
}

ns::S<int> x1;            // ns:: repeated
struct ns::S<double> x2;  // ns:: repeated
ns::S<double>::FOO x3;    // OK.
==================

The types for the first two VarDecl nodes (for x1 and x2) have the structure

  ETLoc -> TSTLoc -> QTN

that is

  ElaboratedTypeLoc
    -> TemplateSpecializationTypeLoc
         -> QualifiedTemplateName

We have an NNSLoc (for "ns::") inside the ETLoc nodes;
we also have an NNS (again for "ns::") inside the QTN nodes.
As a result, the AST dump contains a repetition of the qualification
ns:: for both x1 and x2.

The simple patch attached tries to avoid these repetitions by NOT adding
the NNSLoc info to the ETLoc nodes if they contain a QTN node. This is
assuming that either TSTLoc or QTN nodes will evolve to include
syntactic NNSLoc info (currently, TSTLoc has no qualifier info and QTN
has a semantic NNS). The patch "as is" passes all clang lit tests except for
    Clang :: Index/annotate-nested-name-specifier.cpp
    Clang :: Index/recursive-cxx-member-calls.cpp

Does this sound as a reasonable approach?

Regards,
Enea.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ETLoc.patch
Type: text/x-patch
Size: 2748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110302/3e095c7b/attachment.bin>


More information about the cfe-dev mailing list