On 11 June 2015 at 14:02, Jonathan S. Shapiro <[email protected]> wrote:

> On Thu, Jun 11, 2015 at 12:30 AM, Keean Schupke <[email protected]> wrote:
>
>> On 10 June 2015 at 17:13, Jonathan S. Shapiro <[email protected]> wrote:
>>
>>>
>>> Umm. Actually, that sounds pretty expensive. The problem isn't popping
>>> the vector. The problem is the unnecessary constructions you're going to do
>>> every time you *grow* the vector. You want a vector of pointers, not a
>>> vector of objects. Though even that's a problem, because the parse stack
>>> elements don't have homogeneous type.
>>>
>>>
>>> shap
>>>
>>
>> What unnecessary constructions? It is also polymorphic, a unique pointer
>> can point to any subclass just like a plain pointer. Hopefully this will
>> make it clearer:
>>
>> vector<unique_ptr<ast>> region;
>>
>
> Right. Once you are using a unique_ptr (or any ptr type), this works fine.
> The only real problem with unique_ptr here is that it's sometimes
> convenient for AST's to become DAGs in later processing passes.
>

DAGs or cyclic-graphs are fine. The vector just owns the nodes, it is not
the structure. Each node contains plain pointers to the other nodes it
references. This is what the union-stack is for, storing the original
pointer addresses when you move bits of the tree around. Before you can
backtrack, freeing the memory for some AST objects, all references created
between tree nodes after the choice point have to be undone first.

K.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to