Skip to content

[Parse] Add back TrailingSemiLoc to Expr, Stmt, and Decl #6979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ class alignas(1 << DeclAlignInBits) Decl {
/// Returns the source range of the entire declaration.
SourceRange getSourceRange() const;

SourceLoc TrailingSemiLoc;

LLVM_ATTRIBUTE_DEPRECATED(
void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ class alignas(8) Expr {
SourceLoc getLoc() const { return (SUBEXPR)->getLoc(); } \
SourceRange getSourceRange() const { return (SUBEXPR)->getSourceRange(); }

SourceLoc TrailingSemiLoc;

/// getSemanticsProvidingExpr - Find the smallest subexpression
/// which obeys the property that evaluating it is exactly
/// equivalent to evaluating this expression.
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class alignas(8) Stmt {
SourceLoc getEndLoc() const;

SourceRange getSourceRange() const;
SourceLoc TrailingSemiLoc;

/// isImplicit - Determines whether this statement was implicitly-generated,
/// rather than explicitly written in the AST.
Expand Down
26 changes: 14 additions & 12 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ class Parser {
return AlreadyHandledDecls.erase(D);
}

ParserStatus parseDecl(ParseDeclOptions Flags,
llvm::function_ref<void(Decl*)> Handler);
ParserResult<Decl> parseDecl(ParseDeclOptions Flags,
llvm::function_ref<void(Decl*)> Handler);

void parseDeclDelayed();

Expand Down Expand Up @@ -736,18 +736,20 @@ class Parser {
DeclAttributes &Attributes);
ParserResult<EnumDecl> parseDeclEnum(ParseDeclOptions Flags,
DeclAttributes &Attributes);
ParserStatus parseDeclEnumCase(ParseDeclOptions Flags, DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &decls);
ParserResult<EnumCaseDecl>
parseDeclEnumCase(ParseDeclOptions Flags, DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &decls);
ParserResult<StructDecl>
parseDeclStruct(ParseDeclOptions Flags, DeclAttributes &Attributes);
ParserResult<ClassDecl>
parseDeclClass(SourceLoc ClassLoc,
ParseDeclOptions Flags, DeclAttributes &Attributes);
ParserStatus parseDeclVar(ParseDeclOptions Flags, DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &Decls,
SourceLoc StaticLoc,
StaticSpellingKind StaticSpelling,
SourceLoc TryLoc);
ParserResult<PatternBindingDecl>
parseDeclVar(ParseDeclOptions Flags, DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &Decls,
SourceLoc StaticLoc,
StaticSpellingKind StaticSpelling,
SourceLoc TryLoc);

void consumeGetSetBody(AbstractFunctionDecl *AFD, SourceLoc LBLoc);

Expand Down Expand Up @@ -796,9 +798,9 @@ class Parser {
ParserResult<ProtocolDecl> parseDeclProtocol(ParseDeclOptions Flags,
DeclAttributes &Attributes);

ParserStatus parseDeclSubscript(ParseDeclOptions Flags,
DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &Decls);
ParserResult<SubscriptDecl>
parseDeclSubscript(ParseDeclOptions Flags, DeclAttributes &Attributes,
SmallVectorImpl<Decl *> &Decls);

ParserResult<ConstructorDecl>
parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes);
Expand Down
97 changes: 40 additions & 57 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ namespace {

if (D->isImplicit())
PrintWithColorRAII(OS, DeclModifierColor) << " implicit";

if (D->TrailingSemiLoc.isValid())
PrintWithColorRAII(OS, DeclModifierColor) << " trailing_semi";
}

void printInherited(ArrayRef<TypeLoc> Inherited) {
Expand Down Expand Up @@ -1297,6 +1300,20 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}
}

raw_ostream &printCommon(Stmt *S, const char *Name) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << Name;

if (S->isImplicit())
OS << " implicit";

if (S->TrailingSemiLoc.isValid())
OS << " trailing_semi";

return OS;
}

void visitBraceStmt(BraceStmt *S) {
printASTNodes(S->getElements(), "brace_stmt");
}
Expand All @@ -1318,9 +1335,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitReturnStmt(ReturnStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "return_stmt";
printCommon(S, "return_stmt");
if (S->hasResult()) {
OS << '\n';
printRec(S->getResult());
Expand All @@ -1329,19 +1344,15 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitDeferStmt(DeferStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "defer_stmt\n";
printCommon(S, "defer_stmt") << '\n';
printRec(S->getTempDecl());
OS << '\n';
printRec(S->getCallExpr());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitIfStmt(IfStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "if_stmt\n";
printCommon(S, "if_stmt") << '\n';
for (auto elt : S->getCond())
printRec(elt);
OS << '\n';
Expand All @@ -1354,9 +1365,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitGuardStmt(GuardStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "guard_stmt\n";
printCommon(S, "guard_stmt") << '\n';
for (auto elt : S->getCond())
printRec(elt);
OS << '\n';
Expand All @@ -1365,11 +1374,10 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitIfConfigStmt(IfConfigStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "#if_stmt\n";
printCommon(S, "#if_stmt");
Indent += 2;
for (auto &Clause : S->getClauses()) {
OS << '\n';
OS.indent(Indent);
if (Clause.Cond) {
PrintWithColorRAII(OS, ParenthesisColor) << '(';
Expand All @@ -1390,17 +1398,13 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitDoStmt(DoStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "do_stmt\n";
printCommon(S, "do_stmt") << '\n';
printRec(S->getBody());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitWhileStmt(WhileStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "while_stmt\n";
printCommon(S, "while_stmt") << '\n';
for (auto elt : S->getCond())
printRec(elt);
OS << '\n';
Expand All @@ -1409,18 +1413,14 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}

void visitRepeatWhileStmt(RepeatWhileStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "do_while_stmt\n";
printCommon(S, "repeat_while_stmt") << '\n';
printRec(S->getBody());
OS << '\n';
printRec(S->getCond());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitForStmt(ForStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "for_stmt\n";
printCommon(S, "for_stmt") << '\n';
if (!S->getInitializerVarDecls().empty()) {
for (auto D : S->getInitializerVarDecls()) {
printRec(D);
Expand Down Expand Up @@ -1449,9 +1449,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitForEachStmt(ForEachStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
OS << "for_each_stmt\n";
printCommon(S, "for_each_stmt") << '\n';
printRec(S->getPattern());
OS << '\n';
if (S->getWhere()) {
Expand All @@ -1477,27 +1475,19 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitBreakStmt(BreakStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "break_stmt";
printCommon(S, "break_stmt");
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitContinueStmt(ContinueStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "continue_stmt";
printCommon(S, "continue_stmt");
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitFallthroughStmt(FallthroughStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "fallthrough_stmt";
printCommon(S, "fallthrough_stmt");
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitSwitchStmt(SwitchStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "switch_stmt\n";
printCommon(S, "switch_stmt") << '\n';
printRec(S->getSubjectExpr());
for (CaseStmt *C : S->getCases()) {
OS << '\n';
Expand All @@ -1506,9 +1496,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitCaseStmt(CaseStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "case_stmt";
printCommon(S, "case_stmt");
for (const auto &LabelItem : S->getCaseLabelItems()) {
OS << '\n';
OS.indent(Indent + 2);
Expand All @@ -1529,24 +1517,18 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}
void visitFailStmt(FailStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "fail_stmt";
printCommon(S, "fail_stmt");
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitThrowStmt(ThrowStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "throw_stmt\n";
printCommon(S, "throw_stmt") << '\n';
printRec(S->getSubExpr());
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

void visitDoCatchStmt(DoCatchStmt *S) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "do_catch_stmt\n";
printCommon(S, "do_catch_stmt") << '\n';
printRec(S->getBody());
OS << '\n';
Indent += 2;
Expand All @@ -1560,9 +1542,7 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
}
}
void visitCatchStmt(CatchStmt *clause) {
OS.indent(Indent);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "catch\n";
printCommon(clause, "catch") << '\n';
printRec(clause->getErrorPattern());
if (auto guard = clause->getGuardExpr()) {
OS << '\n';
Expand Down Expand Up @@ -1670,6 +1650,9 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
}
}

if (E->TrailingSemiLoc.isValid())
OS << " trailing_semi";

return OS;
}

Expand Down
Loading