Added missing functionality to <container> elements in Librarie, completed STL container definitions in std.cfg

This commit is contained in:
PKEuS 2015-11-20 18:22:15 +01:00
parent 4abc0b7c1f
commit 6590d46013
4 changed files with 79 additions and 12 deletions

View File

@ -3966,6 +3966,11 @@
<function name="clear" action="clear"/> <function name="clear" action="clear"/>
<function name="size" yields="size"/> <function name="size" yields="size"/>
<function name="empty" yields="empty"/> <function name="empty" yields="empty"/>
<function name="erase" action="erase"/>
<function name="insert" action="insert"/>
<function name="emplace" action="push"/>
<function name="swap" action="change"/>
<function name="assign" action="change"/>
</size> </size>
<access> <access>
<function name="begin" yields="start-iterator"/> <function name="begin" yields="start-iterator"/>
@ -3981,8 +3986,10 @@
<container id="stdVectorDeque" startPattern="std :: vector|deque &lt;" inherits="stdContainer" opLessAllowed="true"> <container id="stdVectorDeque" startPattern="std :: vector|deque &lt;" inherits="stdContainer" opLessAllowed="true">
<size> <size>
<function name="push_back" action="push"/> <function name="push_back" action="push"/>
<function name="emplace_back" action="push"/>
<function name="pop_back" action="pop"/> <function name="pop_back" action="pop"/>
<function name="push_front" action="push"/> <function name="push_front" action="push"/>
<function name="emplace_front" action="push"/>
<function name="pop_front" action="pop"/> <function name="pop_front" action="pop"/>
</size> </size>
<access indexOperator="array-like"> <access indexOperator="array-like">
@ -3990,15 +3997,20 @@
<function name="front" yields="item"/> <function name="front" yields="item"/>
<function name="back" yields="item"/> <function name="back" yields="item"/>
<function name="data" yields="buffer"/> <function name="data" yields="buffer"/>
<function name="shrink_to_fit" action="change-internal"/>
<function name="reserve" action="change-internal"/>
</access> </access>
</container> </container>
<container id="stdArray" startPattern="std :: array &lt;" inherits="stdContainer" opLessAllowed="true"> <container id="stdArray" startPattern="std :: array &lt;" inherits="stdContainer" opLessAllowed="true">
<size templateParameter="1"/> <size templateParameter="1">
<function name="max_size" yields="size"/>
</size>
<access indexOperator="array-like"> <access indexOperator="array-like">
<function name="at" yields="at_index"/> <function name="at" yields="at_index"/>
<function name="front" yields="item"/> <function name="front" yields="item"/>
<function name="back" yields="item"/> <function name="back" yields="item"/>
<function name="data" yields="buffer"/> <function name="data" yields="buffer"/>
<function name="fill" action="change-content"/>
</access> </access>
</container> </container>
<container id="stdBitset" startPattern="std :: bitset &lt;" inherits="stdContainer" itEndPattern=""> <container id="stdBitset" startPattern="std :: bitset &lt;" inherits="stdContainer" itEndPattern="">
@ -4006,41 +4018,78 @@
<access indexOperator="array-like" /> <access indexOperator="array-like" />
</container> </container>
<container id="stdQueue" startPattern="std :: queue|priority_queue &lt;" inherits="stdContainer"> <container id="stdQueue" startPattern="std :: queue|priority_queue &lt;" inherits="stdContainer">
<access>
<function name="push" action="push"/>
<function name="pop" action="pop"/>
<function name="front" yields="item"/>
<function name="back" yields="item"/>
</access>
</container> </container>
<container id="stdStack" startPattern="std :: stack &lt;" inherits="stdContainer"> <container id="stdStack" startPattern="std :: stack &lt;" inherits="stdContainer">
<access>
<function name="push" action="push"/>
<function name="pop" action="pop"/>
<function name="top" yields="item"/>
</access>
</container> </container>
<container id="stdSet" startPattern="std :: set|unoredered_set|multiset|unoredered_multiset &lt;" inherits="stdContainer"> <container id="stdSet" startPattern="std :: set|unoredered_set|multiset|unoredered_multiset &lt;" inherits="stdContainer">
<access> <access>
<function name="find" action="find"/> <function name="find" action="find" yields="iterator"/>
<function name="count" action="find"/>
<function name="emplace_hint" action="push"/>
<function name="rehash" action="change-internal"/>
<function name="lower_bound" yields="iterator"/>
<function name="upper_bound" yields="iterator"/>
</access> </access>
</container> </container>
<container id="stdMap" startPattern="std :: map|unordered_map|multimap|unordered_multimap &lt;" inherits="stdContainer"> <container id="stdMap" startPattern="std :: map|unordered_map|multimap|unordered_multimap &lt;" inherits="stdContainer">
<type templateParameter="1"/> <type templateParameter="1"/>
<access> <access>
<function name="at" yields="at_index"/> <function name="at" yields="at_index"/>
<function name="find" action="find"/> <function name="count" action="find"/>
<function name="find" action="find" yields="iterator"/>
<function name="emplace_hint" action="push"/>
<function name="rehash" action="change-internal"/>
<function name="lower_bound" yields="iterator"/>
<function name="upper_bound" yields="iterator"/>
</access> </access>
</container> </container>
<container id="stdList" startPattern="std :: list|forward_list &lt;" inherits="stdContainer"> <container id="stdList" startPattern="std :: list|forward_list &lt;" inherits="stdContainer">
<size> <size>
<function name="push_back" action="push"/> <function name="push_back" action="push"/>
<function name="emplace_back" action="push"/>
<function name="emplace_after" action="push"/>
<function name="pop_back" action="pop"/> <function name="pop_back" action="pop"/>
<function name="push_front" action="push"/> <function name="push_front" action="push"/>
<function name="emplace_front" action="push"/>
<function name="pop_front" action="pop"/> <function name="pop_front" action="pop"/>
<function name="erase_after" action="erase"/>
<function name="insert_after" action="insert"/>
<function name="remove" action="change"/>
<function name="remove_if" action="change"/>
<function name="unique" action="change"/>
<function name="merge" action="change"/>
<function name="splice" action="change"/>
<function name="splice_after" action="change"/>
</size> </size>
<access> <access>
<function name="front" yields="item"/> <function name="front" yields="item"/>
<function name="back" yields="item"/> <function name="back" yields="item"/>
<function name="before_begin" yields="iterator"/>
<function name="cbefore_begin" yields="iterator"/>
<function name="reverse" action="change-content"/>
<function name="sort" action="change-content"/>
</access> </access>
</container> </container>
<container id="stdComplex" startPattern="std :: complex &lt;" endPattern="&gt; !!::">
<type templateParameter="1"/>
</container>
<container id="stdAllString" inherits="stdContainer" opLessAllowed="true"> <container id="stdAllString" inherits="stdContainer" opLessAllowed="true">
<type string="std-like"/> <type string="std-like"/>
<size> <size>
<function name="push_back" action="push"/> <function name="push_back" action="push"/>
<function name="pop_back" action="pop"/> <function name="pop_back" action="pop"/>
<function name="append" action="change"/>
<function name="replace" action="change"/>
<function name="reserve" action="change-internal"/>
<function name="shrink_to_fit" action="change-internal"/>
</size> </size>
<access indexOperator="array-like"> <access indexOperator="array-like">
<function name="at" yields="at_index"/> <function name="at" yields="at_index"/>
@ -4050,6 +4099,11 @@
<function name="c_str" yields="buffer-nt"/> <function name="c_str" yields="buffer-nt"/>
<function name="length" yields="size"/> <function name="length" yields="size"/>
<function name="find" action="find"/> <function name="find" action="find"/>
<function name="rfind" action="find"/>
<function name="find_last_of" action="find"/>
<function name="find_last_not_of" action="find"/>
<function name="find_first_of" action="find"/>
<function name="find_first_not_of" action="find"/>
</access> </access>
</container> </container>
<container id="stdBasicString" startPattern="std :: basic_string &lt;" inherits="stdAllString"> <container id="stdBasicString" startPattern="std :: basic_string &lt;" inherits="stdAllString">

