Rewrite AST before elaborate #572
HungMingWu
started this conversation in
General
Replies: 2 comments 1 reply
|
My intention was that you should be able to do things exactly like that, but you make a good point -- I hadn't considered the effect it would have on the metadata. I need to think about how best to handle that. Obviously we could make the metadata modifiable but needing to manually update it seems annoying, it would be nice if it just figured it out for you. |
0 replies
|
Hi Mike, I have another question. void handle(const TypedefDeclarationSyntax& decl) {
if (decl.type->kind != SyntaxKind::EnumType)
return;
// Create a new localparam hardcoded with the number of entries in the enum.
auto type = model.getDeclaredSymbol(decl.type->as<EnumTypeSyntax>());
REQUIRE(type);
size_t count = type->as<EnumType>().members().size();
auto& newNode = parse(
fmt::format("\n localparam int {}__count = {};", decl.name.valueText(), count));
insertAfter(decl, newNode);
auto& newNode1 = parse(
fmt::format("\n localparam int {}__count = {};", decl.name.valueText(), count));
insertAfter(decl, newNode1);
}It doesn't work, the following code snippet doesn't work either. auto& newNode = parse(
fmt::format("\n localparam int {}__count = {};", decl.name.valueText(), count));
insertAfter(decl, newNode);
auto& newNode1 = parse(
fmt::format("\n localparam int {}__count = {};", decl.name.valueText(), count));
insertAfter(newNode, newNode1);Since the newNode is not oldNode. struct CloneVisitor {
SyntaxNode* visit(const T& node) {
// Ignore
auto it = changes.find(child);
if (it == changes.end()) {
// ignore
}
else {
switch (it->second.kind) {
// Ignore
}
}
}
};It only accept one modification. using ChangeMap = flat_hash_map<const SyntaxNode*, std::vector<detail::SyntaxChange>>; |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi Mike,
I have one question.
Can I operator like this?
In my brief test, The metadata have been changed.
So I need to serialize to string and construct it again?
All reactions