Skip to content

Commit

Permalink
feat(codegen_json): add enum to json creation
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed May 27, 2024
1 parent eaadb8b commit 098e187
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion compiler/src/compiler/codegen_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,21 @@ void to_json_compiler::visit_del_stmt(del_stmt *obj) {
json_ << "}\n";
}
void to_json_compiler::visit_enum_stmt(enum_stmt *obj) {
// Placeholder statement - this is not parsed
json_ << "{\n";
write_location(obj);
json_ << "\"type\": \"enum\",\n";
json_ << "\"name\": \"" << string_utils::escape_json(obj->name_->token_) << "\",\n";
json_ << "\"values\": [\n";
int index = 0;
for (auto &value : obj->members_) {
json_ << "{\n";
json_ << "\"name\": \"" << string_utils::escape_json(value.name_->token_) << "\",\n";
json_ << "\"value\": " << index << "\n";
json_ << "}\n";
if (&value != &obj->members_.back()) { json_ << ","; }
}
json_ << "]\n";
json_ << "}\n";
}
void to_json_compiler::visit_expression_stmt(expression_stmt *obj) {
obj->expression_->accept(this);
Expand Down

0 comments on commit 098e187

Please sign in to comment.