Fixed msvc compilation error by implementing Variable::operator=

This commit is contained in:
Daniel Marjamäki 2021-01-28 13:46:00 +01:00
parent 6914f375e1
commit 1151c3dafd
2 changed files with 29 additions and 25 deletions

View File

@ -1887,35 +1887,16 @@ Variable::Variable(const Token *name_, const std::string &clangType, const Token
} }
Variable::Variable(const Variable &var, const Scope *scope) Variable::Variable(const Variable &var, const Scope *scope)
: mNameToken(var.mNameToken) : mValueType(nullptr)
, mTypeStartToken(var.mTypeStartToken)
, mTypeEndToken(var.mTypeEndToken)
, mIndex(var.mIndex)
, mAccess(var.mAccess)
, mFlags(var.mFlags)
, mType(var.mType)
, mScope(scope ? scope : var.mScope)
, mValueType(nullptr)
, mDimensions(var.mDimensions)
{ {
if (var.mValueType) *this = var;
mValueType = new ValueType(*var.mValueType); mScope = scope;
} }
Variable::Variable(const Variable &var) Variable::Variable(const Variable &var)
: mNameToken(var.mNameToken) : mValueType(nullptr)
, mTypeStartToken(var.mTypeStartToken)
, mTypeEndToken(var.mTypeEndToken)
, mIndex(var.mIndex)
, mAccess(var.mAccess)
, mFlags(var.mFlags)
, mType(var.mType)
, mScope(var.mScope)
, mValueType(nullptr)
, mDimensions(var.mDimensions)
{ {
if (var.mValueType) *this = var;
mValueType = new ValueType(*var.mValueType);
} }
Variable::~Variable() Variable::~Variable()
@ -1923,6 +1904,29 @@ Variable::~Variable()
delete mValueType; delete mValueType;
} }
Variable& Variable::operator=(const Variable &var)
{
if (this == &var)
return *this;
mNameToken = var.mNameToken;
mTypeStartToken = var.mTypeStartToken;
mTypeEndToken = var.mTypeEndToken;
mIndex = var.mIndex;
mAccess = var.mAccess;
mFlags = var.mFlags;
mType = var.mType;
mScope = var.mScope;
mDimensions = var.mDimensions;
delete mValueType;
if (var.mValueType)
mValueType = new ValueType(*var.mValueType);
else
mValueType = nullptr;
return *this;
}
bool Variable::isPointerArray() const bool Variable::isPointerArray() const
{ {
return isArray() && nameToken() && nameToken()->previous() && (nameToken()->previous()->str() == "*"); return isArray() && nameToken() && nameToken()->previous() && (nameToken()->previous()->str() == "*");

View File

@ -246,7 +246,7 @@ public:
~Variable(); ~Variable();
Variable &operator=(const Variable &var) = delete; Variable &operator=(const Variable &var);
/** /**
* Get name token. * Get name token.