Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C backend lacks destructor for ASTs #348

Closed
andreasabel opened this issue Mar 18, 2021 · 1 comment
Closed

C backend lacks destructor for ASTs #348

andreasabel opened this issue Mar 18, 2021 · 1 comment
Assignees
Labels
AST Concerning the generated abstract syntax C enhancement
Milestone

Comments

@andreasabel
Copy link
Member

The C backend defines constructors, but no destructors for ASTs.

Too add a recursive deallocation procedure e.g. for grammar Calc.cf we need to:

Add to Absyn.h

void freeExp(Exp p);

Add to Absyn.c

void freeExp (Exp p)
{
  switch (p->kind)
  {
   case is_EAdd:
     freeExp(p->u.eadd_.exp_1);
     freeExp(p->u.eadd_.exp_2);
     break;

   case is_ESub:
     freeExp(p->u.esub_.exp_1);
     freeExp(p->u.esub_.exp_2);
     break;

   case is_EMul:
     freeExp(p->u.emul_.exp_1);
     freeExp(p->u.emul_.exp_2);
     break;

   case is_EDiv:
     freeExp(p->u.ediv_.exp_1);
     freeExp(p->u.ediv_.exp_2);
     break;

   case is_EInt:
     break;
  }
  free(p);
}

The code could be adapted from the printer generator.

@andreasabel andreasabel added enhancement C AST Concerning the generated abstract syntax labels Mar 18, 2021
@andreasabel andreasabel self-assigned this Mar 21, 2021
@andreasabel andreasabel added this to the 2.9.2 milestone Mar 21, 2021
@andreasabel
Copy link
Member Author

Similarly, we want clone_XXX methods to recursively copy trees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AST Concerning the generated abstract syntax C enhancement
Projects
None yet
Development

No branches or pull requests

1 participant