c++17 to c++20

This commit is contained in:
Louis Rubet 2022-03-31 10:40:45 +02:00
parent 3fb1201220
commit f8f42889bf
2 changed files with 21 additions and 18 deletions

View file

@ -80,10 +80,13 @@ ${PROJECT_SOURCE_DIR}/linenoise-ng/src/wcwidth.cpp)
set_source_files_properties(${RPN_SRC_FILES} COMPILE_FLAGS # some harder warnings
"-Wall -Wextra -pedantic -Wno-missing-field-initializers")
set_source_files_properties(${LINENOISE_NG_SRC_FILES} COMPILE_FLAGS
"-fpermissive") # removing error on redeclaration of char8_t
if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Compiler type GNU: ${CMAKE_CXX_COMPILER}")
# TODO still up to date?
set(BASE_COMPILER_OPTIONS "-std=c++17 -Wl,--no-as-needed")
set(BASE_COMPILER_OPTIONS "-std=c++20 -Wl,--no-as-needed")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILER_OPTIONS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BASE_COMPILER_OPTIONS} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BASE_COMPILER_OPTIONS} -O3 -s")

View file

@ -58,13 +58,13 @@ bool Lexer::ParseString(const string& entry, size_t idx, size_t& next_idx, vecto
for (size_t i = idx + 1; i < entry.size(); i++) {
if (entry[i] == '"') {
if (entry[i] - 1 != '\\') {
elements.push_back({kString, .value = entry.substr(idx + 1, i - idx - 1)});
elements.push_back({.type = kString, .value = entry.substr(idx + 1, i - idx - 1)});
next_idx = i + 1;
return true;
}
}
}
elements.push_back({kString, .value = entry.substr(idx + 1, entry.size() - idx - 1)});
elements.push_back({.type = kString, .value = entry.substr(idx + 1, entry.size() - idx - 1)});
next_idx = entry.size();
return true;
}
@ -74,12 +74,12 @@ bool Lexer::ParseSymbol(const string& entry, size_t idx, size_t& next_idx, vecto
// here we are sure that entry[0] is at least '\''
for (size_t i = idx + 1; i < entry.size(); i++) {
if (entry[i] == '\'') {
elements.push_back({kSymbol, .value = entry.substr(idx + 1, i - idx - 1), .auto_eval = false});
elements.push_back({.type = kSymbol, .value = entry.substr(idx + 1, i - idx - 1), .auto_eval = false});
next_idx = i + 1;
return true;
}
}
elements.push_back({kSymbol, .value = entry.substr(idx + 1, entry.size() - idx - 1)});
elements.push_back({.type = kSymbol, .value = entry.substr(idx + 1, entry.size() - idx - 1)});
next_idx = entry.size();
return true;
}
@ -96,7 +96,7 @@ bool Lexer::ParseProgram(const string& entry, size_t idx, size_t& next_idx, vect
if (countNested == 0) {
string prg = entry.substr(idx + 2, i - idx - 2);
Trim(prg);
elements.push_back({kProgram, .value = prg});
elements.push_back({.type = kProgram, .value = prg});
next_idx = i + 2;
return true;
} else {
@ -106,7 +106,7 @@ bool Lexer::ParseProgram(const string& entry, size_t idx, size_t& next_idx, vect
}
string prg = entry.substr(idx + 2, entry.size() - idx - 2);
Trim(prg);
elements.push_back({kProgram, .value = prg});
elements.push_back({.type = kProgram, .value = prg});
next_idx = entry.size();
return true;
}
@ -186,8 +186,8 @@ bool Lexer::ParseNumber(const string& entry, size_t idx, size_t& next_idx, vecto
vector<SynElement>& elements) {
mpreal* r = nullptr;
int base = 10;
if (GetNumberAt(entry, idx, next_idx, base, &r)) {
elements.push_back({kNumber, .re = r, .re_base = base});
if (GetNUmberAt(entry, idx, next_idx, base, &r)) {
elements.push_back({.type = kNumber, .re = r, .re_base = base});
return true;
} else {
errors.push_back({entry.size(), "unterminated number"});
@ -201,33 +201,33 @@ bool Lexer::ParseComplex(const string& entry, size_t idx, size_t& next_idx, vect
mpreal* im = nullptr;
int re_base, im_base = 10;
if (idx + 1 == entry.size()) {
elements.push_back({kSymbol, .value = entry.substr(idx, entry.size() - idx)});
elements.push_back({.type = kSymbol, .value = entry.substr(idx, entry.size() - idx)});
next_idx = entry.size();
return true; // complex format error, return a symbol
}
if (!GetNumberAt(entry, idx + 1, next_idx, re_base, &re, ',')) {
elements.push_back({kSymbol, .value = entry.substr(idx, entry.size() - idx)});
if (!GetNUmberAt(entry, idx + 1, next_idx, re_base, &re, ',')) {
elements.push_back({.type = kSymbol, .value = entry.substr(idx, entry.size() - idx)});
next_idx = entry.size();
return true; // complex format error, return a symbol
}
size_t i = next_idx;
if (i >= entry.size()) {
elements.push_back({kSymbol, .value = entry.substr(idx, entry.size() - idx)});
elements.push_back({.type = kSymbol, .value = entry.substr(idx, entry.size() - idx)});
next_idx = entry.size();
if (re != nullptr) delete re;
if (im != nullptr) delete im;
return true; // complex format error, return a symbol
}
if (!GetNumberAt(entry, i, next_idx, im_base, &im, ')')) {
elements.push_back({kSymbol, .value = entry.substr(idx, entry.size() - idx)});
if (!GetNUmberAt(entry, i, next_idx, im_base, &im, ')')) {
elements.push_back({.type = kSymbol, .value = entry.substr(idx, entry.size() - idx)});
next_idx = entry.size();
if (re != nullptr) delete re;
if (im != nullptr) delete im;
return true; // complex format error, return a symbol
}
elements.push_back({kComplex, .re = re, .im = im, .re_base = re_base, .im_base = im_base});
elements.push_back({.type = kComplex, .re = re, .im = im, .re_base = re_base, .im_base = im_base});
next_idx++;
return true;
}
@ -240,7 +240,7 @@ bool Lexer::ParseReserved(const string& entry, size_t idx, size_t& next_idx, vec
auto resa = keywords.find(token);
if (resa != keywords.end()) {
elements.push_back({resa->second.type, .value = token, .fn = resa->second.fn});
elements.push_back({.type = resa->second.type, .value = token, .fn = resa->second.fn});
next_idx = token.size() + idx;
return true;
}
@ -251,7 +251,7 @@ bool Lexer::ParseUnknown(const string& entry, size_t idx, size_t& next_idx, vect
stringstream ss(entry.substr(idx));
string token;
ss >> token;
elements.push_back({kSymbol, .value = token, .auto_eval = true});
elements.push_back({.type = kSymbol, .value = token, .auto_eval = true});
next_idx = token.size() + idx;
return true;
}