Skip to content

Commit

Permalink
Develop 2.0 - Added Unit test (#59)
Browse files Browse the repository at this point in the history
* checkpoint - changed structure

* changed structure again!

* working checkpoint

* yahh done with restructuring hopefully !

* added string wasm and reformtting web code

* fix codacy errors

* checkpoint

* frontend done!

* trying to mke things better and adding tests

* fixing quality

* fixing javascript

* prettier
  • Loading branch information
jnyfah authored Oct 28, 2024
1 parent e8f1434 commit 87b9b27
Show file tree
Hide file tree
Showing 32 changed files with 1,653 additions and 1,208 deletions.
20 changes: 11 additions & 9 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
Language: Cpp
# Base style
BasedOnStyle: LLVM

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
NamespaceIndentation: None

# Line breaking
ColumnLimit: 100
ColumnLimit: 120
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

# Alignment
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignOperands: true
AlignTrailingComments: true

# Spacing
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
Expand All @@ -34,8 +30,14 @@ SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Other
PointerAlignment: Left
SortIncludes: true
FixNamespaceComments: true
FixNamespaceComments: true
# Added options
BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: true
BreakConstructorInitializersBeforeComma: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
AllowAllConstructorInitializersOnNextLine: true
52 changes: 0 additions & 52 deletions .github/workflows/msvc.yml

This file was deleted.

113 changes: 71 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,104 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# -------------------- Set Compiler Warnings --------------------------------
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
# -------------------- Compiler Warnings --------------------------------
if(NOT EMSCRIPTEN)
if(MSVC)
add_compile_options(/W4 /WX /MP)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
else()
add_compile_options(
-Wall -Wextra -Wpedantic -Werror
-Wno-unused-parameter
-Wno-missing-field-initializers
)
endif()
endif()

# -------------------- Fetch Json component --------------------------------
# -------------------- FetchContent Setup --------------------------------
include(FetchContent)

FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG master
GIT_TAG master
)
FetchContent_MakeAvailable(json)

# -------------------- Specify the source files for each component --------------------------------
set(SOURCES_LEXER
CuriousX/Lexer/LexerToken.cpp
)

set(SOURCES_PARSER
CuriousX/Parser/Parser.cpp
)

set(SOURCES_SEMANTIC
CuriousX/Semantic/Semantic.cpp
)

set(SOURCES_GEN
CuriousX/Gen/Codegen.cpp
)
FetchContent_GetProperties(json)
if(NOT json_POPULATED)
FetchContent_MakeAvailable(json)
endif()

# -------------------- Build Tests Option --------------------------------
option(BUILD_TESTS "Build tests" OFF)
message(STATUS "[STX] Build tests: ${BUILD_TESTS}")

#------------ Include Utility Folder--------------------------------
# -------------------- Include Utility Folder --------------------------------
add_library(CompilerUtils INTERFACE)
target_include_directories(CompilerUtils INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/CompilerUtils)

# -------------------- Include Lexer Folder--------------------------------
# -------------------- Include Lexer --------------------------------
set(SOURCES_LEXER CuriousX/Lexer/LexerToken.cpp)
add_library(Lexer STATIC ${SOURCES_LEXER})
target_include_directories(Lexer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Lexer)
target_link_libraries(Lexer PUBLIC CompilerUtils nlohmann_json::nlohmann_json)

# -------------------- Include CodeGen Folder--------------------------------
add_library(Gen STATIC ${SOURCES_GEN})
target_include_directories(Gen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Gen)
target_link_libraries(Gen PUBLIC Lexer)
# -------------------- Include Parser --------------------------------
set(SOURCES_PARSER CuriousX/Parser/Parser.cpp)
add_library(Parser STATIC ${SOURCES_PARSER})
target_include_directories(Parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Parser)
target_link_libraries(Parser PUBLIC Lexer)

# -------------------- Include Semantic Folder--------------------------------
# -------------------- Include Semantic Analyzer --------------------------------
set(SOURCES_SEMANTIC CuriousX/Semantic/Semantic.cpp)
add_library(Semantic STATIC ${SOURCES_SEMANTIC})
target_include_directories(Semantic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Semantic)
target_link_libraries(Semantic PUBLIC Gen)
target_link_libraries(Semantic PUBLIC Parser)

# -------------------- Include Parser Folder--------------------------------
add_library(Parser STATIC ${SOURCES_PARSER})
target_include_directories(Parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Parser)
target_link_libraries(Parser PUBLIC Semantic)
# -------------------- Include Code Generator --------------------------------
set(SOURCES_GEN CuriousX/Generation/Codegen.cpp)
add_library(Gen STATIC ${SOURCES_GEN})
target_include_directories(Gen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX/Generation)
target_link_libraries(Gen PUBLIC Semantic)

# -------------------- Include Compiler Core --------------------------------
add_library(Compiler STATIC CuriousX/Compiler.cpp)
target_include_directories(Compiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX)
target_link_libraries(Compiler PUBLIC Parser Semantic Gen)

# -------------------- Create the main executable and link it to the libraries --------------------------------
add_executable(CuriousX "CuriousX/main.cpp")
target_link_libraries(CuriousX PRIVATE Parser)
# -------------------- Main Executable --------------------------------
add_executable(CuriousX CuriousX/main.cpp)
target_include_directories(CuriousX PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CuriousX)
target_link_libraries(CuriousX PRIVATE Compiler)

# -------------------- Tests --------------------------------
if(BUILD_TESTS)
FetchContent_Declare(
gtest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
)

FetchContent_GetProperties(gtest)
if(NOT gtest_POPULATED)
FetchContent_MakeAvailable(gtest)
endif()

include(CTest)
enable_testing()

file(GLOB SOURCES_tests tests/*.cpp)
add_executable(curiousx_tests ${SOURCES_tests})
target_include_directories(curiousx_tests PRIVATE ${CMAKE_SOURCE_DIR}/CuriousX ${CMAKE_SOURCE_DIR}/CompilerUtils)
target_link_libraries(curiousx_tests PRIVATE GTest::gtest GTest::gtest_main Compiler)
add_test(NAME CuriousxTests COMMAND curiousx_tests)
endif()

# -------------------- Emscripten Support --------------------------------
if(EMSCRIPTEN)
set_target_properties(CuriousX PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/CompilerEditor"
LINK_FLAGS "--bind -s DISABLE_EXCEPTION_CATCHING=0"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/CompilerEditor"
)
endif()
target_link_options(CuriousX PRIVATE --bind -s DISABLE_EXCEPTION_CATCHING=0)
message(STATUS "Building with Emscripten support")
endif()
Loading

0 comments on commit 87b9b27

Please sign in to comment.