Bump simplecpp
This commit is contained in:
parent
090a178ed6
commit
3d860e6f36
|
@ -112,7 +112,7 @@ static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
|
||||||
static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string &alt)
|
static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string &alt)
|
||||||
{
|
{
|
||||||
return (tok->name &&
|
return (tok->name &&
|
||||||
tok->str == alt &&
|
tok->str() == alt &&
|
||||||
tok->previous &&
|
tok->previous &&
|
||||||
tok->next &&
|
tok->next &&
|
||||||
(tok->previous->number || tok->previous->name || tok->previous->op == ')') &&
|
(tok->previous->number || tok->previous->name || tok->previous->op == ')') &&
|
||||||
|
@ -121,11 +121,14 @@ static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string
|
||||||
|
|
||||||
static bool isAlternativeUnaryOp(const simplecpp::Token *tok, const std::string &alt)
|
static bool isAlternativeUnaryOp(const simplecpp::Token *tok, const std::string &alt)
|
||||||
{
|
{
|
||||||
return ((tok->name && tok->str == alt) &&
|
return ((tok->name && tok->str() == alt) &&
|
||||||
(!tok->previous || tok->previous->op == '(') &&
|
(!tok->previous || tok->previous->op == '(') &&
|
||||||
(tok->next && (tok->next->name || tok->next->number)));
|
(tok->next && (tok->next->name || tok->next->number)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::string simplecpp::Location::emptyFileName;
|
||||||
|
|
||||||
void simplecpp::Location::adjust(const std::string &str)
|
void simplecpp::Location::adjust(const std::string &str)
|
||||||
{
|
{
|
||||||
if (str.find_first_of("\r\n") == std::string::npos) {
|
if (str.find_first_of("\r\n") == std::string::npos) {
|
||||||
|
@ -151,12 +154,12 @@ bool simplecpp::Token::isOneOf(const char ops[]) const
|
||||||
|
|
||||||
bool simplecpp::Token::startsWithOneOf(const char c[]) const
|
bool simplecpp::Token::startsWithOneOf(const char c[]) const
|
||||||
{
|
{
|
||||||
return std::strchr(c, str[0]) != 0;
|
return std::strchr(c, string[0]) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simplecpp::Token::endsWithOneOf(const char c[]) const
|
bool simplecpp::Token::endsWithOneOf(const char c[]) const
|
||||||
{
|
{
|
||||||
return std::strchr(c, str[str.size() - 1U]) != 0;
|
return std::strchr(c, string[string.size() - 1U]) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplecpp::Token::printAll() const
|
void simplecpp::Token::printAll() const
|
||||||
|
@ -168,7 +171,7 @@ void simplecpp::Token::printAll() const
|
||||||
if (tok->previous) {
|
if (tok->previous) {
|
||||||
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
|
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
|
||||||
}
|
}
|
||||||
std::cout << tok->str;
|
std::cout << tok->str();
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +182,7 @@ void simplecpp::Token::printOut() const
|
||||||
if (tok != this) {
|
if (tok != this) {
|
||||||
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
|
std::cout << (sameline(tok, tok->previous) ? ' ' : '\n');
|
||||||
}
|
}
|
||||||
std::cout << tok->str;
|
std::cout << tok->str();
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -257,9 +260,9 @@ std::string simplecpp::TokenList::stringify() const
|
||||||
if (sameline(tok->previous, tok))
|
if (sameline(tok->previous, tok))
|
||||||
ret << ' ';
|
ret << ' ';
|
||||||
|
|
||||||
ret << tok->str;
|
ret << tok->str();
|
||||||
|
|
||||||
loc.adjust(tok->str);
|
loc.adjust(tok->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret.str();
|
return ret.str();
|
||||||
|
@ -439,15 +442,15 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
|
||||||
|
|
||||||
if (lastline == "# file %str%") {
|
if (lastline == "# file %str%") {
|
||||||
loc.push(location);
|
loc.push(location);
|
||||||
location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U));
|
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
|
||||||
location.line = 1U;
|
location.line = 1U;
|
||||||
} else if (lastline == "# line %num%") {
|
} else if (lastline == "# line %num%") {
|
||||||
loc.push(location);
|
loc.push(location);
|
||||||
location.line = std::atol(cback()->str.c_str());
|
location.line = std::atol(cback()->str().c_str());
|
||||||
} else if (lastline == "# line %num% %str%") {
|
} else if (lastline == "# line %num% %str%") {
|
||||||
loc.push(location);
|
loc.push(location);
|
||||||
location.fileIndex = fileIndex(cback()->str.substr(1U, cback()->str.size() - 2U));
|
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
|
||||||
location.line = std::atol(cback()->previous->str.c_str());
|
location.line = std::atol(cback()->previous->str().c_str());
|
||||||
}
|
}
|
||||||
// #endfile
|
// #endfile
|
||||||
else if (lastline == "# endfile" && !loc.empty()) {
|
else if (lastline == "# endfile" && !loc.empty()) {
|
||||||
|
@ -536,7 +539,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
|
||||||
// string / char literal
|
// string / char literal
|
||||||
else if (ch == '\"' || ch == '\'') {
|
else if (ch == '\"' || ch == '\'') {
|
||||||
// C++11 raw string literal
|
// C++11 raw string literal
|
||||||
if (ch == '\"' && cback() && cback()->name && isRawStringId(cback()->str)) {
|
if (ch == '\"' && cback() && cback()->name && isRawStringId(cback()->str())) {
|
||||||
std::string delim;
|
std::string delim;
|
||||||
ch = readChar(istr,bom);
|
ch = readChar(istr,bom);
|
||||||
while (istr.good() && ch != '(' && ch != '\n') {
|
while (istr.good() && ch != '(' && ch != '\n') {
|
||||||
|
@ -557,7 +560,7 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
|
||||||
if (cback()->op == 'R')
|
if (cback()->op == 'R')
|
||||||
back()->setstr(escapeString(currentToken));
|
back()->setstr(escapeString(currentToken));
|
||||||
else {
|
else {
|
||||||
back()->setstr(cback()->str.substr(0, cback()->str.size() - 1));
|
back()->setstr(cback()->str().substr(0, cback()->str().size() - 1));
|
||||||
push_back(new Token(currentToken, location)); // push string without newlines
|
push_back(new Token(currentToken, location)); // push string without newlines
|
||||||
}
|
}
|
||||||
location.adjust(currentToken);
|
location.adjust(currentToken);
|
||||||
|
@ -650,9 +653,9 @@ void simplecpp::TokenList::constFold()
|
||||||
|
|
||||||
static bool isFloatSuffix(const simplecpp::Token *tok)
|
static bool isFloatSuffix(const simplecpp::Token *tok)
|
||||||
{
|
{
|
||||||
if (!tok || tok->str.size() != 1U)
|
if (!tok || tok->str().size() != 1U)
|
||||||
return false;
|
return false;
|
||||||
const char c = std::tolower(tok->str[0]);
|
const char c = std::tolower(tok->str()[0]);
|
||||||
return c == 'f' || c == 'l';
|
return c == 'f' || c == 'l';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,22 +688,22 @@ void simplecpp::TokenList::combineOperators()
|
||||||
continue;
|
continue;
|
||||||
// float literals..
|
// float literals..
|
||||||
if (tok->previous && tok->previous->number) {
|
if (tok->previous && tok->previous->number) {
|
||||||
tok->setstr(tok->previous->str + '.');
|
tok->setstr(tok->previous->str() + '.');
|
||||||
deleteToken(tok->previous);
|
deleteToken(tok->previous);
|
||||||
if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("Ee"))) {
|
if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("Ee"))) {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tok->next && tok->next->number) {
|
if (tok->next && tok->next->number) {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// match: [0-9.]+E [+-] [0-9]+
|
// match: [0-9.]+E [+-] [0-9]+
|
||||||
const char lastChar = tok->str[tok->str.size() - 1];
|
const char lastChar = tok->str()[tok->str().size() - 1];
|
||||||
if (tok->number && !isHex(tok->str) && (lastChar == 'E' || lastChar == 'e') && tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) {
|
if (tok->number && !isHex(tok->str()) && (lastChar == 'E' || lastChar == 'e') && tok->next && tok->next->isOneOf("+-") && tok->next->next && tok->next->next->number) {
|
||||||
tok->setstr(tok->str + tok->next->op + tok->next->next->str);
|
tok->setstr(tok->str() + tok->next->op + tok->next->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
}
|
}
|
||||||
|
@ -731,7 +734,7 @@ void simplecpp::TokenList::combineOperators()
|
||||||
const Token *ftok = start;
|
const Token *ftok = start;
|
||||||
bool isFuncDecl = ftok->name;
|
bool isFuncDecl = ftok->name;
|
||||||
while (isFuncDecl) {
|
while (isFuncDecl) {
|
||||||
if (!start->name && start->str != "::" && start->op != '*' && start->op != '&')
|
if (!start->name && start->str() != "::" && start->op != '*' && start->op != '&')
|
||||||
isFuncDecl = false;
|
isFuncDecl = false;
|
||||||
if (!start->previous)
|
if (!start->previous)
|
||||||
break;
|
break;
|
||||||
|
@ -746,22 +749,22 @@ void simplecpp::TokenList::combineOperators()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tok->setstr(tok->str + "=");
|
tok->setstr(tok->str() + "=");
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else if ((tok->op == '|' || tok->op == '&') && tok->op == tok->next->op) {
|
} else if ((tok->op == '|' || tok->op == '&') && tok->op == tok->next->op) {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else if (tok->op == ':' && tok->next->op == ':') {
|
} else if (tok->op == ':' && tok->next->op == ':') {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else if (tok->op == '-' && tok->next->op == '>') {
|
} else if (tok->op == '-' && tok->next->op == '>') {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else if ((tok->op == '<' || tok->op == '>') && tok->op == tok->next->op) {
|
} else if ((tok->op == '<' || tok->op == '>') && tok->op == tok->next->op) {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
if (tok->next && tok->next->op == '=') {
|
if (tok->next && tok->next->op == '=') {
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
}
|
}
|
||||||
} else if ((tok->op == '+' || tok->op == '-') && tok->op == tok->next->op) {
|
} else if ((tok->op == '+' || tok->op == '-') && tok->op == tok->next->op) {
|
||||||
|
@ -771,7 +774,7 @@ void simplecpp::TokenList::combineOperators()
|
||||||
continue;
|
continue;
|
||||||
if (tok->next->next && tok->next->next->number)
|
if (tok->next->next && tok->next->next->number)
|
||||||
continue;
|
continue;
|
||||||
tok->setstr(tok->str + tok->next->str);
|
tok->setstr(tok->str() + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -790,10 +793,10 @@ void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
|
||||||
tok->op = '~';
|
tok->op = '~';
|
||||||
|
|
||||||
if (tok->op == '!' && tok->next && tok->next->number) {
|
if (tok->op == '!' && tok->next && tok->next->number) {
|
||||||
tok->setstr(tok->next->str == "0" ? "1" : "0");
|
tok->setstr(tok->next->str() == "0" ? "1" : "0");
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else if (tok->op == '~' && tok->next && tok->next->number) {
|
} else if (tok->op == '~' && tok->next && tok->next->number) {
|
||||||
tok->setstr(toString(~stringToLL(tok->next->str)));
|
tok->setstr(toString(~stringToLL(tok->next->str())));
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
} else {
|
} else {
|
||||||
if (tok->previous && (tok->previous->number || tok->previous->name))
|
if (tok->previous && (tok->previous->number || tok->previous->name))
|
||||||
|
@ -802,11 +805,11 @@ void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
|
||||||
continue;
|
continue;
|
||||||
switch (tok->op) {
|
switch (tok->op) {
|
||||||
case '+':
|
case '+':
|
||||||
tok->setstr(tok->next->str);
|
tok->setstr(tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
tok->setstr(tok->op + tok->next->str);
|
tok->setstr(tok->op + tok->next->str());
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -824,12 +827,12 @@ void simplecpp::TokenList::constFoldMulDivRem(Token *tok)
|
||||||
|
|
||||||
long long result;
|
long long result;
|
||||||
if (tok->op == '*')
|
if (tok->op == '*')
|
||||||
result = (stringToLL(tok->previous->str) * stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) * stringToLL(tok->next->str()));
|
||||||
else if (tok->op == '/' || tok->op == '%') {
|
else if (tok->op == '/' || tok->op == '%') {
|
||||||
long long rhs = stringToLL(tok->next->str);
|
long long rhs = stringToLL(tok->next->str());
|
||||||
if (rhs == 0)
|
if (rhs == 0)
|
||||||
throw std::overflow_error("division/modulo by zero");
|
throw std::overflow_error("division/modulo by zero");
|
||||||
long long lhs = stringToLL(tok->previous->str);
|
long long lhs = stringToLL(tok->previous->str());
|
||||||
if (rhs == -1 && lhs == std::numeric_limits<long long>::min())
|
if (rhs == -1 && lhs == std::numeric_limits<long long>::min())
|
||||||
throw std::overflow_error("division overflow");
|
throw std::overflow_error("division overflow");
|
||||||
if (tok->op == '/')
|
if (tok->op == '/')
|
||||||
|
@ -856,9 +859,9 @@ void simplecpp::TokenList::constFoldAddSub(Token *tok)
|
||||||
|
|
||||||
long long result;
|
long long result;
|
||||||
if (tok->op == '+')
|
if (tok->op == '+')
|
||||||
result = stringToLL(tok->previous->str) + stringToLL(tok->next->str);
|
result = stringToLL(tok->previous->str()) + stringToLL(tok->next->str());
|
||||||
else if (tok->op == '-')
|
else if (tok->op == '-')
|
||||||
result = stringToLL(tok->previous->str) - stringToLL(tok->next->str);
|
result = stringToLL(tok->previous->str()) - stringToLL(tok->next->str());
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -878,10 +881,10 @@ void simplecpp::TokenList::constFoldShift(Token *tok)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
long long result;
|
long long result;
|
||||||
if (tok->str == "<<")
|
if (tok->str() == "<<")
|
||||||
result = stringToLL(tok->previous->str) << stringToLL(tok->next->str);
|
result = stringToLL(tok->previous->str()) << stringToLL(tok->next->str());
|
||||||
else if (tok->str == ">>")
|
else if (tok->str() == ">>")
|
||||||
result = stringToLL(tok->previous->str) >> stringToLL(tok->next->str);
|
result = stringToLL(tok->previous->str()) >> stringToLL(tok->next->str());
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -907,18 +910,18 @@ void simplecpp::TokenList::constFoldComparison(Token *tok)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
if (tok->str == "==")
|
if (tok->str() == "==")
|
||||||
result = (stringToLL(tok->previous->str) == stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) == stringToLL(tok->next->str()));
|
||||||
else if (tok->str == "!=")
|
else if (tok->str() == "!=")
|
||||||
result = (stringToLL(tok->previous->str) != stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) != stringToLL(tok->next->str()));
|
||||||
else if (tok->str == ">")
|
else if (tok->str() == ">")
|
||||||
result = (stringToLL(tok->previous->str) > stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) > stringToLL(tok->next->str()));
|
||||||
else if (tok->str == ">=")
|
else if (tok->str() == ">=")
|
||||||
result = (stringToLL(tok->previous->str) >= stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) >= stringToLL(tok->next->str()));
|
||||||
else if (tok->str == "<")
|
else if (tok->str() == "<")
|
||||||
result = (stringToLL(tok->previous->str) < stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) < stringToLL(tok->next->str()));
|
||||||
else if (tok->str == "<=")
|
else if (tok->str() == "<=")
|
||||||
result = (stringToLL(tok->previous->str) <= stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) <= stringToLL(tok->next->str()));
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -952,11 +955,11 @@ void simplecpp::TokenList::constFoldBitwise(Token *tok)
|
||||||
continue;
|
continue;
|
||||||
long long result;
|
long long result;
|
||||||
if (*op == '&')
|
if (*op == '&')
|
||||||
result = (stringToLL(tok->previous->str) & stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) & stringToLL(tok->next->str()));
|
||||||
else if (*op == '^')
|
else if (*op == '^')
|
||||||
result = (stringToLL(tok->previous->str) ^ stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) ^ stringToLL(tok->next->str()));
|
||||||
else /*if (*op == '|')*/
|
else /*if (*op == '|')*/
|
||||||
result = (stringToLL(tok->previous->str) | stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) | stringToLL(tok->next->str()));
|
||||||
tok = tok->previous;
|
tok = tok->previous;
|
||||||
tok->setstr(toString(result));
|
tok->setstr(toString(result));
|
||||||
deleteToken(tok->next);
|
deleteToken(tok->next);
|
||||||
|
@ -976,7 +979,7 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
|
||||||
else if (isAlternativeBinaryOp(tok,OR))
|
else if (isAlternativeBinaryOp(tok,OR))
|
||||||
tok->setstr("||");
|
tok->setstr("||");
|
||||||
}
|
}
|
||||||
if (tok->str != "&&" && tok->str != "||")
|
if (tok->str() != "&&" && tok->str() != "||")
|
||||||
continue;
|
continue;
|
||||||
if (!tok->previous || !tok->previous->number)
|
if (!tok->previous || !tok->previous->number)
|
||||||
continue;
|
continue;
|
||||||
|
@ -984,10 +987,10 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
if (tok->str == "||")
|
if (tok->str() == "||")
|
||||||
result = (stringToLL(tok->previous->str) || stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) || stringToLL(tok->next->str()));
|
||||||
else /*if (tok->str == "&&")*/
|
else /*if (tok->str() == "&&")*/
|
||||||
result = (stringToLL(tok->previous->str) && stringToLL(tok->next->str));
|
result = (stringToLL(tok->previous->str()) && stringToLL(tok->next->str()));
|
||||||
|
|
||||||
tok = tok->previous;
|
tok = tok->previous;
|
||||||
tok->setstr(toString(result));
|
tok->setstr(toString(result));
|
||||||
|
@ -1001,7 +1004,7 @@ void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
|
||||||
bool gotoTok1 = false;
|
bool gotoTok1 = false;
|
||||||
for (Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
|
for (Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
|
||||||
gotoTok1 = false;
|
gotoTok1 = false;
|
||||||
if (tok->str != "?")
|
if (tok->str() != "?")
|
||||||
continue;
|
continue;
|
||||||
if (!tok->previous || !tok->next || !tok->next->next)
|
if (!tok->previous || !tok->next || !tok->next->next)
|
||||||
throw std::runtime_error("invalid expression");
|
throw std::runtime_error("invalid expression");
|
||||||
|
@ -1015,10 +1018,10 @@ void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
|
||||||
if (!falseTok)
|
if (!falseTok)
|
||||||
throw std::runtime_error("invalid expression");
|
throw std::runtime_error("invalid expression");
|
||||||
if (condTok == *tok1)
|
if (condTok == *tok1)
|
||||||
*tok1 = (condTok->str != "0" ? trueTok : falseTok);
|
*tok1 = (condTok->str() != "0" ? trueTok : falseTok);
|
||||||
deleteToken(condTok->next); // ?
|
deleteToken(condTok->next); // ?
|
||||||
deleteToken(trueTok->next); // :
|
deleteToken(trueTok->next); // :
|
||||||
deleteToken(condTok->str == "0" ? trueTok : falseTok);
|
deleteToken(condTok->str() == "0" ? trueTok : falseTok);
|
||||||
deleteToken(condTok);
|
deleteToken(condTok);
|
||||||
gotoTok1 = true;
|
gotoTok1 = true;
|
||||||
}
|
}
|
||||||
|
@ -1085,8 +1088,8 @@ std::string simplecpp::TokenList::lastLine(int maxsize) const
|
||||||
continue;
|
continue;
|
||||||
if (!ret.empty())
|
if (!ret.empty())
|
||||||
ret = ' ' + ret;
|
ret = ' ' + ret;
|
||||||
ret = (tok->str[0] == '\"' ? std::string("%str%")
|
ret = (tok->str()[0] == '\"' ? std::string("%str%")
|
||||||
: std::isdigit(static_cast<unsigned char>(tok->str[0])) ? std::string("%num%") : tok->str) + ret;
|
: std::isdigit(static_cast<unsigned char>(tok->str()[0])) ? std::string("%num%") : tok->str()) + ret;
|
||||||
if (++count > maxsize)
|
if (++count > maxsize)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1119,7 @@ namespace simplecpp {
|
||||||
throw std::runtime_error("bad macro syntax");
|
throw std::runtime_error("bad macro syntax");
|
||||||
const Token * const hashtok = tok;
|
const Token * const hashtok = tok;
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
if (!tok || tok->str != DEFINE)
|
if (!tok || tok->str() != DEFINE)
|
||||||
throw std::runtime_error("bad macro syntax");
|
throw std::runtime_error("bad macro syntax");
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
if (!tok || !tok->name || !sameline(hashtok,tok))
|
if (!tok || !tok->name || !sameline(hashtok,tok))
|
||||||
|
@ -1169,9 +1172,9 @@ namespace simplecpp {
|
||||||
// Copy macro call to a new tokenlist with no linebreaks
|
// Copy macro call to a new tokenlist with no linebreaks
|
||||||
const Token * const rawtok1 = rawtok;
|
const Token * const rawtok1 = rawtok;
|
||||||
TokenList rawtokens2(inputFiles);
|
TokenList rawtokens2(inputFiles);
|
||||||
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
rawtokens2.push_back(new Token(rawtok->str(), rawtok1->location));
|
||||||
rawtok = rawtok->next;
|
rawtok = rawtok->next;
|
||||||
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
rawtokens2.push_back(new Token(rawtok->str(), rawtok1->location));
|
||||||
rawtok = rawtok->next;
|
rawtok = rawtok->next;
|
||||||
int par = 1;
|
int par = 1;
|
||||||
while (rawtok && par > 0) {
|
while (rawtok && par > 0) {
|
||||||
|
@ -1181,7 +1184,7 @@ namespace simplecpp {
|
||||||
--par;
|
--par;
|
||||||
else if (rawtok->op == '#' && !sameline(rawtok->previous, rawtok))
|
else if (rawtok->op == '#' && !sameline(rawtok->previous, rawtok))
|
||||||
throw Error(rawtok->location, "it is invalid to use a preprocessor directive as macro parameter");
|
throw Error(rawtok->location, "it is invalid to use a preprocessor directive as macro parameter");
|
||||||
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
rawtokens2.push_back(new Token(rawtok->str(), rawtok1->location));
|
||||||
rawtok = rawtok->next;
|
rawtok = rawtok->next;
|
||||||
}
|
}
|
||||||
if (expand(&output2, rawtok1->location, rawtokens2.cfront(), macros, expandedmacros))
|
if (expand(&output2, rawtok1->location, rawtokens2.cfront(), macros, expandedmacros))
|
||||||
|
@ -1208,23 +1211,23 @@ namespace simplecpp {
|
||||||
macro2tok = output2.back();
|
macro2tok = output2.back();
|
||||||
if (!macro2tok || !macro2tok->name)
|
if (!macro2tok || !macro2tok->name)
|
||||||
break;
|
break;
|
||||||
if (output2.cfront() != output2.cback() && macro2tok->str == this->name())
|
if (output2.cfront() != output2.cback() && macro2tok->str() == this->name())
|
||||||
break;
|
break;
|
||||||
const std::map<TokenString,Macro>::const_iterator macro = macros.find(macro2tok->str);
|
const std::map<TokenString,Macro>::const_iterator macro = macros.find(macro2tok->str());
|
||||||
if (macro == macros.end() || !macro->second.functionLike())
|
if (macro == macros.end() || !macro->second.functionLike())
|
||||||
break;
|
break;
|
||||||
TokenList rawtokens2(inputFiles);
|
TokenList rawtokens2(inputFiles);
|
||||||
const Location loc(macro2tok->location);
|
const Location loc(macro2tok->location);
|
||||||
while (macro2tok) {
|
while (macro2tok) {
|
||||||
Token *next = macro2tok->next;
|
Token *next = macro2tok->next;
|
||||||
rawtokens2.push_back(new Token(macro2tok->str, loc));
|
rawtokens2.push_back(new Token(macro2tok->str(), loc));
|
||||||
output2.deleteToken(macro2tok);
|
output2.deleteToken(macro2tok);
|
||||||
macro2tok = next;
|
macro2tok = next;
|
||||||
}
|
}
|
||||||
par = (rawtokens2.cfront() != rawtokens2.cback()) ? 1U : 0U;
|
par = (rawtokens2.cfront() != rawtokens2.cback()) ? 1U : 0U;
|
||||||
const Token *rawtok2 = rawtok;
|
const Token *rawtok2 = rawtok;
|
||||||
for (; rawtok2; rawtok2 = rawtok2->next) {
|
for (; rawtok2; rawtok2 = rawtok2->next) {
|
||||||
rawtokens2.push_back(new Token(rawtok2->str, loc));
|
rawtokens2.push_back(new Token(rawtok2->str(), loc));
|
||||||
if (rawtok2->op == '(')
|
if (rawtok2->op == '(')
|
||||||
++par;
|
++par;
|
||||||
else if (rawtok2->op == ')') {
|
else if (rawtok2->op == ')') {
|
||||||
|
@ -1245,7 +1248,7 @@ namespace simplecpp {
|
||||||
|
|
||||||
/** macro name */
|
/** macro name */
|
||||||
const TokenString &name() const {
|
const TokenString &name() const {
|
||||||
return nameTokDef->str;
|
return nameTokDef->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** location for macro definition */
|
/** location for macro definition */
|
||||||
|
@ -1263,7 +1266,7 @@ namespace simplecpp {
|
||||||
return nameTokDef->next &&
|
return nameTokDef->next &&
|
||||||
nameTokDef->next->op == '(' &&
|
nameTokDef->next->op == '(' &&
|
||||||
sameline(nameTokDef, nameTokDef->next) &&
|
sameline(nameTokDef, nameTokDef->next) &&
|
||||||
nameTokDef->next->location.col == nameTokDef->location.col + nameTokDef->str.size();
|
nameTokDef->next->location.col == nameTokDef->location.col + nameTokDef->str().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** base class for errors */
|
/** base class for errors */
|
||||||
|
@ -1287,7 +1290,7 @@ namespace simplecpp {
|
||||||
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced) const {
|
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced) const {
|
||||||
Token *tok = new Token(str,loc);
|
Token *tok = new Token(str,loc);
|
||||||
if (replaced)
|
if (replaced)
|
||||||
tok->macro = nameTokDef->str;
|
tok->macro = nameTokDef->str();
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1316,7 +1319,7 @@ namespace simplecpp {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (argtok->op != ',')
|
if (argtok->op != ',')
|
||||||
args.push_back(argtok->str);
|
args.push_back(argtok->str());
|
||||||
argtok = argtok->next;
|
argtok = argtok->next;
|
||||||
}
|
}
|
||||||
if (!sameline(nametoken, argtok)) {
|
if (!sameline(nametoken, argtok)) {
|
||||||
|
@ -1388,8 +1391,8 @@ namespace simplecpp {
|
||||||
} else {
|
} else {
|
||||||
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
|
if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) {
|
||||||
bool expanded = false;
|
bool expanded = false;
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str);
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
||||||
if (it != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) {
|
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
||||||
const Macro &m = it->second;
|
const Macro &m = it->second;
|
||||||
if (!m.functionLike()) {
|
if (!m.functionLike()) {
|
||||||
m.expand(tokens, tok->location, tok, macros, expandedmacros);
|
m.expand(tokens, tok->location, tok, macros, expandedmacros);
|
||||||
|
@ -1414,19 +1417,19 @@ namespace simplecpp {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token * expand(TokenList * const output, const Location &loc, const Token * const nameTokInst, const std::map<TokenString,Macro> ¯os, std::set<TokenString> expandedmacros) const {
|
const Token * expand(TokenList * const output, const Location &loc, const Token * const nameTokInst, const std::map<TokenString,Macro> ¯os, std::set<TokenString> expandedmacros) const {
|
||||||
expandedmacros.insert(nameTokInst->str);
|
expandedmacros.insert(nameTokInst->str());
|
||||||
|
|
||||||
usageList.push_back(loc);
|
usageList.push_back(loc);
|
||||||
|
|
||||||
if (nameTokInst->str == "__FILE__") {
|
if (nameTokInst->str() == "__FILE__") {
|
||||||
output->push_back(new Token('\"'+loc.file()+'\"', loc));
|
output->push_back(new Token('\"'+loc.file()+'\"', loc));
|
||||||
return nameTokInst->next;
|
return nameTokInst->next;
|
||||||
}
|
}
|
||||||
if (nameTokInst->str == "__LINE__") {
|
if (nameTokInst->str() == "__LINE__") {
|
||||||
output->push_back(new Token(toString(loc.line), loc));
|
output->push_back(new Token(toString(loc.line), loc));
|
||||||
return nameTokInst->next;
|
return nameTokInst->next;
|
||||||
}
|
}
|
||||||
if (nameTokInst->str == "__COUNTER__") {
|
if (nameTokInst->str() == "__COUNTER__") {
|
||||||
output->push_back(new Token(toString(usageList.size()-1U), loc));
|
output->push_back(new Token(toString(usageList.size()-1U), loc));
|
||||||
return nameTokInst->next;
|
return nameTokInst->next;
|
||||||
}
|
}
|
||||||
|
@ -1439,7 +1442,7 @@ namespace simplecpp {
|
||||||
if (functionLike()) {
|
if (functionLike()) {
|
||||||
// No arguments => not macro expansion
|
// No arguments => not macro expansion
|
||||||
if (nameTokInst->next && nameTokInst->next->op != '(') {
|
if (nameTokInst->next && nameTokInst->next->op != '(') {
|
||||||
output->push_back(new Token(nameTokInst->str, loc));
|
output->push_back(new Token(nameTokInst->str(), loc));
|
||||||
return nameTokInst->next;
|
return nameTokInst->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,7 +1463,7 @@ namespace simplecpp {
|
||||||
if (!parametertokens1.empty()) {
|
if (!parametertokens1.empty()) {
|
||||||
bool counter = false;
|
bool counter = false;
|
||||||
for (const Token *tok = parametertokens1[0]; tok != parametertokens1.back(); tok = tok->next) {
|
for (const Token *tok = parametertokens1[0]; tok != parametertokens1.back(); tok = tok->next) {
|
||||||
if (tok->str == "__COUNTER__") {
|
if (tok->str() == "__COUNTER__") {
|
||||||
counter = true;
|
counter = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1474,7 +1477,7 @@ namespace simplecpp {
|
||||||
const Macro &counterMacro = m->second;
|
const Macro &counterMacro = m->second;
|
||||||
unsigned int par = 0;
|
unsigned int par = 0;
|
||||||
for (const Token *tok = parametertokens1[0]; tok && par < parametertokens1.size(); tok = tok->next) {
|
for (const Token *tok = parametertokens1[0]; tok && par < parametertokens1.size(); tok = tok->next) {
|
||||||
if (tok->str == "__COUNTER__") {
|
if (tok->str() == "__COUNTER__") {
|
||||||
tokensparams.push_back(new Token(toString(counterMacro.usageList.size()), tok->location));
|
tokensparams.push_back(new Token(toString(counterMacro.usageList.size()), tok->location));
|
||||||
counterMacro.usageList.push_back(tok->location);
|
counterMacro.usageList.push_back(tok->location);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1534,7 +1537,7 @@ namespace simplecpp {
|
||||||
|
|
||||||
if (!functionLike()) {
|
if (!functionLike()) {
|
||||||
for (Token *tok = output_end_1 ? output_end_1->next : output->front(); tok; tok = tok->next) {
|
for (Token *tok = output_end_1 ? output_end_1->next : output->front(); tok; tok = tok->next) {
|
||||||
tok->macro = nameTokInst->str;
|
tok->macro = nameTokInst->str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1547,7 +1550,7 @@ namespace simplecpp {
|
||||||
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
||||||
// Not name..
|
// Not name..
|
||||||
if (!tok->name) {
|
if (!tok->name) {
|
||||||
output->push_back(newMacroToken(tok->str, loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1565,8 +1568,8 @@ namespace simplecpp {
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(temp.cback()->str);
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(temp.cback()->str());
|
||||||
if (it == macros.end() || expandedmacros.find(temp.cback()->str) != expandedmacros.end()) {
|
if (it == macros.end() || expandedmacros.find(temp.cback()->str()) != expandedmacros.end()) {
|
||||||
output->takeTokens(temp);
|
output->takeTokens(temp);
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
|
@ -1578,7 +1581,7 @@ namespace simplecpp {
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenList temp2(files);
|
TokenList temp2(files);
|
||||||
temp2.push_back(new Token(temp.cback()->str, tok->location));
|
temp2.push_back(new Token(temp.cback()->str(), tok->location));
|
||||||
|
|
||||||
const Token *tok2 = appendTokens(&temp2, tok->next, macros, expandedmacros, parametertokens);
|
const Token *tok2 = appendTokens(&temp2, tok->next, macros, expandedmacros, parametertokens);
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
|
@ -1593,27 +1596,27 @@ namespace simplecpp {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Macro..
|
// Macro..
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str);
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(tok->str());
|
||||||
if (it != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) {
|
if (it != macros.end() && expandedmacros.find(tok->str()) == expandedmacros.end()) {
|
||||||
const Macro &calledMacro = it->second;
|
const Macro &calledMacro = it->second;
|
||||||
if (!calledMacro.functionLike())
|
if (!calledMacro.functionLike())
|
||||||
return calledMacro.expand(output, loc, tok, macros, expandedmacros);
|
return calledMacro.expand(output, loc, tok, macros, expandedmacros);
|
||||||
if (!sameline(tok, tok->next) || tok->next->op != '(') {
|
if (!sameline(tok, tok->next) || tok->next->op != '(') {
|
||||||
output->push_back(newMacroToken(tok->str, loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
TokenList tokens(files);
|
TokenList tokens(files);
|
||||||
tokens.push_back(new Token(*tok));
|
tokens.push_back(new Token(*tok));
|
||||||
const Token *tok2 = appendTokens(&tokens, tok->next, macros, expandedmacros, parametertokens);
|
const Token *tok2 = appendTokens(&tokens, tok->next, macros, expandedmacros, parametertokens);
|
||||||
if (!tok2) {
|
if (!tok2) {
|
||||||
output->push_back(newMacroToken(tok->str, loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
calledMacro.expand(output, loc, tokens.cfront(), macros, expandedmacros);
|
calledMacro.expand(output, loc, tokens.cfront(), macros, expandedmacros);
|
||||||
return tok2->next;
|
return tok2->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->str == DEFINED) {
|
else if (tok->str() == DEFINED) {
|
||||||
const Token *tok2 = tok->next;
|
const Token *tok2 = tok->next;
|
||||||
const Token *tok3 = tok2 ? tok2->next : NULL;
|
const Token *tok3 = tok2 ? tok2->next : NULL;
|
||||||
const Token *tok4 = tok3 ? tok3->next : NULL;
|
const Token *tok4 = tok3 ? tok3->next : NULL;
|
||||||
|
@ -1626,13 +1629,13 @@ namespace simplecpp {
|
||||||
defToken = lastToken = tok2;
|
defToken = lastToken = tok2;
|
||||||
}
|
}
|
||||||
if (defToken) {
|
if (defToken) {
|
||||||
const bool def = (macros.find(defToken->str) != macros.end());
|
const bool def = (macros.find(defToken->str()) != macros.end());
|
||||||
output->push_back(newMacroToken(def ? "1" : "0", loc, true));
|
output->push_back(newMacroToken(def ? "1" : "0", loc, true));
|
||||||
return lastToken->next;
|
return lastToken->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output->push_back(newMacroToken(tok->str, loc, true));
|
output->push_back(newMacroToken(tok->str(), loc, true));
|
||||||
return tok->next;
|
return tok->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1640,7 +1643,7 @@ namespace simplecpp {
|
||||||
if (!tok->name)
|
if (!tok->name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const unsigned int argnr = getArgNum(tok->str);
|
const unsigned int argnr = getArgNum(tok->str());
|
||||||
if (argnr >= args.size())
|
if (argnr >= args.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1657,17 +1660,17 @@ namespace simplecpp {
|
||||||
bool expandArg(TokenList *output, const Token *tok, const Location &loc, const std::map<TokenString, Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
bool expandArg(TokenList *output, const Token *tok, const Location &loc, const std::map<TokenString, Macro> ¯os, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> ¶metertokens) const {
|
||||||
if (!tok->name)
|
if (!tok->name)
|
||||||
return false;
|
return false;
|
||||||
const unsigned int argnr = getArgNum(tok->str);
|
const unsigned int argnr = getArgNum(tok->str());
|
||||||
if (argnr >= args.size())
|
if (argnr >= args.size())
|
||||||
return false;
|
return false;
|
||||||
if (variadic && argnr + 1U >= parametertokens.size()) // empty variadic parameter
|
if (variadic && argnr + 1U >= parametertokens.size()) // empty variadic parameter
|
||||||
return true;
|
return true;
|
||||||
for (const Token *partok = parametertokens[argnr]->next; partok != parametertokens[argnr + 1U];) {
|
for (const Token *partok = parametertokens[argnr]->next; partok != parametertokens[argnr + 1U];) {
|
||||||
const std::map<TokenString, Macro>::const_iterator it = macros.find(partok->str);
|
const std::map<TokenString, Macro>::const_iterator it = macros.find(partok->str());
|
||||||
if (it != macros.end() && (partok->str == name() || expandedmacros.find(partok->str) == expandedmacros.end()))
|
if (it != macros.end() && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end()))
|
||||||
partok = it->second.expand(output, loc, partok, macros, expandedmacros);
|
partok = it->second.expand(output, loc, partok, macros, expandedmacros);
|
||||||
else {
|
else {
|
||||||
output->push_back(newMacroToken(partok->str, loc, isReplaced(expandedmacros)));
|
output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros)));
|
||||||
partok = partok->next;
|
partok = partok->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1685,10 +1688,10 @@ namespace simplecpp {
|
||||||
if (expandArg(&tokens, tok, parametertokens)) {
|
if (expandArg(&tokens, tok, parametertokens)) {
|
||||||
std::string s;
|
std::string s;
|
||||||
for (const Token *tok2 = tokens.cfront(); tok2; tok2 = tok2->next)
|
for (const Token *tok2 = tokens.cfront(); tok2; tok2 = tok2->next)
|
||||||
s += tok2->str;
|
s += tok2->str();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
return tok->str;
|
return tok->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1707,7 +1710,7 @@ namespace simplecpp {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << '\"';
|
ostr << '\"';
|
||||||
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next)
|
for (const Token *hashtok = tokenListHash.cfront(); hashtok; hashtok = hashtok->next)
|
||||||
ostr << hashtok->str;
|
ostr << hashtok->str();
|
||||||
ostr << '\"';
|
ostr << '\"';
|
||||||
output->push_back(newMacroToken(escapeString(ostr.str()), loc, isReplaced(expandedmacros)));
|
output->push_back(newMacroToken(escapeString(ostr.str()), loc, isReplaced(expandedmacros)));
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -1730,7 +1733,7 @@ namespace simplecpp {
|
||||||
throw invalidHashHash(tok->location, name());
|
throw invalidHashHash(tok->location, name());
|
||||||
if (!sameline(tok, tok->next) || !sameline(tok, tok->next->next))
|
if (!sameline(tok, tok->next) || !sameline(tok, tok->next->next))
|
||||||
throw invalidHashHash(tok->location, name());
|
throw invalidHashHash(tok->location, name());
|
||||||
if (!A->name && !A->number && A->op != ',' && !A->str.empty())
|
if (!A->name && !A->number && A->op != ',' && !A->str().empty())
|
||||||
throw invalidHashHash(tok->location, name());
|
throw invalidHashHash(tok->location, name());
|
||||||
|
|
||||||
Token *B = tok->next->next;
|
Token *B = tok->next->next;
|
||||||
|
@ -1739,25 +1742,25 @@ namespace simplecpp {
|
||||||
|
|
||||||
std::string strAB;
|
std::string strAB;
|
||||||
|
|
||||||
const bool varargs = variadic && args.size() >= 1U && B->str == args[args.size()-1U];
|
const bool varargs = variadic && args.size() >= 1U && B->str() == args[args.size()-1U];
|
||||||
|
|
||||||
TokenList tokensB(files);
|
TokenList tokensB(files);
|
||||||
if (expandArg(&tokensB, B, parametertokens)) {
|
if (expandArg(&tokensB, B, parametertokens)) {
|
||||||
if (tokensB.empty())
|
if (tokensB.empty())
|
||||||
strAB = A->str;
|
strAB = A->str();
|
||||||
else if (varargs && A->op == ',') {
|
else if (varargs && A->op == ',') {
|
||||||
strAB = ",";
|
strAB = ",";
|
||||||
} else {
|
} else {
|
||||||
strAB = A->str + tokensB.cfront()->str;
|
strAB = A->str() + tokensB.cfront()->str();
|
||||||
tokensB.deleteToken(tokensB.front());
|
tokensB.deleteToken(tokensB.front());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
strAB = A->str + B->str;
|
strAB = A->str() + B->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *nextTok = B->next;
|
const Token *nextTok = B->next;
|
||||||
|
|
||||||
if (varargs && tokensB.empty() && tok->previous->str == ",")
|
if (varargs && tokensB.empty() && tok->previous->str() == ",")
|
||||||
output->deleteToken(A);
|
output->deleteToken(A);
|
||||||
else if (strAB != "," && macros.find(strAB) == macros.end()) {
|
else if (strAB != "," && macros.find(strAB) == macros.end()) {
|
||||||
A->setstr(strAB);
|
A->setstr(strAB);
|
||||||
|
@ -1987,7 +1990,7 @@ namespace simplecpp {
|
||||||
static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType)
|
static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType)
|
||||||
{
|
{
|
||||||
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
||||||
if (tok->str != "sizeof")
|
if (tok->str() != "sizeof")
|
||||||
continue;
|
continue;
|
||||||
simplecpp::Token *tok1 = tok->next;
|
simplecpp::Token *tok1 = tok->next;
|
||||||
if (!tok1) {
|
if (!tok1) {
|
||||||
|
@ -2009,13 +2012,13 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
|
||||||
|
|
||||||
std::string type;
|
std::string type;
|
||||||
for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
|
for (simplecpp::Token *typeToken = tok1; typeToken != tok2; typeToken = typeToken->next) {
|
||||||
if ((typeToken->str == "unsigned" || typeToken->str == "signed") && typeToken->next->name)
|
if ((typeToken->str() == "unsigned" || typeToken->str() == "signed") && typeToken->next->name)
|
||||||
continue;
|
continue;
|
||||||
if (typeToken->str == "*" && type.find('*') != std::string::npos)
|
if (typeToken->str() == "*" && type.find('*') != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
if (!type.empty())
|
if (!type.empty())
|
||||||
type += ' ';
|
type += ' ';
|
||||||
type += typeToken->str;
|
type += typeToken->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string, std::size_t>::const_iterator it = sizeOfType.find(type);
|
const std::map<std::string, std::size_t>::const_iterator it = sizeOfType.find(type);
|
||||||
|
@ -2036,12 +2039,12 @@ static void simplifyName(simplecpp::TokenList &expr)
|
||||||
{
|
{
|
||||||
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
||||||
if (tok->name) {
|
if (tok->name) {
|
||||||
if (altop.find(tok->str) != altop.end()) {
|
if (altop.find(tok->str()) != altop.end()) {
|
||||||
bool alt;
|
bool alt;
|
||||||
if (tok->str == "not" || tok->str == "compl") {
|
if (tok->str() == "not" || tok->str() == "compl") {
|
||||||
alt = isAlternativeUnaryOp(tok,tok->str);
|
alt = isAlternativeUnaryOp(tok,tok->str());
|
||||||
} else {
|
} else {
|
||||||
alt = isAlternativeBinaryOp(tok,tok->str);
|
alt = isAlternativeBinaryOp(tok,tok->str());
|
||||||
}
|
}
|
||||||
if (alt)
|
if (alt)
|
||||||
continue;
|
continue;
|
||||||
|
@ -2054,12 +2057,12 @@ static void simplifyName(simplecpp::TokenList &expr)
|
||||||
static void simplifyNumbers(simplecpp::TokenList &expr)
|
static void simplifyNumbers(simplecpp::TokenList &expr)
|
||||||
{
|
{
|
||||||
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
|
||||||
if (tok->str.size() == 1U)
|
if (tok->str().size() == 1U)
|
||||||
continue;
|
continue;
|
||||||
if (tok->str.compare(0,2,"0x") == 0)
|
if (tok->str().compare(0,2,"0x") == 0)
|
||||||
tok->setstr(toString(stringToULL(tok->str)));
|
tok->setstr(toString(stringToULL(tok->str())));
|
||||||
else if (tok->str[0] == '\'')
|
else if (tok->str()[0] == '\'')
|
||||||
tok->setstr(toString(tok->str[1] & 0xffU));
|
tok->setstr(toString(tok->str()[1] & 0xffU));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2070,7 +2073,7 @@ static long long evaluate(simplecpp::TokenList &expr, const std::map<std::string
|
||||||
simplifyNumbers(expr);
|
simplifyNumbers(expr);
|
||||||
expr.constFold();
|
expr.constFold();
|
||||||
// TODO: handle invalid expressions
|
// TODO: handle invalid expressions
|
||||||
return expr.cfront() && expr.cfront() == expr.cback() && expr.cfront()->number ? stringToLL(expr.cfront()->str) : 0LL;
|
return expr.cfront() && expr.cfront() == expr.cback() && expr.cfront()->number ? stringToLL(expr.cfront()->str()) : 0LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok)
|
static const simplecpp::Token *gotoNextLine(const simplecpp::Token *tok)
|
||||||
|
@ -2191,7 +2194,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rawtok = rawtok->nextSkipComments();
|
rawtok = rawtok->nextSkipComments();
|
||||||
if (!rawtok || rawtok->str != INCLUDE)
|
if (!rawtok || rawtok->str() != INCLUDE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string &sourcefile = rawtok->location.file();
|
const std::string &sourcefile = rawtok->location.file();
|
||||||
|
@ -2200,9 +2203,9 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
|
||||||
if (!sameline(rawtok, htok))
|
if (!sameline(rawtok, htok))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool systemheader = (htok->str[0] == '<');
|
bool systemheader = (htok->str()[0] == '<');
|
||||||
|
|
||||||
const std::string header(realFilename(htok->str.substr(1U, htok->str.size() - 2U)));
|
const std::string header(realFilename(htok->str().substr(1U, htok->str().size() - 2U)));
|
||||||
if (hasFile(ret, sourcefile, header, dui, systemheader))
|
if (hasFile(ret, sourcefile, header, dui, systemheader))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -2223,7 +2226,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
|
||||||
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token **tok1, std::map<std::string, simplecpp::Macro> ¯os, std::vector<std::string> &files, simplecpp::OutputList *outputList)
|
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token **tok1, std::map<std::string, simplecpp::Macro> ¯os, std::vector<std::string> &files, simplecpp::OutputList *outputList)
|
||||||
{
|
{
|
||||||
const simplecpp::Token *tok = *tok1;
|
const simplecpp::Token *tok = *tok1;
|
||||||
const std::map<std::string,simplecpp::Macro>::const_iterator it = macros.find(tok->str);
|
const std::map<std::string,simplecpp::Macro>::const_iterator it = macros.find(tok->str());
|
||||||
if (it != macros.end()) {
|
if (it != macros.end()) {
|
||||||
simplecpp::TokenList value(files);
|
simplecpp::TokenList value(files);
|
||||||
try {
|
try {
|
||||||
|
@ -2233,7 +2236,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
|
||||||
simplecpp::Output out(files);
|
simplecpp::Output out(files);
|
||||||
out.type = simplecpp::Output::SYNTAX_ERROR;
|
out.type = simplecpp::Output::SYNTAX_ERROR;
|
||||||
out.location = err.location;
|
out.location = err.location;
|
||||||
out.msg = "failed to expand \'" + tok->str + "\', " + err.what;
|
out.msg = "failed to expand \'" + tok->str() + "\', " + err.what;
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -2250,26 +2253,26 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
|
||||||
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage)
|
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
|
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("char"), sizeof(char)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("char", sizeof(char)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("short"), sizeof(short)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("short", sizeof(short)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("short int"), sizeOfType["short"]));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("short int", sizeOfType["short"]));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("int"), sizeof(int)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("int", sizeof(int)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long"), sizeof(long)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long", sizeof(long)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long int"), sizeOfType["long"]));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long int", sizeOfType["long"]));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long long"), sizeof(long long)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long long", sizeof(long long)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("float"), sizeof(float)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("float", sizeof(float)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("double"), sizeof(double)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("double", sizeof(double)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long double"), sizeof(long double)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long double", sizeof(long double)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("char *"), sizeof(char *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("char *", sizeof(char *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("short *"), sizeof(short *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("short *", sizeof(short *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("short int *"), sizeOfType["short *"]));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("short int *", sizeOfType["short *"]));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("int *"), sizeof(int *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("int *", sizeof(int *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long *"), sizeof(long *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long *", sizeof(long *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long int *"), sizeOfType["long *"]));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long int *", sizeOfType["long *"]));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long long *"), sizeof(long long *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long long *", sizeof(long long *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("float *"), sizeof(float *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("float *", sizeof(float *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("double *"), sizeof(double *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("double *", sizeof(double *)));
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("long double *"), sizeof(long double *)));
|
sizeOfType.insert(std::pair<std::string, std::size_t>("long double *", sizeof(long double *)));
|
||||||
|
|
||||||
std::map<TokenString, Macro> macros;
|
std::map<TokenString, Macro> macros;
|
||||||
for (std::list<std::string>::const_iterator it = dui.defines.begin(); it != dui.defines.end(); ++it) {
|
for (std::list<std::string>::const_iterator it = dui.defines.begin(); it != dui.defines.end(); ++it) {
|
||||||
|
@ -2325,38 +2328,38 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifstates.size() <= 1U && (rawtok->str == ELIF || rawtok->str == ELSE || rawtok->str == ENDIF)) {
|
if (ifstates.size() <= 1U && (rawtok->str() == ELIF || rawtok->str() == ELSE || rawtok->str() == ENDIF)) {
|
||||||
if (outputList) {
|
if (outputList) {
|
||||||
simplecpp::Output err(files);
|
simplecpp::Output err(files);
|
||||||
err.type = Output::SYNTAX_ERROR;
|
err.type = Output::SYNTAX_ERROR;
|
||||||
err.location = rawtok->location;
|
err.location = rawtok->location;
|
||||||
err.msg = "#" + rawtok->str + " without #if";
|
err.msg = "#" + rawtok->str() + " without #if";
|
||||||
outputList->push_back(err);
|
outputList->push_back(err);
|
||||||
}
|
}
|
||||||
output.clear();
|
output.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifstates.top() == TRUE && (rawtok->str == ERROR || rawtok->str == WARNING)) {
|
if (ifstates.top() == TRUE && (rawtok->str() == ERROR || rawtok->str() == WARNING)) {
|
||||||
if (outputList) {
|
if (outputList) {
|
||||||
simplecpp::Output err(rawtok->location.files);
|
simplecpp::Output err(rawtok->location.files);
|
||||||
err.type = rawtok->str == ERROR ? Output::ERROR : Output::WARNING;
|
err.type = rawtok->str() == ERROR ? Output::ERROR : Output::WARNING;
|
||||||
err.location = rawtok->location;
|
err.location = rawtok->location;
|
||||||
for (const Token *tok = rawtok->next; tok && sameline(rawtok,tok); tok = tok->next) {
|
for (const Token *tok = rawtok->next; tok && sameline(rawtok,tok); tok = tok->next) {
|
||||||
if (!err.msg.empty() && isNameChar(tok->str[0]))
|
if (!err.msg.empty() && isNameChar(tok->str()[0]))
|
||||||
err.msg += ' ';
|
err.msg += ' ';
|
||||||
err.msg += tok->str;
|
err.msg += tok->str();
|
||||||
}
|
}
|
||||||
err.msg = '#' + rawtok->str + ' ' + err.msg;
|
err.msg = '#' + rawtok->str() + ' ' + err.msg;
|
||||||
outputList->push_back(err);
|
outputList->push_back(err);
|
||||||
}
|
}
|
||||||
if (rawtok->str == ERROR) {
|
if (rawtok->str() == ERROR) {
|
||||||
output.clear();
|
output.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawtok->str == DEFINE) {
|
if (rawtok->str() == DEFINE) {
|
||||||
if (ifstates.top() != TRUE)
|
if (ifstates.top() != TRUE)
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
|
@ -2379,7 +2382,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
output.clear();
|
output.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (ifstates.top() == TRUE && rawtok->str == INCLUDE) {
|
} else if (ifstates.top() == TRUE && rawtok->str() == INCLUDE) {
|
||||||
TokenList inc1(files);
|
TokenList inc1(files);
|
||||||
for (const Token *inctok = rawtok->next; sameline(rawtok,inctok); inctok = inctok->next) {
|
for (const Token *inctok = rawtok->next; sameline(rawtok,inctok); inctok = inctok->next) {
|
||||||
if (!inctok->comment)
|
if (!inctok->comment)
|
||||||
|
@ -2401,14 +2404,14 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
// TODO: Sometimes spaces must be added in the string
|
// TODO: Sometimes spaces must be added in the string
|
||||||
// Somehow preprocessToken etc must be told that the location should be source location not destination location
|
// Somehow preprocessToken etc must be told that the location should be source location not destination location
|
||||||
for (const Token *tok = inc2.cfront(); tok; tok = tok->next) {
|
for (const Token *tok = inc2.cfront(); tok; tok = tok->next) {
|
||||||
hdr += tok->str;
|
hdr += tok->str();
|
||||||
}
|
}
|
||||||
inc2.clear();
|
inc2.clear();
|
||||||
inc2.push_back(new Token(hdr, inc1.cfront()->location));
|
inc2.push_back(new Token(hdr, inc1.cfront()->location));
|
||||||
inc2.front()->op = '<';
|
inc2.front()->op = '<';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inc2.empty() || inc2.cfront()->str.size() <= 2U) {
|
if (inc2.empty() || inc2.cfront()->str().size() <= 2U) {
|
||||||
if (outputList) {
|
if (outputList) {
|
||||||
simplecpp::Output err(files);
|
simplecpp::Output err(files);
|
||||||
err.type = Output::SYNTAX_ERROR;
|
err.type = Output::SYNTAX_ERROR;
|
||||||
|
@ -2423,7 +2426,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
const Token *inctok = inc2.cfront();
|
const Token *inctok = inc2.cfront();
|
||||||
|
|
||||||
const bool systemheader = (inctok->op == '<');
|
const bool systemheader = (inctok->op == '<');
|
||||||
const std::string header(realFilename(inctok->str.substr(1U, inctok->str.size() - 2U)));
|
const std::string header(realFilename(inctok->str().substr(1U, inctok->str().size() - 2U)));
|
||||||
std::string header2 = getFileName(filedata, rawtok->location.file(), header, dui, systemheader);
|
std::string header2 = getFileName(filedata, rawtok->location.file(), header, dui, systemheader);
|
||||||
if (header2.empty()) {
|
if (header2.empty()) {
|
||||||
// try to load file..
|
// try to load file..
|
||||||
|
@ -2439,7 +2442,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
simplecpp::Output out(files);
|
simplecpp::Output out(files);
|
||||||
out.type = Output::MISSING_HEADER;
|
out.type = Output::MISSING_HEADER;
|
||||||
out.location = rawtok->location;
|
out.location = rawtok->location;
|
||||||
out.msg = "Header not found: " + inctok->str;
|
out.msg = "Header not found: " + inctok->str();
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
}
|
}
|
||||||
} else if (includetokenstack.size() >= 400) {
|
} else if (includetokenstack.size() >= 400) {
|
||||||
|
@ -2456,13 +2459,13 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
rawtok = includetokens ? includetokens->cfront() : 0;
|
rawtok = includetokens ? includetokens->cfront() : 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (rawtok->str == IF || rawtok->str == IFDEF || rawtok->str == IFNDEF || rawtok->str == ELIF) {
|
} else if (rawtok->str() == IF || rawtok->str() == IFDEF || rawtok->str() == IFNDEF || rawtok->str() == ELIF) {
|
||||||
if (!sameline(rawtok,rawtok->next)) {
|
if (!sameline(rawtok,rawtok->next)) {
|
||||||
if (outputList) {
|
if (outputList) {
|
||||||
simplecpp::Output out(files);
|
simplecpp::Output out(files);
|
||||||
out.type = Output::SYNTAX_ERROR;
|
out.type = Output::SYNTAX_ERROR;
|
||||||
out.location = rawtok->location;
|
out.location = rawtok->location;
|
||||||
out.msg = "Syntax error in #" + rawtok->str;
|
out.msg = "Syntax error in #" + rawtok->str();
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
}
|
}
|
||||||
output.clear();
|
output.clear();
|
||||||
|
@ -2470,13 +2473,13 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
}
|
}
|
||||||
|
|
||||||
bool conditionIsTrue;
|
bool conditionIsTrue;
|
||||||
if (ifstates.top() == ALWAYS_FALSE || (ifstates.top() == ELSE_IS_TRUE && rawtok->str != ELIF))
|
if (ifstates.top() == ALWAYS_FALSE || (ifstates.top() == ELSE_IS_TRUE && rawtok->str() != ELIF))
|
||||||
conditionIsTrue = false;
|
conditionIsTrue = false;
|
||||||
else if (rawtok->str == IFDEF)
|
else if (rawtok->str() == IFDEF)
|
||||||
conditionIsTrue = (macros.find(rawtok->next->str) != macros.end());
|
conditionIsTrue = (macros.find(rawtok->next->str()) != macros.end());
|
||||||
else if (rawtok->str == IFNDEF)
|
else if (rawtok->str() == IFNDEF)
|
||||||
conditionIsTrue = (macros.find(rawtok->next->str) == macros.end());
|
conditionIsTrue = (macros.find(rawtok->next->str()) == macros.end());
|
||||||
else { /*if (rawtok->str == IF || rawtok->str == ELIF)*/
|
else { /*if (rawtok->str() == IF || rawtok->str() == ELIF)*/
|
||||||
TokenList expr(files);
|
TokenList expr(files);
|
||||||
for (const Token *tok = rawtok->next; tok && tok->location.sameline(rawtok->location); tok = tok->next) {
|
for (const Token *tok = rawtok->next; tok && tok->location.sameline(rawtok->location); tok = tok->next) {
|
||||||
if (!tok->name) {
|
if (!tok->name) {
|
||||||
|
@ -2484,13 +2487,13 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->str == DEFINED) {
|
if (tok->str() == DEFINED) {
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
const bool par = (tok && tok->op == '(');
|
const bool par = (tok && tok->op == '(');
|
||||||
if (par)
|
if (par)
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
if (tok) {
|
if (tok) {
|
||||||
if (macros.find(tok->str) != macros.end())
|
if (macros.find(tok->str()) != macros.end())
|
||||||
expr.push_back(new Token("1", tok->location));
|
expr.push_back(new Token("1", tok->location));
|
||||||
else
|
else
|
||||||
expr.push_back(new Token("0", tok->location));
|
expr.push_back(new Token("0", tok->location));
|
||||||
|
@ -2502,7 +2505,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
Output out(rawtok->location.files);
|
Output out(rawtok->location.files);
|
||||||
out.type = Output::SYNTAX_ERROR;
|
out.type = Output::SYNTAX_ERROR;
|
||||||
out.location = rawtok->location;
|
out.location = rawtok->location;
|
||||||
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
|
out.msg = "failed to evaluate " + std::string(rawtok->str() == IF ? "#if" : "#elif") + " condition";
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
}
|
}
|
||||||
output.clear();
|
output.clear();
|
||||||
|
@ -2524,7 +2527,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
Output out(rawtok->location.files);
|
Output out(rawtok->location.files);
|
||||||
out.type = Output::SYNTAX_ERROR;
|
out.type = Output::SYNTAX_ERROR;
|
||||||
out.location = rawtok->location;
|
out.location = rawtok->location;
|
||||||
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
|
out.msg = "failed to evaluate " + std::string(rawtok->str() == IF ? "#if" : "#elif") + " condition";
|
||||||
if (e.what() && *e.what())
|
if (e.what() && *e.what())
|
||||||
out.msg += std::string(", ") + e.what();
|
out.msg += std::string(", ") + e.what();
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
|
@ -2534,7 +2537,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawtok->str != ELIF) {
|
if (rawtok->str() != ELIF) {
|
||||||
// push a new ifstate..
|
// push a new ifstate..
|
||||||
if (ifstates.top() != TRUE)
|
if (ifstates.top() != TRUE)
|
||||||
ifstates.push(ALWAYS_FALSE);
|
ifstates.push(ALWAYS_FALSE);
|
||||||
|
@ -2545,19 +2548,19 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
} else if (ifstates.top() == ELSE_IS_TRUE && conditionIsTrue) {
|
} else if (ifstates.top() == ELSE_IS_TRUE && conditionIsTrue) {
|
||||||
ifstates.top() = TRUE;
|
ifstates.top() = TRUE;
|
||||||
}
|
}
|
||||||
} else if (rawtok->str == ELSE) {
|
} else if (rawtok->str() == ELSE) {
|
||||||
ifstates.top() = (ifstates.top() == ELSE_IS_TRUE) ? TRUE : ALWAYS_FALSE;
|
ifstates.top() = (ifstates.top() == ELSE_IS_TRUE) ? TRUE : ALWAYS_FALSE;
|
||||||
} else if (rawtok->str == ENDIF) {
|
} else if (rawtok->str() == ENDIF) {
|
||||||
ifstates.pop();
|
ifstates.pop();
|
||||||
} else if (rawtok->str == UNDEF) {
|
} else if (rawtok->str() == UNDEF) {
|
||||||
if (ifstates.top() == TRUE) {
|
if (ifstates.top() == TRUE) {
|
||||||
const Token *tok = rawtok->next;
|
const Token *tok = rawtok->next;
|
||||||
while (sameline(rawtok,tok) && tok->comment)
|
while (sameline(rawtok,tok) && tok->comment)
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
if (sameline(rawtok, tok))
|
if (sameline(rawtok, tok))
|
||||||
macros.erase(tok->str);
|
macros.erase(tok->str());
|
||||||
}
|
}
|
||||||
} else if (ifstates.top() == TRUE && rawtok->str == PRAGMA && rawtok->next && rawtok->next->str == ONCE && sameline(rawtok,rawtok->next)) {
|
} else if (ifstates.top() == TRUE && rawtok->str() == PRAGMA && rawtok->next && rawtok->next->str() == ONCE && sameline(rawtok,rawtok->next)) {
|
||||||
pragmaOnce.insert(rawtok->location.file());
|
pragmaOnce.insert(rawtok->location.file());
|
||||||
}
|
}
|
||||||
rawtok = gotoNextLine(rawtok);
|
rawtok = gotoNextLine(rawtok);
|
||||||
|
@ -2592,11 +2595,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
if (hash || hashhash) {
|
if (hash || hashhash) {
|
||||||
std::string s;
|
std::string s;
|
||||||
for (const Token *hashtok = tokens.cfront(); hashtok; hashtok = hashtok->next)
|
for (const Token *hashtok = tokens.cfront(); hashtok; hashtok = hashtok->next)
|
||||||
s += hashtok->str;
|
s += hashtok->str();
|
||||||
if (hash)
|
if (hash)
|
||||||
output.push_back(new Token('\"' + s + '\"', loc));
|
output.push_back(new Token('\"' + s + '\"', loc));
|
||||||
else if (output.back())
|
else if (output.back())
|
||||||
output.back()->setstr(output.cback()->str + s);
|
output.back()->setstr(output.cback()->str() + s);
|
||||||
else
|
else
|
||||||
output.push_back(new Token(s, loc));
|
output.push_back(new Token(s, loc));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace simplecpp {
|
||||||
unsigned int line;
|
unsigned int line;
|
||||||
unsigned int col;
|
unsigned int col;
|
||||||
private:
|
private:
|
||||||
const std::string emptyFileName;
|
static const std::string emptyFileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,22 +97,23 @@ namespace simplecpp {
|
||||||
class SIMPLECPP_LIB Token {
|
class SIMPLECPP_LIB Token {
|
||||||
public:
|
public:
|
||||||
Token(const TokenString &s, const Location &loc) :
|
Token(const TokenString &s, const Location &loc) :
|
||||||
str(string), location(loc), previous(NULL), next(NULL), string(s) {
|
location(loc), previous(NULL), next(NULL), string(s) {
|
||||||
flags();
|
flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token(const Token &tok) :
|
Token(const Token &tok) :
|
||||||
str(string), macro(tok.macro), location(tok.location), previous(NULL), next(NULL), string(tok.str) {
|
macro(tok.macro), location(tok.location), previous(NULL), next(NULL), string(tok.string) {
|
||||||
flags();
|
flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void flags() {
|
void flags() {
|
||||||
name = (std::isalpha((unsigned char)str[0]) || str[0] == '_' || str[0] == '$');
|
name = (std::isalpha((unsigned char)string[0]) || string[0] == '_' || string[0] == '$');
|
||||||
comment = (str.compare(0, 2, "//") == 0 || str.compare(0, 2, "/*") == 0);
|
comment = (string.compare(0, 2, "//") == 0 || string.compare(0, 2, "/*") == 0);
|
||||||
number = std::isdigit((unsigned char)str[0]) || (str.size() > 1U && str[0] == '-' && std::isdigit((unsigned char)str[1]));
|
number = std::isdigit((unsigned char)string[0]) || (string.size() > 1U && string[0] == '-' && std::isdigit((unsigned char)string[1]));
|
||||||
op = (str.size() == 1U) ? str[0] : '\0';
|
op = (string.size() == 1U) ? string[0] : '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TokenString& str() const { return string; }
|
||||||
void setstr(const std::string &s) {
|
void setstr(const std::string &s) {
|
||||||
string = s;
|
string = s;
|
||||||
flags();
|
flags();
|
||||||
|
@ -122,7 +123,6 @@ namespace simplecpp {
|
||||||
bool startsWithOneOf(const char c[]) const;
|
bool startsWithOneOf(const char c[]) const;
|
||||||
bool endsWithOneOf(const char c[]) const;
|
bool endsWithOneOf(const char c[]) const;
|
||||||
|
|
||||||
const TokenString &str;
|
|
||||||
TokenString macro;
|
TokenString macro;
|
||||||
char op;
|
char op;
|
||||||
bool comment;
|
bool comment;
|
||||||
|
|
|
@ -216,7 +216,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
fdump << " <tok "
|
fdump << " <tok "
|
||||||
<< "fileIndex=\"" << tok->location.fileIndex << "\" "
|
<< "fileIndex=\"" << tok->location.fileIndex << "\" "
|
||||||
<< "linenr=\"" << tok->location.line << "\" "
|
<< "linenr=\"" << tok->location.line << "\" "
|
||||||
<< "str=\"" << ErrorLogger::toxml(tok->str) << "\""
|
<< "str=\"" << ErrorLogger::toxml(tok->str()) << "\""
|
||||||
<< "/>" << std::endl;
|
<< "/>" << std::endl;
|
||||||
}
|
}
|
||||||
fdump << " </rawtokens>" << std::endl;
|
fdump << " </rawtokens>" << std::endl;
|
||||||
|
|
|
@ -82,7 +82,7 @@ static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &_se
|
||||||
if (tok->comment) {
|
if (tok->comment) {
|
||||||
Suppressions::Suppression s;
|
Suppressions::Suppression s;
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (!s.parseComment(tok->str, &errmsg))
|
if (!s.parseComment(tok->str(), &errmsg))
|
||||||
continue;
|
continue;
|
||||||
if (!errmsg.empty())
|
if (!errmsg.empty())
|
||||||
bad->push_back(BadInlineSuppression(tok->location, errmsg));
|
bad->push_back(BadInlineSuppression(tok->location, errmsg));
|
||||||
|
@ -147,18 +147,18 @@ void Preprocessor::setDirectives(const simplecpp::TokenList &tokens)
|
||||||
for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) {
|
for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) {
|
||||||
if ((tok->op != '#') || (tok->previous && tok->previous->location.line == tok->location.line))
|
if ((tok->op != '#') || (tok->previous && tok->previous->location.line == tok->location.line))
|
||||||
continue;
|
continue;
|
||||||
if (tok->next && tok->next->str == "endfile")
|
if (tok->next && tok->next->str() == "endfile")
|
||||||
continue;
|
continue;
|
||||||
Directive directive(tok->location.file(), tok->location.line, emptyString);
|
Directive directive(tok->location.file(), tok->location.line, emptyString);
|
||||||
for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) {
|
for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) {
|
||||||
if (tok2->comment)
|
if (tok2->comment)
|
||||||
continue;
|
continue;
|
||||||
if (!directive.str.empty() && (tok2->location.col > tok2->previous->location.col + tok2->previous->str.size()))
|
if (!directive.str.empty() && (tok2->location.col > tok2->previous->location.col + tok2->previous->str().size()))
|
||||||
directive.str += ' ';
|
directive.str += ' ';
|
||||||
if (directive.str == "#" && tok2->str == "file")
|
if (directive.str == "#" && tok2->str() == "file")
|
||||||
directive.str += "include";
|
directive.str += "include";
|
||||||
else
|
else
|
||||||
directive.str += tok2->str;
|
directive.str += tok2->str();
|
||||||
}
|
}
|
||||||
directives.push_back(directive);
|
directives.push_back(directive);
|
||||||
}
|
}
|
||||||
|
@ -188,27 +188,27 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
|
||||||
if (sameline(iftok,next3))
|
if (sameline(iftok,next3))
|
||||||
len = 4;
|
len = 4;
|
||||||
|
|
||||||
if (len == 1 && cond->str == "0")
|
if (len == 1 && cond->str() == "0")
|
||||||
return "0";
|
return "0";
|
||||||
|
|
||||||
if (len == 1 && cond->name) {
|
if (len == 1 && cond->name) {
|
||||||
if (defined.find(cond->str) == defined.end())
|
if (defined.find(cond->str()) == defined.end())
|
||||||
return cond->str;
|
return cond->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 2 && cond->op == '!' && next1->name) {
|
if (len == 2 && cond->op == '!' && next1->name) {
|
||||||
if (defined.find(next1->str) == defined.end())
|
if (defined.find(next1->str()) == defined.end())
|
||||||
return next1->str + "=0";
|
return next1->str() + "=0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 3 && cond->op == '(' && next1->name && next2->op == ')') {
|
if (len == 3 && cond->op == '(' && next1->name && next2->op == ')') {
|
||||||
if (defined.find(next1->str) == defined.end() && undefined.find(next1->str) == undefined.end())
|
if (defined.find(next1->str()) == defined.end() && undefined.find(next1->str()) == undefined.end())
|
||||||
return next1->str;
|
return next1->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 3 && cond->name && next1->str == "==" && next2->number) {
|
if (len == 3 && cond->name && next1->str() == "==" && next2->number) {
|
||||||
if (defined.find(cond->str) == defined.end())
|
if (defined.find(cond->str()) == defined.end())
|
||||||
return cond->str + '=' + cond->next->next->str;
|
return cond->str() + '=' + cond->next->next->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> configset;
|
std::set<std::string> configset;
|
||||||
|
@ -216,20 +216,20 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
|
||||||
if (cond->op == '!') {
|
if (cond->op == '!') {
|
||||||
if (!sameline(iftok,cond->next) || !cond->next->name)
|
if (!sameline(iftok,cond->next) || !cond->next->name)
|
||||||
break;
|
break;
|
||||||
if (cond->next->str == "defined")
|
if (cond->next->str() == "defined")
|
||||||
continue;
|
continue;
|
||||||
configset.insert(cond->next->str + "=0");
|
configset.insert(cond->next->str() + "=0");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cond->str != "defined")
|
if (cond->str() != "defined")
|
||||||
continue;
|
continue;
|
||||||
const simplecpp::Token *dtok = cond->next;
|
const simplecpp::Token *dtok = cond->next;
|
||||||
if (!dtok)
|
if (!dtok)
|
||||||
break;
|
break;
|
||||||
if (dtok->op == '(')
|
if (dtok->op == '(')
|
||||||
dtok = dtok->next;
|
dtok = dtok->next;
|
||||||
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str) == defined.end() && undefined.find(dtok->str) == undefined.end())
|
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end())
|
||||||
configset.insert(dtok->str);
|
configset.insert(dtok->str());
|
||||||
}
|
}
|
||||||
std::string cfg;
|
std::string cfg;
|
||||||
for (const std::string &s : configset) {
|
for (const std::string &s : configset) {
|
||||||
|
@ -308,9 +308,9 @@ static const simplecpp::Token *gotoEndIf(const simplecpp::Token *cmdtok)
|
||||||
int level = 0;
|
int level = 0;
|
||||||
while (nullptr != (cmdtok = cmdtok->next)) {
|
while (nullptr != (cmdtok = cmdtok->next)) {
|
||||||
if (cmdtok->op == '#' && !sameline(cmdtok->previous,cmdtok) && sameline(cmdtok, cmdtok->next)) {
|
if (cmdtok->op == '#' && !sameline(cmdtok->previous,cmdtok) && sameline(cmdtok, cmdtok->next)) {
|
||||||
if (cmdtok->next->str.compare(0,2,"if")==0)
|
if (cmdtok->next->str().compare(0,2,"if")==0)
|
||||||
++level;
|
++level;
|
||||||
else if (cmdtok->next->str == "endif") {
|
else if (cmdtok->next->str() == "endif") {
|
||||||
--level;
|
--level;
|
||||||
if (level < 0)
|
if (level < 0)
|
||||||
return cmdtok;
|
return cmdtok;
|
||||||
|
@ -332,15 +332,15 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
const simplecpp::Token *cmdtok = tok->next;
|
const simplecpp::Token *cmdtok = tok->next;
|
||||||
if (!sameline(tok, cmdtok))
|
if (!sameline(tok, cmdtok))
|
||||||
continue;
|
continue;
|
||||||
if (cmdtok->str == "ifdef" || cmdtok->str == "ifndef" || cmdtok->str == "if") {
|
if (cmdtok->str() == "ifdef" || cmdtok->str() == "ifndef" || cmdtok->str() == "if") {
|
||||||
std::string config;
|
std::string config;
|
||||||
if (cmdtok->str == "ifdef" || cmdtok->str == "ifndef") {
|
if (cmdtok->str() == "ifdef" || cmdtok->str() == "ifndef") {
|
||||||
const simplecpp::Token *expr1 = cmdtok->next;
|
const simplecpp::Token *expr1 = cmdtok->next;
|
||||||
if (sameline(tok,expr1) && expr1->name && !sameline(tok,expr1->next))
|
if (sameline(tok,expr1) && expr1->name && !sameline(tok,expr1->next))
|
||||||
config = expr1->str;
|
config = expr1->str();
|
||||||
if (defined.find(config) != defined.end())
|
if (defined.find(config) != defined.end())
|
||||||
config.clear();
|
config.clear();
|
||||||
} else if (cmdtok->str == "if") {
|
} else if (cmdtok->str() == "if") {
|
||||||
config = readcondition(cmdtok, defined, undefined);
|
config = readcondition(cmdtok, defined, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,10 +348,10 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
if (isUndefined(config, undefined))
|
if (isUndefined(config, undefined))
|
||||||
config.clear();
|
config.clear();
|
||||||
|
|
||||||
configs_if.push_back((cmdtok->str == "ifndef") ? std::string() : config);
|
configs_if.push_back((cmdtok->str() == "ifndef") ? std::string() : config);
|
||||||
configs_ifndef.push_back((cmdtok->str == "ifndef") ? config : std::string());
|
configs_ifndef.push_back((cmdtok->str() == "ifndef") ? config : std::string());
|
||||||
ret.insert(cfg(configs_if,userDefines));
|
ret.insert(cfg(configs_if,userDefines));
|
||||||
} else if (cmdtok->str == "elif" || cmdtok->str == "else") {
|
} else if (cmdtok->str() == "elif" || cmdtok->str() == "else") {
|
||||||
if (getConfigsElseIsFalse(configs_if,userDefines)) {
|
if (getConfigsElseIsFalse(configs_if,userDefines)) {
|
||||||
tok = gotoEndIf(tok);
|
tok = gotoEndIf(tok);
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
@ -359,12 +359,12 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
tok = tok->previous;
|
tok = tok->previous;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cmdtok->str == "else" &&
|
if (cmdtok->str() == "else" &&
|
||||||
cmdtok->next &&
|
cmdtok->next &&
|
||||||
!sameline(cmdtok,cmdtok->next) &&
|
!sameline(cmdtok,cmdtok->next) &&
|
||||||
sameline(cmdtok->next, cmdtok->next->next) &&
|
sameline(cmdtok->next, cmdtok->next->next) &&
|
||||||
cmdtok->next->op == '#' &&
|
cmdtok->next->op == '#' &&
|
||||||
cmdtok->next->next->str == "error") {
|
cmdtok->next->next->str() == "error") {
|
||||||
const std::string &ifcfg = cfg(configs_if, userDefines);
|
const std::string &ifcfg = cfg(configs_if, userDefines);
|
||||||
if (!ifcfg.empty()) {
|
if (!ifcfg.empty()) {
|
||||||
if (!elseError.empty())
|
if (!elseError.empty())
|
||||||
|
@ -374,7 +374,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
}
|
}
|
||||||
if (!configs_if.empty())
|
if (!configs_if.empty())
|
||||||
configs_if.pop_back();
|
configs_if.pop_back();
|
||||||
if (cmdtok->str == "elif") {
|
if (cmdtok->str() == "elif") {
|
||||||
std::string config = readcondition(cmdtok, defined, undefined);
|
std::string config = readcondition(cmdtok, defined, undefined);
|
||||||
if (isUndefined(config,undefined))
|
if (isUndefined(config,undefined))
|
||||||
config.clear();
|
config.clear();
|
||||||
|
@ -384,12 +384,12 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
configs_if.push_back(configs_ifndef.back());
|
configs_if.push_back(configs_ifndef.back());
|
||||||
ret.insert(cfg(configs_if, userDefines));
|
ret.insert(cfg(configs_if, userDefines));
|
||||||
}
|
}
|
||||||
} else if (cmdtok->str == "endif" && !sameline(tok, cmdtok->next)) {
|
} else if (cmdtok->str() == "endif" && !sameline(tok, cmdtok->next)) {
|
||||||
if (!configs_if.empty())
|
if (!configs_if.empty())
|
||||||
configs_if.pop_back();
|
configs_if.pop_back();
|
||||||
if (!configs_ifndef.empty())
|
if (!configs_ifndef.empty())
|
||||||
configs_ifndef.pop_back();
|
configs_ifndef.pop_back();
|
||||||
} else if (cmdtok->str == "error") {
|
} else if (cmdtok->str() == "error") {
|
||||||
if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) {
|
if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) {
|
||||||
if (configs_ifndef.size() == 1U)
|
if (configs_ifndef.size() == 1U)
|
||||||
ret.erase("");
|
ret.erase("");
|
||||||
|
@ -413,8 +413,8 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
||||||
elseError += cfg(configs, userDefines);
|
elseError += cfg(configs, userDefines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) {
|
} else if (cmdtok->str() == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) {
|
||||||
defined.insert(cmdtok->next->str);
|
defined.insert(cmdtok->next->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!elseError.empty())
|
if (!elseError.empty())
|
||||||
|
@ -652,7 +652,7 @@ std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std
|
||||||
}
|
}
|
||||||
if (!tok->macro.empty())
|
if (!tok->macro.empty())
|
||||||
ret << Preprocessor::macroChar;
|
ret << Preprocessor::macroChar;
|
||||||
ret << tok->str;
|
ret << tok->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret.str();
|
return ret.str();
|
||||||
|
@ -888,12 +888,12 @@ unsigned int Preprocessor::calculateChecksum(const simplecpp::TokenList &tokens1
|
||||||
ostr << toolinfo << '\n';
|
ostr << toolinfo << '\n';
|
||||||
for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) {
|
for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) {
|
||||||
if (!tok->comment)
|
if (!tok->comment)
|
||||||
ostr << tok->str;
|
ostr << tok->str();
|
||||||
}
|
}
|
||||||
for (std::map<std::string, simplecpp::TokenList *>::const_iterator it = tokenlists.begin(); it != tokenlists.end(); ++it) {
|
for (std::map<std::string, simplecpp::TokenList *>::const_iterator it = tokenlists.begin(); it != tokenlists.end(); ++it) {
|
||||||
for (const simplecpp::Token *tok = it->second->cfront(); tok; tok = tok->next) {
|
for (const simplecpp::Token *tok = it->second->cfront(); tok; tok = tok->next) {
|
||||||
if (!tok->comment)
|
if (!tok->comment)
|
||||||
ostr << tok->str;
|
ostr << tok->str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return crc32(ostr.str());
|
return crc32(ostr.str());
|
||||||
|
@ -917,11 +917,11 @@ void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const simplecpp::Token * const tok2 = tok->nextSkipComments();
|
const simplecpp::Token * const tok2 = tok->nextSkipComments();
|
||||||
if (!tok2 || !sameline(tok, tok2) || tok2->str != "pragma")
|
if (!tok2 || !sameline(tok, tok2) || tok2->str() != "pragma")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const simplecpp::Token * const tok3 = tok2->nextSkipComments();
|
const simplecpp::Token * const tok3 = tok2->nextSkipComments();
|
||||||
if (!tok3 || !sameline(tok, tok3) || tok3->str != "asm")
|
if (!tok3 || !sameline(tok, tok3) || tok3->str() != "asm")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const simplecpp::Token *endasm = tok3;
|
const simplecpp::Token *endasm = tok3;
|
||||||
|
@ -929,10 +929,10 @@ void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList)
|
||||||
if (endasm->op != '#' || sameline(endasm,endasm->previousSkipComments()))
|
if (endasm->op != '#' || sameline(endasm,endasm->previousSkipComments()))
|
||||||
continue;
|
continue;
|
||||||
const simplecpp::Token * const endasm2 = endasm->nextSkipComments();
|
const simplecpp::Token * const endasm2 = endasm->nextSkipComments();
|
||||||
if (!endasm2 || !sameline(endasm, endasm2) || endasm2->str != "pragma")
|
if (!endasm2 || !sameline(endasm, endasm2) || endasm2->str() != "pragma")
|
||||||
continue;
|
continue;
|
||||||
const simplecpp::Token * const endasm3 = endasm2->nextSkipComments();
|
const simplecpp::Token * const endasm3 = endasm2->nextSkipComments();
|
||||||
if (!endasm3 || !sameline(endasm2, endasm3) || endasm3->str != "endasm")
|
if (!endasm3 || !sameline(endasm2, endasm3) || endasm3->str() != "endasm")
|
||||||
continue;
|
continue;
|
||||||
while (sameline(endasm,endasm3))
|
while (sameline(endasm,endasm3))
|
||||||
endasm = endasm->next;
|
endasm = endasm->next;
|
||||||
|
|
|
@ -283,7 +283,7 @@ void TokenList::createTokens(const simplecpp::TokenList *tokenList)
|
||||||
|
|
||||||
for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) {
|
for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) {
|
||||||
|
|
||||||
std::string str = tok->str;
|
std::string str = tok->str();
|
||||||
|
|
||||||
// Replace hexadecimal value with decimal
|
// Replace hexadecimal value with decimal
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
|
|
Loading…
Reference in New Issue