Permalink
Browse files

Generated properties from setters returning Booleans.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 22, 2017
1 parent f17441f commit 973fdafdfe06d9ed9aca06650263e0c3b0fb08d8
@@ -372,7 +372,8 @@ private void GeneratePropertySetter<T>(T decl, Class @class, string name, Type t
if (decl is Function && !isIndexer)
{
var func = decl as Function;
GenerateFunctionCall(func, @class);
var @void = new BuiltinType(PrimitiveType.Void);
GenerateFunctionCall(func, @class, @void);
}
else
{
@@ -817,15 +817,17 @@ private void GenerateFunctionSetter(Class @class, Property property)
param.Name = "&" + param.Name;
var parameters = new List<Parameter> { param };
var @void = new QualifiedType(new BuiltinType(PrimitiveType.Void));
if (property.SetMethod.SynthKind == FunctionSynthKind.AbstractImplCall)
GenerateVirtualPropertyCall(property.SetMethod, @class.BaseClass,
property, parameters);
property, parameters, @void);
else if (property.SetMethod.IsVirtual)
GenerateVirtualPropertyCall(property.SetMethod, @class, property, parameters);
GenerateVirtualPropertyCall(property.SetMethod, @class,
property, parameters, @void);
else if (property.SetMethod.OperatorKind == CXXOperatorKind.Subscript)
GenerateIndexerSetter(property.SetMethod);
else
GenerateInternalFunctionCall(property.SetMethod, parameters);
GenerateInternalFunctionCall(property.SetMethod, parameters, @void);
}
private void GenerateFieldSetter(Field field, Class @class)
@@ -1597,20 +1599,29 @@ private void GenerateVTableManagedCall(Method method)
}
}
var hasReturn = !method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void);
bool isVoid = method.OriginalReturnType.Type.Desugar().IsPrimitiveType(
PrimitiveType.Void);
var property = ((Class) method.Namespace).Properties.Find(
p => p.GetMethod == method || p.SetMethod == method);
bool isSetter = property != null && property.SetMethod == method;
var hasReturn = !isVoid && !isSetter;
if (hasReturn)
Write("var {0} = ", Helpers.ReturnIdentifier);
Write($"var {Helpers.ReturnIdentifier} = ");
if (method.IsGenerated)
Write($"{Helpers.TargetIdentifier}.");
string marshalsCode = string.Join(", ", marshals);
if (property == null)
{
WriteLine("{0}.{1}({2});", Helpers.TargetIdentifier,
method.Name, string.Join(", ", marshals));
Write($"{method.Name}({marshalsCode})");
}
else
{
InvokeProperty(method, marshals);
Write($"{property.Name}");
if (isSetter)
Write($" = {marshalsCode}");
}
WriteLine(";");
if (hasReturn)
{
@@ -1649,27 +1660,13 @@ private void GenerateVTableManagedCall(Method method)
}
}
if (!isVoid && isSetter)
WriteLine("return false;");
for (var i = 0; i < numBlocks; ++i)
WriteCloseBraceIndent();
}
private void InvokeProperty(Declaration method, IEnumerable<string> marshals)
{
var property = ((Class) method.Namespace).Properties.FirstOrDefault(
p => p.GetMethod == method);
if (property == null)
{
property = ((Class) method.Namespace).Properties.First(
p => p.SetMethod == method);
WriteLine("{0}.{1} = {2};", Helpers.TargetIdentifier, property.Name,
string.Join(", ", marshals));
}
else
{
WriteLine("{0}.{1};", Helpers.TargetIdentifier, property.Name);
}
}
private void GenerateVTableMethodDelegates(Class @class, Method method)
{
PushBlock(BlockKind.VTableDelegate);
@@ -247,7 +247,10 @@ private static string GetPropertyNameFromSetter(Method setter)
private void DistributeMethod(Method method)
{
if (method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
Type returnType = method.OriginalReturnType.Type.Desugar();
if ((returnType.IsPrimitiveType(PrimitiveType.Void) ||
returnType.IsPrimitiveType(PrimitiveType.Bool)) &&
method.Parameters.Any(p => p.Kind == ParameterKind.Regular))
{
if (method.Parameters.Count == 1)
setters.Add(method);
@@ -473,6 +473,12 @@ public void TestProperties()
prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
prop.SetterReturnsBoolean = 35;
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
}
[Test]
@@ -489,7 +489,8 @@ std::string& HasStdString::getStdString()
return s;
}
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0), _getterAndSetterWithTheSameName(0)
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0),
_getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0), _virtualSetterReturnsBoolean(0)
{
}
@@ -536,6 +537,30 @@ void TestProperties::set(int value)
{
}
int TestProperties::setterReturnsBoolean()
{
return _setterReturnsBoolean;
}
bool TestProperties::setterReturnsBoolean(int value)
{
bool changed = _setterReturnsBoolean != value;
_setterReturnsBoolean = value;
return changed;
}
int TestProperties::virtualSetterReturnsBoolean()
{
return _virtualSetterReturnsBoolean;
}
bool TestProperties::setVirtualSetterReturnsBoolean(int value)
{
bool changed = _virtualSetterReturnsBoolean != value;
_virtualSetterReturnsBoolean = value;
return changed;
}
HasOverridenSetter::HasOverridenSetter()
{
}
@@ -544,6 +569,16 @@ void HasOverridenSetter::setVirtual(bool value)
{
}
int HasOverridenSetter::virtualSetterReturnsBoolean()
{
return TestProperties::virtualSetterReturnsBoolean();
}
bool HasOverridenSetter::setVirtualSetterReturnsBoolean(int value)
{
return TestProperties::setVirtualSetterReturnsBoolean(value);
}
TypeMappedIndex::TypeMappedIndex()
{
}
@@ -590,17 +590,28 @@ struct DLL_API TestProperties
void getterAndSetterWithTheSameName(int value);
void set(int value);
int setterReturnsBoolean();
bool setterReturnsBoolean(int value);
virtual int virtualSetterReturnsBoolean();
virtual bool setVirtualSetterReturnsBoolean(int value);
private:
int FieldValue;
double _refToPrimitiveInSetter;
int _getterAndSetterWithTheSameName;
int _setterReturnsBoolean;
int _virtualSetterReturnsBoolean;
};
class DLL_API HasOverridenSetter : public TestProperties
{
public:
HasOverridenSetter();
void setVirtual(bool value);
int virtualSetterReturnsBoolean() override;
bool setVirtualSetterReturnsBoolean(int value) override;
};
class DLL_API TypeMappedIndex
@@ -1368,4 +1379,4 @@ inline namespace InlineNamespace
{
}
}
}

0 comments on commit 973fdaf

Please sign in to comment.