Require Clang 13.0+ in the CMakeLists.txt file, import the tok::type enumeration in lexer.cpp + Parser.hpp, and add [[likely]] attributes to 2 branches of the switch case in lexer.cpp.
This commit is contained in:
parent
3c703e55b5
commit
3b991da962
|
@ -35,9 +35,6 @@ if (NOT MSVC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang))
|
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang))
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
|
|
||||||
message(WARNING "A ${CMAKE_CXX_COMPILER_ID} compiler version of preferably 11 or higher should be used.")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
|
||||||
set(CMAKE_CXX_FLAGS "-flto ${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong -fstack-clash-protection")
|
set(CMAKE_CXX_FLAGS "-flto ${CMAKE_CXX_FLAGS} -pipe -fstack-protector-strong -fstack-clash-protection")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize")
|
||||||
|
@ -49,9 +46,15 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUA
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
|
||||||
|
message(WARNING "A GNU compiler version of preferably 11 or higher should be used.")
|
||||||
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fipa-pta -fivopts -s")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fipa-pta -fivopts -s")
|
||||||
set(CMAKE_CXX_FLAGS "-fno-use-linker-plugin -fwhole-program ${CMAKE_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "-fno-use-linker-plugin -fwhole-program ${CMAKE_CXX_FLAGS}")
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0)
|
||||||
|
message(FATAL_ERROR "Clang 13.0 or higher is required.")
|
||||||
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
set(CMAKE_CXX_FLAGS "-fwhole-program-vtables ${CMAKE_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "-fwhole-program-vtables ${CMAKE_CXX_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "../headers/lex.hpp"
|
#include "../headers/lex.hpp"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using enum tok::type;
|
||||||
|
|
||||||
tok::type getIdentifierCharType(const char& Char) {
|
tok::type getIdentifierCharType(const char& Char) {
|
||||||
if (isalpha(Char)) return tok::IDENTIFIER;
|
if (isalpha(Char)) return IDENTIFIER;
|
||||||
else if (isdigit(Char)) return tok::NUMBER;
|
else if (isdigit(Char)) return NUMBER;
|
||||||
else if (Char == '"') return tok::STRING;
|
else if (Char == '"') return STRING;
|
||||||
else return tok::UNEXPECTED;
|
else return UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<tok> lex(const string& in)
|
vector<tok> lex(const string& in)
|
||||||
|
@ -13,24 +14,25 @@ vector<tok> lex(const string& in)
|
||||||
vector<tok> resVal;
|
vector<tok> resVal;
|
||||||
for (unsigned int i = 0; i < in.size(); ++i) {
|
for (unsigned int i = 0; i < in.size(); ++i) {
|
||||||
const char& current = in[i];
|
const char& current = in[i];
|
||||||
|
|
||||||
switch (current) {
|
switch (current) {
|
||||||
case tok::TAG: case tok::DEFINE: case tok::LPAR: case tok::RPAR:
|
case TAG: case DEFINE: case LPAR: case RPAR:
|
||||||
case tok::LBRACE: case tok::RBRACE: case tok::LBRACKET: case tok::RBRACKET:
|
case LBRACE: case RBRACE: case LBRACKET: case RBRACKET:
|
||||||
case tok::PLUS: case tok::HYPHEN: case tok::LCOMP: case tok::RCOMP:
|
case PLUS: case HYPHEN: case LCOMP: case RCOMP:
|
||||||
case '$': case '\'': resVal.emplace_back(static_cast<tok::type>(current), string(1, current));
|
case '$': case '\'': resVal.emplace_back(static_cast<tok::type>(current), string(1, current));
|
||||||
case ' ': case '\t': case '\r':
|
[[likely]] case ' ': case '\t': case '\r':
|
||||||
case '\n': break;
|
[[likely]] case '\n': break;
|
||||||
default: {
|
default: {
|
||||||
tok::type type = getIdentifierCharType(current);
|
tok::type type = getIdentifierCharType(current);
|
||||||
bool isTypeString = (type == tok::STRING);
|
bool isTypeString = (type == STRING);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case tok::UNEXPECTED: break;
|
case UNEXPECTED: break;
|
||||||
case tok::STRING: ++i;
|
case STRING: ++i;
|
||||||
case tok::IDENTIFIER: case tok::NUMBER: {
|
case IDENTIFIER: case NUMBER: {
|
||||||
string formedString;
|
string formedString;
|
||||||
for (;i < in.size(); ++i) {
|
for (;i < in.size(); ++i) {
|
||||||
tok::type currentCharType = getIdentifierCharType(in[i]);
|
tok::type currentCharType = getIdentifierCharType(in[i]);
|
||||||
bool isString = currentCharType == tok::STRING;
|
bool isString = currentCharType == STRING;
|
||||||
if (i == in.size() - 1 && not isString) throw tok::LexerException("A never ending string was found");
|
if (i == in.size() - 1 && not isString) throw tok::LexerException("A never ending string was found");
|
||||||
if ((currentCharType == type || isTypeString) && !isString) {
|
if ((currentCharType == type || isTypeString) && !isString) {
|
||||||
formedString += string(1, in[i]);
|
formedString += string(1, in[i]);
|
||||||
|
|
|
@ -12,20 +12,21 @@ namespace Parser {
|
||||||
ParseTree parseVector(const vector<tok>& lexed) {
|
ParseTree parseVector(const vector<tok>& lexed) {
|
||||||
ParseTree parseTree;
|
ParseTree parseTree;
|
||||||
using namespace StandardComponents;
|
using namespace StandardComponents;
|
||||||
|
using enum tok::type;
|
||||||
if (lexed.size() > 1) {
|
if (lexed.size() > 1) {
|
||||||
for (unsigned int i = 0; i < lexed.size() - 1; ++i) {
|
for (unsigned int i = 0; i < lexed.size() - 1; ++i) {
|
||||||
const auto& current = lexed[i], next = lexed[i + 1];
|
const auto& current = lexed[i], next = lexed[i + 1];
|
||||||
|
|
||||||
switch (current.toktype) {
|
switch (current.toktype) {
|
||||||
case tok::STRING: parseTree << types::String(current.toktext.data()); break;
|
case STRING: parseTree << types::String(current.toktext.data()); break;
|
||||||
case tok::IDENTIFIER: {
|
case IDENTIFIER: {
|
||||||
if (current.toktext == "class") {
|
if (current.toktext == "class") {
|
||||||
if (next.toktype == tok::IDENTIFIER) {
|
if (next.toktype == IDENTIFIER) {
|
||||||
parseTree << Class(next.toktext); ++i;
|
parseTree << Class(next.toktext); ++i;
|
||||||
} else throw ParsingException('"' + next.toktext + "\" is not a valid class identifier");
|
} else throw ParsingException('"' + next.toktext + "\" is not a valid class identifier");
|
||||||
} else {
|
} else {
|
||||||
const bool isFinalDefine = next.toktype == tok::TAG && (lexed.size() - i) > 2 && lexed[i + 2].toktype == tok::DEFINE;
|
const bool isFinalDefine = next.toktype == TAG && (lexed.size() - i) > 2 && lexed[i + 2].toktype == DEFINE;
|
||||||
if (isFinalDefine || next.toktype == tok::DEFINE) {
|
if (isFinalDefine || next.toktype == DEFINE) {
|
||||||
parseTree << Define(isFinalDefine, current.toktext);
|
parseTree << Define(isFinalDefine, current.toktext);
|
||||||
i += isFinalDefine ? 2 : 1;
|
i += isFinalDefine ? 2 : 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue