Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5d3aed4
feat: implemented preprocessor
cloalenka Oct 25, 2025
0255085
fix: processors and processor_factory logic, changed throws to returns
cloalenka Oct 25, 2025
26d888c
feat: added extra EOF tokens removing
cloalenka Oct 25, 2025
214dc25
fix: #define and #else logic
cloalenka Oct 25, 2025
85abb92
fix: small logic fixes
cloalenka Oct 25, 2025
4a42ea3
feat: added console ui for preprocessor
cloalenka Oct 25, 2025
b8a3bb8
fix: clang-format
cloalenka Oct 25, 2025
0b9f674
feat: added --help handling
cloalenka Oct 25, 2025
2477728
fix: console ui integration test
cloalenka Oct 25, 2025
e0003e0
fix: clang-format
cloalenka Oct 25, 2025
a7a0a84
fix: workflow for windows
cloalenka Oct 25, 2025
5ad738b
fix: deleted Tests and application run on Windows Latest MinGW from c…
cloalenka Oct 25, 2025
d0db5bf
refactor: codestyle
cloalenka Oct 27, 2025
96f398d
refactor: added move
cloalenka Oct 27, 2025
56a4d1f
refactor: changed import processor initialization
cloalenka Oct 27, 2025
9adb618
feat: added parent path of main file to include_paths
cloalenka Oct 27, 2025
75df0ff
refactor: const & for constructor parameter
cloalenka Oct 27, 2025
1943f36
feat: added FileGraph class and moved all graph logic there
cloalenka Oct 27, 2025
1b7c3e4
refactor: changed constructor
cloalenka Oct 27, 2025
db07331
refactor: break lines
cloalenka Oct 27, 2025
e8e2dcb
refactor: made big function smaller
cloalenka Oct 27, 2025
4529caf
refactor: clang-format
cloalenka Oct 27, 2025
d8ea4f2
refactor: added separate directives handlers
cloalenka Oct 27, 2025
02e4054
feat: added special errors for directives processor
cloalenka Oct 27, 2025
bdce3ab
feat: changed #define and #undef handling
cloalenka Oct 27, 2025
2297097
feat: changed graph set and map type
cloalenka Oct 27, 2025
9cdc065
feat: changed directive processor logic
cloalenka Nov 1, 2025
90b5cf6
fix: codestyle
cloalenka Nov 1, 2025
40096a8
fix: codestyle
cloalenka Nov 1, 2025
fbca73e
refactor: got rid of unnecessary function
cloalenka Nov 1, 2025
acd5afc
add: test data for preprocessor unit tests
sashbek Nov 1, 2025
b94331e
fix: minor test data fix
sashbek Nov 1, 2025
b8091b0
refactor: improve code formatting and consistency in directive handlers
bialger Nov 1, 2025
776f032
refactor: simplify iterator declarations in FileGraph and TokenImport…
bialger Nov 1, 2025
3b1f3b5
refactor: reorganize includes and improve header structure in preproc…
bialger Nov 1, 2025
1938634
refactor: streamline directive handler chain creation and enhance Set…
bialger Nov 1, 2025
b73b9cd
refactor: fix line breaks
bialger Nov 1, 2025
c60ff55
refactor: update DefaultHandler namespace and improve header guard na…
bialger Nov 1, 2025
34c6ce5
refactor: encapsulate preprocessor components within ovum::compiler::…
bialger Nov 1, 2025
87ebece
refactor: naming
cloalenka Nov 2, 2025
80c1dec
add: test .cpp and .hpp files for preprocessor
sashbek Nov 2, 2025
5750011
fix: WAITERROR directive changed to EXPECTERROR
sashbek Nov 2, 2025
bff9fb5
fix: imported files signature and usege
sashbek Nov 2, 2025
f9effec
Merge remote-tracking branch 'origin/preprocessor' into preprocessor-…
sashbek Nov 2, 2025
c901486
fix: namespace & minor fixes in tests
sashbek Nov 2, 2025
3fb7b3f
fix: adding main_file node to graph
cloalenka Nov 2, 2025
0def0cd
refactor: test_data
sashbek Nov 2, 2025
3d3947d
refactor: test_data 2
sashbek Nov 2, 2025
1756f50
refactor: test method
sashbek Nov 2, 2025
58fdc4e
merge with preprocessor
sashbek Nov 2, 2025
977e5fc
fix: tests launcher
sashbek Nov 2, 2025
18c9164
refactor: clanged
sashbek Nov 2, 2025
b4f266a
fix: double-else condition fix and extra \n after directives deletion
cloalenka Nov 2, 2025
e7a3ee6
refactor: clang-format
cloalenka Nov 2, 2025
3dddf80
fix: test suite for neg tests
sashbek Nov 3, 2025
4e726c1
merge: origin/preprocessor
sashbek Nov 3, 2025
624d09d
fix: some tests fixed
sashbek Nov 3, 2025
8c722cf
fix: else_seen indexes
cloalenka Nov 3, 2025
9a9ebf6
fix: minor
sashbek Nov 3, 2025
173cb02
fix: position shift after directives
cloalenka Nov 3, 2025
8316eba
merge: with origin/preprocessor
sashbek Nov 3, 2025
98f9042
fix: position shift after directives
cloalenka Nov 3, 2025
d22d9b7
fix: tests \n in the end
sashbek Nov 3, 2025
d691eed
fix: tests for preprocessor
sashbek Nov 3, 2025
26f7c8c
merge: remote-tracking branch 'origin/preprocessor' into preprocessor…
sashbek Nov 3, 2025
2bdd318
fix: position shift after import directive
cloalenka Nov 3, 2025
7317c9e
fix: tests for preprocessor
sashbek Nov 3, 2025
10512bb
merge: remote-tracking branch 'origin/preprocessor' into preprocessor…
sashbek Nov 3, 2025
b3cf993
fix: tests for preprocessor
sashbek Nov 3, 2025
bc1bbf0
fix: tests for preprocessor
sashbek Nov 3, 2025
5d0c737
fix: update preprocessor test cases to fix case sensitiveness issues
bialger Nov 3, 2025
1936031
fix: name rest of the files properly
bialger Nov 3, 2025
053af41
fix: correct case of import file names in complex test cases
bialger Nov 3, 2025
33d4a75
refactor: rename input and expected file path functions for consisten…
bialger Nov 3, 2025
5979852
build: update CMake configuration to automate test data preparation
bialger Nov 3, 2025
7e83fe1
chore: add submodule for example tests and update CMake configuration…
bialger Nov 3, 2025
25f8ff4
Merge pull request #22 from Ovum-Programming-Language/preprocessor-tests
bialger Nov 3, 2025
e563bdf
chore: update .clang-tidy and .gitignore for improved code quality ch…
bialger Nov 4, 2025
a64fd67
refactor: update method calls to use static methods from SourceCodeWr…
bialger Nov 4, 2025
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
93 changes: 88 additions & 5 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,20 +1,103 @@
Checks: '-*,
Checks: "-*,
modernize-*,
performance-*,
cppcoreguidelines-*,
bugprone-*,
misc-header-include-cycle,
readability-delete-null-pointer,
readability-identifier-naming,
readability-misleading-indentation,
readability-redundant-control-flow,
readability-static-accessed-through-instance,
llvm-namespace-comment,
-modernize-use-trailing-return-type,
-performance-no-int-to-ptr,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-bugprone-exception-escape,
-bugprone-easily-swappable-parameters'
-bugprone-easily-swappable-parameters"

