From 3d7d1d7cf8685f0d9230cd89d06017869da1c6d8 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 27 Oct 2026 14:00:16 +0000 Subject: feat(library)!: replace #LIB with __LIB source regions Track library mode by original source line, including deferred template bodies and automatic object cleanup. Update call lines from ordinary code and migrate the embedded standard library to PP_DEFINE __LIB. Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/CodeGen.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CodeGen.cc') diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc index 49b470c..ce5fa00 100644 --- a/lib/CodeGen/CodeGen.cc +++ b/lib/CodeGen/CodeGen.cc @@ -149,9 +149,12 @@ void CodeGen::selectUnit(size_t Unit) { CurrentUnit = Unit; DiagnosticSource = (*Units)[Unit].Path; FuncGen->setCurrentUnit(Unit, (*Units)[Unit].Path); - RuntimeChecker->setLibraryMode((*Units)[Unit].IsLibrary); - FuncGen->setCallHook([this](const FuncSig &Sig) { - if (!(*Units)[CurrentUnit].IsLibrary && (*Units)[Sig.OwnerUnit].IsLibrary) + RuntimeChecker->setLibraryLookup([this](int Line) { + return (*Units)[CurrentUnit].isLibrary(Line); + }); + FuncGen->setCallHook([this](const FuncSig &) { + // The callee may enable __LIB inside its body even if its header is ordinary code. + if (!(*Units)[CurrentUnit].isLibrary(DiagnosticLine)) RuntimeChecker->setUserLine(DiagnosticLine); }); } @@ -195,7 +198,8 @@ void CodeGen::compile(const std::vector &Sources) { if (!Added && !Compatible && (It->second.Unit != CurrentUnit || ((IsTemplate || It->second.IsTemplate) && !(IsFunction && It->second.IsFunction)))) { // Default library units follow user inputs; point at the user's conflicting definition. - bool UserConflict = Sources[CurrentUnit].IsLibrary && !Sources[It->second.Unit].IsLibrary; + bool UserConflict = Sources[CurrentUnit].isLibrary(DiagnosticLine) && + !Sources[It->second.Unit].isLibrary(It->second.Line); SaveAndRestore Location(DiagnosticLine, UserConflict ? It->second.Line : DiagnosticLine); SaveAndRestore Source(DiagnosticSource, UserConflict ? Sources[It->second.Unit].Path : DiagnosticSource); -- cgit v1.3.1-4-g156e