Few questions related to type checking in clang

Hi All,

I am fairly new to clang. I am trying to implement experimental type checking rules for lambda functions. I would mainly like to get feedback on following;

  1. I believe clang/lib/Sema is responsible for carrying out type checking. In the files in clang/lib/Sema I mainly saw 2 types of functions; a. BuildXXX functions and ActOnXXX functions. Which function pattern contains actual type checking implementations ? (In other words in which functions we do type checking ? e.g. :- function type checking etc …)

  2. In clang where (the class responsible) do we keep the information about type environment (i.e. type information about each variable, function etc …) and how to retrieve/update type information ?

Will be great if I could get feedback on above.

Thank you in advance.

Regards
Thejaka Amila

  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.

Hi Nikola,

Thanks a lot for the response.

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.

Thanks a lot, Reid. This is very helpful.

Regards
-Thejaka Amila