data: Added intermediate fix to handle multiple definitions of main() in C/C++ (issue #233)

* record main definition as .:main:.<filename>
* restore original name in name deserialization
* don't look up id when undoing main activation
This commit is contained in:
Eberhard Graether
2019-04-30 13:04:57 +02:00
parent ee1fd9c38b
commit af70d684a5
8 changed files with 51 additions and 19 deletions
@@ -493,7 +493,13 @@ void UndoRedoController::replayCommand(std::list<Command>::iterator it)
for (SearchMatch match : matches)
{
match.tokenIds = m_storageAccess->getNodeIdsForNameHierarchies(match.tokenNames);
// TODO: replace duplicate main definition fix with better solution
if (match.nodeType.getType() != NodeType::NODE_FUNCTION || !match.tokenNames.size() ||
match.tokenNames[0].getRawName() != L"main")
{
match.tokenIds = m_storageAccess->getNodeIdsForNameHierarchies(match.tokenNames);
}
if (!match.tokenIds.size())
{
match.nodeType = NodeType::NODE_SYMBOL;
+2 -2
View File
@@ -38,7 +38,7 @@ std::wstring NameElement::Signature::qualifyName(const std::wstring& name) const
bool NameElement::Signature::isValid() const
{
return ((m_prefix + m_postfix).size() > 0);
return !m_prefix.empty() || !m_postfix.empty();
}
const std::wstring& NameElement::Signature::getPrefix() const
@@ -53,7 +53,7 @@ const std::wstring& NameElement::Signature::getPostfix() const
std::wstring NameElement::Signature::getParameterString() const
{
if (m_postfix.size())
if (!m_postfix.empty())
{
return utility::substrBeforeLast(m_postfix, L')') + L')';
}
+9
View File
@@ -89,6 +89,15 @@ NameHierarchy NameHierarchy::deserialize(const std::wstring& serializedName)
nameHierarchy.push(NameElement(std::move(name), std::move(prefix), std::move(postfix)));
}
// TODO: replace duplicate main definition fix with better solution
if (nameHierarchy.size() == 1 && nameHierarchy.back().hasSignature() && !nameHierarchy.back().getName().empty() &&
nameHierarchy.back().getName()[0] == '.' && utility::isPrefix<std::wstring>(L".:main:.", nameHierarchy.back().getName()))
{
NameElement::Signature sig = nameHierarchy.back().getSignature();
nameHierarchy.pop();
nameHierarchy.push(NameElement(L"main", sig.getPrefix(), sig.getPostfix()));
}
return nameHierarchy;
}