diff --git a/src/AST/FunctionExtensions.cs b/src/AST/FunctionExtensions.cs index ce37ec67f5..36ba64b45a 100644 --- a/src/AST/FunctionExtensions.cs +++ b/src/AST/FunctionExtensions.cs @@ -16,18 +16,8 @@ public static IList GatherInternalParams(this Function function, var pointer = new QualifiedType(new PointerType(new QualifiedType(new BuiltinType(PrimitiveType.Void)))); - if (isInstanceMethod && !isItaniumLikeAbi) - { - @params.Add(new Parameter - { - QualifiedType = pointer, - Name = "__instance", - Namespace = function - }); - } - - if (!function.HasIndirectReturnTypeParameter && - isInstanceMethod && isItaniumLikeAbi) + if (isInstanceMethod && + (!isItaniumLikeAbi || !function.HasIndirectReturnTypeParameter)) { @params.Add(new Parameter { diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index d8490a4178..d3d1022e1c 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -2923,14 +2923,9 @@ Enumeration::Item* Parser::WalkEnumItem(clang::EnumConstantDecl* ECD) static const clang::CodeGen::CGFunctionInfo& GetCodeGenFunctionInfo( clang::CodeGen::CodeGenTypes* CodeGenTypes, const clang::FunctionDecl* FD) { - using namespace clang; - if (auto CD = dyn_cast(FD)) { - return CodeGenTypes->arrangeCXXStructorDeclaration(CD); - } else if (auto DD = dyn_cast(FD)) { - return CodeGenTypes->arrangeCXXStructorDeclaration(DD); - } - - return CodeGenTypes->arrangeFunctionDeclaration(FD); + auto FTy = FD->getType()->getCanonicalTypeUnqualified(); + return CodeGenTypes->arrangeFreeFunctionType( + FTy.castAs()); } bool Parser::CanCheckCodeGenInfo(clang::Sema& S, const clang::Type* Ty) @@ -3294,9 +3289,8 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F, unsigned Index = 0; for (const auto& Arg : CGInfo.arguments()) { - if (Index >= F->Parameters.size()) - continue; - F->Parameters[Index++]->isIndirect = Arg.info.isIndirect(); + F->Parameters[Index++]->isIndirect = + Arg.info.isIndirect() && !Arg.info.getIndirectByVal(); } MarkValidity(F); diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index a1b619bd33..5412afcfab 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -253,11 +253,6 @@ public void SetupPasses(ILibrary library) if (Options.IsCSharpGenerator) { - if (Options.GenerateDefaultValuesForArguments) - { - TranslationUnitPasses.AddPass(new FixDefaultParamValuesOfOverridesPass()); - TranslationUnitPasses.AddPass(new HandleDefaultParamValuesPass()); - } TranslationUnitPasses.AddPass(new GenerateAbstractImplementationsPass()); TranslationUnitPasses.AddPass(new MultipleInheritancePass()); } diff --git a/src/Generator/Generators/CSharp/CSharpGenerator.cs b/src/Generator/Generators/CSharp/CSharpGenerator.cs index d31a08520a..b49c1b83fd 100644 --- a/src/Generator/Generators/CSharp/CSharpGenerator.cs +++ b/src/Generator/Generators/CSharp/CSharpGenerator.cs @@ -25,6 +25,12 @@ public override List Generate(IEnumerable units) public override bool SetupPasses() { + if (Context.Options.GenerateDefaultValuesForArguments) + { + Context.TranslationUnitPasses.AddPass(new FixDefaultParamValuesOfOverridesPass()); + Context.TranslationUnitPasses.AddPass(new HandleDefaultParamValuesPass()); + } + // Both the CheckOperatorsOverloadsPass and CheckAbiParameters can // create and and new parameters to functions and methods. Make sure // CheckAbiParameters runs last because hidden structure parameters diff --git a/src/Generator/Passes/HandleDefaultParamValuesPass.cs b/src/Generator/Passes/HandleDefaultParamValuesPass.cs index 9e0296e0a9..77f56dab00 100644 --- a/src/Generator/Passes/HandleDefaultParamValuesPass.cs +++ b/src/Generator/Passes/HandleDefaultParamValuesPass.cs @@ -75,7 +75,7 @@ public override bool VisitFunctionDecl(Function function) { var desugared = type.Desugar(); - if (!desugared.IsPrimitiveTypeConvertibleToRef() && + if (desugared.IsAddress() && !desugared.IsPrimitiveTypeConvertibleToRef() && (expression.String == "0" || expression.String == "nullptr")) { result = desugared.GetPointee()?.Desugar() is FunctionType ? diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 6cb6b4106d..9159c80983 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -249,7 +249,7 @@ public void TestDefaultArguments() methodsWithDefaultValues.DefaultMappedToZeroEnum(); methodsWithDefaultValues.DefaultMappedToEnumAssignedWithCtor(); methodsWithDefaultValues.DefaultZeroMappedToEnumAssignedWithCtor(); - methodsWithDefaultValues.DefaultImplicitCtorInt(); + Assert.That(methodsWithDefaultValues.DefaultImplicitCtorInt().Priv, Is.EqualTo(0)); methodsWithDefaultValues.DefaultImplicitCtorChar(); methodsWithDefaultValues.DefaultImplicitCtorFoo(); methodsWithDefaultValues.DefaultImplicitCtorEnum(); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 250f859514..d487bd1c55 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -117,7 +117,7 @@ Quux::Quux() : _setterWithDefaultOverload(0) Quux::Quux(int i) : Quux() { - + priv = i; } Quux::Quux(char c) : Quux() @@ -139,6 +139,11 @@ Quux::~Quux() } } +int Quux::getPriv() const +{ + return priv; +} + Foo* Quux::setterWithDefaultOverload() { return _setterWithDefaultOverload; @@ -645,8 +650,9 @@ void MethodsWithDefaultValues::defaultZeroMappedToEnumAssignedWithCtor(DefaultZe { } -void MethodsWithDefaultValues::defaultImplicitCtorInt(Quux arg) +Quux MethodsWithDefaultValues::defaultImplicitCtorInt(Quux arg) { + return arg; } void MethodsWithDefaultValues::defaultImplicitCtorChar(Quux arg) diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 0699964538..99b28b04d5 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -56,6 +56,7 @@ class DLL_API Quux Quux(Foo f); ~Quux(); + int getPriv() const; Foo* setterWithDefaultOverload(); void setSetterWithDefaultOverload(Foo* value = new Foo()); @@ -419,7 +420,7 @@ class DLL_API MethodsWithDefaultValues : public Quux void defaultMappedToZeroEnum(QFlags qFlags = 0); void defaultMappedToEnumAssignedWithCtor(QFlags qFlags = QFlags()); void defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum = DefaultZeroMappedToEnum()); - void defaultImplicitCtorInt(Quux arg = 0); + Quux defaultImplicitCtorInt(Quux arg = 0); void defaultImplicitCtorChar(Quux arg = 'a'); void defaultImplicitCtorFoo(Quux arg = Foo()); // this looks the same test as 'defaultRefTypeEnumImplicitCtor' two lines below