Skip to content

Commit 8da1c75

Browse files
committed
Added the expression cases of the form 'visit...Expr()'
1 parent 80b9386 commit 8da1c75

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,7 +4723,9 @@ void PrintAST::visitPostfixOperatorDecl(PostfixOperatorDecl *decl) {
47234723
});
47244724
}
47254725

4726-
void PrintAST::visitModuleDecl(ModuleDecl *decl) { }
4726+
void PrintAST::visitModuleDecl(ModuleDecl *decl) {
4727+
4728+
}
47274729

47284730
void PrintAST::visitMissingDecl(MissingDecl *missing) {
47294731
Printer << "missing_decl";
@@ -4879,12 +4881,27 @@ void PrintAST::visitErrorExpr(ErrorExpr *expr) {
48794881
Printer << "<error>";
48804882
}
48814883

4882-
void PrintAST::visitTernaryExpr(TernaryExpr *expr) {}
4884+
void PrintAST::visitTernaryExpr(TernaryExpr *expr) {
4885+
if (auto condExpr = expr->getCondExpr()) {
4886+
visit(expr->getCondExpr());
4887+
}
4888+
Printer << " ? ";
4889+
visit(expr->getThenExpr());
4890+
Printer << " : ";
4891+
if (auto elseExpr = expr->getElseExpr()) {
4892+
visit(expr->getElseExpr());
4893+
}
4894+
}
48834895

48844896
void PrintAST::visitIsExpr(IsExpr *expr) {
4897+
visit(expr->getSubExpr());
4898+
Printer << " is ";
4899+
printType(expr->getCastType());
48854900
}
48864901

48874902
void PrintAST::visitTapExpr(TapExpr *expr) {
4903+
printType(expr->getVar()->getType());
4904+
printBraceStmt(expr->getBody());
48884905
}
48894906

48904907
void PrintAST::visitTryExpr(TryExpr *expr) {
@@ -4965,6 +4982,15 @@ void PrintAST::visitDictionaryExpr(DictionaryExpr *expr) {
49654982
}
49664983

49674984
void PrintAST::visitArrowExpr(ArrowExpr *expr) {
4985+
visit(expr->getArgsExpr());
4986+
if (auto isAsync = expr->getAsyncLoc()) {
4987+
Printer << " async";
4988+
}
4989+
if (auto doesThrow = expr->getThrowsLoc()) {
4990+
Printer << " throws";
4991+
}
4992+
Printer << " -> ";
4993+
visit(expr->getResultExpr());
49684994
}
49694995

49704996
void PrintAST::visitAwaitExpr(AwaitExpr *expr) {
@@ -5006,8 +5032,7 @@ void PrintAST::visitTupleExpr(TupleExpr *expr) {
50065032
Printer << ")";
50075033
}
50085034

5009-
void PrintAST::visitTypeJoinExpr(TypeJoinExpr *expr) {
5010-
}
5035+
void PrintAST::visitTypeJoinExpr(TypeJoinExpr *expr) { }
50115036

50125037
void PrintAST::visitAssignExpr(AssignExpr *expr) {
50135038
visit(expr->getDest());
@@ -5028,12 +5053,35 @@ void PrintAST::visitBinaryExpr(BinaryExpr *expr) {
50285053
}
50295054

50305055
void PrintAST::visitCoerceExpr(CoerceExpr *expr) {
5056+
visit(expr->getSubExpr());
5057+
Printer << " as ";
5058+
printType(expr->getCastType());
50315059
}
50325060

5033-
void PrintAST::visitOneWayExpr(OneWayExpr *expr) {
5034-
}
5061+
void PrintAST::visitOneWayExpr(OneWayExpr *expr) { }
50355062

50365063
void PrintAST::visitClosureExpr(ClosureExpr *expr) {
5064+
Printer << "{ ";
5065+
if (auto parameters = expr->getParameters()) {
5066+
if (expr->hasExplicitResultType()) {
5067+
Printer << "(";
5068+
}
5069+
bool isFirst = true;
5070+
for (auto& parameter: *parameters) {
5071+
if (!isFirst) {
5072+
Printer << ", ";
5073+
}
5074+
visit(parameter);
5075+
isFirst = true;
5076+
}
5077+
if (expr->hasExplicitResultType()) {
5078+
Printer << ") -> ";
5079+
printType(expr->getExplicitResultType());
5080+
}
5081+
}
5082+
auto body = expr->getBody();
5083+
printBraceStmt(body);
5084+
Printer << "}";
50375085
}
50385086

50395087
void PrintAST::visitDeclRefExpr(DeclRefExpr *expr) {
@@ -5050,6 +5098,7 @@ void PrintAST::visitErasureExpr(ErasureExpr *expr) {
50505098
}
50515099

50525100
void PrintAST::visitKeyPathExpr(KeyPathExpr *expr) {
5101+
50535102
}
50545103

50555104
void PrintAST::visitSingleValueStmtExpr(SingleValueStmtExpr *expr) {
@@ -5062,6 +5111,7 @@ void PrintAST::visitForceTryExpr(ForceTryExpr *expr) {
50625111
}
50635112

50645113
void PrintAST::visitSequenceExpr(SequenceExpr *expr) {
5114+
50655115
}
50665116

50675117
void PrintAST::visitSuperRefExpr(SuperRefExpr *expr) {

0 commit comments

Comments
 (0)