WarningsAsErrors: ''
HeaderFilterRegex: ''
WarningsAsErrors: ""
HeaderFilterRegex: ""
FormatStyle: none
CheckOptions:
- key: modernize-use-using.IgnoreMacros
value: 'true'
value: "true"
- key: readability-identifier-naming.NamespaceCase
value: "lower_case"
- key: readability-identifier-naming.ClassCase
value: "CamelCase"
- key: readability-identifier-naming.StructCase
value: "CamelCase"
- key: readability-identifier-naming.TemplateParameterCase
value: "CamelCase"
- key: readability-identifier-naming.FunctionCase
value: "CamelCase"
- key: readability-identifier-naming.VariableCase
value: "lower_case"
- key: readability-identifier-naming.ClassMemberCase
value: "lower_case"
- key: readability-identifier-naming.ClassMemberSuffix
value: "_"
- key: readability-identifier-naming.PrivateMemberSuffix
value: "_"
- key: readability-identifier-naming.ProtectedMemberSuffix
value: "_"
- key: readability-identifier-naming.EnumConstantCase
value: "CamelCase"
- key: readability-identifier-naming.EnumConstantPrefix
value: "k"
- key: readability-identifier-naming.ConstexprVariableCase
value: "CamelCase"
- key: readability-identifier-naming.ConstexprVariablePrefix
value: "k"
- key: readability-identifier-naming.GlobalConstantCase
value: "CamelCase"
- key: readability-identifier-naming.GlobalConstantPrefix
value: "k"
- key: readability-identifier-naming.MemberConstantCase
value: "CamelCase"
- key: readability-identifier-naming.MemberConstantPrefix
value: "k"
- key: readability-identifier-naming.StaticConstantCase
value: "CamelCase"
- key: readability-identifier-naming.StaticConstantPrefix
value: "k"
- key: readability-identifier-naming.StructCase
value: "CamelCase"
- key: readability-identifier-naming.TemplateParameterCase
value: "CamelCase"
- key: readability-identifier-naming.FunctionCase
value: "CamelCase"
- key: readability-identifier-naming.VariableCase
value: "lower_case"
- key: readability-identifier-naming.ClassMemberCase
value: "lower_case"
- key: readability-identifier-naming.ClassMemberSuffix
value: "_"
- key: readability-identifier-naming.PrivateMemberSuffix
value: "_"
- key: readability-identifier-naming.ProtectedMemberSuffix
value: "_"
- key: readability-identifier-naming.EnumConstantCase
value: "CamelCase"
- key: readability-identifier-naming.EnumConstantPrefix
value: "k"
- key: readability-identifier-naming.ConstexprVariableCase
value: "CamelCase"
- key: readability-identifier-naming.ConstexprVariablePrefix
value: "k"
- key: readability-identifier-naming.GlobalConstantCase
value: "CamelCase"
- key: readability-identifier-naming.GlobalConstantPrefix
value: "k"
- key: readability-identifier-naming.MemberConstantCase
value: "CamelCase"
- key: readability-identifier-naming.MemberConstantPrefix
value: "k"
- key: readability-identifier-naming.StaticConstantCase
value: "CamelCase"
- key: readability-identifier-naming.StaticConstantPrefix
value: "k"
41 changes: 0 additions & 41 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,6 @@ name: "CI tests"
on: [ push, workflow_dispatch ]

