Internals: Emit newlines for AstCStmt automatically. No functional change intended.

This commit is contained in:
Wilson Snyder
2025-09-26 08:25:47 -04:00
parent 62880c125e
commit 4ad1dde723
16 changed files with 841 additions and 820 deletions
+16 -8
View File
@@ -86,7 +86,7 @@ static void makeVlToString(AstNodeUOrStructDType* nodep) {
funcp->isConst(false);
funcp->isStatic(false);
funcp->protect(false);
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;\n"});
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
for (const AstMemberDType* itemp = nodep->membersp(); itemp;
itemp = VN_AS(itemp->nextp(), MemberDType)) {
std::string stmt = "out += \"";
@@ -97,11 +97,15 @@ static void makeVlToString(AstNodeUOrStructDType* nodep) {
}
stmt += VIdProtect::protect(itemp->prettyName()) + ":\" + ";
stmt += V3Common::makeToStringCall(itemp->dtypep(), "obj."s + itemp->nameProtect());
stmt += ";\n";
stmt += ";";
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
}
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "out += \"}\";\n"});
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "return out;\n"});
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "out += \"}\";"});
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), "out", 0};
exprp->dtypeSetString();
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
modp->addStmtsp(funcp);
}
static void makeToString(AstClass* nodep) {
@@ -121,7 +125,7 @@ static void makeToStringMiddle(AstClass* nodep) {
funcp->isConst(true);
funcp->isStatic(false);
funcp->protect(false);
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;\n"});
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "std::string out;"});
std::string comma;
for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) {
if (const auto* const varp = VN_CAST(itemp, Var)) {
@@ -135,7 +139,7 @@ static void makeToStringMiddle(AstClass* nodep) {
stmt += itemp->origNameProtect();
stmt += ":\" + ";
stmt += V3Common::makeToStringCall(itemp->dtypep(), itemp->nameProtect());
stmt += ";\n";
stmt += ";";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
}
@@ -146,11 +150,15 @@ static void makeToStringMiddle(AstClass* nodep) {
if (!comma.empty()) stmt += "\", \"+ ";
// comma = ", "; // Nothing further so not needed
stmt += EmitCUtil::prefixNameProtect(nodep->extendsp()->dtypep());
stmt += "::to_string_middle();\n";
stmt += "::to_string_middle();";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
}
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "return out;\n"});
AstCExpr* const exprp = new AstCExpr{nodep->fileline(), "out", 0};
exprp->dtypeSetString();
funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp});
nodep->addStmtsp(funcp);
}