{"action":"created","comment":{"url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/comments/28666877","id":28666877,"diff_hunk":"@@ -1,16 +1,692 @@\n ﻿using System.Collections.Generic;\n-\n+using System.Linq;\n using Dynamo.Models;\n+using Dynamo.Nodes;\n+using System;\n+using ProtoCore.AST.AssociativeAST;\n+using ProtoCore.DSASM;\n+using Dynamo.Utilities;\n \n namespace Dynamo.DSEngine\n {\n-    public static class NodeToCodeUtils\n+    /// <summary>\n+    /// The result of converting nodes to code. As when a node is converted to \n+    /// code, its inputs and outputs may be renamed to avoid confliction, the\n+    /// result contains maps for inputs/new-inputs and outputs/new-outputs.\n+    /// </summary>\n+    public class NodeToCodeResult\n+    {\n+        /// <summary>\n+        /// AST nodes that compiled from NodeModel.\n+        /// </summary>\n+        public IEnumerable<AssociativeNode> AstNodes { get; private set; }\n+\n+        /// <summary>\n+        /// The map between original input name and new name.\n+        /// </summary>\n+        public Dictionary<string, string> InputMap { get; private set; }\n+\n+        /// <summary>\n+        /// The map between original output name and new name.\n+        /// </summary>\n+        public Dictionary<string, string> OutputMap { get; private set; }\n+\n+        public NodeToCodeResult(\n+            IEnumerable<AssociativeNode> astNodes, \n+            Dictionary<string, string> inputMap, \n+            Dictionary<string, string> outputMap)\n+        {\n+            AstNodes = astNodes;\n+            InputMap = inputMap;\n+            OutputMap = outputMap;\n+        }\n+    }\n+    public class NodeToCodeUtils\n     {\n-        public static string ConvertNodesToCode(AstBuilder astBuilder, IEnumerable<NodeModel> nodeList, bool verboseLogging)\n+        /// <summary>\n+        /// Traverse all identifiers in depth-first order and for each \n+        /// identifier apply a function to it.\n+        /// </summary>\n+        private class IdentifierVisitor\n+        {\n+            public static void Visit(AssociativeNode astNode, Action<IdentifierNode> func)\n+            {\n+                if (astNode is IdentifierNode)\n+                {\n+                    var identNode = astNode as IdentifierNode;\n+                    func(identNode);\n+                    Visit(identNode.ArrayDimensions, func);\n+                }\n+                else if (astNode is IdentifierListNode)\n+                {\n+                    var node = astNode as IdentifierListNode;\n+                    Visit(node.LeftNode, func);\n+                    Visit(node.RightNode, func);\n+                }\n+                else if (astNode is FunctionCallNode)\n+                {\n+                    var node = astNode as FunctionCallNode;\n+                    for (int i = 0; i < node.FormalArguments.Count; ++i)","path":"src/DynamoCore/DSEngine/NodeToCode.cs","position":72,"original_position":72,"commit_id":"af333af84e9c4e66eecddd5d4f423ab0388617a7","original_commit_id":"ea1516f17da8d467a8b82097df4043c9f94d0e9b","user":{"login":"Benglin","id":5086849,"avatar_url":"https://avatars.githubusercontent.com/u/5086849?v=3","gravatar_id":"","url":"https://api.github.com/users/Benglin","html_url":"https://github.com/Benglin","followers_url":"https://api.github.com/users/Benglin/followers","following_url":"https://api.github.com/users/Benglin/following{/other_user}","gists_url":"https://api.github.com/users/Benglin/gists{/gist_id}","starred_url":"https://api.github.com/users/Benglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Benglin/subscriptions","organizations_url":"https://api.github.com/users/Benglin/orgs","repos_url":"https://api.github.com/users/Benglin/repos","events_url":"https://api.github.com/users/Benglin/events{/privacy}","received_events_url":"https://api.github.com/users/Benglin/received_events","type":"User","site_admin":false},"body":"Good point about the `MoveNext`. Anyway, I don't see how `Visit` method modify the content of `FormalArguments` and `node.list`, am I missing anything?","created_at":"2015-04-20T06:51:54Z","updated_at":"2015-04-20T06:51:54Z","html_url":"https://github.com/DynamoDS/Dynamo/pull/4216#discussion_r28666877","pull_request_url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216","_links":{"self":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/comments/28666877"},"html":{"href":"https://github.com/DynamoDS/Dynamo/pull/4216#discussion_r28666877"},"pull_request":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216"}}},"pull_request":{"url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216","id":33016396,"html_url":"https://github.com/DynamoDS/Dynamo/pull/4216","diff_url":"https://github.com/DynamoDS/Dynamo/pull/4216.diff","patch_url":"https://github.com/DynamoDS/Dynamo/pull/4216.patch","issue_url":"https://api.github.com/repos/DynamoDS/Dynamo/issues/4216","number":4216,"state":"open","locked":false,"title":"Basic implementation of node to code","user":{"login":"ke-yu","id":2600379,"avatar_url":"https://avatars.githubusercontent.com/u/2600379?v=3","gravatar_id":"","url":"https://api.github.com/users/ke-yu","html_url":"https://github.com/ke-yu","followers_url":"https://api.github.com/users/ke-yu/followers","following_url":"https://api.github.com/users/ke-yu/following{/other_user}","gists_url":"https://api.github.com/users/ke-yu/gists{/gist_id}","starred_url":"https://api.github.com/users/ke-yu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ke-yu/subscriptions","organizations_url":"https://api.github.com/users/ke-yu/orgs","repos_url":"https://api.github.com/users/ke-yu/repos","events_url":"https://api.github.com/users/ke-yu/events{/privacy}","received_events_url":"https://api.github.com/users/ke-yu/received_events","type":"User","site_admin":false},"body":"This pull request re-enables [node to code] (http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6768) command and enhances the original implementation. Note the implementation is not complete yet.  \r\n\r\n* **What are done in this pull request?**\r\n  1. Node to code command is re-enabled in the context menu of a selection\r\n![1](https://cloud.githubusercontent.com/assets/2600379/7081485/6fe3e1bc-df75-11e4-98ce-808fe13961e4.png)\r\n  2. No more long and mysterious variable names in generated code\r\n![2](https://cloud.githubusercontent.com/assets/2600379/7081548/65927704-df76-11e4-9400-68e62a68f38a.png)\r\n  3. Conflicting variables will be renamed in the generated code block node\r\n![3](https://cloud.githubusercontent.com/assets/2600379/7081567/bd5f99da-df76-11e4-9790-f3730f609063.png)\r\n  4. If there are holes in the selection node (for example, some nodes not selected but connecting to selected node, or the selection contains nodes that can't be converted now like custom nodes and partially applied function nodes), multiple code block nodes may be created. For example, in the following graph 4 code block nodes are selected but not `+` node, so 2 code block nodes will be finally created. Multiple code block nodes are created to avoid circular reference.\r\n![untitled](https://cloud.githubusercontent.com/assets/2600379/7224036/24565fa8-e75f-11e4-8ee0-db771d98d976.png)\r\n\r\n* **What haven't been done in this pull request?**\r\n  1. Custom node, partial applied function and UI nodes can't be converted to code. The reasons are, for custom node, as it will compiled to mysterious name like \"``__func__6BBA4B28C5E54CF89F300D510499A00E``\", it is hard to figure out what's custom node that it represents for. Partial applied function will be compiled to ``__SingleFunctionObject`` which is mysterious for most users and UI nodes are not compiled to a direct function. But we'll fix these issues in the following sprint. \r\n* **What's the scope of impact?**\r\n  1. It is self-contained functionality, so shouldn't have impact on the existing ones. Most implementation is in `Dynamo.DSEngine.NodeToCodeUtils`.\r\n\r\n@Benglin please help to review the change. Thanks. ","created_at":"2015-04-10T03:56:45Z","updated_at":"2015-04-20T06:51:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9d6728fff8c47cc835823063f074d6dc7f334b41","assignee":{"login":"Benglin","id":5086849,"avatar_url":"https://avatars.githubusercontent.com/u/5086849?v=3","gravatar_id":"","url":"https://api.github.com/users/Benglin","html_url":"https://github.com/Benglin","followers_url":"https://api.github.com/users/Benglin/followers","following_url":"https://api.github.com/users/Benglin/following{/other_user}","gists_url":"https://api.github.com/users/Benglin/gists{/gist_id}","starred_url":"https://api.github.com/users/Benglin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Benglin/subscriptions","organizations_url":"https://api.github.com/users/Benglin/orgs","repos_url":"https://api.github.com/users/Benglin/repos","events_url":"https://api.github.com/users/Benglin/events{/privacy}","received_events_url":"https://api.github.com/users/Benglin/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216/commits","review_comments_url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216/comments","review_comment_url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DynamoDS/Dynamo/issues/4216/comments","statuses_url":"https://api.github.com/repos/DynamoDS/Dynamo/statuses/af333af84e9c4e66eecddd5d4f423ab0388617a7","head":{"label":"ke-yu:node2code","ref":"node2code","sha":"af333af84e9c4e66eecddd5d4f423ab0388617a7","user":{"login":"ke-yu","id":2600379,"avatar_url":"https://avatars.githubusercontent.com/u/2600379?v=3","gravatar_id":"","url":"https://api.github.com/users/ke-yu","html_url":"https://github.com/ke-yu","followers_url":"https://api.github.com/users/ke-yu/followers","following_url":"https://api.github.com/users/ke-yu/following{/other_user}","gists_url":"https://api.github.com/users/ke-yu/gists{/gist_id}","starred_url":"https://api.github.com/users/ke-yu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ke-yu/subscriptions","organizations_url":"https://api.github.com/users/ke-yu/orgs","repos_url":"https://api.github.com/users/ke-yu/repos","events_url":"https://api.github.com/users/ke-yu/events{/privacy}","received_events_url":"https://api.github.com/users/ke-yu/received_events","type":"User","site_admin":false},"repo":{"id":18300645,"name":"Dynamo","full_name":"ke-yu/Dynamo","owner":{"login":"ke-yu","id":2600379,"avatar_url":"https://avatars.githubusercontent.com/u/2600379?v=3","gravatar_id":"","url":"https://api.github.com/users/ke-yu","html_url":"https://github.com/ke-yu","followers_url":"https://api.github.com/users/ke-yu/followers","following_url":"https://api.github.com/users/ke-yu/following{/other_user}","gists_url":"https://api.github.com/users/ke-yu/gists{/gist_id}","starred_url":"https://api.github.com/users/ke-yu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ke-yu/subscriptions","organizations_url":"https://api.github.com/users/ke-yu/orgs","repos_url":"https://api.github.com/users/ke-yu/repos","events_url":"https://api.github.com/users/ke-yu/events{/privacy}","received_events_url":"https://api.github.com/users/ke-yu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ke-yu/Dynamo","description":"Visual Programming For Revit","fork":true,"url":"https://api.github.com/repos/ke-yu/Dynamo","forks_url":"https://api.github.com/repos/ke-yu/Dynamo/forks","keys_url":"https://api.github.com/repos/ke-yu/Dynamo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ke-yu/Dynamo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ke-yu/Dynamo/teams","hooks_url":"https://api.github.com/repos/ke-yu/Dynamo/hooks","issue_events_url":"https://api.github.com/repos/ke-yu/Dynamo/issues/events{/number}","events_url":"https://api.github.com/repos/ke-yu/Dynamo/events","assignees_url":"https://api.github.com/repos/ke-yu/Dynamo/assignees{/user}","branches_url":"https://api.github.com/repos/ke-yu/Dynamo/branches{/branch}","tags_url":"https://api.github.com/repos/ke-yu/Dynamo/tags","blobs_url":"https://api.github.com/repos/ke-yu/Dynamo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ke-yu/Dynamo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ke-yu/Dynamo/git/refs{/sha}","trees_url":"https://api.github.com/repos/ke-yu/Dynamo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ke-yu/Dynamo/statuses/{sha}","languages_url":"https://api.github.com/repos/ke-yu/Dynamo/languages","stargazers_url":"https://api.github.com/repos/ke-yu/Dynamo/stargazers","contributors_url":"https://api.github.com/repos/ke-yu/Dynamo/contributors","subscribers_url":"https://api.github.com/repos/ke-yu/Dynamo/subscribers","subscription_url":"https://api.github.com/repos/ke-yu/Dynamo/subscription","commits_url":"https://api.github.com/repos/ke-yu/Dynamo/commits{/sha}","git_commits_url":"https://api.github.com/repos/ke-yu/Dynamo/git/commits{/sha}","comments_url":"https://api.github.com/repos/ke-yu/Dynamo/comments{/number}","issue_comment_url":"https://api.github.com/repos/ke-yu/Dynamo/issues/comments{/number}","contents_url":"https://api.github.com/repos/ke-yu/Dynamo/contents/{+path}","compare_url":"https://api.github.com/repos/ke-yu/Dynamo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ke-yu/Dynamo/merges","archive_url":"https://api.github.com/repos/ke-yu/Dynamo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ke-yu/Dynamo/downloads","issues_url":"https://api.github.com/repos/ke-yu/Dynamo/issues{/number}","pulls_url":"https://api.github.com/repos/ke-yu/Dynamo/pulls{/number}","milestones_url":"https://api.github.com/repos/ke-yu/Dynamo/milestones{/number}","notifications_url":"https://api.github.com/repos/ke-yu/Dynamo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ke-yu/Dynamo/labels{/name}","releases_url":"https://api.github.com/repos/ke-yu/Dynamo/releases{/id}","created_at":"2014-03-31T16:53:50Z","updated_at":"2014-06-26T05:45:55Z","pushed_at":"2015-04-20T04:53:54Z","git_url":"git://github.com/ke-yu/Dynamo.git","ssh_url":"git@github.com:ke-yu/Dynamo.git","clone_url":"https://github.com/ke-yu/Dynamo.git","svn_url":"https://github.com/ke-yu/Dynamo","homepage":"http://dynamobim.org","size":674014,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"DynamoDS:master","ref":"master","sha":"5463fb88ac02b5ad260d17dd38db823f3aa81265","user":{"login":"DynamoDS","id":6528209,"avatar_url":"https://avatars.githubusercontent.com/u/6528209?v=3","gravatar_id":"","url":"https://api.github.com/users/DynamoDS","html_url":"https://github.com/DynamoDS","followers_url":"https://api.github.com/users/DynamoDS/followers","following_url":"https://api.github.com/users/DynamoDS/following{/other_user}","gists_url":"https://api.github.com/users/DynamoDS/gists{/gist_id}","starred_url":"https://api.github.com/users/DynamoDS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DynamoDS/subscriptions","organizations_url":"https://api.github.com/users/DynamoDS/orgs","repos_url":"https://api.github.com/users/DynamoDS/repos","events_url":"https://api.github.com/users/DynamoDS/events{/privacy}","received_events_url":"https://api.github.com/users/DynamoDS/received_events","type":"Organization","site_admin":false},"repo":{"id":3395179,"name":"Dynamo","full_name":"DynamoDS/Dynamo","owner":{"login":"DynamoDS","id":6528209,"avatar_url":"https://avatars.githubusercontent.com/u/6528209?v=3","gravatar_id":"","url":"https://api.github.com/users/DynamoDS","html_url":"https://github.com/DynamoDS","followers_url":"https://api.github.com/users/DynamoDS/followers","following_url":"https://api.github.com/users/DynamoDS/following{/other_user}","gists_url":"https://api.github.com/users/DynamoDS/gists{/gist_id}","starred_url":"https://api.github.com/users/DynamoDS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DynamoDS/subscriptions","organizations_url":"https://api.github.com/users/DynamoDS/orgs","repos_url":"https://api.github.com/users/DynamoDS/repos","events_url":"https://api.github.com/users/DynamoDS/events{/privacy}","received_events_url":"https://api.github.com/users/DynamoDS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DynamoDS/Dynamo","description":"Visual Programming","fork":false,"url":"https://api.github.com/repos/DynamoDS/Dynamo","forks_url":"https://api.github.com/repos/DynamoDS/Dynamo/forks","keys_url":"https://api.github.com/repos/DynamoDS/Dynamo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DynamoDS/Dynamo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DynamoDS/Dynamo/teams","hooks_url":"https://api.github.com/repos/DynamoDS/Dynamo/hooks","issue_events_url":"https://api.github.com/repos/DynamoDS/Dynamo/issues/events{/number}","events_url":"https://api.github.com/repos/DynamoDS/Dynamo/events","assignees_url":"https://api.github.com/repos/DynamoDS/Dynamo/assignees{/user}","branches_url":"https://api.github.com/repos/DynamoDS/Dynamo/branches{/branch}","tags_url":"https://api.github.com/repos/DynamoDS/Dynamo/tags","blobs_url":"https://api.github.com/repos/DynamoDS/Dynamo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DynamoDS/Dynamo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DynamoDS/Dynamo/git/refs{/sha}","trees_url":"https://api.github.com/repos/DynamoDS/Dynamo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DynamoDS/Dynamo/statuses/{sha}","languages_url":"https://api.github.com/repos/DynamoDS/Dynamo/languages","stargazers_url":"https://api.github.com/repos/DynamoDS/Dynamo/stargazers","contributors_url":"https://api.github.com/repos/DynamoDS/Dynamo/contributors","subscribers_url":"https://api.github.com/repos/DynamoDS/Dynamo/subscribers","subscription_url":"https://api.github.com/repos/DynamoDS/Dynamo/subscription","commits_url":"https://api.github.com/repos/DynamoDS/Dynamo/commits{/sha}","git_commits_url":"https://api.github.com/repos/DynamoDS/Dynamo/git/commits{/sha}","comments_url":"https://api.github.com/repos/DynamoDS/Dynamo/comments{/number}","issue_comment_url":"https://api.github.com/repos/DynamoDS/Dynamo/issues/comments{/number}","contents_url":"https://api.github.com/repos/DynamoDS/Dynamo/contents/{+path}","compare_url":"https://api.github.com/repos/DynamoDS/Dynamo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DynamoDS/Dynamo/merges","archive_url":"https://api.github.com/repos/DynamoDS/Dynamo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DynamoDS/Dynamo/downloads","issues_url":"https://api.github.com/repos/DynamoDS/Dynamo/issues{/number}","pulls_url":"https://api.github.com/repos/DynamoDS/Dynamo/pulls{/number}","milestones_url":"https://api.github.com/repos/DynamoDS/Dynamo/milestones{/number}","notifications_url":"https://api.github.com/repos/DynamoDS/Dynamo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DynamoDS/Dynamo/labels{/name}","releases_url":"https://api.github.com/repos/DynamoDS/Dynamo/releases{/id}","created_at":"2012-02-09T07:35:33Z","updated_at":"2015-04-19T06:55:37Z","pushed_at":"2015-04-20T06:42:21Z","git_url":"git://github.com/DynamoDS/Dynamo.git","ssh_url":"git@github.com:DynamoDS/Dynamo.git","clone_url":"https://github.com/DynamoDS/Dynamo.git","svn_url":"https://github.com/DynamoDS/Dynamo","homepage":"http://dynamobim.org","size":913272,"stargazers_count":211,"watchers_count":211,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":590,"forks":156,"open_issues":590,"watchers":211,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216"},"html":{"href":"https://github.com/DynamoDS/Dynamo/pull/4216"},"issue":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/issues/4216"},"comments":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/issues/4216/comments"},"review_comments":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216/comments"},"review_comment":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/pulls/4216/commits"},"statuses":{"href":"https://api.github.com/repos/DynamoDS/Dynamo/statuses/af333af84e9c4e66eecddd5d4f423ab0388617a7"}}}}