Add support for C++ classes and dynamic memory allocation via new and delete - #68
Open
Plastpase123 wants to merge 5 commits into
Open
Add support for C++ classes and dynamic memory allocation via new and delete#68Plastpase123 wants to merge 5 commits into
new and delete#68Plastpase123 wants to merge 5 commits into
Conversation
This enables verification of C++ classes by transforming them into C-style structs.
High-level description of transformation pipeline:
1. Preprocess with C++-specific tri-pp
2. Collect class definitions, mapping fully qualified class names with their
member function definitions and C-struct valid declarations
3. Create new global struct definitions from collected classes
4. Add global member function definitions with and added `struct ClassName *this` argument
5. Transform member function call-sites and object declarations to match
6. Run remaining TriCera pipeline on resulting C-program
Besides class transformations, this commit also adds a check for the TriCeraPreProcessor,
which uses a specific version of tri-pp depending on the type of the file currently being read.
This adds support for dynamic memory allocation via `new` and `delete`. This allows one to declare pointers of primitive- and class types with `new`, and deallocate them via `delete`. Class type pointers are transformed into calls to helper functions that both allocate and construct the object via the constructor, whereas `new` is directly encoded as CHCs for primitives. NOTE: Constructing pointers to pointers with such as `new T*(new ...)` is still a bit iffy. There are also some issues in regards to classes.
new and delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What has been implemented
newanddeletenewfor primitive types are encoded directly as CHCs, and translated into helper functions for class typesdeleteis translated tofreefor primitive types, and helper function calls for class typesLimitations
newto create pointer-to-pointers might be buggyNot implemented (A non-exhaustive list)
Examples
For classes, the following program:
Gets translated to:
For
newanddelete:Gets turned into: