fix static block appearing before rsquirly

This commit is contained in:
Rune
2026-03-06 17:22:57 +01:00
parent fa90624c84
commit 09748b9eeb

View File

@@ -154,6 +154,9 @@ abstract class Cpp2BeefGenerator
case .Namespace: BeginCursor(cursor); Namespace(cursor); case .Namespace: BeginCursor(cursor); Namespace(cursor);
case .FunctionDecl: BeginCursor(cursor); FunctionDecl(cursor); case .FunctionDecl: BeginCursor(cursor); FunctionDecl(cursor);
case .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl:
Runtime.FatalError("Templates are currently unsupported but Coming Soon tm");
case .CXXMethod, case .CXXMethod,
.Constructor, .Constructor,
.Destructor, .Destructor,
@@ -323,7 +326,7 @@ abstract class Cpp2BeefGenerator
CXTranslationUnit_Flags unitFlags = .SkipFunctionBodies | .DetailedPreprocessingRecord; CXTranslationUnit_Flags unitFlags = .SkipFunctionBodies | .DetailedPreprocessingRecord;
unit = Clang.ParseTranslationUnit(index, headerPath, args.Ptr, (.)args.Length, null, 0, (.)unitFlags); unit = Clang.ParseTranslationUnit(index, headerPath, args.Ptr, (.)args.Length, null, 0, (.)unitFlags);
if (unit == default) return .Err(.ParsingFailed); if (unit == default) return .Err(.ParsingFailed);
printingPolicy = Clang.GetCursorPrintingPolicy(Clang.GetTranslationUnitCursor(unit)); printingPolicy = Clang.GetCursorPrintingPolicy(Clang.GetTranslationUnitCursor(unit));
ModifyWrapperPrintingPolicy(printingPolicy); ModifyWrapperPrintingPolicy(printingPolicy);
defer Clang.PrintingPolicy_Dispose(printingPolicy); defer Clang.PrintingPolicy_Dispose(printingPolicy);
@@ -408,7 +411,6 @@ abstract class Cpp2BeefGenerator
switch (cursor.kind) switch (cursor.kind)
{ {
case .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl: case .FunctionTemplate, .ClassTemplate, .TypeAliasTemplateDecl:
Runtime.FatalError("Templates are currently unsupported but Coming Soon tm");
templateParams.Append('<'); templateParams.Append('<');
let len = wrapperTemplateChain.Length; let len = wrapperTemplateChain.Length;
Clang.VisitChildren(cursor, (cursor, parent, client_data) => Clang.VisitChildren(cursor, (cursor, parent, client_data) =>
@@ -523,7 +525,7 @@ abstract class Cpp2BeefGenerator
let cursorLocation = Clang.GetCursorLocation(cursor); let cursorLocation = Clang.GetCursorLocation(cursor);
//let rangeLocation = Clang.GetRangeStart(Clang.GetCursorExtent(cursor)); //let rangeLocation = Clang.GetRangeStart(Clang.GetCursorExtent(cursor));
//if (Clang.File_IsEqual(Clang.GetSpellingLocation(cursorLocation, file: ..?, ?, ?, ?), Clang.GetSpellingLocation(rangeLocation, file: ..?, ?, ?, ?)) == 0) //if (Clang.File_IsEqual(Clang.GetSpellingLocation(cursorLocation, file: ..?, ?, ?, ?), Clang.GetSpellingLocation(rangeLocation, file: ..?, ?, ?, ?)) == 0)
return cursorLocation; return cursorLocation;
//return rangeLocation; //return rangeLocation;
} }
@@ -542,6 +544,9 @@ abstract class Cpp2BeefGenerator
} }
protected virtual void WriteComments(CXSourceLocation writeUntil, Block? block = null) 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(writeUntil, let curFile, let curLine, let curColumn, let curOffset);
Clang.GetFileLocation(fileInfo.prevEnd, let prevFile, let prevLine, let prevColumn, let prevOffset); Clang.GetFileLocation(fileInfo.prevEnd, let prevFile, let prevLine, let prevColumn, let prevOffset);
@@ -587,6 +592,7 @@ abstract class Cpp2BeefGenerator
void Block() void Block()
{ {
if (fileInfo.queuedTokens != .None) return;
findMacros: do findMacros: do
{ {
for (uint32 ln = line; ln < curLine; ln++) for (uint32 ln = line; ln < curLine; ln++)
@@ -620,6 +626,7 @@ abstract class Cpp2BeefGenerator
QueuedToken!(decltype(fileInfo.queuedTokens).RSquirly, "}"); QueuedToken!(decltype(fileInfo.queuedTokens).RSquirly, "}");
if (!isWritingQueuedToken) continue; if (!isWritingQueuedToken) continue;
if (fileInfo.queuedTokens == .None) block = @block;
default: continue; default: continue;
} }
let location = Clang.GetTokenLocation(unit, token); let location = Clang.GetTokenLocation(unit, token);
@@ -637,7 +644,7 @@ abstract class Cpp2BeefGenerator
Flush(); Flush();
} }
WriteLinesUntil!(curLine, writeUntil); WriteLinesUntil!(curLine, writeUntil);
if (block.HasValue) WriteBlock(block.Value); if (@block.HasValue) WriteBlock(@block.Value);
} }
protected enum TypeParamMode { None, InParam, OutParam } protected enum TypeParamMode { None, InParam, OutParam }
@@ -940,7 +947,7 @@ abstract class Cpp2BeefGenerator
String whitespace; String whitespace;
if (preserveColumns) if (preserveColumns)
{ {
whitespace = scope .(str); whitespace = scope:: .(str);
str.Clear(); str.Clear();
Type(type); Type(type);
whitespace.Length -= Math.Min(str.Length, whitespace.Length); whitespace.Length -= Math.Min(str.Length, whitespace.Length);
@@ -1057,7 +1064,7 @@ abstract class Cpp2BeefGenerator
if (Clang.Cursor_IsNull(cursor) != 0) break; if (Clang.Cursor_IsNull(cursor) != 0) break;
GetNameInBindings(cursor, str); GetNameInBindings(cursor, str);
break token; break token;
} }
str.Append(spelling); str.Append(spelling);
if (kind == .Literal && str.EndsWith("LL")) if (kind == .Literal && str.EndsWith("LL"))
str.Length--; str.Length--;
@@ -1501,7 +1508,7 @@ abstract class Cpp2BeefGenerator
str.Append(" : "); str.Append(" : ");
Type(Clang.GetEnumDeclIntegerType(cursor)); Type(Clang.GetEnumDeclIntegerType(cursor));
str.Append(templateParamsWhere); str.Append(templateParamsWhere);
} }
BeginBody!(cursor); BeginBody!(cursor);
Clang.VisitChildren(cursor, (cursor, parent, client_data) => Clang.VisitChildren(cursor, (cursor, parent, client_data) =>
{ {