Clang import: Full name for methods
This commit is contained in:
parent
87323b33bd
commit
1078855029
|
@ -161,9 +161,10 @@ static std::vector<std::string> splitString(const std::string &line)
|
||||||
namespace clangimport {
|
namespace clangimport {
|
||||||
struct Data {
|
struct Data {
|
||||||
struct Decl {
|
struct Decl {
|
||||||
Decl(Token *def, Variable *var) : def(def), enumerator(nullptr), function(nullptr), var(var) {}
|
Decl(Scope *scope) : def(nullptr), enumerator(nullptr), function(nullptr), scope(scope), var(nullptr) {}
|
||||||
Decl(Token *def, Function *function) : def(def), enumerator(nullptr), function(function), var(nullptr) {}
|
Decl(Token *def, Variable *var) : def(def), enumerator(nullptr), function(nullptr), scope(nullptr), var(var) {}
|
||||||
Decl(Token *def, Enumerator *enumerator) : def(def), enumerator(enumerator), function(nullptr), var(nullptr) {}
|
Decl(Token *def, Function *function) : def(def), enumerator(nullptr), function(function), scope(nullptr), var(nullptr) {}
|
||||||
|
Decl(Token *def, Enumerator *enumerator) : def(def), enumerator(enumerator), function(nullptr), scope(nullptr), var(nullptr) {}
|
||||||
void ref(Token *tok) {
|
void ref(Token *tok) {
|
||||||
if (enumerator)
|
if (enumerator)
|
||||||
tok->enumerator(enumerator);
|
tok->enumerator(enumerator);
|
||||||
|
@ -177,6 +178,7 @@ namespace clangimport {
|
||||||
Token *def;
|
Token *def;
|
||||||
Enumerator *enumerator;
|
Enumerator *enumerator;
|
||||||
Function *function;
|
Function *function;
|
||||||
|
Scope *scope;
|
||||||
Variable *var;
|
Variable *var;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,6 +201,11 @@ namespace clangimport {
|
||||||
notFound(addr);
|
notFound(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scopeDecl(const std::string &addr, Scope *scope) {
|
||||||
|
Decl decl(scope);
|
||||||
|
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
|
||||||
|
}
|
||||||
|
|
||||||
void varDecl(const std::string &addr, Token *def, Variable *var) {
|
void varDecl(const std::string &addr, Token *def, Variable *var) {
|
||||||
Decl decl(def, var);
|
Decl decl(def, var);
|
||||||
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
|
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
|
||||||
|
@ -231,6 +238,11 @@ namespace clangimport {
|
||||||
return mDeclMap.find(addr) != mDeclMap.end();
|
return mDeclMap.find(addr) != mDeclMap.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Scope *getScope(const std::string &addr) {
|
||||||
|
auto it = mDeclMap.find(addr);
|
||||||
|
return (it == mDeclMap.end() ? nullptr : it->second.scope);
|
||||||
|
}
|
||||||
|
|
||||||
// "}" tokens that are not end-of-scope
|
// "}" tokens that are not end-of-scope
|
||||||
std::set<Token *> mNotScope;
|
std::set<Token *> mNotScope;
|
||||||
private:
|
private:
|
||||||
|
@ -277,6 +289,7 @@ namespace clangimport {
|
||||||
Token *createTokens(TokenList *tokenList);
|
Token *createTokens(TokenList *tokenList);
|
||||||
Token *addtoken(TokenList *tokenList, const std::string &str, bool valueType=true);
|
Token *addtoken(TokenList *tokenList, const std::string &str, bool valueType=true);
|
||||||
const ::Type *addTypeTokens(TokenList *tokenList, const std::string &str, const Scope *scope = nullptr);
|
const ::Type *addTypeTokens(TokenList *tokenList, const std::string &str, const Scope *scope = nullptr);
|
||||||
|
void addFullScopeNameTokens(TokenList *tokenList, const Scope *recordScope);
|
||||||
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, AstNodePtr astNode, const Token *def);
|
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, AstNodePtr astNode, const Token *def);
|
||||||
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children, const Token *def);
|
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children, const Token *def);
|
||||||
Token *createTokensCall(TokenList *tokenList);
|
Token *createTokensCall(TokenList *tokenList);
|
||||||
|
@ -475,6 +488,23 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clangimport::AstNode::addFullScopeNameTokens(TokenList *tokenList, const Scope *recordScope)
|
||||||
|
{
|
||||||
|
if (!recordScope)
|
||||||
|
return;
|
||||||
|
std::list<const Scope *> scopes;
|
||||||
|
while (recordScope && recordScope != tokenList->back()->scope() && !recordScope->isExecutable()) {
|
||||||
|
scopes.push_front(recordScope);
|
||||||
|
recordScope = recordScope->nestedIn;
|
||||||
|
}
|
||||||
|
for (const Scope *s: scopes) {
|
||||||
|
if (!s->className.empty()) {
|
||||||
|
addtoken(tokenList, s->className);
|
||||||
|
addtoken(tokenList, "::");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Scope *clangimport::AstNode::getNestedInScope(TokenList *tokenList)
|
const Scope *clangimport::AstNode::getNestedInScope(TokenList *tokenList)
|
||||||
{
|
{
|
||||||
if (!tokenList->back())
|
if (!tokenList->back())
|
||||||
|
@ -1127,6 +1157,10 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
|
||||||
addTypeTokens(tokenList, '\'' + getType() + '\'');
|
addTypeTokens(tokenList, '\'' + getType() + '\'');
|
||||||
startToken = before ? before->next() : tokenList->front();
|
startToken = before ? before->next() : tokenList->front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mExtTokens.size() > 4 && mExtTokens[1] == "parent")
|
||||||
|
addFullScopeNameTokens(tokenList, mData->getScope(mExtTokens[2]));
|
||||||
|
|
||||||
Token *nameToken = addtoken(tokenList, getSpelling() + getTemplateParameters());
|
Token *nameToken = addtoken(tokenList, getSpelling() + getTemplateParameters());
|
||||||
Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
|
Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
|
||||||
|
|
||||||
|
@ -1249,6 +1283,8 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
|
||||||
children2.push_back(child);
|
children2.push_back(child);
|
||||||
}
|
}
|
||||||
Scope *scope = createScope(tokenList, isStruct ? Scope::ScopeType::eStruct : Scope::ScopeType::eClass, children2, classToken);
|
Scope *scope = createScope(tokenList, isStruct ? Scope::ScopeType::eStruct : Scope::ScopeType::eClass, children2, classToken);
|
||||||
|
const std::string addr = mExtTokens[0];
|
||||||
|
mData->scopeDecl(addr, scope);
|
||||||
scope->className = className;
|
scope->className = className;
|
||||||
mData->mSymbolDatabase->typeList.push_back(Type(classToken, scope, classToken->scope()));
|
mData->mSymbolDatabase->typeList.push_back(Type(classToken, scope, classToken->scope()));
|
||||||
scope->definedType = &mData->mSymbolDatabase->typeList.back();
|
scope->definedType = &mData->mSymbolDatabase->typeList.back();
|
||||||
|
|
|
@ -500,7 +500,7 @@ private:
|
||||||
"| `-CXXMethodDecl 0x21ccc68 <line:3:1, col:10> col:6 foo 'void ()'\n"
|
"| `-CXXMethodDecl 0x21ccc68 <line:3:1, col:10> col:6 foo 'void ()'\n"
|
||||||
"`-CXXMethodDecl 0x21ccd60 parent 0x21cca40 prev 0x21ccc68 <line:6:1, col:19> col:12 foo 'void ()'\n"
|
"`-CXXMethodDecl 0x21ccd60 parent 0x21cca40 prev 0x21ccc68 <line:6:1, col:19> col:12 foo 'void ()'\n"
|
||||||
" `-CompoundStmt 0x21cce50 <col:18, col:19>";
|
" `-CompoundStmt 0x21cce50 <col:18, col:19>";
|
||||||
ASSERT_EQUALS("class Fred { void foo ( ) ; } ; void foo ( ) { }", parse(clang));
|
ASSERT_EQUALS("class Fred { void foo ( ) ; } ; void Fred :: foo ( ) { }", parse(clang));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cxxNewExpr1() {
|
void cxxNewExpr1() {
|
||||||
|
|
Loading…
Reference in New Issue