Library: Refactoring of markup code
This commit is contained in:
parent
07948677f8
commit
4769838b80
|
@ -153,7 +153,7 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
const char * const extension = functionnode->Attribute("extension");
|
const char * const extension = functionnode->Attribute("extension");
|
||||||
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
||||||
if (strcmp(librarynode->Name(), "keyword") == 0) {
|
if (strcmp(librarynode->Name(), "keyword") == 0) {
|
||||||
_keywords[extension].push_back(librarynode->Attribute("name"));
|
_keywords[extension].insert(librarynode->Attribute("name"));
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
const char * const extension = functionnode->Attribute("extension");
|
const char * const extension = functionnode->Attribute("extension");
|
||||||
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
for (const tinyxml2::XMLElement *librarynode = functionnode->FirstChildElement(); librarynode; librarynode = librarynode->NextSiblingElement()) {
|
||||||
if (strcmp(librarynode->Name(), "importer") == 0) {
|
if (strcmp(librarynode->Name(), "importer") == 0) {
|
||||||
_importers[extension].push_back(librarynode->Attribute("name"));
|
_importers[extension].insert(librarynode->Attribute("name"));
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,13 +134,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reportErrors(const std::string &path) const {
|
bool reportErrors(const std::string &path) const {
|
||||||
const std::map<std::string, bool>::const_iterator it =
|
const std::map<std::string, bool>::const_iterator it = _reporterrors.find(Path::getFilenameExtensionInLowerCase(path));
|
||||||
_reporterrors.find(Path::getFilenameExtensionInLowerCase(path));
|
return (it == _reporterrors.end() || it->second);
|
||||||
if (it != _reporterrors.end()) {
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
// assume true if we don't know as it'll be a core-type (c/cpp etc)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ignorefunction(const std::string &function) const {
|
bool ignorefunction(const std::string &function) const {
|
||||||
|
@ -149,16 +144,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isexecutableblock(const std::string &file, const std::string &token) const {
|
bool isexecutableblock(const std::string &file, const std::string &token) const {
|
||||||
bool isexecblock;
|
const std::map<std::string, CodeBlock>::const_iterator it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
||||||
const std::map<std::string, CodeBlock>::const_iterator map_it
|
return (it != _executableblocks.end() && it->second.isBlock(token));
|
||||||
= _executableblocks.find(Path::getFilenameExtensionInLowerCase(file));
|
|
||||||
|
|
||||||
if (map_it != _executableblocks.end()) {
|
|
||||||
isexecblock = map_it->second.isBlock(token);
|
|
||||||
} else {
|
|
||||||
isexecblock = false;
|
|
||||||
}
|
|
||||||
return isexecblock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockstartoffset(const std::string &file) const {
|
int blockstartoffset(const std::string &file) const {
|
||||||
|
@ -195,71 +182,35 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool iskeyword(const std::string &file, const std::string &keyword) const {
|
bool iskeyword(const std::string &file, const std::string &keyword) const {
|
||||||
bool iskw;
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
||||||
const std::map<std::string, std::list<std::string> >::const_iterator it =
|
|
||||||
_keywords.find(Path::getFilenameExtensionInLowerCase(file));
|
_keywords.find(Path::getFilenameExtensionInLowerCase(file));
|
||||||
|
return (it != _keywords.end() && it->second.count(keyword));
|
||||||
if (it != _keywords.end()) {
|
|
||||||
const std::list<std::string> list = it->second;
|
|
||||||
const std::list<std::string>::const_iterator list_it =
|
|
||||||
std::find(list.begin(), list.end(), keyword);
|
|
||||||
iskw = list_it != list.end();
|
|
||||||
} else {
|
|
||||||
iskw = false;
|
|
||||||
}
|
|
||||||
return iskw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isexporter(const std::string &prefix) const {
|
bool isexporter(const std::string &prefix) const {
|
||||||
const std::map<std::string, ExportedFunctions>::const_iterator it =
|
return _exporters.find(prefix) != _exporters.end();
|
||||||
_exporters.find(prefix);
|
|
||||||
return it != _exporters.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isexportedprefix(const std::string &prefix, const std::string &token) const {
|
bool isexportedprefix(const std::string &prefix, const std::string &token) const {
|
||||||
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
||||||
if (it != _exporters.end()) {
|
return (it != _exporters.end() && it->second.isPrefix(token));
|
||||||
return it->second.isPrefix(token);
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isexportedsuffix(const std::string &prefix, const std::string &token) const {
|
bool isexportedsuffix(const std::string &prefix, const std::string &token) const {
|
||||||
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
const std::map<std::string, ExportedFunctions>::const_iterator it = _exporters.find(prefix);
|
||||||
if (it != _exporters.end()) {
|
return (it != _exporters.end() && it->second.isSuffix(token));
|
||||||
return it->second.isSuffix(token);
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isimporter(const std::string& file, const std::string &importer) const {
|
bool isimporter(const std::string& file, const std::string &importer) const {
|
||||||
bool isImporter;
|
const std::map<std::string, std::set<std::string> >::const_iterator it =
|
||||||
const std::map<std::string, std::list<std::string> >::const_iterator it =
|
|
||||||
_importers.find(Path::getFilenameExtensionInLowerCase(file));
|
_importers.find(Path::getFilenameExtensionInLowerCase(file));
|
||||||
|
return (it != _importers.end() && it->second.count(importer) > 0);
|
||||||
if (it != _importers.end()) {
|
|
||||||
const std::list<std::string> list = it->second;
|
|
||||||
const std::list<std::string>::const_iterator it2 =
|
|
||||||
std::find(list.begin(), list.end(), importer);
|
|
||||||
isImporter = (it2 != list.end());
|
|
||||||
} else {
|
|
||||||
isImporter = false;
|
|
||||||
}
|
|
||||||
return isImporter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isreflection(const std::string& file, const std::string &token) const {
|
bool isreflection(const std::string& file, const std::string &token) const {
|
||||||
bool isReflecMethod;
|
|
||||||
const std::map<std::string,std::map<std::string,int> >::const_iterator it
|
const std::map<std::string,std::map<std::string,int> >::const_iterator it
|
||||||
= _reflection.find(Path::getFilenameExtensionInLowerCase(file));
|
= _reflection.find(Path::getFilenameExtensionInLowerCase(file));
|
||||||
if (it != _reflection.end()) {
|
return (it != _reflection.end() && it->second.count(token));
|
||||||
const std::map<std::string,int>::const_iterator it2 =
|
|
||||||
it->second.find(token);
|
|
||||||
isReflecMethod = it2 != it->second.end();
|
|
||||||
} else {
|
|
||||||
isReflecMethod = false;
|
|
||||||
}
|
|
||||||
return isReflecMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int reflectionArgument(const std::string& file, const std::string &token) const {
|
int reflectionArgument(const std::string& file, const std::string &token) const {
|
||||||
|
@ -282,23 +233,21 @@ private:
|
||||||
class ExportedFunctions {
|
class ExportedFunctions {
|
||||||
public:
|
public:
|
||||||
void addPrefix(const std::string& prefix) {
|
void addPrefix(const std::string& prefix) {
|
||||||
_prefixes.push_back(prefix);
|
_prefixes.insert(prefix);
|
||||||
}
|
}
|
||||||
void addSuffix(const std::string& suffix) {
|
void addSuffix(const std::string& suffix) {
|
||||||
_suffixes.push_back(suffix);
|
_suffixes.insert(suffix);
|
||||||
}
|
}
|
||||||
bool isPrefix(const std::string& prefix) const {
|
bool isPrefix(const std::string& prefix) const {
|
||||||
return std::find(_prefixes.begin(), _prefixes.end(), prefix)
|
return (_prefixes.find(prefix) != _prefixes.end());
|
||||||
!= _prefixes.end();
|
|
||||||
}
|
}
|
||||||
bool isSuffix(const std::string& suffix) const {
|
bool isSuffix(const std::string& suffix) const {
|
||||||
return std::find(_suffixes.begin(), _suffixes.end(), suffix)
|
return (_suffixes.find(suffix) != _suffixes.end());
|
||||||
!= _suffixes.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::string> _prefixes;
|
std::set<std::string> _prefixes;
|
||||||
std::list<std::string> _suffixes;
|
std::set<std::string> _suffixes;
|
||||||
};
|
};
|
||||||
class CodeBlock {
|
class CodeBlock {
|
||||||
public:
|
public:
|
||||||
|
@ -342,10 +291,10 @@ private:
|
||||||
std::map<std::string, bool> _ignorefunction; // ignore functions/macros from a library (gtk, qt etc)
|
std::map<std::string, bool> _ignorefunction; // ignore functions/macros from a library (gtk, qt etc)
|
||||||
std::map<std::string, bool> _reporterrors;
|
std::map<std::string, bool> _reporterrors;
|
||||||
std::set<std::string> _markupExtensions; // file extensions of markup files
|
std::set<std::string> _markupExtensions; // file extensions of markup files
|
||||||
std::map<std::string, std::list<std::string> > _keywords; // keywords for code in the library
|
std::map<std::string, std::set<std::string> > _keywords; // keywords for code in the library
|
||||||
std::map<std::string, CodeBlock> _executableblocks; // keywords for blocks of executable code
|
std::map<std::string, CodeBlock> _executableblocks; // keywords for blocks of executable code
|
||||||
std::map<std::string, ExportedFunctions> _exporters; // keywords that export variables/functions to libraries (meta-code/macros)
|
std::map<std::string, ExportedFunctions> _exporters; // keywords that export variables/functions to libraries (meta-code/macros)
|
||||||
std::map<std::string, std::list<std::string> > _importers; // keywords that import variables/functions
|
std::map<std::string, std::set<std::string> > _importers; // keywords that import variables/functions
|
||||||
std::map<std::string,std::map<std::string,int> > _reflection; // invocation of reflection
|
std::map<std::string,std::map<std::string,int> > _reflection; // invocation of reflection
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue