Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building on MSVC #9

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ include(cmake/SettiUtils.cmake)
include(cmake/sanitize-helpers.cmake)
include(CheckCXXCompilerFlag)

CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_14)

include(cmake/CompilerWarnings.cmake)

if(MSVC)
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

SET(CMAKE_SKIP_BUILD_RPATH FALSE)

SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
Expand Down
24 changes: 24 additions & 0 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Set compiler warnings
add_library(project_warnings INTERFACE)

set(MSVC_WARNINGS
/W4)

set(CLANG_WARNINGS
-Wall
-Wextra)

set(GCC_WARNINGS
${CLANG_WARNINGS})

if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PROJECT_WARNINGS ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()

target_compile_options(project_warnings INTERFACE ${PROJECT_WARNINGS})
6 changes: 3 additions & 3 deletions src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ class Expression;

// Position of ast node on source code
struct Position {
uint line;
uint col;
unsigned int line;
unsigned int col;
};

const char* AstNodeStr(size_t i);

class AstNode {
public:
#define DECLARE_TYPE_ENUM(type) k##type,
enum class NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) };
enum class NodeType : unsigned int8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) };
#undef DECLARE_TYPE_ENUM

virtual ~AstNode() {}
Expand Down
10 changes: 5 additions & 5 deletions src/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Message {

Message() = delete;

Message(Severity severity, const boost::format& msg, uint line, uint pos)
Message(Severity severity, const boost::format& msg, unsigned int line, unsigned int pos)
: severity_(severity)
, msg_(msg)
, line_(line)
Expand Down Expand Up @@ -62,11 +62,11 @@ class Message {
return msg_.str();
}

uint line() {
unsigned int line() {
return line_;
}

uint pos() {
unsigned int pos() {
return pos_;
}

Expand All @@ -92,8 +92,8 @@ class Message {
private:
Severity severity_;
boost::format msg_;
uint line_;
uint pos_;
unsigned int line_;
unsigned int pos_;
std::string str_line_error_;
std::string file_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/objects/abstract-obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Object {
using Args = std::vector<std::shared_ptr<Object>>;
using KWArgs = std::unordered_map<std::string, std::shared_ptr<Object>>;

enum class ObjectType: uint8_t {
enum class ObjectType: unsigned int8_t {
ROOT,
NIL,
INT,
Expand Down
2 changes: 1 addition & 1 deletion src/parser/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string Lexer::ScanUnicodeEscapeCode() {

Back();

uint32_t hex_number = static_cast<uint32_t>(std::stoi(number,nullptr,16));
unsigned int32_t hex_number = static_cast<unsigned int32_t>(std::stoi(number,nullptr,16));

// initialize wstring with 1 wchar_t
std::wstring str_hex(1, static_cast<wchar_t>(hex_number));
Expand Down
14 changes: 7 additions & 7 deletions src/parser/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Lexer {

TokenStream Scanner();

inline uint NumErrors() noexcept {
inline unsigned int NumErrors() noexcept {
return nerror_;
}

Expand Down Expand Up @@ -174,13 +174,13 @@ class Lexer {
void ErrorMsg(const boost::format& fmt_msg);

std::string str_;
uint strlen_;
unsigned int strlen_;
char c_;
uint buffer_cursor_;
uint line_;
uint line_pos_;
uint start_pos_;
uint nerror_;
unsigned int buffer_cursor_;
unsigned int line_;
unsigned int line_pos_;
unsigned int start_pos_;
unsigned int nerror_;
Messages msgs_;

};
Expand Down
4 changes: 2 additions & 2 deletions src/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Parser {
return ParserExpCmd();
}

inline uint nerrors() const {
inline unsigned int nerrors() const {
return nerror_;
}

Expand Down Expand Up @@ -350,7 +350,7 @@ class Parser {

TokenStream ts_;
AstNodeFactory factory_;
uint nerror_;
unsigned int nerror_;
Token& token_;
Token token_error_;
Messages msgs_;
Expand Down
14 changes: 7 additions & 7 deletions src/parser/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ class Token {
public:
using Value = boost::variant<int, std::string, float, bool>;

Token(TokenKind k, Value value, bool blank_after, uint line, uint col)
Token(TokenKind k, Value value, bool blank_after, unsigned int line, unsigned int col)
: kind_(k)
, value_(value)
, blank_after_(blank_after)
, line_(line)
, col_(col) {}

Token(TokenKind k, const char* value, bool blank_after, uint line, uint col)
Token(TokenKind k, const char* value, bool blank_after, unsigned int line, unsigned int col)
: kind_(k)
, value_(std::string(value))
, blank_after_(blank_after)
, line_(line)
, col_(col) {}

Token(TokenKind k, bool blank_after, uint line, uint col)
Token(TokenKind k, bool blank_after, unsigned int line, unsigned int col)
: kind_(k)
, value_(std::string(token_value_str[static_cast<int>(k)]))
, blank_after_(blank_after)
Expand Down Expand Up @@ -143,9 +143,9 @@ class Token {

bool BlankAfter() const noexcept { return blank_after_; }

uint Line() const noexcept { return line_; }
unsigned int Line() const noexcept { return line_; }

uint Col() const noexcept { return col_; }
unsigned int Col() const noexcept { return col_; }

bool Is(TokenKind k) const noexcept { return kind_ == k; }

Expand Down Expand Up @@ -264,8 +264,8 @@ class Token {
TokenKind kind_;
Value value_;
bool blank_after_;
uint line_;
uint col_;
unsigned int line_;
unsigned int col_;
};

inline std::ostream& operator<<(std::ostream& stream, Token& token) {
Expand Down
2 changes: 1 addition & 1 deletion src/run_time_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace internal {
*/
class RunTimeError : public std::exception {
public:
enum class ErrorCode: uint8_t{
enum class ErrorCode: unsigned int8_t{
NULL_ACCESS,
SYMBOL_NOT_FOUND,
BAD_ALLOC,
Expand Down