automatically generated declarations in the AST

Hi!

Is there any mechanism to identify automatically generated nodes inside
the AST? I found CXXRecordDecl::hasDeclaredDefaultConstructor() etc. but
there are also other auto generated nodes. I tried to use the source
location but this is not consistent, e.g. the auto generated ctors do
have a valid source location despite not having any source code.

Another issue are anonymous namespaces. After the first occurrence,
Clang will insert an using directive. Fine. The problem is, that this
directive does have a valid source location, but the namespace
declarations don't. The beginning of their SourceRanges is invalid, the
end is correct. Is this intended behavior? How can I get the correct
start locations?

Regards, Jan.

Hi!

Is there any mechanism to identify automatically generated nodes inside
the AST? I found CXXRecordDecl::hasDeclaredDefaultConstructor() etc. but
there are also other auto generated nodes. I tried to use the source
location but this is not consistent, e.g. the auto generated ctors do
have a valid source location despite not having any source code.

Decl::isImplicit()

Another issue are anonymous namespaces. After the first occurrence,
Clang will insert an using directive. Fine. The problem is, that this
directive does have a valid source location, but the namespace
declarations don't. The beginning of their SourceRanges is invalid, the
end is correct. Is this intended behavior? How can I get the correct
start locations?

The using declaration is marked "implicit", so you can determine that we're in this case with Decl::isImplicit(). However, the broken SourceRange is a bug. Please file a bug at llvm.org/bugs or, better yet, provide a fix :slight_smile:

  - Doug

Douglas Gregor meinte am 19.08.2010 19:13:

Is there any mechanism to identify automatically generated nodes
inside the AST?

Decl::isImplicit()

Thanks, that helps a lot!

But even that does not cover all the auto insertions. The first
instruction in every translation unit is

typedef char* __builtin_va_list;

which states its source location as <built-in>:102:15. This is not
marked implicit. I guess it's from some internal include directive. In
that case I can just check that it doesn't come from the main file. Are
there any other things like that I should keep an eye on?

However, the broken SourceRange is a bug. Please file a bug at
llvm.org/bugs or, better yet, provide a fix :slight_smile:

http://llvm.org/bugs/show_bug.cgi?id=7939

I'll also give the bugfix a try, but don't expect too much. Until now I
never had a look at that part of Clang...

Regards, Jan.

Douglas Gregor meinte am 19.08.2010 19:13:

Is there any mechanism to identify automatically generated nodes
inside the AST?

Decl::isImplicit()

Thanks, that helps a lot!

But even that does not cover all the auto insertions. The first
instruction in every translation unit is

typedef char* __builtin_va_list;

which states its source location as <built-in>:102:15. This is not
marked implicit. I guess it's from some internal include directive. In
that case I can just check that it doesn't come from the main file.

You can check that it comes from the predefines buffer. It is, admittedly, a bit weird.

Are
there any other things like that I should keep an eye on?

I don't think so.

However, the broken SourceRange is a bug. Please file a bug at
llvm.org/bugs or, better yet, provide a fix :slight_smile:

http://llvm.org/bugs/show_bug.cgi?id=7939

I'll also give the bugfix a try, but don't expect too much. Until now I
never had a look at that part of Clang...

Thanks!

Douglas Gregor meinte am 19.08.2010 21:22:

However, the broken SourceRange is a bug. Please file a bug at
llvm.org/bugs or, better yet, provide a fix :slight_smile:

http://llvm.org/bugs/show_bug.cgi?id=7939

I'll also give the bugfix a try, but don't expect too much. Until now I
never had a look at that part of Clang...

Thanks!

=> patch attached

anonNS.patch (763 Bytes)

Thanks! Committed in r111561.

  Doug