-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AST] Eliminate IfConfigStmt #9413
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
[AST] Eliminate IfConfigStmt #9413
Conversation
@slavapestov @jrose-apple |
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
include/swift/AST/Decl.h
Outdated
/// All elements must be Decl. | ||
const AsDeclRange getAsDecls() const { | ||
return AsDeclRange(getActiveClauseElements(), AsDeclWithSkippingIfConfig()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new methods looks overkill since they only have one client.
include/swift/AST/Stmt.h
Outdated
@@ -24,6 +24,7 @@ | |||
#include "swift/AST/IfConfigClause.h" | |||
#include "swift/AST/TypeAlignments.h" | |||
#include "swift/Basic/NullablePtr.h" | |||
#include "swift/Basic/STLExtras.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidental addition.
lib/AST/ASTDumper.cpp
Outdated
Indent += 2; | ||
for (auto &Clause : ICD->getClauses()) { | ||
OS << '\n'; | ||
OS.indent(Indent); | ||
PrintWithColorRAII(OS, StmtColor) << (Clause.Cond ? "#if:" : "#else"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add :
after #else
.
10c93c4
to
1266ada
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test that shows that we still reject statements within #if
within types, and at the top level in -parse-as-library code?
lib/AST/ASTPrinter.cpp
Outdated
|
||
for (auto &Clause : ICD->getClauses()) { | ||
if (&Clause == &*ICD->getClauses().begin()) | ||
Printer << tok::pound_if << " "; // FIXME: print condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you print something here, even a comment, so that people will know it's not a bug? Or, well, that it's a known bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just a unimplemented feature.
For now, added a commit for printing /* condition */
here.
@swift-ci Please smoke test |
Compatibility test result |
@rintaro Is there anything blocking you from merging this now? |
I didn't see any problems but I wasn't looking too closely. Slava may also still have opinions. |
Resolves: https://bugs.swift.org/browse/SR-4426 * Make IfConfigDecl be able to hold ASTNodes * Parse #if as IfConfigDecl * Stop enclosing toplevel #if into TopLevelCodeDecl. * Eliminate IfConfigStmt
Now that, all TopLevelCodeDecl is real. Just don't need this.
* Removed extra newlines. * Print '/* condition */' for condition part.
26629d8
to
2ad22a8
Compare
@swift-ci Please smoke test |
Now that, IfConfigDecl holds ASTNode regardless statements position or declarations postion. We can construct it in single method.
552dea0
to
c8d717e
Compare
@swift-ci Please smoke test |
@slavapestov Could you review this? |
Just to get the validation tests in @swift-ci please test |
@slavapestov Ping |
Thanks! |
NOTE: This conflicts with #7955 , I will rebase this PR when it's merged.landedResolves: SR-4426
#if
in statements position doesn't have to beStmt
.Modeling it as
IfConfigDecl
simplify the code and AST.IfConfigDecl
be able to holdASTNode
elements#if
asIfConfigDecl
#if
intoTopLevelCodeDecl
.New methods onIfConfigDecl
for retrieving active elements asDecl
s. This replacesIfConfigDecl::getActiveMembers()
.IfConfigStmt
is now dumped as: