include Update

This commit is contained in:
mmichlol
2026-02-07 11:57:44 +01:00
parent e250b2f5fb
commit 9bbf8435c6
4 changed files with 26 additions and 30 deletions

View File

@@ -17,7 +17,7 @@ std::string loadFileContent(const std::string& path) {
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
}
std::string preprocessSource(const std::string& src, const std::string& basePath) {
std::string preprocessSource(const std::string& src, const std::string& projectDir, const std::string& compilerDir) {
std::istringstream iss(src);
std::string line;
std::stringstream output;
@@ -53,26 +53,17 @@ std::string preprocessSource(const std::string& src, const std::string& basePath
if (!includePath.empty()) {
std::string fullPath;
if (isStdLib) {
// Biblioteka standardowa: szukamy w folderze "std" obok exe/projektu
// U¿ywamy current_path() + "std"
fullPath = "std/" + includePath;
fullPath = compilerDir + "/std/" + includePath;
std::cout << "[PREPROCESSOR] Including STD lib: " << fullPath << "\n";
}
else {
// Plik lokalny: szukamy w tym samym folderze co plik Ÿród³owy
// Jeœli basePath jest pusty, szukamy lokalnie
if (basePath.empty()) fullPath = includePath;
else fullPath = basePath + "/" + includePath;
// Plik lokalny: Szukamy w folderze projektu
if (projectDir.empty()) fullPath = includePath;
else fullPath = projectDir + "/" + includePath;
std::cout << "[PREPROCESSOR] Including local file: " << fullPath << "\n";
}
// Wczytujemy plik i REKURENCYJNIE go przetwarzamy
// (bo plik do³¹czany mo¿e mieæ swoje include!)
std::string content = loadFileContent(fullPath);
// Dla uproszczenia rekurencji w include'ach lokalnych, przekazujemy ten sam basePath
// W idealnym œwiecie powinniœmy braæ folder nowego pliku.
std::string processedContent = preprocessSource(content, basePath);
std::string processedContent = preprocessSource(content, projectDir, compilerDir);
output << "\n// --- BEGIN INCLUDE: " << includePath << " ---\n";
output << processedContent;
@@ -80,7 +71,6 @@ std::string preprocessSource(const std::string& src, const std::string& basePath
}
}
else {
// Zwyk³a linia kodu - przepisujemy bez zmian
output << line << "\n";
}
}