From 5f632cd204b7a85f3a97b6c316c5a34f9fc8193e Mon Sep 17 00:00:00 2001 From: Ronan Date: Fri, 25 Apr 2025 00:48:37 +0200 Subject: Implemented #pragma warning (#6748) * Implemented #pragma warning Based on https://learn.microsoft.com/en-us/cpp/preprocessor/warning?view=msvc-170 * Make #pragma warning work with #includes. - SourceLoc are not sorted by inclusion order. - Construct a mapping from SourceLoc to "absolute locations" that are sorted by inclusion order (roughly represents a location in a raw file with all #include resolved). - The absolute location can be used in the pragma warning timeline * Added preprocessor #pragma warning tests. - Fixed #pragma warning (push / pop) SourceLoc - Fixed unused directiveLoc in #pragma warning parsing * #pragma warning: Added some comments and fixed some typos * Cleaned #pragma warning preprocessor implementation. --------- Co-authored-by: Yong He --- source/compiler-core/slang-source-loc.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source/compiler-core/slang-source-loc.cpp') diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp index 5058a1522..cfde5f1da 100644 --- a/source/compiler-core/slang-source-loc.cpp +++ b/source/compiler-core/slang-source-loc.cpp @@ -1018,4 +1018,44 @@ PathInfo SourceManager::getPathInfo(SourceLoc loc, SourceLocType type) } } +SourceLoc::RawValue SourceView::getAbsoluteLocation(SourceLoc location) const +{ + AbsoluteSegment segment; + if (m_absSegments.getCount()) + { + if (m_absSegments.getFirst().begin > location) + { + segment.begin = m_range.begin; + segment.absoluteBegin = m_absoluteLocationBase; + } + else + { + auto it = std::upper_bound( + m_absSegments.begin(), + m_absSegments.end(), + location, + [](SourceLoc const& loc, AbsoluteSegment const& seg) + { return loc < seg.begin; }) - + 1; + segment = *it; + } + } + else + { + segment = getLastSegment(); + } + auto offset = SourceRange(segment.begin, location).getSize(); + return segment.absoluteBegin + offset; +} + +SourceLoc::RawValue SourceManager::getAbsoluteLocation(SourceLoc location) const +{ + SourceLoc::RawValue res = 0; + if (const SourceView* view = findSourceView(location)) + { + res = view->getAbsoluteLocation(location); + } + return res; +} + } // namespace Slang -- cgit v1.2.3