eth-cscs / modparser

BSD 2-Clause "Simplified" License
0 stars 0 forks source link

introduce shared_ptr for AST nodes #9

Closed bcumming closed 9 years ago

bcumming commented 9 years ago

Currently Expressions are created as raw pointers, and never deleted. In practice this works fine, and we are never likely to run out of memory. However, as the application scales, this approach might not scale. It is also just bad practice.

bcumming commented 9 years ago

I have started a pointers branch for this.

The next step is to take a step back, and resolve ownership of things in the symbol table.

bcumming commented 9 years ago

fixed in the merge of the ast branch. The unit tests and the compiler now pass valgrind with zero memory leaks.

The fix used std::unique_ptr to manage ownership of AST nodes and symbols. Each node is stored in the AST using a unique_ptr. Symbols are stored in the symbol tables using unique pointers, and all references to a symbol from the AST (formed during semantic analysis) are raw pointers. This fixed some complexities of the original approach, by ensuring that Symbols are only created in the symbol tables, and that it is much more difficult to accidentally create two symbols twice.