Clang import; Better handling of enums
This commit is contained in:
parent
625da9af5c
commit
66dd985c9d
|
@ -148,16 +148,21 @@ 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), function(nullptr), var(var) {}
|
Decl(Token *def, Variable *var) : def(def), enumerator(nullptr), function(nullptr), var(var) {}
|
||||||
Decl(Token *def, Function *function) : def(def), function(function), var(nullptr) {}
|
Decl(Token *def, Function *function) : def(def), enumerator(nullptr), function(function), var(nullptr) {}
|
||||||
|
Decl(Token *def, Enumerator *enumerator) : def(def), enumerator(enumerator), function(nullptr), var(nullptr) {}
|
||||||
void ref(Token *tok) {
|
void ref(Token *tok) {
|
||||||
|
if (enumerator)
|
||||||
|
tok->enumerator(enumerator);
|
||||||
if (function)
|
if (function)
|
||||||
tok->function(function);
|
tok->function(function);
|
||||||
tok->varId(var ? var->declarationId() : 0);
|
if (var) {
|
||||||
if (var)
|
|
||||||
tok->variable(var);
|
tok->variable(var);
|
||||||
|
tok->varId(var->declarationId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Token *def;
|
Token *def;
|
||||||
|
Enumerator *enumerator;
|
||||||
Function *function;
|
Function *function;
|
||||||
Variable *var;
|
Variable *var;
|
||||||
};
|
};
|
||||||
|
@ -165,6 +170,22 @@ namespace clangimport {
|
||||||
const Settings *mSettings = nullptr;
|
const Settings *mSettings = nullptr;
|
||||||
SymbolDatabase *mSymbolDatabase = nullptr;
|
SymbolDatabase *mSymbolDatabase = nullptr;
|
||||||
|
|
||||||
|
int enumValue = 0;
|
||||||
|
|
||||||
|
void enumDecl(const std::string &addr, Token *nameToken, Enumerator *enumerator) {
|
||||||
|
Decl decl(nameToken, enumerator);
|
||||||
|
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
|
||||||
|
nameToken->enumerator(enumerator);
|
||||||
|
notFound(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
notFound(addr);
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
@ -175,13 +196,6 @@ namespace clangimport {
|
||||||
notFound(addr);
|
notFound(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
notFound(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
||||||
|
@ -469,6 +483,8 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
|
||||||
|
|
||||||
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
|
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
|
||||||
Scope *scope = &symbolDatabase->scopeList.back();
|
Scope *scope = &symbolDatabase->scopeList.back();
|
||||||
|
if (scopeType == Scope::ScopeType::eEnum)
|
||||||
|
scope->enumeratorList.reserve(children.size());
|
||||||
nestedIn->nestedList.push_back(scope);
|
nestedIn->nestedList.push_back(scope);
|
||||||
scope->type = scopeType;
|
scope->type = scopeType;
|
||||||
scope->classDef = def;
|
scope->classDef = def;
|
||||||
|
@ -733,9 +749,19 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
||||||
par1->astOperand2(expr);
|
par1->astOperand2(expr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (nodeType == EnumConstantDecl)
|
if (nodeType == EnumConstantDecl) {
|
||||||
return addtoken(tokenList, getSpelling());
|
Token *nameToken = addtoken(tokenList, getSpelling());
|
||||||
|
Scope *scope = const_cast<Scope *>(nameToken->scope());
|
||||||
|
scope->enumeratorList.push_back(Enumerator(nameToken->scope()));
|
||||||
|
Enumerator *e = &scope->enumeratorList.back();
|
||||||
|
e->name = nameToken;
|
||||||
|
e->value = mData->enumValue++;
|
||||||
|
e->value_known = true;
|
||||||
|
mData->enumDecl(mExtTokens.front(), nameToken, e);
|
||||||
|
return nameToken;
|
||||||
|
}
|
||||||
if (nodeType == EnumDecl) {
|
if (nodeType == EnumDecl) {
|
||||||
|
mData->enumValue = 0;
|
||||||
Token *enumtok = addtoken(tokenList, "enum");
|
Token *enumtok = addtoken(tokenList, "enum");
|
||||||
Token *nametok = nullptr;
|
Token *nametok = nullptr;
|
||||||
if (mExtTokens[mExtTokens.size() - 3].compare(0,4,"col:") == 0)
|
if (mExtTokens[mExtTokens.size() - 3].compare(0,4,"col:") == 0)
|
||||||
|
|
Loading…
Reference in New Issue