Clang import: Improved handling of overloaded operators

This commit is contained in:
Daniel Marjamäki 2020-11-01 15:30:40 +01:00
parent db3d9a79b5
commit 9dc085c3ec
2 changed files with 22 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <climits> #include <climits>
#include <cstring>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <unordered_map> #include <unordered_map>
@ -2044,6 +2045,15 @@ std::string Variable::getTypeName() const
return ret; return ret;
} }
static bool isOperator(const Token *tokenDef) {
if (!tokenDef)
return false;
if (tokenDef->isOperatorKeyword())
return true;
const std::string name = tokenDef->str();
return name.size() > 8 && name.compare(0,8,"operator")==0 && std::strchr("+-*/%&|~^<>!=[(", name[8]);
}
Function::Function(const Tokenizer *mTokenizer, Function::Function(const Tokenizer *mTokenizer,
const Token *tok, const Token *tok,
const Scope *scope, const Scope *scope,
@ -2067,7 +2077,7 @@ Function::Function(const Tokenizer *mTokenizer,
mFlags(0) mFlags(0)
{ {
// operator function // operator function
if (tokenDef->isOperatorKeyword()) { if (::isOperator(tokenDef)) {
isOperator(true); isOperator(true);
// 'operator =' is special // 'operator =' is special
@ -2215,6 +2225,14 @@ Function::Function(const Token *tokenDef)
functionPointerUsage(nullptr), functionPointerUsage(nullptr),
mFlags(0) mFlags(0)
{ {
// operator function
if (::isOperator(tokenDef)) {
isOperator(true);
// 'operator =' is special
if (tokenDef->str() == "operator=")
type = Function::eOperatorEqual;
}
} }
std::string Function::fullName() const std::string Function::fullName() const

View File

@ -94,6 +94,9 @@ def test_symbol_database_3():
def test_symbol_database_4(): def test_symbol_database_4():
check_symbol_database('void f(const int x) {}') check_symbol_database('void f(const int x) {}')
def test_symbol_database_operator():
check_symbol_database('struct Fred { void operator=(int x); };')
def test_symbol_database_struct_1(): def test_symbol_database_struct_1():
check_symbol_database('struct S {};') check_symbol_database('struct S {};')