[cfe-dev] Missing info from TypeLoc?

Vane, Edwin edwin.vane at intel.com
Wed Mar 13 21:00:08 PDT 2013


I'm writing a tool to replace some part of the declaration with the 'auto' type specifier in the specific instance where a CXXNewExpr is the initializer. So like:

MyType *a = new MyType()

My problem is the handling of odd cases like:

Const MyType *a = new MyType();       -> const auto *a = new MyType();
Const MyType *a = new const MyType();  -> auto a = new const MyType();
Mytype * const a = new MyType(); -> const auto a = new MyType();
// And so on

Really what I need is a way of locating the cv-qualifier and what it applies to so I can replace as much or as little with 'auto' as necessary. I was using TypeLoc to get the location information for the replacement but I need something more complex now.

From: metafoo at gmail.com [mailto:metafoo at gmail.com] On Behalf Of Richard Smith
Sent: Wednesday, March 13, 2013 4:04 PM
To: Vane, Edwin
Cc: Clang Dev List (cfe-dev at cs.uiuc.edu)
Subject: Re: [cfe-dev] Missing info from TypeLoc?

On Wed, Mar 13, 2013 at 6:27 AM, Vane, Edwin <edwin.vane at intel.com<mailto:edwin.vane at intel.com>> wrote:
Is there an API I can re-use to parse the specifiers or at least get me part of the way toward what I need?

What is it that you need? :)

From: metafoo at gmail.com<mailto:metafoo at gmail.com> [mailto:metafoo at gmail.com<mailto:metafoo at gmail.com>] On Behalf Of Richard Smith
Sent: Tuesday, March 12, 2013 7:01 PM
To: Vane, Edwin
Cc: Clang Dev List (cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>)
Subject: Re: [cfe-dev] Missing info from TypeLoc?

On Tue, Mar 12, 2013 at 12:28 PM, Vane, Edwin <edwin.vane at intel.com<mailto:edwin.vane at intel.com>> wrote:
Hi all,

Given this c++ code:

const MyType *a;

The TypeSourceInfo from the VarDecl provides a TypeLoc that claims the type starts at "MyType" not "const". Is this by design or is there a bug here?

QualifiedTypeLoc does not store location information for the type qualifiers. This is "intentional" but clearly not ideal for tooling clients of type location information. Since the decl-specifiers for such a declaration can be in any order, the source range for such a type isn't necessarily going to be useful, and you may be able to get the information you're looking for by just looking at the start location of the Decl.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130314/c39310b1/attachment.html>


More information about the cfe-dev mailing list