Remove unused function Preprocessor::preprocessCleanupDirectives()
This commit is contained in:
parent
2e2800f5bd
commit
48fc19b34c
|
@ -282,86 +282,6 @@ std::set<std::string> Preprocessor::getConfigs(const simplecpp::TokenList &token
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string Preprocessor::preprocessCleanupDirectives(const std::string &processedFile)
|
||||
{
|
||||
std::ostringstream code;
|
||||
std::istringstream sstr(processedFile);
|
||||
|
||||
std::string line;
|
||||
while (std::getline(sstr, line)) {
|
||||
// Trim lines..
|
||||
if (!line.empty() && line[0] == ' ')
|
||||
line.erase(0, line.find_first_not_of(" "));
|
||||
if (!line.empty() && line.back() == ' ')
|
||||
line.erase(line.find_last_not_of(" ") + 1);
|
||||
|
||||
// Preprocessor
|
||||
if (!line.empty() && line[0] == '#') {
|
||||
enum {
|
||||
ESC_NONE,
|
||||
ESC_SINGLE,
|
||||
ESC_DOUBLE
|
||||
} escapeStatus = ESC_NONE;
|
||||
|
||||
char prev = ' '; // hack to make it skip spaces between # and the directive
|
||||
code << "#";
|
||||
std::string::const_iterator i = line.begin();
|
||||
++i;
|
||||
|
||||
// need space.. #if( => #if (
|
||||
bool needSpace = true;
|
||||
while (i != line.end()) {
|
||||
// disable esc-mode
|
||||
if (escapeStatus != ESC_NONE) {
|
||||
if (prev != '\\' && escapeStatus == ESC_SINGLE && *i == '\'') {
|
||||
escapeStatus = ESC_NONE;
|
||||
}
|
||||
if (prev != '\\' && escapeStatus == ESC_DOUBLE && *i == '"') {
|
||||
escapeStatus = ESC_NONE;
|
||||
}
|
||||
} else {
|
||||
// enable esc-mode
|
||||
if (escapeStatus == ESC_NONE && *i == '"')
|
||||
escapeStatus = ESC_DOUBLE;
|
||||
if (escapeStatus == ESC_NONE && *i == '\'')
|
||||
escapeStatus = ESC_SINGLE;
|
||||
}
|
||||
// skip double whitespace between arguments
|
||||
if (escapeStatus == ESC_NONE && prev == ' ' && *i == ' ') {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
// Convert #if( to "#if ("
|
||||
if (escapeStatus == ESC_NONE) {
|
||||
if (needSpace) {
|
||||
if (*i == '(' || *i == '!')
|
||||
code << " ";
|
||||
else if (!std::isalpha((unsigned char)*i))
|
||||
needSpace = false;
|
||||
}
|
||||
if (*i == '#')
|
||||
needSpace = true;
|
||||
}
|
||||
code << *i;
|
||||
if (escapeStatus != ESC_NONE && prev == '\\' && *i == '\\') {
|
||||
prev = ' ';
|
||||
} else {
|
||||
prev = *i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (escapeStatus != ESC_NONE) {
|
||||
// unmatched quotes.. compiler should probably complain about this..
|
||||
}
|
||||
} else {
|
||||
// Do not mess with regular code..
|
||||
code << line;
|
||||
}
|
||||
code << (sstr.eof()?"":"\n");
|
||||
}
|
||||
|
||||
return code.str();
|
||||
}
|
||||
|
||||
void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::string> &result, const std::string &filename, const std::list<std::string> &includePaths)
|
||||
{
|
||||
|
|
|
@ -168,12 +168,6 @@ public:
|
|||
*/
|
||||
static std::string removeParentheses(const std::string &str);
|
||||
|
||||
/**
|
||||
* clean up #-preprocessor lines (only)
|
||||
* @param processedFile The data to be processed
|
||||
*/
|
||||
static std::string preprocessCleanupDirectives(const std::string &processedFile);
|
||||
|
||||
/**
|
||||
* Returns the string between double quote characters or \< \> characters.
|
||||
* @param str e.g. \code#include "menu.h"\endcode or \code#include <menu.h>\endcode
|
||||
|
|
Loading…
Reference in New Issue