include Update
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user