-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[template] Arguments substititation, class arguments checking, arguments in params duplication #41
Open
NikitaZotov
wants to merge
5
commits into
main
Choose a base branch
from
feat/sc_template_search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
952d33e
[template] Argument replacements, class arguments checking, arguments…
NikitaZotov ee6e77d
[test][template] Test case with equal constructions in template
NikitaZotov 7e5f401
[docs] Apply changes
NikitaZotov 8bdbfee
Review fixes
NikitaZotov 5533f9f
Review fixes
NikitaZotov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,72 +23,86 @@ std::vector<ScTemplateParams> TemplateManager::createTemplateParams( | |
ScAddrVector const & argumentList) | ||
{ | ||
std::map<std::string, std::set<ScAddr, AddrComparator>> replacementsMultimap; | ||
std::vector<ScTemplateParams> templateParamsVector; | ||
|
||
ScIterator3Ptr varIterator = context->Iterator3(scTemplate, ScType::EdgeAccessConstPosPerm, ScType::NodeVar); | ||
while (varIterator->Next()) | ||
{ | ||
ScAddr var = varIterator->Get(2); | ||
std::string varName = context->HelperGetSystemIdtf(var); | ||
if (!replacementsMultimap[varName].empty()) | ||
{ | ||
continue; | ||
} | ||
ScAddr argumentOfVar; | ||
ScIterator5Ptr classesIterator = context->Iterator5( | ||
ScType::NodeConstClass, ScType::EdgeAccessVarPosPerm, var, ScType::EdgeAccessConstPosPerm, scTemplate); | ||
while (classesIterator->Next()) | ||
for (ScAddr const & argument : argumentList) | ||
{ | ||
ScAddr varClass = classesIterator->Get(0); | ||
for (ScAddr const & argument : argumentList) // this block is executed if inputStructure is valid | ||
ScIterator5Ptr const & classesIterator = context->Iterator5( | ||
ScType::NodeConstClass, ScType::EdgeAccessVarPosPerm, var, ScType::EdgeAccessConstPosPerm, scTemplate); | ||
bool isBelong = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is belong what? Name variables clear |
||
while (classesIterator->Next()) | ||
{ | ||
ScAddr varClass = classesIterator->Get(0); | ||
if (context->HelperCheckEdge(varClass, argument, ScType::EdgeAccessConstPosPerm)) | ||
replacementsMultimap[varName].insert(argument); | ||
{ | ||
isBelong = true; | ||
} | ||
else | ||
{ | ||
isBelong = false; | ||
break; | ||
} | ||
} | ||
if (argumentList.empty()) // this block is executed if inputStructure is not valid | ||
|
||
if (isBelong) | ||
{ | ||
ScIterator3Ptr iterator3 = context->Iterator3(varClass, ScType::EdgeAccessConstPosPerm, ScType::Unknown); | ||
while (iterator3->Next()) | ||
replacementsMultimap[varName].insert(iterator3->Get(2)); | ||
replacementsMultimap[varName].insert(argument); | ||
} | ||
} | ||
if (templateParamsVector.empty()) | ||
} | ||
|
||
std::vector<std::map<std::string, ScAddr>> paramsVector; | ||
paramsVector.reserve(replacementsMultimap.size()); | ||
for (auto const & pair : replacementsMultimap) | ||
{ | ||
std::vector<std::map<std::string, ScAddr>> newParamsVector; | ||
newParamsVector.reserve(replacementsMultimap.size()); | ||
kilativ-dotcom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (auto const & addr : pair.second) | ||
{ | ||
std::set<ScAddr, AddrComparator> addresses = replacementsMultimap[varName]; | ||
templateParamsVector.reserve(replacementsMultimap[varName].size()); | ||
for (ScAddr const & address : addresses) | ||
bool isUploaded = false; | ||
for (auto map : paramsVector) | ||
{ | ||
ScTemplateParams params; | ||
params.Add(varName, address); | ||
templateParamsVector.push_back(params); | ||
} | ||
} | ||
else | ||
{ | ||
std::set<ScAddr, AddrComparator> addresses = replacementsMultimap[varName]; | ||
size_t amountOfAddressesForVar = addresses.size(); | ||
size_t oldParamsSize = templateParamsVector.size(); | ||
bool isDuplicatedValue = false; | ||
for (auto const & mapPair : map) | ||
{ | ||
if (mapPair.second == addr) | ||
{ | ||
isDuplicatedValue = true; | ||
} | ||
} | ||
kilativ-dotcom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (amountOfAddressesForVar == 0) | ||
continue; | ||
if (!isDuplicatedValue) | ||
{ | ||
map.insert({ pair.first, addr }); | ||
newParamsVector.emplace_back(map); | ||
} | ||
|
||
size_t amountOfNewElements = oldParamsSize * amountOfAddressesForVar; | ||
std::vector<ScTemplateParams> updatedParams; | ||
updatedParams.reserve(amountOfNewElements); | ||
isUploaded = true; | ||
} | ||
|
||
size_t beginOfCopy = 0; | ||
size_t endOfCopy = oldParamsSize; | ||
for (ScAddr const & address : addresses) | ||
if (!isUploaded) | ||
{ | ||
copy_n(templateParamsVector.begin(), oldParamsSize, back_inserter(updatedParams)); | ||
for (size_t i = 0; i < oldParamsSize; ++i) | ||
updatedParams[beginOfCopy + i].Add(varName, address); | ||
beginOfCopy = endOfCopy; | ||
endOfCopy += oldParamsSize; | ||
std::map<std::string, ScAddr> map{{ pair.first, addr }}; | ||
newParamsVector.emplace_back(map); | ||
} | ||
} | ||
paramsVector = newParamsVector; | ||
} | ||
|
||
templateParamsVector = std::move(updatedParams); | ||
std::vector<ScTemplateParams> templateParamsVector; | ||
for (auto const & params : paramsVector) | ||
{ | ||
ScTemplateParams templateParams; | ||
for (auto const & param : params) | ||
{ | ||
templateParams.Add(param.first, param.second); | ||
} | ||
templateParamsVector.emplace_back(templateParams); | ||
} | ||
|
||
return templateParamsVector; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this var should be initialized with true. In that case replacements for variables without classes will be searched in arguments and not in input structure