Skip to content

Commit

Permalink
Merge pull request #7186 from DynamoDS/revert-7178-static-methods
Browse files Browse the repository at this point in the history
Revert "Compile all UI nodes to static methods"
  • Loading branch information
ke-yu authored Sep 21, 2016
2 parents b5ad113 + 1872d01 commit feb3af1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 115 deletions.
57 changes: 51 additions & 6 deletions src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ protected override AssociativeNode GetFunctionApplication(NodeModel model, List<
{
case FunctionType.Constructor:
case FunctionType.StaticMethod:
case FunctionType.InstanceMethod:
if (model.IsPartiallyApplied)
{
var functionNode = new IdentifierListNode
Expand Down Expand Up @@ -308,24 +307,70 @@ protected override AssociativeNode GetFunctionApplication(NodeModel model, List<
break;

case FunctionType.InstanceProperty:

// Only handle getter here. Setter could be handled in CBN.
if (model.IsPartiallyApplied)
{
var functionNode = new IdentifierListNode
{
LeftNode = new IdentifierNode(Definition.ClassName),
RightNode = new IdentifierNode(ProtoCore.DSASM.Constants.kGetterPrefix + Definition.FunctionName)
RightNode = new IdentifierNode(Definition.FunctionName)
};
rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
}
else
{
rhs = new NullNode();
if (inputAstNodes != null && inputAstNodes.Count >= 1)
{
var thisNode = inputAstNodes[0];
if (thisNode != null && !(thisNode is NullNode))
{
var insProp = new IdentifierListNode
{
LeftNode = inputAstNodes[0],
RightNode = new IdentifierNode(Definition.FunctionName)
};
rhs = insProp;
}
}
}

break;

case FunctionType.InstanceMethod:
if (model.IsPartiallyApplied)
{
var functionNode = new IdentifierListNode
{
LeftNode = new IdentifierNode(Definition.ClassName),
RightNode = new IdentifierNode(Definition.FunctionName)
};
rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
}
else
{
rhs = new NullNode();
model.UseLevelAndReplicationGuide(inputAstNodes);
rhs = AstFactory.BuildFunctionCall(
Definition.ClassName,
ProtoCore.DSASM.Constants.kGetterPrefix + Definition.FunctionName,
inputAstNodes);

if (inputAstNodes != null && inputAstNodes.Count >= 1)
{
var thisNode = inputAstNodes[0];
inputAstNodes.RemoveAt(0); // remove this pointer

if (thisNode != null && !(thisNode is NullNode))
{
var memberFunc = new IdentifierListNode
{
LeftNode = thisNode,
RightNode =
AstFactory.BuildFunctionCall(function, inputAstNodes)
};
rhs = memberFunc;
}
}
}

break;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/ProtoAssociative/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,6 @@ private void EmitClassDeclNode(AssociativeNode node, ref ProtoCore.Type inferedT
};
procNode.Signature.Arguments.Insert(0, thisPtrArg);
procNode.IsAutoGeneratedThisProc = true;
procNode.IsStatic = true;

if (CoreUtils.IsGetterSetter(funcDef.Name))
{
Expand Down Expand Up @@ -3121,6 +3120,7 @@ private void EmitClassDeclNode(AssociativeNode node, ref ProtoCore.Type inferedT
// {
// return = a.f()
// }
procNode.IsStatic = true;
var args = procNode.Signature.Arguments.Select(a => a.NameNode).ToList();
var fcall = AstFactory.BuildFunctionCall(procNode.Name, args) as FunctionCallNode;

Expand Down
4 changes: 2 additions & 2 deletions src/Engine/ProtoCore/DSASM/DSasmDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ public struct Constants

public const string termline = ";\n";
public const string kInternalNamePrefix = "%";
public const string kGetterPrefix = "get_";
public const string kSetterPrefix = "set_";
public const string kGetterPrefix = "%get_";
public const string kSetterPrefix = "%set_";
public const string kLHS = "%lhs";
public const string kRHS = "%rhs";
public const string kTempFunctionReturnVar = "%tmpRet";
Expand Down
5 changes: 3 additions & 2 deletions src/Engine/ProtoCore/FFI/CLRDLLModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private ProtoCore.AST.AssociativeAST.FunctionDefinitionNode ParseFieldAccessor(F
return null;

ProtoCore.AST.AssociativeAST.FunctionDefinitionNode func = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
func.Name = string.Format("{0}{1}", Constants.kGetterPrefix, f.Name);
func.Name = string.Format("%get_{0}", f.Name);
func.Signature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
func.ReturnType = CLRModuleType.GetProtoCoreType(f.FieldType, Module);
func.FunctionBody = null;
Expand Down Expand Up @@ -688,7 +688,8 @@ private ProtoCore.AST.AssociativeAST.AssociativeNode ParseMethod(MethodInfo meth
return node;
}

string prefix = isOperator ? Constants.kInternalNamePrefix : string.Empty;
//Need to hide property accessor from design script users, prefix with %
string prefix = (isOperator || propaccessor) ? "%" : "";
var func = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();

if (isOperator)
Expand Down
9 changes: 0 additions & 9 deletions test/DynamoCoreTests/DSEvaluationModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,6 @@ public void TestContainsArray()
AssertPreviewValue("b0d7b844-93a9-43fa-b8f1-15cbb7469a84", true);
AssertPreviewValue("d1942e84-355f-4083-bb1c-6b7203ee192c", true);
}

[Test]
public void TestHeterogeneousArray()
{
var dynFilePath = Path.Combine(TestDirectory, @"core\dsevaluation\heterogenous-input.dyn");
OpenModel(dynFilePath);
AssertPreviewValue("4bc89f87-5496-4932-88c1-9f184da70f58", new object[] {null, null, 2, 5 });
AssertPreviewValue("d1d6bc0b-aea9-4a62-9a27-af7c502f9e62", new object[] {null, null, 7, 16 });
}
}

[Category("DSCustomNode")]
Expand Down
4 changes: 2 additions & 2 deletions test/DynamoCoreTests/NodeToCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void TestShortestQualifiedNameReplacer6()

var expr = result.AstNodes.Last() as BinaryExpressionNode;
Assert.IsNotNull(expr);
Assert.AreEqual("Geometry.DistanceTo(t1, t2)", expr.RightNode.ToString());
Assert.AreEqual("t1.DistanceTo(t2)", expr.RightNode.ToString());
}

[Test]
Expand Down Expand Up @@ -839,7 +839,7 @@ public void TestPropertyWontBeReplaced1()
NodeToCodeCompiler.ReplaceWithShortestQualifiedName(engine.LibraryServices.LibraryManagementCore.ClassTable, result.AstNodes);
Assert.IsTrue(result != null && result.AstNodes != null);

var rhs = result.AstNodes.Skip(1).Select(b => (b as BinaryExpressionNode).RightNode.ToString().Contains("get_X"));
var rhs = result.AstNodes.Skip(1).Select(b => (b as BinaryExpressionNode).RightNode.ToString().EndsWith(".X"));
Assert.IsTrue(rhs.All(r => r));
}

Expand Down
4 changes: 2 additions & 2 deletions test/core/DynamoDefects/Bool_Case_3420.dyn
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PortInfo index="2" default="True" />
</Dynamo.Nodes.DSFunction>
<Dynamo.Nodes.CodeBlockNodeModel type="Dynamo.Nodes.CodeBlockNodeModel" guid="da9c1757-2cd4-4a25-b4a6-0e90ede88bf7" nickname="Code Block" x="-606" y="-614" isVisible="true" isUpstreamVisible="true" lacing="Disabled" CodeText="0.1;" ShouldFocus="false" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="b8f4c8fb-fa8b-4c10-96b7-70c5763917cd" nickname="Solid.Area" x="-210.836870097748" y="-555.736219208454" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="ProtoGeometry.dll" function="Autodesk.DesignScript.Geometry.Solid.Area" />
<Dynamo.Nodes.DSFunction type="Dynamo.Nodes.DSFunction" guid="b8f4c8fb-fa8b-4c10-96b7-70c5763917cd" nickname="Surface.Area" x="-210.836870097748" y="-555.736219208454" isVisible="true" isUpstreamVisible="true" lacing="Shortest" assembly="ProtoGeometry.dll" function="Autodesk.DesignScript.Geometry.Surface.Area" />
</Elements>
<Connectors>
<Dynamo.Models.ConnectorModel start="ebd1f642-ee18-46d7-ad76-490d6adcf3f0" start_index="0" end="a95a201d-c07b-4b11-9154-5ad0ee995243" end_index="2" portType="0" />
Expand All @@ -47,4 +47,4 @@
<Dynamo.Models.ConnectorModel start="da9c1757-2cd4-4a25-b4a6-0e90ede88bf7" start_index="0" end="a95a201d-c07b-4b11-9154-5ad0ee995243" end_index="1" portType="0" />
</Connectors>
<Notes />
</Workspace>
</Workspace>
Loading

0 comments on commit feb3af1

Please sign in to comment.