How to tell semantic node from lexical node using libClang?

Hi, :raised_hand_with_fingers_splayed:
Recently I’m using libClang to write a parser for my project. However, when libClang traverses a .cpp file, it introduces a lot of nodes that are not literally related to the source code, e.g. NamespaceDecl from the template libraries, FunctionDecl from the gcc thread translation unit, etc., which make sense but I don’t want to include in my analysis (I only need to analyze some superficial information in the source code in my project).

I managed to filter out a lot of NamespaceDecl and LinkageSpecDecl nodes by checking the Kind of cursors, but there are still some FunctionDecl nodes that behave as semantic nodes in the AST (I hope I understand correctly) that hinder my analysis.

As I understand it (and there may be a misunderstanding), syntactic nodes, that is, nodes that behave in the AST as `-FunctionDecl[…] and not |-FunctionDecl must come from the source file, which is what I need to analyze.

Is there any way to distinguish between these two types of nodes? Or do I need to use a more advanced Clang tool to do this type of analysis? Or, is there any way to tell if a node is literally from the source file?

Update: This problem has been solved.

I managed to get the source filename of each cursor and compare it with the source filename of the translation unit, nodes and their children that don’t match are skipped.

    CXSourceLocation location = clang_getCursorLocation(cursor);
    CXFile srcfile;
    unsigned int line, column, offset;
    clang_getSpellingLocation(location, &srcfile, &line, &column, &offset);
    CXString fileName = clang_getFileName(srcfile);
    const char *fileNameStr = clang_getCString(fileName);

    if (strcmp(srcFileStr, fileNameStr) != 0) {
        return CXChildVisit_Continue;