aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlformat/dumpastvisitor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qmlformat/dumpastvisitor.cpp')
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index 75712975cc..e0feff4e51 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -626,7 +626,7 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext,
case Node::Kind_IfStatement: {
auto *ifStatement = cast<IfStatement *>(statement);
- m_blockNeededBraces = false;
+ m_blockNeededBraces = !blockAllowBraceless;
QString ifFalse = parseStatement(ifStatement->ko, false, true);
QString ifTrue = parseStatement(ifStatement->ok, !ifFalse.isEmpty(), true);
@@ -641,8 +641,36 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext,
ifTrue = parseStatement(ifStatement->ok, !ifFalse.isEmpty(), false);
}
+ if (ifStatement->ok->kind != Node::Kind_Block)
+ ifTrue += ";";
+
+ if (ifStatement->ko && ifStatement->ko->kind != Node::Kind_Block && ifStatement->ko->kind != Node::Kind_IfStatement)
+ ifFalse += ";";
+
QString result = "if (" + parseExpression(ifStatement->expression) + ")";
+ if (m_blockNeededBraces) {
+ if (ifStatement->ok->kind != Node::Kind_Block) {
+ QString result = "{\n";
+ m_indentLevel++;
+ result += formatLine(ifTrue);
+ m_indentLevel--;
+ result += formatLine("} ", false);
+ ifTrue = result;
+ ifTrueBlock = true;
+ }
+
+ if (ifStatement->ko && ifStatement->ko->kind != Node::Kind_Block && ifStatement->ko->kind != Node::Kind_IfStatement) {
+ QString result = "{\n";
+ m_indentLevel++;
+ result += formatLine(ifFalse);
+ m_indentLevel--;
+ result += formatLine("} ", false);
+ ifFalse = result;
+ ifFalseBlock = true;
+ }
+ }
+
if (ifTrueBlock) {
result += " " + ifTrue;
} else {
@@ -724,8 +752,6 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext,
else
result += ";";
-
-
return result;
}
case Node::Kind_WhileStatement: {
@@ -825,7 +851,7 @@ QString DumpAstVisitor::parseStatementList(StatementList *list)
result += getOrphanedComments(list);
for (auto *item = list; item != nullptr; item = item->next) {
- QString statement = parseStatement(item->statement->statementCast());
+ QString statement = parseStatement(item->statement->statementCast(), false, true);
if (statement.isEmpty())
continue;
@@ -843,8 +869,8 @@ QString DumpAstVisitor::parseStatementList(StatementList *list)
}
bool DumpAstVisitor::visit(UiPublicMember *node) {
- addLine(getComment(node, Comment::Location::Front));
+ QString commentFront = getComment(node, Comment::Location::Front);
QString commentBackInline = getComment(node, Comment::Location::Back_Inline);
switch (node->type)
@@ -859,6 +885,7 @@ bool DumpAstVisitor::visit(UiPublicMember *node) {
scope().m_firstSignal = false;
}
+ addLine(commentFront);
addLine("signal "+node->name.toString()+"("+parseUiParameterList(node->parameters) + ")"
+ commentBackInline);
break;
@@ -897,6 +924,7 @@ bool DumpAstVisitor::visit(UiPublicMember *node) {
if (has_type_modifier)
member_type = node->typeModifier + "<" + member_type + ">";
+ addLine(commentFront);
if (is_readonly && statement.isEmpty()
&& scope().m_bindings.contains(node->name.toString())) {
m_result += formatLine(prefix + "property " + member_type + " ", false);
@@ -1003,6 +1031,7 @@ bool DumpAstVisitor::visit(UiObjectDefinition *node) {
}
addLine(getComment(node, Comment::Location::Front));
+ addLine(getComment(node, Comment::Location::Front_Inline));
addLine(parseUiQualifiedId(node->qualifiedTypeNameId) + " {");
m_indentLevel++;
@@ -1198,6 +1227,7 @@ bool DumpAstVisitor::visit(UiObjectBinding *node) {
} else {
addNewLine();
addLine(getComment(node, Comment::Location::Front));
+ addLine(getComment(node, Comment::Location::Front_Inline));
addLine(result + " {");
}