Reworked initialization of globals for -O gen-standalone-C++ code

This commit is contained in:
Vern Paxson 2025-09-30 11:27:53 -07:00
parent 0700427bac
commit eb13ff3110
15 changed files with 155 additions and 62 deletions

View file

@ -87,7 +87,17 @@ void CPPCompile::GenInitStmt(const InitStmt* init) {
continue;
}
Emit("%s = make_intrusive<%s>(cast_intrusive<%s>(%s));", IDName(aggr), type_name, type_type, type_ind);
auto aggr_name = IDName(aggr);
Emit("%s = make_intrusive<%s>(cast_intrusive<%s>(%s));", aggr_name, type_name, type_type, type_ind);
const auto& attrs = aggr->GetAttrs();
if ( ! attrs )
continue;
auto attrs_offset = AttributesOffset(attrs);
auto attrs_str = "CPP__Attributes__[" + Fmt(attrs_offset) + "]";
Emit("%s->SetAttrs(%s);", aggr_name, attrs_str);
}
}