Bump simplecpp
This commit is contained in:
parent
45ba1ff1e3
commit
a1081f961c
|
@ -43,91 +43,90 @@
|
||||||
#define SIMPLECPP_WINDOWS
|
#define SIMPLECPP_WINDOWS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool isHex(const std::string &s) {
|
static bool isHex(const std::string &s)
|
||||||
|
{
|
||||||
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
|
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
const simplecpp::TokenString DEFINE("define");
|
|
||||||
const simplecpp::TokenString UNDEF("undef");
|
|
||||||
|
|
||||||
const simplecpp::TokenString INCLUDE("include");
|
static const simplecpp::TokenString DEFINE("define");
|
||||||
|
static const simplecpp::TokenString UNDEF("undef");
|
||||||
|
|
||||||
const simplecpp::TokenString ERROR("error");
|
static const simplecpp::TokenString INCLUDE("include");
|
||||||
const simplecpp::TokenString WARNING("warning");
|
|
||||||
|
|
||||||
const simplecpp::TokenString IF("if");
|
static const simplecpp::TokenString ERROR("error");
|
||||||
const simplecpp::TokenString IFDEF("ifdef");
|
static const simplecpp::TokenString WARNING("warning");
|
||||||
const simplecpp::TokenString IFNDEF("ifndef");
|
|
||||||
const simplecpp::TokenString DEFINED("defined");
|
|
||||||
const simplecpp::TokenString ELSE("else");
|
|
||||||
const simplecpp::TokenString ELIF("elif");
|
|
||||||
const simplecpp::TokenString ENDIF("endif");
|
|
||||||
|
|
||||||
const simplecpp::TokenString PRAGMA("pragma");
|
static const simplecpp::TokenString IF("if");
|
||||||
const simplecpp::TokenString ONCE("once");
|
static const simplecpp::TokenString IFDEF("ifdef");
|
||||||
|
static const simplecpp::TokenString IFNDEF("ifndef");
|
||||||
|
static const simplecpp::TokenString DEFINED("defined");
|
||||||
|
static const simplecpp::TokenString ELSE("else");
|
||||||
|
static const simplecpp::TokenString ELIF("elif");
|
||||||
|
static const simplecpp::TokenString ENDIF("endif");
|
||||||
|
|
||||||
template<class T> std::string toString(T t)
|
static const simplecpp::TokenString PRAGMA("pragma");
|
||||||
{
|
static const simplecpp::TokenString ONCE("once");
|
||||||
std::ostringstream ostr;
|
|
||||||
ostr << t;
|
|
||||||
return ostr.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
long long stringToLL(const std::string &s)
|
template<class T> static std::string toString(T t)
|
||||||
{
|
{
|
||||||
long long ret;
|
std::ostringstream ostr;
|
||||||
const bool hex = isHex(s);
|
ostr << t;
|
||||||
std::istringstream istr(hex ? s.substr(2) : s);
|
return ostr.str();
|
||||||
if (hex)
|
}
|
||||||
istr >> std::hex;
|
|
||||||
istr >> ret;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long long stringToULL(const std::string &s)
|
static long long stringToLL(const std::string &s)
|
||||||
{
|
{
|
||||||
unsigned long long ret;
|
long long ret;
|
||||||
const bool hex = isHex(s);
|
const bool hex = isHex(s);
|
||||||
std::istringstream istr(hex ? s.substr(2) : s);
|
std::istringstream istr(hex ? s.substr(2) : s);
|
||||||
if (hex)
|
if (hex)
|
||||||
istr >> std::hex;
|
istr >> std::hex;
|
||||||
istr >> ret;
|
istr >> ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startsWith(const std::string &str, const std::string &s)
|
static unsigned long long stringToULL(const std::string &s)
|
||||||
{
|
{
|
||||||
return (str.size() >= s.size() && str.compare(0, s.size(), s) == 0);
|
unsigned long long ret;
|
||||||
}
|
const bool hex = isHex(s);
|
||||||
|
std::istringstream istr(hex ? s.substr(2) : s);
|
||||||
|
if (hex)
|
||||||
|
istr >> std::hex;
|
||||||
|
istr >> ret;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool endsWith(const std::string &s, const std::string &e)
|
static bool startsWith(const std::string &str, const std::string &s)
|
||||||
{
|
{
|
||||||
return (s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0);
|
return (str.size() >= s.size() && str.compare(0, s.size(), s) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
|
static bool endsWith(const std::string &s, const std::string &e)
|
||||||
{
|
{
|
||||||
return tok1 && tok2 && tok1->location.sameline(tok2->location);
|
return (s.size() >= e.size() && s.compare(s.size() - e.size(), e.size(), e) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
|
||||||
|
{
|
||||||
|
return tok1 && tok2 && tok1->location.sameline(tok2->location);
|
||||||
|
}
|
||||||
|
|
||||||
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 == ')') &&
|
||||||
(tok->next->number || tok->next->name || tok->next->op == '('));
|
(tok->next->number || tok->next->name || tok->next->op == '('));
|
||||||
}
|
}
|
||||||
|
|
||||||
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)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplecpp::Location::adjust(const std::string &str)
|
void simplecpp::Location::adjust(const std::string &str)
|
||||||
|
@ -353,7 +352,7 @@ static unsigned short getAndSkipBOM(std::istream &istr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNameChar(unsigned char ch)
|
static bool isNameChar(unsigned char ch)
|
||||||
{
|
{
|
||||||
return std::isalnum(ch) || ch == '_' || ch == '$';
|
return std::isalnum(ch) || ch == '_' || ch == '$';
|
||||||
}
|
}
|
||||||
|
@ -591,12 +590,12 @@ void simplecpp::TokenList::constFold()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isFloatSuffix(const simplecpp::Token *tok) {
|
static bool isFloatSuffix(const simplecpp::Token *tok)
|
||||||
if (!tok || tok->str.size() > 2)
|
{
|
||||||
|
if (!tok || tok->str.size() != 1U)
|
||||||
return false;
|
return false;
|
||||||
std::string s = tok->str;
|
const char c = std::tolower(tok->str[0]);
|
||||||
std::transform(s.begin(), s.end(), s.begin(), static_cast<int (*)(int)>(std::tolower));
|
return c == 'f' || c == 'l';
|
||||||
return s == "lf" || s == "f";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplecpp::TokenList::combineOperators()
|
void simplecpp::TokenList::combineOperators()
|
||||||
|
@ -1661,6 +1660,10 @@ namespace simplecpp {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
std::string::size_type sep = 0;
|
std::string::size_type sep = 0;
|
||||||
while ((sep = f.find_first_of("\\/", sep + 1U)) != std::string::npos) {
|
while ((sep = f.find_first_of("\\/", sep + 1U)) != std::string::npos) {
|
||||||
|
if (sep >= 2 && f.compare(sep-2,2,"..",0,2) == 0) {
|
||||||
|
ostr << "../";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buf[sep] = 0;
|
buf[sep] = 0;
|
||||||
if (!realFileName(buf,ostr))
|
if (!realFileName(buf,ostr))
|
||||||
return f;
|
return f;
|
||||||
|
|
Loading…
Reference in New Issue