Skip to content

Commit fe68d33

Browse files
authored
Generate C++ deconflicted with system functions (#1626)
If a type shares a name with a system function, such as, well, "system()", declaring the type by name alone is taken as the function. So we need to prefix the type with "class" or "struct" as appropriate. Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 7ead6b4 commit fe68d33

File tree

8 files changed

+1480
-1472
lines changed

8 files changed

+1480
-1472
lines changed

src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser-symbols.cpp

Lines changed: 245 additions & 245 deletions
Large diffs are not rendered by default.

src/Generator/Generators/C/CppTypePrinter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CppTypePrinter : TypePrinter
2121
public bool PrintLogicalNames { get; set; }
2222
public bool PrintTypeQualifiers { get; set; }
2323
public bool PrintTypeModifiers { get; set; }
24+
public bool PrintTags { get; set; }
2425
public bool PrintVariableArrayAsPointers { get; set; }
2526

2627
public TypePrintScopeKind MethodScopeKind = TypePrintScopeKind.Qualified;
@@ -499,7 +500,11 @@ public virtual TypePrinterResult GetDeclName(Declaration declaration,
499500
if (declaration.Namespace is Class)
500501
{
501502
var declName = GetDeclName(declaration, TypePrintScopeKind.Local);
502-
return $"{declaration.Namespace.Visit(this)}{NamespaceSeparator}{declName}";
503+
bool printTags = PrintTags;
504+
PrintTags = false;
505+
TypePrinterResult declContext = declaration.Namespace.Visit(this);
506+
PrintTags = printTags;
507+
return $"{declContext}{NamespaceSeparator}{declName}";
503508
}
504509

505510
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
@@ -547,7 +552,8 @@ public override TypePrinterResult VisitClassDecl(Class @class)
547552
if (@class.CompleteDeclaration != null)
548553
return VisitClassDecl(@class.CompleteDeclaration as Class);
549554

550-
return VisitDeclaration(@class);
555+
string printed = VisitDeclaration(@class);
556+
return PrintTags ? PrintTag(@class) + printed : printed;
551557
}
552558

553559
public override TypePrinterResult VisitClassTemplateSpecializationDecl(

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ private void TakeFunctionAddress(Function function, string wrapper)
225225
Write($"class {wrapper}{function.Namespace.Name} : public {@namespace} {{ public: ");
226226
Write("static constexpr ");
227227
}
228+
cppTypePrinter.PrintTags = true;
228229
TypePrinterResult returnType = function.OriginalReturnType.Visit(cppTypePrinter);
229230
string signature = GetSignature(function);
231+
cppTypePrinter.PrintTags = false;
230232

231233
string functionName = GetFunctionName(function, @namespace);
232234
if (function.FriendKind != FriendKind.None)

0 commit comments

Comments
 (0)