From a91bd145008432fb8c5d91d94ab6f50473a277f5 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 27 Oct 2026 13:55:36 +0000 Subject: feat(preprocessor): add file-local conditional switches Co-Authored-By: Claude Opus 5.5 --- tools/driver/main.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/driver/main.cc b/tools/driver/main.cc index d1dda81..e3d4c28 100644 --- a/tools/driver/main.cc +++ b/tools/driver/main.cc @@ -1,4 +1,5 @@ #include "cps/Lexer.h" +#include "cps/Preprocessor.h" #include "cps/Diagnostics.h" #include "cps/Parser.h" #include "cps/CodeGen.h" @@ -17,6 +18,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include +#include #include #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -187,13 +189,16 @@ bool parseUnits(const std::vector &InputPaths, size_t UserInputCoun return false; } cps::DiagnosticSource = InputPath; - cps::Lexer Lex(Input); - cps::Parser Parser(Lex); - Programs[I] = Parser.Parse(); + auto Source = cps::preprocess(Input); if (Input.bad()) { llvm::errs() << cps::diagnosticPrefix(cps::Severity::Fatal) << "cannot read source file '" << InputPath << "'\n"; return false; } + if (Source.HadError) return false; + std::istringstream Processed(Source.Text); + cps::Lexer Lex(Processed); + cps::Parser Parser(Lex); + Programs[I] = Parser.Parse(); if (Lex.hadError() || Parser.hadError()) return false; Units.push_back({InputPath, Programs[I], std::vector(InputPaths.size(), false), Lex.isLibrary()}); Units.back().Visible[I] = true; -- cgit v1.3.1-4-g156e