IP Library Granted Patent US 11,068,244
Granted Patent B2
US 11,068,244 · App. 16/589,998 · Granted Jul 20, 2021

Optimized transpilation

Inventors: Alexander Rich (Fremont, CA); Jinai Kathiara (Walnut Creek, CA)
Assignee: salesforce.com, inc.
G06F8/427G06F7/24G06F8/443G06F40/154G06F40/211
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,068,244
App. No.
16/589,998
Granted
Jul 20, 2021
Kind
B2
Abstract

System and methods are described to parse input source code and generate a tree representing the input source code, optimize the tree by determining reusable sub-trees of the tree and replacing the reusable sub-trees with variables, and transpile the optimized tree to generate output source code.

Claims (21)

1. An apparatus, comprising: a processing device; and a memory device coupled to the processing device, the memory device having instructions stored thereon that, in response to execution by the processing device, cause the processing device to: parse input source code and generate a tree representing the input source code; optimize the tree by recursively traverse the tree starting with a root node of the tree as a current node; if the current node represents a reusable sub-tree already encountered during traversal, replace the current node with a first leaf node assigned to a variable; and if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, assign a new variable, replace the current node with a second leaf node referencing the new variable, and replace a previous instance of the current node with a third leaf node referencing the new variable; and transpile the optimized tree to generate output source code.

2. The apparatus of claim 1 , wherein the tree is an abstract syntax tree.

3. The apparatus of claim 1 , wherein the input source code is in a formula language.

4. The apparatus of claim 1 , wherein the output source code in JavaScript.

5. The apparatus of claim 1 , wherein instructions to optimize the tree comprise instructions that, in response to execution by the processing device, cause the processing device to: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, store the new variable in a set of replaced sub-trees.

6. The apparatus of claim 1 , wherein instructions to optimize the tree comprise instructions that, in response to execution by the processing device, cause the processing device to: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has not already been encountered during traversal, add the current node to a set of nodes already encountered during traversal.

7. The apparatus of claim 1 , wherein instructions to transpile the optimized tree to generate output source code comprise instructions that, in response to execution by the processing device, cause the processing device to: sort replaced sub-trees by level of the tree; and transpile, in sorted order, each replaced sub-tree, and append generated source code for each replaced sub-tree as an assignment statement to a variable assigned to each replaced sub-tree.

8. The apparatus of claim 7 , comprising instructions that, in response to execution by the processing device, cause the processing device to: sort the replaced sub-trees by level of the tree from deepest level of the tree to top-most level of the tree.

9. A computer-implemented method comprising: parsing input source code and generating a tree representing the input source code; optimizing the tree by recursively traversing the tree starting with a root node of the tree as a current node, if the current node represents a reusable sub-tree already encountered during traversal, replacing the current node with a first leaf node assigned to a variable, and if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, assigning a new variable, replacing the current node with a second leaf node referencing the new variable, and replacing a previous instance of the current node with a third leaf node referencing the new variable; and transpiling the optimized tree to generate output source code.

10. The computer-implemented method of claim 9 , wherein the tree is an abstract syntax tree.

11. The computer-implemented method of claim 9 , wherein the input source code is in a formula language.

12. The computer-implemented method of claim 9 , wherein the output source code in JavaScript.

13. The computer-implemented method of claim 9 , wherein optimizing the tree comprises: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, storing the new variable in a set of replaced sub-trees.

14. The computer-implemented method of claim 9 , wherein optimizing the tree comprises: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has not already been encountered during traversal, adding the current node to a set of nodes already encountered during traversal.

15. The computer-implemented method of claim 9 , wherein transpiling the optimized tree to generate output source code comprises: sorting replaced sub-trees by level of the tree; and transpiling, in sorted order, each replaced sub-tree, and appending generated source code for each replaced sub-tree as an assignment statement to a variable assigned to each replaced sub-tree.

16. The computer-implemented method of claim 15 , comprising sorting the replaced sub-trees by level of the tree from deepest level of the tree to top-most level of the tree.

17. A tangible, non-transitory computer-readable storage medium having instructions encoded thereon which, when executed by a processing device, cause the processing device to: parse input source code and generating a tree representing the input source code; optimize the tree by recursively traverse the tree starting with a root node of the tree as a current node; if the current node represents a reusable sub-tree already encountered during traversal, replace the current node with a first leaf node assigned to a variable; and if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, assign a new variable, replace the current node with a second leaf node referencing the new variable, and replace a previous instance of the current node with a third leaf node referencing the new variable; and transpile the optimized tree to generate output source code.

18. The tangible, non-transitory computer-readable storage medium of claim 17 , wherein instructions stored thereon to optimize the tree comprise instructions that, in response to execution by the processing device, cause the processing device to: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has already been encountered during traversal, store the new variable in a set of replaced sub-trees.

19. The tangible, non-transitory computer-readable storage medium of claim 17 , wherein instructions stored thereon to optimize the tree comprise instructions that, in response to execution by the processing device, cause the processing device to: if the current node does not represent a reusable sub-tree already encountered during traversal, and the current node has not already been encountered during traversal, add the current node to a set of nodes already encountered during traversal.

20. The tangible, non-transitory computer-readable storage medium of claim 17 , wherein instructions stored thereon to transpile the optimized tree to generate output source code comprise instructions that, in response to execution by the processing device, cause the processing device to: sort replaced sub-trees by level of the tree; and transpile, in sorted order, each replaced sub-tree, and append generated source code for each replaced sub-tree as an assignment statement to a variable assigned to each replaced sub-tree.

21. The tangible, non-transitory computer-readable storage medium of claim 20 , comprising instructions stored thereon that, in response to execution by the processing device, cause the processing device to: sort the replaced sub-trees by level of the tree from deepest level of the tree to top-most level of the tree.

Assignments (2)
CHANGE OF NAME Recorded Dec 18, 2024
From: SALESFORCE.COM, INC.
To: SALESFORCE, INC.
Reel/Frame 069717/0444 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Oct 25, 2019
From: RICH, ALEXANDER; KATHIARA, JINAI
To: SALESFORCE.COM, INC.
Reel/Frame 050825/0672 →
Continuity (1)
Related Publication 20210096832A1 · Apr 1, 2021
Cited By (2)
US 12,327,088 US 12,705,036