Pages: 1
Author Topic: Proposals for implementing ASTOperator for EDL_AST  (Read 1273 times)
Offline (Unknown gender) forthevin
Posted on: January 20, 2013, 10:53:21 AM

Joined: Jun 2012
Posts: 171

View Profile
I have looked at the To Do for "Create ASTOperator class for EDL_AST" for the parser at Trello, and have come up with some ways that it may be implemented. I don't see a straight-forward way to do it, since the operator class and the AST nodes in JDI are tightly coupled - the operate method refers directly to ASTOperator/ConstASTOperator, and the ASTOperator/ConstASTOperator have methods specific to each node. The most straight-forward way I can think of would be to make a new class, maybe EDL_ASTOperator, and let it inherit from ASTOperator. The problem with this is that the AST nodes in JDI can only call ASTOperator, not EDL_ASTOperator. I haven't found any solution which is generally good.

I have therefore come up with a couple of different suggestions on how the problem may be tackled:

1: Simply put more methods into ASTOperator and call it a day. The advantage of this method is that it is very easy and should work without any problems in the short-term. The disadvantage is that it makes JDI dependent on EDL, and it seems like JDI is meant to be an independent project separate from EDL.

2: Introduce constant values for each node type, and let operators on the nodes simply cast to the given node type based on the constant values. The advantage is that it would decouple the nodes and the operators, and shouldn't take much time to implement. The disadvantage is that it would make more boilerplate code necessary in the operators, and that it would throw type-safety away.

3: Use a template in the AST for which operator type to use. The advantage is that it would decouple the nodes and the operators like 2, and it would keep type-safety. The disadvantage is that it seems non-trivial, it would take considerably more time than the other options, and both the non-operator parts and the general use of ASTs would be affected.
Offline (Male) Josh @ Dreamland
Reply #1 Posted on: January 20, 2013, 11:37:32 AM

Prince of all Goldfish
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2960

View Profile Email
I mostly put the task on Trello to give cheeseboy something to do instead of bitching at me to do it. Your (1) is more than sufficient.

The ASTOperator class is just an interface: the node types themselves call it. So when a node needs operated on, instead of calling a function in ASTOperator, you call one in node; ie, instead of astOperator->operate(node), you call node->operate(astOperator). The vtable in the node handles making the correct call.

So even if JDI AST elements could end up accidentally storing an EDL AST element (which doesn't happen, presently), the vtable would still call the correct method (but it would have to cast from jdi::ASTOperator to EDL_ASTOperator, which is potentially dangerous).

So yeah, no templates necessary. Just vtables.
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1