systemc-clang
systemc-clang copied to clipboard
Refactor the destruction of the objects
Description
The destruction of objects with Matchers
and SystemCClang
should be revisited. It seems that the destruction of dynamically objects are not done properly.
The current design creates an incomplete ModuleDecl
in Matchers. The ports are populated there. Then, for each instance that is recognized, a new ModuleDecl
is created, and information from the incomplete ModuleDecl
is copied into the new instance-specific ModuleDecl
. When deleting an instance of ModuleDec
l, we have to be careful. This is because we do not want to delete the instance-specific ModuleDecl
, which has structures with pointers in it (PortDecl
), and then delete the incomplete ModuleDecl
because the latter will cause a double free memory error. This is because the deletion of the instance-specific ModuleDecl will free the objects identified in the incomplete ModuleDecl
.
The current solution is to clear the information for the instance-specific ModuleDecl
before deleting it. Then, the deletion of the incomplete ModuleDecl
will free the other objects such as PortDecl
.
clearOnlyGlobal
does exactly this.