[cfe-dev] Few questions related to type checking in clang

Amila Jayasekara thejaka.amila at gmail.com
Wed Sep 3 12:43:12 PDT 2014


Thanks a lot, Reid. This is very helpful.

Regards
-Thejaka Amila


On Wed, Sep 3, 2014 at 3:08 AM, Reid Kleckner <rnk at google.com> wrote:

> On Tue, Sep 2, 2014 at 11:30 PM, Amila Jayasekara <thejaka.amila at gmail.com
> > wrote:
>
>> Hi Nikola,
>>
>> Thanks a lot for the response.
>>
>>
>> On Wed, Sep 3, 2014 at 1:56 AM, Nikola Smiljanic <popizdeh at gmail.com>
>> wrote:
>>
>>> 1. Sema is responsible for building the ast, after doing all the checks.
>>> Act methods are 'hooks' that Parser uses to call into Sema. Build methods
>>> are used to build the actual ast nodes.
>>>
>>> 2. Various declaration classes have methods that return QualType, see
>>> http://clang.llvm.org/docs/InternalsManual.html#the-qualtype-class. So
>>> VarDecl has getType but FunctionDecl in addtion has getReturnType and
>>> getFunctionType, etc.
>>>
>>
>> I am actually looking for the class which contains all VarDecl's for a
>> program. As an example, if I have a program as follows;
>>
>> int a;
>> bool b;
>> ...
>> ...
>>
>> I am assuming there is a some sort of a container in clang which keeps
>> all declaration data.
>> Suppose the container is named as TypeEnvironment for the moment. Then I
>> need to query type information about each declaration with code similar to
>> following;
>>
>> TypeEnvironment.get("a")
>> TypeEnvironment.get("b")
>>
>> etc ...
>>
>> So I am looking for the closest implementation in clang, which gives me
>> the functionality of TypeEnvironment (in example above).
>>
>
> Clang AST types are attached to the Decl involved. So you would find a's
> Decl and say something like ADecl->getType(), which is a QualType, which
> can be examined in many ways.
>
> If you just want to do name lookup, the closest thing to what you are
> thinking of is a DeclContext. Lots of things like functions, namespaces,
> classes, unions, etc are DeclContexts, and the lookup is complicated. For
> example, you can find a type from a base class. You would use
> Sema::LookupQualifiedName to find what you want, probably. There can be
> many results of varying kind, and you would have to consider all cases.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140903/07c862bf/attachment.html>


More information about the cfe-dev mailing list