about summary refs log tree commit diff stats
path: root/wrapperhelper/utils.h
blob: 06acbb7290f3df3f72cbf5aa3091dbf32e352639 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <clang/AST/ASTContext.h>
#include <clang/AST/Decl.h>
#include <clang/AST/Type.h>
#include <clang/Tooling/Tooling.h>
#include <clang/AST/RecordLayout.h>
#include <clang/AST/Decl.h>

#include <llvm/ADT/Triple.h>
#include <llvm/Support/Casting.h>

#include <cstddef>
#include <cstring>
#include <iostream>

static const clang::Type* StripTypedef(clang::QualType type) {
    if (type->isTypedefNameType()) {
        return StripTypedef(type->getAs<clang::TypedefType>()->getDecl()->getUnderlyingType());
    } else {
        return type.getTypePtr();
    }
}

// FIXME: Need to support other triple except default target triple
static std::string GetDeclHeaderFile(clang::ASTContext& Ctx, clang::Decl* Decl) {
    const auto& SourceManager = Ctx.getSourceManager();
    const clang::FileID FileID = SourceManager.getFileID(Decl->getBeginLoc());
    const clang::FileEntry *FileEntry = SourceManager.getFileEntryForID(FileID);
    if (FileEntry) {
        return FileEntry->getName().str();
    }
    return "";
}