View File

@ -86,7 +86,7 @@ void CheckStl::iterators()
continue; continue;
Library::Container::Yield yield = container->getYield(containertok->strAt(2)); Library::Container::Yield yield = container->getYield(containertok->strAt(2));
if (yield != Library::Container::END_ITERATOR && yield != Library::Container::START_ITERATOR) if (yield != Library::Container::END_ITERATOR && yield != Library::Container::START_ITERATOR && yield != Library::Container::ITERATOR)
continue; continue;
} else } else
continue; continue;
@ -693,7 +693,7 @@ void CheckStl::if_find()
if (if_findCompare(funcTok->next())) if (if_findCompare(funcTok->next()))
continue; continue;
if (printWarning && !container->stdStringLike) if (printWarning && container->getYield(funcTok->str()) == Library::Container::ITERATOR)
if_findError(tok, false); if_findError(tok, false);
else if (printPerformance && container->stdStringLike) else if (printPerformance && container->stdStringLike)
if_findError(tok, true); if_findError(tok, true);
@ -1405,13 +1405,14 @@ void CheckStl::readingEmptyStlContainer_parseUsage(const Token* tok, const Libra
const Token* parent = tok->tokAt(3)->astParent(); const Token* parent = tok->tokAt(3)->astParent();
// Member function call // Member function call
if (yield != Library::Container::NO_YIELD && if (yield != Library::Container::NO_YIELD &&
((yield != Library::Container::START_ITERATOR && ((yield != Library::Container::ITERATOR &&
yield != Library::Container::START_ITERATOR &&
yield != Library::Container::END_ITERATOR) || !parent || Token::Match(parent, "%cop%|=|*"))) { // These functions read from the container yield != Library::Container::END_ITERATOR) || !parent || Token::Match(parent, "%cop%|=|*"))) { // These functions read from the container
if (!noerror) if (!noerror)
readingEmptyStlContainerError(tok); readingEmptyStlContainerError(tok);
} else { } else {
Library::Container::Action action = container->getAction(tok->strAt(2)); Library::Container::Action action = container->getAction(tok->strAt(2));
if (action == Library::Container::FIND) { if (action == Library::Container::FIND || action == Library::Container::ERASE || action == Library::Container::POP || action == Library::Container::CLEAR) {
if (!noerror) if (!noerror)
readingEmptyStlContainerError(tok); readingEmptyStlContainerError(tok);
} else } else

View File

@ -356,6 +356,16 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
action = Container::POP; action = Container::POP;
else if (actionName == "find") else if (actionName == "find")
action = Container::FIND; action = Container::FIND;
else if (actionName == "insert")
action = Container::INSERT;
else if (actionName == "erase")
action = Container::ERASE;
else if (actionName == "change-content")
action = Container::CHANGE_CONTENT;
else if (actionName == "change-internal")
action = Container::CHANGE_INTERNAL;
else if (actionName == "change")
action = Container::CHANGE;
else else
return Error(BAD_ATTRIBUTE_VALUE, actionName); return Error(BAD_ATTRIBUTE_VALUE, actionName);
} }
@ -376,6 +386,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
yield = Container::START_ITERATOR; yield = Container::START_ITERATOR;
else if (yieldName == "end-iterator") else if (yieldName == "end-iterator")
yield = Container::END_ITERATOR; yield = Container::END_ITERATOR;
else if (yieldName == "iterator")
yield = Container::ITERATOR;
else if (yieldName == "size") else if (yieldName == "size")
yield = Container::SIZE; yield = Container::SIZE;
else if (yieldName == "empty") else if (yieldName == "empty")

View File

@ -142,11 +142,11 @@ public:
} }
enum Action { enum Action {
RESIZE, CLEAR, PUSH, POP, FIND, RESIZE, CLEAR, PUSH, POP, FIND, INSERT, ERASE, CHANGE_CONTENT, CHANGE, CHANGE_INTERNAL,
NO_ACTION NO_ACTION
}; };
enum Yield { enum Yield {
AT_INDEX, ITEM, BUFFER, BUFFER_NT, START_ITERATOR, END_ITERATOR, SIZE, EMPTY, AT_INDEX, ITEM, BUFFER, BUFFER_NT, START_ITERATOR, END_ITERATOR, ITERATOR, SIZE, EMPTY,
NO_YIELD NO_YIELD
}; };
struct Function { struct Function {