From 1872d0178db350fcee915ed9eee254a41544b6a1 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 21 Sep 2016 23:04:57 +0800 Subject: [PATCH] Revert "Compile all UI nodes to static methods" --- .../Graph/Nodes/ZeroTouch/DSFunctionBase.cs | 57 ++++++++++-- src/Engine/ProtoAssociative/CodeGen.cs | 2 +- src/Engine/ProtoCore/DSASM/DSasmDefs.cs | 4 +- src/Engine/ProtoCore/FFI/CLRDLLModule.cs | 5 +- test/DynamoCoreTests/DSEvaluationModelTest.cs | 9 -- test/DynamoCoreTests/NodeToCodeTest.cs | 4 +- test/core/DynamoDefects/Bool_Case_3420.dyn | 4 +- test/core/dsevaluation/heterogenous-input.dyn | 91 ------------------- 8 files changed, 61 insertions(+), 115 deletions(-) delete mode 100644 test/core/dsevaluation/heterogenous-input.dyn diff --git a/src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs b/src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs index 955bb1273fa..4bb3948cf1c 100644 --- a/src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs +++ b/src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs @@ -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 @@ -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: diff --git a/src/Engine/ProtoAssociative/CodeGen.cs b/src/Engine/ProtoAssociative/CodeGen.cs index c2765df4bc7..d3529ab9ce6 100644 --- a/src/Engine/ProtoAssociative/CodeGen.cs +++ b/src/Engine/ProtoAssociative/CodeGen.cs @@ -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)) { @@ -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; diff --git a/src/Engine/ProtoCore/DSASM/DSasmDefs.cs b/src/Engine/ProtoCore/DSASM/DSasmDefs.cs index a458bf639e6..06bf8dbc7bd 100644 --- a/src/Engine/ProtoCore/DSASM/DSasmDefs.cs +++ b/src/Engine/ProtoCore/DSASM/DSasmDefs.cs @@ -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"; diff --git a/src/Engine/ProtoCore/FFI/CLRDLLModule.cs b/src/Engine/ProtoCore/FFI/CLRDLLModule.cs index 38de55a329e..765eaa86a60 100644 --- a/src/Engine/ProtoCore/FFI/CLRDLLModule.cs +++ b/src/Engine/ProtoCore/FFI/CLRDLLModule.cs @@ -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; @@ -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) diff --git a/test/DynamoCoreTests/DSEvaluationModelTest.cs b/test/DynamoCoreTests/DSEvaluationModelTest.cs index edf1f6246a5..4f8577202dd 100644 --- a/test/DynamoCoreTests/DSEvaluationModelTest.cs +++ b/test/DynamoCoreTests/DSEvaluationModelTest.cs @@ -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")] diff --git a/test/DynamoCoreTests/NodeToCodeTest.cs b/test/DynamoCoreTests/NodeToCodeTest.cs index 61bf6e568cd..7e68044a1d6 100644 --- a/test/DynamoCoreTests/NodeToCodeTest.cs +++ b/test/DynamoCoreTests/NodeToCodeTest.cs @@ -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] @@ -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)); } diff --git a/test/core/DynamoDefects/Bool_Case_3420.dyn b/test/core/DynamoDefects/Bool_Case_3420.dyn index bb4ca8d2396..08201a6d9eb 100644 --- a/test/core/DynamoDefects/Bool_Case_3420.dyn +++ b/test/core/DynamoDefects/Bool_Case_3420.dyn @@ -28,7 +28,7 @@ - + @@ -47,4 +47,4 @@ - + \ No newline at end of file diff --git a/test/core/dsevaluation/heterogenous-input.dyn b/test/core/dsevaluation/heterogenous-input.dyn deleted file mode 100644 index ded6d082a30..00000000000 --- a/test/core/dsevaluation/heterogenous-input.dyn +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file