Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] (C/C++ AST API) const/volatile/... qualifiers for IType or IVariable

However, IQualifierType is public, you can use it instead of CPPQualifierType in the code snippet.
Note, that pointer-types (as opposed to other types) contain the cv-qualification by themselves. So you also need to check for IPointerType (and possibly ICArrayType).

-----Original Message-----
From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Nathan Ridge
Sent: Sat, 27. 09. 2014 06:47
To: CDT Mailing List
Subject: Re: [cdt-dev] (C/C++ AST API) const/volatile/... qualifiers for IType or IVariable

> On 2014-09-26 07:25 AM, Dmitry Petrov wrote:
>> Is there a concise way to obtain const/volatile/... type qualifiers for a given IType (or at least for a given IVariable)?

Here's how I would do it in internal CDT code:

  IType type = ...;
  if (type instanceof CPPQualifierType) {
    CPPQualifierType qualifierType = (CPPQualifierType) type;
    if (qualifierType.isConst()) {
      // variable is const
    } else if (qualifierType.isVolatile()) {
      // variable is volatile

Unfortunately, CPPQualifierType is not public API.

We should probably add a public interface ICPPQualifierType which CPPQualifierType implements, and which has isConst() and isVolatile() methods. Please file a bug for this, and I'll be happy to write a patch.

>> In fact, I have a bit simpler question: for a given IVariable, tell if it's const.
> I might be completely off target here, but: IVariable implements IDeclaration, which has isStatic, isConst, isVolatile. Isn't it what you want?

There are two interfaces names IVariable in the CDT codebase: one in the IBinding hierarchy, and one in the ICElement hierarchy.

Since Dmitry talks about IType as well, I'm assuming he means the first, in which case the ways I can see are to use getType() to get the type of the variable and examine it (as described above, not currently possible using only public API), or to find the variable's declaration in the AST and examine that.

I'm not very familiar with the ICElement hierarchy, but the IVariable interface in that hierarchy does indeed have isConst() and isVolatile() methods as you say, so if the question concerns this IVariable interface, then that seems to be the answer.

> As far as I understand, a Type can't be const/volatile/static, so you can't get that from an IType. They apply to a variable declaration.

A type can be const or volatile. 'static' only applies to variables and functions.

Hope that helps,
cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top