Clang Import; set Token::function()

This commit is contained in:
Daniel Marjamäki 2020-01-06 15:26:21 +01:00
parent 8ea22edb4e
commit 28688dcc09
1 changed files with 21 additions and 9 deletions

View File

@ -65,8 +65,15 @@ static std::vector<std::string> splitString(const std::string &line)
namespace clangastdump { namespace clangastdump {
struct Data { struct Data {
struct Decl { struct Decl {
Decl(Token *def, Variable *var) : def(def), var(var) {} Decl(Token *def, Variable *var) : def(def), function(nullptr), var(var) {}
Decl(Token *def, Function *function) : def(def), function(function), var(nullptr) {}
void ref(Token *tok) {
tok->function(function);
tok->varId(var ? var->declarationId() : 0);
tok->variable(var);
}
Token *def; Token *def;
Function *function;
Variable *var; Variable *var;
}; };
@ -80,12 +87,16 @@ namespace clangastdump {
var->setValueType(ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0)); var->setValueType(ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0));
} }
void funcDecl(const std::string &addr, Token *nameToken, Function *function) {
Decl decl(nameToken, function);
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
nameToken->function(function);
}
void ref(const std::string &addr, Token *tok) { void ref(const std::string &addr, Token *tok) {
auto it = mDeclMap.find(addr); auto it = mDeclMap.find(addr);
if (it != mDeclMap.end()) { if (it != mDeclMap.end())
tok->varId(it->second.var->declarationId()); it->second.ref(tok);
tok->variable(it->second.var);
}
} }
std::vector<const Variable *> getVariableList() const { std::vector<const Variable *> getVariableList() const {
@ -279,14 +290,15 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
SymbolDatabase *symbolDatabase = mData->mSymbolDatabase; SymbolDatabase *symbolDatabase = mData->mSymbolDatabase;
addTypeTokens(tokenList, mExtTokens.back()); addTypeTokens(tokenList, mExtTokens.back());
Token *nameToken = addtoken(tokenList, mExtTokens[mExtTokens.size() - 2]); Token *nameToken = addtoken(tokenList, mExtTokens[mExtTokens.size() - 2]);
Scope &globalScope = symbolDatabase->scopeList.front(); Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, &globalScope)); symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
Scope &scope = symbolDatabase->scopeList.back(); Scope &scope = symbolDatabase->scopeList.back();
symbolDatabase->functionScopes.push_back(&scope); symbolDatabase->functionScopes.push_back(&scope);
globalScope.functionList.push_back(Function(nameToken)); nestedIn->functionList.push_back(Function(nameToken));
scope.function = &globalScope.functionList.back(); scope.function = &nestedIn->functionList.back();
scope.type = Scope::ScopeType::eFunction; scope.type = Scope::ScopeType::eFunction;
scope.className = nameToken->str(); scope.className = nameToken->str();
mData->funcDecl(mExtTokens.front(), nameToken, scope.function);
Token *par1 = addtoken(tokenList, "("); Token *par1 = addtoken(tokenList, "(");
// Function arguments // Function arguments
for (AstNodePtr child: children) { for (AstNodePtr child: children) {