-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnamelookup.cpp
More file actions
110 lines (90 loc) · 3.01 KB
/
namelookup.cpp
File metadata and controls
110 lines (90 loc) · 3.01 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "namelookup.h"
#include <clang/AST/ASTContext.h>
#include <clang/AST/Decl.h>
#include <clang/AST/DeclCXX.h>
// 需要把Sema.h中的emit()函数改名,否则会与Qt中的emit冲突。
#include <clang/Sema/Sema.h>
#include <clang/Sema/Lookup.h>
#include <clang/Frontend/ASTUnit.h>
#include <clang/Basic/IdentifierTable.h>
#include "frontengine.h"
bool test_code()
{
// 这个函数生成的II能否用于namelookup呢?
auto str2ii = [](QString name) -> clang::IdentifierInfo * {
std::string xname = name.toStdString();
llvm::StringRef rname(xname);
clang::LangOptions opts;
auto *idt = new clang::IdentifierTable(opts);
auto &II = idt->getOwn(rname);
llvm::StringRef sname = II.getName();
qDebug()<<sname.str().c_str();
idt->PrintStats();
return &II; // unsafe
return NULL;
};
auto str2dn = [&](QString name) -> clang::DeclarationName {
clang::IdentifierInfo *II = NULL;
II = str2ii(name);
assert(II->getName().str() == name.toStdString());
clang::DeclarationName dn(II);
return dn;
};
return true;
}
bool nlu_find_method(FrontEngine *fe, QString method, clang::CXXRecordDecl *rd)
{
auto &ctx = fe->getASTContext();
auto unit = fe->getASTUnit();
auto &sema = unit->getSema();
//
method = "arg";
clang::NamedDecl *nd = NULL;
for (auto md: rd->methods()) {
if (llvm::isa<clang::NamedDecl>(md)) {
if (method == md->getName().data()) {
nd = md;
break;
}
}
}
qDebug()<<nd;
// nd->dumpColor();
clang::DeclarationName dname(nd->getIdentifier());
clang::LookupResult lur(sema, dname, clang::SourceLocation(),
clang::Sema::LookupMemberName);
clang::DeclContext *dctx = clang::Decl::castToDeclContext(rd);
bool bret = sema.LookupQualifiedName(lur, dctx);
qDebug()<<bret<<dctx->getDeclKindName()
<<lur.getResultKind();
// dname.dump();
int idx = 0;
for (auto it = lur.begin(); it != lur.end(); it++, idx++) {
auto td = *it;
qDebug()<<"idx="<<idx;
// td->dumpColor();
}
qDebug()<<"idx="<<idx;
//
QVariant vv(idx);
llvm::APInt iv(sizeof(int), vv.toInt());
clang::Expr *te = clang::IntegerLiteral::Create(ctx, clang::Stmt::EmptyShell());
clang::ADLResult adlur;
std::vector<clang::Expr*> args = {te};
qDebug()<<"......";
// sema.ArgumentDependentLookup(dname, clang::SourceLocation(), args, adlur);
qDebug()<<"......";
idx = 0;
for (auto it = adlur.begin(); it != adlur.end(); it++, idx++) {
}
qDebug()<<idx;
idx = 0;
for (auto it = lur.begin(); it != lur.end(); it++, idx++) {
auto td = *it;
// td->dumpColor();
auto ea = sema.CheckEnableIf(llvm::cast<clang::FunctionDecl>(td), args, true);
// qDebug()<<"idx="<<idx<<ea;
}
qDebug()<<"idx="<<idx;
return false;
}