diff --git a/ir/Function.cpp b/ir/Function.cpp index 95092e2..132b194 100644 --- a/ir/Function.cpp +++ b/ir/Function.cpp @@ -23,7 +23,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Function &func) { } if (func.isVariadic) { /* the C Iso require at least one argument in a variadic function, so the comma is fine */ - s << ", varArgs: native.CVararg*"; + s << ", " << func.getVarargsParameterName() << ": native.CVararg*"; } s << "): " << func.retType @@ -46,3 +46,21 @@ bool Function::usesType(const std::string &type) const { std::string Function::getName() const { return name; } + +std::string Function::getVarargsParameterName() const { + std::string parameterName = "varArgs"; + int i = 0; + while (existParameterWithName(parameterName)) { + parameterName = "varArgs" + std::to_string(i++); + } + return parameterName; +} + +bool Function::existParameterWithName(const std::string ¶meterName) const { + for (const auto ¶meter : parameters) { + if (parameter.getName() == parameterName) { + return true; + } + } + return false; +} diff --git a/ir/Function.h b/ir/Function.h index b6e4718..fbe8323 100644 --- a/ir/Function.h +++ b/ir/Function.h @@ -24,6 +24,11 @@ class Function { std::string getName() const; private: + + std::string getVarargsParameterName() const; + + bool existParameterWithName(const std::string ¶meterName) const; + std::string name; std::vector parameters; std::string retType; diff --git a/tests/samples/Function.h b/tests/samples/Function.h index 4a848cb..7412a73 100644 --- a/tests/samples/Function.h +++ b/tests/samples/Function.h @@ -3,4 +3,4 @@ int void_arg(void); void one_arg(int a); void *two_args(float a, int b); void anonymous_args(float, int); -double variadic_args(double a, void* b, ...); +double variadic_args(double a, void* varArgs, ...); diff --git a/tests/samples/Function.scala b/tests/samples/Function.scala index 8457666..092586c 100644 --- a/tests/samples/Function.scala +++ b/tests/samples/Function.scala @@ -10,5 +10,5 @@ object Function { def one_arg(a: native.CInt): Unit = native.extern def two_args(a: native.CFloat, b: native.CInt): native.Ptr[Byte] = native.extern def anonymous_args(anonymous0: native.CFloat, anonymous1: native.CInt): Unit = native.extern - def variadic_args(a: native.CDouble, b: native.Ptr[Byte], varArgs: native.CVararg*): native.CDouble = native.extern + def variadic_args(a: native.CDouble, varArgs: native.Ptr[Byte], varArgs0: native.CVararg*): native.CDouble = native.extern }