Skip to content

C backend lacks destructor for ASTs #348

Closed

Description

@andreasabel

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.

Activity

  1. added
    AST
    on Mar 18, 2021
  2. self-assigned this
    on Mar 21, 2021
  3. added this to the 2.9.2 milestone on Mar 21, 2021
  4. andreasabel commented on Jun 5, 2021

    @andreasabel
    MemberAuthor

    Similarly, we want clone_XXX methods to recursively copy trees.

  5. added 2 commits that reference this issue on Jun 5, 2021
  6. added a commit that references this issue on Mar 1, 2026
    a9d360d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ASTCenhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions