Update simplecpp
This commit is contained in:
parent
d0bbd0535f
commit
d488467664
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
|
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
|
||||||
|
#define SIMPLECPP_WINDOWS
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif
|
#endif
|
||||||
#include "simplecpp.h"
|
#include "simplecpp.h"
|
||||||
|
@ -33,11 +34,10 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
|
#ifdef SIMPLECPP_WINDOWS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#undef ERROR
|
#undef ERROR
|
||||||
#undef TRUE
|
#undef TRUE
|
||||||
#define SIMPLECPP_WINDOWS
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool isHex(const std::string &s)
|
static bool isHex(const std::string &s)
|
||||||
|
@ -338,7 +338,7 @@ static unsigned short getAndSkipBOM(std::istream &istr)
|
||||||
|
|
||||||
// Skip UTF-8 BOM 0xefbbbf
|
// Skip UTF-8 BOM 0xefbbbf
|
||||||
if (ch1 == 0xef) {
|
if (ch1 == 0xef) {
|
||||||
istr.get();
|
(void)istr.get();
|
||||||
if (istr.get() == 0xbb && istr.peek() == 0xbf) {
|
if (istr.get() == 0xbb && istr.peek() == 0xbf) {
|
||||||
(void)istr.get();
|
(void)istr.get();
|
||||||
} else {
|
} else {
|
||||||
|
@ -699,6 +699,7 @@ void simplecpp::TokenList::combineOperators()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const std::string COMPL("compl");
|
||||||
static const std::string NOT("not");
|
static const std::string NOT("not");
|
||||||
void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
|
void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
|
||||||
{
|
{
|
||||||
|
@ -706,10 +707,16 @@ void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
|
||||||
// "not" might be !
|
// "not" might be !
|
||||||
if (isAlternativeUnaryOp(tok, NOT))
|
if (isAlternativeUnaryOp(tok, NOT))
|
||||||
tok->op = '!';
|
tok->op = '!';
|
||||||
|
// "compl" might be ~
|
||||||
|
else if (isAlternativeUnaryOp(tok, COMPL))
|
||||||
|
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) {
|
||||||
|
tok->setstr(toString(~stringToLL(tok->next->str)));
|
||||||
|
deleteToken(tok->next);
|
||||||
} else {
|
} else {
|
||||||
if (tok->previous && (tok->previous->number || tok->previous->name))
|
if (tok->previous && (tok->previous->number || tok->previous->name))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1662,7 +1669,12 @@ namespace simplecpp {
|
||||||
|
|
||||||
if (varargs && tokensB.empty() && tok->previous->str == ",")
|
if (varargs && tokensB.empty() && tok->previous->str == ",")
|
||||||
output->deleteToken(A);
|
output->deleteToken(A);
|
||||||
else {
|
else if (strAB != "," && macros.find(strAB) == macros.end()) {
|
||||||
|
A->setstr(strAB);
|
||||||
|
for (Token *b = tokensB.front(); b; b = b->next)
|
||||||
|
b->location = loc;
|
||||||
|
output->takeTokens(tokensB);
|
||||||
|
} else {
|
||||||
output->deleteToken(A);
|
output->deleteToken(A);
|
||||||
TokenList tokens(files);
|
TokenList tokens(files);
|
||||||
tokens.push_back(new Token(strAB, tok->location));
|
tokens.push_back(new Token(strAB, tok->location));
|
||||||
|
@ -1738,15 +1750,11 @@ static bool realFileName(const std::string &f, std::string *result)
|
||||||
if (!alpha)
|
if (!alpha)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Convert char path to CHAR path
|
|
||||||
std::vector<CHAR> buf(f.size()+1U, 0);
|
|
||||||
for (unsigned int i = 0; i < f.size(); ++i)
|
|
||||||
buf[i] = f[i];
|
|
||||||
|
|
||||||
// Lookup filename or foldername on file system
|
// Lookup filename or foldername on file system
|
||||||
WIN32_FIND_DATAA FindFileData;
|
WIN32_FIND_DATAA FindFileData;
|
||||||
HANDLE hFind = FindFirstFileA(&buf[0], &FindFileData);
|
HANDLE hFind = FindFirstFileExA(f.c_str(), FindExInfoBasic, &FindFileData, FindExSearchNameMatch, NULL, 0);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
|
||||||
|
if (INVALID_HANDLE_VALUE == hFind)
|
||||||
return false;
|
return false;
|
||||||
*result = FindFileData.cFileName;
|
*result = FindFileData.cFileName;
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
|
@ -1821,6 +1829,9 @@ namespace simplecpp {
|
||||||
*/
|
*/
|
||||||
std::string simplifyPath(std::string path)
|
std::string simplifyPath(std::string path)
|
||||||
{
|
{
|
||||||
|
if (path.empty())
|
||||||
|
return path;
|
||||||
|
|
||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
|
|
||||||
// replace backslash separators
|
// replace backslash separators
|
||||||
|
@ -1929,15 +1940,15 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const altopData[] = {"and","or","bitand","bitor","not","not_eq","xor"};
|
static const char * const altopData[] = {"and","or","bitand","bitor","compl","not","not_eq","xor"};
|
||||||
static const std::set<std::string> altop(&altopData[0], &altopData[7]);
|
static const std::set<std::string> altop(&altopData[0], &altopData[8]);
|
||||||
static void simplifyName(simplecpp::TokenList &expr)
|
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") {
|
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);
|
||||||
|
@ -2016,6 +2027,9 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
|
||||||
|
|
||||||
static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)
|
static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)
|
||||||
{
|
{
|
||||||
|
if (filedata.empty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if (isAbsolutePath(header)) {
|
if (isAbsolutePath(header)) {
|
||||||
return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : "";
|
return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,6 +275,10 @@ namespace simplecpp {
|
||||||
Location useLocation;
|
Location useLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command line preprocessor settings.
|
||||||
|
* On the command line these are configured by -D, -U, -I, --include
|
||||||
|
*/
|
||||||
struct SIMPLECPP_LIB DUI {
|
struct SIMPLECPP_LIB DUI {
|
||||||
DUI() {}
|
DUI() {}
|
||||||
std::list<std::string> defines;
|
std::list<std::string> defines;
|
||||||
|
|
Loading…
Reference in New Issue