Clang import; reference before declaration

This commit is contained in:
Daniel Marjamäki 2020-01-09 18:03:24 +01:00
parent d842f00aef
commit 2137f1ead9
2 changed files with 15 additions and 1 deletions

View File

@ -116,18 +116,22 @@ namespace clangastdump {
def->varId(++mVarId); def->varId(++mVarId);
def->variable(var); def->variable(var);
var->setValueType(ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0)); var->setValueType(ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0));
notFound(addr);
} }
void funcDecl(const std::string &addr, Token *nameToken, Function *function) { void funcDecl(const std::string &addr, Token *nameToken, Function *function) {
Decl decl(nameToken, function); Decl decl(nameToken, function);
mDeclMap.insert(std::pair<std::string, Decl>(addr, decl)); mDeclMap.insert(std::pair<std::string, Decl>(addr, decl));
nameToken->function(function); 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())
it->second.ref(tok); it->second.ref(tok);
else
mNotFound[addr].push_back(tok);
} }
std::vector<const Variable *> getVariableList() const { std::vector<const Variable *> getVariableList() const {
@ -141,7 +145,17 @@ namespace clangastdump {
} }
private: private:
void notFound(const std::string &addr) {
auto it = mNotFound.find(addr);
if (it != mNotFound.end()) {
for (Token *reftok: it->second)
ref(addr, reftok);
mNotFound.erase(it);
}
}
std::map<std::string, Decl> mDeclMap; std::map<std::string, Decl> mDeclMap;
std::map<std::string, std::vector<Token *>> mNotFound;
int mVarId = 0; int mVarId = 0;
}; };

View File

@ -186,7 +186,7 @@ private:
"| | `-CXXThisExpr 0x428e9c0 <col:17> 'C *' this\n" "| | `-CXXThisExpr 0x428e9c0 <col:17> 'C *' this\n"
"| `-IntegerLiteral 0x428ea10 <col:21> 'int' 0\n" "| `-IntegerLiteral 0x428ea10 <col:21> 'int' 0\n"
"`-FieldDecl 0x428e958 <col:26, col:30> col:30 referenced x 'int'"; "`-FieldDecl 0x428e958 <col:26, col:30> col:30 referenced x 'int'";
ASSERT_EQUALS("void C ( ) { this . x = 0 ; } int x@1", parse(clang)); ASSERT_EQUALS("void C ( ) { this . x@1 = 0 ; } int x@1", parse(clang));
} }
void cxxMemberCall() { void cxxMemberCall() {