How to add new content to extraClassDeclaration in subclasses?

The current situation is as follows. There is a record of extraClassDeclaration in the parent class, and there are multiple classes that inherit from this class. I want to add a new content in the extraClassDeclaration of the child class. I don’t want to rewrite the content of the parent class extraClassDeclaration in the child class. Here is how I do it

let extraClassDeclaration = !strconcat(!cast<string>(extraClassDeclaration), "fuction declaration").

I checked the documentation of TableGen, tried to use strconcat, and tried to convert code type to string type but it didn’t help.I hope someone can give me some guiding advice.Thanks!

Let me be more specific in making this question. Because the use of let extraClassDeclaration = ... in the child class causes overloading the extraClassDeclaration in the parent class, I want to keep the extraClassDeclaration in the parent class(Multiple classes will inherit from this parent class.) and then add the code in the child class(function declaration). In fact, you can look at this problem from another perspective. I need to use the method I wrote in the extraClassDeclaration in the verify of an operation, and also in the pass, and the pass and verify are in two different files, so I want to make it a member of some operation. In fact, there should be many ways to solve this problem, but we must consider how to achieve the most elegant and reduce the coupling of the code.

I’ve done something along the following lines in the past:

class Parent {
  string commonClassDeclaration = [{ ... }];
  let extraClassDeclaration = commonClassDeclaration;

class Child : Parent {
  let extraClassDeclaration = commonClassDeclaration # [{ ... }];

That is, store the common part in a separate field and you won’t have any problems with redefinition.

1 Like

Thanks for the help. I think I still have a long way to go in developing with llvm.:smile:

Some time ago I did think about changing how one specifies this for exactly this reason. But it opened up other issues, so as Alex suggested is the least surprising way that is explicit.

1 Like

I think this approach is also very nice and elegant.:+1: