Library: Added <smart-pointer> element
This commit is contained in:
parent
b59d7e2f35
commit
2513c1499b
|
@ -393,6 +393,10 @@
|
||||||
</zeroOrMore>
|
</zeroOrMore>
|
||||||
</element>
|
</element>
|
||||||
|
|
||||||
|
<element name="smart-pointer">
|
||||||
|
<attribute name="class-name"><ref name="DATA-EXTNAME"/></attribute>
|
||||||
|
</element>
|
||||||
|
|
||||||
<element name="podtype">
|
<element name="podtype">
|
||||||
<attribute name="name"><ref name="DATA-EXTNAME"/></attribute>
|
<attribute name="name"><ref name="DATA-EXTNAME"/></attribute>
|
||||||
<optional>
|
<optional>
|
||||||
|
|
|
@ -7470,6 +7470,8 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
|
||||||
<type templateParameter="0"/>
|
<type templateParameter="0"/>
|
||||||
</container>
|
</container>
|
||||||
<container id="stdString" startPattern="std :: string|wstring|u16string|u32string" endPattern="" inherits="stdAllString"/>
|
<container id="stdString" startPattern="std :: string|wstring|u16string|u32string" endPattern="" inherits="stdAllString"/>
|
||||||
|
<smart-pointer class-name="std::shared_ptr"/>
|
||||||
|
<smart-pointer class-name="std::unique_ptr"/>
|
||||||
<podtype name="char16_t,std::char16_t" sign="u" size="2"/>
|
<podtype name="char16_t,std::char16_t" sign="u" size="2"/>
|
||||||
<podtype name="char32_t,std::char32_t" sign="u" size="4"/>
|
<podtype name="char32_t,std::char32_t" sign="u" size="4"/>
|
||||||
<podtype name="int8_t,std::int8_t" sign="s" size="1"/>
|
<podtype name="int8_t,std::int8_t" sign="s" size="1"/>
|
||||||
|
|
|
@ -1837,8 +1837,8 @@ void CheckClass::checkConst()
|
||||||
const std::string& opName = func.tokenDef->str();
|
const std::string& opName = func.tokenDef->str();
|
||||||
if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
|
if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*')))
|
||||||
continue;
|
continue;
|
||||||
} else if (Token::simpleMatch(func.retDef, "std :: shared_ptr <")) {
|
} else if (mSettings->library.isSmartPointer(func.retDef)) {
|
||||||
// Don't warn if a std::shared_ptr is returned
|
// Don't warn if a std::shared_ptr etc is returned
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// don't warn for unknown types..
|
// don't warn for unknown types..
|
||||||
|
|
|
@ -488,6 +488,12 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (nodename == "smart-pointer") {
|
||||||
|
const char *className = node->Attribute("class-name");
|
||||||
|
if (className)
|
||||||
|
smartPointers.insert(className);
|
||||||
|
}
|
||||||
|
|
||||||
else if (nodename == "podtype") {
|
else if (nodename == "podtype") {
|
||||||
const char * const name = node->Attribute("name");
|
const char * const name = node->Attribute("name");
|
||||||
if (!name)
|
if (!name)
|
||||||
|
@ -1302,3 +1308,14 @@ bool Library::isimporter(const std::string& file, const std::string &importer) c
|
||||||
mImporters.find(Path::getFilenameExtensionInLowerCase(file));
|
mImporters.find(Path::getFilenameExtensionInLowerCase(file));
|
||||||
return (it != mImporters.end() && it->second.count(importer) > 0);
|
return (it != mImporters.end() && it->second.count(importer) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Library::isSmartPointer(const Token *tok) const
|
||||||
|
{
|
||||||
|
std::string typestr;
|
||||||
|
while (Token::Match(tok, "%name%|::")) {
|
||||||
|
typestr += tok->str();
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
return smartPointers.find(typestr) != smartPointers.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -390,6 +390,9 @@ public:
|
||||||
std::set<std::string> returnuninitdata;
|
std::set<std::string> returnuninitdata;
|
||||||
std::vector<std::string> defines; // to provide some library defines
|
std::vector<std::string> defines; // to provide some library defines
|
||||||
|
|
||||||
|
std::set<std::string> smartPointers;
|
||||||
|
bool isSmartPointer(const Token *tok) const;
|
||||||
|
|
||||||
struct PodType {
|
struct PodType {
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
char sign;
|
char sign;
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
" <alloc init=\"false\">malloc</alloc>\n"
|
" <alloc init=\"false\">malloc</alloc>\n"
|
||||||
" <dealloc>free</dealloc>\n"
|
" <dealloc>free</dealloc>\n"
|
||||||
" </memory>\n"
|
" </memory>\n"
|
||||||
|
" <smart-pointer class-name=\"std::shared_ptr\"/>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
doc.Parse(xmldata, sizeof(xmldata));
|
||||||
|
|
Loading…
Reference in New Issue