From 09748b9eeba03968afbd0def04c93d43087f5571 Mon Sep 17 00:00:00 2001 From: Rune Date: Fri, 6 Mar 2026 17:22:57 +0100 Subject: [PATCH] fix static block appearing before rsquirly --- src/Generator.bf | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Generator.bf b/src/Generator.bf index 955d7ab..6b14505 100644 --- a/src/Generator.bf +++ b/src/Generator.bf @@ -154,6 +154,9 @@ abstract class Cpp2BeefGenerator case .Namespace: BeginCursor(cursor); Namespace(cursor); case .FunctionDecl: BeginCursor(cursor); FunctionDecl(cursor); + case .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl: + Runtime.FatalError("Templates are currently unsupported but Coming Soon tm"); + case .CXXMethod, .Constructor, .Destructor, @@ -323,7 +326,7 @@ abstract class Cpp2BeefGenerator CXTranslationUnit_Flags unitFlags = .SkipFunctionBodies | .DetailedPreprocessingRecord; unit = Clang.ParseTranslationUnit(index, headerPath, args.Ptr, (.)args.Length, null, 0, (.)unitFlags); if (unit == default) return .Err(.ParsingFailed); - + printingPolicy = Clang.GetCursorPrintingPolicy(Clang.GetTranslationUnitCursor(unit)); ModifyWrapperPrintingPolicy(printingPolicy); defer Clang.PrintingPolicy_Dispose(printingPolicy); @@ -408,7 +411,6 @@ abstract class Cpp2BeefGenerator switch (cursor.kind) { case .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl: - Runtime.FatalError("Templates are currently unsupported but Coming Soon tm"); templateParams.Append('<'); let len = wrapperTemplateChain.Length; Clang.VisitChildren(cursor, (cursor, parent, client_data) => @@ -523,7 +525,7 @@ abstract class Cpp2BeefGenerator let cursorLocation = Clang.GetCursorLocation(cursor); //let rangeLocation = Clang.GetRangeStart(Clang.GetCursorExtent(cursor)); //if (Clang.File_IsEqual(Clang.GetSpellingLocation(cursorLocation, file: ..?, ?, ?, ?), Clang.GetSpellingLocation(rangeLocation, file: ..?, ?, ?, ?)) == 0) - return cursorLocation; + return cursorLocation; //return rangeLocation; } @@ -542,6 +544,9 @@ abstract class Cpp2BeefGenerator } protected virtual void WriteComments(CXSourceLocation writeUntil, Block? block = null) { + var block; + if (fileInfo.queuedTokens != .None) block = null; + Clang.GetFileLocation(writeUntil, let curFile, let curLine, let curColumn, let curOffset); Clang.GetFileLocation(fileInfo.prevEnd, let prevFile, let prevLine, let prevColumn, let prevOffset); @@ -587,6 +592,7 @@ abstract class Cpp2BeefGenerator void Block() { + if (fileInfo.queuedTokens != .None) return; findMacros: do { for (uint32 ln = line; ln < curLine; ln++) @@ -620,6 +626,7 @@ abstract class Cpp2BeefGenerator QueuedToken!(decltype(fileInfo.queuedTokens).RSquirly, "}"); if (!isWritingQueuedToken) continue; + if (fileInfo.queuedTokens == .None) block = @block; default: continue; } let location = Clang.GetTokenLocation(unit, token); @@ -637,7 +644,7 @@ abstract class Cpp2BeefGenerator Flush(); } WriteLinesUntil!(curLine, writeUntil); - if (block.HasValue) WriteBlock(block.Value); + if (@block.HasValue) WriteBlock(@block.Value); } protected enum TypeParamMode { None, InParam, OutParam } @@ -940,7 +947,7 @@ abstract class Cpp2BeefGenerator String whitespace; if (preserveColumns) { - whitespace = scope .(str); + whitespace = scope:: .(str); str.Clear(); Type(type); whitespace.Length -= Math.Min(str.Length, whitespace.Length); @@ -1057,7 +1064,7 @@ abstract class Cpp2BeefGenerator if (Clang.Cursor_IsNull(cursor) != 0) break; GetNameInBindings(cursor, str); break token; - } + } str.Append(spelling); if (kind == .Literal && str.EndsWith("LL")) str.Length--; @@ -1501,7 +1508,7 @@ abstract class Cpp2BeefGenerator str.Append(" : "); Type(Clang.GetEnumDeclIntegerType(cursor)); str.Append(templateParamsWhere); - } + } BeginBody!(cursor); Clang.VisitChildren(cursor, (cursor, parent, client_data) => {