Best way to know if a method declaration is defined in the source

Hi

I am working on clang codegen module and I would like to know how anyone can identify a CXXMethodDecl is defined in the compiled source. In the codegen, I have encountered number of methods thats are not part of my test source code, so if I try to modify them in codegen, they have broken down. Is there any flag or other way using sourcelocation to discard those method declaration from modification.

You probably want the isUserProvided() predicate, which is false for things like implicitly defined constructors and destructors.

–paulr

What about if I want to include implicitly defined constructor and destructor with other user-defined method for a class that is defined in the source? Like I don’t want to have ios_base constructor but I want Employee constructor that is either implicitly or explicitly defined because the class is user-defined.

So, you want to exclude methods defined in system headers? I think there is a way to detect whether a source location is considered to be in a system header; if you grep through clang/include/clang/* for ‘SystemHeader’ you should find it.

–paulr

I am not sure if the following procedure is correct for this purpose, I will like if someone ensure if it is correct to do so.

const CXXMethodDecl *MD = cast(CGF.CurGD.getDecl());
if (isa(MD)) {
auto *classDecl = MD->getParent();
if (!classDecl->isCXX11StandardLayout()) {
// constructor of user-defined class
}
}