Rewrite AST before elaborate #572
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. |
Beta Was this translation helpful? Give feedback.
-
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>>; |
Beta Was this translation helpful? Give feedback.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions