diff --git a/.clang-format b/.clang-format index a5c6b03..d18ac33 100644 --- a/.clang-format +++ b/.clang-format @@ -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 @@ -34,8 +30,14 @@ SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false SpacesInParentheses: false SpacesInSquareBrackets: false - # Other PointerAlignment: Left SortIncludes: true -FixNamespaceComments: true \ No newline at end of file +FixNamespaceComments: true +# Added options +BinPackArguments: false +BinPackParameters: false +AllowAllParametersOfDeclarationOnNextLine: true +BreakConstructorInitializersBeforeComma: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true +AllowAllConstructorInitializersOnNextLine: true \ No newline at end of file diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc.yml deleted file mode 100644 index 474f570..0000000 --- a/.github/workflows/msvc.yml +++ /dev/null @@ -1,52 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# -# Find more information at: -# https://github.com/microsoft/msvc-code-analysis-action - -name: C++ Code Analysis - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - schedule: - - cron: '22 23 * * 3' - -env: - BUILD_TYPE: Debug - BUILD_DIR: '${{ github.workspace }}/build' - -jobs: - analyze: - name: Analyze - runs-on: windows-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Configure CMake - run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }} - - - name: Run MSVC Code Analysis - uses: microsoft/msvc-code-analysis-action@v0.1.1 - id: run-analysis - with: - cmakeBuildDirectory: ${{ env.BUILD_DIR }} - buildConfiguration: ${{ env.BUILD_TYPE }} - ruleset: NativeRecommendedRules.ruleset - - - name: Upload SARIF to GitHub - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: ${{ steps.run-analysis.outputs.sarif }} - - - name: Upload SARIF as an Artifact - uses: actions/upload-artifact@v2 - with: - name: sarif-file - path: ${{ steps.run-analysis.outputs.sarif }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 40e06a1..68ca144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() \ No newline at end of file + target_link_options(CuriousX PRIVATE --bind -s DISABLE_EXCEPTION_CATCHING=0) + message(STATUS "Building with Emscripten support") +endif() diff --git a/CompilerEditor/index.html b/CompilerEditor/index.html index 3e549a3..706bdae 100644 --- a/CompilerEditor/index.html +++ b/CompilerEditor/index.html @@ -1,89 +1,135 @@ - + +
-