Skip to content

Commit 900dac1

Browse files
authored
removing invalid tokens (#138)
1 parent fbf5011 commit 900dac1

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Chimera.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,9 @@ static void findModuleName(Node *head, Node *&name) {
830830
}
831831

832832
static void removeEmptyGateTypes(Node *head) {
833-
if (head->type == NodeType::GATETYPE &&
834-
head->getChildren()[0]->getElement().empty()) {
833+
if ((head->type == NodeType::GATETYPE &&
834+
head->getChildren()[0]->getElement().empty()) ||
835+
head->type == NodeType::SWITCHTYPE) {
835836
auto parent = head->getParent();
836837
parent->clearChildren();
837838
parent->insertChildToEnd(std::make_unique<Terminal>(""));
@@ -842,6 +843,23 @@ static void removeEmptyGateTypes(Node *head) {
842843
}
843844
}
844845

846+
static void removeInvalidTokens(Node *head) {
847+
if (head->type == NodeType::PROPERTY_DECLARATION ||
848+
head->type == NodeType::SEQUENCE_DECLARATION) {
849+
if (head->getChildren().size() == 8) {
850+
head->getChildren()[3]->setElement(";");
851+
} else {
852+
head->getChildren()[5]->setElement(";");
853+
}
854+
} else if (head->type == NodeType::PREPROCESSOR_ACTION) {
855+
head->clearChildren();
856+
head->insertChildToEnd(std::make_unique<Terminal>(" "));
857+
}
858+
for (size_t i = 0; i < head->getChildren().size(); i++) {
859+
removeInvalidTokens(head->getChildren()[i].get());
860+
}
861+
}
862+
845863
static void removeIncorrectGates(Node *head) {
846864
// Remove gates declarations from the generated module
847865
if (head->type ==
@@ -1680,6 +1698,7 @@ formatandCallCustomFunctions(std::vector<std::shared_ptr<Module>> &modules) {
16801698
static void cleanModule(Node *head) {
16811699
removeIncorrectGateInstances(head);
16821700
removeDeclDimensions(head);
1701+
removeInvalidTokens(head);
16831702
}
16841703

16851704
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)