jobs:
build-mingw:
name: Tests and application run on Windows Latest MinGW
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Install MinGW toolchain
shell: powershell
run: |
choco install mingw --yes --no-progress
echo "C:\tools\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Create CMake cache
run: |
cmake -S . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles"
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles"

- name: Build main target
shell: bash
run: |
cmake --build cmake-build-release || echo Built with errors

- name: Build tests target
shell: bash
run: |
cmake --build cmake-build-debug --target ovumc_tests || echo Built with errors

- name: Run program
working-directory: .\cmake-build-release
shell: bash
run: |
./ovumc.exe --help

- name: Run tests
working-directory: .\cmake-build-debug
shell: bash
run: |
# ./ovumc_tests.exe
echo "Tests are not run on Windows MinGW due to issues with the test runner"

build-matrix:
name: Tests and application run on ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build/

# Clangd rules
.clangd
.cache/

# File-based project format
*.iws
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tests/test_data/examples"]
path = tests/test_data/examples
url = https://github.com/Ovum-Programming-Language/OvumExamples
branch = main
12 changes: 2 additions & 10 deletions bin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
#include "lib/compiler_ui/compiler_ui_functions.hpp"

int main(int32_t argc, char** argv) {
const std::string sample = R"ovum(
// demo
fun Main(args: StringArray): Int {
val count: Int = args.Length()
sys::Print("Args count: " + count.ToString())
return 0
}
)ovum";

return StartCompilerConsoleUI({"ovumc", sample}, std::cout, std::cerr);
std::vector<std::string> args = std::vector<std::string>(argv, argv + argc);
return StartCompilerConsoleUI(args, std::cout, std::cerr);
}
1 change: 1 addition & 0 deletions lib/compiler_ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(compiler_ui STATIC

target_link_libraries(compiler_ui PUBLIC
lexer
preprocessor
)

target_include_directories(compiler_ui PUBLIC ${PROJECT_SOURCE_DIR})
50 changes: 36 additions & 14 deletions lib/compiler_ui/compiler_ui_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
#include "lib/lexer/Lexer.hpp"

#include <exception>

#include "compiler_ui_functions.hpp"

#include "lib/preprocessor/Preprocessor.hpp"

int32_t StartCompilerConsoleUI(const std::vector<std::string>& args, std::ostream& out, std::ostream& err) {
if (args.size() < 2) {
err << "Insufficient arguments\n";
err << "Usage: ovumc <main_file.ovum> [include_path1] [include_path2] ...\n";
err << "Example: ovumc sample.ovum /path/to/includes\n";
return 1;
}

const std::string& sample = args[1];
Lexer lx(sample, true);
if (args[1] == "--help") {
out << "Usage: ovumc <main_file.ovum> [include_path1] [include_path2] ...\n";
out << "Example: ovumc sample.ovum /path/to/includes\n";
return 0;
}

std::filesystem::path main_file = args[1];
std::set<std::filesystem::path> include_paths;

include_paths.emplace(main_file.parent_path());

for (size_t i = 2; i < args.size(); ++i) {
include_paths.emplace(args[i]);
}

try {
auto toks = lx.Tokenize();
std::unordered_set<std::string> predefined_symbols;

for (auto& t : toks) {
out << t->ToString() << "\n";
}
} catch (const std::exception& e) {
err << "Lexer error: " << e.what() << "\n";
ovum::compiler::preprocessor::PreprocessingParameters params{
.include_paths = include_paths, .predefined_symbols = predefined_symbols, .main_file = main_file};

ovum::compiler::preprocessor::Preprocessor preprocessor(params);

auto result = preprocessor.Process();

if (!result) {
err << result.error().what() << "\n";
return 1;
}

const auto& tokens = result.value();

for (const auto& t : tokens) {
out << t->ToString() << "\n";
}

out << "\nPreprocessed " << tokens.size() << " tokens successfully.\n";

return 0;
}
2 changes: 1 addition & 1 deletion lib/lexer/handlers/ColonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OptToken ColonHandler::Scan(SourceCodeWrapper& wrapper) {

if (next != '\0') {
std::string two = op + next;
if (wrapper.IsMultiOp(two)) {
if (SourceCodeWrapper::IsMultiOp(two)) {
wrapper.Advance();
op = two;
return std::make_optional(TokenFactory::MakeOperator(std::move(op), wrapper.GetLine(), wrapper.GetTokenCol()));
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer/handlers/IdentifierHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OptToken IdentifierHandler::Scan(SourceCodeWrapper& wrapper) {
TokenFactory::MakeFloatLiteral(s, std::nan(""), wrapper.GetLine(), wrapper.GetTokenCol()));
}

if (wrapper.IsKeyword(s)) {
if (SourceCodeWrapper::IsKeyword(s)) {
if (s == "true" || s == "false") {
return std::make_optional(
TokenFactory::MakeBoolLiteral(s, s == "true", wrapper.GetLine(), wrapper.GetTokenCol()));
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer/handlers/OperatorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OptToken OperatorHandler::Scan(SourceCodeWrapper& wrapper) {
if (p != '\0') {
std::string two = op + p;

if (wrapper.IsMultiOp(two)) {
if (SourceCodeWrapper::IsMultiOp(two)) {
wrapper.Advance();
op = two;
}
Expand Down
30 changes: 24 additions & 6 deletions lib/preprocessor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
add_library(preprocessor STATIC
Preprocessor.cpp
token_processor_factory.cpp
Preprocessor.cpp
token_processor_factory.cpp
import_processor/TokenImportProcessor.cpp
directives_processor/TokenDirectivesProcessor.cpp
import_processor/FileGraph.cpp
directives_processor/directives_chain_factory.cpp
directives_processor/handlers/DefaultHandler.cpp
directives_processor/handlers/DefineHandler.cpp
directives_processor/handlers/ElseHandler.cpp
directives_processor/handlers/EndifHandler.cpp
directives_processor/handlers/UndefHandler.cpp
directives_processor/handlers/IfndefHandler.cpp
directives_processor/handlers/IfdefHandler.cpp
)

target_include_directories(preprocessor
PUBLIC
${CMAKE_SOURCE_DIR}
PUBLIC
${CMAKE_SOURCE_DIR}
)

target_include_directories(preprocessor
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(preprocessor PUBLIC
lexer
)

target_include_directories(preprocessor PUBLIC ${PROJECT_SOURCE_DIR})

9 changes: 7 additions & 2 deletions lib/preprocessor/PreprocessingParameters.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#ifndef PREPROCESSINGPARAMETERS_HPP_
#define PREPROCESSINGPARAMETERS_HPP_
#ifndef PREPROCESSOR_PREPROCESSINGPARAMETERS_HPP_
#define PREPROCESSOR_PREPROCESSINGPARAMETERS_HPP_

#include <filesystem>
#include <set>
#include <string>
#include <unordered_set>

namespace ovum::compiler::preprocessor {

struct PreprocessingParameters {
std::set<std::filesystem::path> include_paths;
std::unordered_set<std::string> predefined_symbols;
std::filesystem::path main_file;
};

} // namespace ovum::compiler::preprocessor

#endif // PREPROCESSINGPARAMETERS_HPP_
Loading